pseudologic is this:ой надо ж по русски... (привычка)
на время разработки пришлось добавить эту вспомогательную чушь - назвал temporary_notify, неоптимально но это гляделка для отладки и не более.
Code: Select all
macro temporary_notify sz_string {
pushad
mov esi, sz_string
xchg esi, [run_notify_struct.Flags]
mcall SF_FILE,run_notify_struct
xchg esi, [run_notify_struct.Flags]
popad}
Code: Select all
GetStrLength:
; string: [in] edi
; string length: [out] ecx
; [unchanged] ebx, edx, esi, edi, ebp, esp
or ecx, -1
xor eax, eax
cld
repne scasb
not ecx
sub edi,ecx
ret
Code: Select all
GetProcAddress:
; hInstance (export table): [in] esi
; proc name: [in] edi
; proc address: [out] eax
; [unchanged] ebp, esp
call GetStrLength
mov edx, ecx
mov ebx, edi
mov eax, esi
.import_find:
mov esi, ebx
mov edi, [eax]
test edi, edi
jz .import_not_found
repe cmpsb
je .import_found
mov ecx, edx
add eax, 8
jmp .import_find
.import_not_found:
sub eax, 4
.import_found:
mov eax, [eax+4]
ret
Code: Select all
ResolveImports:
; hInstance (export table): [in] esi
; lib.lookup table: [in] ebp
; ?isResolved: [out] eax
; [unchanged] esi, esp
.retFrom = 4
;temporary_notify edx ;-success
.import_loop:
mov edi, [ebp]
test edi, edi
jz .import_done
push esi
call GetProcAddress
pop esi
test eax, eax
jz .import_not_found
mov [ebp],eax
add ebp,4
jmp .import_loop
.import_not_found:
mov eax, sz_EPnotFound
mov ebx, sizeof.sz_EPnotFound
mov ecx, 3
mov edx, [ebp]
call ShowErrorWindow
or [LoadLibraries.errStatus+ResolveImports.retFrom],1
;mcall SF_TERMINATE_PROCESS ;uncomment to stop after 1st error
jmp .import_loop
.import_done:
ret
Code: Select all
@copy_path_wo_pdname:
; library name: [in] edx
; library path: [in] esi
; current directory path: [in] edi
; [out] no
; [unchanged] ebx, edx, ebp, esp
call GetStrLength
add edi,ecx
mov al, '/'
std
repne scasb
cld
sub edi,ecx
add ecx,2
xchg esi, edi
mov eax, ecx
shr ecx, 2
rep movsd
mov ecx, eax
and ecx, 3
rep movsb
;cld
;add edi,2
mov esi, edx
xchg esi, edi
call GetStrLength
xchg esi, edi
mov eax, ecx
shr ecx, 2
rep movsd
mov ecx, eax
and ecx, 3
rep movsb
ret
Code: Select all
LoadLibrary:
; library name: [in] edx
; hInstance (export table): [out] eax
; [unchanged] edx, ebp, esp
mov edi, cur_dir_path
mov esi, library_path
call @copy_path_wo_pdname
;temporary_notify library_path ;-success
mcall SF_SYS_MISC,SSF_LOAD_DLL,library_path
test eax, eax
jnz .ret
lea ecx, [edx-9]
mcall SF_SYS_MISC,SSF_LOAD_DLL,[=]/ecx ; load of sys directory
.ret
ret
Code: Select all
LoadLibraries:
; [in/out] no
; [unchanged] esp
push 0
push import.data
virtual at esp+4
.errStatus dd ?
end virtual
.LoopLibraries:
mov eax, [esp]
mov ebp, [eax]
test ebp, ebp
jz .done
mov edx, [eax+4]
call LoadLibrary;edx=name
test eax, eax
jz .onError
mov esi,eax
call ResolveImports
add [esp],8
jmp .LoopLibraries
.onError:
mov eax, sz_cantLL
mov ebx, sizeof.sz_cantLL
mov ecx, 1
;mov edx, edx
call ShowErrorWindow
or [LoadLibraries.errStatus],1
;mcall SF_TERMINATE_PROCESS ;uncomment to stop after 1st error
jmp .LoopLibraries
.done:
test [LoadLibraries.errStatus],1
jz .exit
mcall SF_TERMINATE_PROCESS
.exit:
add esp,8
ret
Code: Select all
ShowErrorWindow:
; error string: [in] edx
; [unchanged] edx, ebp, esp
mov edi, [run_notify_struct.Flags]
xor ecx, [rns.state]
test ecx, ecx
jz .rns.FlagsInited
cmp ecx, 2
jz .rns.FlagsPreInited
.rns.FlagsPreInit:
mov esi, sz_system_error
mov ecx, sizeof.sz_system_error-1
cld
rep movsb
or [rns.state],1
jmp .rns.FlagsInit
.rns.FlagsPreInited:
add edi, sizeof.sz_system_error-1
.rns.FlagsInit:
mov esi, eax
xchg esi, edi
call GetStrLength
dec ecx
xchg esi, edi
rep movsb
xor [rns.state],2
jmp .rns.FlagsDone
.rns.FlagsInited:
lea edi, [edi+ebx-1+sizeof.sz_system_error-1]
.rns.FlagsDone:
mov esi, edx
xchg esi, edi
call GetStrLength
xchg esi, edi
rep movsb
mcall SF_FILE,run_notify_struct
ret
во всех вышеперечисленных процедурах вызывающая процедура сама ответственна за сохранение регистров, уничтожаемых вызываемой процедурой.
ну и сами макросы импорта (схожие с макросами для Win & Linux import):
Code: Select all
macro library [name,string]
{ common
import.data:
forward
local _label
if defined name#.redundant
if ~ name#.redundant
dd name#.lookup,_label
end if
end if
name#.referred = 1
common
dd 0
forward
if defined name#.redundant
if ~ name#.redundant
align 4
db '/sys/lib/' ; thats why I substructs 9 from reg3 in pseudocode sizeof '/sys/lib/' = 9, от этого, конечно, потом надо будет избавиться и формировать сислибпуть динамически
_label db string,0
end if
end if }
Code: Select all
macro import name,[label,string]
{ common
align 4
if defined name#.referred
name#.lookup:
;name#.redundant = 1
forward
if used label
local _label
label dd _label
end if
common
if $ > name#.lookup
name#.redundant = 0
dd 0
else
name#.redundant = 1
end if
forward
if used label
align 4
_label db string,0
end if
common
end if }