flat assembler
Message board for the users of flat assembler.
Index
> Main > Is it possible to change assembling point? / Patching macros Goto page 1, 2 Next |
Author |
|
revolution 17 May 2008, 13:19
Use 'org' for that. Or if you mean to patch an existing file then use 'store'.
|
|||
17 May 2008, 13:19 |
|
Grom PE 17 May 2008, 13:36
Using "store" won't be any more convenient than plain byte patch.
Or it's possible to use it in macro to achieve syntax similar to my example? |
|||
17 May 2008, 13:36 |
|
revolution 17 May 2008, 13:44
Have a look at the fasmarm sources. There are some macros used to this type of patching with normal assembly used to get the patch bytes.
|
|||
17 May 2008, 13:44 |
|
Grom PE 17 May 2008, 13:51
Thanks, but there's a problem with "store" anyway: if I move assembled code to wanted address, it's still is not deleted from original place.
So there's side effect of increasing patched executable size with garbage, or, in best case, with zero bytes. |
|||
17 May 2008, 13:51 |
|
revolution 17 May 2008, 14:37
Use virtual to make the patch bytes, then capture with load, close the virtual and patch whatever you need. Zero bytes added to the file.
|
|||
17 May 2008, 14:37 |
|
Grom PE 17 May 2008, 15:13
How to make it work when "load" can only define 8-byte constants max, and I want to have patching sequences of arbitrary size?
Maybe it's easier to modify fasm source code to allow changing assembling point? |
|||
17 May 2008, 15:13 |
|
revolution 17 May 2008, 15:58
You could use multiple load/store sequences etc. but it is messy. I think you might want to use a proper patching program. fasm is not really designed to efficiently do what you want.
|
|||
17 May 2008, 15:58 |
|
Grom PE 18 May 2008, 13:30
No, no, fasm is just one step from becoming best patching program.
While I think how it can be done in load/store, tell me, what should I change in fasm source code. At least where can I see current assembling point. |
|||
18 May 2008, 13:30 |
|
revolution 18 May 2008, 14:13
Grom PE wrote: No, no, fasm is just one step from becoming best patching program. Grom PE wrote: While I think how it can be done in load/store, ... Grom PE wrote: ... tell me, what should I change in fasm source code. At least where can I see current assembling point. |
|||
18 May 2008, 14:13 |
|
Grom PE 18 May 2008, 15:27
revolution wrote: If you haven't seen it above the link to fasmarm will show one method of patching that uses load/store sequences. revolution wrote: It is not clear what you want to change, can you be more specific about what you want/need to achieve. Last edited by Grom PE on 18 May 2008, 15:35; edited 1 time in total |
|||
18 May 2008, 15:27 |
|
revolution 18 May 2008, 15:34
Grom PE wrote: Just what is mentioned in the first topic - achieve syntax similar to my example. |
|||
18 May 2008, 15:34 |
|
Grom PE 18 May 2008, 15:38
Maybe... As starting point, I need to catch where this "current offset" value is. Can you show me?
|
|||
18 May 2008, 15:38 |
|
bitRAKE 18 May 2008, 16:06
I wonder if there is a way to alter the END VIRTUAL directive to instead of discarding the data generated, to store it at another offset, or give it a symbolic name. Would be nice, imho.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
18 May 2008, 16:06 |
|
Tomasz Grysztar 18 May 2008, 20:59
I'm thinking about some new feature that would allow such things, and things like code compression etc. aswell. I already have some interesting idea; I will let you know, when I have something ready for testing.
|
|||
18 May 2008, 20:59 |
|
Grom PE 04 Jun 2008, 16:59
Tomasz, I eagerly waiting for such feature.
I wrote some macros with limited patching functionality: - Doesn't allow patching backwards - Doesn't allow "org" directive between "patchat" macros Tips on how these could be solved are very welcome. Code: ; Patching macros ; v0.50 ; for flat assembler by Grom PE ; Plan: ; 1. Specify file name and size with "patchfile" ; 2. On every "patchat", Load and add part of file, ; (or zeroes if file is finished) to move to specified offset. ; 3. On "patchend", if there part of file left, add it. macro patchfile name { virtual @@: file name p_filesize = $ - @b end virtual p_start = ($-$$) p_pointer = 0 p_filename equ name } macro patchat address { p_pointer = p_pointer - p_start + ($-$$) p_toadd = address - ($-$$) if address >= 0 if p_toadd >= 0 if p_pointer + p_toadd <= p_filesize file p_filename: p_pointer, p_toadd else p_addpart = 0 if p_pointer < p_filesize p_addpart = p_filesize - p_pointer file p_filename: p_pointer, p_addpart end if rb p_toadd - p_addpart end if else "Error: can't move backwards." end if else "Error: invalid address, must be >= 0." end if p_start = ($-$$) p_pointer = p_pointer + p_toadd } macro patchend { p_pointer = p_pointer - p_start + ($-$$) p_toadd = p_filesize - ($-$$) if p_toadd >= 0 if p_pointer + p_toadd <= p_filesize file p_filename: p_pointer, p_toadd else p_addpart = 0 if p_pointer < p_filesize p_addpart = p_filesize - p_pointer file p_filename: p_pointer, p_addpart end if db p_toadd - p_addpart dup 0 end if end if } Abstract usage example: Code: format binary as 'exe' use32 include 'patching.inc' patchfile 'program.exe' patchat 1688h ; Patching old drawing routine jmp new_drawing_routine nop after_drawing_routine: patchat 3840h ; Unused free space (2 kb) new_drawing_routine: ; (old code, overwritten by jmp) ; (new code) jmp after_drawing_routine patchend Real example would be MoonEdit |
|||
04 Jun 2008, 16:59 |
|
Grom PE 22 Jul 2008, 12:54
I tried several times, but had no success in removing this limit:
Quote: - Doesn't allow "org" directive between "patchat" macros How can I use "org" for some block and then set it to other value so anything below will work like no "org" was here? Or how can I modify patching macros so they don't rely on "org" setting? |
|||
22 Jul 2008, 12:54 |
|
revolution 22 Jul 2008, 16:28
I think you are trying to push an assembler into a task it is not designed or suited for. Going outside of the current section and "patching" another section (or sections) would need a lot of changes to the fasm core. I suggest that a proper patching program (maybe with a nice GUI) would be a good project to work on
|
|||
22 Jul 2008, 16:28 |
|
Grom PE 22 Jul 2008, 17:23
Hm? Why would I need to go outside of the current section?
Fasm is the best choice for my task because of the following reasons: - Open source patch - Adding code to patch and then testing is quick and easy - No additional steps between writing code and patching Remember, I'm not patching a couple of bytes, but adding functionality. |
|||
22 Jul 2008, 17:23 |
|
revolution 22 Jul 2008, 18:06
Grom PE wrote: Hm? Why would I need to go outside of the current section? |
|||
22 Jul 2008, 18:06 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.