Пример #1
0
        public bool DisassembleMethod()
        {
            if (selectedMethod == null && selection.selectedMethod != null)
            {
                SelectMethod(selection.selectedMethod);
            }

            if (selectedMethod == null)
            {
                return(false);
            }
            var reader = new MethodBodyReader(selectedMethod);

            byteCount = reader.ilByteCount;
            ilCode    = reader.GetBodyCode();
            localVariables.Clear();
            if (string.IsNullOrWhiteSpace(ilCode))
            {
                instructionInfo.Clear();
                Updated?.Invoke(this);
                return(false);
            }

            if (reader.LocalVariables != null)
            {
                foreach (var local in reader.LocalVariables)
                {
                    localVariables.Add(local.LocalIndex, local);
                }
            }

            var lines = ilCode?.Split('\n').ToList();

            lines.RemoveAll(string.IsNullOrWhiteSpace);
            var ilCodeLines = lines.ToArray();

            var ilLinesInfos = new OpCodeInfo[ilCodeLines?.Length ?? 0];

            if (reader.instructions == null)
            {
                return(false);
            }
            for (var index = 0; index < reader.instructions.Count && index < ilLinesInfos.Length; index++)
            {
                var instruction = reader.instructions[index];
                var d           = TryGetOpCodeDescription(instruction.Code);
                if (d == null)
                {
                    continue;
                }
                ilLinesInfos[index] = d;
            }

            FindBlocks(ilCodeLines, reader.instructions, ilLinesInfos);

            Updated?.Invoke(this);
            DisassemblyChanged?.Invoke(this);
            return(true);
        }
Пример #2
0
 private void lbAvailableMethodsList_SelectedValueChanged(object sender, EventArgs e)
 {
     try
     {
         MethodInfo mi = methods[lbAvailableMethodsList.SelectedIndex];
         SDILReader.MethodBodyReader mr = new MethodBodyReader(mi);
         rchMethodBodyCode.Clear();
         rchMethodBodyCode.Text = mr.GetBodyCode();
     }
     catch
     {
     }
 }
Пример #3
0
        public static ILMethodInfo Disassemble(MethodInfo method)
        {
            if (method == null)
            {
                return(null);
            }

            var reader = new MethodBodyReader(method);
            var ilCode = reader.GetBodyCode();

            if (string.IsNullOrWhiteSpace(ilCode))
            {
                return(null);
            }

            var localVariables = new List <LocalVariableInfo>();

            if (reader.LocalVariables != null)
            {
                localVariables.AddRange(reader.LocalVariables);
            }

            var lines = ilCode?.Split('\n').ToList();

            lines.RemoveAll(string.IsNullOrWhiteSpace);
            var ilCodeLines = lines.ToArray();

            var ilLinesInfos = new OpCodeInfo[ilCodeLines?.Length ?? 0];

            if (reader.instructions == null)
            {
                return(null);
            }
            for (var index = 0; index < reader.instructions.Count && index < ilLinesInfos.Length; index++)
            {
                var instruction = reader.instructions[index];
                var d           = ILNavigator.TryGetOpCodeDescription(instruction.Code);
                if (d == null)
                {
                    continue;
                }
                ilLinesInfos[index] = d;
            }

            var instructions = FindBlocks(ilCodeLines, reader.instructions, ilLinesInfos);

            return(new ILMethodInfo(localVariables, instructions));
        }