annotate src/dbgprocess.d @ 1:4a9dcbd9e54f

-files of 0.13 beta -fixes so that it now compiles with the current dmd version
author marton@basel.hu
date Tue, 05 Apr 2011 20:44:01 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
1 /* Ddbg - Win32 Debugger for the D programming language
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
2 * Copyright (c) 2007 Jascha Wetzel
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
3 * All rights reserved. See LICENSE.TXT for details.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
4 */
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
5 module dbgprocess;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
6
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
7 import win32.winbase;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
8 import win32.windef;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
9
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
10 import std.string;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
11 import std.c.string;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
12
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
13 import util;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
14 import breakpoint;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
15 import dbgthread;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
16 import callstack;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
17 import codeview.coff;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
18
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
19 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
20
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
21 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
22 class DbgProcess
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
23 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
24 public:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
25 HANDLE process_handle;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
26 uint processId,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
27 mainThreadId;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
28 DLL[] loaded_dlls;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
29
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
30 DbgThread[uint] threads;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
31
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
32 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
33
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
34 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
35 DLL loadDLL(LOAD_DLL_DEBUG_INFO* lddi)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
36 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
37 DLL dll = new DLL;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
38 dll.filehandle = lddi.hFile;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
39 dll.base = cast(uint)lddi.lpBaseOfDll;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
40 dll.debug_info_offset = lddi.dwDebugInfoFileOffset;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
41 dll.debug_info_size = lddi.nDebugInfoSize;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
42 loaded_dlls ~= dll;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
43
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
44 size_t filesize = GetFileSize(lddi.hFile, null);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
45 if ( filesize == 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
46 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
47 debug DbgIO.println("Couldn't get DLL %s image size: %s", dll.image.name, lastError);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
48 return dll;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
49 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
50
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
51 ubyte[] buf;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
52 buf.length = filesize;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
53 if ( !ReadFile(lddi.hFile, cast(void*)buf.ptr, buf.length, &filesize, null) || filesize != buf.length )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
54 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
55 debug DbgIO.println("Couldn't read DLL image for %s: %s", dll.image.name, lastError);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
56 return dll;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
57 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
58 dll.image = new COFFImage;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
59 dll.image.load(buf);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
60
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
61 return dll;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
62 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
63
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
64 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
65
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
66 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
67 DLL findDLL(size_t vaddress)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
68 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
69 foreach ( dll; loaded_dlls )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
70 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
71 if ( vaddress < dll.base )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
72 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
73 assert( dll !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
74 assert( dll.image !is null );
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
75 uint size_image = dll.image.imageSize;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
76 if ( vaddress-dll.base > size_image )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
77 continue;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
78 return dll;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
79 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
80 return null;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
81 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
82
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
83 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
84 Loads the given thread's stack and the index of the current frame pointer (ebp).
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
85 Returns: Arrays of uints.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
86 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
87 CallStack loadStack(DbgThread thread)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
88 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
89 CONTEXT ctx;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
90 if ( !thread.getContext(ctx, CONTEXT_CONTROL) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
91 throw new Exception("Couldn't get thread's context");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
92
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
93 CallStack stack = new CallStack(thread.stack_base, ctx.Esp, ctx.Ebp);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
94 uint read = readProcessMemory(ctx.Esp, stack.data.ptr, stack.data.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
95 if ( read == 0 )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
96 throw new Exception("Couldn't read thread's stack memory");
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
97 else if ( read < stack.data.length )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
98 stack.data.length = read;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
99 return stack;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
100 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
101
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
102 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
103 Read from debuggee's memory.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
104 Returns: #bytes read
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
105 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
106 size_t readProcessMemory(size_t address, void* data, size_t size, bool changeProtect=false)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
107 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
108 uint oldprot;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
109 if( changeProtect && !VirtualProtectEx(process_handle, cast(void*)address, size, PAGE_READONLY, &oldprot) ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
110 debug DbgIO.println("readProcessMemory(): Failed to obtain read access to page at 0x%08x: %s", address, lastError);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
111 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
112 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
113
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
114 size_t numbytes;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
115 if( !ReadProcessMemory(process_handle, cast(void*)address, data, size, &numbytes) ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
116 debug DbgIO.println("ReadProcessMemory() returned false reading address 0x%08x: %s", address, lastError);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
117 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
118 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
119 if ( numbytes != size ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
120 debug DbgIO.println("readProcessMemory(): Failed to read at address 0x%08x: %s", address, lastError);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
121 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
122
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
123 if( changeProtect && !VirtualProtectEx(process_handle, cast(void*)address, size, oldprot, &oldprot) ) {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
124 DbgIO.println("writeProcessMemory(): Failed to restore access to page at 0x%08x: %s", address, lastError);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
125 return 0;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
126 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
127
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
128 return numbytes;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
129 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
130
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
131 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
132 Write to debuggee's memory.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
133 Returns success.
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
134 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
135 size_t writeProcessMemory(size_t address, void* data, size_t size)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
136 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
137 uint oldprot;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
138
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
139 if( !VirtualProtectEx(process_handle, cast(void*)address, size, PAGE_EXECUTE_READWRITE, &oldprot) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
140 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
141 DbgIO.println("writeProcessMemory(): Failed to obtain write access to page at 0x%08x: %s", address, lastError);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
142 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
143 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
144
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
145 size_t numbytes;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
146 if( !WriteProcessMemory(process_handle, cast(void*)address, data, size, &numbytes) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
147 DbgIO.println("writeProcessMemory(): Failed to write byte at 0x%08x: %s", address, lastError);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
148
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
149 if( !VirtualProtectEx(process_handle, cast(void*)address, size, oldprot, &oldprot) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
150 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
151 DbgIO.println("writeProcessMemory(): Failed to restore access to page at 0x%08x: %s", address, lastError);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
152 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
153 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
154
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
155 if ( !FlushInstructionCache(process_handle, cast(void*)address, numbytes) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
156 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
157 DbgIO.println("writeProcessMemory(): FlushInstructionCache failed for 0x%08x: %s", address, lastError());
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
158 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
159 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
160
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
161 return numbytes;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
162 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
163
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
164 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
165
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
166 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
167 ClassInfo getClassInfo(size_t obj_ptr)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
168 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
169 uint vtbl,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
170 ci_ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
171 readProcessMemory(obj_ptr, &vtbl, size_t.sizeof);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
172 readProcessMemory(vtbl, &ci_ptr, size_t.sizeof);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
173 ubyte[] data;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
174 data.length = ClassInfo.classinfo.init.length;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
175 readProcessMemory(ci_ptr, data.ptr, data.length);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
176 return cast(ClassInfo)data.ptr;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
177 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
178
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
179 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
180 simple check for invalidity of a memory block
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
181 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
182 const size_t MEMCHECK_MIN = 0x1000;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
183 bool isInvalidMem(size_t ptr, size_t len)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
184 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
185 uint tmp;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
186 if ( uint.sizeof != readProcessMemory(ptr, &tmp, uint.sizeof)
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
187 || uint.sizeof != readProcessMemory(ptr+len-uint.sizeof, &tmp, uint.sizeof) )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
188 return true;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
189 return false;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
190 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
191
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
192 /**********************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
193
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
194 **********************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
195 MEMORY_BASIC_INFORMATION[] walkMemory()
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
196 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
197 SYSTEM_INFO si;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
198 MEMORY_BASIC_INFORMATION[] mbis;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
199 GetSystemInfo(&si);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
200 for ( void* ptr = si.lpMinimumApplicationAddress; ptr < si.lpMaximumApplicationAddress; )
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
201 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
202 mbis.length = mbis.length + 1;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
203 VirtualQueryEx(process_handle, ptr, &mbis[$-1], MEMORY_BASIC_INFORMATION.sizeof);
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
204 ptr = mbis[$-1].BaseAddress + mbis[$-1].RegionSize;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
205 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
206 return mbis;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
207 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
208 }
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
209
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
210 /**************************************************************************************************
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
211
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
212 **************************************************************************************************/
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
213 class DLL
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
214 {
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
215 public:
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
216 HANDLE filehandle;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
217 uint base,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
218 debug_info_offset,
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
219 debug_info_size;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
220 COFFImage image;
4a9dcbd9e54f -files of 0.13 beta
marton@basel.hu
parents:
diff changeset
221 }