示例#1
0
        protected override void DoRender(MachineInstructionRenderer renderer, MachineInstructionRendererOptions options)
        {
            if ((options.Flags & MachineInstructionRendererFlags.ExplicitOperandSize) != 0)
            {
                string s;
                if (Width == PrimitiveType.Byte)
                {
                    s = "byte ptr ";
                }
                else if (Width == PrimitiveType.Word16)
                {
                    s = "word ptr ";
                }
                else if (Width.Size == 4)
                {
                    s = "dword ptr ";
                }
                else if (Width == PrimitiveType.Word64)
                {
                    s = "qword ptr ";
                }
                else if (Width == PrimitiveType.Real32)
                {
                    s = "float ptr ";
                }
                else if (Width == PrimitiveType.Real64)
                {
                    s = "double ptr ";
                }
                else if (Width == PrimitiveType.Real80 || Width == PrimitiveType.Bcd80)
                {
                    s = "tword ptr ";
                }
                else if (Width == PrimitiveType.Word128)
                {
                    s = "xmmword ptr ";
                }
                else if (Width == PrimitiveType.Word256)
                {
                    s = "ymmword ptr ";
                }
                else
                {
                    s = "";
                }
                renderer.WriteString(s);
            }

            if (SegOverride != RegisterStorage.None)
            {
                renderer.WriteString(SegOverride.ToString());
                renderer.WriteString(":");
            }
            renderer.WriteString("[");
            if (Base != RegisterStorage.None)
            {
                renderer.WriteString(Base.ToString());
            }
            else
            {
                var s = FormatUnsignedValue(Offset !);
                renderer.WriteAddress(s, Address.FromConstant(Offset !));
            }

            if (Index != RegisterStorage.None)
            {
                renderer.WriteString("+");
                renderer.WriteString(Index.ToString());
                if (Scale > 1)
                {
                    renderer.WriteString("*");
                    renderer.WriteUInt32(Scale);
                }
            }
            if (Base != RegisterStorage.None && Offset != null && Offset.IsValid)
            {
                if (Offset.DataType == PrimitiveType.Byte || Offset.DataType == PrimitiveType.SByte)
                {
                    renderer.WriteString(FormatSignedValue(Offset));
                }
                else
                {
                    var off = Offset.ToInt32();
                    if (off == Int32.MinValue)
                    {
                        renderer.WriteString("-80000000");
                    }
                    else
                    {
                        var absOff = Math.Abs(off);
                        if (Offset.DataType.Size > 2 && off < 0 && absOff < 0x10000)
                        {
                            // Special case for negative 32-bit offsets whose
                            // absolute value < 0x10000 (GitHub issue #252)
                            renderer.WriteString("-");
                            renderer.WriteFormat("{0:X8}", absOff);
                        }
                        else
                        {
                            renderer.WriteString("+");
                            renderer.WriteString(FormatUnsignedValue(Offset));
                        }
                    }
                }
            }
            renderer.WriteString("]");
        }
示例#2
0
        protected void RenderMemory(
            MemoryOperand mem,
            MachineInstructionRenderer renderer,
            MachineInstructionRendererFlags flags)
        {
            if ((flags & MachineInstructionRendererFlags.ExplicitOperandSize) != 0)
            {
                var s = ExplicitOperandPrefix(mem.Width);
                renderer.WriteString(s);
            }

            if (mem.SegOverride != RegisterStorage.None)
            {
                RenderRegister(mem.SegOverride.Name, renderer);
                renderer.WriteString(":");
            }
            renderer.WriteString("[");
            if (mem.Base != RegisterStorage.None)
            {
                RenderRegister(mem.Base.Name, renderer);
            }
            else
            {
                var s = FormatUnsignedValue(mem.Offset !.ToUInt64(), "{0:X4}");
                renderer.WriteAddress(s, Address.FromConstant(mem.Offset !));
            }

            if (mem.Index != RegisterStorage.None)
            {
                renderer.WriteString("+");
                RenderRegister(mem.Index.Name, renderer);
                if (mem.Scale > 1)
                {
                    renderer.WriteString("*");
                    renderer.WriteUInt32(mem.Scale);
                }
            }
            if (mem.Base != RegisterStorage.None && mem.Offset != null && mem.Offset.IsValid)
            {
                if (mem.Offset.DataType == PrimitiveType.Byte || mem.Offset.DataType == PrimitiveType.SByte)
                {
                    renderer.WriteString(FormatSignedValue(mem.Offset.ToInt64(), true));
                }
                else
                {
                    var off = mem.Offset.ToInt32();
                    if (off == Int32.MinValue)
                    {
                        renderer.WriteString("-80000000h");
                    }
                    else
                    {
                        var absOff = Math.Abs(off);
                        if (mem.Offset.DataType.Size > 2 && off < 0 && absOff < 0x10000)
                        {
                            // Special case for negative 32-bit offsets whose
                            // absolute value < 0x10000 (GitHub issue #252)
                            renderer.WriteString("-");
                            renderer.WriteFormat(FormatUnsignedValue((ulong)absOff));
                        }
                        else
                        {
                            renderer.WriteString("+");
                            renderer.WriteString(FormatUnsignedValue(mem.Offset.ToUInt64()));
                        }
                    }
                }
            }
            renderer.WriteString("]");
        }