Пример #1
0
 private static void PrintOperandValue(StringBuilder sb, object value, DisassemblyOptions options)
 {
     if (value is System.Type t)
     {
         sb.Append(t.Name);
     }
     else if (value is string s)
     {
         sb.Append($"\"{s}\"");
     }
     else if (value is ObjectReference or)
     {
         if (options.HasFlag(DisassemblyOptions.ShowNames) && or.Reference != null && !string.IsNullOrWhiteSpace(or.Reference.Name))
         {
             sb.Append(or.Reference.Name);
         }
         else
         {
             sb.Append(or);
         }
     }
     else if (value is IBitEnumOperandValue beov)
     {
         PrintBitEnumValue(sb, beov, options);
     }
     else if (value is IValueEnumOperandValue veov)
     {
         PrintValueEnumValue(sb, veov, options);
     }
     else
     {
         sb.Append(value);
     }
 }
Пример #2
0
        private static void PrintInstruction(StringBuilder sb, ParsedInstruction instruction, DisassemblyOptions options)
        {
            if (instruction.Operands.Count == 0)
            {
                sb.Append(instruction.Instruction.Name);
                return;
            }

            int currentOperand = 0;

            if (instruction.Instruction.Operands[currentOperand].Type is IdResultType)
            {
                if (options.HasFlag(DisassemblyOptions.ShowTypes))
                {
                    sb.Append(instruction.ResultType.ToString());
                    sb.Append(" ");
                }

                ++currentOperand;
            }

            if (currentOperand < instruction.Operands.Count &&
                instruction.Instruction.Operands[currentOperand].Type is IdResult)
            {
                if (!options.HasFlag(DisassemblyOptions.ShowNames) || string.IsNullOrWhiteSpace(instruction.Name))
                {
                    PrintOperandValue(sb, instruction.Operands[currentOperand].Value, options);
                }
                else
                {
                    sb.Append(instruction.Name);
                }
                sb.Append(" = ");

                ++currentOperand;
            }

            sb.Append(instruction.Instruction.Name);
            sb.Append(" ");

            for (; currentOperand < instruction.Operands.Count; ++currentOperand)
            {
                PrintOperandValue(sb, instruction.Operands[currentOperand].Value, options);
                sb.Append(" ");
            }
        }
        private static void PrintOperandValue(StringBuilder sb, object value, DisassemblyOptions options)
        {
            switch (value)
            {
            case System.Type t:
                sb.Append(t.Name);
                break;

            case string s:
            {
                sb.Append('"');
                sb.Append(s);
                sb.Append('"');
            }
            break;

            case ObjectReference or:
            {
                if (options.HasFlag(DisassemblyOptions.ShowNames) && or.Reference != null && !string.IsNullOrWhiteSpace(or.Reference.Name))
                {
                    sb.Append(or.Reference.Name);
                }
                else
                {
                    or.ToString(sb);
                }
            }
            break;

            case IBitEnumOperandValue beov:
                PrintBitEnumValue(sb, beov, options);
                break;

            case IValueEnumOperandValue veov:
                PrintValueEnumValue(sb, veov, options);
                break;

            case VaryingOperandValue varOpVal:
                varOpVal.ToString(sb);
                break;

            default:
                sb.Append(value);
                break;
            }
        }