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-05-31 7:04

>>40
Good job for bumping it

s/GNU/GNAA/g

Name: Anonymous 2007-11-29 7:31

bump that shit bitches

Name: Anonymous 2007-11-29 7:52

>>42
Good job for bumping it

Name: Anonymous 2007-11-29 8:38

>>19
wait, how the fuck did you link to that

Name: Anonymous 2007-11-29 8:58

>>44
read sicp

Name: Anonymous 2007-11-29 12:54

Oh wow, nice to see this one again. I was OP.

Name: age 2007-11-29 23:18

age goes in all fucking fields. Which aren't that many on Shiichan.

Name: Anonymous 2007-11-30 0:22

>>46
NO YOU WERE NOT, I START THIS THREAD, I AM THE OP

Name: Anonymous 2009-03-18 2:13

I feel the need, the need for weed!

Marijuana MUST be legalized.

Name: Anonymous 2010-12-06 9:06

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2013-06-02 19:32

check these dubs

Name: Anonymous 2013-06-02 21:09

what dubs? shitty dubs.

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