473,395 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Changing a memory value.

Spippo
15
Hi all,

I'm trying to create a trainer for a flash game.
I have an AxShockwaveFlash component to play the flash game in a windows form.
With an other program (cheat engine) I found the memory place of the money-value in the game.
How can I change this value in C# .NET? When I click a button for example.

Thanks
Feb 4 '08 #1
8 1448
Plater
7,872 Expert 4TB
You will have to use some unsafe code to do it.
Possible even create an unmanaged DLL that contains methods for doing that.
Feb 4 '08 #2
Spippo
15
Yes, I already thought it would be unsave. Writing directly into a programs memory, but any idea how to do this?
Feb 4 '08 #3
Plater
7,872 Expert 4TB
Honestly, I recomend using an unmanged DLL to do it. Less messy then trying to do unsafe stuff.
Create a function that say takes in two integers. One integer will be an address, one will be the value to set it to. Your unmanaged function would set the memory to be that value.
That way your C# just needs to know the memory location and the value.
Feb 4 '08 #4
Spippo
15
OK, I found something that works for writing into the memory:

To use the C/C++ functions I called these parts:
Expand|Select|Wrap|Line Numbers
  1. [DllImport("kernel32.dll")]
  2. public static extern Int32 CloseHandle(IntPtr hObject);
  3. [DllImport("kernel32.dll")]
  4. public static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, Int32 bInheritHandle, UInt32 dwProcessId);
  5. [DllImport("kernel32.dll")]
  6. public static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, uint[] lpBuffer, UInt32 nSize, IntPtr lpNumberOfBytesWritten);
  7. [DllImport("kernel32.dll")]
  8. public static extern Int32 ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [In, Out] byte[] buffer, UInt32 size, out IntPtr lpNumberOfBytesRead);
And I used them as followed:
Expand|Select|Wrap|Line Numbers
  1. Process proc = Process.GetCurrentProcess();
  2. IntPtr procHandle = OpenProcess(0x1F0FFF, 0, (UInt32)proc.Id);
  3. WriteProcessMemory(procHandle, (IntPtr)0x038C3148, new uint[] { 0x08 }, 4, (IntPtr)0);
  4. byte[] b = null;
  5. IntPtr i;
  6. if((ReadProcessMemory(procHandle, (IntPtr)0x038C3148, b, 4, out i) != 0))
  7.            MessageBox.Show(b.ToString());
The writing works (because the money value changes), but I don't get a messagebox, so the reading doesn't work. What am I doing wrong?
To 0x1F0FFF parameter to open the handle is "enables all possible access rights to the process specified by the Process ID."
Feb 5 '08 #5
Plater
7,872 Expert 4TB
The return value is the value it is reading from the memory address right?
And the out variable tells you how many bytes it's reading, is it reading any bytes?
Feb 5 '08 #6
Spippo
15
no, the variable 'i' is always 0
Feb 5 '08 #7
Plater
7,872 Expert 4TB
It might have something to do with how you initialized b. Seems like b is supposed to return the data read?
Try setting b to an array that has enough bytes to read, then see if i changes?
Feb 5 '08 #8
Spippo
15
Nope, still doesn't return anything and i stays 0
Feb 5 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Daniel | last post by:
how to make two references to one string that stay refered to the same string reguardless of the changing value in the string?
3
by: Jeremy Ames | last post by:
I have a form that contains two hidden values, among other controls. I was wondering, if I change these values in server script and immediately do a server.transfer, do these values get updated...
4
by: Siah | last post by:
Hi, I wanted to dynamically update pieces of my page in the following fashion. Look at the following html code: <span id='person_23_name'> Mike </span> <span id='person_28_name'> Siah </span>...
4
by: andychambers2002 | last post by:
I'm working on a "TempFile" class that stores the data in memory until it gets larger than a specified threshold (as per PEP 42). Whilst trying to implement it, I've come across some strange...
3
by: Rob Prins | last post by:
{ This is probably a non-environment-specific problem buried in an environment-specific context; thus accepted. -mod } L.S. For a couple of days I've been trying to write a small Windows...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.