public Val32(Val32 a, Val32 b) { isInitialized = a.isInitialized; isNeedForRelocation = a.isNeedForRelocation; ref1 = a; ref2 = b; }
public static OpCode Cmp(Reg32 op1, Val32 op2) { return FromName("cmp", op1, op2); }
public static OpCode And(Addr32 op1, Val32 op2) { return FromName("and", op1, op2); }
public static OpCode Add(Reg32 op1, Val32 op2) { return FromName("add", op1, op2); }
public static OpCode Call(Val32 op1) { return new OpCode(new byte[] { 0xe8 }, op1, true); }
public OpCode(byte[] d, Val32 op, bool rel) { data = d; op1 = op; relative = rel; }
public static OpCode Jmp(Val32 op1) { return new OpCode(new byte[] { 0xe9 }, op1, true); }
public void Add(int n) { if (n == 0) return; if (address != null) { address = new Val32(address, (uint)n); } else { disp += n; } }
public static OpCode Sbb(Reg32 op1, Val32 op2) { return FromName("sbb", op1, op2); }
public static OpCode Or(Reg32 op1, Val32 op2) { return FromName("or", op1, op2); }
public static OpCode Mov(Addr32 op1, Val32 op2) { return FromName("mov", op1, op2); }
public static OpCode FromName(string op, Addr32 op1, Val32 op2) { switch (op) { case "mov": return new OpCode(new byte[] { 0xc7 }, op2, op1); case "test": return new OpCode(new byte[] { 0xf7 }, op2, op1); default: int code = GetOperatorCode(op); if (code < 0) throw new Exception("invalid operator: " + op); return new OpCode(new byte[] { 0x81 }, op2, new Addr32(op1, (byte)code)); } }
public static OpCode FromName(string op, Reg32 op1, Val32 op2) { byte[] bytes; switch (op) { case "mov": bytes = new byte[] { (byte)(0xb8 + op1) }; break; case "test": if (op1 == Reg32.EAX) bytes = new byte[] { 0xa9 }; else bytes = new byte[] { 0xf7, (byte)(0xc0 + op1) }; break; default: int code = GetOperatorCode(op); if (code < 0) throw new Exception("invalid operator: " + op); if (op1 == Reg32.EAX) bytes = new byte[] { (byte)(code * 8 + 5) }; else bytes = new byte[] { 0x81, (byte)(code * 8 + 0xc0 + op1) }; break; } return new OpCode(bytes, op2); }
// Push, Pop, Inc, Dec, Not, Neg, Mul, Imul, Div, Idiv public static OpCode Push(Val32 op1) { return new OpCode(new byte[] { 0x68 }, op1); }
public void Set(Addr32 src) { isInitialized = src.isInitialized; reg = src.reg; disp = src.disp; address = src.address; middleBits = src.middleBits; }
public Addr32(Val32 ad) { address = ad; }
public static OpCode Adc(Addr32 op1, Val32 op2) { return FromName("adc", op1, op2); }
public static OpCode Jcc(Cc c, Val32 op1) { return new OpCode(new byte[] { 0x0f, (byte)(0x80 + c) }, op1, true); }
public static OpCode Sub(Addr32 op1, Val32 op2) { return FromName("sub", op1, op2); }
public static OpCode Loop(Val32 op1) { return new OpCode(new byte[] { 0xe2 }, op1, true) { ByteRelative = true }; }
public static OpCode Test(Addr32 op1, Val32 op2) { return FromName("test", op1, op2); }
public void Add(Val32 v) { data.Add(v); if (v.IsNeedForRelocation) relocs.Add(length); length += sizeof(uint); }
public static OpCode Xor(Addr32 op1, Val32 op2) { return FromName("xor", op1, op2); }