Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static VMDebugger vmDebugger;
- static void Main(string[] args)
- {
- uVirtualMachine uVM;
- VMOptionSet vmOptions = new VMOptionSet();
- vmOptions.AllowDebug = true;
- vmOptions.DisplayConsole = true;
- vmOptions.DisplayLogo = true;
- vmOptions.JITOptimize = false;
- vmOptions.ExecSecurity = VMExecutionSecurity.Safe;
- vmOptions.CallSecurity = VMCallSecurity.LocalFramework;
- uVM = new uVirtualMachine(vmOptions);
- vmDebugger = new VMDebugger(uVM);
- uVM.AttachDebugger(vmDebugger);
- vmDebugger.OnBreakPoint += new uVM.Virtual_Machine.Debugger.DebuggerEvents.BreakPointHandler(BreakPoint);
- uVM.OnBeforeJITCompilation += new uVM.Virtual_Machine.Events.JITCompilerHandler(BeforeJIT);
- uVM.LoadImage(Encoding.Default.GetBytes(
- "maxstacksize = 5\n" +
- "loadstr correct\n" +
- "loadstr correct\n" +
- "comp\n" +
- "jie 4\n" +
- "loadstr You failed! :)\n" +
- "println\n" +
- "wait\n" +
- "end\n" +
- "loadstr Success! :D\n" +
- "println\n" +
- "wait\n" +
- "end"
- ));
- uVM.QuickExecute();
- }
- public static void BeforeJIT(object o, JITCompilerEventArgs e)
- {
- //You can "Hook" JIT engine so that you can decrypt encrypted functions BEFORE they get JITed. Like in CodeVeil or CliSecure.
- byte[] evil = e.FunctionBody;
- }
- public static void BreakPoint(object o)
- {
- Console.WriteLine("Current Instruction:\n\nOpcode: {0}\nOperand: {1}\nSize: {2}\nIndex: {3}\nParentFunction: {4}", vmDebugger.CurrentInstruction.OpCode.ToString().ToLower(), vmDebugger.CurrentInstruction.Operand.ToString(), vmDebugger.CurrentInstruction.RequiredBytes, vmDebugger.CurrentInstruction.Index, vmDebugger.CurrentInstruction.ParentFunction.Name);
- Console.WriteLine("\nCurrent Function:\n\nName: {0}\nSize: {1}\nStackCount: {2}\nMaxStackSize: {3}\nInstruction Count: {4}\nEntry Point?: {5}", vmDebugger.CurrentFunction.Name, vmDebugger.CurrentFunction.Size, vmDebugger.CurrentFunction.Stack.Count, vmDebugger.CurrentFunction.MaxStackSize, vmDebugger.CurrentFunction.Instructions.Count, vmDebugger.CurrentFunction.EntryPoint);
- Console.WriteLine();
- uInstruction tmp = null;
- Console.WriteLine("Example; get first instruction from current function with opcode END:\n\nName: {0}\nIndex: {1}", (tmp = vmDebugger.RetrieveInstruction(vmDebugger.CurrentFunction, _OpCodes.END)).OpCode.ToString(), tmp.Index);
- Console.WriteLine();
- Console.WriteLine("Example; get second instruction from current function with opcode LOADSTR:\n\nName: {0}\nIndex: {1}", (tmp = vmDebugger.RetrieveInstruction(vmDebugger.CurrentFunction, _OpCodes.LOADSTR, 1)).OpCode.ToString(), tmp.Index);
- Console.ReadLine();
- vmDebugger.Resume();
- }
Add Comment
Please, Sign In to add comment