Skip to content

Jump helper function #29

Description

@DenJur

Currently building jump instructions is a bit annoying since you have to initialize them outside the instruction array. It becomes worse when you need to change it later. I would like to see an option similar to method call builder that would allow to create those jumps while initializing instruction array.
One idea I had was to extend Instruction with an optional string id field and create instruction child type (ResolveLaterInstruction?) that can be replaced by a processor before patching. Ideally I would like instruction array initialization to look something like this.

Instruction[] opCodes = {
                Instruction.Create(OpCodes.Ldarg_0),
                Instruction.Create(OpCodes.Call, p.BuildCall(typeof(Mod), "get_Assembly", typeof(System.Reflection.Assembly), new Type[]{})),
                Instruction.BuildJump(OpCodes.Brtrue_S, "assemblyIsNull"),
                Instruction.Create(OpCodes.Ldc_I4_1),
                Instruction.Create(OpCodes.Ret),
                Instruction.Create(OpCodes.Ldc_I4_0, null, "assemblyIsNull"),
                Instruction.Create(OpCodes.Ret)
            };

After method Patch is called it goes through the list of instructions and resolves those jumps. This way some errors can be thrown before dnlib tries to save the assembly, it is easier to keep track what jumps where and it is easier to modify whole thing later.

This is from the top of the head solution and I have not looked at the code so sorry if there are some obvious problems with it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions