下面一个你试试。这种问题在google上的newsgroup搜也许能找到!<br>#define WIN32_NO_STATUS<br>#include <windows.h><br>#undef WIN32_NO_STATUS<br><br>namespace NT {<br> extern "C" {<br><br>#pragma warning(disable: 4005) // macro redefinition<br>#include <ntddk.h><br>#pragma warning(default: 4005)<br><br> }<br>}<br>using NT::NTSTATUS;<br><br>typedef struct _DEBUG_CONTROL {<br> ULONG L0 : 1;<br> ULONG G0 : 1;<br> ULONG L1 : 1;<br> ULONG G1 : 1;<br> ULONG L2 : 1;<br> ULONG G2 : 1;<br> ULONG L3 : 1;<br> ULONG G3 : 1;<br> ULONG LE : 1;<br> ULONG GE : 1;<br> ULONG : 3;<br> ULONG GD : 1;<br> ULONG : 2;<br> ULONG RWE0 : 2;<br> ULONG LEN0 : 2;<br> ULONG RWE1 : 2;<br> ULONG LEN1 : 2;<br> ULONG RWE2 : 2;<br> ULONG LEN2 : 2;<br> ULONG RWE3 : 2;<br> ULONG LEN3 : 2;<br>} DEBUG_CONTROL, *PDEBUG_CONTROL;<br><br><br>VOID preppatch()<br>{<br> CONTEXT context = {CONTEXT_DEBUG_REGISTERS};<br><br> PDEBUG_CONTROL dr7 = PDEBUG_CONTROL(&context.Dr7);<br><br> context.Dr0 = ULONG(GetProcAddress(GetModuleHandle("ntdll.dll"),<br>"ZwCreateThread"));<br><br> dr7->L0 = 1, dr7->RWE0 = 0, dr7->LEN0 = 0;<br><br> SetThreadContext(GetCurrentThread(), &context);<br>}<br><br>LONG patch(PEXCEPTION_POINTERS ep)<br>{<br> if (ep->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP) {<br><br> HANDLE hProcess = PHANDLE(ep->ContextRecord->Esp)[4];<br><br> PCONTEXT context = ((PCONTEXT*)(ep->ContextRecord->Esp))[6];<br><br> NT:
ROCESS_BASIC_INFORMATION pbi;<br><br> NT::NtQueryInformationProcess(hProcess, NT:
rocessBasicInformation,<br>&pbi, sizeof pbi, 0);<br><br> PVOID x; ReadProcessMemory(hProcess, PCHAR(pbi.PebBaseAddress) + 8,<br>&x, sizeof x, 0);<br><br> NT::ZwUnmapViewOfSection(hProcess, x);<br><br> HRSRC hRsrc = FindResource(0, "Image", "EXE");<br><br> HGLOBAL hGlobal = LoadResource(0, hRsrc);<br><br> PVOID p = LockResource(hGlobal);<br><br> PIMAGE_NT_HEADERS nt = PIMAGE_NT_HEADERS(PCHAR(p) +<br>PIMAGE_DOS_HEADER(p)->e_lfanew);<br><br> PVOID q = VirtualAllocEx(hProcess,<br> PVOID(nt->OptionalHeader.ImageBase),<br> nt->OptionalHeader.SizeOfImage,<br> MEM_RESERVE | MEM_COMMIT,<br>PAGE_EXECUTE_READWRITE);<br><br> WriteProcessMemory(hProcess, PCHAR(q), PCHAR(p), 0x1000, 0);<br><br> PIMAGE_SECTION_HEADER sect = IMAGE_FIRST_SECTION(nt);<br><br> for (ULONG i = 0; i < nt->FileHeader.NumberOfSections; i++)<br><br> WriteProcessMemory(hProcess,<br> PCHAR(q) + sect
.VirtualAddress,<br> PCHAR(p) + sect.PointerToRawData,<br> sect.SizeOfRawData, 0);<br><br> WriteProcessMemory(hProcess, PCHAR(pbi.PebBaseAddress) + 8, &q,<br>sizeof q, 0);<br><br> context->Eax = ULONG(q) + nt->OptionalHeader.AddressOfEntryPoint;<br><br> ep->ContextRecord->Dr7 = 0;<br><br> return EXCEPTION_CONTINUE_EXECUTION;<br> }<br><br> return EXCEPTION_CONTINUE_SEARCH;<br>}<br><br>int main(int argc, char *argv[])<br>{<br> PROCESS_INFORMATION pi;<br> STARTUPINFO si = {sizeof si};<br><br> __try {<br> preppatch();<br><br> CreateProcess(0, "Explorer", 0, 0, FALSE, 0, 0, 0, &si, &pi);<br> }<br> __except (patch(GetExceptionInformation())) {}<br><br> return 0;<br>}<br>