단위 유닛 1; 인터페이스는 Windows, 메시지, sysutils, 변형, 클래스, 그래픽, 컨트롤, 양식, 대화 상자, stdctrls를 사용합니다. type tform1 = class (tform) Button1 : tbutton; 메모 1 : tmemo; 버튼 2 : tbutton; 버튼 3 : tbutton; 절차 버튼 1Click (sender : tobject); 절차 button2click (sender : tobject); 절차 버튼 3Click (sender : tobject); 절차 formdestroy (sender : tobject); 프로 시저 Formcreate (sender : tobject); 개인 {개인 선언} 절차 showmsg (s : 문자열); 공개 {공개 선언} 종료; var form1 : tform1; 구현 {$ r *.dfm} 사용 mlde32unit을 사용합니다. const despath = 'c :/program files/borland/delphi6/projects/adv apihook/test/vt.exe'; func2hook = 'freelibrary'; var //는 Globle 변수 ptrreal : 포인터 여야합니다. CBSTOLEN : 추기경; ntdllbase, ntdllllength : 정수; P : 포인터; H : dword; 절차 tform1.showmsg (s : 문자열); 시작 memo1.lines.add (s); 끝; 절차 tform1.Button1click (sender : tobject); 레이블 Fakecode, rtncode; var // si : startupinfo; // pi : process_information; OriginalBytes : char의 배열 [0..4]; hookjmp : pchar; RTN : 추기경; 바이트 : char의 배열 [0..4]; TMP : 추기경; PEB, LDR, FLINK : 포인터; BS : dword; ptrreal을 시작하십시오 : = nil; ntdllllength : = 0; ntdllbase : = getModuleHandle ( 'ntdll.dll'); ASM Mov EAX, FS : [$ 30] Mov Peb, EAX End; ldr : = 포인터 (dword (pointer (dword (dword) +12))); flink : = 포인터 (dword (포인터 (dword (ldr) +12)^)); P : = 플링크; 반복 bs : = dword (포인터 (dword (p)+$ 18)^); bs = ntdllbase 인 경우 ntdllllength : = dword (포인터 (dword (p)+$ 20)^); 부서지다; 끝; p : = 포인터 (dword (p^)); dword (flink) = dword (p^)까지; ntdlllength = 0이면 showmsg ( 'ntdll.dll 이미지 크기를 얻을 수 없습니다!'); {showmsg ( '정지 된 프로세스 생성 ...'); Zeromemory (@si, sizeof (startupinfo)); si.cb : = sizeof (startupinfo); CreateProcess (Despath, nil, nil, nil, false, create_suspended, nil, nil, si, pi); } showmsg ( '훅 준비' + func2hook + '...'); ptrreal : = getProcadDress (getModuleHandle ( 'kernel32.dll'), func2hook); 할당 된 경우 (ptrreal) showmsg ( 'real' + func2hook + 'addr :' + inttoHex (dword (ptrReal), 8)) 그렇지 않으면 showmsg ( 'addr :' + func2hook + '가 읽을 수 없습니다! 출구!'); // remethread (pi.hthread); 출구; 끝; readProcessMemory (GetCurrentProcess, PtrReal, @Bytes, 5, RTN); // readProcessMemory (pi.hprocess, ptrreal, @bytes, 5, rtn); 바이트 [0] <> chr ($ e9) 인 경우 copymemory (@originalBytes, @bytes, 5)를 시작하십시오. showmsg (func2hook + 'havn''t reted!'); END ELSE BEGIN SHOWMSG (FUNC2HOOK + '가 푹 빠졌습니다! 출구!'); // remethread (pi.hthread); 출구; 끝; cbstolen : = 0; cbstolen <5는 cbstolen을 수행하는 동안 : = cbstolen + lde32 (포인터 (dword (ptrreal) + cbstolen)); showmsg ( '첫 번째' + inttostr (cbstolen) + 'bytes :)'); showmsg ( '하지만 먼저 쓰기를 먼저 쓸 수있게 해줍니다 ...'); virtualProtect (ptrreal, cbstolen, page_execute_readwrite, @tmp) 그런 다음 showmsg ( 'make' + inttoHex (dword (ptrReal), 8) + 'Writable Succeed!') else showmsg ( 'hoops! make' + inttohex (ptrreal ), 8) + '쓰기 실패!'); // remethread (pi.hthread); 출구; 끝; showmsg ( '조립 JMP 코드 & hook' + func2hook + '...'); getmem (hookjmp, 5); hookjmp [0] : = chr ($ e9); ASM PUSH EAX LEA EAX, FAKECODE MOV TMP, EAX POP EAX END; tmp : = tmp -dword (ptrreal) -5; copymemory (@hookjmp [1], @tmp, 4); ASM PUSH EAX LEA EAX, RTNCODE MOV TMP, EAX POP EAX END; VirtualProtect (포인터 (TMP), CBSTOLEN, PAGE_EXECUTE_READWRITE, @RTN); copymemory (포인터 (TMP), PtrReal, CBStolen); WriteProcessMemory (getCurrentProcess, ptrreal, hookjmp, 5, rtn); // WriteProcessMemory (pi.hprocess, ptrreal, hookjmp, 5, rtn); showmsg ( 'hook' + func2hook + '성공! 이력서 스레드!'); 마지막으로 프리 메미 (hookjmp); // remethread (pi.hthread); 끝; 출구; fakecode : // 여기에서 asm int 3 끝에서 문자열 없음; ASM PUSH EAX LEA EAX, [ESP+4] MOV P, EAX POP EAX END; if dword (p^) -ntdllbase <ntdlllllength the a asm pop pop eax pop eax pop eax mov eax, 0 jmp p // 푸시 p // ret end; // messagebox (0, pchar (p), '', 0); RTNCODE : ASM NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP MOV EAX, PTRREAL ADD EAX, CBSTOLEN JMP EAX END; 끝; VAR PTR, PPP : 포인터; 절차 tform1.Button2Click (sender : tobject); 시작 {ASM Call PPP; 끝; 출구; } button3click (nil); ptr : = virtualAlloc (nil, 1024, mem_commit, page_execute_readwrite); 할당되지 않으면 (ptr) memo1.lines.add ( '치명적인 오류 : virtualalloc 실패!') else memo1.lines.add ( 'virtualalloc succeate! ptr =' + inttohex (ptr), 8); 끝; 절차 tform1.formdestroy (sender : tobject); 시작 button3click (nil); Unmapviewoffile (PPP); CloseHandle (H); 끝; 절차 tform1.Button3Click (sender : tobject); 할당 된 경우 시작 (ptr) 그런 다음 virtualfree (ptr, 0, mem_release); 끝; 절차 tform1. formcreate (sender : tobject); 시작 H : = CreateEfilemapping ($ ffffffff, nil, page_readwrite 또는 sec_commit, 0, 1, 'pe'); ppp : = mapViewoffile (h, file_map_all_access, 0,0,0); 캡션 : = inttoHex (dword (ppp), 8); char (ppp^) : = chr ($ c3); 끝; 끝. ======= Unit1 里有很多垃圾代码 里有很多垃圾代码, 因为这个防 hook 的程序只是一个副产品。有用代码写成 dll 注入其他进程就可以防 hook 了, 已经试过没问题。代码风格比较差, 不过不知道怎么改的更好 ak + (如将 如将 fakecode 部分放到单独过程中) 。如果你改好了希望能发给我一份。 mlde32Unit 代码来自 29a 第七期, 作者忘记了, 不好意思。 不好意思。