Jump to content
Tuts 4 You

Patch file example


Teerayoot

Recommended Posts

Posted
// ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <stdio.h>
#include <Windows.h>

//Returns the last Win32 error, in string format. Returns an empty string if there is no error.
std::string GetLastErrorAsString()
{
	//Get the error message ID, if any.
	DWORD errorMessageID = ::GetLastError();
	if (errorMessageID == 0) {
		return std::string(); //No error message has been recorded
	}

	LPSTR messageBuffer = nullptr;

	//Ask Win32 to give us the string version of that message ID.
	//The parameters we pass in, tell Win32 to create the buffer that holds the message for us (because we don't yet know how long the message string will be).
	size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
		NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);

	//Copy the error message into a std::string.
	std::string message(messageBuffer, size);

	//Free the Win32's string's buffer.
	LocalFree(messageBuffer);

	return message;
}

int main()
{
	/*FILE *fp = NULL;
	fopen_s(&fp, "example.bin", "ab");


	unsigned char buf[] = { 0x90 ,0x90 ,0x90 ,0x90 ,0x90 ,0x90 ,0x90 ,0x90 ,0x90 ,0x90 };
	fseek(fp, 0x10, 0);
	fwrite(buf, 1, sizeof(buf), fp);
	fclose(fp);
	*/
	HANDLE h = NULL;// CreateFile(L"example.bin", 0, 0, 0, 0, 0, 0);

	OVERLAPPED ol = { 0 };
	h = CreateFile(L"example.bin",               // file to open
		GENERIC_READ | GENERIC_WRITE,          // open for reading
		0,       // share for reading
		NULL,                  // default security
		OPEN_EXISTING,         // existing file only
		FILE_ATTRIBUTE_NORMAL , // normal file
		NULL);                 // no attr. template

	DWORD fLen = SetFilePointer(h, 0, 0, FILE_END);

	unsigned char *buffer = new unsigned char[fLen];

	SetFilePointer(h, 0, 0, FILE_BEGIN);


	DWORD nr = 0;

	ReadFile(h, buffer, fLen,&nr, 0);

	std::string errS = GetLastErrorAsString();

	printf(errS.c_str());

	SetFilePointer(h, 0, 0, FILE_BEGIN);

	DWORD nw = 0;

	unsigned char buf[] = { 0x90,0x90 ,0x90 ,0x90 ,0x90 ,0x90 ,0x90 ,0x90 ,0x90 ,0x90 ,0x90 ,0x90 ,0x90 ,0x90 };


	memcpy(&buffer[0x10], buf, sizeof(buf));

	WriteFile(h, buffer,fLen, &nw, 0);
	
	errS = GetLastErrorAsString();

	printf(errS.c_str());

	printf("%d", nw);

	delete[] buffer;
	CloseHandle(h);
}

 

Posted

1/10 would not use, but thanks for trying.

Teddy Rogers
Posted
2 hours ago, Xyl2k said:

1/10 would not use, but thanks for trying.

Please provide reasoning...

Ted.

  • Thanks 1
Posted

This is my sauce for beginners to learn.
It's been a long time to write.

#include <windows.h>
#include <iostream>


using namespace std;

int main() {

    HWND hd = FindWindowA("Qt5QWindowIcon", "4K Video Downloader – Not Activated");

    DWORD dwPID = 0;

    GetWindowThreadProcessId(hd, &dwPID);

    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, dwPID);

    Sleep(200);

    BYTE data[2] = { 254,192 };

    WriteProcessMemory(hProcess, (LPVOID)13837574, (LPVOID)data, 2, NULL);

    std::cout << "Hello World" << endl;

    return 0;
}

 

Posted
4 hours ago, Teddy Rogers said:

Please provide reasoning...

Ted.

c, console, no file backup, no preliminary check on file you are about to patch

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...