flat assembler
Message board for the users of flat assembler.

Index > Windows > [solved] DLL error. error satus 0xc000007b

Author
Thread Post new topic Reply to topic
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
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. Shocked
Hope someone can help. Sad

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
;=======================================================================================================     
    


Description:
Filesize: 200.02 KB
Viewed: 4222 Time(s)

error.PNG


Description:
Download
Filename: testDLLSTR.ASM
Filesize: 2.3 KB
Downloaded: 496 Time(s)

Description: DLL file
Download
Filename: StrFuncDLL.ASM
Filesize: 4.95 KB
Downloaded: 503 Time(s)

Post 23 Apr 2020, 09:56
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 23 Apr 2020, 10:04
I notice your numbToStr function only uses "ret 4" but you push 2 parameters on the stack.

You can use the "proc" macro to help you here. Define numbToStr using proc stdcall with the input parameters, then you can use the ret macro to automatically restore everything.
Post 23 Apr 2020, 10:04
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
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    
This snippet is present in EXAMPLES\WIN64\DLL\WRITEMSG.ASM (because in 64-bit world it is much more common to have a completely position-independent code that does not require relocation entries), but it is not in EXAMPLES\DLL\ERRORMSG.ASM. Perhaps I should correct that, because - as demonstrated here - having a 32-bit DLL without fixups is not completely out of ordinary.

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.
Post 23 Apr 2020, 10:15
View user's profile Send private message Visit poster's website Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
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.
Post 23 Apr 2020, 10:44
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.