Beispiel #1
0
 public Val32(Val32 a, Val32 b)
 {
     isInitialized = a.isInitialized;
     isNeedForRelocation = a.isNeedForRelocation;
     ref1 = a;
     ref2 = b;
 }
Beispiel #2
0
 public static OpCode Cmp(Reg32 op1, Val32 op2)
 {
     return FromName("cmp", op1, op2);
 }
Beispiel #3
0
 public static OpCode And(Addr32 op1, Val32 op2)
 {
     return FromName("and", op1, op2);
 }
Beispiel #4
0
 public static OpCode Add(Reg32 op1, Val32 op2)
 {
     return FromName("add", op1, op2);
 }
Beispiel #5
0
 public static OpCode Call(Val32 op1)
 {
     return new OpCode(new byte[] { 0xe8 }, op1, true);
 }
Beispiel #6
0
 public OpCode(byte[] d, Val32 op, bool rel)
 {
     data = d;
     op1 = op;
     relative = rel;
 }
Beispiel #7
0
 public static OpCode Jmp(Val32 op1)
 {
     return new OpCode(new byte[] { 0xe9 }, op1, true);
 }
Beispiel #8
0
        public void Add(int n)
        {
            if (n == 0) return;

            if (address != null)
            {
                address = new Val32(address, (uint)n);
            }
            else
            {
                disp += n;
            }
        }
Beispiel #9
0
 public static OpCode Sbb(Reg32 op1, Val32 op2)
 {
     return FromName("sbb", op1, op2);
 }
Beispiel #10
0
 public static OpCode Or(Reg32 op1, Val32 op2)
 {
     return FromName("or", op1, op2);
 }
Beispiel #11
0
 public static OpCode Mov(Addr32 op1, Val32 op2)
 {
     return FromName("mov", op1, op2);
 }
Beispiel #12
0
 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));
     }
 }
Beispiel #13
0
 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);
 }
Beispiel #14
0
 // Push, Pop, Inc, Dec, Not, Neg, Mul, Imul, Div, Idiv
 public static OpCode Push(Val32 op1)
 {
     return new OpCode(new byte[] { 0x68 }, op1);
 }
Beispiel #15
0
 public void Set(Addr32 src)
 {
     isInitialized = src.isInitialized;
     reg = src.reg;
     disp = src.disp;
     address = src.address;
     middleBits = src.middleBits;
 }
Beispiel #16
0
 public Addr32(Val32 ad)
 {
     address = ad;
 }
Beispiel #17
0
 public static OpCode Adc(Addr32 op1, Val32 op2)
 {
     return FromName("adc", op1, op2);
 }
Beispiel #18
0
 public static OpCode Jcc(Cc c, Val32 op1)
 {
     return new OpCode(new byte[] { 0x0f, (byte)(0x80 + c) }, op1, true);
 }
Beispiel #19
0
 public static OpCode Sub(Addr32 op1, Val32 op2)
 {
     return FromName("sub", op1, op2);
 }
Beispiel #20
0
 public static OpCode Loop(Val32 op1)
 {
     return new OpCode(new byte[] { 0xe2 }, op1, true) { ByteRelative = true };
 }
Beispiel #21
0
 public static OpCode Test(Addr32 op1, Val32 op2)
 {
     return FromName("test", op1, op2);
 }
Beispiel #22
0
 public void Add(Val32 v)
 {
     data.Add(v);
     if (v.IsNeedForRelocation) relocs.Add(length);
     length += sizeof(uint);
 }
Beispiel #23
0
 public static OpCode Xor(Addr32 op1, Val32 op2)
 {
     return FromName("xor", op1, op2);
 }