public void TycoUserData() { var addrUserData = Address.Ptr32(0x00001400); var program = new ProgramBuilder().BuildProgram(); program.User = new UserData { Globals = { { addrUserData, new GlobalDataItem_v2 { Name = "xAcceleration", DataType = PrimitiveType_v1.Real64() } } } }; new EquivalenceClassBuilder(program.TypeFactory, program.TypeStore, eventListener).Build(program); var tyco = Given_TypeCollector(program); tyco.CollectGlobalType(); tyco.CollectUserGlobalVariableTypes(); Then_GlobalFieldsAre(program, "1400: xAcceleration: real64"); }
public void X86_64Psig_MixedIntsFloats() { var pser = Given_ProcedureSerializer(); var ssig = new SerializedSignature { ReturnValue = new Argument_v1 { Type = PrimitiveType_v1.Int32() }, Arguments = new Argument_v1[] { new Argument_v1 { Type = PrimitiveType_v1.Int32(), Name = "a" }, new Argument_v1 { Type = PrimitiveType_v1.Real64(), Name = "b" }, new Argument_v1 { Type = PointerType_v1.Create(PrimitiveType_v1.Char8(), 8), Name = "c" }, new Argument_v1 { Type = PrimitiveType_v1.Real64(), Name = "d" }, new Argument_v1 { Type = PrimitiveType_v1.Real32(), Name = "e" }, } }; var sig = pser.Deserialize(ssig, frame); Assert.AreEqual("rax", sig.ReturnValue.Storage.ToString()); ExpectArgs(sig, "rcx", "xmm1", "r8", "xmm3", "Stack +0008"); }
private SerializedType Type() { switch (str[i++]) { case 'b': return(PrimitiveType_v1.Bool()); case 'c': return(PrimitiveType_v1.Char8()); case 'h': return(PrimitiveType_v1.UChar8()); case 's': return(PrimitiveType_v1.Int16()); case 'r': return(PrimitiveType_v1.UInt16()); case 'i': return(PrimitiveType_v1.Int32()); case 'j': return(PrimitiveType_v1.UInt32()); case 'l': return(PrimitiveType_v1.Int64()); case 'm': return(PrimitiveType_v1.UInt64()); case 'w': return(PrimitiveType_v1.WChar16()); case 'f': return(PrimitiveType_v1.Real32()); case 'd': return(PrimitiveType_v1.Real64()); case 'P': return(new PointerType_v1 { DataType = Type(), PointerSize = ptrSize }); case 'R': return(new ReferenceType_v1 { Referent = Type(), Size = ptrSize }); default: --i; if (char.IsDigit(str[i])) { return(new TypeReference_v1 { TypeName = SimpleName(), }); } throw new NotImplementedException(string.Format("Unknown GCC type code '{0}'.", str[i])); } }
public void SvArm32Ps_DeserializeFpuReturnValue() { var ssig = new SerializedSignature { ReturnValue = new Argument_v1 { Type = PrimitiveType_v1.Real64(), } }; Given_ProcedureSerializer(); mr.ReplayAll(); var sig = ser.Deserialize(ssig, arch.CreateFrame()); Assert.AreEqual("Sequence r1:r0", sig.ReturnValue.Storage.ToString()); }
public void SvX86Ps_DeserializeFpuArgument() { var ssig = new SerializedSignature { Convention = "stdapi", ReturnValue = RegArg(PrimitiveType_v1.Int32(), "eax"), Arguments = new Argument_v1[] { StackArg(PrimitiveType_v1.Real64(), "rArg04") } }; Given_ProcedureSerializer(); mr.ReplayAll(); var sig = ser.Deserialize(ssig, arch.CreateFrame()); Assert.AreEqual("Register int32 test(Stack real64 rArg04)", sig.ToString("test")); }
public void X86ProcSer_Load_FpuReturnValue() { var ssig = new SerializedSignature { Convention = "__cdecl", ReturnValue = new Argument_v1 { Type = PrimitiveType_v1.Real64() } }; Given_ProcedureSerializer(ssig.Convention); mr.ReplayAll(); var sig = ser.Deserialize(ssig, arch.CreateFrame()); var sExp = @"FpuStack real64 test() // stackDelta: 4; fpuStackDelta: 1; fpuMaxParam: -1 "; Assert.AreEqual(sExp, sig.ToString("test", FunctionType.EmitFlags.AllDetails)); }
public void TycoUserData() { var addrUserData = Address.Ptr32(0x00001400); var program = new ProgramBuilder().BuildProgram(); program.User = new UserData { Globals = { { addrUserData, new GlobalDataItem_v2 { Name = "xAcceleration", DataType = PrimitiveType_v1.Real64() } } } }; var tyco = Given_TypeCollector(program); tyco.CollectUserGlobalVariableTypes(new Dictionary <ImageSegment, StructureType>()); Assert.AreEqual("400: xAcceleration: real64", program.GlobalFields.Fields.First().ToString()); }
private SerializedType Type() { var qual = CvQualifier(); switch (str[i++]) { case 'v': return(new VoidType_v1()); case 'b': return(Qualify(PrimitiveType_v1.Bool(), qual)); case 'c': return(Qualify(PrimitiveType_v1.Char8(), qual)); case 'h': return(Qualify(PrimitiveType_v1.UChar8(), qual)); case 's': return(Qualify(PrimitiveType_v1.Int16(), qual)); case 't': return(Qualify(PrimitiveType_v1.UInt16(), qual)); case 'i': return(Qualify(PrimitiveType_v1.Int32(), qual)); case 'j': return(Qualify(PrimitiveType_v1.UInt32(), qual)); case 'l': return(Qualify(PrimitiveType_v1.Int64(), qual)); case 'm': return(Qualify(PrimitiveType_v1.UInt64(), qual)); case 'w': return(Qualify(PrimitiveType_v1.WChar16(), qual)); case 'f': return(Qualify(PrimitiveType_v1.Real32(), qual)); case 'd': return(Qualify(PrimitiveType_v1.Real64(), qual)); case 'F': --i; return(FunctionType()); case 'N': --i; return(CreateTypeReference(NestedName())); case 'P': var ptr = new PointerType_v1 { DataType = Type(), PointerSize = ptrSize }; AddSubstitution(ptr); return(Qualify(ptr, qual)); case 'R': qual = CvQualifier(); var r = new ReferenceType_v1 { Referent = Type(), Size = ptrSize }; return(Qualify(r, qual)); case 'S': switch (str[i++]) { case 't': return(Qualify(new TypeReference_v1 { Scope = new[] { "std" }, TypeName = Type().ToString(), }, qual)); case 's': return(Qualify(new TypeReference_v1 { Scope = new[] { "std" }, TypeName = "string" }, qual)); default: int iStart = --i; while (str[i] != '_') { ++i; } ++i; var sub = str.Substring(iStart, i - iStart); Debug.Print(sub); return(Qualify((SerializedType)substitutions[sub], qual)); } throw new NotImplementedException(); default: --i; if (char.IsDigit(str[i])) { var tref = new TypeReference_v1 { TypeName = UnqualifiedName() }; AddSubstitution(tref); return(Qualify(tref, qual)); } throw new NotImplementedException(string.Format("Unknown GCC type code '{0}' ({1}).", str[i], str.Substring(i))); } }
private SerializedType Type() { switch (str[i++]) { case 'v': return(new VoidType_v1()); case 'b': return(PrimitiveType_v1.Bool()); case 'c': return(PrimitiveType_v1.Char8()); case 'h': return(PrimitiveType_v1.UChar8()); case 's': return(PrimitiveType_v1.Int16()); case 't': return(PrimitiveType_v1.UInt16()); case 'i': return(PrimitiveType_v1.Int32()); case 'j': return(PrimitiveType_v1.UInt32()); case 'l': return(PrimitiveType_v1.Int64()); case 'm': return(PrimitiveType_v1.UInt64()); case 'w': return(PrimitiveType_v1.WChar16()); case 'f': return(PrimitiveType_v1.Real32()); case 'd': return(PrimitiveType_v1.Real64()); case 'F': --i; return(FunctionType()); case 'N': --i; return(CreateTypeReference(NestedName())); case 'P': var ptr = new PointerType_v1 { DataType = Type(), PointerSize = ptrSize }; AddSubstitution(ptr); return(ptr); case 'R': //$TODO: Reko doesn't have a concept of 'const' or 'volatile'. // Needs to be implemented for completeness, but should not affect // quality of decompilation. var qual = CvQualifier(); return(new ReferenceType_v1 { Referent = Type(), Size = ptrSize }); case 'S': switch (str[i++]) { case 't': return(new TypeReference_v1 { Scope = new[] { "std" }, TypeName = Type().ToString(), }); case 's': return(new TypeReference_v1 { Scope = new[] { "std" }, TypeName = "string" }); default: int iStart = --i; while (str[i] != '_') { ++i; } ++i; var sub = str.Substring(iStart, i - iStart); Debug.Print(sub); return((SerializedType)substitutions[sub]); } throw new NotImplementedException(); default: --i; if (char.IsDigit(str[i])) { var tref = new TypeReference_v1 { TypeName = UnqualifiedName() }; AddSubstitution(tref); return(tref); } throw new NotImplementedException(string.Format("Unknown GCC type code '{0}' ({1}).", str[i], str.Substring(i))); } }
static TypeBuilder() { reservedTypes = new Dictionary <int, SerializedType> { // Type indices 0-511 are reserved.Types 0-255 (high byte = 0) have meaning according // to the decoding of the following bits: // // xxxx xxxx x xx xxx xx // xxxx xxxx i md typ sz // // The format of Type Index(and Reserved Types) is illustrated in the next // four tables. // // Table 1.2, Format of i // i Action // ----------- // 0 Special type, not interpreted as follows // (see "Special Types" below) // 1 Low 7 bits are interpreted as follows: // Table 1.3, Format of md // md Mode // ------- // 00 Direct // 01 Near Pointer // 10 Far pointer // 11 Huge pointer // Table 1.4, Format of typ // typ Basic type // --------------- // 000 Signed // 001 Unsigned // 010 Real // 011 Complex // 100 Boolean // 101 ASCII // 110 Currency // 111 Reserved // Table 1.5 Format of sz // sz Size (Real) (Complex) (Currency) // --------------------------------------------- // 00 8-bit 4-byte 8-byte Reserved // 01 16-bit 8-byte 16-byte 8-byte // 10 32-bit 10-byte 20-byte Reserved // 11 Reserved // Tables 1.6 and 1.7 list the predefined primitive types of the symbolic // debugging OMF. // Table 1.6 Special Types (8th bit = 0) // Name Value Description // ---------------------------- // T_NOTYPE 0 Uncharacterized type(no type) // T_ABS 1 Absolute symbol // Table 1.7 Primitive Type Listing(8th bit = 1) // Name Value Description // -------------------------------- // T_CHAR 80H 8-bit signed // T_SHORT 8lH 16-bit signed // T_LONG 82H 32-bit signed // T_UCHAR 84H 8-bit unsigned // T_USHORT 85H 16-bit unsigned // T_ULONG 86H 32-bit unsigned // T_REAL2 88H 32-bit real // T_REAL64 89H 64-bit real // T_REAL80 8AH(10) 80-bit real // T_CPLX64 8CH(12) 64-bit complex // T_CPLX128 8DH(13) 128-bit complex // T_CPLX160 8EH(14) 160-bit complex { 0x80, PrimitiveType_v1.Char8() }, { 0x81, PrimitiveType_v1.Int16() }, { 0x82, PrimitiveType_v1.Int32() }, { 0x84, new PrimitiveType_v1(Domain.UnsignedInt, 1) }, { 0x85, PrimitiveType_v1.UInt16() }, { 0x86, PrimitiveType_v1.UInt32() }, { 0x88, PrimitiveType_v1.Real32() }, { 0x89, PrimitiveType_v1.Real64() }, { 0x8A, PrimitiveType_v1.Real80() }, // T_BOOL08 90H(16) 8-bit Boolean // T_BOOL16 91H(17) 16-bit Boolean // T_BOOL32 9H(18) 32-bit Boolean // T_ ASCII 94H(20) 8-bit character // T_ASCII16 95H(21) 16-bit characters // T_ASCII32 96H(22) 32-bit characters // T_BSTRING 97H(23) Basic string type { 0x90, PrimitiveType_v1.Bool() }, { 0x91, PrimitiveType_v1.Bool(2) }, { 0x92, PrimitiveType_v1.Bool(4) }, // T_PCHAR A0H(32) Near pointer to 8-bit signed // T_PSHORT A1H(33) Near pointer to 16-bit signed // T_PLONG A2H(34) Near pointer to 32-bit signed // T_PUCHAR A4H(36) Near pointer to 8-bit unsigned // T_PUSHORT A5H(37) Near pointer to 16-bit unsigned // T_PULONG A6H(38) Near pointer to 32-bit unsigned // T_PREAL32 A8H(40) Near pointer to 32-bit real // T_PREAL64 A9H(41) Near pointer to 64-bit real // T_PREAL80 AAH(42) Near pointer to 80-bit real // T_PCPLX64 ACH(44) Near pointer to 64-bit complex // T_PCPLX128 ADH(45) Near pointer to 128-bit complex // T_ PCPLX160 AEH(46) Near pointer to 160-bit complex { 0xA0, NearPtr(PrimitiveType_v1.Char8()) }, { 0xA1, NearPtr(PrimitiveType_v1.Int16()) }, { 0xA2, NearPtr(PrimitiveType_v1.Int32()) }, { 0xA4, NearPtr(new PrimitiveType_v1 { Domain = Domain.UnsignedInt, ByteSize = 1 }) }, { 0xA5, NearPtr(PrimitiveType_v1.UInt16()) }, { 0xA6, NearPtr(PrimitiveType_v1.UInt32()) }, { 0xA8, NearPtr(PrimitiveType_v1.Real32()) }, { 0xA9, NearPtr(PrimitiveType_v1.Real64()) }, { 0xAA, NearPtr(PrimitiveType_v1.Real80()) }, // T_PBOOL08 B0H(48) Near pointer to 8-bit Boolean // T_PBOOL16 B1H(49) Near pointer to 16-bit Boolean // T_PBOOL32 B2H(50) Near pointer to 32-bit Boolean // T_PASCII B4H(52) Near pointer to 8-bit character // T_PASCII16 B5H(53) Near pointer to 16-bit character // T_PASC1132 B6H(54) Near pointer to 32-bit character // T_PBSTRING B7H(55) Near pointer to Basic string { 0xB0, NearPtr(PrimitiveType_v1.Bool()) }, { 0xB1, NearPtr(PrimitiveType_v1.Bool(2)) }, { 0xB2, NearPtr(PrimitiveType_v1.Bool(4)) }, // T_PFCHAR C0H(64) Far pointer to 8-bit signed // T_PFSHORT C1H(65) Far pointer to 16-bit signed // T_PFLONG C2H(66) Far pointer to 32-bit signed // T_PFUCHAR C4H(68) Far pointer to 8-bit unsigned // T_PFUSHORT C5H(69) Far pointer to 16-bit unsigned // T_PFULONG C6H(70) Far pointer to 32-bit unsigned // T_PFREAL32 C8H(72) Far pointer to 32-bit real // T_PFREAL64 C9H(73) Far pointer to 64-bit real // T_PFREAL80 CAH(74) Far pointer to 80-bit real // T_PFCPLX64 CCH(76) Far pointer to 64-bit complex // T_PFCPLX128 CDH(77) Far pointer to 128-bit complex // T_PFCPLX160 CEH(78) Far pointer to 160-bit complex { 0xC0, FarPtr(PrimitiveType_v1.Char8()) }, { 0xC1, FarPtr(PrimitiveType_v1.Int16()) }, { 0xC2, FarPtr(PrimitiveType_v1.Int32()) }, { 0xC4, FarPtr(new PrimitiveType_v1 { Domain = Domain.UnsignedInt, ByteSize = 1 }) }, { 0xC5, FarPtr(PrimitiveType_v1.UInt16()) }, { 0xC6, FarPtr(PrimitiveType_v1.UInt32()) }, { 0xC8, FarPtr(PrimitiveType_v1.Real32()) }, { 0xC9, FarPtr(PrimitiveType_v1.Real64()) }, { 0xCA, FarPtr(PrimitiveType_v1.Real80()) }, // T_PFBOOL08 D0H(80) Far pointer to 8-bit Boolean // T_PFBOOL16 D1H(81) Far pointer to 16-bit Boolean // T_PFBOO132 D2H(82) Far pointer to 32-bit Boolean // T_PFASCII D4H(84) Far pointer to 8-bit character // T_PFASCII16 D5H(85) Far pointer to 16-bit character // T_PFASCII32 D6H(86) Far pointer to 32-bit character // T_PFBSTRING D7H(87) Far pointer to Basic string { 0xD0, NearPtr(PrimitiveType_v1.Bool()) }, { 0xD1, NearPtr(PrimitiveType_v1.Bool(2)) }, { 0xD2, NearPtr(PrimitiveType_v1.Bool(4)) }, // T_PHCHAR E0H(96) Huge pointer to 8-bit signed // T_PHSHORT E1H(97) Huge pointer to 16-bit signed // T_PHLONG E2H(98) Huge pointer to 32-bit signed // T_PHUCHAR E4H(100) Huge pointer to 8-bit unsigned // T_PHUSHORT E5H(101) Huge pointer to 16-bit unsigned // T_PHULONG E6H(102) Huge pointer to 32-bit unsigned // T_PHREAL32 E8H(104) Huge pointer to 32-bit real // T_PHREAL64 E9H(105) Huge pointer to 64-bit real // T_PHREAL80 EAH(106) Huge pointer to 80-bit real // T_PHCPLX64 ECH(108) Huge pointer to 64-bit complex // T_PHCPLX128 EDH(109) Huge pointer to 128-bit complex // T_PHCPLX160 EEH(110) Huge pointer to 160-bit complex // T_PHBOOL08 F0H(112) Huge pointer to 8-bit Boolean // T_PHBOOL16 F1H(113) Huge pointer to 16-bit Boolean // T_PHBOOL32 F2H(114) Huge pointer to 32-bit Boolean // T_PHASCII F4H(116) Huge pointer to 8-bit character // T_PHASC1116 F5H(117) Huge pointer to 16-bit character // T_PHASC1132 F6H(118) Huge pointer to 32-bit character // T_PHBSTRING F7H(119) Huge pointer to Basic string }; }
private SerializedType Type() { switch (str[i++]) { case 'b': return(PrimitiveType_v1.Bool()); case 'c': return(PrimitiveType_v1.Char8()); case 'h': return(PrimitiveType_v1.UChar8()); case 's': return(PrimitiveType_v1.Int16()); case 'r': return(PrimitiveType_v1.UInt16()); case 'i': return(PrimitiveType_v1.Int32()); case 'j': return(PrimitiveType_v1.UInt32()); case 'l': return(PrimitiveType_v1.Int64()); case 'm': return(PrimitiveType_v1.UInt64()); case 'w': return(PrimitiveType_v1.WChar16()); case 'f': return(PrimitiveType_v1.Real32()); case 'd': return(PrimitiveType_v1.Real64()); case 'P': return(new PointerType_v1 { DataType = Type(), PointerSize = ptrSize }); case 'R': //$TODO: Reko doesn't have a concept of 'const' or 'volatile'. // Needs to be implemented for completeness, but should not affect // quality of decompilation. var qual = CvQualifier(); return(new ReferenceType_v1 { Referent = Type(), Size = ptrSize }); case 'S': switch (str[i++]) { case 't': return(new TypeReference_v1 { Scope = new[] { "std" }, TypeName = Type().ToString(), }); case 's': return(new TypeReference_v1 { Scope = new[] { "std" }, TypeName = "string" }); } throw new NotImplementedException(); default: --i; if (char.IsDigit(str[i])) { return(new TypeReference_v1 { TypeName = UnqualifiedName(), }); } throw new NotImplementedException(string.Format("Unknown GCC type code '{0}'.", str[i])); } }