Problem with export and with the SIZEOF macro / structures

Started by Baboon, March 13, 2008, 05:18:00 PM

Previous topic - Next topic

Baboon

Hi, i use goasm for few month and i'm very happy about it
but i have encountred some problems (with the most recents version of GoTool) :

1] I have tried to export some function to create a .dll but no methods seems to work

in GoAsm :

EXPORT MyFunction:
mycode

EXPORTS Function1 , Function2 , Function3

and in GoLink:

/EXPORTS Function1 , Function2 , Function3
/EXPORT Function1

in goasm, EXPORT and EXPORTS do nothing and in golink /EXPORT and /EXPORTS return this error :
The following exported symbols were not defined in the object file or files:-
MyFunction1
MyFunction2
etc ..

while my functions are correctly defined ...
(MyFunction:
    mycode [..])

2] I wrote a very simple program which create a window, to create a window i used the RegisterClassExA API which take  a WNDCLASSEXA structure in parameter.
I have written this structure :

WNDCLASSEXA Struct
    cbSize DD
    style DD
    lpfnWndProc DD
    cbClsExtra DD
    cbWndExtra DD
    hInstance DD
    hIcon DD
    hCursor DD
    hbrBackground DD
    lpszMenuName DD
    lpszClassName DD
    hIconSm DD
EndS

but when i use it :
wc WNDCLASSEXA {cbSize = SIZEOF WNDCLASSEXA, [...]  }

Goasm decale the structure and my structure become in debugger :
WNDCLASSEXA Struct
    cbSize DB
    style DD
    lpfnWndProc DD
    cbClsExtra DD
    cbWndExtra DD
    hInstance DD
    hIcon DD
    hCursor DD
    hbrBackground DD
    lpszMenuName DD
    lpszClassName DD
    hIconSm DD
EndS

(if I do a "mov eax , [wc.cbSize]" , eax = 0x30000000 instead of 0x30 and all the others initialized datas are decaled)

I have tried to declare my structure this way :
WNDCLASSEXA Struct
    cbSize DD SIZEOF WNDCLASSEXA
    style DD
    lpfnWndProc DD
    cbClsExtra DD
    cbWndExtra DD
    hInstance DD
    hIcon DD
    hCursor DD
    hbrBackground DD
    lpszMenuName DD
    lpszClassName DD
    hIconSm DD
EndS

but i have the same result ....
I have been forced to do a "mov [wc.cbSize] , SIZEOF WNDCLASSEXA" ...

In an other programm a "StartupInfo STARTUPINFOA {cb = SIZEOF STARTUPINFO}" have worked without any problem
:dazzled:

So

I would like to know how to correctly export my function and signal this problem

I like Goasm and I don't want to change for an other assembler but those problems are very time consuming

(excuse my poor/bad english)

jorgon

Hi Baboon

Welcome to the forum.
I'm sorry you are having trouble with GoAsm



As for the EXPORT problem, something is wrong but I don't know what.

If you define an EXPORT in your source code sent to GoAsm, then it might appear as if nothing is happening but in fact GoAsm inserts information in the object file about the export (in the .drectve section) and at link-time GoLink will be aware of the export from this.  There is no need to define the EXPORT in GoLink's command line or file again.  However you can specify the export to GoLink if you prefer, instead of defining the export in your source code.

There could be various reasons for your error code from GoLink (export function not found), maybe the function was not spelt correctly or a letter not the correct case, or something in your source causing your function to be jumped over (maybe it was commented out?).  Sorry to be simplistic about this, but it could be one explanation.  Could I suggest that either you post your full source here or send it to me by private message (not just an excerpt) so I can check this, alternatively could I suggest that you obtain a tool which can look inside the obj file and the final dll, such as Wayne Radburrn's excellent PEView available from here.  That is capable of showing you the .drectve section in the obj file (so you can check that GoAsm is indicating there that there is an export) and it can also show the .edata section in the dll (showing the actual export).  It will also show the symbol table in the obj file so you can check what code and data labels have been identified by GoAsm.



As for the SIZEOF structure problem, I've just tried this and it does not happen in my tests.

Do you think it is possible that your line
wc WNDCLASSEXA {cbSize = SIZEOF WNDCLASSEXA, [...]  }
is not dword aligned?

If, so then GoAsm will add padding to align it onto a dword.  It is possible that depending on which debugger you are using, that might appear as if GoAsm is inserting a DB.
However, the structure itself should be intact and correct (all dwords).

For example, in GoBug if there is one byte of padding the resulting structure appears as:-


wc
00
wc.cbSize
30000000
wc.style
00000000
wc.lpfnWndProc
00000000


and so on ..

If this is not the problem, I would be very grateful if you could send me the source where this error occurs so that I can try to identify the problem.

Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

Baboon

Hi Jorgon thank you for your reply

QuoteDo you think it is possible that your line
wc WNDCLASSEXA {cbSize = SIZEOF WNDCLASSEXA, [...]  }
is not dword aligned?

