Author Topic: Asmc source and binaries  (Read 799 times)

powershadow

  • Regular Member
  • *
  • Posts: 11
Re: Asmc source and binaries
« Reply #15 on: January 16, 2017, 07:55:04 PM »
Confirmed.

Quotes in command line arguments are not expanded in the same way in the RTL now used, so additional expansion was needed for switch -D, -I and -Fi used with -I"quoted text".

Wow so fast, this project has better support then hjwasm! :t
Nidud, may I request a feature?
Can you add to the listing file (/Fl), dump for all used procedure protos.
Example:

Code: [Select]
...
.NOLIST
Include kernel32.inc
...
.code

TestProc1 proc Par1:HANDLE,Par2:DWORD,Par3:PVOID
xor eax,eax
ret

TestProc1 endp

start:

invoke CreateFile,SADD('file.txt'),GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
invoke TestProc1,eax,11111111h,NULL
invoke ExitProcess,0
end start

Listing file:
...
Procedures protos:

                N a m e                 PROTO

TestProc1  . . . . . . . . . . .        PROTO Par1:HANDLE, Par2:DWORD, Par3:PVOID
CreateFileA  . . . . . . . . . .        PROTO lpFileName:PSTR ,dwDesiredAccess:DWORD ,dwShareMode:DWORD ,lpSecurityAttributes:PVOID ,dwCreationDisposition:DWORD ,dwFlagsAndAttributes:DWORD ,hTemplateFile:HANDLE
ExitProcess  . . . . . . . . . .        PROTO uExitCode:DWORD
...

Where TestProc1 generated from source, CreateFileA & ExitProcess - just copy used proto from inc file.

nidud

  • Member
  • *****
  • Posts: 1067
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #16 on: January 17, 2017, 03:12:40 AM »
Nidud, may I request a feature?
Can you add to the listing file (/Fl), dump for all used procedure protos.

Unused functions have a '*' added to the list if that helps:
Code: [Select]
.386
.model flat,stdcall
.code

foo proto
bar proto

foo()

END

Code: [Select]
Procedures, parameters and locals:

                N a m e                 Type     Value    Segment  Length

bar  . . . . . . . . . . . . . .        P Near32 00000000 No Seg   00000000 *External STDCALL
foo  . . . . . . . . . . . . . .        P Near32 00000000 No Seg   00000000 External  STDCALL

powershadow

  • Regular Member
  • *
  • Posts: 11
Re: Asmc source and binaries
« Reply #17 on: January 17, 2017, 03:21:56 AM »
Unused functions have a '*' added to the list if that helps:
Thanks for reply nidud, unfortunately it's not help :(. I need PROTOs

nidud

  • Member
  • *****
  • Posts: 1067
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #18 on: January 17, 2017, 03:48:16 AM »
Well, I can see the usefulness of this and the information to compile the list may also be available, so I may look into this someday.

nidud

  • Member
  • *****
  • Posts: 1067
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #19 on: March 02, 2017, 08:08:18 AM »
Some imort libraries are added to the source base. I was hoping to do this the simple way by target the .dll files directly, at least the 64-bit without any decoration.
Code: [Select]
32 libw /n /c /l /b /fac /ii version.lib %windir%\system32\version.dll
64 libw /n /c /l /b /fac /i6 version.lib %windir%\system32\version.dll

However, this didn't work very well for some (unknown) reason, so I ended up using .def files for all of them. The command that works looks like this:
Code: [Select]
++_BlockWOWIdle@4.'NTVDM.exe'

Given this works (I assume), the import record for the simple approach should in theory also work, at least for C and FASTCALL.

I have also done some testing with using windows.inc for differnt targets. The same include files should now work for both 32 and 64.bit, unicode/ascii, C/stdcall/fastcall, creating PE (no libs), using msvcrt (C/fastcall), or using the local library with startup modules.

Some changes have also been added to MAKE to simplify the build process. If %AsmcDir% is set MAKE will use the .\lib directory as a common include directory for .mif files.

Well, parsing these includes is tidious work so the current state looks like this:
Code: [Select]
WIN32_LEAN_AND_MEAN equ 1
include windows.inc

I currently only need kernel32 and user32 in the source base, but as the parsing improves more files will be added. Depending on how these functions are decleared, some will be defined with return type and line breaks, others with a single line:

Code: [Select]
if (_WIN32_WINNT GE 0x0500)
;BOOL
InitializeCriticalSectionAndSpinCount proto _CType \
     lpCriticalSection: LPCRITICAL_SECTION,
   dwSpinCount: DWORD
;DWORD
SetCriticalSectionSpinCount proto _CType \
     lpCriticalSection: LPCRITICAL_SECTION,
   dwSpinCount: DWORD
endif

Code: [Select]
ifndef _WDIRECT_DEFINED

;; also declared in direct.h

_wchdir proto :ptr wchar_t
_wgetcwd proto :ptr wchar_t, :SINT
_wgetdcwd proto :SINT, :ptr wchar_t, :SINT
_wmkdir proto :ptr wchar_t
_wrmdir proto :ptr wchar_t

_WDIRECT_DEFINED equ 1
endif

Vortex

  • Member
  • *****
  • Posts: 1603
