我不是代码编写和C#编程的专家。 我写了一个简单的应用程序,使用ZeraPain脚本ReadProcessMemory()从进程内存中读取。 与4字节和8字节值一起工作正常。 这个应用程序的另一个功能是可以读取字符串,但我真的需要阅读Double值,我无法在网上找到任何东西。 有人可以用这个来帮助我吗? 这是应用程序的打印屏幕
这是班级(通过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);
}
}
这是脚本
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");
}
}
答案 0 :(得分:1)
如果你有一个表示double的字节数组,你可以使用BitConverter.ToDouble()将这些字节转换为double
ToDouble方法将索引startIndex的字节转换为startIndex + 7为Double值。数组中的字节顺序必须反映计算机系统架构的字节顺序;有关更多信息,请参阅BitConverter类主题的“备注”部分。
http://msdn.microsoft.com/en-us/library/system.bitconverter.todouble(v=vs.110).aspx