public bool Parse(DumpMode mode = DumpMode.AutoPlus, ulong codeRegistration = 0L, ulong metadataRegistration = 0L) { if (il2cpp == null) { return(false); } switch (mode) { case DumpMode.Auto: return(il2cpp.Search()); case DumpMode.AutoAdvanced: return(il2cpp.AdvancedSearch( metadata.methodDefs.Count(x => x.methodIndex >= 0) )); case DumpMode.AutoPlus: return(il2cpp.PlusSearch( metadata.methodDefs.Count(x => x.methodIndex >= 0), metadata.typeDefs.Length )); case DumpMode.AutoSymbol: return(il2cpp.SymbolSearch()); case DumpMode.Manual: il2cpp.Init(codeRegistration, metadataRegistration); return(true); default: return(false); } }
public void Dump(string filename, DumpMode mode = DumpMode.Text) { if (mode == DumpMode.Text) { InternalTextDump(filename); } if (mode == DumpMode.Binary) { InternalBinaryDump(filename); } }
public static void Dump <T>(T obj, DumpMode mode) { var nvps = CreateTable(obj, mode == DumpMode.Table); if (mode == DumpMode.Table) { DumpTable(nvps); } else if (mode == DumpMode.Details) { DumpDetails(nvps); } else { throw new ArgumentException("Invalid mode."); } }
public static void Dump <T>(T obj, DumpMode mode) { // Func<PropertyInfo, string> tryGet = x => // { // try // { //#if NET35 // return (x.GetValue(obj, null) ?? "null").ToString(); //#else // return (x.GetValue(obj) ?? "null").ToString(); //#endif // } // catch (Exception e) // { // return string.Format("Error getting value: {0}", e); // } // }; // var t = obj.GetType(); // var nvps = t // .GetProperties() // .Select(x => new KeyValuePair<string, string>( // x.Name, // mode == DumpMode.Table ? // tryGet(x).Replace("\r", "\\r").Replace("\n", "\\n") : // tryGet(x) // )); var nvps = CreateTable(obj, mode == DumpMode.Table); if (mode == DumpMode.Table) { DumpTable(nvps); } else if (mode == DumpMode.Details) { DumpDetails(nvps); } else { throw new ArgumentException("Invalid mode."); } }
public static void Dump <T>(T obj, DumpMode mode) { Func <PropertyInfo, string> tryGet = x => { try { #if NET35 return((x.GetValue(obj, null) ?? "null").ToString()); #else return((x.GetValue(obj) ?? "null").ToString()); #endif } catch (Exception e) { return(string.Format("Error getting value: {0}", e)); } }; var t = obj.GetType(); var nvps = t .GetProperties() .Select(x => new KeyValuePair <string, string>( x.Name, mode == DumpMode.Table ? tryGet(x).Replace("\r", "\\r").Replace("\n", "\\n") : tryGet(x) )); if (mode == DumpMode.Table) { DumpTable(nvps); } else if (mode == DumpMode.Details) { DumpDetails(nvps); } else { throw new ArgumentException("Invalid mode."); } }
public DynamicMethod ComposePatchedMethod() { DynamicMethod method = AllocatePatchMethod(); var generator = new LoggingIlGenerator(method.GetILGenerator(), PrintMode.HasFlag(PrintModeEnum.EmittedReflection) ? LogLevel.Info : LogLevel.Trace); List <MsilInstruction> il = EmitPatched((type, pinned) => new MsilLocal(generator.DeclareLocal(type, pinned))).ToList(); var dumpTarget = DumpTarget != null?File.CreateText(DumpTarget) : null; try { const string gap = "\n\n\n\n\n"; void LogTarget(PrintModeEnum mode, bool err, string msg) { if (DumpMode.HasFlag(mode)) { dumpTarget?.WriteLine((err ? "ERROR " : "") + msg); } if (!PrintMode.HasFlag(mode)) { return; } if (err) { _log.Error(msg); } else { _log.Info(msg); } } if (PrintMsil || DumpTarget != null) { lock (_log) { var ctx = new MethodContext(_method); ctx.Read(); LogTarget(PrintModeEnum.Original, false, "========== Original method =========="); MethodTranspiler.IntegrityAnalysis((a, b) => LogTarget(PrintModeEnum.Original, a, b), ctx.Instructions, true); LogTarget(PrintModeEnum.Original, false, gap); LogTarget(PrintModeEnum.Emitted, false, "========== Desired method =========="); MethodTranspiler.IntegrityAnalysis((a, b) => LogTarget(PrintModeEnum.Emitted, a, b), il); LogTarget(PrintModeEnum.Emitted, false, gap); } } MethodTranspiler.EmitMethod(il, generator); try { PatchUtilities.Compile(method); } catch { lock (_log) { var ctx = new MethodContext(method); ctx.Read(); MethodTranspiler.IntegrityAnalysis((err, msg) => _log.Warn(msg), ctx.Instructions); } throw; } if (PrintMsil || DumpTarget != null) { lock (_log) { var ctx = new MethodContext(method); ctx.Read(); LogTarget(PrintModeEnum.Patched, false, "========== Patched method =========="); MethodTranspiler.IntegrityAnalysis((a, b) => LogTarget(PrintModeEnum.Patched, a, b), ctx.Instructions, true); LogTarget(PrintModeEnum.Patched, false, gap); } } } finally { dumpTarget?.Close(); } return(method); }
public void DumpTest <T>(T obj, DumpMode mode) { Cli.Dump <T>(obj, mode); // TODO: add assertions to method CliTest.DumpTest(!!0, DumpMode) }