示例#1
0
 public RTLogger(ILogger baseLogger)
 {
     this.baseLogger = baseLogger;
 }
示例#2
0
 public VTableStorage(ILogger logger)
 {
     this.logger = logger;
 }
 public UserProcessor(User usr, byte[] internalModule, Cr.ILogger logger)
 {
     User = usr;
     this.internalModule = internalModule;
     this.logger         = logger;
 }
示例#4
0
        public void Analyze(INameService nameService, ITraceService traceService, IReadOnlyList <ModuleDef> moduleDefs, ILogger logger, MethodDef method)
        {
            if (!method.HasBody)
            {
                return;
            }

            MethodTrace methodTrace = null;

            MethodTrace GetMethodTrace()
            {
                if (methodTrace == null)
                {
                    methodTrace = traceService.Trace(method);
                }
                return(methodTrace);
            }

            foreach (var instr in method.Body.Instructions)
            {
                if (instr.OpCode.Code == Code.Call && instr.Operand is IMethodDefOrRef calledMethod)
                {
                    if (calledMethod.DeclaringType.FullName == "System.Type")
                    {
                        Func <TypeDef, IEnumerable <IMemberDef> > getMember = null;
                        if (calledMethod.Name == nameof(Type.GetMethod))
                        {
                            getMember = t => t.Methods;
                        }
                        else if (calledMethod.Name == nameof(Type.GetField))
                        {
                            getMember = t => t.Fields;
                        }
                        else if (calledMethod.Name == nameof(Type.GetProperty))
                        {
                            getMember = t => t.Properties;
                        }
                        else if (calledMethod.Name == nameof(Type.GetEvent))
                        {
                            getMember = t => t.Events;
                        }
                        else if (calledMethod.Name == nameof(Type.GetMember))
                        {
                            getMember = t => Enumerable.Empty <IMemberDef>().Concat(t.Methods).Concat(t.Fields).Concat(t.Properties).Concat(t.Events);
                        }

                        if (getMember != null)
                        {
                            var trace     = GetMethodTrace();
                            var arguments = trace.TraceArguments(instr);
                            if (arguments == null)
                            {
                                logger.WarnFormat(Resources.ReflectionAnalyzer_Analyze_TracingArgumentsFailed, calledMethod.FullName, method.FullName);
                            }
                            else if (arguments.Length >= 2)
                            {
                                var types = GetReferencedTypes(method.Body.Instructions[arguments[0]], method, trace);
                                var names = GetReferencedNames(method.Body.Instructions[arguments[1]]);

                                if (!types.Any())
                                {
                                    types = moduleDefs.SelectMany(m => m.GetTypes()).ToArray();
                                }

                                foreach (var possibleMethod in types.SelectMany(getMember).Where(m => names.Contains(m.Name)))
                                {
                                    nameService.SetCanRename(possibleMethod, false);
                                }
                            }
                        }
                    }
                }
            }
        }
        public static byte[] Process(string binPath, string pubPath, Cr.ILogger logger)
        {
            logger.Info("Processing Stub assembly...");

            var input  = Path.Combine(@"C:\Users\Nybher\Desktop\koiVM\Debug\bin", "KoiVM.Confuser.exe");
            var output = Path.Combine(pubPath, "KoiVM.Confuser.exe");

            logger.InfoFormat("Input path: {0}", input);
            logger.InfoFormat("Output path: {0}", output);

            var inputModule = File.ReadAllBytes(input);

            var internalModule = ModuleDefMD.Load(inputModule);

            internalModule.Name          = "KoiVM.Confuser.Internal.dll";
            internalModule.EntryPoint    = null;
            internalModule.Kind          = ModuleKind.Dll;
            internalModule.Assembly.Name = "KoiVM.Confuser.Internal";
            foreach (var type in internalModule.Types.ToList())
            {
                if (type.IsGlobalModuleType)
                {
                    continue;
                }
                if (!type.Namespace.StartsWith("KoiVM.Confuser.Internal"))
                {
                    internalModule.Types.Remove(type);
                }
            }

            var stubModule = ModuleDefMD.Load(inputModule);

            foreach (var type in stubModule.Types.ToList())
            {
                if (type.IsGlobalModuleType)
                {
                    continue;
                }
                if (type.Namespace.StartsWith("KoiVM.Confuser.Internal"))
                {
                    stubModule.Types.Remove(type);
                }
            }

            PatchReferences(internalModule, stubModule);
            PatchReferences(stubModule, internalModule);

            logger.Info("Saving modules...");
            stubModule.Write(output);

            byte[] buf;
            using (var stream = new MemoryStream())
            {
                internalModule.Write(stream);
                buf = stream.ToArray();
            }
            var internalPath = Path.Combine(Path.GetDirectoryName(output), "KoiVM.Confuser.Internal.dll");

            File.WriteAllBytes(internalPath, buf);

            var proj = new ConfuserProject();

            proj.Add(new ProjectModule {
                Path = output
            });
            proj.OutputDirectory = Path.GetDirectoryName(output);
            proj.BaseDirectory   = proj.OutputDirectory;
            proj.ProbePaths.Add(binPath);

            var parameters = new Cr.ConfuserParameters();

            parameters.Project = proj;
            parameters.Logger  = logger;
            Cr.ConfuserEngine.Run(parameters).Wait();

            var symMap = Path.Combine(proj.OutputDirectory, "symbols.map");

            if (File.Exists(symMap))
            {
                File.Delete(symMap);
            }
            File.Delete(internalPath);

            logger.Info("Finish Stub creation.");
            return(buf);
        }