flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > [solved] generate random data in macros?

Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4335
Location: Now
edfed 12 Jul 2019, 08:44
how can i generate random datas from a bunch of macro repetition?

for example something like
Code:
macro Random {
local p = random mod 4
repeat 4
 if % equ p
 db random ; here i want to make a random byte
 else 
 db 0xff
 end if
end repeat
}

repeat 4
Random
end random

    


as a result, i would get 4 packets of 4 bytes, with a random byte at a random position for each packet.
Post 12 Jul 2019, 08:44
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20339
Location: In your JS exploiting you and your system
revolution 12 Jul 2019, 09:21
It depends upon your definition of "random".

You can use %t to get the current time. It isn't really random but might serve for your purpose as a seed value.

Otherwise use an external file to grab some random bytes and insert those. If you have Linux then /dev/urandom could suffice.
Post 12 Jul 2019, 09:21
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 12 Jul 2019, 09:51
If pseudo-random numbers would be enough for you, my article about types of multi-pass assembly contains some Xorshift macros for fasmg that I used to generate randomized sources. You could make something similar for fasm 1, though you'd have to do it a bit differently to avoid overflows.
Post 12 Jul 2019, 09:51
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4335
Location: Now
edfed 12 Jul 2019, 12:49
Code:
macro Random n{
p = ((%t mod n) mod 14) + 1
db n and 0xff
db p
repeat 14
 if % = p
 db (%t shr n) and 0xff ; here i want to make a random byte
 else 
 db 0xff
 end if
end repeat
}

repeat 256
Random %
end repeat
                                       
    


this code makes what i wanted. thanks Wink
Post 12 Jul 2019, 12:49
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4335
Location: Now
edfed 18 Jul 2019, 15:04
this single line makes a good enough random source
Code:
RNDT equ ($ + %t)  
    
Post 18 Jul 2019, 15:04
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20339
Location: In your JS exploiting you and your system
revolution 18 Jul 2019, 16:10
Cool Yeah, sometimes simple is all that is needed.
Post 18 Jul 2019, 16:10
View user's profile Send private message Visit poster's website 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.