[DllImport("Kernel32.dll")] public static extern uint VirtualQueryEx(IntPtr handle, IntPtr address, ref MEMORY_BASIC_INFORMATION info, int size);
unsafe public bool ReadProcessM(uint address, uint point_num, uint bytes_per_point, IntPtr result, ref uint point_num_read) { //detecting how many points we can read //detecting how many pages age commitied //reading them //truncating point_num if necessary point_num_read = 0; // here we must check if the process is available for debugging DTE dte = (DTE)Package.GetGlobalService(typeof(DTE)); EnvDTE.Debugger dbg = dte.Debugger; EnvDTE.Process current_process = dbg.CurrentProcess; if (current_process == null) { return(false); } int process_id = ((DTE)Package.GetGlobalService(typeof(DTE))).Debugger.CurrentProcess.ProcessID; IntPtr handle = OpenProcess(PROCESS_VM_READ | PROCESS_QUERY_INFORMATION, false, process_id); if (handle.ToInt32() == 0) { return(false); } uint variable_address = address; uint tmp = address / PAGE_SIZE; //avoiding optimisation uint base_address = tmp * PAGE_SIZE; IntPtr base_address_param = new IntPtr(base_address); MEMORY_BASIC_INFORMATION info = new MEMORY_BASIC_INFORMATION(); uint err = VirtualQueryEx(handle, base_address_param, ref info, sizeof(MEMORY_BASIC_INFORMATION)); if (err == 0) { return(false); } if (info.State != MEM_COMMIT) { return(false); } //calculating number of points commited uint region_size = info.RegionSize; uint variable_address_offset = variable_address - base_address; uint bytes_available = info.RegionSize - variable_address_offset; uint point_num_available = bytes_available / bytes_per_point; if (point_num > point_num_available) { point_num = point_num_available; } //reading available data uint bytes_requested = point_num * bytes_per_point; int result_size = 0x00; IntPtr result_size_param = new IntPtr(&result_size); IntPtr variable_address_param = new IntPtr(variable_address); bool r = ReadProcessMemory(handle, variable_address_param, result, bytes_requested, result_size_param); if (r == false) { return(false); } if (result_size != bytes_requested) { return(false); } point_num_read = point_num; CloseHandle(handle); return(true); }