Sign in to follow this  

[.net] C# reading and writing memory for game trainer

This topic is 4085 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm interested in creating a small trainer for a single player game I have and want to know how to read/write memory with C# given a specific memory address. I found the memory addresses which hold the score (int '004F19EC') and player x position (float '01150630') and want to use them to produce variables in C# to track them and manipulate them. I couldn't find much info on how to do this. It seems I use the Marshal class but I'm having trouble figuring it out.

Share this post


Link to post
Share on other sites
Wrap an unmanaged pointer in a class that sets its address at runtime, and then changes the pointed value. Make sure to mention that your program may only be used if its usage is compatible with the EULA of the game.

Share this post


Link to post
Share on other sites
you might be able to use unsafe code to do this... since in unsafe code you can use pointers like you would in C++. I don't know if that would work though.

Share this post


Link to post
Share on other sites
I think the first question is: is this the right solution to your problem? C# is kind of designed as a high-level language that doesn't need to know about memory addresses and suchlike. Are you trying to 'poke' memory values in another application that's written in a native language? (If your game, i.e. 'other application', is written in .Net also, you can change the values more cleanly by using Reflection.)

That said, if you're sure that the question you asked is actually what you want to do, I think unsafe code is the answer, which allows you to effectively write C++ code. I don't know if Windows will let you modify values within another app's memory space though.

Oh, and if this single player game you mention isn't yours, and you don't have consent of the owner, you are probably violating its license agreement by reverse engineering it (finding the memory locations of game variables could be construed as such) and almost certainly by modifying values while it is running.

Share this post


Link to post
Share on other sites
The thing about what you're trying to do is that that memory address will never be the same whenever you start up the program again. Taking that into consideration, making a trainer to change memory values that arn't always in the memory location you want them to be seems a bit unpractical.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Bob Janova
I think the first question is: is this the right solution to your problem? C# is kind of designed as a high-level language that doesn't need to know about memory addresses and suchlike. Are you trying to 'poke' memory values in another application that's written in a native language? (If your game, i.e. 'other application', is written in .Net also, you can change the values more cleanly by using Reflection.)

That said, if you're sure that the question you asked is actually what you want to do, I think unsafe code is the answer, which allows you to effectively write C++ code. I don't know if Windows will let you modify values within another app's memory space though.

Oh, and if this single player game you mention isn't yours, and you don't have consent of the owner, you are probably violating its license agreement by reverse engineering it (finding the memory locations of game variables could be construed as such) and almost certainly by modifying values while it is running.


You obviously have no idea about C# at all.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Quote:
Original post by Bob Janova
...


You obviously have no idea about C# at all.


Was that really necessary? This is why anonymous posting needs to go.

On topic... Rob Loach is correct, you can't count on the addresses to be static, even if those addresses are relative to the program memory space. But I'd wager if you can get a starting point in memory you could just use unsafe code to access the values, provided those values are fixed in memory space. And I'd also have to agree that C# really isn't the best tool for this kind of work, unless of couse you're just trying to experiment and see what you can do.

Share this post


Link to post
Share on other sites
The debugger that I wrote uses a C++/CLI DLL for about a dozen calls into Win32 code and C# for everything else. You don't need 'unsafe' for anything.

DebugActiveProcess, DebugSetProcessKillOnExit, VirtualProtect, VirtualQuery, ReadProcessMemory, WriteProcessMemory are the main functions you want. Have the C++ side convert between C-style byte arrays into .Net byte arrays and you're done with worrying about low-level stuff.

004F19EC is static data, 01150630 is heap data (and will probably move depending on order of allocations in the game).

Share this post


Link to post
Share on other sites

This topic is 4085 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this