本文整理汇总了C#中ReaderParameters类的典型用法代码示例。如果您正苦于以下问题:C# ReaderParameters类的具体用法?C# ReaderParameters怎么用?C# ReaderParameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReaderParameters类属于命名空间,在下文中一共展示了ReaderParameters类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAssemblyDef
public static AssemblyDefinition GetAssemblyDef(string assemblyPath)
{
if (assemblies.ContainsKey(assemblyPath))
return assemblies[assemblyPath];
var assemblyResolver = new DefaultAssemblyResolver();
var assemblyLocation = Path.GetDirectoryName(assemblyPath);
assemblyResolver.AddSearchDirectory(assemblyLocation);
var readerParameters = new ReaderParameters { AssemblyResolver = assemblyResolver };
var pdbName = Path.ChangeExtension(assemblyPath, "pdb");
if (File.Exists(pdbName))
{
var symbolReaderProvider = new PdbReaderProvider();
readerParameters.SymbolReaderProvider = symbolReaderProvider;
readerParameters.ReadSymbols = true;
}
var assemblyDef = AssemblyDefinition.ReadAssembly(assemblyPath, readerParameters);
assemblies.Add(assemblyPath,assemblyDef);
return assemblyDef;
}
示例2: LoadAssemblyAndGetMethods
public void LoadAssemblyAndGetMethods()
{
var readerParameters = new ReaderParameters { ReadSymbols = true };
assembly = AssemblyDefinition.ReadAssembly(assemblyPath, readerParameters);
methods = assembly.MainModule.Types.
SelectMany(type => type.Methods);
}
示例3: ReadModule
public void ReadModule()
{
if (pdbFound)
{
using (var symbolStream = File.OpenRead(pdbPath))
{
var readerParameters = new ReaderParameters
{
AssemblyResolver = this,
ReadSymbols = pdbFound || mdbFound,
SymbolReaderProvider = debugReaderProvider,
SymbolStream = symbolStream
};
ModuleDefinition = ModuleDefinition.ReadModule(AssemblyFilePath, readerParameters);
}
}
else
{
var readerParameters = new ReaderParameters
{
AssemblyResolver = this,
ReadSymbols = pdbFound || mdbFound,
SymbolReaderProvider = debugReaderProvider,
};
ModuleDefinition = ModuleDefinition.ReadModule(AssemblyFilePath, readerParameters);
}
}
示例4: ReadModule
public virtual void ReadModule()
{
string symbolsPath;
if (pdbFound)
{
symbolsPath = pdbPath;
}
else
{
symbolsPath = mdbPath;
}
var tempAssembly = $"{AssemblyFilePath}.tmp";
var tempSymbols = $"{symbolsPath}.tmp";
File.Copy(AssemblyFilePath, tempAssembly,true);
File.Copy(symbolsPath, tempSymbols, true);
SymbolStream = File.OpenRead(tempSymbols);
var readerParameters = new ReaderParameters
{
AssemblyResolver = this,
ReadSymbols = true,
SymbolReaderProvider = debugReaderProvider,
SymbolStream = SymbolStream,
};
ModuleDefinition = ModuleDefinition.ReadModule(tempAssembly, readerParameters);
}
示例5: Resolve
public AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
{
lock (resolutionCache)
{
string key = name.FullName;
AssemblyDefinition result;
if (resolutionCache.TryGetValue(key, out result))
return result;
}
if (!name.Name.StartsWith("System", StringComparison.OrdinalIgnoreCase)
&& !name.Name.StartsWith("mscorlib", StringComparison.OrdinalIgnoreCase))
return null;
var asm = Assembly.Load(name.ToString());
var asmDef = AssemblyDefinition.ReadAssembly(
asm.Location,
parameters ??
new ReaderParameters(ReadingMode.Deferred) { AssemblyResolver = this });
lock (resolutionCache)
{
string key = name.FullName;
AssemblyDefinition result;
if (resolutionCache.TryGetValue(key, out result))
return result;
resolutionCache[key] = asmDef;
}
return asmDef;
}
示例6: Patch
/// <summary>
/// Patches the specified input PDB file.
/// </summary>
/// <param name="inputExeFile">The input PDB file.</param>
/// <param name="outputPdbFile">The output PDB file.</param>
/// <param name="sourcePathRewriter">The source path modifier.</param>
/// <exception cref="System.ArgumentNullException">inputExeFile</exception>
public static void Patch(string inputExeFile, string outputPdbFile, SourcePathRewriterDelegate sourcePathRewriter)
{
if (inputExeFile == null) throw new ArgumentNullException("inputExeFile");
if (outputPdbFile == null) throw new ArgumentNullException("outputPdbFile");
if (sourcePathRewriter == null) throw new ArgumentNullException("sourcePathRewriter");
// Copy PDB from input assembly to output assembly if any
var inputPdbFile = Path.ChangeExtension(inputExeFile, "pdb");
if (!File.Exists(inputPdbFile))
{
ShowMessage(string.Format("Warning file [{0}] does not exist", inputPdbFile), ConsoleColor.Yellow);
return;
}
var symbolReaderProvider = new PdbReaderProvider();
var readerParameters = new ReaderParameters
{
SymbolReaderProvider = symbolReaderProvider,
ReadSymbols = true
};
// Read Assembly
var assembly = AssemblyDefinition.ReadAssembly(inputExeFile, readerParameters);
// Write back the assembly and pdb
assembly.Write(inputExeFile, new WriterParameters {WriteSymbols = true, SourcePathRewriter = sourcePathRewriter});
}
示例7: GetMemberReference
public MemberReference GetMemberReference(IAssemblyResolver resolver)
{
if (resolver == null)
throw new ArgumentNullException("resolver");
if (memberReference != null)
return memberReference;
// reload from filename
ReaderParameters readerParameters = new ReaderParameters();
// Use new assembly resolver instance so that the AssemblyDefinitions can be garbage-collected
// once the code is decompiled.
readerParameters.AssemblyResolver = resolver;
string typeName;
if (GetAssemblyAndType(FileName.ToString(), out assemblyFile, out typeName)) {
ModuleDefinition module = ModuleDefinition.ReadModule(assemblyFile, readerParameters);
TypeDefinition typeDefinition = module.GetType(typeName);
if (typeDefinition == null)
throw new InvalidOperationException("Could not find type");
memberReference = typeDefinition;
}
return memberReference;
}
示例8: Resolve
public AssemblyDefinition Resolve(string fullName, ReaderParameters parameters)
{
if (string.IsNullOrEmpty(fullName))
throw new ArgumentException("fullName is null or empty");
return Resolve(AssemblyNameReference.Parse(fullName), parameters);
}
示例9: Load
public static AssemblyDefinition Load(string fileName)
{
var resolver = new DefaultAssemblyResolver();
resolver.AddSearchDirectory(new FileInfo(fileName).DirectoryName);
var parameters = new ReaderParameters
{
SymbolReaderProvider = new PdbReaderProvider(),
ReadingMode = ReadingMode.Immediate,
AssemblyResolver = resolver
};
AssemblyDefinition assemblyDef;
try
{
assemblyDef = AssemblyDefinition.ReadAssembly(fileName, parameters);
}
catch (FileNotFoundException)
{
// Perhaps we have an MDB file (Mono), or there is no symbol file to load.
// Try MDB first!
parameters.SymbolReaderProvider = new MdbReaderProvider();
try
{
assemblyDef = AssemblyDefinition.ReadAssembly(fileName, parameters);
}
catch (FileNotFoundException)
{
parameters.SymbolReaderProvider = null;
assemblyDef = AssemblyDefinition.ReadAssembly(fileName, parameters);
}
}
return assemblyDef;
}
示例10: Main
static void Main(string[] args)
{
try
{
var path = args.Length >= 1 ? args[0] : "Ibasa.dll";
var symbolReader = new Mono.Cecil.Pdb.PdbReaderProvider();
var readerParameters = new ReaderParameters()
{
SymbolReaderProvider = symbolReader,
ReadSymbols = true,
};
var writerParameters = new WriterParameters()
{
WriteSymbols = true,
};
AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(path, readerParameters);
Console.WriteLine("Loaded {0}.", path);
GenerateMemoryType(assembly.MainModule);
Console.WriteLine("Saving new dll.");
assembly.Write(path, writerParameters);
}
catch (Exception e)
{
Console.WriteLine("InteropBuilder failed with: {0}", e);
}
}
示例11: Resolve
public override AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters)
{
if (name == null)
throw new ArgumentNullException("name");
return Cache.GetOrCreate(name.FullName, () => base.Resolve(name, parameters));
}
示例12: DiscoverSpecs
public IEnumerable<MSpecTestCase> DiscoverSpecs(string assemblyFilePath)
{
if (!this.AssemblyContainsMSpecReference(assemblyFilePath) || !this.SourceDirectoryContainsMSpec(assemblyFilePath))
return new List<MSpecTestCase>();
assemblyFilePath = Path.GetFullPath(assemblyFilePath);
if (!File.Exists(assemblyFilePath))
{
throw new ArgumentException("Could not find file: " + assemblyFilePath);
}
this.AssemblyFilename = assemblyFilePath;
// make sure that cecil looks in the assembly path for mspec (+ related assemblies) first
this.AssemblyResolver = new ScopedAssemblyResolver(Path.GetDirectoryName(assemblyFilePath));
this.ReaderParameters = new ReaderParameters()
{
ReadSymbols = true,
AssemblyResolver = AssemblyResolver
};
List<MSpecTestCase> list = new List<MSpecTestCase>();
List<IDelegateFieldScanner> fieldScanners = new List<IDelegateFieldScanner>();
fieldScanners.Add(new ItDelegateFieldScanner());
fieldScanners.Add(new CustomDelegateFieldScanner());
// statically inspect the types in the assembly using mono.cecil
var assembly = AssemblyDefinition.ReadAssembly(this.AssemblyFilename, this.ReaderParameters);
foreach (TypeDefinition type in GetNestedTypes(assembly.MainModule.Types))
{
// if a type is an It delegate generate some test case info for it
foreach (FieldDefinition fieldDefinition in type.Fields.Where(x => !x.Name.Contains("__Cached")))
{
foreach (IDelegateFieldScanner scanner in fieldScanners)
{
if (scanner.ProcessFieldDefinition(fieldDefinition))
{
string typeName = NormalizeCecilTypeName(type.Name);
string typeFullName = NormalizeCecilTypeName(type.FullName);
MSpecTestCase testCase = new MSpecTestCase()
{
ClassName = typeName,
ContextFullType = typeFullName,
SpecificationName = fieldDefinition.Name,
ContextDisplayName = GetContextDisplayName(type),
SpecificationDisplayName = fieldDefinition.Name.Replace("_", " "),
};
// get the source code location for the It delegate from the PDB file using mono.cecil.pdb
this.UpdateTestCaseWithLocation(type, testCase);
list.Add(testCase);
break;
}
}
}
}
return list.Select(x => x);
}
示例13: Weave
public static string Weave(string assemblyPath)
{
var newAssembly = assemblyPath.Replace(".dll", "2.dll");
var oldPdb = assemblyPath.Replace(".dll", ".pdb");
var newPdb = assemblyPath.Replace(".dll", "2.pdb");
File.Copy(assemblyPath, newAssembly, true);
File.Copy(oldPdb, newPdb, true);
var assemblyResolver = new MockAssemblyResolver
{
Directory = Path.GetDirectoryName(assemblyPath)
};
using (var symbolStream = File.OpenRead(newPdb))
{
var readerParameters = new ReaderParameters
{
ReadSymbols = true,
SymbolStream = symbolStream,
SymbolReaderProvider = new PdbReaderProvider()
};
var moduleDefinition = ModuleDefinition.ReadModule(newAssembly, readerParameters);
var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
AssemblyResolver = assemblyResolver
};
weavingTask.Execute();
moduleDefinition.Write(newAssembly);
return newAssembly;
}
}
示例14: ReadAssembly
public static AssemblyNode ReadAssembly (string filename)
{
var readerParameters = new ReaderParameters ();
AssemblyDefinition definition = AssemblyDefinition.ReadAssembly (filename, readerParameters);
return new AssemblyNode (definition);
}
示例15: WeaverHelper
public WeaverHelper(string projectPath)
{
this.projectPath = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, @"..\..\..\TestAssemblies", projectPath));
GetAssemblyPath();
AfterAssemblyPath = BeforeAssemblyPath.Replace(".dll", "2.dll");
File.Copy(BeforeAssemblyPath, AfterAssemblyPath, true);
var assemblyResolver = new TestAssemblyResolver(BeforeAssemblyPath, this.projectPath);
var readerParameters = new ReaderParameters
{
AssemblyResolver = assemblyResolver
};
var moduleDefinition = ModuleDefinition.ReadModule(AfterAssemblyPath, readerParameters);
var weavingTask = new ModuleWeaver
{
ModuleDefinition = moduleDefinition,
AssemblyResolver = assemblyResolver
};
weavingTask.Execute();
moduleDefinition.Write(AfterAssemblyPath);
Assembly = Assembly.LoadFile(AfterAssemblyPath);
}