added fasm2 as well

This commit is contained in:
2024-11-25 00:04:53 -05:00
parent 8a974e9c89
commit dceb330571
165 changed files with 78512 additions and 0 deletions

View File

@ -0,0 +1,47 @@
; Global strings demonstration for Linux.
format ELF64 executable 3
entry start
include 'globstr.inc'
include 'macro/inline.inc'
inlinemacro GLOB(value&)
local data
data GLOBSTR value,0
return equ data
end inlinemacro
segment readable executable
start:
lea rsi,[GLOB("Hello, it's ")]
call display_string
mov rsi,[rsp+8] ; argv
call display_string
lea rsi,[GLOB(' speaking.',10)]
call display_string
xor edi,edi ; exit code 0
mov eax,60 ; sys_exit
syscall
display_string: ; rsi = address of ASCIIZ string
xor al,al
mov rdi,rsi
or rcx,-1
repne scasb
neg rcx
sub rcx,2
mov edi,1
mov eax,1 ; sys_write
mov rdx,rcx
syscall
retn
segment readable
GLOBSTR.here

View File

@ -0,0 +1,44 @@
; Global strings demonstration for Windows.
include 'win64ax.inc'
include 'globstr.inc'
GLOBSTR.reuse := 1
.data
GLOBSTR.here
.code
start:
; Inline macro allows to put string data in any expression
; (getting the address in return):
inlinemacro GLOB(value)
local data
data GLOBSTR value,0
return equ data
end inlinemacro
lea rdx,[GLOB('Hello!')]
invoke MessageBox, HWND_DESKTOP, rdx, GLOB('Example'), MB_OK
; Alternatively, replacing the "fastcall?.inline_string" macro changes
; how the string arguments to "fastcall" and "invoke" are handled:
macro fastcall?.inline_string var
local data
data GLOBSTR var,0
redefine var data
end macro
; For 32-bit case it would be the "stdcall?.push_string" macro,
; provided here for completness:
macro stdcall?.push_string value&
local data
data GLOBSTR value,0
push data
end macro
invoke MessageBox, HWND_DESKTOP, 'And bye!', 'Example', MB_OK
invoke ExitProcess,0
.end start

View File

@ -0,0 +1,82 @@
define GLOBSTR GLOBSTR
virtual at GLOBSTR.baseaddr
GLOBSTR.buffer::
end virtual
postpone
virtual GLOBSTR.buffer
load GLOBSTR.data:$-$$ from $$
end virtual
if ~ defined GLOBSTR.where
display 'Global string data has been placed automatically at the end of the executable.',13,10
display 'To place it elsewhere, use "GLOBSTR.here" macro in the intended location.',13,10
GLOBSTR.baseaddr db GLOBSTR.data
end if
end postpone
macro GLOBSTR.here
GLOBSTR.baseaddr db GLOBSTR.data
GLOBSTR.where := GLOBSTR.baseaddr
end macro
if defined GLOBSTR.reuse & GLOBSTR.reuse
virtual at 0
GLOBSTR.chr_skips:: dd 256 dup ?
end virtual
struc GLOBSTR data&
local buffer,size,a,b,c,p,skip,found
virtual at 0
buffer:: db data
size := $
end virtual
repeat 256
store size:dword at GLOBSTR.chr_skips:(%-1)*4
end repeat
repeat size-1
load a:byte from buffer:%-1
store size-%:dword at GLOBSTR.chr_skips:a*4
end repeat
virtual GLOBSTR.buffer
found = -1
p = 0
while p + size <= $-$$
c = size
while c > 0
load a:byte from $$+p+c-1
load b:byte from buffer:c-1
if a <> b
c = -1
break
end if
c = c - 1
end while
if c = 0
found = p
break
else
load a:byte from $$+p+size-1
load skip:dword from GLOBSTR.chr_skips:a*4
p = p + skip
end if
end while
if found >= 0
label . at $$+found
else
. db data
end if
end virtual
end struc
else
struc GLOBSTR data&
virtual GLOBSTR.buffer
. db data
end virtual
end struc
end if