Re: Asmc source and binaries
« Reply #20 on: March 03, 2017, 07:01:57 AM »
Hi nidud,

Regarding 64-bit coding, it's easy to create .def files and import libraries from DLLs :

Creating include files and import libraries for ml64

nidud

  • Member
  • *****
  • Posts: 1067
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #21 on: March 03, 2017, 10:25:40 AM »
Hey Vortex

The problem here is that LIBW is capable of creating a working import record from the command line but fail to do so from a .dll file. Asmc also use the same code for the /pe switch. This means that the problem is fixable within the source for LIBW, but I haven't looked into this yet.

The include files used in the Asmc package is the same for both 32 and 64-bit, so I need the arguments for all the functions as well. In addition to this I also need the type and size of each of them as oppose to just flip from DWORD to QWORD.

It would have been possible to just flip :DWORD to :PTR in the MASM32 package as well as appose to create a new set of files, but having the correct size and types makes a huge difference with regards to debugging.

What I'm doing now is moving (and adding) declarations to the correct MS header files to get them better organized and thereby easier yo use for those more familiar with these. So there is a C/ASM merger of sorts going on here.

As for the decorated symbols for 32-bit they available here:
https://github.com/open-watcom/open-watcom-v2/tree/master/bld/w32api/lib

It's possible parse these to create simple .inc files for both 32 and 64-bit.
.def 32:
AddConsoleAliasA@12
.def 64:
AddConsoleAliasA
.inc 32/64
AddConsoleAliasA proto :ptr, :ptr, :ptr

This is currently how the imports are created.
32-bit:
https://github.com/nidud/asmc/blob/master/lib/makefile
64-bit:
https://github.com/nidud/asmc/blob/master/lib/x64/makefile

Given no libraries exist at this point and the .def files needs parsing, the parser is made using the includes with the /pe switch.
32-bit:
https://github.com/nidud/asmc/blob/master/lib/def/lbc.asm
64-bit:
https://github.com/nidud/asmc/blob/master/lib/def/lbc64.asm

nidud

  • Member
  • *****
  • Posts: 1067
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #22 on: March 04, 2017, 06:35:13 AM »
A sample on how to use TCHAR.INC for multiple targets. Most of the samples used by MS apply this methood for unicode/ascii.
Code: [Select]
include stdio.inc
include stdlib.inc
include tchar.inc

.code

_tmain proc _CDecl argc:SINT, argv:PVOID

.for RSI = argv, edi = argc, ebx = 0: edi: edi--, ebx++, RSI += size_t

_tprintf("[%d]: %s\n", ebx, [RSI])
.endf
xor eax,eax
ret

_tmain endp

end _tstart

The command line for Asmc /pe:
asmc -pe -D__PE__ $*.asm
asmc -pe -ws -D_UNICODE -D__PE__ $*.asm
asmc -pe -D_WIN64 -D__PE__ $*.asm
asmc -pe -ws -D_UNICODE -D_WIN64 -D__PE__ $*.asm

The same code may also be built using the local library, but only the 32-bit ASCII version has the appropriate startup module to handle the the main arguments for now.

Thus it may not be recommendable to mix 32 and 64-bit code in this way the possibility to do just that is at least within reach. The CALL directive is somewhat limited for this approach so you have to use INVOKE on function calls to handle the local/import declarations (_imp_*) correctly.

The startup module is now defined in the tchar.inc file for the /pe switch, so the _tstart macro is either <> or <mainCRTStartup>. The Rxx registers are define in up-case chars so they become case sensitive in 32-bit.
« Last Edit: March 04, 2017, 08:43:32 AM by nidud »

Vortex

  • Member
  • *****
  • Posts: 1603
Re: Asmc source and binaries
« Reply #23 on: March 04, 2017, 06:39:21 AM »
Hi nidud,

I am fine with the DWORD to QWORD conversion but knowing the size and the type of the arguments is useful while debugging as you said.

The same include files supporting both 32-bit and 64-bit coding is a good idea. Creating the module definition files is not a problem, I do it with my lib2def tool. Pelle's library manager polib can be used for the same task.

Keep up the good work nidud :t

jj2007

  • Member
  • *****
  • Posts: 6507
  • Assembler is fun ;-)
    • MasmBasic
Re: Asmc source and binaries
« Reply #24 on: March 04, 2017, 07:06:06 AM »
The same include files supporting both 32-bit and 64-bit coding is a good idea.

I agree, see 64-bit assembly with RichMasm. It is pretty easy, actually, mainly because Microsoft needs it for the transition from 32-bit to 64-bit ("The header files for the Windows API enable you to create 32- and 64-bit applications."). My solution works fine, not a single extra library or header needed, but it is limited to the most important WinAPIs. Currently, I can't find enough enthusiasm to develop it further, simply because I don't see a convincing reason to go 64-bit 8)

nidud

  • Member
  • *****
  • Posts: 1067
    • https://github.com/nidud/asmc
Re: Asmc source and binaries
« Reply #25 on: March 11, 2017, 05:48:07 AM »
Code: [Select]
WIN32_LEAN_AND_MEAN equ 1
include windows.inc

The rest of the include files are now added but not tested: no assembly error.