本文整理汇总了C#中ICSharpCode.Decompiler.DecompilerContext类的典型用法代码示例。如果您正苦于以下问题:C# DecompilerContext类的具体用法?C# DecompilerContext怎么用?C# DecompilerContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DecompilerContext类属于ICSharpCode.Decompiler命名空间,在下文中一共展示了DecompilerContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetClass
public string GetClass(TypeIdentity identity)
{
// Before we attempt to fetch it just try a decompilation.
GetAssembly(identity.AssemblyPath);
ModuleDefinition moduleDef;
if (!this.loadedModules.TryGetValue(identity.AssemblyPath, out moduleDef))
{
// Can't find the assembly, just return nothing.
return string.Empty;
}
TypeDefinition typeDef = moduleDef.GetType(identity.FullyQualifiedName);
if (typeDef == null)
{
// If we can't find our type just return as well.
return string.Empty;
}
DecompilerContext context = new DecompilerContext(moduleDef);
AstBuilder astBuilder = new AstBuilder(context);
astBuilder.AddType(typeDef);
PlainTextOutput textOutput = new PlainTextOutput();
astBuilder.GenerateCode(textOutput);
return textOutput.ToString();
}
开发者ID:chemix-lunacy,项目名称:Skyling,代码行数:27,代码来源:AssemblyAnalyzer.cs
示例2: DecompileMethod
public override void DecompileMethod(MethodDefinition method, ITextOutput output, DecompilationOptions options)
{
if (!method.HasBody) {
return;
}
ILAstBuilder astBuilder = new ILAstBuilder();
ILBlock ilMethod = new ILBlock();
ilMethod.Body = astBuilder.Build(method, inlineVariables);
if (abortBeforeStep != null) {
DecompilerContext context = new DecompilerContext(method.Module) { CurrentType = method.DeclaringType, CurrentMethod = method };
new ILAstOptimizer().Optimize(context, ilMethod, abortBeforeStep.Value);
}
var allVariables = ilMethod.GetSelfAndChildrenRecursive<ILExpression>().Select(e => e.Operand as ILVariable)
.Where(v => v != null && !v.IsParameter).Distinct();
foreach (ILVariable v in allVariables) {
output.WriteDefinition(v.Name, v);
if (v.Type != null) {
output.Write(" : ");
if (v.IsPinned)
output.Write("pinned ");
v.Type.WriteTo(output, ILNameSyntax.ShortTypeName);
}
output.WriteLine();
}
output.WriteLine();
foreach (ILNode node in ilMethod.Body) {
node.WriteTo(output);
output.WriteLine();
}
}
开发者ID:rmattuschka,项目名称:ILSpy,代码行数:34,代码来源:ILAstLanguage.cs
示例3: Decompile
public void Decompile(Stream assemblyStream, TextWriter resultWriter)
{
// ReSharper disable once AgentHeisenbug.CallToNonThreadSafeStaticMethodInThreadSafeType
var module = ModuleDefinition.ReadModule(assemblyStream);
((BaseAssemblyResolver)module.AssemblyResolver).AddSearchDirectory(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
);
var context = new DecompilerContext(module) {
Settings = {
AnonymousMethods = false,
YieldReturn = false,
AsyncAwait = false,
AutomaticProperties = false,
ExpressionTrees = false
}
};
var ast = new AstBuilder(context);
ast.AddAssembly(module.Assembly);
RunTransforms(ast, context);
// I cannot use GenerateCode as it re-runs all the transforms
var userCode = GetUserCode(ast);
WriteResult(resultWriter, userCode, context);
}
开发者ID:i3arnon,项目名称:TryRoslyn,代码行数:27,代码来源:AstDecompiler.cs
示例4: ILBlockTranslator
public ILBlockTranslator(AssemblyTranslator translator, DecompilerContext context, MethodReference methodReference, MethodDefinition methodDefinition, ILBlock ilb, IEnumerable<ILVariable> parameters, IEnumerable<ILVariable> allVariables)
{
Translator = translator;
Context = context;
ThisMethodReference = methodReference;
ThisMethod = methodDefinition;
Block = ilb;
SpecialIdentifiers = new JSIL.SpecialIdentifiers(TypeSystem);
if (methodReference.HasThis)
Variables.Add("this", JSThisParameter.New(methodReference.DeclaringType, methodReference));
foreach (var parameter in parameters) {
if ((parameter.Name == "this") && (parameter.OriginalParameter.Index == -1))
continue;
ParameterNames.Add(parameter.Name);
Variables.Add(parameter.Name, new JSParameter(parameter.Name, parameter.Type, methodReference));
}
foreach (var variable in allVariables) {
var v = JSVariable.New(variable, methodReference);
if (Variables.ContainsKey(v.Identifier)) {
v = new JSVariable(variable.OriginalVariable.Name, variable.Type, methodReference);
RenamedVariables[variable] = v;
Variables.Add(v.Identifier, v);
} else {
Variables.Add(v.Identifier, v);
}
}
}
开发者ID:aprishchepov,项目名称:JSIL,代码行数:32,代码来源:ILBlockTranslator.cs
示例5: Transform
/// <summary>
/// Public translation interface.
/// Translates the given method to GLSL
/// </summary>
/// <param name="s">Shader type definition.</param>
/// <param name="m">A method representing a shader to translate.</param>
/// <param name="attr">The shader type as attribute (either FragmentShaderAttribute or VertexShaderAttribute</param>
/// <param name="type">The shader type as ShaderType</param>
/// <returns>The translated GLSL shader source</returns>
public FunctionDescription Transform(TypeDefinition s, MethodDefinition m, CustomAttribute attr,
ShaderType type)
{
if (s == null)
throw new ArgumentNullException("s");
if (m == null)
throw new ArgumentNullException("m");
if (attr == null)
throw new ArgumentNullException("attr");
var ctx = new DecompilerContext(s.Module)
{
CurrentType = s,
CurrentMethod = m,
CancellationToken = CancellationToken.None
};
var d = AstMethodBodyBuilder.CreateMethodBody(m, ctx);
var glsl = new GlslVisitor(d, attr, ctx);
_functions.UnionWith(glsl.Functions);
var entry = (bool)attr.ConstructorArguments.FirstOrDefault().Value;
var sig = entry ? "void main()" : GlslVisitor.GetSignature(m);
var code = glsl.Result;
var desc = new FunctionDescription(entry ? "main" : Shader.GetMethodName(m), sig + code, entry, type);
_dependencies.UnionWith(glsl.Dependencies);
return desc;
}
开发者ID:mono-soc-2011,项目名称:SLSharp,代码行数:44,代码来源:GlslTransform.cs
示例6: DecompileOnDemand
public void DecompileOnDemand(TypeDefinition type)
{
if (type == null)
return;
if (CheckMappings(type.MetadataToken.ToInt32()))
return;
try {
DecompilerContext context = new DecompilerContext(type.Module);
AstBuilder astBuilder = new AstBuilder(context);
astBuilder.AddType(type);
astBuilder.GenerateCode(new PlainTextOutput());
int token = type.MetadataToken.ToInt32();
var info = new DecompileInformation {
CodeMappings = astBuilder.CodeMappings,
LocalVariables = astBuilder.LocalVariables,
DecompiledMemberReferences = astBuilder.DecompiledMemberReferences
};
// save the data
DebugInformation.AddOrUpdate(token, info, (k, v) => info);
} catch {
return;
}
}
开发者ID:pir0,项目名称:SharpDevelop,代码行数:27,代码来源:DebuggerDecompilerService.cs
示例7: GetSourceCode
public static async Task<string> GetSourceCode(MethodDefinition methodDefinition, ILWeaver weaver = null)
{
return await Task.Run(() =>
{
try
{
if (weaver != null) weaver.Apply(methodDefinition.Body);
var settings = new DecompilerSettings { UsingDeclarations = false };
var context = new DecompilerContext(methodDefinition.Module)
{
CurrentType = methodDefinition.DeclaringType,
Settings = settings
};
var astBuilder = new AstBuilder(context);
astBuilder.AddMethod(methodDefinition);
var textOutput = new PlainTextOutput();
astBuilder.GenerateCode(textOutput);
return textOutput.ToString();
}
catch (Exception ex)
{
return "Error in creating source code from IL: " + ex.Message + Environment.NewLine + ex.StackTrace;
}
finally
{
if (weaver != null) methodDefinition.Body = null;
}
});
}
开发者ID:AEtherSurfer,项目名称:OxidePatcher,代码行数:29,代码来源:Decompiler.cs
示例8: DecompileMethod
public override void DecompileMethod(MethodDef method, ITextOutput output, DecompilationOptions options)
{
WriteComment(output, "Method: ");
output.WriteDefinition(IdentifierEscaper.Escape(method.FullName), method, TextTokenType.Comment, false);
output.WriteLine();
if (!method.HasBody) {
return;
}
StartKeywordBlock(output, ".body", method);
ILAstBuilder astBuilder = new ILAstBuilder();
ILBlock ilMethod = new ILBlock();
DecompilerContext context = new DecompilerContext(method.Module) { CurrentType = method.DeclaringType, CurrentMethod = method };
ilMethod.Body = astBuilder.Build(method, inlineVariables, context);
if (abortBeforeStep != null) {
new ILAstOptimizer().Optimize(context, ilMethod, abortBeforeStep.Value);
}
if (context.CurrentMethodIsAsync) {
output.Write("async", TextTokenType.Keyword);
output.Write('/', TextTokenType.Operator);
output.WriteLine("await", TextTokenType.Keyword);
}
var allVariables = ilMethod.GetSelfAndChildrenRecursive<ILExpression>().Select(e => e.Operand as ILVariable)
.Where(v => v != null && !v.IsParameter).Distinct();
foreach (ILVariable v in allVariables) {
output.WriteDefinition(IdentifierEscaper.Escape(v.Name), v, v.IsParameter ? TextTokenType.Parameter : TextTokenType.Local);
if (v.Type != null) {
output.WriteSpace();
output.Write(':', TextTokenType.Operator);
output.WriteSpace();
if (v.IsPinned) {
output.Write("pinned", TextTokenType.Keyword);
output.WriteSpace();
}
v.Type.WriteTo(output, ILNameSyntax.ShortTypeName);
}
if (v.IsGenerated) {
output.WriteSpace();
output.Write('[', TextTokenType.Operator);
output.Write("generated", TextTokenType.Keyword);
output.Write(']', TextTokenType.Operator);
}
output.WriteLine();
}
var memberMapping = new MemberMapping(method);
foreach (ILNode node in ilMethod.Body) {
node.WriteTo(output, memberMapping);
if (!node.WritesNewLine)
output.WriteLine();
}
output.AddDebugSymbols(memberMapping);
EndKeywordBlock(output);
}
开发者ID:nakijun,项目名称:dnSpy,代码行数:59,代码来源:ILAstLanguage.cs
示例9: TextTokenWriter
public TextTokenWriter(ITextOutput output, DecompilerContext context)
{
if (output == null)
throw new ArgumentNullException("output");
if (context == null)
throw new ArgumentNullException("context");
this.output = output;
this.context = context;
}
开发者ID:damnya,项目名称:dnSpy,代码行数:9,代码来源:TextTokenWriter.cs
示例10: AstBuilder
public AstBuilder(DecompilerContext context)
{
if (context == null)
throw new ArgumentNullException("context");
this.context = context;
this.DecompileMethodBodies = true;
this.LocalVariables = new ConcurrentDictionary<int, IEnumerable<ILVariable>>();
}
开发者ID:ThomasZitzler,项目名称:ILSpy,代码行数:9,代码来源:AstBuilder.cs
示例11: RunTransforms
//private IEnumerable<AstNode> FlattenScript(TypeDeclaration scriptClass) {
// foreach (var member in scriptClass.Members) {
// var constructor = member as ConstructorDeclaration;
// if (constructor != null) {
// foreach (var statement in constructor.Body.Statements) {
// yield return statement;
// }
// }
// else {
// yield return member;
// }
// }
//}
private void RunTransforms(AstBuilder ast, DecompilerContext context)
{
var transforms = TransformationPipeline.CreatePipeline(context).ToList();
transforms[transforms.FindIndex(t => t is ConvertConstructorCallIntoInitializer)] = new RoslynFriendlyConvertConstructorCallIntoInitializer();
foreach (var transform in transforms) {
transform.Run(ast.SyntaxTree);
}
}
开发者ID:i3arnon,项目名称:TryRoslyn,代码行数:22,代码来源:AstDecompiler.cs
示例12: CreateBuilder
AstBuilder CreateBuilder(IDnlibDef item, CancellationToken token) {
ModuleDef moduleDef;
DecompilerContext ctx;
AstBuilder builder;
if (item is ModuleDef) {
var def = (ModuleDef)item;
moduleDef = def;
builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token });
builder.AddAssembly(def, true);
}
else if (item is TypeDef) {
var def = (TypeDef)item;
moduleDef = def.Module;
builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token });
builder.DecompileMethodBodies = false;
ctx.CurrentType = def;
builder.AddType(def);
}
else if (item is MethodDef) {
var def = (MethodDef)item;
moduleDef = def.Module;
builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token });
ctx.CurrentType = def.DeclaringType;
builder.AddMethod(def);
}
else if (item is FieldDef) {
var def = (FieldDef)item;
moduleDef = def.Module;
builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token });
ctx.CurrentType = def.DeclaringType;
builder.AddField(def);
}
else if (item is PropertyDef) {
var def = (PropertyDef)item;
moduleDef = def.Module;
builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token });
ctx.CurrentType = def.DeclaringType;
builder.AddProperty(def);
}
else if (item is EventDef) {
var def = (EventDef)item;
moduleDef = def.Module;
builder = new AstBuilder(ctx = new DecompilerContext(moduleDef) { CancellationToken = token });
ctx.CurrentType = def.DeclaringType;
builder.AddEvent(def);
}
else
return null;
ctx.Settings = new DecompilerSettings {
UsingDeclarations = false
};
return builder;
}
开发者ID:mamingxiu,项目名称:dnExplorer,代码行数:56,代码来源:CSharpLanguage.cs
示例13: WriteResult
protected override void WriteResult(TextWriter writer, IEnumerable<AstNode> ast, DecompilerContext context)
{
var visitor = new DecompiledPseudoCSharpOutputVisitor(
new TextWriterOutputFormatter(writer) {
IndentationString = " "
},
context.Settings.CSharpFormattingOptions
);
foreach (var node in ast) {
node.AcceptVisitor(visitor);
}
}
开发者ID:i3arnon,项目名称:TryRoslyn,代码行数:13,代码来源:CSharpDecompiler.cs
示例14: GlslVisitor
public GlslVisitor(BlockStatement block, CustomAttribute attr, DecompilerContext ctx)
: this()
{
_attr = attr;
var trans1 = new ReplaceMethodCallsWithOperators(ctx);
var trans2 = new RenameLocals();
((IAstTransform)trans1).Run(block);
trans2.Run(block);
Result = block.AcceptVisitor(this, 0).ToString();
Result += Environment.NewLine;
}
开发者ID:mono-soc-2011,项目名称:SLSharp,代码行数:13,代码来源:GlslVisitor.cs
示例15: EmitField
public void EmitField(DecompilerContext context, IAstEmitter astEmitter, FieldDefinition field, JSRawOutputIdentifier dollar, JSExpression defaultValue)
{
var fieldInfo = Translator.TypeInfoProvider.GetField(field);
var typeKeyword = WasmUtil.PickTypeKeyword(fieldInfo.FieldType);
// Unhandled type
if (typeKeyword == null)
return;
Switch(PrecedingType.Global);
Formatter.WriteRaw("(global ${0} {1})", WasmUtil.EscapeIdentifier(fieldInfo.Name), typeKeyword);
Formatter.ConditionalNewLine();
}
开发者ID:nanexcool,项目名称:ilwasm,代码行数:14,代码来源:AssemblyEmitter.cs
示例16: ToSource
public static string ToSource(MethodDefinition methodDefinition)
{
var settings = new DecompilerSettings { UsingDeclarations = false };
var context = new DecompilerContext(methodDefinition.Module)
{
CurrentType = methodDefinition.DeclaringType,
Settings = settings,
};
var astBuilder = new AstBuilder(context);
astBuilder.AddMethod(methodDefinition);
var textOutput = new PlainTextOutput();
astBuilder.GenerateCode(textOutput);
return textOutput.ToString();
}
开发者ID:JamesWilko,项目名称:UnityExtensionPatcher,代码行数:14,代码来源:Decompiler.cs
示例17: WriteResult
protected override void WriteResult(TextWriter writer, IEnumerable<AstNode> ast, DecompilerContext context)
{
var converter = new CSharpToVBConverterVisitor(new ILSpyEnvironmentProvider());
var visitor = new OutputVisitor(
new VBTextOutputFormatter(new CustomizableIndentPlainTextOutput(writer) {
IndentationString = " "
}),
new VBFormattingOptions()
);
foreach (var node in ast) {
node.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true });
var converted = node.AcceptVisitor(converter, null);
converted.AcceptVisitor(visitor, null);
}
}
开发者ID:i3arnon,项目名称:TryRoslyn,代码行数:15,代码来源:VBNetDecompiler.cs
示例18: DecompileEventMappings
public Dictionary<int, EventRegistration[]> DecompileEventMappings(string fullTypeName)
{
var result = new Dictionary<int, EventRegistration[]>();
TypeDefinition type = this.assembly.MainModule.GetType(fullTypeName);
if (type == null)
return result;
MethodDefinition def = null;
foreach (var method in type.Methods) {
if (method.Name == "System.Windows.Markup.IComponentConnector.Connect") {
def = method;
break;
}
}
if (def == null)
return result;
// decompile method and optimize the switch
ILBlock ilMethod = new ILBlock();
ILAstBuilder astBuilder = new ILAstBuilder();
ILAstOptimizer optimizer = new ILAstOptimizer();
var context = new DecompilerContext(type.Module) { CurrentMethod = def, CurrentType = type };
ilMethod.Body = astBuilder.Build(def, true, context);
optimizer.Optimize(context, ilMethod, ILAstOptimizationStep.RemoveRedundantCode3);
ILSwitch ilSwitch = ilMethod.Body.OfType<ILSwitch>().FirstOrDefault();
ILCondition condition = ilMethod.Body.OfType<ILCondition>().FirstOrDefault();
if (ilSwitch != null) {
foreach (var caseBlock in ilSwitch.CaseBlocks) {
if (caseBlock.Values == null)
continue;
var events = FindEvents(caseBlock);
foreach (int id in caseBlock.Values)
result.Add(id, events);
}
} else if (condition != null) {
result.Add(1, FindEvents(condition.FalseBlock));
}
return result;
}
开发者ID:PoroCYon,项目名称:ILSpy,代码行数:45,代码来源:ConnectMethodDecompiler.cs
示例19: GetDebugLanguages
internal static IEnumerable<CSharpLanguage> GetDebugLanguages()
{
DecompilerContext context = new DecompilerContext(ModuleDefinition.CreateModule("dummy", ModuleKind.Dll));
string lastTransformName = "no transforms";
foreach (Type _transformType in TransformationPipeline.CreatePipeline(context).Select(v => v.GetType()).Distinct()) {
Type transformType = _transformType; // copy for lambda
yield return new CSharpLanguage {
transformAbortCondition = v => transformType.IsInstanceOfType(v),
name = "C# - " + lastTransformName,
showAllMembers = true
};
lastTransformName = "after " + transformType.Name;
}
yield return new CSharpLanguage {
name = "C# - " + lastTransformName,
showAllMembers = true
};
}
开发者ID:Netring,项目名称:ILSpy,代码行数:18,代码来源:CSharpLanguage.cs
示例20: GetDebugDecompilers
internal static IEnumerable<CSharpDecompiler> GetDebugDecompilers(CSharpVBDecompilerSettings langSettings) {
DecompilerContext context = new DecompilerContext(new ModuleDefUser("dummy"), CSharpMetadataTextColorProvider.Instance);
string lastTransformName = "no transforms";
double orderUI = DecompilerConstants.CSHARP_ILSPY_DEBUG_ORDERUI;
uint id = 0xBF67AF3F;
foreach (Type _transformType in TransformationPipeline.CreatePipeline(context).Select(v => v.GetType()).Distinct()) {
Type transformType = _transformType; // copy for lambda
yield return new CSharpDecompiler(langSettings, orderUI++) {
transformAbortCondition = v => transformType.IsInstanceOfType(v),
uniqueNameUI = "C# - " + lastTransformName,
uniqueGuid = new Guid($"203F702E-7E87-4F01-84CD-B0E8{id++:X8}"),
showAllMembers = true
};
lastTransformName = "after " + transformType.Name;
}
yield return new CSharpDecompiler(langSettings, orderUI++) {
uniqueNameUI = "C# - " + lastTransformName,
uniqueGuid = new Guid($"203F702E-7E87-4F01-84CD-B0E8{id++:X8}"),
showAllMembers = true
};
}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:21,代码来源:CSharpDecompiler.cs
注:本文中的ICSharpCode.Decompiler.DecompilerContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论