本文整理汇总了C#中ICSharpCode.ILSpy.LoadedAssembly类的典型用法代码示例。如果您正苦于以下问题:C# LoadedAssembly类的具体用法?C# LoadedAssembly怎么用?C# LoadedAssembly使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LoadedAssembly类属于ICSharpCode.ILSpy命名空间,在下文中一共展示了LoadedAssembly类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetFilterResult
public override TreeViewNodeFilterResult GetFilterResult(LoadedAssembly asm, AssemblyFilterType type) {
if (type == AssemblyFilterType.NonNetFile)
return new TreeViewNodeFilterResult(FilterResult.Hidden, false);
if (type == AssemblyFilterType.Assembly) {
if (assembly == null || asm.AssemblyDefinition != assembly)
return new TreeViewNodeFilterResult(FilterResult.Hidden, false);
return new TreeViewNodeFilterResult(FilterResult.Match, false);
}
if (type == AssemblyFilterType.NetModule) {
if (asm.AssemblyDefinition != assembly)
return new TreeViewNodeFilterResult(FilterResult.Hidden, false);
if (assembly == null || assembly.ManifestModule != module) {
if (asm.ModuleDefinition != module)
return new TreeViewNodeFilterResult(FilterResult.Hidden, false);
return new TreeViewNodeFilterResult(FilterResult.Match, false);
}
else
return new TreeViewNodeFilterResult(FilterResult.Match, asm.ModuleDefinition != assembly.ManifestModule);
}
Debug.Fail("Invalid AssemblyFilterType value");
return new TreeViewNodeFilterResult(FilterResult.Hidden, false);
}
示例2: GetFilterResult
public override TreeViewNodeFilterResult GetFilterResult(LoadedAssembly asm, AssemblyFilterType type) {
if (asm.AssemblyDefinition != allowedAsm)
return new TreeViewNodeFilterResult(FilterResult.Hidden, false);
if (allowedAsm == null && asm.ModuleDefinition != allowedMod)
return new TreeViewNodeFilterResult(FilterResult.Hidden, false);
return base.GetFilterResult(asm, type);
}
示例3: Execute
static void Execute(ILSpyTreeNode[] nodes)
{
if (!AddNetModuleToAssemblyCommand.CanExecute(nodes))
return;
var dialog = new System.Windows.Forms.OpenFileDialog() {
Filter = ".NET NetModules (*.netmodule)|*.netmodule|All files (*.*)|*.*",
RestoreDirectory = true,
};
if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
return;
if (string.IsNullOrEmpty(dialog.FileName))
return;
var asm = new LoadedAssembly(MainWindow.Instance.CurrentAssemblyList, dialog.FileName);
if (asm.ModuleDefinition == null || asm.AssemblyDefinition != null) {
MainWindow.Instance.ShowMessageBox(string.Format("{0} is not a NetModule", asm.FileName), System.Windows.MessageBoxButton.OK);
asm.TheLoadedFile.Dispose();
return;
}
var cmd = new AddExistingNetModuleToAssemblyCommand((AssemblyTreeNode)nodes[0], asm);
UndoCommandManager.Instance.Add(cmd);
MainWindow.Instance.JumpToReference(cmd.modNode);
}
示例4: WriteResourceToFile
public string WriteResourceToFile(LoadedAssembly assembly, string fileName, Stream stream, DecompilationOptions options)
{
var document = BamlResourceEntryNode.LoadIntoDocument(assembly.GetAssemblyResolver(), assembly.AssemblyDefinition, stream);
fileName = Path.ChangeExtension(fileName, ".xaml");
document.Save(Path.Combine(options.SaveAsProjectDirectory, fileName));
return fileName;
}
示例5: DecompileAssembly
public override void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
{
output.WriteLine("// " + assembly.FileName);
output.WriteLine();
new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken).WriteAssemblyHeader(assembly.AssemblyDefinition);
}
示例6: DecompileAssembly
public virtual void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
{
WriteCommentLine(output, assembly.FileName);
if (assembly.AssemblyDefinition != null) {
if (assembly.AssemblyDefinition.IsContentTypeWindowsRuntime) {
WriteCommentLine(output, assembly.AssemblyDefinition.Name + " [WinRT]");
} else {
WriteCommentLine(output, assembly.AssemblyDefinition.FullName);
}
} else {
WriteCommentLine(output, assembly.ModuleDefinition.Name);
}
}
示例7: GetFilterResult
public override TreeViewNodeFilterResult GetFilterResult(LoadedAssembly asm, AssemblyFilterType type) {
VisibleMembersFlags thisFlag, visibleFlags;
switch (type) {
case AssemblyFilterType.Assembly:
thisFlag = VisibleMembersFlags.AssemblyDef;
visibleFlags = thisFlag | VisibleMembersFlags.ModuleDef |
VisibleMembersFlags.Namespace | VisibleMembersFlags.AnyTypeDef |
VisibleMembersFlags.FieldDef | VisibleMembersFlags.MethodDef |
VisibleMembersFlags.InstanceConstructor | VisibleMembersFlags.PropertyDef |
VisibleMembersFlags.EventDef | VisibleMembersFlags.AssemblyRef |
VisibleMembersFlags.BaseTypes | VisibleMembersFlags.DerivedTypes |
VisibleMembersFlags.ModuleRef | VisibleMembersFlags.ResourceList |
VisibleMembersFlags.MethodBody | VisibleMembersFlags.ParamDefs |
VisibleMembersFlags.ParamDef | VisibleMembersFlags.Locals |
VisibleMembersFlags.Local | VisibleMembersFlags.Resource |
VisibleMembersFlags.ResourceElement | VisibleMembersFlags.PE |
VisibleMembersFlags.Hex;
break;
case AssemblyFilterType.NetModule:
thisFlag = VisibleMembersFlags.ModuleDef;
visibleFlags = thisFlag |
VisibleMembersFlags.Namespace | VisibleMembersFlags.AnyTypeDef |
VisibleMembersFlags.FieldDef | VisibleMembersFlags.MethodDef |
VisibleMembersFlags.InstanceConstructor | VisibleMembersFlags.PropertyDef |
VisibleMembersFlags.EventDef | VisibleMembersFlags.AssemblyRef |
VisibleMembersFlags.BaseTypes | VisibleMembersFlags.DerivedTypes |
VisibleMembersFlags.ModuleRef | VisibleMembersFlags.ResourceList |
VisibleMembersFlags.MethodBody | VisibleMembersFlags.ParamDefs |
VisibleMembersFlags.ParamDef | VisibleMembersFlags.Locals |
VisibleMembersFlags.Local | VisibleMembersFlags.Resource |
VisibleMembersFlags.ResourceElement | VisibleMembersFlags.PE |
VisibleMembersFlags.Hex;
break;
case AssemblyFilterType.NonNetFile:
default:
thisFlag = VisibleMembersFlags.NonNetFile;
visibleFlags = thisFlag | VisibleMembersFlags.PE | VisibleMembersFlags.Hex;
break;
}
bool isMatch = (flags & thisFlag) != 0;
if ((flags & visibleFlags) == 0)
return new TreeViewNodeFilterResult(FilterResult.Hidden, isMatch);
if (isMatch)
return new TreeViewNodeFilterResult(FilterResult.Match, isMatch); // Make sure it's not hidden
return new TreeViewNodeFilterResult(null, isMatch);
}
示例8: DecompileAssembly
public AssemblyCompiler AssemblyCompiler { get { return compiler.AssemblyCompiler; } }
public MapFileLookup MapFile { get { return compiler.MapFile; } }
public static bool GenerateSetNextInstructionCode
{
get { return compiler.GenerateSetNextInstructionCode; }
set { compiler.GenerateSetNextInstructionCode = value; }
}
public override void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
{
compiler.CompileIfRequired(assembly.AssemblyDefinition);
示例9: DecompileAssembly
public override void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
{
output.WriteLine("// " + assembly.FileName);
output.WriteLine();
ReflectionDisassembler rd = new ReflectionDisassembler(output, detectControlStructure, options.CancellationToken);
//if (options.FullDecompilation)
// rd.WriteAssemblyReferences(assembly.ModuleDefinition);
if (assembly.AssemblyDefinition != null)
rd.WriteAssemblyHeader(assembly.AssemblyDefinition);
output.WriteLine();
rd.WriteModuleHeader(assembly.ModuleDefinition);
if (options.FullDecompilation) {
output.WriteLine();
output.WriteLine();
rd.WriteModuleContents(assembly.ModuleDefinition);
}
}
示例10: OpenAssembly
/// <summary>
/// Opens an assembly from disk.
/// Returns the existing assembly node if it is already loaded.
/// </summary>
public LoadedAssembly OpenAssembly(string file)
{
App.Current.Dispatcher.VerifyAccess();
file = Path.GetFullPath(file);
foreach (LoadedAssembly asm in this.assemblies) {
if (file.Equals(asm.FileName, StringComparison.OrdinalIgnoreCase))
return asm;
}
var newAsm = new LoadedAssembly(this, file);
lock (assemblies) {
this.assemblies.Add(newAsm);
}
return newAsm;
}
示例11: DecompileAssembly
public virtual void DecompileAssembly(LoadedAssembly assembly, ITextOutput output, DecompilationOptions options)
{
WriteCommentLine(output, assembly.FileName);
WriteCommentLine(output, assembly.AssemblyDefinition.FullName);
}
示例12: WriteResourceFilesInProject
IEnumerable<Tuple<string, string>> WriteResourceFilesInProject(LoadedAssembly assembly, DecompilationOptions options, HashSet<string> directories)
{
//AppDomain bamlDecompilerAppDomain = null;
//try {
foreach (EmbeddedResource r in assembly.AssemblyDefinition.MainModule.Resources.OfType<EmbeddedResource>()) {
string fileName;
Stream s = r.GetResourceStream();
s.Position = 0;
if (r.Name.EndsWith(".g.resources", StringComparison.OrdinalIgnoreCase)) {
IEnumerable<DictionaryEntry> rs = null;
try {
rs = new ResourceSet(s).Cast<DictionaryEntry>();
}
catch (ArgumentException) {
}
if (rs != null && rs.All(e => e.Value is Stream)) {
foreach (var pair in rs) {
fileName = Path.Combine(((string)pair.Key).Split('/').Select(p => TextView.DecompilerTextView.CleanUpName(p)).ToArray());
string dirName = Path.GetDirectoryName(fileName);
if (!string.IsNullOrEmpty(dirName) && directories.Add(dirName)) {
Directory.CreateDirectory(Path.Combine(options.SaveAsProjectDirectory, dirName));
}
Stream entryStream = (Stream)pair.Value;
entryStream.Position = 0;
if (fileName.EndsWith(".baml", StringComparison.OrdinalIgnoreCase)) {
MemoryStream ms = new MemoryStream();
entryStream.CopyTo(ms);
// TODO implement extension point
// var decompiler = Baml.BamlResourceEntryNode.CreateBamlDecompilerInAppDomain(ref bamlDecompilerAppDomain, assembly.FileName);
// string xaml = null;
// try {
// xaml = decompiler.DecompileBaml(ms, assembly.FileName, new ConnectMethodDecompiler(assembly), new AssemblyResolver(assembly));
// }
// catch (XamlXmlWriterException) { } // ignore XAML writer exceptions
// if (xaml != null) {
// File.WriteAllText(Path.Combine(options.SaveAsProjectDirectory, Path.ChangeExtension(fileName, ".xaml")), xaml);
// yield return Tuple.Create("Page", Path.ChangeExtension(fileName, ".xaml"));
// continue;
// }
}
using (FileStream fs = new FileStream(Path.Combine(options.SaveAsProjectDirectory, fileName), FileMode.Create, FileAccess.Write)) {
entryStream.CopyTo(fs);
}
yield return Tuple.Create("Resource", fileName);
}
continue;
}
}
fileName = GetFileNameForResource(r.Name, directories);
using (FileStream fs = new FileStream(Path.Combine(options.SaveAsProjectDirectory, fileName), FileMode.Create, FileAccess.Write)) {
s.CopyTo(fs);
}
yield return Tuple.Create("EmbeddedResource", fileName);
}
//}
//finally {
// if (bamlDecompilerAppDomain != null)
// AppDomain.Unload(bamlDecompilerAppDomain);
//}
}
示例13: CreateDebugProcessVM
DebugProcessVM CreateDebugProcessVM(LoadedAssembly asm = null)
{
// Re-use the previous one if it's the same file
if (lastDebugProcessVM != null && asm != null) {
if (StringComparer.OrdinalIgnoreCase.Equals(lastDebugProcessVM.Filename, asm.FileName))
return lastDebugProcessVM.Clone();
}
var vm = new DebugProcessVM();
if (asm != null)
vm.Filename = asm.FileName;
vm.BreakProcessType = DebuggerSettings.Instance.BreakProcessType;
return vm;
}
示例14: DumpNetModule
static void DumpNetModule(ProjectInfo info, List<ProjectInfo> projectFiles)
{
var fileName = info.AssemblyFileName;
if (string.IsNullOrEmpty(fileName))
throw new Exception(".NET module filename is empty or null");
var asmList = new AssemblyList("dnspc.exe", false);
asmList.UseGAC = !noGac;
asmList.AddSearchPath(Path.GetDirectoryName(fileName));
foreach (var path in asmPaths)
asmList.AddSearchPath(path);
var lasm = new LoadedAssembly(asmList, fileName);
var opts = new DecompilationOptions {
FullDecompilation = true,
CancellationToken = new CancellationToken(),
};
TextWriter writer = null;
try {
var lang = GetLanguage();
if (useStdout)
writer = System.Console.Out;
else {
var baseDir = GetProjectDir(lang, fileName);
Directory.CreateDirectory(baseDir);
writer = new StreamWriter(info.ProjectFileName, false, Encoding.UTF8);
opts.SaveAsProjectDirectory = baseDir;
opts.DontReferenceStdLib = noCorlibRef;
opts.ProjectFiles = projectFiles;
opts.ProjectGuid = info.ProjectGuid;
opts.DontShowCreateMethodBodyExceptions = dontMaskErr;
Console.WriteLine("Saving {0} to {1}", fileName, baseDir);
}
lang.DecompileAssembly(lasm, new PlainTextOutput(writer), opts);
}
finally {
if (!useStdout && writer != null)
writer.Dispose();
}
}
示例15: HandleModelUpdated
public override bool HandleModelUpdated(LoadedAssembly asm)
{
this.Children.RemoveAll(
delegate(SharpTreeNode n) {
AnalyzerTreeNode an = n as AnalyzerTreeNode;
return an == null || !an.HandleModelUpdated(asm);
});
return true;
}