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 18:59

>>26
Are you implying that Windows has a neater file organization than Linux's FHS? Ha!
Yes, because application files aren't tossed into your filesystem directories as you deal playing cards in a fucking Poker game. Yes, because Linux' retarded way library paths work force you to toss all the shit into shared folders. Yes, because /usr, /sbin, /var, /opt, and pretty much anything else are stupid, poorly named, easily misunderstood, and wrongly used. Yes, because in Windows NT you control filesystem hierarchy, while in mother Unix filesystem hierarchy controls you. Yes, because applications are so much easier to move by hand without collecting files from everywhere like a faggot. Yes, because FHS is just gay.

When I'm using Linux the GUI works fine (except for Firefox which is a shitty piece of shit anyway.) When I'm using Windows everything is so sluggish that I feel like beating my mouse frantically with an iron rod.
This is just not serious. You Linux fanboys will just reverse whatever criticism anyone throws at it. If I said Linux looks Unixy and it's a bad thing, you'd claim that it's Windows what looks more Unixy.

Are you sure you didn't install all the latest bells and whistles on an old pc, because you didn't know any better?
I installed and toned down KDE on an Athlon 64 Venice with 512 MB RAM and a suitable accelerator, is this an old computer to run X?

Who ever told you to compile shit if you don't want to?
Linux fags keep telling me

Ever heard of binary packages?
Yes, if only they were always available

Do you, by any chance, base your experience with Linux on some epenis-inspired fucking around with Gentoo or similar NerdCore stuff?
Never used Gentoo, nor tried to compile something just for some slick optimisation.

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