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)); }
public void Set(Addr32 src) { isInitialized = src.isInitialized; reg = src.reg; disp = src.disp; address = src.address; middleBits = src.middleBits; }
public static OpCode AndR(Reg32 op1, Val32 op2) { return FromName2R("and", op1, op2); }
public static OpCode XorR(Reg32 op1, Val32 op2) { return FromName2R("xor", op1, op2); }
public static OpCode TestR(Reg32 op1, Val32 op2) { return FromName2R("test", op1, op2); }
public static OpCode SubR(Reg32 op1, Val32 op2) { return FromName2R("sub", op1, op2); }
public static OpCode AdcR(Reg32 op1, Val32 op2) { return FromName2R("adc", op1, op2); }
public static OpCode MovA(Addr32 op1, Val32 op2) { return FromName2A("mov", op1, op2); }
public static Val32 New(uint v) { var ret = new Val32(); ret.Value = v; return ret; }
// Push, Pop, Inc, Dec, Not, Neg, Mul, Imul, Div, Idiv public static OpCode PushD(Val32 op1) { return OpCode.NewD(Util.GetBytes1(0x68), op1); }
public static OpCode Loop(Val32 op1) { var ret = OpCode.NewDRel(Util.GetBytes1(0xe2), op1, true); ret.ByteRelative = true; return ret; }
public static OpCode Jcc(Cc c, Val32 op1) { return OpCode.NewDRel(Util.GetBytes2(0x0f, (byte)(0x80 + c)), op1, true); }
public void Add(int n) { if (n == 0) return; if (address != null) { address = Val32.New2(address, Val32.NewI(n)); } else { disp += n; } }
public static Addr32 NewD(Val32 ad) { var ret = new Addr32(); ret.isInitialized = true; ret.address = ad; return ret; }
public static OpCode AdcA(Addr32 op1, Val32 op2) { return FromName2A("adc", op1, op2); }
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); }
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; }
public static OpCode MovR(Reg32 op1, Val32 op2) { return FromName2R("mov", op1, op2); }
public static OpCode CallD(Val32 op1) { return OpCode.NewDRel(Util.GetBytes1(0xe8), op1, true); }
public static OpCode SubA(Addr32 op1, Val32 op2) { return FromName2A("sub", op1, op2); }
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; } }
public static OpCode TestA(Addr32 op1, Val32 op2) { return FromName2A("test", op1, op2); }
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; }
public static OpCode XorA(Addr32 op1, Val32 op2) { return FromName2A("xor", op1, op2); }
public static OpCode CmpR(Reg32 op1, Val32 op2) { return FromName2R("cmp", op1, op2); }
public static OpCode AndA(Addr32 op1, Val32 op2) { return FromName2A("and", op1, op2); }
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)); } }
public static OpCode CmpA(Addr32 op1, Val32 op2) { return FromName2A("cmp", op1, op2); }
public void AddVal32(Val32 v) { data.Add(v); if (v.IsNeedForRelocation) relocs.Add(length); length += sizeof(uint); }