Author Topic: Automation the creation of inc-, def- and lib-files  (Read 1158 times)


aw27

  • Member
  • ****
  • Posts: 854
  • Let's Make ASM Great Again!
Re: Automation the creation of inc-, def- and lib-files
« Reply #16 on: July 11, 2017, 12:04:35 AM »
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

  • Member
  • *****
  • Posts: 1731
Re: Automation the creation of inc-, def- and lib-files
« Reply #17 on: July 11, 2017, 03:22:35 AM »
Hi Mikl__,

Here is a tool to create import libraries from module definition files :

Module definition file to MS COFF import library converter

aw27

  • Member
  • ****
  • Posts: 854
  • Let's Make ASM Great Again!
Re: Automation the creation of inc-, def- and lib-files
« Reply #18 on: July 11, 2017, 04:34:38 AM »
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

  • Member
  • *****
  • Posts: 1731
Re: Automation the creation of inc-, def- and lib-files
« Reply #19 on: July 11, 2017, 05:21:34 AM »
Hi aw27,

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

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

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

Code: [Select]
    _invoke GetModuleHandle,NULL
    mov     hInstance,eax
    _invoke GetCommandLine
    mov     CommandLine,eax
    _invoke WinMain, hInstance,NULL,CommandLine,SW_SHOWDEFAULT
    _invoke ExitProcess,eax

Code: [Select]
\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

  • Member
  • *****
  • Posts: 7752
  • Assembler is fun ;-)
    • MasmBasic
Re: Automation the creation of inc-, def- and lib-files
« Reply #20 on: July 11, 2017, 05:25:35 AM »
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.

"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

  • Member
  • *****
  • Posts: 1731
Re: Automation the creation of inc-, def- and lib-files
« Reply #21 on: July 11, 2017, 05:36:49 AM »
Processing Masm object files with an external tool and removing completely the decorations :

Code: [Select]
\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

  • Member
  • ****
  • Posts: 854
  • Let's Make ASM Great Again!
Re: Automation the creation of inc-, def- and lib-files
« Reply #22 on: July 11, 2017, 05:46:50 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

  • Member
  • ****
  • Posts: 854
  • Let's Make ASM Great Again!
Re: Automation the creation of inc-, def- and lib-files
« Reply #23 on: July 11, 2017, 05:49:46 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

  • Member
  • *****
  • Posts: 1731
Re: Automation the creation of inc-, def- and lib-files
« Reply #24 on: July 11, 2017, 06:06:04 AM »
Hi aw27,

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

aw27

  • Member
  • ****
  • Posts: 854
  • Let's Make ASM Great Again!
Re: Automation the creation of inc-, def- and lib-files
« Reply #25 on: July 11, 2017, 06:38:09 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

  • Member
  • *****
  • Posts: 7752
  • Assembler is fun ;-)
    • MasmBasic
Re: Automation the creation of inc-, def- and lib-files
« Reply #26 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?

aw27

  • Member
  • ****
  • Posts: 854
  • Let's Make ASM Great Again!
Re: Automation the creation of inc-, def- and lib-files
« Reply #27 on: July 11, 2017, 07:13:51 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__

  • Member
  • ****
  • Posts: 555
Re: Automation the creation of inc-, def- and lib-files
« Reply #28 on: July 11, 2017, 07:46:43 AM »
Hi Erol,
nice work. Thank you very much!

Mikl__

  • Member
  • ****
  • Posts: 555
Re: Automation the creation of inc-, def- and lib-files
« Reply #29 on: July 22, 2017, 11:29:23 AM »
Bat-file to create user32.inc from user32.txt
Code: [Select]
Set 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.txt
Code: [Select]
Set 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.txt
Code: [Select]
Dump 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 lines
Code: [Select]
1500      0002B260 [NONAME]Create strings in user32.def
Code: [Select]
User32_ordinal1500 = ordinal1500 @ 1500 NONAMEAnd user32.inc
Code: [Select]
extern __imp_user32_ordinal1500:qword
user32_ordinal1500 TEXTEQU <__imp_user32_ordinal1500>
« Last Edit: July 22, 2017, 01:51:33 PM by Mikl__ »