Пример #1
0
 public Val32 AddData(string category, string name, Val32 type, int size, int len, Block32 data)
 {
     var db = new DataBlock();
     db.Block.AddVal32(type);
     db.Block.AddInt(1);
     db.Block.AddInt(size);
     db.Block.AddInt(len);
     var offset = db.Block.Length;
     db.Block.AddBlock(data);
     Module.Data.AddDataBlock(category, name, db);
     return Val32.New2(db.Address, Val32.New(offset));
 }
Пример #2
0
 public void Set(Addr32 src)
 {
     isInitialized = src.isInitialized;
     reg = src.reg;
     disp = src.disp;
     address = src.address;
     middleBits = src.middleBits;
 }
Пример #3
0
 public static OpCode AndR(Reg32 op1, Val32 op2)
 {
     return FromName2R("and", op1, op2);
 }
Пример #4
0
 public static OpCode XorR(Reg32 op1, Val32 op2)
 {
     return FromName2R("xor", op1, op2);
 }
Пример #5
0
 public static OpCode TestR(Reg32 op1, Val32 op2)
 {
     return FromName2R("test", op1, op2);
 }
Пример #6
0
 public static OpCode SubR(Reg32 op1, Val32 op2)
 {
     return FromName2R("sub", op1, op2);
 }
Пример #7
0
 public static OpCode AdcR(Reg32 op1, Val32 op2)
 {
     return FromName2R("adc", op1, op2);
 }
Пример #8
0
 public static OpCode MovA(Addr32 op1, Val32 op2)
 {
     return FromName2A("mov", op1, op2);
 }
Пример #9
0
 public static Val32 New(uint v)
 {
     var ret = new Val32();
     ret.Value = v;
     return ret;
 }
Пример #10
0
 // Push, Pop, Inc, Dec, Not, Neg, Mul, Imul, Div, Idiv
 public static OpCode PushD(Val32 op1)
 {
     return OpCode.NewD(Util.GetBytes1(0x68), op1);
 }
Пример #11
0
Файл: I386.cs Проект: 7shi/LLPML
 public static OpCode Loop(Val32 op1)
 {
     var ret = OpCode.NewDRel(Util.GetBytes1(0xe2), op1, true);
     ret.ByteRelative = true;
     return ret;
 }
Пример #12
0
Файл: I386.cs Проект: 7shi/LLPML
 public static OpCode Jcc(Cc c, Val32 op1)
 {
     return OpCode.NewDRel(Util.GetBytes2(0x0f, (byte)(0x80 + c)), op1, true);
 }
Пример #13
0
        public void Add(int n)
        {
            if (n == 0) return;

            if (address != null)
            {
                address = Val32.New2(address, Val32.NewI(n));
            }
            else
            {
                disp += n;
            }
        }
Пример #14
0
 public static Addr32 NewD(Val32 ad)
 {
     var ret = new Addr32(); ret.isInitialized = true; ret.address = ad; return ret;
 }
Пример #15
0
 public static OpCode AdcA(Addr32 op1, Val32 op2)
 {
     return FromName2A("adc", op1, op2);
 }
Пример #16
0
 public static OpCode FromName2R(string op, Reg32 op1, Val32 op2)
 {
     byte[] bytes;
     switch (op)
     {
         case "mov":
             bytes = Util.GetBytes1((byte)(0xb8 + op1));
             break;
         case "test":
             if (op1 == Reg32.EAX)
                 bytes = Util.GetBytes1(0xa9);
             else
                 bytes = Util.GetBytes2(0xf7, (byte)(0xc0 + op1));
             break;
         default:
             int code = GetOperatorCode(op);
             if (code < 0) throw new Exception("invalid operator: " + op);
             if (op1 == Reg32.EAX)
                 bytes = Util.GetBytes1((byte)(code * 8 + 5));
             else
                 bytes = Util.GetBytes2(0x81, (byte)(code * 8 + 0xc0 + op1));
             break;
     }
     return OpCode.NewD(bytes, op2);
 }
Пример #17
0
 public static Val32 New2(Val32 a, Val32 b)
 {
     var ret = new Val32();
     ret.isInitialized = a.isInitialized;
     ret.isNeedForRelocation = a.isNeedForRelocation;
     ret.ref1 = a;
     ret.ref2 = b;
     return ret;
 }
Пример #18
0
 public static OpCode MovR(Reg32 op1, Val32 op2)
 {
     return FromName2R("mov", op1, op2);
 }
Пример #19
0
 public static OpCode CallD(Val32 op1)
 {
     return OpCode.NewDRel(Util.GetBytes1(0xe8), op1, true);
 }
Пример #20
0
 public static OpCode SubA(Addr32 op1, Val32 op2)
 {
     return FromName2A("sub", op1, op2);
 }
Пример #21
0
 public void AddCodesV(string op, Addr32 dest, Val32 v)
 {
     switch (op)
     {
         case "push":
             Add(I386.PushD(v));
             break;
         default:
             if (dest != null)
                 Add(I386.FromName2A(op, dest, v));
             else
                 Add(I386.FromName2R(op, Reg32.EAX, v));
             break;
     }
 }
Пример #22
0
 public static OpCode TestA(Addr32 op1, Val32 op2)
 {
     return FromName2A("test", op1, op2);
 }
Пример #23
0
        public Val32 GetTypeObjectV(string name, Function dtor, int size, Val32 baseType)
        {
            if (types.ContainsKey(name))
                return types.Get(name) as Val32;

            var block = new Block32();
            var namev = Val32.NewB(0, true);
            block.AddVal32(namev);
            if (dtor == null || name == "string" || name == "Type")
                block.AddInt(0);
            else
                block.AddVal32(GetAddress(dtor));
            block.AddInt(size);
            block.AddVal32(baseType);
            var type = Val32.NewB(0, true);
            var tsz = (int)block.Length;
            var ret = AddData("type_object", name, type, tsz, -1, block);
            types.Add(name, ret);
            namev.Reference = GetString(name);
            type.Reference = GetTypeObjectD(Root.GetStruct("Type"));
            return ret;
        }
Пример #24
0
 public static OpCode XorA(Addr32 op1, Val32 op2)
 {
     return FromName2A("xor", op1, op2);
 }
Пример #25
0
 public static OpCode CmpR(Reg32 op1, Val32 op2)
 {
     return FromName2R("cmp", op1, op2);
 }
Пример #26
0
 public static OpCode AndA(Addr32 op1, Val32 op2)
 {
     return FromName2A("and", op1, op2);
 }
Пример #27
0
 public static OpCode FromName2A(string op, Addr32 op1, Val32 op2)
 {
     switch (op)
     {
         case "mov":
             return OpCode.NewDA(Util.GetBytes1(0xc7), op2, op1);
         case "test":
             return OpCode.NewDA(Util.GetBytes1(0xf7), op2, op1);
         default:
             int code = GetOperatorCode(op);
             if (code < 0) throw new Exception("invalid operator: " + op);
             return OpCode.NewDA(Util.GetBytes1(0x81), op2, Addr32.NewAdM(op1, (byte)code));
     }
 }
Пример #28
0
 public static OpCode CmpA(Addr32 op1, Val32 op2)
 {
     return FromName2A("cmp", op1, op2);
 }
Пример #29
0
 public void AddVal32(Val32 v)
 {
     data.Add(v);
     if (v.IsNeedForRelocation) relocs.Add(length);
     length += sizeof(uint);
 }