flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Reverse code macro??? possibilty |
Author |
|
shism2 16 Apr 2006, 05:04
Let's say like having a whole block of code reversed... So I could push the contents on to stack. Does fasm preprocessor have that ability???
|
|||
16 Apr 2006, 05:04 |
|
vid 17 Apr 2006, 18:22
Code: load dword CodeAtMinus1234 from $-1234 push CodeAtMinus1234 only preceding code can be loaded |
|||
17 Apr 2006, 18:22 |
|
shism2 18 Apr 2006, 01:33
????? What do you mean???
|
|||
18 Apr 2006, 01:33 |
|
Madis731 18 Apr 2006, 07:05
Code: db 0,1,2,3,4,5,6,7,8,9,10 ;length=11 for x=0 to length/2 xcgh bytes at x and (length-x) next The result would be: 10,9,8,7,6,5,4,3,2,1,0 Is this what you are looking for? I think this is what LOAD/STORE can do for you. You can decide yourself if you want byte/word/dword wise |
|||
18 Apr 2006, 07:05 |
|
vid 18 Apr 2006, 10:50
isn't that MASM code?
Code: dest rb 4 virtual src db 1,2,3,4 repeat 4 load a from src+% store a at dest+3-% end repeat end virtual not tested, i don't have FASM now. i am not sure if repeat goes 0 to 3 or 1 to 4. but the idea is something like this |
|||
18 Apr 2006, 10:50 |
|
shism2 18 Apr 2006, 16:58
dest rb 4
virtual src db 1,2,3,4 repeat 4 load a from src+% store a at dest+3-% end repeat end virtual store a at dest+3-% error: value out of range. |
|||
18 Apr 2006, 16:58 |
|
Borsuc 18 Apr 2006, 17:40
then it means repeat starts from 1.. so, replace the % with (%-1) (everywhere you use it here). because you need to start from 0 (when % is 1), and end up with 3 (when % is 4).
|
|||
18 Apr 2006, 17:40 |
|
shism2 19 Apr 2006, 01:43
dest rb 4
virtual src db 1,2,3,4 repeat 4 load a from src+(%-1) store a at dest+3-(%-1) end repeat end virtual store a at dest+3-(%-1) error: value out of range. |
|||
19 Apr 2006, 01:43 |
|
vid 19 Apr 2006, 07:25
i forgot "byte" operator with "load" and "store"
|
|||
19 Apr 2006, 07:25 |
|
Tomasz Grysztar 19 Apr 2006, 08:40
"byte" is anyway default for them, even if you omit it.
[a little offtopic] One tricky thing about "load" and "store" is when they operate on code that has relocations. I just realized I forgot to explain it in the manual. |
|||
19 Apr 2006, 08:40 |
|
vid 19 Apr 2006, 12:38
tomasz: so why doesn't that code work?
|
|||
19 Apr 2006, 12:38 |
|
Tomasz Grysztar 19 Apr 2006, 15:09
Because "virtual" is a separate addressing space.
|
|||
19 Apr 2006, 15:09 |
|
shism2 19 Apr 2006, 15:12
Code: macro beginreverse name { name#.begin: } macro endreverse name { name#.end: count = (rva name#.end - rva name#.begin) repeat count load b byte from %+ name#.begin -1 t = store byte t at %+ name#.begin -1 end repeat } I'm using this from a encrypting macro I have.. it works however know how do I reverse it. So instead of 1234 ...it would be 4321 However this is for each seperate instruction. Such as mov eax,0 xchg eax,eax add eax,eax |
|||
19 Apr 2006, 15:12 |
|
shism2 19 Apr 2006, 16:08
Thomas does the preprocessor know what is an instruction and just data???
If it does maybe... I can make it so it goes to the end of the instruction and takes that byte and replaces it with the first one. etc etc |
|||
19 Apr 2006, 16:08 |
|
Borsuc 22 Apr 2006, 09:23
How about this macro that reverses strings?
Code: macro reverse_string string* { local str, a, b str db string repeat ($-str)/2 load a from $-% load b from str+%-1 store a at str+%-1 store b at $-% end repeat } and then you use it like: Code: reverse_string "string" Code: gnirts if you want instructions, you can replace the "db" there when I used it with the instruction (don't forget to put a label): example Code: local instr, a, b instr: xor eax, eax repeat ($-instr)/2 load a from $-% load b from instr+%-1 store a at instr+%-1 store b at $-% end repeat PS: This is the assembler part, not preprocessor. Only the macro and local directives are in the preprocessor. The rest is in the assembler. |
|||
22 Apr 2006, 09:23 |
|
shism2 22 Apr 2006, 19:20
let me try it out
|
|||
22 Apr 2006, 19:20 |
|
vid 22 Apr 2006, 19:25
grey_beast: good idea :]
|
|||
22 Apr 2006, 19:25 |
|
shism2 22 Apr 2006, 19:46
Code: macro beginrev name { name#.begin: } macro endrev name { name#.end: count = (rva name#.end - rva name#.begin) repeat count load a from $-% load b from name#.begin+%-1 store a at name#.begin+%-1 store b at $-% end repeat } beginrev revnow xor ecx,ecx endrev revnow Nothing happens to it at all... However, If i divide count by 2... Then it does get reversed along with some instructions under it... What am I doing wrong? |
|||
22 Apr 2006, 19:46 |
|
f0dder 23 Apr 2006, 09:56
shism2 wrote: Let's say like having a whole block of code reversed... So I could push the contents on to stack. Does fasm preprocessor have that ability??? If you're going to execute code from the stack, realize this will not work on processors with NX bit enabled and an OS that supports it. _________________ - carpe noctem |
|||
23 Apr 2006, 09:56 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.