The MASM Forum

Projects => ObjAsm => Topic started by: Biterider on November 28, 2021, 08:13:21 PM

Title: MASM Projection
Post by: Biterider on November 28, 2021, 08:13:21 PM
Hi
As you have probably noticed, the latest Windows kits contain many .winmd files. These files describe the Windows Runtime API in a binary form that is described by the ECMA-335 standard. The MS description is here https://docs.microsoft.com/en-us/uwp/winrt-cref/winmd-files#:~:text=of%20this%20document.-,WinMD%20files,-WinMD%20file%20format (https://docs.microsoft.com/en-us/uwp/winrt-cref/winmd-files#:~:text=of%20this%20document.-,WinMD%20files,-WinMD%20file%20format)

Winmd stands for Windows Metadata. I digged deeper into the topic and fearless pointed out that a simpler version of these files as JSON files is available here https://github.com/marlersoft/win32json (https://github.com/marlersoft/win32json)
The idea behind the winmd files is to create so-called projections for many different languages. These projections should allow access to the Windows Runtime API.
In theory, this information can also be used for MASM to create a set of include files to replace Windows.inc with a more recent version.
Since interpreting JSON files is much easier, I started a pilot project called MasmProjector to get the job done.

I found a few issues in the JSON files and some I'm not sure where they are from
  1. There is no structure alignment information available
  2. Type references often point to “ApiRef”, with no further information if the type is a native type or a structure/union.
  3. There are obvious translation errors (see picture).
  4. There is no clear hierarchy of file inclusion (may be some deeper C# knowledge is required)
  5. There is no information about function decoration for 32 bit.

Point 2 can be solved with a first pass to collect all information in a sort of database in order to resolve the missing information on the second pass. To do this, point 4 must be solved.
If enough information is known about the structures and other types, point 5 can also be solved.
On the other hand, this can only be done with knowledge of the correct internal alignment (point 1), which is not provided.

After playing with the JSON files, I'm no longer sure if this is the right way to go. This intermediate translation into JSON files introduces its own problems. Perhaps in the future this project will become more mature to use.

It seems to me that decompiling the winmd files without additional tools is a huge undertaking. In my opinion, the best way to create a MASM set of API include files is currently to parse the C header files as good as possible.

I am attaching the pilot project and some of the translated files as a reference.
Please note that they are only intended to see how the projection can be done.

Biterider

PS: I used a very handy tool for visualizing and editing JSON files called cJSONTree, which is available here https://github.com/mrfearless/cjsontree (https://github.com/mrfearless/cjsontree)

 
Title: Re: MASM Projection
Post by: jj2007 on November 29, 2021, 03:33:25 AM
Good intentions, biterider... we are counting on you ;-)

I had my own C to Masm project, as several people over here, and currently feel absolutely no enthusiasm in finalising it. It's so much easier to indulge in crappy conspiration theories around the coronavirus.

64-bit Assembly suffers from too many actors pursuing too many roads. And they are all tired...