[Help]C# ReadMemory Function

04/21/2010 10:59 shimo diaz#1
Hi!
I am a newbie and trying to learn the C# ReadProcessMemory function!
As a training I am trying to read the HP value in "Conquer Online" so please tell me is this code right or wrong and will it cause me problems?
note: this is a console application
the program should read the HP address then it shows the value of the address!
PHP Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Diagnostics;


namespace 
ConsoleApplication1
{
    class 
Program
    
{
        [
DllImport("kernel32.dll")]
        public static 
extern int OpenProcess(
        
int dwDesiredAccess,
        
bool bInheritHandle,
        
int dwProcessId
        
);
        [
DllImport("kernel32.dll"EntryPoint "CloseHandle")]
        public static 
extern int CloseHandle(
        
int hObject
        
);
        [
DllImport("kernel32.dll")]
        public static 
extern Int32 ReadProcessMemory(
        
IntPtr hProcess,
        
IntPtr lpBaseAddress,
        
byte[] buffer,
        
int size,
        
out int lpNumberOfBytesRead
        
);
        static 
void Main(string[] args)
        {
            
int PID;
            
PID Process.GetProcessesByName("Conquer")[0].Id;
            
int hprocess OpenProcess(0x0010falsePID);
            
int num;
            
byte[] buffer = new byte[6];
            
ReadProcessMemory((IntPtr)hprocess, (IntPtr)0xE72E40buffer4out num);
            
CloseHandle(hprocess);
            
string x Encoding.Default.GetString(buffer);
            
Console.WriteLine(x);
        }
    }

If you don't want to answer just choose from the poll :p
04/21/2010 11:37 I3iLLiG#2
[Only registered and activated users can see links. Click Here To Register...]