Author Topic: h2incX  (Read 187 times)

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 207
  • ObjAsm32 - ObjAsm64
    • ObjAsm64
h2incX
« on: June 30, 2018, 06:30:07 PM »
Today is the time to show what's under the hood in the new h2incX project.
It took me some time to analyse the Japheth’s original code. It became clear to me that this project was in a phase where code was still being tested and some other routines were not finished yet.
I decided not to modify the core of how the program was originally designed, but changed the code where necessary to add some necessary new features, such as parsing of annotations and some bug fixes.

Purpose:
This tool is a Win32 console application, whose purpose is to convert C header files to MASM-style include files. A private profile file is used to fine-tune the include files to be created.
Huge C header sets can be converted in one run, for example the Win32 headers in the "Windows Kits" or "PSDK".
Prototypes can be written so that the include file is suitable for dynamic linking to a DLL, using the IAT entries, as well as for static linking to a library.
Optionally, a .DEF file can be written to generate an import library.

Features and limitations
h2incX is very reliable, but it is not perfect. Without a full-fledged C-precompiler/compiler, manual intervention will always be required.
It should be noted that some C header file declarations simply cannot be translated into ASM. For example, there are no things like inline functions in ASM for example.
On some situations h2incx has to "count" braces. This can interfere with “#if“ pre-processor commands, because h2incX cannot evaluate expressions in these commands. As a result, h2incX can become confused and produces incorrect code.
h2incX has some limited knowledge about C++, but its original purpose was to convert C headers. So some C++ specific keywords can confuse h2incX. This also applies to templates.
"far" and "near" qualifiers are skipped, so this tool does not work for 16bit includes.
The current MASM / UASM implementation treats the conditional compile statement "if" differently than the C equivalent “#if”. Therefore, some problems may occur when symbols are undefined.

Result
I took the latest Kit for Win10 and translated all the .h files following the inclusion tree, starting with Windows.h. Unfortunately, the resulting .zip file containing the generated .inc files exceeds the allowed quota of the forum, so I am forced to put the .zip file on an alternative server. The download can be started here: http://objasm.x10host.com/DwnFiles/Inc.zip

Final notes
The source code is attached to this post. To avoid confusion, I have restarted the h2incX versioning with "B.01.00".
The original code used some pseudo-OO constructs, which I replaced with ObjAsm32 code. This change allowed much better handling of internal lists. The output of its contents is copied to .lst files for better verification of results.
Memory management has also been streamlined, but the core idea of how the information is stored remains the same.


I checked the result with some x64 projects and quickly found that more .h files needed a translation, for example CommCtrl.h. Based on this experience, if someone notices missing files, please report it here, so it can be added to the distribution.

Regards, Biterider


Vortex

  • Member
  • *****
  • Posts: 1807
Re: h2incX
« Reply #1 on: June 30, 2018, 07:16:54 PM »
Hi Biterider,

Thanks for your tool. Trying your include file set, I received the following error messages :

Code: [Select]
Assembling: SimpleWnd.asm
H:\inc\crtdefs.inc(22) : error A2045: missing angle bracket or brace in literal
H:\inc\vadefs.inc(9) : error A2045: missing angle bracket or brace in literal
H:\inc\stdarg.inc(9) : error A2045: missing angle bracket or brace in literal
H:\inc\winnt.inc(753) : error A2008: syntax error : POINTER
H:\inc\winnt.inc(754) : error A2008: syntax error : POINTER
H:\inc\winnt.inc(761) : error A2008: syntax error : POINTER
H:\inc\winnt.inc(4260) : error A2008: syntax error : POINTER
H:\inc\winnt.inc(5103) : error A2008: syntax error : POINTER
H:\inc\winnt.inc(5199) : error A2008: syntax error : POINTER
H:\inc\winnt.inc(5353) : error A2008: syntax error : TokenUser
H:\inc\winnt.inc(5516) : error A2008: syntax error : TokenSource
H:\inc\winnt.inc(5588) : error A2041: string or text literal too long
H:\inc\winnt.inc(5599) : error A2008: syntax error : POINTER
H:\inc\winnt.inc(5784) : error A2008: syntax error : POINTER
H:\inc\winnt.inc(5790) : error A2008: syntax error : POINTER
H:\inc\winnt.inc(5803) : error A2008: syntax error : POINTER
H:\inc\winnt.inc(6445) : error A2041: string or text literal too long
H:\inc\winnt.inc(7021) : error A2006: undefined symbol : POINTER
H:\inc\winnt.inc(10552) : error A2008: syntax error : POINTER
H:\inc\winnt.inc(10595) : error A2159: structure cannot be instanced
H:\inc\winnt.inc(11092) : error A2008: syntax error : POINTER
H:\inc\winnt.inc(11164) : error A2008: syntax error : POINTER
H:\inc\winnt.inc(11165) : error A2159: structure cannot be instanced
H:\inc\winnt.inc(11183) : error A2041: string or text literal too long
H:\inc\winnt.inc(11685) : error A2041: string or text literal too long
H:\inc\ktmtypes.inc(84) : error A2179: structure improperly initialized
H:\inc\ktmtypes.inc(84) : error A2008: syntax error : in type
H:\inc\ktmtypes.inc(107) : error A2179: structure improperly initialized
H:\inc\ktmtypes.inc(107) : error A2008: syntax error : in type
H:\inc\ktmtypes.inc(116) : error A2179: structure improperly initialized
H:\inc\ktmtypes.inc(116) : error A2008: syntax error : in type
H:\inc\ktmtypes.inc(138) : error A2179: structure improperly initialized
H:\inc\ktmtypes.inc(138) : error A2008: syntax error : in type
H:\inc\winnt.inc(12088) : error A2179: structure improperly initialized
H:\inc\winnt.inc(12088) : error A2008: syntax error : in type
H:\inc\winnt.inc(12095) : error A2159: structure cannot be instanced
H:\inc\winnt.inc(12182) : error A2008: syntax error : POINTER
H:\inc\minwinbase.inc(251) : error A2008: syntax error : POINTER
H:\inc\libloaderapi.inc(32) : error A2008: syntax error : POINTER
H:\inc\securitybaseapi.inc(35) : error A2041: string or text literal too long
H:\inc\wingdi.inc(863) : error A2085: instruction or register not accepted in cu
rrent CPU mode
H:\inc\wingdi.inc(2954) : error A2008: syntax error : POINTER
H:\inc\wingdi.inc(2968) : error A2008: syntax error : POINTER
H:\inc\wingdi.inc(3106) : error A2008: syntax error : POINTER
H:\inc\wingdi.inc(3107) : error A2008: syntax error : POINTER
H:\inc\wingdi.inc(3108) : error A2008: syntax error : POINTER
H:\inc\wingdi.inc(3120) : error A2008: syntax error : POINTER
H:\inc\wingdi.inc(3121) : error A2008: syntax error : POINTER
H:\inc\wingdi.inc(3122) : error A2008: syntax error : POINTER
H:\inc\winuser.inc(232) : error A2131: VARARG parameter requires C calling conve
ntion
 @DefProto(2): Macro Called From
  H:\inc\winuser.inc(232): Include File
H:\inc\winuser.inc(233) : error A2131: VARARG parameter requires C calling conve
ntion
 @DefProto(2): Macro Called From
  H:\inc\winuser.inc(233): Include File
H:\inc\winuser.inc(570) : error A2008: syntax error : POINTER
H:\inc\winuser.inc(577) : error A2008: syntax error : POINTER
H:\inc\winuser.inc(6026) : error A2006: undefined symbol : _WIN32_WCE
H:\inc\winuser.inc(6133) : error A2006: undefined symbol : _WIN32_WCE
H:\inc\mmsyscom.inc(192) : error A2006: undefined symbol : HDRVR
H:\inc\mmsyscom.inc(192) : error A2195: parameter or local cannot have void type

H:\inc\mmsyscom.inc(192) : error A2129: VARARG parameter must be last parameter
H:\inc\mmiscapi.inc(113) : error A2006: undefined symbol : HDRVR
H:\inc\mmiscapi.inc(113) : error A2195: parameter or local cannot have void type

H:\inc\mmiscapi.inc(113) : error A2129: VARARG parameter must be last parameter
H:\inc\mmiscapi.inc(117) : error A2006: undefined symbol : HDRVR
H:\inc\mmiscapi.inc(117) : error A2195: parameter or local cannot have void type

H:\inc\mmiscapi.inc(117) : error A2129: VARARG parameter must be last parameter
H:\inc\playsoundapi.inc(29) : error A2006: undefined symbol : FALSE_
H:\inc\playsoundapi.inc(29) : error A2195: parameter or local cannot have void t
ype
H:\inc\playsoundapi.inc(29) : error A2131: VARARG parameter requires C calling c
onvention
H:\inc\playsoundapi.inc(71) : error A2006: undefined symbol : FALSE_
H:\inc\playsoundapi.inc(71) : error A2195: parameter or local cannot have void t
ype
H:\inc\playsoundapi.inc(71) : error A2131: VARARG parameter requires C calling c
onvention
H:\inc\mmeapi.inc(54) : error A2008: syntax error : POINTER
H:\inc\mmeapi.inc(720) : error A2008: syntax error : POINTER
H:\inc\nb30.inc(36) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(74) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(154) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(159) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(201) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(587) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(589) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(591) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(602) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(604) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(606) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(646) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(650) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(651) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(657) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(661) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(662) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(669) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(673) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(674) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(675) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(677) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(683) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(687) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(688) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(689) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(691) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(703) : error A2008: syntax error : POINTER
H:\inc\rpcdce.inc(704) : fatal error A1012: error count exceeds 100; stopping assembly

Attached is the example project. It can be assembled with WinInc209 offered by johnsa and habran.

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 207
  • ObjAsm32 - ObjAsm64
    • ObjAsm64
Re: h2incX
« Reply #2 on: June 30, 2018, 09:32:01 PM »
Hi Vortex
Thank you for your feedback.  :t
I will take a look at it.

Biterider

LiaoMi

  • Member
  • **
  • Posts: 242
Re: h2incX
« Reply #3 on: July 01, 2018, 03:16:53 AM »
Hi Biterider,

I tried to rebuild an example for x64 from Vortex, somewhere there is a bug in the code for x64, I have not looked at yet where. The executable file was compiled with sdk from ToutEnMasm, in addition there is a file with errors that occurs during build with h2incX incs.


habran

  • Member
  • *****
  • Posts: 1168
    • uasm
Re: h2incX
« Reply #4 on: July 02, 2018, 08:39:05 AM »
Hi Biterider :biggrin:
You are doing a great job :t
I have looked in ole2.inc and found some functions without @DefProto, EG:
   
Code: [Select]
IsAccelerator proto fastcall :HACCEL, :DWORD, :LPMSG, :ptr WORDwhich are in WinInc expressed as:
   
Code: [Select]
@DefProto WINOLEAPI, IsAccelerator, stdcall, , <:HACCEL, :DWORD, :LPMSG, :ptr WORD>, 16I am afraid that your version will not work for 32bit because of fastcall convention, however, I might be wrong.
Anyway, I understand how much effort you have put in that project and appreciate very much your work :eusa_clap:

Ones when we get it done, we should think about adding C++ compiler to that code ;)
Cod-Father

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 207
  • ObjAsm32 - ObjAsm64
    • ObjAsm64
Re: h2incX
« Reply #5 on: July 05, 2018, 05:02:04 AM »
Hi
Short feedback: I found some minor issues and the cause of the wrong prototyping. A C-macro interferes with the detection of the import specification.
I will try to stay as close as possible to the original C version by using a masm macro.
I was able to build Vortex Test App and some of mine. For that, I had to translate more header files, which showed me more problems, that I did not see before.
I will need some time to fix this.  :icon_rolleyes:

Biterider