Tool to inject data into class files

Here is the tool i created for injecting byte data directly into the class file for my 2007 entry.

It reduces the overhead that embedding data as a Hexadecimal String in the source creates.

The tool creates a new Attribute in which the data is embedded. This Attribute is then injected at an valid point into the class file.

Feel free to use it or modify it just let me know if it is useful or if you make beneficial changes :slight_smile:

p.s. the source is not very well commented, read at your own peril :stuck_out_tongue:


This is great. Reduced the jar by over 50 bytes.

glad it helped :slight_smile:

If the data you are injecting has some logically different components, e.g. different images, etc, then you might find by re-arranging the order of these data components may yield a few extra bytes.

Tried, but to no avail. It never finds the || with the loop you provided in the readme. If changed to the actual two first characters it worked, dunno what’s wrong.

Ah, i just realised that the magic symbols (i.e. ||) are actually part of the image data payload of the sprites i had embedded in my game last year!

So yes, currently you have to append || to the start of your data that you are embedding. Or you could change it to what ever you want… just make sure you change the code looking for the magic symbols.

Problem is adding || makes java say the program’s been altered :confused:

when you say add || where are you adding it to?

are you adding it as part of the data you are embedding or injecting it before embedding your data into the class file?

if you do the later then you will need to increase the size of the attribute payload by two to incorporate the two extra bytes. By adding it as part of the data you are going to embed, there is no need to increase the size of the attribute payload.