szKernel32 db "kernel32.dll",0
szExitProcess db "ExitProcess",0
...
invoke GetModuleHandle, ADDR szKernel32
invoke GetProcAddress, eax, ADDR szExitProcess
xor edx,edx
push edx
call eax
Динамическая загрузка dll
P.S. кста если после вызова лоадлайбрари попробывать call eax...
Код:
Код:
include 'macro\struct.inc'
;---------------- Base --------------- Только в XP
proc Base
dw 0a164h,0030h,0000h
mov eax, [eax+0Ch]
mov esi, [eax+1Ch]
lodsd
mov eax, [eax+08h]
ret
endp
;-------------- GetAddress -------------------------
proc GetAddress Base,Function
local OptionalHeader:DWORD
local ExportDirectory:DWORD
local NumberOfNames:DWORD
local nOrdinal:WORD
push ebx edi esi edx ecx
mov ebx,[Base]
add ebx,3ch
mov ebx,[ebx]
add ebx,18h
add ebx,[Base] ;--- ebx - Optional Header
mov [OptionalHeader],ebx
add ebx,60h
mov ebx,[ebx]
add ebx,[Base];--- ebx - Export Directory
mov [ExportDirectory],ebx
add ebx,20h
mov edi,[ebx];--- edi - ExportDirectory->AddressOfNames
add ebx,4h
mov esi,[ebx];--- esi - ExportDirectory->AddressOfNamesOrdinal
add edi,[Base]
add esi,[Base]
mov edx,[ExportDirectory]
add edx,18h
mov edx,[edx]
mov [NumberOfNames],edx
xor ecx,ecx
mov ecx,edx
f10:
xor edx,edx
mov edx,[edi]
add edx,[Base];edx - NameOfFunction
push edx
push [Function]
call strcmp
test eax,eax
jz f30
add edi,4h
add esi,2h
loop f10
xor eax,eax
pop ecx edx esi edi ebx
ret
f30:
xor ecx,ecx
mov cx,word[esi]
mov [nOrdinal],cx
mov eax,[Base]
mov edi,[ExportDirectory]
add edi,1ch
mov edi,[edi]
add edi,eax
imul ecx,ecx,4
add edi,ecx
mov ebx,[edi]
add eax,ebx
pop ecx edx esi edi ebx
ret
endp
;-------------- strcmp --------------
proc strcmp str1,str2
local flag:DWORD
push ebx ecx edx
mov ebx,[str1]
mov [flag],-1
dec ebx
f1:
inc [flag]
inc ebx
cmp byte[ebx],0
jne f1
mov ecx,-1
mov edx,[str2]
dec edx
f2:
inc ecx
inc edx
cmp byte[edx],0
jne f2
cmp [flag],ecx
jne endx
;---------------
mov ebx,[str1]
mov edx,[str2]
mov ecx,-1
dec ebx
dec edx
f3:
inc ecx
inc edx
cmp byte[edx],0
je f4
inc ebx
cmp byte[ebx],0
je f4
mov al,byte[ebx]
cmp byte[edx],al
je f3
f4:
cmp ecx,[flag]
jne endx
mov eax,0
pop edx ecx ebx
ret
endx:
mov eax,-1
pop edx ecx ebx
ret
endp
;---------------- Base --------------- Только в XP
proc Base
dw 0a164h,0030h,0000h
mov eax, [eax+0Ch]
mov esi, [eax+1Ch]
lodsd
mov eax, [eax+08h]
ret
endp
;-------------- GetAddress -------------------------
proc GetAddress Base,Function
local OptionalHeader:DWORD
local ExportDirectory:DWORD
local NumberOfNames:DWORD
local nOrdinal:WORD
push ebx edi esi edx ecx
mov ebx,[Base]
add ebx,3ch
mov ebx,[ebx]
add ebx,18h
add ebx,[Base] ;--- ebx - Optional Header
mov [OptionalHeader],ebx
add ebx,60h
mov ebx,[ebx]
add ebx,[Base];--- ebx - Export Directory
mov [ExportDirectory],ebx
add ebx,20h
mov edi,[ebx];--- edi - ExportDirectory->AddressOfNames
add ebx,4h
mov esi,[ebx];--- esi - ExportDirectory->AddressOfNamesOrdinal
add edi,[Base]
add esi,[Base]
mov edx,[ExportDirectory]
add edx,18h
mov edx,[edx]
mov [NumberOfNames],edx
xor ecx,ecx
mov ecx,edx
f10:
xor edx,edx
mov edx,[edi]
add edx,[Base];edx - NameOfFunction
push edx
push [Function]
call strcmp
test eax,eax
jz f30
add edi,4h
add esi,2h
loop f10
xor eax,eax
pop ecx edx esi edi ebx
ret
f30:
xor ecx,ecx
mov cx,word[esi]
mov [nOrdinal],cx
mov eax,[Base]
mov edi,[ExportDirectory]
add edi,1ch
mov edi,[edi]
add edi,eax
imul ecx,ecx,4
add edi,ecx
mov ebx,[edi]
add eax,ebx
pop ecx edx esi edi ebx
ret
endp
;-------------- strcmp --------------
proc strcmp str1,str2
local flag:DWORD
push ebx ecx edx
mov ebx,[str1]
mov [flag],-1
dec ebx
f1:
inc [flag]
inc ebx
cmp byte[ebx],0
jne f1
mov ecx,-1
mov edx,[str2]
dec edx
f2:
inc ecx
inc edx
cmp byte[edx],0
jne f2
cmp [flag],ecx
jne endx
;---------------
mov ebx,[str1]
mov edx,[str2]
mov ecx,-1
dec ebx
dec edx
f3:
inc ecx
inc edx
cmp byte[edx],0
je f4
inc ebx
cmp byte[ebx],0
je f4
mov al,byte[ebx]
cmp byte[edx],al
je f3
f4:
cmp ecx,[flag]
jne endx
mov eax,0
pop edx ecx ebx
ret
endx:
mov eax,-1
pop edx ecx ebx
ret
endp
примерчик использования:
Код:
section '.text' data readable writeable
Basez dd 0
addrLoadLibrary dd ?
addrExitProcess dd ?
szLoadLibrary db 'LoadLibraryA',0
szExitProcess db 'ExitProcess',0
section '.text' code readable executable
start_code:
entry $
call Base
mov [Basez],eax
push szLoadLibrary
push eax
call GetAddress
cmp eax,0
je .exiting
mov [addrLoadLibrary],eax
;------------------------------------
push szExitProcess
push [Basez]
call GetAddress
cmp eax,0
je .exiting
mov [addrExitProcess],eax
Basez dd 0
addrLoadLibrary dd ?
addrExitProcess dd ?
szLoadLibrary db 'LoadLibraryA',0
szExitProcess db 'ExitProcess',0
section '.text' code readable executable
start_code:
entry $
call Base
mov [Basez],eax
push szLoadLibrary
push eax
call GetAddress
cmp eax,0
je .exiting
mov [addrLoadLibrary],eax
;------------------------------------
push szExitProcess
push [Basez]
call GetAddress
cmp eax,0
je .exiting
mov [addrExitProcess],eax
Спасибо конечно народ, все понял) все работает.