flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > processing a macro parameter by condition

Author
Thread Post new topic Reply to topic
chiacorp



Joined: 16 Oct 2017
Posts: 12
chiacorp 28 Aug 2025, 08:29
Greetings to the seekers of truth in bytes)

macro set,a,b,c,d
{
mov eax,a
mov ebx,b
mov ecx,c
mov edu,d
}

set 1,2,3,4

mov eax,1
mov ebx,2
mov ecx,3
mov edu,4

Is there a way to somehow mark a parameter to perform an additional action on it or solve it in another way?

macro set,a,b,c,d
{
mov eax,a
mov ebx,b
mov ecx,c
mov edu,d
}

set 1,!2,3,4

mov eax,1
mov ebx,2
add ebx,100
mov ecx,3
mov edu,4

Thank you for your attention!
Post 28 Aug 2025, 08:29
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20729
Location: In your JS exploiting you and your system
revolution 28 Aug 2025, 23:13
A construct like this might work:
Code:
macro set a,b,c,d {
        mov     eax,a
        match   x=,y , b {
                mov     ebx,y
                add     ebx,100
        rept 0 {\} rept 1 {
                mov     ebx,b
        \}
        mov     ecx,c
        mov     edx,d
}

set 1,2,3,4
set 1,<!,2>,3,4    
Code:
mov eax,0x1
mov ebx,0x2
mov ecx,0x3
mov edx,0x4
mov eax,0x1
mov ebx,0x2
add ebx,byte +0x64
mov ecx,0x3
mov edx,0x4    
Post 28 Aug 2025, 23:13
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1997
Roman 29 Aug 2025, 08:12
Unusual method using rept 0 {\} .
Interesting info.
Post 29 Aug 2025, 08:12
View user's profile Send private message Reply with quote
chiacorp



Joined: 16 Oct 2017
Posts: 12
chiacorp 29 Aug 2025, 17:13
revolution wrote:
A construct like this might work:
Code:
macro set a,b,c,d {
        mov     eax,a
        match   x=,y , b {
                mov     ebx,y
                add     ebx,100
        rept 0 {\} rept 1 {
                mov     ebx,b
        \}
        mov     ecx,c
        mov     edx,d
}

set 1,2,3,4
set 1,<!,2>,3,4    
Code:
mov eax,0x1
mov ebx,0x2
mov ecx,0x3
mov edx,0x4
mov eax,0x1
mov ebx,0x2
add ebx,byte +0x64
mov ecx,0x3
mov edx,0x4    


*********************
Here is the macro I got!
The goal is achieved, thanks to revolution.
You need to mark the offset parameter to add the base address.

macro sys f*,p1,p2,p3,p4,p5,p6{
if ~eq p6
match x=,y,p6{mov r11,y
add r11,hbase
rept 0{\}rept 1{mov r11,p6\}
end if
if ~eq p5
match x=,y,p5{mov r10,y
add r10,hbase
rept 0{\}rept 1{mov r10,p5\}
end if
if ~eq p4
match x=,y,p4{mov r9,y
add r9,hbase
rept 0{\}rept 1{mov r9,p4\}
end if
if ~eq p3
match x=,y,p3{mov r8,y
add r8,hbase
rept 0{\}rept 1{mov r8,p3\}
end if
if ~eq p2
match x=,y,p2{mov rdx,y
add rdx,hbase
rept 0{\}rept 1{mov rdx,p2\}
end if
if ~eq p1
match x=,y,p1{mov rcx,y
add rcx,hbase
rept 0{\}rept 1{mov rcx,p1\}
end if
call f}

sys proc dword,<!,offset>,qwords
It's not clear how it works though)
Post 29 Aug 2025, 17:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20729
Location: In your JS exploiting you and your system
revolution 30 Aug 2025, 00:55
Perhaps the formatting is confusing. Maybe if it is formatted in a more "normal" way it makes more sense?

Here is the same code, just formatted differently:
Code:
macro set a,b,c,d {
        mov     eax,a

    ; first stage match
        match   x=,y , b \{
                mov     ebx,y
                add     ebx,100
                rept 0 \{
        \}

    ; second stage if above does not match
        rept 1 \{
                mov     ebx,b
        \}

        mov     ecx,c
        mov     edx,d
}

set 1,2,3,4
set 1,<!,2>,3,4    
Post 30 Aug 2025, 00:55
View user's profile Send private message Visit poster's website Reply with quote
chiacorp



Joined: 16 Oct 2017
Posts: 12
chiacorp 30 Aug 2025, 03:04
revolution wrote:
Perhaps the formatting is confusing. Maybe if it is formatted in a more "normal" way it makes more sense?

Here is the same code, just formatted differently:
Code:
macro set a,b,c,d {
        mov     eax,a

    ; first stage match
        match   x=,y , b \{
                mov     ebx,y
                add     ebx,100
                rept 0 \{
        \}

    ; second stage if above does not match
        rept 1 \{
                mov     ebx,b
        \}

        mov     ecx,c
        mov     edx,d
}

set 1,2,3,4
set 1,<!,2>,3,4    



It is unclear by what algorithm the action is determined, the condition is missing. At least it seems so.
Post 30 Aug 2025, 03:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20729
Location: In your JS exploiting you and your system
revolution 30 Aug 2025, 03:53
match emits "rept 0" as the final line, disabling the following "rept 1".
Code:
rept 0 {
  rept 1 { ; this now has no effect. It isn't emitted
  mov ... ; not emitted
}    
Post 30 Aug 2025, 03:53
View user's profile Send private message Visit poster's website Reply with quote
chiacorp



Joined: 16 Oct 2017
Posts: 12
chiacorp 31 Aug 2025, 04:23
The fastcall macro of the proc 64 file has a function to determine the size of the operand and whether it is an address. It is difficult to understand from the macro how it works. What is the easiest way to use this feature?

if vararg@fastcall & ~ param eq rcx
movq rcx,xmm0
end if
else if type@param eq addr
if ~ param eq rcx
lea rcx,[param]
end if
else if size@param = 8
if ~ param eq rcx
mov rcx,param
end if
else if size@param = 4
if ~ param eq ecx
mov ecx,param
end if
else if size@param = 2
if ~ param eq cx
mov cx,param
end if
else if size@param = 1
if ~ param eq cl
mov cl,param
end if
end if
Post 31 Aug 2025, 04:23
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.