Beispiel #1
0
        static void Main(string[] args)
        {
            if (args.Length != 1 || !File.Exists(args[0]))
            {
                return;
            }

            var filePath = args[0];

            Console.WriteLine("Loading module..");
            var module = ModuleDefMD.Load(filePath);

            Console.WriteLine("Initializing deobfuscator..");
            var deobfuscator = new Deobfuscator(module, filePath);

            var outputPath = Misc.GetOutPath(filePath);
            var result     = deobfuscator.Process(outputPath);

            var message = result
                ? "Successfully deobfuscated.."
                : "Failed to deobfuscate..";

            Console.WriteLine(message);
            Console.Read();
        }
Beispiel #2
0
        /// <summary>
        /// Read single component
        /// </summary>
        /// <param name="path">component .xdev file path</param>
        /// <returns>Returns single component instance</returns>
        public Component ReadComponent(string path)
        {
            Component device = null;

            XmlSerializer serializer = new XmlSerializer(typeof(Component));

            try
            {
                using (StreamReader reader = new StreamReader(path))
                {
                    device = (Component)serializer.Deserialize(reader);
                }
                return(device);
            }
            catch (Exception e)
            {
                Console.WriteLine("Component blocked, trying to deobfuscate... ");
            }

            //If component is blocked
            Deobfuscator deobfuscator        = new Deobfuscator();
            string       deobfuscatedContent = deobfuscator.Deobfuscate(path);

            using (var reader = new StringReader(deobfuscatedContent))
            {
                device = (Component)serializer.Deserialize(reader);
            }

            return(device);
        }
        private void CreateOriginal(string oldfile, string newfile)
        {
            AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(oldfile, new ReaderParameters {
                AssemblyResolver = resolver
            });
            Deobfuscator deob = Deobfuscators.Find(assembly);

            if (deob != null)
            {
                DialogResult result = MessageBox.Show(this, string.Format("Assembly '{0}' appears to be obfuscated using '{1}', attempt to deobfuscate?", assembly.MainModule.Name, deob.Name), "Oxide Patcher", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                if (result == DialogResult.Yes)
                {
                    // Deobfuscate
                    if (deob.Deobfuscate(assembly))
                    {
                        // Success
                        if (File.Exists(newfile))
                        {
                            File.Delete(newfile);
                        }
                        assembly.Write(newfile);
                        return;
                    }
                    else
                    {
                        MessageBox.Show(this, "Deobfuscation failed!", "Oxide Patcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            File.Copy(oldfile, newfile);
        }
Beispiel #4
0
        private void CheckCustomAttributes(List <string> errors,
                                           TypeDefinition sourceTd,
                                           TypeDefinition targetTd,
                                           Deobfuscator deobf)
        {
            if (sourceTd.CustomAttributes.Count > 0)
            {
                for (int i = 0; i < sourceTd.CustomAttributes.Count; i++)
                {
                    CustomAttribute ca = sourceTd.CustomAttributes[i];

                    for (int j = 0; j < ca.ConstructorArguments.Count; j++)
                    {
                        CustomAttributeArgument caa       = ca.ConstructorArguments[j];
                        TypeDefinition          valueType = caa.Value as TypeDefinition;
                        if (caa.Type.FullName == "System.Type" && IsRenameMe(valueType.Name))
                        {
                            string         targetTypeName  = GetTargetTypeName(deobf, valueType);
                            TypeDefinition targetValueType = targetTd.CustomAttributes[i].ConstructorArguments[j].Value as TypeDefinition;
                            if (targetTypeName != targetValueType.FullName)
                            {
                                errors.Add(String.Format("Unmatched custom attribute type \"{0}\"->\"{1}\".", valueType.FullName, targetValueType.FullName));
                            }
                        }
                    }

                    for (int j = 0; j < ca.Fields.Count; j++)
                    {
                        CustomAttributeNamedArgument cana = ca.Fields[j];
                        if (IsRenameMe(cana.Name))
                        {
                            string targetName = targetTd.CustomAttributes[i].Fields[j].Name;
                            if (cana.Name == targetName)
                            {
                                errors.Add(String.Format("Unrenamed custom attribute named argument found \"{0}\".", cana.Name));
                            }
                        }
                    }

                    for (int j = 0; j < ca.Properties.Count; j++)
                    {
                        CustomAttributeNamedArgument cana = ca.Properties[j];
                        if (IsRenameMe(cana.Name))
                        {
                            string targetName = targetTd.CustomAttributes[i].Properties[j].Name;
                            if (cana.Name == targetName)
                            {
                                errors.Add(String.Format("Unrenamed custom attribute named argument found \"{0}\".", cana.Name));
                            }
                        }
                    }

                    continue;
                }
            }
        }
        public void CreateDeobfuscator(string renamingMapFilePath)
        {
            if (m_deobfuscator != null && m_deobfuscator.RenamingMapPath.Equals(renamingMapFilePath, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            m_allObjects   = new Lazy <List <ClrObject> >(() => Heap.EnumerateClrObjects().ToList());
            m_deobfuscator = new Deobfuscator(renamingMapFilePath);
        }
Beispiel #6
0
        public override IDeobfuscator ModuleReloaded(ModuleDefMD module)
        {
            var newOne = new Deobfuscator(options);

            newOne.SetModule(module);
            newOne.mainType      = new MainType(module, mainType);
            newOne.decrypterInfo = decrypterInfo;
            decrypterInfo        = null;
            if (newOne.decrypterInfo != null)
            {
                newOne.decrypterInfo.mainType = newOne.mainType;
            }
            return(newOne);
        }
Beispiel #7
0
        public void CreateDeobfuscator(string renamingMapFilePath)
        {
            if (m_deobfuscator != null && m_deobfuscator.RenamingMapPath.Equals(renamingMapFilePath, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            if (m_allObjects.IsValueCreated)
            {
                m_allObjects = CreateLazyAllObjects();
            }

            m_deobfuscator = new Deobfuscator(renamingMapFilePath);
        }
Beispiel #8
0
        public MainWindowPresenter(IMainWindowView view)
        {
            this.view = view;
            var mappingStore = new MappingStore();

            this.mapping = new Mapping(mappingStore);
            this.mapping.LoadingCompleted     += Mapping_LoadingCompleted;
            this.mapping.LiveLoadingCompleted += Mapping_LoadingCompleted;

            this.versionsManager = new Versions(mappingStore);
            this.versionsManager.LoadingCompleted += VersionsManager_LoadingCompleted;

            this.deobfuscator = new Deobfuscator(this.mapping);
            this.deobfuscator.ReportDeobfuscateProgress += Deobfuscator_ReportDeobfuscateProgress;
            this.deobfuscator.DeobfuscationCompleted    += Deobfuscator_DeobfuscationCompleted;
        }
Beispiel #9
0
        public void Main()
        {
            var deobfuscator = new Deobfuscator();

            if (DoLoad)
            {
                if (!deobfuscator.Load(PathToLoad))
                {
                    return;
                }
            }
            deobfuscator.Deobfuscate(PathToArchive, DisableJavaFixes);
            if (DoSave)
            {
                deobfuscator.Save(PathToSave);
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            switch (btnOK.Text)
            {
            case Consts.Stop:
                _isCancelPending = true;
                return;

            default:
                break;
            }

            string outputDir = txtOutputDir.Text;

            if (!Directory.Exists(outputDir))
            {
                SimpleMessage.ShowInfo("Please choose output directory.");
                return;
            }

            if (_sourceDir != null && _sourceDir.Equals(outputDir))
            {
                Config.DeobfOutputDir = String.Empty;
            }
            else
            {
                Config.DeobfOutputDir = outputDir;
            }

            Config.DeobfFlowOptionBranchLoopCount = (int)nudLoopCount.Value;
            Config.DeobfFlowOptionMaxRefCount     = (int)nudMaxRefCount.Value;
            Config.LastRegex    = txtRegex.Text;
            Config.DeobfProfile = cboProfile.SelectedIndex;
            Config.DeobfFlowOptionBranchDirection = cboDirection.SelectedIndex;

            try
            {
                btnOK.Text       = Consts.Stop;
                _isCancelPending = false;

                Utils.EnableUI(this.Controls, false);

                DeobfOptions options = GetOptions();
                _host.TextInfo = options;
                Deobfuscator deobf = new Deobfuscator(options);
                deobf.Go();

                List <DeobfError> errors = deobf.Errors;
                if (errors.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (DeobfError error in errors)
                    {
                        sb.Append(error.ToString());
                        sb.Append("\r\n\r\n");
                    }
                    SimpleMessage.ShowError(sb.ToString());
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                _host.TextInfo = null;
                btnOK.Text     = Consts.OK;

                Utils.EnableUI(this.Controls, true);
            }
        }
Beispiel #11
0
 private string GetTargetTypeName(Deobfuscator deobf, TypeDefinition sourceTd)
 {
     return(String.Format("NS001.{0}", deobf.GetNewTypeName(sourceTd)));
 }