| 下载本节例子程序和源代码 (1.80 KB) |
| //=========================================================== // File: TIB.H // Author: Matt Pietrek // From: Microsoft Systems Journal "Under the Hood", May 1996 //=========================================================== #pragma pack(1) typedef struct _EXCEPTION_REGISTRATION_RECORD { struct _EXCEPTION_REGISTRATION_RECORD * pNext; FARPROC pfnHandler; } EXCEPTION_REGISTRATION_RECORD, *PEXCEPTION_REGISTRATION_RECORD; typedef struct _TIB { PEXCEPTION_REGISTRATION_RECORD pvExcept; // 00h Head of exception record list PVOID pvStackUserTop; // 04h Top of user stack PVOID pvStackUserBase; // 08h Base of user stack union // 0Ch (NT/Win95 differences) { struct // Win95 fields { WORD pvTDB; // 0Ch TDB WORD pvThunkSS; // 0Eh SS selector used for thunking to 16 bits DWORD unknown1; // 10h } WIN95; struct // WinNT fields { PVOID SubSystemTib; // 0Ch ULONG FiberData; // 10h } WINNT; } TIB_UNION1; PVOID pvArbitrary; // 14h Available for application use struct _tib *ptibSelf; // 18h Linear address of TIB structure union // 1Ch (NT/Win95 differences) { struct // Win95 fields { WORD TIBFlags; // 1Ch WORD Win16MutexCount; // 1Eh DWORD DebugContext; // 20h DWORD pCurrentPriority; // 24h DWORD pvQueue; // 28h Message Queue selector } WIN95; struct // WinNT fields { DWORD unknown1; // 1Ch DWORD processID; // 20h DWORD threadID; // 24h DWORD unknown2; // 28h } WINNT; } TIB_UNION2; PVOID* pvTLSArray; // 2Ch Thread Local Storage array union // 30h (NT/Win95 differences) { struct // Win95 fields { PVOID* pProcess; // 30h Pointer to owning process database } WIN95; } TIB_UNION3; } TIB, *PTIB; #pragma pack() |
| push offset _SEH_Handler push fs:[0] mov fs:[0], esp |
| PEXCEPTION_REGISTRATION_RECORD pvExcept; // 00h Head of exception record list |
| struct _tib *ptibSelf; // 18h Linear address of TIB structure DWORD threadID; // 24h |
| mov eax, fs:[18h] ;因为 18h 偏移处是 TIB 结构的线性偏移地址 mov eax, [eax + 24h] ;因为 24h 偏移处是 threadID 的地址 ret ;把 eax 中储存的 threadID 地址返回 |
| PVOID* pProcess; // 30h Pointer to owning process database |
| ;********************************************************* ;程序名称:演示利用 TEB 结构进行 Anti-Debug ; 请用 OllyDbg 进行调试 ;适用OS:Windows NT/2K/XP ;作者:罗聪 ;日期:2003-2-9 ;出处:http://www.LuoCong.com(老罗的缤纷天地) ;注意事项:如欲转载,请保持本程序的完整,并注明: ;转载自“老罗的缤纷天地”(http://www.LuoCong.com) ;********************************************************* .386 .model flat, stdcall option casemap:none include \masm32\include\windows.inc include \masm32\include\kernel32.inc include \masm32\include\user32.inc includelib \masm32\lib\kernel32.lib includelib \masm32\lib\user32.lib .data szCaption db "Anti-Debug Demo by LC, 2003-2-9", 0 szDebugged db "Hah, let me guess... U r dEBUGGINg me! :)", 0 szFine db "Good boy, no dEBUGGEr detected!", 0 .code main: assume fs:nothing mov eax, fs:[30h] ;指向 PDB(Process Database) movzx eax, byte ptr [eax + 2h] or al, al jz _Fine _Debugged: push MB_OK or MB_ICONHAND push offset szCaption push offset szDebugged jmp _Output _Fine: push MB_OK or MB_ICONINFORMATION push offset szCaption push offset szFine _Output: push NULL call MessageBoxA invoke ExitProcess, 0 end main |
老罗
2003-2-9