mov ebx,eax
mov ecx,eax
push edi
push esi
//比较两个动态库字符串
repe cmps //byte ptr [edi], byte ptr [esi]
jz _it_fixup_1_do_normal_it_0
pop esi
pop edi
//下一个
add edi,ebx
//是否结束
cmp byte ptr [edi],0
jnz _it_fixup_1_check_dll_redirected
//_p_dwThunk
mov ecx,[ebp-08h]
//api地址
mov eax,[ebp-014h]
//FirstThunk指向的数组被填充为真正的函数地址
mov [ecx],eax
jmp _it_fixup_1_do_normal_it_1
_it_fixup_1_do_normal_it_0:
//对应repe之前的push
pop esi
pop edi
//新申请的内存空间
mov edi,[ebp-04h]
//插入JMP
mov byte ptr [edi], 0e9h
//API地址
mov eax,[ebp-14h]
//计算跳转偏移
sub eax, edi
sub eax,05h
//插入偏移
mov [edi+1],eax
//0c8bh-->mov eax,eax,对齐
mov word ptr [edi+05],0c8bh
//THUNK
mov ecx,[ebp-08h]
//将原程序的THUNK指向我们的内存地址
mov [ecx],edi
//下一个位置
add dword ptr [ebp-04h],07h
_it_fixup_1_do_normal_it_1:
pop ebx
pop esi
pop edi
//================================================================
add dword ptr [ebp-08h],004h // dwThunk => next dwThunk
add dword ptr [ebp-0ch],004h// dwHintName => next dwHintName
jmp _it_fixup_1_get_proc_address_loop
_it_fixup_1_next_module:
add ebx,014h // sizeof(IMAGE_IMPORT_DESCRIPTOR)
jmp _it_fixup_1_get_lib_address_loop
_it_fixup_1_end:
mov esp,ebp
pop ebp
ret 0ch //-------------------------------------------------------- //======================================================== //-- char_upper(LPCTSTR lpDestination, LPCTSTR lpSource )
_char_upper:
push ebp
mov ebp,esp
push ecx
push eax
push esi
push edi
mov edi,dword ptr [ebp+08h]// -> Destination
mov esi,dword ptr [ebp+0Ch]// -> Source
mov ecx,255// -> Length
xor eax,eax
__makeupperloop:
lods byte ptr [esi]//ESI
cmp al,00h
jz endofbuffer
cmp al,60h
jc notinlowerfield
cmp al,7bh
jnc notinlowerfield
sub al,20h
notinlowerfield:
stos byte ptr [edi]//EDI
loop __makeupperloop
endofbuffer:
pop edi
pop esi
pop eax
pop ecx
pop ebp
retn 08h //-------------------------------------------------------- //======================================================== //------------- load necessary api functions ------------- //以下都是重定位之后的地址
_api_load:
//取得_p_szKernel32字符串地址
lea edi,[ebp+_p_szKernel32]
//取得_p_GetModuleHandle的地址
lea ebx,[ebp+_p_GetModuleHandle]
//取得_jmp_GetModuleHandle地址
lea ecx,[ebp+_jmp_GetModuleHandle]
//取得_jmp_GetModuleFileName的地址?
add ecx,02h
_api_get_lib_address_loop:
//保存ECX
push ecx
push edi
mov eax,offset _p_LoadLibrary
//加载kernel32.dll
call [ebp+eax]// LoadLibrary(lpLibFileName);
//-------------------
pop ecx
//kernel32.dll模块地址
mov esi,eax // esi -> hModule
//字符串长度
push edi
call __strlen
//平衡堆栈,弹出参数
add esp,04h
//指向下一个字符串
add edi,eax
_api_get_proc_address_loop:
push ecx
//edi=getmodulhanda
push edi
//esi=hmodule
push esi
mov eax,offset _p_GetProcAddress
call [ebp+eax]// GetModuleHandle=GetProcAddress(hModule, lpProcName);
//--------------------
pop ecx
//存入GetModuleHandle的实际地址
mov [ebx],eax
//注意看这里!!
mov [ecx],ebx
//下一个
add ebx,04h
//下一个
add ecx,06h
//下一个
push edi
call __strlen
add esp,04h
add edi,eax
mov al,byte ptr [edi]
test al,al
//不为0继续循环
jnz _api_get_proc_address_loop
//edi地址加一
inc edi
mov al,byte ptr [edi]
test al,al
//不为0则载入user32.dll
jnz _api_get_lib_address_loop
ret //---------------------------------------------------------- //-------------------------------------------------------- //======================================================== // -------- exception handler expression filter ----------
_except_handler1_OEP_Jump:
push ebp
mov ebp,esp
mov eax,[ebp+010h] // PCONTEXT: pContext <- eax
//---------------
push edi
// restore original SEH
mov edi,[eax+0C4h] // pContext.Esp
push dword ptr ds:[edi]
pop dword ptr fs:[0]
add dword ptr [eax+0C4h],8 // pContext.Esp
// set the Eip to the OEP
mov edi,[eax+0A4h] // edi <- pContext.Ebx
mov [eax+0B8h],edi // pContext.Eip <- edi
//
pop edi
//---------------
mov eax, EXCEPTION_CONTINUE_SEARCH
leave
ret //-------------------------------------------------------- //========================================================
dword_type(DYN_LOADER_START_DATA1) //0xcccccccc自填充----------------------------------
_p_dwFileType: dword_type(0xCCCCCCCC)
_p_dwImageBase: dword_type(0xCCCCCCCC)
_p_dwOrgEntryPoint: dword_type(0xCCCCCCCC)
_p_dwImportVirtualAddress: dword_type(0xCCCCCCCC)
_p_dwRelocationVirtualAddress: dword_type(0xCCCCCCCC)
_p_dwRelocationSize: dword_type(0xCCCCCCCC) //----------------------------------
_tls_dwStartAddressOfRawData: dword_type(0xCCCCCCCC)
_tls_dwEndAddressOfRawData: dword_type(0xCCCCCCCC)
_tls_dwAddressOfIndex: dword_type(0xCCCCCCCC)
_tls_dwAddressOfCallBacks: dword_type(0xCCCCCCCC)
_tls_dwSizeOfZeroFill: dword_type(0xCCCCCCCC)
_tls_dwCharacteristics: dword_type(0xCCCCCCCC) //----------------------------------
_p_szKernel32: //db "Kernel32.dll",0,13
db db db db db db db db db db db db db
_p_szGetModuleHandle: //db "GetModuleHandleA",0,17
db db db db db db db db db db db db db db db db db
_p_szVirtualProtect: //db "VirtualProtect",0,15
db db db db db db db db db db db db db db db
_p_szGetModuleFileName: //db "GetModuleFileNameA",0,19
db db db db db db db db db db db db db db db db db db db
_p_szCreateFile: //db "CreateFileA",0,12
db db db db db db db db db db db db
_p_szGlobalAlloc: //db "GlobalAlloc",0,12
db db db db db db db db db db db db
_p_szVirtualAlloc: //db "VirtualAlloc",0,13
db db db db db db db db db db db db db
_p_szLoadLibrary: //db "LoadLibraryA",0,13
db db db db db db db db db db db db db
_p_szGetProcAddress: //db "GetProcAddress",0,15
db db db db db db db db db db db db db db db
byte_type(0)
_p_szUser32: //db "User32.dll",0,11
db db db db db db db db db db db
_p_szMessageBox: //db "MessageBoxA",0,12
db db db db db db db db db db db db
byte_type(0)
byte_type(0) //----------------------------------
_p_LoadLibrary: dword_type(0xCCCCCCCC)
_p_GetProcAddress: dword_type(0xCCCCCCCC)
_p_GetModuleHandle:
dword_type(0xCCCCCCCC)
dword_type(0xCCCCCCCC)
dword_type(0xCCCCCCCC)
dword_type(0xCCCCCCCC)
dword_type(0xCCCCCCCC)
dword_type(0xCCCCCCCC)
dword_type(0xCCCCCCCC)
dword_type(0xCCCCCCCC)
dword_type(0xCCCCCCCC)