[Help]C# How to convert memory value to string?

04/25/2010 10:41 shimo diaz#1
How to convert value to string :confused:
this is my code Is this code right or is it wrong?
thanks in advance!:handsdown:
note: I know that CloseHandle is missing :)
PHP Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace 
ReadMemory_function
{
    public 
partial class Form1 Form
    
{
        [
DllImport("kernel32.dll")]
        static 
extern IntPtr OpenProcess(uint dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandleint dwProcessId);

        [
DllImport("kernel32.dll"SetLastError truePreserveSig true)]
        [return: 
MarshalAs(UnmanagedType.Bool)]
        public static 
extern bool ReadProcessMemory(IntPtr hProcessIntPtr lpBaseAddress,
             
byte[] lpBufferUIntPtr nSizeout int lpNumberOfBytesRead);

        public 
Form1()
        {
            
InitializeComponent();
        }

        private 
void button1_Click(object senderEventArgs e)
        {
            
int PID Process.GetProcessesByName("calc")[0].Id;
            
IntPtr hprocess OpenProcess(0x0010falsePID);
            
byte[] value = new byte[4];
            
int num;
            
ReadProcessMemory(hprocess, (IntPtr)0x030000value, (UIntPtr)4out num);
        }
    }

05/04/2010 17:25 BEanErzzz#2
Quote:
Originally Posted by shimo diaz View Post
How to convert value to string :confused:
this is my code Is this code right or is it wrong?
thanks in advance!:handsdown:
note: I know that CloseHandle is missing :)
PHP Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace 
ReadMemory_function
{
    public 
partial class Form1 Form
    
{
        [
DllImport("kernel32.dll")]
        static 
extern IntPtr OpenProcess(uint dwDesiredAccess, [MarshalAs(UnmanagedType.Bool)] bool bInheritHandleint dwProcessId);

        [
DllImport("kernel32.dll"SetLastError truePreserveSig true)]
        [return: 
MarshalAs(UnmanagedType.Bool)]
        public static 
extern bool ReadProcessMemory(IntPtr hProcessIntPtr lpBaseAddress,
             
byte[] lpBufferUIntPtr nSizeout int lpNumberOfBytesRead);

        public 
Form1()
        {
            
InitializeComponent();
        }

        private 
void button1_Click(object senderEventArgs e)
        {
            
int PID Process.GetProcessesByName("calc")[0].Id;
            
IntPtr hprocess OpenProcess(0x0010falsePID);
            
byte[] value = new byte[4];
            
int num;
            
ReadProcessMemory(hprocess, (IntPtr)0x030000value, (UIntPtr)4out num);
        }
    }

To get the number you're retrieving as it's string representation "1234" or the string representation of the bytes "D2-04-00-00"?
05/04/2010 23:34 shimo diaz#3
Quote:
Originally Posted by BEanErzzz View Post
To get the number you're retrieving as it's string representation "1234" or the string representation of the bytes "D2-04-00-00"?
#Delete please
thanks for your concern I already found the answer.