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

Jump helper function #29

Open
DenJur opened this issue Jul 30, 2017 · 1 comment
Open

Jump helper function #29

DenJur opened this issue Jul 30, 2017 · 1 comment
Assignees
Milestone

Comments

@DenJur
Copy link

DenJur commented Jul 30, 2017

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.

@ioncodes
Copy link
Owner

Thanks for this great idea! I will add this to the v1 pool :)

@ioncodes ioncodes self-assigned this Jul 30, 2017
@ioncodes ioncodes added this to the v1 milestone Jul 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants