Esempio n. 1
0
		public void WriteSegmentOverride(x86Segment selected, x86Segment defaultSeg)
		{
			if (selected != defaultSeg)
			{
				switch(selected)
				{
					case x86Segment.ES:
						WriteByte(0x26);
						break;
					case x86Segment.CS:
						WriteByte(0x2E);
						break;
					case x86Segment.SS:
						WriteByte(0x36);
						break;
					case x86Segment.DS:
						WriteByte(0x3E);
						break;
					case x86Segment.FS:
						WriteByte(0x64);
						break;
					case x86Segment.GS:
						WriteByte(0x65);
						break;
					default:
						throw new Exception("Unknown x86 Segment!");
				}
			}
		}
Esempio n. 2
0
		public static string NameSegment(x86Segment seg, bool upper = false)
		{
			switch (seg)
			{
				case x86Segment.CS:
					return upper ? "CS" : "cs";
				case x86Segment.DS:
					return upper ? "DS" : "ds";
				case x86Segment.ES:
					return upper ? "ES" : "es";
				case x86Segment.FS:
					return upper ? "FS" : "fs";
				case x86Segment.GS:
					return upper ? "GS" : "gs";
				case x86Segment.SS:
					return upper ? "SS" : "ss";
				default:
					throw new Exception("Invalid segment!");
			}
		}
Esempio n. 3
0
		public Ret(x86Assembler parentAssembler, ushort popSize = 0, x86Segment seg = x86Segment.CS) : base(parentAssembler)
		{
			PopSize = popSize;
			Segment = seg;
		}
Esempio n. 4
0
		public static string NameMemIndex(x86Assembler a, x86Register baseRegister, int displacement, x86Register indexRegister, x86IndexShift shift, x86Segment segment)
		{
			string ret = "";
			bool form2 = baseRegister == x86Register.None;
			if (form2)
			{
				ret += NameSegment(segment) + ":0x" + displacement.ToString("X").PadLeft(8, '0');
			}
			ret += "[" + NameRegister(indexRegister, 4);
			switch (shift)
			{
				case x86IndexShift.Mul1:
					break;
				case x86IndexShift.Mul2:
					ret += " * 2";
					break;
				case x86IndexShift.Mul4:
					ret += " * 4";
					break;
				case x86IndexShift.Mul8:
					ret += " * 8";
					break;
				default:
					throw new Exception("Invalid index shift!");
			}
			if (baseRegister != x86Register.None)
			{
				ret += " + " + NameRegister(baseRegister, 4);
			}
			if (displacement != 0 && !form2)
			{
				ret += " " + (displacement < 0 ? "-" : "+") + " " + (displacement < 0 ? -displacement : displacement).ToString();
			}
			return ret + "]";
		}
Esempio n. 5
0
		public static string NameMem(x86Assembler a, uint address, x86Segment segment)
		{
			// Assembler gets passed in here because we will eventually do symbol lookup.
			return "[" + NameSegment(segment) + ":0x" + address.ToString("X").PadLeft(8, '0') + "]";
		}
Esempio n. 6
0
		public void WriteRegister(byte o, x86Segment r)
		{
			WriteModRM(x86AddressingMode.Register, o, (byte)r);
		}