flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > macros general questions |
Author |
|
LocoDelAssembly 16 Jul 2011, 17:06
No the first forward does not create any label, it is storing a reference to a not-existing-yet label. The second forward is the one which is actually defining labels.
Lets suppose you call it this way: strtbl foo, 'one', 'two', 'three' The preprocessor would pass the following to the assembler: Code: ; Common label foo dword ; First forward dd label?1 dd label?2 dd label?3 ; Second forward label?1 db "one", 0 label?2 db "two", 0 label?3 db "three", 0 The source above would take the assembler stage two passes at minimum because of the forward referencing of each "dd label?X". |
|||
16 Jul 2011, 17:06 |
|
Enko 16 Jul 2011, 17:11
A.. perfect. Thats why if label db X is removed, there is a problem with referencing label?1
Thanks for quick replay. |
|||
16 Jul 2011, 17:11 |
|
Enko 18 Jul 2011, 04:22
Hy again, here I have some questions again^^
I had made a macro that would encrypt a part of code. Code: macro crypt pstart, pend { local i, len, k len = pend - pstart - 8 common i = 0 repeat len load x from pstart + % -1 load k from (pend + i) x = x xor k store x at pstart + % -1 i = i + 1 if i = 8 i = 0 end if end repeat repeat 8 store 0x90 at pend + % - 1 end repeat } pstart is the label from where to start encryptation pend is the end label. And you use it like this: Code: start_point: mov eax, ebx xor ecx, ecx etc.... end_point: db 'PASSWORD' ;should be after the endpoint crypt start_point, end_point The macro will xor the block with the PASSWORD and then replace the password with NOPS. It actually works fine. But I have a questions to understand better fasm macros. Is it posible to pass the encryptation key to the macro as a parameter? somthing like: crypt start_point, end_point, 'PASSWORD' the problem I had is to access each byte of the key separatly Here goes a pseudocode of what I mean Code: macro crypt _start, _end, [key]{ .... .... .... x = x xor key[i] i = i + 1 if i = 8 i = 0 end if Thanks in advance |
|||
18 Jul 2011, 04:22 |
|
LocoDelAssembly 18 Jul 2011, 05:35
Not that easy, you'll need to resort to the "virtual" trick:(Untested)
Code: macro crypt pstart, pend, key { local len, k, x len = pend - pstart - 8 common repeat len load x byte from pstart + % -1 virtual at 0 db key load k byte from (% - 1) mod $ end virtual x = x xor k store x at pstart + % -1 end repeat repeat 8 store 0x90 at pend + % - 1 end repeat } |
|||
18 Jul 2011, 05:35 |
|
Enko 18 Jul 2011, 05:48
why mod $?
and when/where is key count reseted? for example: Code: p1: db '1234567890' p2: crypt p1, p2, 'PASSWORD' the preprocessor should do: Code: '1' xor 'P' ;key[0] '2' xor 'A' ;key[1] .... '7' xor 'D' ;key[8] the keysize is achieved, so it should be resset to 0 '8' xor 'P' ;key[0] '1' xor 'A' ;key[1] Of course the final result will only be the xored values. thanks a lot |
|||
18 Jul 2011, 05:48 |
|
LocoDelAssembly 18 Jul 2011, 06:24
No, if you call "crypt start_point, end_point, 'PASSWORD'", the preprocessor would pass this to the assembler:
Code: len?0 = end_point - start_point - 8 repeat len?0 load x?0 byte from start_point + % -1 virtual at 0 db 'PASSWORD' load k?0 byte from (% - 1) mod $ end virtual x?0 = x?0 xor k?0 store x?0 at start_point + % -1 end repeat repeat 8 store 0x90 at end_point + % - 1 end repeat Note that "repeat" does not work like "REPT" preprocessor directive, here the code in interpreted and everything generating data/code is output to the file (unless the CPU instruction or data definition directive is wrapped inside a virtual block). PS: The "?0" suffixes may not be accurate, I'm just mimicking what the preprocessor does for symbols declared "local", but the numbers I'm using may be wrong. |
|||
18 Jul 2011, 06:24 |
|
Enko 18 Jul 2011, 06:36
Ah... now I get it
example if the keysize is 8 Code: 7 mod 8 = 7 8 mod 8 = 0 9 mod 8 = 1 etc... its a very nice trick ! thnx. |
|||
18 Jul 2011, 06:36 |
|
Enko 18 Jul 2011, 07:21
Here I'm again!
Code: format binary as "txt" FALSE = 0 TRUE equ ~ FALSE DEBUG equ TRUE match =TRUE, DEBUG { db 'DEBUG' } ;RESULT false match TRUE, DEBUG { db 'DEBUG' } ;RESULT true match DEBUG, TRUE { db 'DEBUG' } ;RESULT true match DEBUG, =TRUE { db 'DEBUG' } ;RESULT true there is somthing I didn't understand with the match directive. I'm trying to emulate the fasm documentation example. But as you see, with the 4 match combinations, 3 are true. But as I understand, there should be 2 of them true, or 4 (all) of them. What I don't understand, is why: match =TRUE, DEBUG { db 'DEBUG' } this is false but match DEBUG, =TRUE { db 'DEBUG' } this is true. |
|||
18 Jul 2011, 07:21 |
|
Enko 18 Jul 2011, 07:34
Code: format binary as "txt" FALSE = 0 TRUE equ ~ FALSE DEBUG equ TRUE match DEBUG, =TRUE { db 'DEBUG, =TRUE',10,13 } match DEBUG, TRUE { db 'DEBUG, TRUE' ,10,13} match TRUE, DEBUG { db 'TRUE, DEBUG' ,10,13} match =TRUE, DEBUG { db '=TRUE, DEBUG' ,10,13} match DEBUG, =FALSE { db 'DEBUG, =FALSE',10,13 } match DEBUG, FALSE { db 'DEBUG, FALSE' ,10,13} match FALSE, DEBUG { db 'FALSE, DEBUG' ,10,13} match =FALSE, DEBUG { db '=FALSE, DEBUG' ,10,13} match DEBUG,=~FALSE { db 'DEBUG,=~FALSE' ,10,13} match DEBUG,~FALSE { db 'DEBUG,~FALSE' ,10,13} match ~FALSE,DEBUG { db '~FALSE,DEBUG' ,10,13} match ~FALSE,DEBUG { db '~FALSE,DEBUG' ,10,13} actually this output: Quote:
all blocks with ~false are true only this two matches are false the block with =FALSE,DEBUG is False the block with =TRUE,DEBUG is False well, I'm going to sleep, becouse here something I don't quit get and I dont understand what. |
|||
18 Jul 2011, 07:34 |
|
LocoDelAssembly 18 Jul 2011, 15:38
Not sure what you don't understand but notice you have used "FALSE = 0" which the preprocessor does not have a clue and just pass it verbatim to the assembler and then, when you do "TRUE equ ~ FALSE" it doesn't get transformed to "TRUE equ ~ 0" because the "=" of the previous line means nothing to the preprocessor (so the "~" although if passed to IRPS or used in match it will recognized as a symbol, it won't preform any negation)
|
|||
18 Jul 2011, 15:38 |
|
Enko 18 Jul 2011, 15:48
Ok, the question I guess should be:
What does "match symbol literally" means when using =? What is the diference beetween using and not using the =? |
|||
18 Jul 2011, 15:48 |
|
LocoDelAssembly 18 Jul 2011, 16:51
When you use it you tell match to look for the symbol next to it, if you don't it just puts the data inside the given symbol:
Code: ; Example match a+b, 1 + 2{display `a, ' is addded with ', `b} display 13, 10 match a =Enko b, Today we had Enko asking something in the forum { ; Unfortunatelly this time the backtick cant work in a single step irps word, a\{display \`word, ' '\} display 'a guy from Mar del Plata' irps word, b\{display ' ',\`word\} } |
|||
18 Jul 2011, 16:51 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.