Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Bytecode splice #3

Open
Krutoy242 opened this issue Nov 21, 2022 · 1 comment
Open

[Feature Request] Bytecode splice #3

Krutoy242 opened this issue Nov 21, 2022 · 1 comment

Comments

@Krutoy242
Copy link

Please add feature to splice bytecode.

Problem

Sometimes, i need to modify only one integer or string in .class files.
Some mods with "All Rights Reserved" license forbid to distribute their .class files, so i can't use Bansoukou.
Other devs using mixins and coremods for this, but i have lack of Java knowledge.

Suggestion

Please add feature to change binary file content without providing whole binary file.
For example, it could be .json with commands that will replace bytes.

Manual example

I have ImmersiveEngineering Silo that i want to change capacity stored in int

public class TileEntitySilo
extends TileEntityMultiblockPart<TileEntitySilo>
implements IEBlockInterfaces.IComparatorOverride {
    public ItemStack identStack = ItemStack.field_190927_a;
    public int storageAmount = 0;
    static int maxStorage = 41472; // Value i want to change
    boolean lockItem = false;
    private int[] oldComps = new int[6];

When i used Bansoukou for the first time, i opened this .class file with Hex editor, found 00 00 A2 and replace it to 00 FF FF.
So now my code should looks like:

static int maxStorage = 16776960;

I saved this file into bansoukou/ folder and its work.

Feature suggestion example

What i want is to do same actions in steps above, but on MC launch.

For example, it could be .json file with arrays of instructions.
In addition to file path it could have special characters that instruct to read file as instructions instead of inject in .jar as is.
In my example, file called TileEntitySilo.class and instructions file called TileEntitySilo.class$$.json

bansoukou/ImmersiveEngineering-0.12-98/blusunrize/immersiveengineering/common/blocks/metal/TileEntitySilo.class$$.json

Instruction file could have arrays of JS-like .splice() parameters:

[
  {
    "index": 6574, // The position to add/remove bytes
    "remove": 2, // Number of bytes removed, optional
    "insert": [255, 255] // New byte(s) to be added
  }
]

When Bansoukou run, it would open .class file in binary format, and replace bytes 6574 and 6575 to FF FF and then save -patched .jar as usual.

Note:
It would be nice if "index" and "insert" values could accept strings, so i could write:

"index": "19AE",
"remove": 2,
"insert": "FF FF"
@Rongmario
Copy link
Member

I will introduce a binary patching system for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants