Hi friends,
Like GoASM, POASM can detect undefined functions seen in call statements and declares them as externals. To avoid decorated symbols, the calling convention should be specified as syscall The imports libraries used in this project are extracted from DLLs by Polib
As you can see in the source code, there is no any single API function declaration.
; assembled with POASM 0.99.1
.386
.model flat,syscall
option casemap:none
includelib ..\kernel32.lib
includelib ..\user32.lib
WM_INITDIALOG EQU 110h
WM_SETCURSOR EQU 20h
WM_CLOSE EQU 10h
IDC_CROSS EQU 32515
.data
DlgName db "MyDialog",0
hInstance dd ?
CommandLine dd ?
hCursor dd ?
.code
start:
push 0
call GetModuleHandleA
mov hInstance,eax
push 0
push OFFSET DlgProc
push 0
push OFFSET DlgName
push hInstance
call DialogBoxParamA
push eax
call ExitProcess
DlgProc PROC hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
cmp uMsg,WM_CLOSE
jne initdlg
push 0
push hWnd
call EndDialog
jmp true
initdlg:
cmp uMsg,WM_INITDIALOG
jne setcursor
push IDC_CROSS
push 0
call LoadCursorA
mov hCursor,eax
jmp true
setcursor:
cmp uMsg,WM_SETCURSOR
jne false
push hCursor
call SetCursor
jmp true
false:
xor eax,eax
ret
true:
mov eax,1
ret
DlgProc ENDP
END start
Check the Poasm example in the zip file :
http://vortex.masmcode.com/files/implib21.zip
Here is another version with decorated functions , it uses the standart import library file set.
.
.
start:
push 0
call GetModuleHandleA@4
mov hInstance,eax
push 0
push OFFSET DlgProc
push 0
push OFFSET DlgName
push hInstance
call DialogBoxParamA@20
push eax
call ExitProcess@4
.
.
[attachment deleted by admin]
what does that mean (auto declaration of externals)? How about auto declaration of internals?
No, Vortex has it right and you have it wrong, read the documentation, please.
RFM, dude,
Paul
I was not saying it meant auto declaration of internals, I was asking what auto declaration of externals meant. How is it different than masm? The second sentence meant and how about doing auto declaration of internals while you are at it! (assuming I have any idea what was meant by declaration of externals, which I really don't). And what manual are you talking about anyway?
Darn it all, looks like I get egg on my face as there is NO help for this in the syntax.txt file. My mistake. sorry.
About auto declaration of externals, it refers to libraries which refer to DLLs. His simple32 includes two INCLUDELIB statements so don't trust me on that. That is the answer I 'would ordinarily should' have given, but I connfess to being just as confused as you are so I wish, now, that I had just not said anything in this post.
Paul
Hi Jimg,
Auto declaration of externals means that POASM keeps track of function names seen in the call statements and if those functions are not declared with EXTERN or PROTO , POASM assumes them as externals. MASM doesn't provide this capacity, simply , it will emit an error message if it detects a function wich is not declared by the user.
A simple example :
.386
.model flat, stdcall
option casemap:none
includelib \masm32\lib\kernel32.lib
.code
start:
push 0
call ExitProcess@4
END start
Assembling with MASM :
error A2006: undefined symbol : ExitProcess@4
Poasm assembles the file without any error message. Disassembling the object file :
public _start
extrn _ExitProcess@4
includelib /DEFAULTLIB:\masm32\lib\kernel32.lib /ENTRY:start
_TEXT segment
assume CS:_TEXT
_start:
push 0
call near ptr _ExitProcess@4
_TEXT ends
end
Vortex,
So this means it works similar to GOASM? Or am I wrong about that? Pelle's examples are pretty vague on this whole process. Any I cannot find that in any of his documents...
Paul
Hi Vortex-
Quote from: Vortex on January 21, 2006, 11:10:42 PM
Auto declaration of externals means that POASM keeps track of function names seen in the call statements and if those functions are not declared with EXTERN or PROTO , POASM assumes them as externals.
So if it was just a typo, it will be found as an error by the linker, right? I like it as far as it goes, but it should add post declared PROC statements to EXTERN and PROTO as things it checks rather than complaining. For me, this would be MUCH more useful.
Quote from: PBrennick on January 21, 2006, 11:55:57 PM
Vortex,
So this means it works similar to GOASM? Or am I wrong about that? Pelle's examples are pretty vague on this whole process. Any I cannot find that in any of his documents...
Paul
Hi Paul,
Yes, iit works like GoAsm. Probably, Pelle will prepare a documentation.
Fixed bug with the NOfnDECL example. The stack is balanced manually with the RET 16 instruction according the SYSCALL convention.
http://vortex.masmcode.com/files/implib211.zip
Here is another example of using the auto-declaration feature. I coded a macro simulating the invoke statement to call extrernal functions without function prototypes like in GoAsm. The usage of the _invoke is a little complicated, in most cases, it requires enclosing parameters between double < and > symbols.
Many thanks to Pelle who helped me to build the invoke simulator macro :U
[attachment deleted by admin]
Here is the second version of the invoke macro simulator. Now, there is no need anymore to enclose parameters between double < and > , one pair of < and > is enough. I redesigned the _invoke macro to make easier the usage.
[attachment deleted by admin]
Here is another example using scan.exe to set the equates for ANSI functions.
[attachment deleted by admin]
Invoke simulator
There was some cases where the external function to be called was defined more than one time - bug fixed
[attachment deleted by admin]
Here is another version of the invoke macro simulator, this new one can handle C functions :
@ArgCount MACRO arglist:VARARG
LOCAL count
count = 0
FOR arg, <arglist>
count = count + 1
ENDM
EXITM count
ENDM
@ArgI MACRO index:REQ, arglist:VARARG
LOCAL count, retstr
count = 0
FOR arg, <arglist>
count = count + 1
IF count EQ index
retstr TEXTEQU arg
ENDIF
ENDM
EXITM retstr
ENDM
_invoke MACRO functionname:REQ,args:VARARG
LOCAL arg,pos,paramcount,count
paramcount=@ArgCount(args)
count=4*paramcount
WHILE paramcount
arg TEXTEQU @ArgI(paramcount,args)
pos=@InStr(1,arg,<ADDR>) OR @InStr(1,arg,<addr>) OR @InStr(1,arg,<Addr>)
IF pos
IF ( OPATTR arg ) AND 64 ; is arg relative to stack?
lea eax,[arg]
push eax
ELSE
push OFFSET @SubStr(arg,pos+5)
ENDIF
ELSE
push arg
ENDIF
paramcount = paramcount - 1
ENDM
call functionname
IF (OPATTR(functionname)) EQ 293 ; is it a C function?
IF count NE 0
add esp,count
ENDIF
ENDIF
ENDM
[attachment deleted by admin]