public override X86Instruction Decode(uint op, X86Disassembler disasm) { var ctx = disasm.decodingContext; if ((ctx.SizeOverridePrefix | ctx.F2Prefix | ctx.F3Prefix) || !disasm.TryReadByte(out byte op2)) { return(disasm.CreateInvalidInstruction()); } var r = (~op2 >> 5) & 4; var vvvv = (~op2 >> 3) & 0xF; var pp = op2 & 3; ctx.IsVex = true; ctx.VexRegister = (byte)vvvv; ctx.RegisterExtensionPrefixByte = (byte)r; ctx.VexLong = (op2 & 4) != 0; ctx.F2Prefix = pp == 3; ctx.F3Prefix = pp == 2; ctx.SizeOverridePrefix = pp == 1; if (!disasm.TryReadByte(out op2) || op2 == 0x38 || op2 == 0x3A) { return(disasm.CreateInvalidInstruction()); } return(decoders0F[op2].Decode(op2, disasm)); }
public override X86Instruction Decode(uint op, X86Disassembler disasm) { // 62 must be the first byte. The presence of previous // prefixes is an error (according to Intel manual 2.6, vol 2A. var ctx = disasm.decodingContext; if (ctx.F2Prefix | ctx.F3Prefix | ctx.IsRegisterExtensionActive() | ctx.SizeOverridePrefix) { return(disasm.CreateInvalidInstruction()); } // The EVEX prefix consists of a leading 0x62 byte, and three // packed payload bytes P0, P1, and P2. //$TODO: this is incomplete: there are many missing flags. if (!disasm.TryReadByte(out byte p0) || !disasm.TryReadByte(out byte p1) || !disasm.TryReadByte(out byte p2) || p0Reserved.Read(p0) != 0 || p1Reserved.Read(p1) != 1) { return(disasm.CreateInvalidInstruction()); } var pp = p1 & 3; var rxb = p0 >> 5; var w = p1 >> 7; var vvvv = p1Vvvv.Read(p1); ctx.IsVex = true; ctx.VexRegister = (byte)vvvv; ctx.VexLong = (op & 4) != 0; ctx.RegisterExtension.FlagWideValue = w != 0; ctx.RegisterExtension.FlagTargetModrmRegister = (rxb & 4) == 0; ctx.RegisterExtension.FlagTargetSIBIndex = (rxb & 2) == 0; ctx.RegisterExtension.FlagTargetModrmRegOrMem = (rxb & 1) == 0; ctx.F2Prefix = pp == 3; ctx.F3Prefix = pp == 2; ctx.SizeOverridePrefix = pp == 1; Decoder[] decoders; switch (pp) { case 2: decoders = decoders0F38; break; case 3: decoders = decoders0F3A; break; default: decoders = decoders0F; break; } if (!disasm.TryReadByte(out byte op2)) { return(disasm.CreateInvalidInstruction()); } return(decoders[op2].Decode(op2, disasm)); }
public override X86Instruction Decode(uint op, X86Disassembler disasm) { var ctx = disasm.decodingContext; if (ctx.RegisterExtension.ByteValue != 0 || ctx.SizeOverridePrefix || ctx.F2Prefix || ctx.F3Prefix) { return(disasm.CreateInvalidInstruction()); } if (!disasm.TryReadByte(out byte evex1)) { return(disasm.CreateInvalidInstruction()); } var rxb = evex1 >> 5; var mmmmm = evex1 & 0x1F; if (!disasm.TryReadByte(out byte evex2)) { return(disasm.CreateInvalidInstruction()); } var w = evex2 >> 7; var vvvv = (~evex2 >> 3) & 0xF; var pp = evex2 & 0x3; ctx.IsVex = true; ctx.VexRegister = (byte)vvvv; ctx.VexLong = (evex2 & 4) != 0; ctx.RegisterExtension.FlagWideValue = w != 0; ctx.RegisterExtension.FlagTargetModrmRegister = (rxb & 4) == 0; ctx.RegisterExtension.FlagTargetSIBIndex = (rxb & 2) == 0; ctx.RegisterExtension.FlagTargetModrmRegOrMem = (rxb & 1) == 0; ctx.F2Prefix = pp == 3; ctx.F3Prefix = pp == 2; ctx.SizeOverridePrefix = pp == 1; Decoder[] decoders; switch (mmmmm) { case 1: decoders = decoders0F; break; case 2: decoders = decoders0F38; break; case 3: decoders = decoders0F3A; break; default: return(disasm.CreateInvalidInstruction()); } if (!disasm.TryReadByte(out byte evex3)) { return(disasm.CreateInvalidInstruction()); } return(decoders[evex3].Decode(evex3, disasm)); }
public override X86Instruction Decode(uint op, X86Disassembler disasm) { PrimitiveType addrWidth; if (disasm.decodingContext.addressWidth != disasm.defaultAddressWidth) { addrWidth = disasm.defaultAddressWidth; } else { if (disasm.defaultAddressWidth.BitSize == 16) { addrWidth = PrimitiveType.Word32; } else if (disasm.defaultAddressWidth.BitSize == 32) { addrWidth = PrimitiveType.Word16; } else { addrWidth = PrimitiveType.Word32; } } disasm.decodingContext.addressWidth = addrWidth; if (!disasm.TryReadByte(out byte op2)) { return(disasm.CreateInvalidInstruction()); } return(rootDecoders[op2].Decode(op2, disasm)); }
public override X86Instruction Decode(uint op, X86Disassembler disasm) { if (!disasm.TryReadByte(out byte op2)) { return(disasm.CreateInvalidInstruction()); } return(decoders[op2].Decode(op2, disasm)); }
public override X86Instruction Decode(uint op, X86Disassembler disasm) { return(disasm.decodingContext.addressWidth.Size switch { 2 => bit16.Decode(op, disasm), 4 => bit32.Decode(op, disasm), 8 => bit64.Decode(op, disasm), _ => disasm.CreateInvalidInstruction(), });
public override X86Instruction Decode(uint op, X86Disassembler disasm) { disasm.decodingContext.F2Prefix = true; if (!disasm.TryReadByte(out byte op2)) { return(disasm.CreateInvalidInstruction()); } return(rootDecoders[op2].Decode(op2, disasm)); }
public override X86Instruction Decode(uint op, X86Disassembler disasm) { disasm.decodingContext.SegmentOverride = SegFromBits(seg); if (!disasm.TryReadByte(out var op2)) { return(disasm.CreateInvalidInstruction()); } return(disasm.rootDecoders[op2].Decode(op2, disasm)); }
public override X86Instruction Decode(uint op, X86Disassembler disasm) { if (!disasm.TryEnsureModRM(out byte modRm)) { return(disasm.CreateInvalidInstruction()); } if (mutators != null) { foreach (var m in this.mutators) { if (!m(op, disasm)) { return(disasm.CreateInvalidInstruction()); } } } Decoder decoder = group[((modRm >> 3) & 0x07)]; return(decoder.Decode(op, disasm)); }
public override X86Instruction Decode(uint op, X86Disassembler disasm) { disasm.decodingContext.SizeOverridePrefix = true; disasm.decodingContext.dataWidth = (disasm.decodingContext.dataWidth == PrimitiveType.Word16) ? PrimitiveType.Word32 : PrimitiveType.Word16; disasm.decodingContext.iWidth = disasm.decodingContext.dataWidth; if (!disasm.TryReadByte(out byte op2)) { return(disasm.CreateInvalidInstruction()); } return(rootDecoders[op2].Decode(op2, disasm)); }
public override X86Instruction Decode(uint op, X86Disassembler disasm) { if (!disasm.rdr.TryPeekByte(0, out byte b)) { return(disasm.CreateInvalidInstruction()); } if (b == 0xC3) { // rep ret idiom. if (!disasm.TryReadByte(out byte opC3)) { return(disasm.CreateInvalidInstruction()); } return(rootDecoders[opC3].Decode(opC3, disasm)); } disasm.decodingContext.F3Prefix = true; if (!disasm.TryReadByte(out byte op2)) { return(disasm.CreateInvalidInstruction()); } return(rootDecoders[op2].Decode(op2, disasm)); }
public override X86Instruction Decode(uint op, X86Disassembler disasm) { if (!disasm.TryEnsureModRM(out byte modRm)) { return(disasm.CreateInvalidInstruction()); } var decoder = ((modRm & 0xC0) == 0xC0) ? regDecoder : memDecoder; return(decoder.Decode(op, disasm)); }
public override X86Instruction Decode(uint op, X86Disassembler disasm) { if (!disasm.TryEnsureModRM(out byte modRm)) { return(disasm.CreateInvalidInstruction()); } if ((modRm & 0xC0) == 0xC0) { var i = modRm & 0x07; if (i < regDecoders.Length) { return(regDecoders[i].Decode(op, disasm)); } else { return(disasm.CreateInvalidInstruction()); } } else { return(memDecoder.Decode(op, disasm)); } }
public override X86Instruction Decode(uint op, X86Disassembler disasm) { disasm.decodingContext.RegisterExtensionPrefixByte = (byte)op; if (disasm.decodingContext.RegisterExtension.FlagWideValue) { var w64 = PrimitiveType.Word64; disasm.decodingContext.dataWidth = w64; disasm.decodingContext.iWidth = w64; } if (!disasm.TryReadByte(out var op2)) { return(disasm.CreateInvalidInstruction()); } return(decoders[op2].Decode(op2, disasm)); }
public override X86Instruction Decode(uint op, X86Disassembler disasm) { if (!disasm.TryEnsureModRM(out byte modRM)) { return(disasm.CreateInvalidInstruction()); } Decoder decoder; uint iDecoder = (op & 0x07) * 0x48; if (modRM < 0xC0) { decoder = fpuDecoders[iDecoder + ((modRM >> 3) & 0x07)]; } else { decoder = fpuDecoders[iDecoder + modRM - 0xB8]; } return(decoder.Decode(op, disasm)); }