Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use .net cil jmp opcode

Tags:

c#

.net

cil

I'm trying to get the jmp opcode to work in Cil

jmp  void ILTest.Program::MyFunc2(int32)

ilasm is fine with it, but when I run the program I always get "common language runtime detects an invalid program" exception.

I know this is unverifiable code so I have tried to give permissions

SecurityPermission perm = new SecurityPermission(SecurityPermissionFlag.Execution | SecurityPermissionFlag.SkipVerification | SecurityPermissionFlag.UnmanagedCode);

but it does not seem to have any effect.

Has anyone got a program using 'jmp' working?

like image 798
William Pearson Avatar asked Jan 29 '26 15:01

William Pearson


1 Answers

jmp can only jump to a method with the same arguments as the current method. Make sure you're already in a method taking an int32 as a parameter, and that you've nothing pushed on the stack: it must be empty. Also ensure you're not in a try/catch/filter/finally block.

If you can't meet those criteria, use a call instead.

like image 166
Julien Lebosquain Avatar answered Feb 01 '26 05:02

Julien Lebosquain