MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / SetBreakpoint

Function SetBreakpoint

emmy_tool/src/windows/utility.cpp:126–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

124
125
126void SetBreakpoint(HANDLE hProcess, LPVOID entryPoint, bool set, BYTE *data) {
127 DWORD protection;
128
129 // Give ourself write access to the region.
130 if (VirtualProtectEx(hProcess, entryPoint, 1, PAGE_EXECUTE_READWRITE, &protection)) {
131 BYTE buffer[1];
132
133 if (set) {
134 SIZE_T numBytesRead;
135 ReadProcessMemory(hProcess, entryPoint, data, 1, &numBytesRead);
136
137 // Write the int 3 instruction.
138 buffer[0] = 0xCC;
139 } else {
140 // Restore the original byte.
141 buffer[0] = data[0];
142 }
143
144 SIZE_T numBytesWritten;
145 WriteProcessMemory(hProcess, entryPoint, buffer, 1, &numBytesWritten);
146
147 // Restore the original protections.
148 VirtualProtectEx(hProcess, entryPoint, 1, protection, &protection);
149
150 // Flush the cache so we know that our new code gets executed.
151 FlushInstructionCache(hProcess, entryPoint, 1);
152 }
153}
154
155enum MessageType {
156 MessageType_Info = 0,

Callers 1

LaunchMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected