News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Automation the creation of inc-, def- and lib-files

Started by Mikl__, July 10, 2017, 03:42:47 PM

Previous topic - Next topic

nidud

#15
deleted

aw27

Quote from: jj2007 on July 10, 2017, 10:56:51 PM
Not only - I used my own tool, it extracts the stuff from the 32-bit DLLs. Does anybody have code using the 64-bit DLLs?

I remembered now what you have to do in relationship with expdef: Just build expdef for 64-bit
That's all. The reason is that only a 64-bit exe can load a 64-bit dll.

Vortex


aw27

In my perspective, the real pain with the manufacture of stdcall import libraries has to do with the name decoration (for example LoadLibraryA@4) which, as far as I know, has to be done by hand unless the functions are dllexported. MASM expects name decoration in order to use Invoke.
But if you use other assemblers like UASM or JWASM, name decoration can be waved with the switch -zt1 (or even -zt0 without the underscore).

Vortex

Hi aw27,

With some macro tricks and new import libraries, it's possible to reduce the level of decoration of Masm object modules :

\PellesC\bin\polib /OUT:kernel32.lib /MACHINE:X86 %windir%\system32\kernel32.dll

\PellesC\bin\polib /OUT:user32.lib /MACHINE:X86 %windir%\system32\user32.dll


    _invoke GetModuleHandle,NULL
    mov     hInstance,eax
    _invoke GetCommandLine
    mov     CommandLine,eax
    _invoke WinMain, hInstance,NULL,CommandLine,SW_SHOWDEFAULT
    _invoke ExitProcess,eax


\masm32\bin\dumpbin.exe /SYMBOLS Window.obj > Symbols.txt

00B 00000000 UNDEF  notype ()    External     | _ExitProcess
00C 00000000 UNDEF  notype ()    External     | _GetCommandLineA
00D 00000000 UNDEF  notype ()    External     | _GetModuleHandleA
00E 00000000 UNDEF  notype ()    External     | _CreateWindowExA
00F 00000000 UNDEF  notype ()    External     | _DefWindowProcA
010 00000000 UNDEF  notype ()    External     | _DispatchMessageA
011 00000000 UNDEF  notype ()    External     | _GetMessageA
012 00000000 UNDEF  notype ()    External     | _LoadCursorA
013 00000000 UNDEF  notype ()    External     | _LoadIconA
014 00000000 UNDEF  notype ()    External     | _PostQuitMessage
015 00000000 UNDEF  notype ()    External     | _RegisterClassExA
016 00000000 UNDEF  notype ()    External     | _ShowWindow
017 00000000 UNDEF  notype ()    External     | _TranslateMessage
018 00000000 UNDEF  notype ()    External     | _UpdateWindow
019 00000000 SECT3  notype       Static       | hInstance
01A 00000000 SECT1  notype ()    External     | _start
01B 00000009 SECT2  notype       Static       | AppName

jj2007

Quote from: aw27 on July 11, 2017, 12:04:35 AMI remembered now what you have to do in relationship with expdef: Just build expdef for 64-bit
That's all. The reason is that only a 64-bit exe can load a 64-bit dll.

"Just build" is a bit more complicated. If you want to have a look, source is attached.
Or drag a bunch of DLLs over the exe and see the exports. It might choke if you drag more than ca 700 DLLs, though.

Vortex

Processing Masm object files with an external tool and removing completely the decorations :

\PellesC\bin\polib /OUT:kernel32.lib /NOUND /MACHINE:X86 %windir%\system32\kernel32.dll

\PellesC\bin\polib /OUT:user32.lib /NOUND /MACHINE:X86 %windir%\system32\user32.dll

\masm32\bin\ml /c /coff Window.asm
undecor Window.obj
\masm32\bin\polink /SUBSYSTEM:WINDOWS Window.obj


No need of macros in this method.

aw27

Quote from: Vortex on July 11, 2017, 05:21:34 AM
With some macro tricks and new import libraries, it's possible to reduce the level of decoration of Masm object modules :

Hi Vortex,
Sure, but I was talking about Invoke not about any macro.  :icon_exclaim:

aw27

Quote from: jj2007 on July 11, 2017, 05:25:35 AM
"Just build" is a bit more complicated. If you want to have a look, source is attached.

It is not more complicated. You used a different approach than ExpDef used and I was talking about ExpDef. :icon_exclaim:

Vortex

Hi aw27,

My method based on object file undecoration with undecor.exe does not depend on any macros.

aw27

Quote from: Vortex on July 11, 2017, 05:36:49 AM
Processing Masm object files with an external tool and removing completely the decorations :

Postprocessing does the trick. Conclusion: there is always a workaround. :t

jj2007

Just curious: How do you get the info for the PROTO, i.e. size/type+number of paras?

aw27

Quote from: jj2007 on July 11, 2017, 07:02:36 AM
Just curious: How do you get the info for the PROTO, i.e. size/type+number of paras?
If is not there, i.e, if it does not appear in dumpbin there is no direct way. Hence, there is a lot of manpower involved if you are dealing with a big dll like kernel32.dll

PS: Sorry, I don't think that you asked for this - I answered what I thought was in the context. The Info for the PROTO you get from the usual Microsoft channels, namely searching the web for the declarations.

Mikl__


Mikl__

#29
Bat-file to create user32.inc from user32.txtSet FileName = user32
For / f "skip=16 tokens=1-4" %%a in (%FileName%.txt) do (
@echo extern __imp_%%d:qword >>%FileName%.inc
@echo %%d TEXTEQU ^<__imp_%%d^> >>%FileName%.inc
)
Bat-file to create user32.def from user32.txtSet FileName = user32
@echo EXPORTS >>%FileName%.def
For / f "skip=16 tokens=1-4" %%a in (%FileName%.txt) do @echo %%d= __imp_%%d >>%FileName%.def
Skip=16 skip the first 16 lines in user32.txtDump of file C:\Windows\System32\user32.dll
File Type: DLL
  Section contains the following exports for USER32.dll
    00000000 characteristics
    4CE799CD time date stamp Sat Nov 20 17:50:05 2010
        0.00 version
        1500 ordinal base
        1003 number of functions
         830 number of names
    ordinal hint RVA      name
       1502    0 000083C0 ActivateKeyboardLayout <-- useful information starts here
^<__imp_%%d^> I escape the control characters "<" and ">" so that the bat-file perceives them as ordinary characters.
True, it is not yet possible to get from the lines1500      0002B260 [NONAME]Create strings in user32.defUser32_ordinal1500 = ordinal1500 @ 1500 NONAMEAnd user32.incextern __imp_user32_ordinal1500:qword
user32_ordinal1500 TEXTEQU <__imp_user32_ordinal1500>