Zophar's Message Domain

Go Back   Zophar's Message Domain > Emulation Talk > Rom Hack

Reply
 
Thread Tools Display Modes
Old 12-19-2005, 07:29 AM   #1
D--
Senior Member
 
D--'s Avatar
 
Join Date: Oct 2001
Location: Chaoyang, Beijing, China
Posts: 826
Default NINJA 2.0 format, looking for ideas

Hey, I'm looking to get ideas for what will be the next version of the NINJA patch format. Binary support is being totally dropped and it is moving to a text-based format. This means a larger filesize, but more flexibility and human-editable files.

Why is this important? Because it will be possible to use NINJA as a generic rom hacking too. Byuu said he'd add support for it to bsnes, too, so it will be useable for auto-patching like IPS.

The basic ideas that made NINJA 1.0 useful will remain, with auto-generated patches being independant of ROM format. Also, it will retain the same file validation options (SHA1 is going out the window, and all verification is now optional).

I finally put together a sample patch in the 2.0 format. The patch is human readable, so just unzip and view in notepad.

http://www.cinnamonpirate.com/pub/ -- Click on crestofgaia.zip

For reference, zipped, this patch is only 2KB larger than a zip of the IPS version. While much larger unzipped, file size shouldn't be an issue at all in distribution. It is also 8KB smaller than NINJA 1.0, since all bytes are between 0x20 - 0x80. I'm not sure yet about supporting unicode in files, other encoding should, technically, be possible if you use setstr instead of setchr.

As before, there is really no limit to the size file NINJA can patch. The only limit would be the maximum bits supported by whatever implementation of NINJA you use.I believe with custom libraries, the highest anything addresses right now is 80-bit, or 0xffffffffffffffffffff. You're welcome to write in a larger address, and some day when programming languages understand such values, the patch will work.

Please note, this is a man-made patch designed to show off all the possible features of NINJA 2.0 (except dir/multi-file patching, which doesn't really work on single-file ROMs, all you need to do is add an "open" command to close the current file and open a new one for patching).

Comments are marked by ;. It must be the first character on a line to be interpreted as a comment (this is to avoid needing to escape them in strings).

You can see an example of how to map characters to different hex values than ASCII, meaning table insertion of text. You can also use the setstr command to map a text string to a hex string for insertion.

Other settings include support for big or little endian values (so when you type word 0x8090 it will output 8090 or 9080 depending on the setting), inserting smart quotes (single and double) and multi-language patching (so multiple translations can be stored in one patch).

Machine-generated files will be nowhere this cool, of course. This is an example of how you could use NINJA as your entire toolset for a small-scale translation instead of having to write your own inserter, or how you can use it to test out certain asm tweaks on systems that don't have an assembler designer for hacking like byuu's xkas.

Files that are machine generated off a final project do have one advantage, however. Machine generated files can be made as an XOR of the two files, allowing one file to both patch and unpatch a ROM.

Please throw me your opinions on this. I'm looking for ideas on how to improve before I sit down and really start coding.

That reminds me, NINJA2 will finally fix a longstanding issue with IPS support (that being how it breaks on patches that are not in order) and will have some massive speed-ups when applying patches (probably same speed for creation though).


Commands not shown:
open "filename" ;opens a new file for patching and closes the current one
dword 0x90 ;writes a 32-bit value
hex deadbeef ;writes a hex string to the file in binary
cut 0x90 ;cuts the next 0x90 bytes out of the file


Addendum: Some ideas that came out of Nightcrawler's board. I'm adding global variables to tell things like the current pointer position, this way pointers can be relatively calculated based on each string insertion. This means a NINJA patch can be a full script inserter. I also want to define bounds for text areas, so the patch can fail if someone messes up and tries to write beyond the text bound. Basic math will also be supported.

Byuu suggest integrating it with FEIDIAN to add support for including bitmap graphics into the game (i.e. incbmp "graphic.bmp" tileformat rows cols), but if I do that, NO ONE will ever be able to support this format. Instead, I will make a FEIDIAN plugin that can make an XOR patch between the two graphic banks of the source file and hacked file. This XOR patch can just be included in with an incsrc line, or pasted in. Since it's an XOR, it will be fine to include a whole graphic chunk without risking any copyrighted data being in the patch file.


Ideas please. This format looks like it has a LOT of potential, and could be really handy when hacking on systems that don't have a quality assembler made for them (like byuu's xkas on SNES).
<P ID="signature"><hr>
Cinnamon Pirate.com</P>
__________________
portfolio :: deviantArt :: 微博 :: Twitter
D-- is offline   Reply With Quote
Old 12-19-2005, 09:17 PM   #2
Dan
Senior Member
 
