private void CheckSameAssembly()
        {
            List <string> processed = new List <string>();

            for (int i = 0; i < this.Assembly.Length - 1; i++)
            {
                Reflector.CodeModel.IAssembly a1 = (Reflector.CodeModel.IAssembly) this.Assembly[i];
                if (a1 == null)
                {
                    continue;
                }
                string name = a1.ToString();
                for (int j = i + 1; j < this.Assembly.Length; j++)
                {
                    Reflector.CodeModel.IAssembly a2 = (Reflector.CodeModel.IAssembly) this.Assembly[j];
                    if (a2 == null)
                    {
                        continue;
                    }
                    if (name == a2.ToString() &&
                        !processed.Contains(name))
                    {
                        SimpleMessage.ShowInfo(String.Format("You are loading multiple instances of Assembly:\n\"{0}\".\n\n.Net Reflector will only work for the last loaded one, or the one explicit loaded with Load button.", name));
                        processed.Add(name);
                    }
                }
            }
        }
        public override void UnloadAssembly(object assembly)
        {
            Reflector.CodeModel.IAssembly a = (Reflector.CodeModel.IAssembly)assembly;

            string             path = a.Location;
            AssemblyDefinition ad   = FindAssemblyDefinition(path);

            if (ad != null)
            {
                CecilHelper.RemoveAssemblyCache(ad);
            }
            _reflector.AssemblyManager.Unload(a);
        }
Exemplo n.º 3
0
        private void DisassembleFile(string fileName)
        {
            WriteLine(String.Format("{0}: ", fileName));

            string outputDir = Path.Combine(txtOutputDir.Text, Path.GetFileName(fileName)) + "_Source";

            if (!Directory.Exists(outputDir))
            {
                Directory.CreateDirectory(outputDir);
            }

            Reflector.CodeModel.IAssembly assembly = null;
            bool unloadAssembly = false;

            try
            {
                assembly = _reflector.FindAssembly(fileName);
                if (assembly == null)
                {
                    assembly       = _reflector.LoadAssembly(fileName);
                    unloadAssembly = true;
                }
                _host.SetProgress(0);

                FileDisassemblerHelper helper = new FileDisassemblerHelper(
                    _reflector,
                    fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) ? ProjectTypes.Library : ProjectTypes.WinExe,
                    outputDir,
                    new FileDisassemblerHelper.WriteLineDelegate(WriteLine),
                    new FileDisassemblerHelper.SetProgressBarDelegate(SetProgressBar),
                    new FileDisassemblerHelper.IsCancelPendingDelegate(IsCancelPending));

                int exceptions = helper.GenerateCode(assembly);

                WriteLine(string.Format("Done. {0} error(s).\r\n", exceptions));
            }
            catch
            {
                throw;
            }
            finally
            {
                if (assembly != null && unloadAssembly)
                {
                    _reflector.AssemblyManager.Unload(assembly);
                }
                _host.SetProgress(100);
            }
        }
Exemplo n.º 4
0
        public static Reflector.CodeModel.IModule Cecil2Reflector(ModuleDefinition md)
        {
            AssemblyDefinition ad = md.Assembly;

            Reflector.CodeModel.IAssembly a = (ad != null ? Cecil2Reflector(ad) : Cecil2Reflector(md.FullyQualifiedName));
            if (a == null)
            {
                return(null);
            }

            string mdName = md.Name;

            foreach (Reflector.CodeModel.IModule m in a.Modules)
            {
                if (m.Name == mdName)
                {
                    return(m);
                }
            }
            return(null);
        }