Esempio n. 1
0
		public SymbolEngine(string assemblyPath)
		{
			AssemblyDefinition assemblyDef = AssemblyFactory.GetAssembly(assemblyPath);
			m_moduleDef = assemblyDef.MainModule;
			PdbFactory factory = new PdbFactory();
			ISymbolReader reader = factory.CreateReader(m_moduleDef, assemblyPath);
			m_moduleDef.LoadSymbols(reader);
		}
 public void loadAndMapSymbols(AssemblyDefinition assemblyDefinition, string assemblyPath, bool decompileCodeIfNoPdb, string pathToSaveDecompiledSourceCode)
 {
     try
     {
         if (assemblyPath != null)
         {
             var pdbFile = assemblyPath.Replace(Path.GetExtension(assemblyPath), ".pdb");
             if (File.Exists(pdbFile))
             {
                 string unit = assemblyPath;
                 ModuleDefinition modDef = assemblyDefinition.MainModule;
                 var pdbFactory = new PdbFactory();
                 ISymbolReader reader = pdbFactory.CreateReader(modDef, unit);
                 modDef.LoadSymbols(reader);
             }
             else
             {
                 if (decompileCodeIfNoPdb)
                     new CecilDecompiler().decompile(assemblyDefinition, pathToSaveDecompiledSourceCode);
             }
         }
     }
     catch (Exception ex)
     {
         PublicDI.log.error("in loadAndMapSymbols: {0]", ex.Message);
     }            
 }
		internal BfAssembly(BfCache cache, AssemblyDefinition assemblyDef, bool isCoreAssembly, string rootDirectory)
		{
			this.int_0 = cache.method_15();
			this.assemblyDefinition_0 = assemblyDef;
			this.string_1 = assemblyDef.Name.Name;
			this.bool_0 = isCoreAssembly;
			this.string_0 = this.assemblyDefinition_0.Name.Version.ToString();
			try
			{
				PdbFactory pdbFactory = new PdbFactory();
				string text = Path.Combine(rootDirectory, this.assemblyDefinition_0.Name.Name + ".dll");
				if (System.IO.File.Exists(text))
				{
					this.isymbolReader_0 = pdbFactory.CreateReader(null, text);
				}
				text = Path.Combine(rootDirectory, this.assemblyDefinition_0.Name.Name + ".exe");
				if (System.IO.File.Exists(text))
				{
					this.isymbolReader_0 = pdbFactory.CreateReader(null, text);
				}
			}
			catch (Exception ex)
			{
				Logger.LogWarning("AssemblyConstructor", "Something went wrong " + ex.ToString());
			}
		}
Esempio n. 4
0
        private void CompileDebugInfo(AssemblyCompileInfo compileInfo)
        {
            AssemblyDefinition sourceAssemblyDefinition = compileInfo.SourceAssemblyDefinition;
            AssemblyDefinition assemblyDefinition = compileInfo.OutputAssemblyDefinition =
                AssemblyFactory.GetAssembly(compileInfo.OutputFilePath);
            ModuleDefinition moduleDefinition = assemblyDefinition.MainModule;

            PdbFactory pdbFactory = new PdbFactory();
                ISymbolWriter symbolWriter =
                pdbFactory.CreateWriter(moduleDefinition, compileInfo.OutputFilePath);
            ISymbolReader symbolReader =
                pdbFactory.CreateReader(sourceAssemblyDefinition.MainModule, sourceAssemblyDefinition.MainModule.Image.FileInformation.FullName);

            sourceAssemblyDefinition.MainModule.LoadSymbols(symbolReader);
            sourceAssemblyDefinition.MainModule.FullLoad();

            // setup debug header
            moduleDefinition.Image.AddDebugHeader();
            DebugHeader debugHeader = moduleDefinition.Image.DebugHeader;
            DebugHeader sourceDebugHeader = sourceAssemblyDefinition.MainModule.Image.DebugHeader;

            debugHeader.AddressOfRawData = sourceDebugHeader.AddressOfRawData;
            debugHeader.Age = sourceDebugHeader.Age;
            debugHeader.Characteristics = sourceDebugHeader.Characteristics;
            debugHeader.FileName = sourceDebugHeader.FileName;
            //debugHeader.FileName = Path.GetFullPath(Path.ChangeExtension(GetOutputFilePath(compileInfo.SourceAssemblyDefinition), ".pdb"));
            debugHeader.Magic = sourceDebugHeader.Magic;
            debugHeader.MajorVersion = sourceDebugHeader.MajorVersion;
            debugHeader.MinorVersion = sourceDebugHeader.MinorVersion;
            debugHeader.PointerToRawData = sourceDebugHeader.PointerToRawData;
            debugHeader.Signature = sourceDebugHeader.Signature;
            debugHeader.SizeOfData = sourceDebugHeader.SizeOfData;
            debugHeader.TimeDateStamp = sourceDebugHeader.TimeDateStamp;//(uint)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
            debugHeader.Type = sourceDebugHeader.Type;

            CustomAttribute sourceDebuggableAttribute = AttributeHelper.GetCustomAttribute(sourceAssemblyDefinition, "System.Diagnostics", "DebuggableAttribute");
            TypeDefinition debuggableAttributeType = ReferenceResolver.ResolveTypeReference(CoreTypes.GetCoreType("System.Diagnostics.DebuggableAttribute"), _compiler.Resolver);
            MethodDefinition debuggableAttributeCtor = debuggableAttributeType.Constructors.GetConstructor(false, new Type[] {
                typeof(bool),
                typeof(bool)
            });
            CustomAttribute debuggableAttribute = new CustomAttribute(moduleDefinition.Import(debuggableAttributeCtor));
            debuggableAttribute.ConstructorParameters.Add(true);
            debuggableAttribute.ConstructorParameters.Add(false);
            assemblyDefinition.CustomAttributes.Add(debuggableAttribute);

            // save files
            //moduleDefinition.SaveSymbols(symbolWriter);
            string tempFile = Path.GetTempFileName();
            AssemblyFactory.SaveAssembly(assemblyDefinition, tempFile);
            symbolWriter.Dispose();

            File.Delete(compileInfo.OutputFilePath);
            File.Move(tempFile, compileInfo.OutputFilePath);
        }