Click here to Skip to main content
15,860,844 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm not a pro in code writing and C# programming. I wrote a simple app to read from process memory 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
http://i.stack.imgur.com/q0QTh.jpg[^]
p.s. Excuse my English

Here's the class (by ZERAPAIN) - with some editing

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");
        }
    }
Posted
Comments
BillWoodruff 16-Oct-14 15:42pm    
Have you experimented with BitConvert.ToDouble ? Why not ask Zerapain a question on the forum where he posted his code ?
Sergey Alexandrovich Kryukov 16-Oct-14 16:12pm    
Why doing all that, I wonder?
—SA
EdisonMecaj 17-Oct-14 13:45pm    
I need it to get some data from a monitoring application at Work, and then i have realtime data that will be calculated and written to an excel file for reporting.
Just a Home Made Query... :P

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900