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
$push esi
EAX=strlen(#a_libdir);
$pop esi
$pop edi
$add edi, eax //9
@loc01: $lodsb
$stosb
$or al,al
$jnz loc01
//IntToStr(EBX); mov eax, 68
//$push edx mov ebx, 19
//WriteDebug(#a_libdir); mov ecx, #a_libdir
//$pop edx int 0x40
//mcall 68,19,a_libdir or eax, eax
$mov eax, 68 jz fail
$mov ebx, 19
$mov ecx,#a_libdir push edx
$int 0x40 push eax
call dll_Link
$or eax,eax
$jz fail push eax
//stdcall dll.Link,eax,edx mov eax, DSDWORD[eax]
dll_Link(EAX, EDX); cmp DSDWORD[EAX], '_bil' // somehow this needs to be reversed..
$push eax pop eax
$mov eax, DSDWORD [eax] jnz loc02
$cmp DSDWORD [eax], 'lib_'
$pop eax push DSDWORD[EAX+4]
//$jnz loc02 call dll_Init
//IntToStr(EBX); @loc02:
//$push eax
//WriteDebug(DSDWORD[EAX]); pop esi
//$pop eax add esi, 8
//stdcall dll.Init,[eax+4] jmp next_lib
//dll_Init(DSDWORD[EAX]); //dll_Init(DSDWORD[EAX+4]); @exit:
@loc02: xor eax, eax
$pop esi leave
$add esi,8 ret 4
$jmp next_lib
@exit_: $xor eax,eax @fail:
return 0; add esp, 4
@fail: $add esp,4 xor eax, eax
$xor eax,eax inc eax
$inc eax leave
return -1; 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
@loc03: mov DSDWORD[esi-4], eax
$mov DSDWORD[esp],0 jmp next
@done: $pop eax @loc03:
mov SSDWORD[esp], 0
@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
@ok: push CSDWORD[EBP+12]
$mov eax, DSDWORD[edx+4] push CSDWORD[EDX]
@end_: call dll_StrCmp
$pop esi test eax, eax
return EAX; jz ok
add edx, 8
jmp next
@ok:
mov eax, DSDWORD[EDX+4]
@end:
leave
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,8 +209,8 @@ 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;
} }