บทที่หน่วย 1; อินเตอร์เฟสใช้ Windows, ข้อความ, sysutils, ตัวแปร, คลาส, กราฟิก, การควบคุม, รูปแบบ, กล่องโต้ตอบ, stdctrls; พิมพ์ tform1 = คลาส (tform) button1: tbutton; memo1: tmemo; button2: tbutton; ปุ่ม 3: tbutton; ขั้นตอน button1click (ผู้ส่ง: tobject); ขั้นตอน button2click (ผู้ส่ง: tobject); ขั้นตอน button3click (ผู้ส่ง: tobject); FORMDESTROY ขั้นตอน (ผู้ส่ง: TOBJECT); โพรซีเดอร์แบบฟอร์ม (ผู้ส่ง: tobject); ส่วนตัว {ประกาศส่วนตัว} ขั้นตอน showmsg (s: string); สาธารณะ {ประกาศสาธารณะ} สิ้นสุด; var form1: tform1; การใช้งาน {$ r *.dfm} ใช้ mlde32Unit; const despath = 'c:/program files/borland/delphi6/projects/adv apihook/test/vt.exe'; func2hook = 'freelibrary'; var // จะต้องเป็นตัวแปร ptrreal: ตัวชี้; CBSTOLEN: พระคาร์ดินัล; ntdllbase, ntdlllength: จำนวนเต็ม; P: ตัวชี้; h: dword; ขั้นตอน TFORM1.SHOWMSG (S: String); เริ่มต้น memo1.lines.add (s); จบ; ขั้นตอน tform1.button1click (ผู้ส่ง: tobject); ฉลาก fakecode, rtncode; var // si: startupinfo; // pi: process_information; OriginalBytes: Array [0..4] ของ Char; hookjmp: pchar; RTN: พระคาร์ดินัล; ไบต์: อาร์เรย์ [0..4] ของถ่าน; TMP: พระคาร์ดินัล; PEB, LDR, Flink: ตัวชี้; BS: DWORD; เริ่ม ptrreal: = nil; ntdllLength: = 0; ntdllbase: = getModuleHandle ('ntdll.dll'); ASM MOV EAX, FS: [$ 30] MOV PEB, EAX End; ldr: = ตัวชี้ (dword (ตัวชี้ (dword (peb) +12)^)); Flink: = pointer (dword (ตัวชี้ (dword (ldr) +12)^)); P: = Flink; ทำซ้ำ bs: = dword (ตัวชี้ (dword (p)+$ 18)^); ถ้า bs = ntdllbase แล้วเริ่ม ntdlllength: = 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 ('การเตรียม hook' + func2hook + '... '); ptrreal: = getProcaddress (getModuleHandle ('Kernel32.dll'), func2hook); ถ้าได้รับมอบหมาย (ptrreal) จากนั้น showmsg ('จริง' + func2hook + 'addr:' + inttohex (dword (ptrreal), 8)) อื่น ๆ เริ่ม showmsg ('addr:' + func2hook + 'ไม่สามารถอ่านได้!'); // resumethread (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 honked!'); สิ้นสุดอื่น ๆ เริ่ม showmsg (func2hook + 'ถูกตะขอ! ออก!'); // resumethread (pi.hthread); ออก; จบ; cbstolen: = 0; ในขณะที่ cbstolen <5 ทำ cbstolen: = cbstolen + lde32 (ตัวชี้ (dword (ptrreal) + cbstolen)); showmsg ('let' ขโมยครั้งแรก ' + inttoStr (cbstolen) +' ไบต์ :) '); showmsg ('แต่ทำให้มันเขียนได้ก่อน ... '); ถ้า virtualprotect (ptrreal, cbstolen, page_execute_readwrite, @tmp) จากนั้น showmsg ('make' + inttohex (dword (ptrreal), 8) + 'Writable ประสบความสำเร็จ! ), 8) + 'เขียนล้มเหลว! // resumethread (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 + 'ประสบความสำเร็จ! กลับมาทำงานอีกครั้ง!'); ในที่สุด Freemem (hookjmp); // resumethread (pi.hthread); จบ; ออก; fakecode: // ไม่มีสตริงจากที่นี่ใน asm int 3 end; ASM PUSH EAX Lea Eax, [ESP+4] MOV P, EAX POP EAX End; ถ้า dword (p^) - ntdllbase <ntdlllength จากนั้น asm pop p pop eax pop pop eax mov eax, 0 jmp p // push p // ret end; // messagebox (0, pchar (p), '', 0); rtncode: asm nop nop nop nop nop nop nop nop nop nop nop nop nop mov eax, ptrreal เพิ่ม eax, cbstolen jmp eax end; จบ; var ptr, PPP: ตัวชี้; ขั้นตอน TFORM1.Button2Click (ผู้ส่ง: TOBJECT); เริ่มต้น {ASM CALL PPP; จบ; ออก; } button3click (ไม่มี); PTR: = VirtualAlloc (NIL, 1024, MEM_COMMIT, PAGE_EXECUTE_READWRITE); หากไม่ได้รับมอบหมาย (PTR) ดังนั้น memo1.lines.add ('ข้อผิดพลาดร้ายแรง: VirtualAlloc ล้มเหลว!') MEMO1.LINES.ADD ('VirtualAlloc ประสบความสำเร็จ! ptr =' + inttoHex (DWORD (PTR), 8)); จบ; ขั้นตอน TFORM1.FormDestroy (ผู้ส่ง: TOBJECT); เริ่ม Button3Click (ไม่มี); unmapviewoffile (PPP); ภาพใกล้ชิด (H); จบ; ขั้นตอน tform1.button3click (ผู้ส่ง: tobject); เริ่มต้นถ้าได้รับมอบหมาย (PTR) แล้ว VirtualFree (PTR, 0, MEM_RELEASE); จบ; ขั้นตอน TFORM1.FormCreate (ผู้ส่ง: TOBJECT); เริ่มต้น h: = createFileMapping ($ ffffffff, nil, page_readwrite หรือ sec_commit, 0, 1, 'pe'); PPP: = MapViewOffile (H, file_map_all_access, 0,0,0); คำบรรยายภาพ: = inttoHex (DWORD (PPP), 8); ถ่าน (PPP^): = Chr ($ c3); จบ; จบ. ====== Unit1 里有很多垃圾代码, 因为这个防 hook 的程序只是一个副产品。有用代码写成 dll 注入其他进程就可以防 hook 了, 已经试过没问题。代码风格比较差, 不过不知道不过不知道不过不知道fakecode 部分放到单独过程中) 。如果你改好了希望能发给我一份。 mlde32unit 代码来自 29a 第七期, 作者忘记了, 不好意思。不好意思。不好意思。不好意思。