flat assembler
Message board for the users of flat assembler.
Index
> Windows > [solved] DLL error. error satus 0xc000007b |
Author |
|
mns 23 Apr 2020, 09:56
I have tried to make a custom DLL and check the function with a test program(both attached with this).DLL and test program assembled correctly.But when running the program windows gives a error.(screen shot is also attached.please see-> error.png).
but when WriteNumbrDLL proc in DLL has 'invoke MessageBox,....' , the program runs without error. Hope someone can help. source of the DLL file Code: format PE GUI 4.0 DLL entry startDLL include 'WIN32AX.inc' ;include 'rcWin32p16.inc' ;///////////////////////////////////////////////////////////////////////////////////////////////////// section '.code' code readable executable ;======================================Entry poin function====================================================== proc startDLL hInstance,Reason,Reserved mov eax,TRUE ret endp ;---------------------------------------------------------------------------------------------------------- ;------------------------------------function WriteNumbr------------------------------------------------------ proc WriteNumbrDLL,number:DWORD,lpStrng push [number] push [lpStrng] call numbToStr mov eax,[lpStrng] ;invoke MessageBox, 0,eax,MsgBoxCaption, MB_OK ret endp ;---------------------------------------------------------------------------------------------------------- ;------------------------------------numbToStr------------------------------------------------------ numbToStr: push ebp mov ebp,esp mov eax,[ebp+12] mov edi,[ebp+8] mov ecx,0 cld .divLoopDLL: cmp eax,0 je .strCrate push ecx mov ecx,10 xor edx,edx div ecx add dl,30h pop ecx inc ecx push edx jmp .divLoopDLL .strCrate: cmp ecx,0 je .retnumbToStr pop eax stosb dec ecx jmp .strCrate .retnumbToStr: mov al,0 stosb pop ebp ret 4 ;endp ;---------------------------------------------------------------------------------------------------------- ;========================================================================================================== ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;////////////////////////////////////////////////////////// ;///////////////////////////////////////////////////////////////////////////////////////////////////// section '.data' data readable writeable ;======================================================================================================== ErrTxt9 db 'Error in writing to the file',0 ErrTxt11 db 'Error in Thread creation',0 MsgBoxCaption db 'DLL message',0 hello db 'This is hello from DLL function',0 Reason dd ? hInstance dd ? Reserved dd ? ;====================================================================================================== ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;////////////////////////////////////////////////////////// ;///////////////////////////////////////////////////////////////////////////////////////////////////// section '.idata' import data readable ;======================================================================================================= library kernel32, 'kernel32.dll',\ user32,'USER32.DLL' include 'api/kernel32.inc' include 'api/USER32.inc' ;======================================================================================================= ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;////////////////////////////////////////////////////////// ;///////////////////////////////////////////////////////////////////////////////////////////////////// section '.edata' export data readable ;======================================================================================================= export 'StrFuncDLL.dll',\ WriteNumbrDLL,'WriteNumbrDLL' ;======================================================================================================= ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ ;////////////////////////////////////////////////////////// ;///////////////////////////////////////////////////////////////////////////////////////////////////// section '.reloc' fixups data readable discardable ;=======================================================================================================
|
||||||||||||||||||||||||||||||
23 Apr 2020, 09:56 |
|
Tomasz Grysztar 23 Apr 2020, 10:15
Some PE loaders, including the one used by the current Windows versions (based on NT kernel), do not accept empty sections. Your '.reloc' section ends up empty when there are no fixups to generate. Your code is mostly position-independent (because you only address local variables through addresses relative to EBP) and only after you add that MessageBox line you are adding an use of an absolute address (the address of string in the data section), which requires a relocation entry.
You could avoid this error by not making a separate (and potentially empty) section for fixups and just placing them in some other section with DATA directive. However, it should be noted that this might create problems with some other PE loaders, like in Win9x, which may still frown upon empty fixups table. For this reason the recommended idiom to ensure that fasm always generates some non-zero-length data for fixups looks like this: Code: section '.reloc' fixups data readable discardable if $=$$ dd 0,8 ; if there are no fixups, generate dummy entry end if On a side note, while I was writing my PE tutorial, I did a bit more research, and I discovered that implementation of PE loader in Win32s was accepting both empty sections and empty fixup data. |
|||
23 Apr 2020, 10:15 |
|
mns 23 Apr 2020, 10:44
Thank you very much Tomasz Grysztar for your kind reply and the links. I changed the code according to your example and it resolved the problem.
Also thank you very much revolution for your kind reply and the suggestions. |
|||
23 Apr 2020, 10:44 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.