Rewrote dll_load function and its subfunctions for c--.

git-svn-id: svn://kolibrios.org@4567 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
hidnplayr 2014-02-09 19:10:04 +00:00
parent 9443bf38d2
commit ef154816ce

View File

@ -1,125 +1,168 @@
//Asper
char a_libdir[43] = "/sys/lib/\0"; char a_libdir[43] = "/sys/lib/\0";
// stdcall with 1 parameter
void dll_Load() {
asm {
push ebp
mov ebp, esp
mov esi, SSDWORD[EBP+8]
@next_lib:
mov edx, DSDWORD[ESI]
or edx, edx
jz exit
push esi
mov esi, DSDWORD[ESI+4]
mov edi, #a_libdir+9
//proc dll.Load, import_table:dword @loc01:
int dll_Load(dword import_table) lodsb
{ stosb
$mov esi, import_table or al, al
@next_lib: $mov edx, DSDWORD[esi] jnz loc01
$or edx,edx
$jz exit_
$push esi
$mov esi,DSDWORD[esi+4]
$mov edi,#a_libdir
$push edi mov eax, 68
$push esi mov ebx, 19
EAX=strlen(#a_libdir); mov ecx, #a_libdir
$pop esi int 0x40
$pop edi or eax, eax
$add edi, eax //9 jz fail
@loc01: $lodsb push edx
$stosb push eax
$or al,al call dll_Link
$jnz loc01
//IntToStr(EBX); push eax
//$push edx mov eax, DSDWORD[eax]
//WriteDebug(#a_libdir); cmp DSDWORD[EAX], '_bil' // somehow this needs to be reversed..
//$pop edx pop eax
//mcall 68,19,a_libdir jnz loc02
$mov eax, 68
$mov ebx, 19
$mov ecx,#a_libdir
$int 0x40
$or eax,eax push DSDWORD[EAX+4]
$jz fail call dll_Init
//stdcall dll.Link,eax,edx
dll_Link(EAX, EDX);
$push eax
$mov eax, DSDWORD [eax]
$cmp DSDWORD [eax], 'lib_'
$pop eax
//$jnz loc02
//IntToStr(EBX);
//$push eax
//WriteDebug(DSDWORD[EAX]);
//$pop eax
//stdcall dll.Init,[eax+4]
//dll_Init(DSDWORD[EAX]); //dll_Init(DSDWORD[EAX+4]);
@loc02: @loc02:
$pop esi
$add esi,8 pop esi
$jmp next_lib add esi, 8
@exit_: $xor eax,eax jmp next_lib
return 0; @exit:
@fail: $add esp,4 xor eax, eax
$xor eax,eax leave
$inc eax ret 4
return -1;
@fail:
add esp, 4
xor eax, eax
inc eax
leave
ret 4
}
} }
//proc dll.Link, exp:dword,imp:dword //stdcall with 2 parameters
void dll_Link(dword exp, imp) void dll_Link() {
{ asm {
$push eax push ebp
$mov esi, imp mov ebp, esp
$test esi, esi push eax
$jz done mov esi, SSDWORD[EBP+12]
@next: $lodsd test esi, esi
$test eax,eax jz done
$jz done @next:
lodsd
//stdcall dll.GetProcAddress,[exp],eax test eax, eax
dll_GetProcAddress(exp,EAX); jz done
$or eax,eax push eax
$jz loc03 push SSDWORD[EBP+8]
call dll_GetProcAddress
$mov DSDWORD[esi-4],eax or eax, eax
$jmp next jz loc03
mov DSDWORD[esi-4], eax
jmp next
@loc03: @loc03:
$mov DSDWORD[esp],0 mov SSDWORD[esp], 0
@done: $pop eax @done:
pop eax
leave
ret 8
}
} }
//proc dll.Init, dllentry:dword
void dll_Init(dword dllentry) //stdcall with 1 parameter
{ void dll_Init() {
$pushad asm {
EAX=#mem_Alloc; push ebp
EBX=#mem_Free; mov ebp, esp
ECX=#mem_ReAlloc; pushad
EDX=#dll_Load; mov eax, #mem_Alloc
DSDWORD [dllentry+4] stdcall (); mov ebx, #mem_Free;
$popad mov ecx, #mem_ReAlloc;
mov edx, #dll_Load;
call SSDWORD[EBP+8]
popad
leave
ret 4
}
} }
//proc dll.GetProcAddress, exp:dword,sz_name:dword
dword dll_GetProcAddress(dword exp, sz_name) // stdcall with 2 parameters
{ void dll_GetProcAddress(){
$push esi asm {
$mov edx, exp push ebp
$xor eax,eax mov ebp, esp
@next: $or edx,edx mov edx, CSDWORD[EBP+8]
$jz end_ xor eax, eax
$cmp edx,0
$jz end_ @next:
strcmp(DSDWORD[EDX],sz_name); or edx, edx
$test eax,eax jz end
$jz ok cmp CSDWORD[edx], 0
$add edx,8 jz end
$jmp next
push CSDWORD[EBP+12]
push CSDWORD[EDX]
call dll_StrCmp
test eax, eax
jz ok
add edx, 8
jmp next
@ok: @ok:
$mov eax, DSDWORD[edx+4] mov eax, DSDWORD[EDX+4]
@end_: @end:
$pop esi leave
return EAX; ret 8
}
} }
// stdcall with 2 parameters
void dll_StrCmp() {
asm {
push ebp
mov ebp, esp
push esi
push edi
mov esi, CSDWORD[EBP+8]
mov edi, CSDWORD[EBP+12]
xor eax, eax
@label1:
lodsb
scasb
jne fail
or al, al
jnz label1
jmp label_ok
@fail:
or eax, -1
@label_ok:
pop edi
pop esi
leave
ret 8
}
}
int load_dll2(dword dllname, import_table, byte need_init) int load_dll2(dword dllname, import_table, byte need_init)
{ {
//dword dllentry=0; //dword dllentry=0;
@ -166,7 +209,7 @@ int load_dll2(dword dllname, import_table, byte need_init)
$jmp import_loop01 $jmp import_loop01
@import_done01: @import_done01:
IF (need_init) dll_Init(EDX); IF (need_init) dll_Init (DSDWORD[EDX+4]);
return 0; return 0;
@exit01: @exit01:
return -1; return -1;