flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Macros and advanced polly code teory, and code request

Author
Thread Post new topic Reply to topic
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
Is it possible to generated random numbers inside a macro? (at preprocessing time)
If not, could this feature be added?

I need it for generating polly code. Example:
Code:
org 100h

macro mov reg,num
{
if reg in <ax,bx> ; & rndnum=1
   mov cx,num
else if reg in <ax,bx> ;& rndnum=2
   mov dx,num
else if reg in <cx,dx>
   mov ax,num
end if
}

start:
mov ax,4
ret
    

If it had this feature, would be possible to add new IF's and based on number generated each time, change the registers building different executables at each compilation. This plus the already built-in feature load and store, people could make 100% polly+encrypted programs in very easy way. Good for program's security.
Also would be great to have macros to manipulate parts of instruction. Example:

MOV EAX, 5

and with some macros we could handle with each part:
MOV | EAX, | 5
and the macro would "know" the size of each part, and we could change these parts:
ADD EAX,5
MOV ECX,5
.
.
.

Is it possible?
Something like:
LoadOpcode buf, opc, opz_size
ChangeOpcode buf, OPCODE_ADD ;this would be a constant somewhere
opc:
MOV EBX,3
opc_size = $-opc
.
.
.
buf rb 10
So,

BEFORE:
MOV EBX,3

AFTER:
ADD EBX,3


Am I dreaming? Laughing
I hope it's possible to do!
Post 16 Feb 2006, 16:33
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
some idea (not real code)
Code:
rand_val = timestamp ;i forgot how to get it Smile
macro get_random {
  rand_val = rand_val ror 30 + 3*rand_val - 5*rand_val + 12312311313 ;etc
}
random
if ... & (rand_val mod 3 = 1)
else if ... & (rand_val mod 3 = 2)
else ...    

this may work for you, but you need to find good expression to generate fine values (especially be careful about value 0, that's why i always add some constant)
Post 16 Feb 2006, 16:54
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7797
Location: Kraków, Poland
Tomasz Grysztar
Actually there already is Random number macro listed in the Macroinstruction FAQ.
Post 16 Feb 2006, 17:30
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.