News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

fastcall

Started by bomz, February 21, 2013, 04:36:03 PM

Previous topic - Next topic

bomz

http://www.masmforum.com/board/index.php?PHPSESSID=786dd40408172108b65a5a36b09c88c0&topic=9136.0
Trying to make back LIB from INC, which was created from DDK lib. POASM support FASTCALL function. such INC works good with original DDK LIB - check with DDKKits examples.
create new LIB:
asm file
Quote...............................................................
RtlUshortByteSwap proc FASTCALL param01:DWORD
ret
RtlUshortByteSwap endp
RtlUlonglongByteSwap proc FASTCALL param01:DWORD,param02:DWORD
ret
RtlUlonglongByteSwap endp
RtlUlongByteSwap proc FASTCALL param01:DWORD
ret
RtlUlongByteSwap endp
RtlInterlockedPushListSList proc FASTCALL param01:DWORD,param02:DWORD,param03:DWORD,param04:DWORD
ret
RtlInterlockedPushListSList endp
end LibMain
def file
Quote...............................................
EXPORTS RtlUshortByteSwap
EXPORTS RtlUlonglongByteSwap
EXPORTS RtlUlongByteSwap
EXPORTS RtlInterlockedPushListSList
compiling
Quote.\poasm\poasm.exe /V2 %~n1.asm
.\poasm\polink.exe /noentry /SUBSYSTEM:WINDOWS /DEF:%~n1.def /dll %~n1.obj
if exports function from create in such way LIB, fastcall functions exports like from microsoft library
drivers makes with this LIB call windows nuclear error and computer immediately switch out.
there is error may be?

bomz

special thanks for ne_viens. working libs creates with C compiller
Quote////////////////ntdll.c///////////////
//cl /Ox /LD ntdll.c ntdll.def

unsigned long __fastcall RtlUshortByteSwap(unsigned long x)
{
    return;
}
Quote////////////////ntdll.def///////////////
LIBRARY ntdll
EXPORTS RtlUshortByteSwap
Quote@ECHO OFF
COLOR 9F
cd %~dp1
\C\bin\cl.exe /Ox /LD ntdll.c ntdll.def
\C\bin\link.exe /libpath:\C\lib /noentry /SUBSYSTEM:WINDOWS /dll /def:ntdll.def ntdll.obj
pause
Quote.386

.model flat, stdcall
option casemap :none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib

includelib ntdll.lib
include ntdll.inc

.data
mestitle   db "FASTCALL",0
form      db "EAX: %08hx", 0

.data?
buffer      db 64 dup(?)

.code
start:
mov ecx, 0ff00h
call @RtlUshortByteSwap
invoke wsprintf,ADDR buffer,ADDR form,eax
invoke MessageBox,0,ADDR buffer,ADDR mestitle,MB_ICONASTERISK
invoke ExitProcess,0
end start
Quote@echo off
..\poasm\poasm.exe /V2 exampleA.asm
..\poasm\polink.exe /SUBSYSTEM:WINDOWS exampleA.obj
del exampleA.obj
pause

Vortex

The name decoration is a bit different. FASTCALL functions have a leading @ symbol.

bomz

may be I don't understand good
the deal is that poasm support calling fastcall but something unsuporting in create fastcall. C looks good for making libraries.
Now I collected new BIN with C. makes full kernel32.lib - check it. trying fastcall macros. now makes batch files for full conversion.
the next step check drivers.

Quote.386

.model flat, stdcall
option casemap :none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib

includelib ntdll.lib
include ntdll.inc

.data
mestitle   db "FASTCALL",0
form      db "EAX: %08hx", 0
form1      db "%08hx%08hx", 0
value      INT64 0FFFFFFFFFFFFFFFFh

.data?
buffer      db 64 dup(?)

.code
start:
mov ecx, 01234h
fastcall @RtlUshortByteSwap, ecx
;call @RtlUshortByteSwap
invoke wsprintf,ADDR buffer,ADDR form,eax
invoke MessageBox,0,ADDR buffer,ADDR mestitle,MB_ICONASTERISK

mov ecx, 012345678h
fastcall @RtlUlongByteSwap, ecx
;call @RtlUlongByteSwap
invoke wsprintf,ADDR buffer,ADDR form,eax
invoke MessageBox,0,ADDR buffer,ADDR mestitle,MB_ICONASTERISK

push 90ABCDEFh
push 12345678h
;fastcall @RtlUlonglongByteSwap
call @RtlUlonglongByteSwap
invoke wsprintf,ADDR buffer,ADDR form1,eax, ecx
invoke MessageBox,0,ADDR buffer,ADDR mestitle,MB_ICONASTERISK

invoke ExitProcess,0
end start
Quote////////////////ntdll.c///////////////
//cl /Ox /LD ntdll.c ntdll.def

void __fastcall RtlUshortByteSwap(unsigned long x)
{
    return;
}
void __fastcall RtlUlongByteSwap(unsigned long x)
{
    return;
}
void __fastcall RtlUlonglongByteSwap(unsigned long x,unsigned long y)
{
    return;
}
void __fastcall RtlInterlockedPushListSList(unsigned long w,unsigned long x,unsigned long y,unsigned long z)
{
    return;
}
void __stdcall RtlRandom(unsigned long z)
{
    return;
}
void __cdecl Myproc(void)
{
    return;
}

bomz

makes batch file which convert INC to C code program, makes LIB's. all  works, drivers too, but new shit appear - C compiler have intrinsic function (_abnormal_termination ntoskrnl.exe and some others) which impossible to add to code in any way.
trying to makes glue LIB's from pieces making only fastcall part with C compiler - without success

Quote@echo off
color 9F
if "%~1"=="" goto End
cd /d %~dp0
SetLocal EnableDelayedExpansion
echo LIBRARY %~n1>%~n1.def
rem echo LIBRARY %~n1.exe>%~n1.def ##for ntoskrnl.inc
echo off>%~n1.c
for /f "skip=2 tokens=1,2,3,* delims= " %%w in ('FIND /I "PROTO" %~nx1') do (
   if not %%w==LibMain (
   set procname=%%w
   set private=!procname:~0,1!
   if not !private!==^; (
   set private=
   if %%w==DllUnload set private= PRIVATE
   if %%w==DllInitialize set private= PRIVATE
   echo EXPORTS !procname!!private!>>%~n1.def
      set string=%%y
      set string1=%%z
      if not "%%y"=="STDCALL" (
      if not "%%y"=="C" (
      if not "%%y"=="" (
      set string=
      set string1=%%y %%z
      )
      )
      )
      if not "!string1!"=="" (
      for /f "tokens=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26 delims=:" %%a in ("!string1!") do (
if not "%%a"=="VARARG" (
         if not "%%a"=="" set string=!string!unsigned long a
         if not "%%b"=="" set string=!string!,unsigned long b
         if not "%%c"=="" set string=!string!,unsigned long c
         if not "%%d"=="" set string=!string!,unsigned long d
         if not "%%e"=="" set string=!string!,unsigned long e
         if not "%%f"=="" set string=!string!,unsigned long f
         if not "%%g"=="" set string=!string!,unsigned long g
         if not "%%h"=="" set string=!string!,unsigned long h
         if not "%%i"=="" set string=!string!,unsigned long i
         if not "%%j"=="" set string=!string!,unsigned long j
         if not "%%k"=="" set string=!string!,unsigned long k
         if not "%%l"=="" set string=!string!,unsigned long l
         if not "%%m"=="" set string=!string!,unsigned long m
         if not "%%n"=="" set string=!string!,unsigned long n
         if not "%%o"=="" set string=!string!,unsigned long o
         if not "%%p"=="" set string=!string!,unsigned long p
         if not "%%q"=="" set string=!string!,unsigned long q
         if not "%%r"=="" set string=!string!,unsigned long r
         if not "%%s"=="" set string=!string!,unsigned long s
         if not "%%t"=="" set string=!string!,unsigned long t
         if not "%%u"=="" set string=!string!,unsigned long u
         if not "%%v"=="" set string=!string!,unsigned long v
         if not "%%w"=="" set string=!string!,unsigned long w
         if not "%%x"=="" set string=!string!,unsigned long x
         if not "%%y"=="" set string=!string!,unsigned long y
         if not "%%z"=="" set string=!string!,unsigned long z
) else (
set string=!string!void
)
            )
         )

         if "%%y"=="C" (
         set "string=!string:Cunsigned=unsigned!"
         set "string=!string:Cvoid=void!"
         set "string1=__cdecl"
         ) else (
         set "string=!string:STDCALL=!"
         set "string1=__stdcall"
         )

   (echo void !string1! !procname! ^(!string!^)
   echo {
   echo    return;
   echo })
)
)
)>>%~n1.c

for /f "tokens=2,3 delims=@:" %%a in ('findstr "@.*@.*:PROC" %~nx1') do (
echo EXPORTS %%a>>%~n1.def
if %%b==4 set "string=long a"
if %%b==8 set "string=long a, long b"
if %%b==12 set "string=long a, long b, long c"
if %%b==16 set "string=long a, long b, long c, long d"
if %%b==20 set "string=long a, long b, long c, long d, long e"
if %%b==24 set "string=long a, long b, long c, long d, long e, long f"
if %%b==28 set "string=long a, long b, long c, long d, long e, long f, long g"
if %%b==32 set "string=long a, long b, long c, long d, long e, long f, long g, long h"
if %%b==36 set "string=long a, long b, long c, long d, long e, long f, long g, long h, long i"
if %%b==40 set "string=long a, long b, long c, long d, long e, long f, long g, long h, long i, long j"
if %%b==44 set "string=long a, long b, long c, long d, long e, long f, long g, long h, long i, long j, long k"
if %%b==48 set "string=long a, long b, long c, long d, long e, long f, long g, long h, long i, long j, long k, long l"
(echo void __fastcall %%a^(!string!^)
echo {
echo    return;
echo })>>%~n1.c
)

.\bin\cl.exe /c /LD /noHRESULT %~n1.c
.\bin\link.exe /dll /noentry /def:%~n1.def %~n1.obj /NODEFAULTLIB:oldnames.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:kernel32.lib
rem .\bin\cl.exe /Ox /LD %~n1.c /link /libpath:.\lib /noentry /def:%~n1.def /NODEFAULTLIB:oldnames.lib /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:kernel32.lib
del %~n1.exp
del %~n1.obj
del %~n1.dll
:End
pause

bomz

some drivers makes with LIB's creating in such way call windows nuclear errors and switch of computer in some situation (second start). I think that convert correctly INC to LIB possible only if program download from MSDN its accurate description (may be). so for drivers (and all others) better use original WDK libs.