Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

patching memory in another process

Name: Anonymous 2006-02-06 9:03

Hi /prog/

I am writing a program to patch a memory location in another running process. Unfortunately it doesn't work as ReadProcessMemory gets an error 6 ("The handle is invalid."), even though the process ID passed on the command line is valid.

Has anyone here done this sort of thing before, and if so d'you know what I may be doing wrong?

Code is below:

#define PATCH_LOCATION 0x0013A142

void error(char *msg)
{
    printf("Error (%s) [0x%08x]\n", msg, GetLastError());
    ExitProcess (0);
};

void main(int argc, char* argv[])
{
    int patch_int;
    HANDLE process_id;
    HANDLE hToken;

    // get process id from command line
    if (argc<2)
        error ("args");
    sscanf(argv[1],"%u",&process_id);
    printf("process_id = %u\n", process_id);

    // attach to process as debugger
    if (DebugActiveProcess((DWORD)process_id)==FALSE)
        error ("DebugActiveProcess()");

    // read patch location
    if (ReadProcessMemory(process_id, (LPVOID)PATCH_LOCATION, &patch_int, 4, NULL)==FALSE)
        error ("ReadProcessMemory()");

    printf("patch_int = 0x%08x\n", patch_int);

    // check if patch location contains expected value
    if (patch_int==250)
    {
        // if so, overwrite with patch value
        patch_int=0xFFFFFFFF;
        if(WriteProcessMemory (process_id, (LPVOID)PATCH_LOCATION, &patch_int, 4, NULL)==FALSE)
            error ("WriteProcessMemory()");
    }
    else
    {
        // or fail
        error("patch_int");
    }

    printf("success!\n");
};

Name: Anonymous 2006-04-28 12:03

>>34
You can give them rights to store these files in these directories for all users.

The deal with ~/.higuyz is my home directory is full of shit, and I want to always show these hidden files because hiding files is a vomit of a luser idea/hack (more fit for a stock Windows installation than a Unix OS BTW) and an insecure practice. I want to know what's everywhere because I control my box, this is not Mother Russia, plus I usually edit these files by hand.

And there's always software who thinks it's the best application in the Universe and doesn't even bother to use a dot file (GNAAstep, for example). Not only it's fugly and spam, but it's even between my regular files.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List