Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C#] Reading a value from memory address

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
aataqah
How do I cheat?
Reputation: 0

Joined: 29 Nov 2009
Posts: 3

PostPosted: Sun Nov 29, 2009 1:34 pm    Post subject: [C#] Reading a value from memory address Reply with quote

Hello!

I would like to make a program that reads a value from another application. What I want is to create a program that reads the current voltage from the UPS application PowerChute, so I can log it to a file (PowerChute does not have this function). Using cheat engine I have found the memory address of this value:

Process: 00000E68-PowerChute.exe
Address: 00A12320 (type: Double)

How can I achieve this? I have some knowledge about C# and C++ programming, but only for microprocessors. I am using visual C# and C++ express.

I have already searched the forum, and tried some things, but it does not compile. I am probably missing something in the header, but don't know what.

To conclude, I am asking for help to create a C# GUI application using windows forms that displays the value read from the memory address. How and where to start?
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Nov 29, 2009 2:08 pm    Post subject: Reply with quote

First, use System.Management.Process to get the pID if your process. You then need to add and use the pinvokes for OpenProcess() and ReadProcessMemory(). Use MSDN to get the arguments.
Back to top
View user's profile Send private message
aataqah
How do I cheat?
Reputation: 0

Joined: 29 Nov 2009
Posts: 3

PostPosted: Mon Nov 30, 2009 3:45 am    Post subject: Reply with quote

I read the links, but I don't know how to use any of it. On the 1. link I didn't find any function that gives me the PID of the process. Also, the other two I don't know how to use.

Can you be a little more specific please?


Like I said, my programming knowledge is very limited. I am an electrical engineer, not a software engineer Cool
Back to top
View user's profile Send private message
iPromise
Grandmaster Cheater
Reputation: -1

Joined: 27 Jun 2009
Posts: 529
Location: Canada

PostPosted: Mon Nov 30, 2009 6:30 pm    Post subject: Reply with quote

Example Code in C++:

Code:

HWND TARGET = FindWindowA(NULL, "PowerChute");
DWORD PID ;
GetWindowThreadProcessId(TARGET, &PID);
HANDLE HTARGET = OpenProcess(PROCESS_ALL_ACCESS, false, PID);
DWORD BUFFER:
WriteProcessMemory(HTARGET, (LPVOID) 0x00A12320, &BUF, 4, NULL);


Try to convert this to C#.
Back to top
View user's profile Send private message MSN Messenger
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Mon Nov 30, 2009 6:52 pm    Post subject: Reply with quote

iPromise wrote:
Example Code in C++:

Code:

HWND TARGET = FindWindowA(NULL, "PowerChute");
DWORD PID ;
GetWindowThreadProcessId(TARGET, &PID);
HANDLE HTARGET = OpenProcess(PROCESS_ALL_ACCESS, false, PID);
DWORD BUFFER:
WriteProcessMemory(HTARGET, (LPVOID) 0x00A12320, &BUF, 4, NULL);


Try to convert this to C#.


Code:
HANDLE hProcess = GetProcessHandleFromHwnd( FindWindow( NULL, _T("PowerChute") ) );
ReadProcessMemory( hProcess( hProcess, X, Y, nSize, NULL  ) );
CloseHandle( hProcess );
Back to top
View user's profile Send private message
aataqah
How do I cheat?
Reputation: 0

Joined: 29 Nov 2009
Posts: 3

PostPosted: Fri Dec 04, 2009 7:09 am    Post subject: Reply with quote

I tried, but I cannot get this thing to work.

Can someone be so nice and make a simple c++ console application that displays the requested value and post it here (with source)? Once I have a working code, that compiles without errors, I will work on that.

Thank you!
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Dec 04, 2009 9:16 am    Post subject: Reply with quote

Code:

[DllImport("Kernel32.Dll")]
public static extern IntPtr OpenProcess(DWORD dwDesiredAccess, bool bInheritance, DWORD dwProcessId);

[DllImport("Kernel32.Dll")]
public static extern bool ReadProcessMemory(IntPtr hProcess,IntPtr BaseAddress, out byte[] buffer, Int32 b_size, out Int32 dwBytesRead);

/* class implementation */
IntPtr hProc = IntPtr.Zero;
Int32 dwBytesRead, Value;
hProc = OpenProcess(0x0010 /* PROCESS_VM_READ access */, false,iPID); // iPID is your process id get it by your self using Process class
byte[] memory = new byte[6]; // can be more than 6 depends how many bytes you're interesting to read
ReadProcessMemory(hProc,(IntPtr)0xFFFFFFFF /* your address */, out memory, memory.Length,out dwBytesRead);
Value = BitConvert.ToInt32(memory);

haven't tested it but should do the job :]
BTW: It's C#
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites