Exemplo n.º 1
0
 public override Expression Interpret(Instruction instruction, IndividualDecompilationContext context)
 {
     var field = ((FieldReferenceInstruction)instruction).Field;
     var instance = !field.IsStatic
                  ? context.CapturePreceding()
                  : null;
     return Expression.Field(instance, field);
 }
Exemplo n.º 2
0
 public TestMethod(string name, Type returnType, IEnumerable<IManagedMethodParameter> parameters, IList<Type> localTypes, Instruction[] instructions)
 {
     this.name = name;
     this.returnType = returnType;
     this.parameters = parameters;
     this.localTypes = localTypes;
     this.instructions = instructions;
 }
Exemplo n.º 3
0
        public override Expression Interpret(Instruction instruction, IndividualDecompilationContext context)
        {
            var right = context.CapturePreceding();
            var left = context.CapturePreceding();

            BooleanSupport.ConvertIfRequired(ref left, ref right);

            var condition = conditions[instruction.OpCode.Name.SubstringBefore(".")];
            return Expression.Condition(
                condition(left, right),
                Expression.Constant(1),
                Expression.Constant(0)
            );
        }
Exemplo n.º 4
0
        public override Expression Interpret(Instruction instruction, IndividualDecompilationContext context)
        {
            var singleOrRight = context.CapturePreceding();
            var unary = unaryOperators.GetValueOrDefault(instruction.OpCode);
            if (unary != null)
                return unary(singleOrRight);

            var left = context.CapturePreceding();
            var binary = binaryOperators[instruction.OpCode];

            Adapt(left, ref singleOrRight);

            return binary(left, singleOrRight);
        }
Exemplo n.º 5
0
        private object GetValue(Instruction instruction)
        {
            var valueInstruction = instruction as IValueInstruction;
            if (valueInstruction != null)
                return valueInstruction.Value;

            var parts = instruction.OpCode.Name.Split('.');
            if (parts.Length < 3)
                throw new InvalidOperationException("Cannot extract value from " + instruction.OpCode + ".");

            if (!parts[1].Equals("i4", StringComparison.InvariantCultureIgnoreCase))
                throw new NotSupportedException("Cannot extract value from " + instruction.OpCode + ": " + parts[1] + " is not yet supported here.");

            var valueString = parts[2];
            if (valueString.Equals("M1", StringComparison.InvariantCultureIgnoreCase))
                return -1;

            return int.Parse(valueString);
        }
Exemplo n.º 6
0
 public override bool CanInterpret(Instruction instruction)
 {
     return binaryOperators.ContainsKey(instruction.OpCode)
         || unaryOperators.ContainsKey(instruction.OpCode);
 }
Exemplo n.º 7
0
 public override Expression Interpret(Instruction instruction, IndividualDecompilationContext context)
 {
     var indexGetter = parameterIndexGetters[instruction.OpCode];
     return this.primaryContext.GetParameter(indexGetter(instruction));
 }
Exemplo n.º 8
0
 public override bool CanInterpret(Instruction instruction)
 {
     return parameterIndexGetters.ContainsKey(instruction.OpCode);
 }
Exemplo n.º 9
0
 public override Expression Interpret(Instruction instruction, IndividualDecompilationContext context)
 {
     return Expression.Constant(
         ((ValueInstruction<string>)instruction).Value
     );
 }
Exemplo n.º 10
0
 public override bool CanInterpret(Instruction instruction)
 {
     return instruction.OpCode == OpCodes.Ldfld
         || instruction.OpCode == OpCodes.Ldsfld;
 }
Exemplo n.º 11
0
 public InstructionElement(Instruction instruction)
 {
     this.Instruction = instruction;
 }
Exemplo n.º 12
0
 public override Expression Interpret(Instruction instruction, IndividualDecompilationContext context)
 {
     return Expression.Constant(GetValue(instruction));
 }
Exemplo n.º 13
0
 public override bool CanInterpret(Instruction instruction)
 {
     return instruction.OpCode.Name.StartsWith(LdcNamePrefix);
 }
Exemplo n.º 14
0
 public override Expression Interpret(Instruction instruction, IndividualDecompilationContext context)
 {
     return context.GetPreceding();
 }
Exemplo n.º 15
0
 public override Expression Interpret(Instruction instruction, IndividualDecompilationContext context)
 {
     var target = context.CapturePreceding();
     return conversions[instruction.OpCode](target);
 }
Exemplo n.º 16
0
 public override bool CanInterpret(Instruction instruction)
 {
     return conversions.ContainsKey(instruction.OpCode);
 }
Exemplo n.º 17
0
 public override Expression Interpret(Instruction instruction, IndividualDecompilationContext context)
 {
     var method = ((MethodReferenceInstruction)instruction).Method;
     return new AddressOfExpression(method);
 }
Exemplo n.º 18
0
 public override bool CanInterpret(Instruction instruction)
 {
     return instruction.OpCode == OpCodes.Newarr;
 }
Exemplo n.º 19
0
 public override Expression Interpret(Instruction instruction, IndividualDecompilationContext context)
 {
     var type = ((TypeReferenceInstruction)instruction).Type;
     return Expression.NewArrayBounds(type, context.CapturePreceding());
 }
Exemplo n.º 20
0
 public override bool CanInterpret(Instruction instruction)
 {
     return conditions.Keys.Any(k => instruction.OpCode.Name.StartsWith(k));
 }