flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Change value based on register value

Author
Thread Post new topic Reply to topic
swank



Joined: 07 Nov 2018
Posts: 4
swank 02 Feb 2019, 17:15
Hello,

I have this code:

macro rndNum {
rdtsc
.if byte[eax]<=$CC
num = $FF
.else
num = $AA
.endif
}

rndNum

My idea is to define num as $FF or $AA based on AL value. But I got always the same value. Can somebody give me a light?

Thanks!
Post 02 Feb 2019, 17:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19725
Location: In your JS exploiting you and your system
revolution 02 Feb 2019, 17:37
RDTSC returns values in the registers directly. So you also need to read them directly.
Code:
macro rndNum {
        local   .higher, .done
        rdtsc
        cmp     al,0xcc
        ja      .higher
        mov     [num],0xff
        jmp     .done
    .higher:
        mov     [num],0xaa
    .done:
}    
Post 02 Feb 2019, 17:37
View user's profile Send private message Visit poster's website Reply with quote
swank



Joined: 07 Nov 2018
Posts: 4
swank 02 Feb 2019, 20:19
Thanks for the fast reply revolution!

The idea is to create a constant in the binary that changes every time it is compiled (preprocess).

But the code always returns 0xaa, with this code:

Code:
macro rndNum {
    local   .higher, .done
    rdtsc
    cmp     al,0xcc
    ja      .higher
    ;mov     [num],0xff
    num = 0xff
    jmp     .done
  .higher:
    ;mov     [num],0xaa
    num = 0xaa
  .done:
}
rndNum
    


Do I have to use match if I wan't preprocess conditional?
Post 02 Feb 2019, 20:19
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19725
Location: In your JS exploiting you and your system
revolution 03 Feb 2019, 01:42
The assembler doesn't execute the RDTSC instruction. It is only compiled.

One way to get a changing value during assembly is the %t value. It is the current local time in seconds since 1970-01-01.
Code:
macro rndNum {
        if %t and 0xff <= 0xcc
                num = 0xff
        else
                num = 0xaa
        end if
}    
You don't need the macro wrapper BTW. It can be assembled directly also.
Post 03 Feb 2019, 01:42
View user's profile Send private message Visit poster's website Reply with quote
swank



Joined: 07 Nov 2018
Posts: 4
swank 03 Feb 2019, 03:17
Thanks mate! Works like a charm!!

With your help, I can generate a random 1byte number preprocessed with just one line!!

Code:
key = %t and 0xff
    


Thanks for the patience!
Post 03 Feb 2019, 03:17
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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.