If, so then GoAsm will add padding to align it onto a dword.  It is possible that depending on which debugger you are using, that might appear as if GoAsm is inserting a DB.
However, the structure itself should be intact and correct (all dwords).
My structure wasn't dword aligned ...
When i place a "align 4" before it , it work

BUT

It is very strange that goasm align my strucutre without tell me anything
"push addr wc" and "push addr wc.cbSize" should be the same instruction but goasm change my structure like that :

WNDCLASSEXA Struct
    align 4
    cbSize DD
    style DD
    lpfnWndProc DD
    cbClsExtra DD
    cbWndExtra DD
    hInstance DD
    hIcon DD
    hCursor DD
    hbrBackground DD
    lpszMenuName DD
    lpszClassName DD
    hIconSm DD
EndS

So if my structure wasn't aligned , wc.cbSize and wc are not at the same place ...

finally if I don't align my structure and i initialize the cbSize field in the code (with a "mov d [wc.cbSize] , SIZEOF WNDCLASSEXA") all work perfectly
and my "push addr wc" is transform in a "push addr wc.cbSize" after verification in ollydbg and its scanner of .obj

Now I know that goasm align my structure and insert an "align field" wich decale all my other fields.


QuoteIf you define an EXPORT in your source code sent to GoAsm, then it might appear as if nothing is happening but in fact GoAsm inserts information in the object file about the export (in the .drectve section) and at link-time GoLink will be aware of the export from this.  There is no need to define the EXPORT in GoLink's command line or file again.  However you can specify the export to GoLink if you prefer, instead of defining the export in your source code.
I have read your documentation so i know this :P
I have tested all the differents methods (but not at the same time of course ;) ) and i have had the results you can see in my previous post

Quotemaybe the function was not spelt correctly or a letter not the correct case, or something in your source causing your function to be jumped over (maybe it was commented out?).  Sorry to be simplistic about this, but it could be one explanation.
No problem ;)
I understand you ask this questions but I have verified (and re-verified ..) all my code and labels and there is no problem of this type

And when I do an "EXPORTS MyFunction1 , MyFunction2 , etc .." i have no error

QuoteCould I suggest that either you post your full source here or send it to me by private message (not just an excerpt) so I can check this
It is a little bit delicate, this code a personnal one but i will look my .obj with the Wayne Radburrn's PEView

I will post results of my investigation
:bg




Baboon

Hi , I'm back

This is what i have with the pe view (i have this image with all the method of export) :


there is apparently a problem with the file header or it is a problem from the pe view

If I do a EXPORTS Myfunction1 , Myfunction2 , at the begining of my code , the dll is linked "correctly" but i have no imports too
:/


moreover my entry point is not detected

So i think there is a problem with goasm wich doesn't correctly create the .obj


[EDIT] When the dll is linked, the only sections i have are .reloc and .rsrc, no .text sections, no .data, no .idata

wjr

Seems like you may have a file Sechel-Inj.asm which becomes Sechel-Inj.obj when assembled, but also a resource file Sechel-Inj.rc which compiled with the GoRC /o option will also output Sechel-Inj.obj overwriting the first one. If this is the case, either use the /fo option to name the output resource file differently, or use the /r option for a res file, and then link with this new obj or res file instead.

As for the PEview error, it seems unlikely that the Time Date Stamp would cause such a problem, so I would be interested in the DWORD at file offset 4.

Thanks,
WJR

jorgon

Baboon

QuoteSo if my structure wasn't aligned , wc.cbSize and wc are not at the same place ...

You're right!

This was a bug, GoAsm adjusts any labels if it adds padding for alignment, but in the structure using the SIZEOF itself was throwing this out.

I attach the fix for this problem (GoAsm 56.04c) ..



[attachment deleted by admin]
Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

jorgon

Baboon

QuoteSo i think there is a problem with goasm wich doesn't correctly create the .obj

The screenshot from PEView definitely shows a "resource-only" object file (which would not have been made by GoAsm), most likely made by a resource compiler.  If you are using the GoRC resource compiler, it will create a res file and an obj file (using the name of the .rc file) unless you tell it not to.  So WJR may be right in his guess about that.

But one thing is very strange.  There is something wrong with the format of obj file (as found with PEView).  I've just tested GoRC and it produces an obj file correctly.  Could you let me know what program created this object file and using what source information?

Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

Baboon

Hi

Sorry to answer so late ...

effectively, GoRc create a .res file AND a .obj file which overwrite the first one created by GoAsm ....
I use the /r option now and all is all right ;)

I'm confused ....

Quote from: jorgonYou're right!

This was a bug, GoAsm adjusts any labels if it adds padding for alignment, but in the structure using the SIZEOF itself was throwing this out.

I attach the fix for this problem (GoAsm 56.04c) ..

Thank you ;)

I'm happy to help GoAsm and its creator  :P