memory reading double value as cheat engine in c#
I'm not a pro in code writing and C# programming. I wrote a simple app to read from processmemory using the ZeraPain script ReadProcessMemory(). Is working good with the 4 bytes and 8
bytes value. The other function of this App is that can read strings, but i really need to
read Double values and i cant find anything on the web. Can somebody HELP me with this?
here's a printscreen of the app
Here's the class (by ZERAPAIN)
================================
class Memory
{
[DllImport("kernel32.dll")]
static extern IntPtr OpenProcess(UInt32 dwDesiredAccess, Boolean bInheritHandle, UInt32
dwProcessId);
[DllImport("kernel32.dll")]
static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress,
byte[] lpBuffer, UIntPtr nSize, uint lpNumberOfBytesWritten);
IntPtr Handle;
public Memory(string sprocess)
{
try
{
Process[] Processes = Process.GetProcessesByName(sprocess);
Process nProcess = Processes[0];
Handle = OpenProcess(0x10, false, (uint)nProcess.Id);
}
catch
{
//do nothing
}
}
public string ReadString(uint pointer, Int32 bts)
{
byte[] bytes = new byte[bts];
ReadProcessMemory(Handle, (IntPtr)pointer, bytes, (UIntPtr)24, 0);
return Encoding.UTF8.GetString(bytes);
}
public int ReadPointer(uint pointer, Int32 bts)
{
byte[] bytes = new byte[bts];
ReadProcessMemory(Handle, (IntPtr)pointer, bytes, (UIntPtr)sizeof(int), 0);
return BitConverter.ToInt32(bytes, 0);
}
}
And here's the script
================================
private void timer1_Tick(object sender, EventArgs e)
{
try
{
Memory mem = new Memory(processnameTB.Text);
uint address = Convert.ToUInt32(AddressTB.Text, 16);
if (checkBox1.Checked == true)
{
try
{
int byt = Convert.ToInt32(bytesnumberTB.Text);
string str = mem.ReadString(address, byt);
stringvalue.Text = str;
}
catch
{
timer1.Enabled = false;
}
}
if (checkBox2.Checked == true)
{
try
{
int byt = Convert.ToInt32(bytesnumberTB.Text);
double pointer = mem.ReadPointer(address,byt);
pointervalue.Text = pointer.ToString();
}
catch
{
timer1.Enabled = false;
}
}
}
catch (Exception ex)
{
timer1.Enabled = false;
MessageBox.Show(ex.Message, "Error");
}
}
_____________________________________________________
If you have an array of bytes that represent the double, you can use BitConverter.ToDouble()
to convert those bytes to a double
The ToDouble method converts the bytes from index startIndex to startIndex + 7 to a
Double value. The order of bytes in the array must reflect the endianness of the computer
system's architecture; for more information, see the Remarks section of the BitConverter
class topic.

No comments:
Post a Comment
Note: only a member of this blog may post a comment.