comrade
Joined: 16 Jun 2003
Posts: 1150
Location: Russian Federation
|
hook.asm:
;##########################################################################
format PE GUI 4.0 DLL
entry DllEntryPoint
;##########################################################################
_TITLE equ "hook"
_NAME equ "hook"
_VERSION equ "0.0"
_VERSIONTEXT equ _VERSION
;##########################################################################
include "%include%/win32am.inc"
include "%include%/equates/kernel32.inc"
include "%include%/equates/user32.inc"
include "%include%/macro/if.inc"
include "%include%/macro/macros.inc"
OFFSET equ
;##########################################################################
;##########################################################################
section ".code" code readable executable
;##########################################################################
;##########################################################################
;##########################################################################
proc DllEntryPoint,hInstance,fdwReason,lpvReserved
enter
xor eax,eax
inc eax
return
;##########################################################################
user32!wsprintfA:
mov eax,[ExitProcess]
retn
;##########################################################################
user32!MessageBoxA:
mov eax,[esp+08h]
showstr "user32.MessageBoxA",eax
jmp [MessageBox]
;##########################################################################
kernel32!CreateFileA:
mov eax,[esp+04h]
showstr "kernel32.CreateFileA",eax
jmp [CreateFile]
;##########################################################################
kernel32!LoadLibraryA:
mov eax,[esp+04h]
showstr "kernel32.LoadLibraryA",eax
jmp [LoadLibrary]
;##########################################################################
kernel32!GetCurrentDirectoryA:
mov eax,[esp+04h]
showstr "kernel32.GetCurrentDirectoryA",eax
jmp [LoadLibrary]
;##########################################################################
kernel32!SetCurrentDirectoryA:
mov eax,[esp+04h]
showstr "kernel32.SetCurrentDirectoryA",eax
jmp [LoadLibrary]
;##########################################################################
wsock32!gethostbyname:
mov eax,[esp+04h]
showstr "wsock32.gethostbyname",eax
jmp [gethostbyname]
;##########################################################################
;##########################################################################
;##########################################################################
;##########################################################################
section ".data" data readable writeable
data import
library kernel32,"kernel32.dll",user32,"user32.dll",wsock32,"wsock32.dll"
include "%include%/apia/kernel32.inc"
include "%include%/apia/user32.inc"
include "%include%/apia/wsock32.inc"
end data
data export
export <_TITLE,".dll">,user32!wsprintfA,"wsprintfA",\
kernel32!CreateFileA,"CreateFileA",\
kernel32!LoadLibraryA,"LoadLibraryA",\
kernel32!GetCurrentDirectoryA,"GetCurrentDirectoryA",\
kernel32!SetCurrentDirectoryA,"SetCurrentDirectoryA",\
user32!MessageBoxA,"MessageBoxA",\
wsock32!gethostbyname,"gethostbyname"
end data
;##########################################################################
;##########################################################################
szLibTitle db _TITLE,0
;##########################################################################
;##########################################################################
section ".rsrc" resource data readable
; identifiers
IDV_MAIN = 01
; resources
directory RT_VERSION,versions
resource versions,IDV_MAIN,SUBLANG_NEUTRAL+LANG_NEUTRAL,version
; version
version version,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,SUBLANG_NEUTRAL+LANG_NEUTRAL,0,\
"FileDescription",_TITLE,\
"LegalCopyright",<0A9h," comrade">,\
"FileVersion",_VERSION,\
"ProductVersion",_VERSION,\
"ProductName",_TITLE,\
"InternalName",_NAME,\
"OriginalFilename",<_NAME,".dll">
;##########################################################################
section ".reloc" fixups data discardable
;##########################################################################
;##########################################################################
and test.asm:
;##########################################################################
format PE GUI 4.0
entry start
;##########################################################################
include "%include%/win32am.inc"
include "%include%/equates/kernel32.inc"
include "%include%/equates/user32.inc"
include "%include%/macro/if.inc"
include "%include%/macro/macros.inc"
OFFSET equ
;##########################################################################
;##########################################################################
section ".code" code readable executable
;##########################################################################
start:
;##########################################################################
;##########################################################################
push ebx esi edi
push 400000h
push 400000h
push 400000h
push 400000h
push 400000h
call [msgxbox]
pop edi esi ebx
stdcall [ExitProcess],0
;##########################################################################
;##########################################################################
;##########################################################################
;##########################################################################
section ".data" import data readable writeable
library kernel32,"kernel32.dll",user32,"user32.dll",hook,"hook.dll"
include "%include%/apia/kernel32.inc"
include "%include%/apia/user32.inc"
import hook,msgxbox,"MessageBoxA"
;##########################################################################
Windows (2000 Pro SP4) will not be able to find hook.dll!MessageBoxA if its exported just after user32!wsprintfA (see hook.asm), but works in the position that I pasted in. Same goes for other exported function. Export table structure seems fine, and PEditor interprets it as fine. Windows, though, refuses to find DLL if it has some wrong position in call to export macro:
---------------------------
output.exe - Entry Point Not Found
---------------------------
The procedure entry point MessageBoxA could not be located in the dynamic link library hook.dll.
---------------------------
OK
---------------------------
|