public Encoding(ModRM modRM, Sib? sib = null, int displacement = 0)
			{
				this.Segment = null;
				this.AddressSizeOverride = false;
				this.BaseRegExtension = false;
				this.IndexRegExtension = false;
				this.ModRM = modRM;
				this.Sib = sib;
				this.Displacement = displacement;
			}
			public Encoding(ImmutableLegacyPrefixList legacyPrefixes, Xex xex,
				ModRM modRM, Sib? sib = null, int displacement = 0)
			{
				this.Segment = legacyPrefixes.SegmentOverride;
				this.AddressSizeOverride = legacyPrefixes.HasAddressSizeOverride;
				this.BaseRegExtension = xex.BaseRegExtension;
				this.IndexRegExtension = xex.IndexRegExtension;
				this.ModRM = modRM;
				this.Sib = sib;
				this.Displacement = displacement;
			}
Exemple #3
0
        public void TestMODRM3()
        {
            // ARRANGE
            byte MODRM = 0x0F;

            // ACT
            ModRM modrm = new ModRM(MODRM);

            // ASSERT
            Assert.Equal(MOD.RM, modrm.MOD);
            Assert.Equal(0x01, modrm.REG);
            Assert.Equal(0x07, modrm.RM);
        }
Exemple #4
0
        public void TestMODRM2()
        {
            // ARRANGE
            byte MODRM = 0xFE;

            // ACT
            ModRM modrm = new ModRM(MODRM);

            // ASSERT
            Assert.Equal(MOD.RM_DIRECT, modrm.MOD);
            Assert.Equal(0x07, modrm.REG);
            Assert.Equal(0x06, modrm.RM);
        }
Exemple #5
0
        //byte = opcode, Dict<byte = displacement(increment doesnt matter), action = thing to do>
        // opcodes with one operand e.g inc eax (increment eax) don't use the REG bits in modRM, so the regbits can be used to make extra instructions instead
        // so we can have one "opcode byte" that has meanings depending on the REG bits
        // reg bit starts at the 8 dec val position in a string of bits e.g "01[100]111" [REG] so each offset is -8 each time
        private static Opcode DecodeExtension(byte opcode)
        {
            ModRM InputModRM = new ModRM(ModRMSettings.EXTENDED);
            ExtendedOpcodeCaller Output;

            if (!ExtendedOpcodeTable[opcode].TryGetValue((int)InputModRM.Source.Code, out Output))
            {
                RaiseException(Logging.LogCode.INVALID_OPCODE);
                return(null);
            }
            else
            {
                return(ExtendedOpcodeTable[opcode][(int)InputModRM.Source.Code](InputModRM));
            }
        }
Exemple #6
0
		private readonly ulong immediate; // 8 bytes
		#endregion

		#region Constructors
		private Instruction(Builder builder)
		{
			legacyPrefixes = builder.LegacyPrefixes;
			xex = builder.Xex; // Validate if redundant with prefixes
			mainByte = builder.OpcodeByte;
			modRM = builder.ModRM.GetValueOrDefault();
			sib = builder.Sib.GetValueOrDefault(); // Validate if necessary
			displacement = builder.Displacement; // Validate with mod/sib
			immediate = builder.Immediate; // Truncate to size

			flags = 0;
			flags |= (Flags)((int)builder.DefaultAddressSize << (int)Flags.DefaultAddressSize_Shift);
			if (builder.ModRM.HasValue) flags |= Flags.HasModRM;
			flags |= (Flags)(builder.ImmediateSizeInBytes << (int)Flags.ImmediateSizeInBytes_Shift);
		}
Exemple #7
0
		public static GprCode? GetBaseReg(this Sib sib, ModRM modRM)
		{
			if ((sib & Sib.Base_Mask) == Sib.Base_Special && modRM.GetMod() == 0)
				return null;
			return (GprCode)GetBase(sib);
		}
Exemple #8
0
		private void Write(ModRM modRM) => Write((byte)modRM);