Is there a way to patch an existing file?
Page 1 of 1

Author:  TheDoug [ Sat Apr 05, 2014 8:30 pm ]
Post subject:  Is there a way to patch an existing file?

Hi, I want to use Easy68k in some projects and I need to know if it's possible to patch an existing file. Someone knows if it's possible?

I want to change some routines of an existing program (and adding data using INCBIN, etc), so I need to patch the resulting assembled code in this existing binary. But seems that Easy68k only supports the "normal" method where it generates a final binary only with the assembled code, so all the insertion must be done manually.

I saw that EASyBIN.exe can fill the region between two "ORGs" with a specified value (0xFF by default), but it's not enough because it doesn't help the merge.

So is there a way to patch a file, or the solution is to keep coding each ORG region as a separated binary and merging manually?

A "patch assembler" is an amazing feature to hacking and changing existing files.


Author:  profkelly [ Wed Apr 09, 2014 8:39 pm ]
Post subject:  Re: Is there a way to patch an existing file?

If you wrote code that was position independent it could be added anywhere in an existing code base. There is no "built-in" mechanism for patching an existing .S68 file.

Author:  TheDoug [ Thu Apr 10, 2014 4:50 pm ]
Post subject:  Re: Is there a way to patch an existing file?

Hi, actually I figured out a way to patch a file.

First you assembly your code to create the .s68. Now, using the EASyBIN.exe, you first open the file you want to patch (using the open binary option) and after you load the .s68 file. This procedure will merge the binary with the assembled code. The last step (and the trick part) is that you need fo change manually the start address to 0x0 and the size must be the file size. So now you can save and you will have the original file with the changed code in the right position.

The EASyBIN.exe will put the start address to be the address of the first ORG, and the size will be the the position of the last assembled data, so you need to change this values manually. Actually is easy to change the code to patch the files automatically without having to do it manually. You only need to download the Borland suite and change some lines.
But if donĀ“t want to do that use the steps above with the oficial version.

Now you can change some files, like genesis Roms, using the same method used by assemblers like xkas and Bass for Snes. This way you can have a single source file with all your code, and with only one step you can generate the final modified Rom.


Author:  profkelly [ Sat Apr 12, 2014 2:09 pm ]
Post subject:  Re: Is there a way to patch an existing file?

I guess I don't understand exactly what you are doing. How does the existing code get hooks to access to appended code?

Author:  TheDoug [ Sat Apr 12, 2014 3:08 pm ]
Post subject:  Re: Is there a way to patch an existing file?

Hi, I think I didn't express correctly in the first post.

I want to change an already compiled program. So let's say I have a program with 4MB size, and I know that in the position (for example) 0x123456 there is the instruction JMP 0x00212121, so I want to change this instruction in the binary to point to another location, say 0x00111111.
So I create this file with Easy68k:

START:                  ; first instruction of program

    ORG $123456
        JMP $00111111

    END    START

Now I assembly the code do generate the .s68 and doing the steps I described in my last post I can patch the binary. So after doing that, if I compare the two binaries I can see the in the position 0x123456 the instructions are different. All the rest is the same.

This is a simple example, and using this method you can do a lot of change in a binary.

Author:  RyanFaeScotland [ Tue Jan 26, 2016 12:11 am ]
Post subject:  Re: Is there a way to patch an existing file?

Hey Doug,

Great write up! It makes sense and was useful to me but that could be because I'm more aware of the context you are applying this in given I am currently doing exactly the same thing myself.

I don't think this is going to be a long term solution as eventually my project is going to get so big I'll want to separate out different parts into separate files but I'm still exploring all the functionality in EASy68K just now so it might still be possible by using INCLUDE commands.

Will be interesting to see what process I finally end up with!

Author:  profkelly [ Thu Jan 28, 2016 9:42 pm ]
Post subject:  Re: Is there a way to patch an existing file?

I did some experimenting today. I think this method should work for patching an existing binary file.

* Title      : dataChange.X68
* Written by : Charles Kelly
* Date       : Jan-28-2016
* Description: Modify existing binary file
    ORG    $1000        ; Make this the same as ORG in original program
    INCBIN "data.bin"   ; Load binary of file to modify
    ORG    $10E0        ; Set origin to addres to modify
    DC.B   'XYZZY',0    ; Overwrite existing data with new data
    MOVE.B  #14,D0      ; or instructions

    END    START        ; last line of source

* Note on ORG directive. The ORG directive will automatically adjust odd
* addresses to the next even location. To apply a modification an odd
* address do the following:
*       ORG     $10E0   ; previous even address
*       DS.B    1       ; reserve 1 byte (does not modify the byte)
*       Proceed as before. The address is now $10E1.

P.S. The binary data may be edited in EASyBin, as numbers in left window or text in right window.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group