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-03-02 6:55

>>17
You're the kind of idiot that will fall for digital rights infringement and treacherous computing. You won't be able to even control what processes run in your OS or run your own code natively, unless you're with Microsoft and enforce treacherous computing yourself to get licenses. You won't be able to run others' free software, and you'll probably have trouble using your own files unless you purchase from Microsoft, AOL, or Sony.

I'm a Windows 2000 user and developer. I prefer Windows as a workstation OS, and work on it daily. But I'm not stupid. If we can't crack Vista and get rid of the treacherous computing and digital rights infringement in it, I will never upgrade. In fact I was thinking not to upgrade for several other reasons, including performance, memory, and bloat, the same reasons I'm using 2000 not XP. I'll stay with Windows 2000 until there are more 64 bit devices released, then move to Windows Server 2003, and stay with it for as long as I can. Vista's kernel is not too different; most things will still run for many years after Vista, just like with XP.

By the day I'm forced to upgrade by software, then I'll see whether I can crack Vista, or say Hasta la Vista to Windows and move to ReactOS (if it's enough developed by then) or Linux (even if I have to cope with the fucking FHS ugly mess, a sluggish GUI, and compiling others' shit).

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