Join Date: Jan 2002
Posts: 499
Default Re: NINJA 2.0 format, looking for ideas

Does this new format have support for inserting bytes in the middle of a ROM, or moving bytes around in a file?
<P ID="signature"><div align="center"><font size=2>http://dan.panicus.orgDan's Space</a></font></div></P>
Dan is offline   Reply With Quote
Old 12-19-2005, 09:51 PM   #3
D--
Senior Member
 
D--'s Avatar
 
Join Date: Oct 2001
Location: Chaoyang, Beijing, China
Posts: 826
Default Re: NINJA 2.0 format, looking for ideas

> Does this new format have support for inserting bytes in the
> middle of a ROM, or moving bytes around in a file?

I'll add a flag to the pad command to make it insert instead of overwrite.

For moving bytes, the best I could do would be to add a copy command, to copy a block from one offset to another one.

The problem will be with making the patch creator itself detect this kind of optimization between the files. Chances are, I myself will not write that. However, the format itself could support it, and if anyone else wanted to write support for it, it could work.
<P ID="signature"><hr>
Cinnamon Pirate.com</P>
__________________
portfolio :: deviantArt :: 微博 :: Twitter
D-- is offline   Reply With Quote
Old 12-19-2005, 10:22 PM   #4
CEpeep
Senior Member
 
Join Date: Feb 2002
Posts: 3,511
Default Re: NINJA 2.0 format, looking for ideas

I don't know whether IPS or NINJA 1 already support this, but a way to patch a file without it having to match a source file would be nice.

Example for clarification:

I have a bunch of data files of some sort. They're all different sizes, and have different data, but the headers are all the same. If I could make one patch that would change the headers of these to a different header, that would be sweet. Also these files are large, like 1GB+.

P.S. If anyone knows of a way to already do that, let me know.
<P ID="signature">
<hr noshade>
When I give food to the poor, they call me a saint. When I ask why the poor have no food, they call me a communist. ~ Dom Helder Camara
</P>
CEpeep is offline   Reply With Quote
Old 12-20-2005, 12:02 AM   #5
D--
Senior Member
 
D--'s Avatar
 
Join Date: Oct 2001
Location: Chaoyang, Beijing, China
Posts: 826
Default Re: NINJA 2.0 format, looking for ideas

> I have a bunch of data files of some sort. They're all
> different sizes, and have different data, but the headers
> are all the same. If I could make one patch that would
> change the headers of these to a different header, that
> would be sweet. Also these files are large, like 1GB+.

In what case could this be useful? Usually, headers indicate a specific file format, and you would be corrupting ... everything. If this is for something like ROMs, I'd say just use NSRT.

I'm just trying to understand when this would be used. I'm not big on adding features whose use doesn't make sense to me. When, I try that, the results are almost never what the person originally asked for.
<P ID="signature"><hr>
Cinnamon Pirate.com</P>
__________________
portfolio :: deviantArt :: 微博 :: Twitter
D-- is offline   Reply With Quote
Old 12-20-2005, 12:15 AM   #6
CEpeep
Senior Member
 
Join Date: Feb 2002
Posts: 3,511
Default Re: NINJA 2.0 format, looking for ideas

