开发者

Help with reading memory, how do i read int and string?

开发者 https://www.devze.com 2023-02-12 19:20 出处:网络
Im trying to fool around with Windows\'s Minesweeper, getting how many bombs left and such. Got this up and working:

Im trying to fool around with Windows's Minesweeper, getting how many bombs left and such.

Got this up and working:

public static byte[] ReadByte开发者_如何转开发s(IntPtr memoryAddress, uint bytesToRead, out int bytesReaded)
{
    byte[] buffer = new byte[bytesToRead];

    IntPtr ptrBytesReaded;
    ReadProcessMemory(process, memoryAddress, buffer, bytesToRead, out ptrBytesReaded);

    bytesReaded = ptrBytesReaded.ToInt32();

    return buffer;
}

But I need some help, how do I read a int and a string? Guess i pass the size of a int to the function? what about string?

thanks :) }


I think you have read the Code Project article how to patch minesweeper from Arik Poznanski. Your code is copied from that article.

How to read a int is shown there. If you know the address of the string you can use the string constructor which takes a void * as argument when you use unsafe code. That is the easiest way.

But you should read the article completeley before asking questions which are already answered by the really good writeup.


To get int you have to read 4 bytes and then use BitConverter.ToInt32 Method.

For string it is more complicated, you have to read bytes one by one until you encounter byte with code 0.


You could finish reading the 4.8 star-rated CodeProject article that you've copied your code from, as per other's insights here. But:

The problem here is that you're reading completely raw memory. You'll have no idea whether the memory at a particular location will be an int or a string. The BytesToRead parameter is an implication that you already have to know (a priori) what type of data to expect at the particular memory address you're trying to read.

Your best bet might be trial-and-error on large chunks of data. Strings are fairly easy to identify this way but isolating ints may be very tough. You may have to try many runs of the game and your app will tweaking the game to see what changes. Good luck! You'll probably need to create some sort of viewer like this, as an example. You could actually use this utility help you get a foothold on some memory to read.

Note that the CodeProject code contains hard-coded, memory address values that the author had to discover in some way...

0

精彩评论

暂无评论...
验证码 换一张
取 消