private string DecompileMethod(MethodBody body, ILanguage language)
        {
            var str = new StringWriter();
            var writer = language.GetWriter(new PlainTextFormatter(str));

            var block = body.Decompile(language);
            writer.Write(block);

            return str.ToString();
        }
Example #2
0
        protected void VisitMethodBody(MethodBody body)
        {
            var localVariableSize = 0;
            if (body.HasVariables)
            {
                foreach (VariableDefinition variable in body.Variables)
                {
                    localVariableSize += GetVariableSize(variable);
                    _variableLocations.Add(variable.Name, -localVariableSize);
                }
            }

            if (body.Method.HasParameters)
            {
                var size = 4; //skip return point
                foreach (ParameterDefinition item in body.Method.Parameters)
                {
                    size += 4;
                    _parameterLocations.Add(item.Name, size);
                }
            }

            var block = body.Decompile();
            block = (BlockStatement)new TypedTransformer().VisitBlockStatement(block);
            EmitMethodEntry(localVariableSize);
            EmitBlockStatement(block, -localVariableSize);
        }