It's not really for ROMs. It's for modifying data files for PC games. There are games that use resource files for multiplayer depending on what server you're on. A common way of obfuscating the data so that no one else can steal your custom work is to change the headers for the resource files. They all have the same header, so it's just a matter of modifying the file header and then changing the program to make it read this header file instead of what it's used to. Usually I do this by hex editing, but it's a pain in the ass to do it for multiple files, and it prevents users from bringing their own resource files (most users don't know enough to hex their own headers). A universal patch one could apply that would automatically change the header from whatever it was (first 60 bytes, I believe) to what's specified in the patch would be awesome.

<P ID="signature">
<hr noshade>
When I give food to the poor, they call me a saint. When I ask why the poor have no food, they call me a communist. ~ Dom Helder Camara
</P>
CEpeep is offline   Reply With Quote
Old 12-20-2005, 04:22 AM   #7
D--
Senior Member
 
D--'s Avatar
 
Join Date: Oct 2001
Location: Chaoyang, Beijing, China
Posts: 826
Default Re: NINJA 2.0 format, looking for ideas

Ah, cool. I get it now.

Hrm, that's an idea I guess. Maybe I can work out some kind of option for supporting wildcards in filenames. I'll just need to figure out the proper regular expression for it.

I think you would have to custom-make the patch rather than auto-generating it, though, because you would have to have a "file" line. Maybe something like:

file *.wad

Then it would apply the patch to all .wad files in the path where you apply the patch. Por ejemplo:

ninja -p wadpatch.rup .\
-gay0000.wad patched
-gay0001.wad patched
-gay0002.wad patched
-gay0003.wad patched
-gay0004.wad patched
-gay0005.wad patched

Is this what you're talking about? I don't think it would be hard to support at all. In fact, using the .RUS source option, you could make something like this. Use the create option to make a RUP/RUS between a patched mod and unpatched. Tell it to make the XOR.

Now make a new file called wadpatch.rup. Inside, put:

;---------------------
;Wad Protect/Unprotect Patch by CEPeep
;---------------------
format raw
author "CEPeep"
email "your email"
website "your website"
title "Protection patch for BLAH BLAH WADs"
descrip "This patch can protect or unprotect a directory of WADs for GAMENAME"
genre "FPS"
version "1.0"
cpright "2005"

file "*.wad"

incsrc "wad.rus"

Now use NINJA to make this into a standalone RUP, or just paste in the contents of wad.rus where the "incsrc" line is. You're done. Since the patch is made off the XOR of a protect and unprotected file, it can both protect and unprotect your stuff.

This good enough?
<P ID="signature"><hr>
Cinnamon Pirate.com</P>
__________________
portfolio :: deviantArt :: 微博 :: Twitter
D-- is offline   Reply With Quote
Old 12-20-2005, 04:30 AM   #8
CEpeep
Senior Member
 
Join Date: Feb 2002
Posts: 3,511
Default Re: NINJA 2.0 format, looking for ideas

> This good enough?
>

Yes. I don't know how NINJA's RUP or RUS files work (never used it), but I'll gladly learn if they can do what you just described above.
<P ID="signature">
<hr noshade>
When I give food to the poor, they call me a saint. When I ask why the poor have no food, they call me a communist. ~ Dom Helder Camara
</P>
CEpeep is offline   Reply With Quote
Old 12-20-2005, 07:59 AM   #9
D--
Senior Member
 
D--'s Avatar
 
Join Date: Oct 2001
Location: Chaoyang, Beijing, China
Posts: 826
Default Re: NINJA 2.0 format, looking for ideas

They'll do it in the next version.

It will be done exactly as I showed above. That's all there is to making one.

I may even make a crappy Visual Basic front-end for it to use until byuu comes up with a fast/better C++ implementation.
<P ID="signature"><hr>
Cinnamon Pirate.com</P>
__________________
portfolio :: deviantArt :: 微博 :: Twitter
D-- is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:27 PM.

Contact Us - Zophar's Domain - Archive - Top

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.