public void Dec_LoadCallSignatures() { var arch = new X86ArchitectureReal(); Program program = new Program { Architecture = arch, Platform = new MsdosPlatform(sc, arch) }; decompiler.Project = new Project { Programs = { program }, }; SerializedSignature sig = new SerializedSignature(); sig.Arguments = new Argument_v1[] { new Argument_v1 { Kind = new Register_v1("ds") }, new Argument_v1 { Kind = new Register_v1("bx"), } }; var al = new List<SerializedCall_v1> { new SerializedCall_v1(Address.SegPtr(0x0C32, 0x3200), sig) }; var sigs = decompiler.LoadCallSignatures(program, al); FunctionType ps = sigs[Address.SegPtr(0x0C32, 0x3200)]; Assert.IsNotNull(ps, "Expected a call signature for address"); }
public void Parse(string signatureString) { this.str = signatureString; idx = 0; try { var ret = ParseReturn(); var procName = ParseProcedureName(); if (procName == null) return; var procArgs = ParseProcedureArgs(); if (procArgs == null) return; ProcedureName = procName; Signature = new SerializedSignature(); Signature.ReturnValue = ret; Signature.Arguments = procArgs; IsValid = true; } catch { IsValid = false; } }
public override ProcedureSignature Deserialize(SerializedSignature ss, Frame frame) { if (ss == null) return null; var argser = new ArgumentSerializer(this, Architecture, frame, ss.Convention); Identifier ret = null; if (ss.ReturnValue != null) { ret = argser.DeserializeReturnValue(ss.ReturnValue); } var args = new List<Identifier>(); if (ss.Arguments != null) { for (int iArg = 0; iArg < ss.Arguments.Length; ++iArg) { var sArg = ss.Arguments[iArg]; Identifier arg = argser.Deserialize(sArg); args.Add(arg); } } var sig = new ProcedureSignature(ret, args.ToArray()); return sig; }
private void Given_Sig(params Argument_v1 [] args) { ssig = new SerializedSignature { Arguments = args }; }
private void Given_Sig(SerializedType ret, params Argument_v1 [] args) { ssig = new SerializedSignature { ReturnValue = new Argument_v1 { Type = ret } }; }
public void Dec_LoadCallSignatures() { var arch = new IntelArchitecture(ProcessorMode.Real); Program program = new Program { Architecture = arch, Platform = new MsdosPlatform(null, arch) }; decompiler.Project = new Project { Programs = { program }, }; List<SerializedCall_v1> al = new List<SerializedCall_v1>(); SerializedSignature sig = new SerializedSignature(); sig.Arguments = new Argument_v1[] { new Argument_v1 { Kind = new Register_v1("ds") }, new Argument_v1 { Kind = new Register_v1("bx"), } }; al.Add(new SerializedCall_v1(Address.SegPtr(0x0C32, 0x3200), sig)); var sigs = decompiler.LoadCallSignatures(program, al); ProcedureSignature ps = sigs[Address.SegPtr(0x0C32, 0x3200)]; Assert.IsNotNull(ps, "Expected a call signature for address"); }
public override ProcedureSignature Deserialize(SerializedSignature ss, Frame frame) { if (ss == null) return null; this.argser = new ArgumentSerializer(this, Architecture, frame, ss.Convention); Identifier ret = null; int fpuDelta = FpuStackOffset; FpuStackOffset = 0; if (ss.ReturnValue != null) { ret = argser.DeserializeReturnValue(ss.ReturnValue); fpuDelta += FpuStackOffset; } FpuStackOffset = 0; var args = new List<Identifier>(); if (ss.Arguments != null) { for (int iArg = 0; iArg < ss.Arguments.Length; ++iArg) { var sArg = ss.Arguments[iArg]; var arg = DeserializeArgument(sArg, iArg, ss.Convention); args.Add(arg); } fpuDelta -= FpuStackOffset; } FpuStackOffset = fpuDelta; var sig = new ProcedureSignature(ret, args.ToArray()); ApplyConvention(ss, sig); return sig; }
public override FunctionType Deserialize(SerializedSignature ss, Frame frame) { if (ss == null) return new FunctionType(); if (ss == null) return null; var argser = new ArgumentDeserializer(this, Architecture, frame, 0, Architecture.WordWidth.Size); Identifier ret = null; if (ss.ReturnValue != null) { ret = argser.DeserializeReturnValue(ss.ReturnValue); } var args = new List<Identifier>(); this.gr = 0; if (ss.Arguments != null) { for (int iArg = 0; iArg < ss.Arguments.Length; ++iArg) { var sArg = ss.Arguments[iArg]; Identifier arg = DeserializeArgument(argser, sArg); args.Add(arg); } } var sig = new FunctionType(ret, args.ToArray()); return sig; }
public void ApplyConvention(SerializedSignature ssig, FunctionType sig) { string d = ssig.Convention; if (d == null || d.Length == 0) d = DefaultConvention; sig.StackDelta = 0; sig.FpuStackDelta = FpuStackOffset; }
public void Setup() { this.mr = new MockRepository(); this.arch = new MipsLe32Architecture(); this.typeLoader = mr.Stub<ISerializedTypeVisitor<DataType>>(); this.ssig = null; this.sig = null; }
public void VoidFunctionSignature() { SerializedSignature sig = new SerializedSignature(); Given_X86ProcedureSerializer(); ProcedureSignature ps = ser.Deserialize(sig, arch.CreateFrame()); Assert.AreEqual("void foo()", ps.ToString("foo")); Assert.IsTrue(ps.ParametersValid); }
public void ApplyConvention(SerializedSignature ssig, ProcedureSignature sig) { string d = ssig.Convention; if (d == null || d.Length == 0) d = DefaultConvention; if (d == "stdapi" || d == "__stdcall" || d == "pascal") sig.StackDelta = StackOffset; sig.FpuStackDelta = FpuStackOffset; }
private void PopulateSignatureFields(SerializedSignature sig) { if (sig.ReturnValue != null) { ListViewItem item = new ListViewItem("<Return value>"); item.Tag = sig.ReturnValue; dlg.ArgumentList.Items.Add(item); } }
public override FunctionType Deserialize(SerializedSignature ss, Frame frame) { int ncrn = 0; int nsaa = 0; // mem arg forb ret val var argser = new ArgumentDeserializer( this, Architecture, frame, Architecture.PointerType.Size, Architecture.WordWidth.Size); Identifier ret = null; if (ss.ReturnValue != null) { ret = argser.DeserializeReturnValue(ss.ReturnValue); } var args = new List<Identifier>(); if (ss.Arguments != null) { foreach (var sArg in ss.Arguments) { var dt = sArg.Type.Accept(TypeLoader); var sizeInWords = (dt.Size + 3) / 4; if (sizeInWords == 2 && (ncrn & 1) == 1) ++ncrn; Identifier arg; if (sizeInWords <= 4 - ncrn) { if (sizeInWords == 2) { arg = frame.EnsureSequence( Architecture.GetRegister(argRegs[ncrn]), Architecture.GetRegister(argRegs[ncrn + 1]), dt); ncrn += 2; } else { arg = frame.EnsureRegister( Architecture.GetRegister(argRegs[ncrn])); ncrn += 1; } } else { arg = frame.EnsureStackArgument(nsaa, dt); nsaa += AlignedStackArgumentSize(dt); } args.Add(arg); } } return new FunctionType(ret, args.ToArray()); }
public override FunctionType Deserialize(SerializedSignature ss, Frame frame) { if (ss == null) return null; this.argDeser = new ArgumentDeserializer( this, Architecture, frame, Architecture.PointerType.Size, //$BUG: x86 real mode? Architecture.WordWidth.Size); Identifier ret = null; int fpuDelta = FpuStackOffset; FpuStackOffset = 0; if (ss.ReturnValue != null) { ret = argDeser.DeserializeReturnValue(ss.ReturnValue); fpuDelta += FpuStackOffset; } FpuStackOffset = 0; var args = new List<Identifier>(); if (ss.EnclosingType != null) { var arg = DeserializeImplicitThisArgument(ss); args.Add(arg); } if (ss.Arguments != null) { if (ss.Convention == "pascal") { for (int iArg = ss.Arguments.Length -1; iArg >= 0; --iArg) { var sArg = ss.Arguments[iArg]; var arg = DeserializeArgument(sArg, iArg, ss.Convention); args.Add(arg); } args.Reverse(); } else { for (int iArg = 0; iArg < ss.Arguments.Length; ++iArg) { var sArg = ss.Arguments[iArg]; var arg = DeserializeArgument(sArg, iArg, ss.Convention); args.Add(arg); } } fpuDelta -= FpuStackOffset; } FpuStackOffset = fpuDelta; var sig = new FunctionType(ret, args.ToArray()); sig.IsInstanceMetod = ss.IsInstanceMethod; ApplyConvention(ss, sig); return sig; }
public void ApplyConvention(SerializedSignature ssig, ProcedureSignature sig) { string d = ssig.Convention; if (d == null || d.Length == 0) d = defaultConvention; if (d != null && d == "stdapi") sig.StackDelta = stackOffset; sig.FpuStackDelta = fpuStackOffset; }
private void Verify(SerializedSignature ssig, string outputFilename) { using (FileUnitTester fut = new FileUnitTester(outputFilename)) { XmlTextWriter x = new FilteringXmlWriter(fut.TextWriter); x.Formatting = Formatting.Indented; XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(ssig.GetType()); ser.Serialize(x, ssig); fut.AssertFilesEqual(); } }
public void ApplyConvention(SerializedSignature ssig, ProcedureSignature sig) { string d = ssig.Convention; if (d == null || d.Length == 0) d = DefaultConvention; sig.StackDelta = Architecture.PointerType.Size; //$BUG: far/near pointers? if (d == "stdapi" || d == "__stdcall" || d == "pascal") sig.StackDelta += StackOffset; sig.FpuStackDelta = FpuStackOffset; sig.ReturnAddressOnStack = Architecture.PointerType.Size; //$BUG: x86 real mode? }
public void PpcPs_DeserializeFpuStackReturnValue() { var ssig = new SerializedSignature { ReturnValue = new Argument_v1 { Type = new PrimitiveType_v1(Domain.Real, 8), } }; Given_ProcedureSerializer(); var sig = ser.Deserialize(ssig, arch.CreateFrame()); Assert.AreEqual("f1", sig.ReturnValue.Storage.ToString()); }
public void PpcPs_DeserializeFpuArgument() { var ssig = new SerializedSignature { Convention = "stdapi", ReturnValue = RegArg(Type("int"), "r3"), Arguments = new Argument_v1[] { FpuArg(Type("double"), "f1") } }; Given_ProcedureSerializer(); var sig = ser.Deserialize(ssig, arch.CreateFrame()); Assert.AreEqual("Register int test(Register word64 f1)", sig.ToString("test")); }
public void ProcSer_DeserializeFpuStackReturnValue() { var ssig = new SerializedSignature { Convention = "stdapi", ReturnValue = new Argument_v1 { Type = new SerializedTypeReference("double"), Kind = new FpuStackVariable_v1 { ByteSize = 8 }, } }; Given_ProcedureSerializer("stdapi"); var sig = ser.Deserialize(ssig, arch.CreateFrame()); Assert.AreEqual(1, sig.FpuStackDelta); }
public void DeserializeFpuStackargument() { var ssig = new SerializedSignature { Convention = "stdapi", ReturnValue = RegArg(Type("int"), "eax"), Arguments = new Argument_v1[] { FpuArg(Type("double"), null) } }; Given_ProcedureSerializer("stdapi"); var sig = ser.Deserialize(ssig, arch.CreateFrame()); Assert.AreEqual(-1, sig.FpuStackDelta); Assert.AreEqual(0, sig.StackDelta); Assert.AreEqual("Register int test(FpuStack real64 fpArg0)", sig.ToString("test")); }
public void SerializedCall_Create() { SerializedSignature sig = new SerializedSignature { Arguments = new Argument_v1[] { new Argument_v1 { Kind = new Register_v1("bx"), } } }; SerializedCall_v1 sc = new SerializedCall_v1(Address.Ptr32(0x01004000), sig); Assert.AreEqual("01004000", sc.InstructionAddress); Assert.AreEqual("bx", ((Register_v1) sc.Signature.Arguments[0].Kind).Name); }
public void SseqBuildSequence() { Frame f = arch.CreateFrame(); Identifier head = f.EnsureRegister(Registers.dx); Identifier tail = f.EnsureRegister(Registers.ax); Identifier seq = f.EnsureSequence(head, tail, PrimitiveType.Word32); SerializedSequence sq = new SerializedSequence((SequenceStorage) seq.Storage); Argument_v1 sa = new Argument_v1(); sa.Kind = sq; SerializedSignature ssig = new SerializedSignature(); ssig.Arguments = new Argument_v1[] { sa }; Given_X86ProcedureSerializer(); ProcedureSignature ps = ser.Deserialize(ssig, f); Assert.AreEqual("void foo(Sequence word32 dx_ax)", ps.ToString("foo")); }
public static SerializedSignature BuildSsigAxBxCl() { SerializedSignature ssig = new SerializedSignature(); Argument_v1 sarg = new Argument_v1(); sarg.Type = new PrimitiveType_v1(Domain.SignedInt, 2); sarg.Kind = new Register_v1("ax"); ssig.ReturnValue = sarg; ssig.Arguments = new Argument_v1[] { new Argument_v1 { Kind = new Register_v1("bx") }, new Argument_v1 { Kind = new Register_v1("cl") }, }; return ssig; }
public SerializedSignature Serialize(ProcedureSignature sig) { SerializedSignature ssig = new SerializedSignature(); if (!sig.ParametersValid) return ssig; ArgumentSerializer argSer = new ArgumentSerializer(this, Architecture, null, null); ssig.ReturnValue = argSer.Serialize(sig.ReturnValue); ssig.Arguments = new Argument_v1[sig.Parameters.Length]; for (int i = 0; i < sig.Parameters.Length; ++i) { Identifier formal = sig.Parameters[i]; ssig.Arguments[i] = argSer.Serialize(formal); } ssig.StackDelta = sig.StackDelta; ssig.FpuStackDelta = sig.FpuStackDelta; return ssig; }
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 SvAmdPs_DeserializeFpuStackReturnValue() { var ssig = new SerializedSignature { ReturnValue = new Argument_v1 { Type = new PrimitiveType_v1(Domain.Real, 8), } }; Given_ProcedureSerializer(); mr.ReplayAll(); var sig = ser.Deserialize(ssig, arch.CreateFrame()); Assert.AreEqual("xmm0", sig.ReturnValue.Storage.ToString()); }
public void PpcPs_DeserializeFpuArgument() { var ssig = new SerializedSignature { Convention = "stdapi", ReturnValue = RegArg(Type("int"), "r3"), Arguments = new Argument_v1[] { FpuArg(Type("double"), "f1") } }; Given_ProcedureSerializer(); mr.ReplayAll(); var sig = ser.Deserialize(ssig, arch.CreateFrame()); Assert.AreEqual("Register int test(Register double f1)", sig.ToString("test")); }
public void SseqBuildSequence() { Frame f = platform.Architecture.CreateFrame(); Identifier head = f.EnsureRegister(Registers.dx); Identifier tail = f.EnsureRegister(Registers.ax); Identifier seq = f.EnsureSequence(head.Storage, tail.Storage, PrimitiveType.Word32); SerializedSequence sq = new SerializedSequence((SequenceStorage)seq.Storage); Argument_v1 sa = new Argument_v1(); sa.Kind = sq; SerializedSignature ssig = new SerializedSignature(); ssig.Arguments = new Argument_v1[] { sa }; Given_X86ProcedureSerializer(); FunctionType ps = ser.Deserialize(ssig, f); Assert.AreEqual("void foo(Sequence word32 dx_ax)", ps.ToString("foo")); }
public void Ici_Return_in_AddressRegister() { var ici = new InlineCodeInterpreter(constants); var ssig = new SerializedSignature { Arguments = new Argument_v1[0], ReturnValue = new Argument_v1 { Type = new PrimitiveType_v1 { Domain = Domain.Pointer, ByteSize = 4 } }, }; var svc = ici.BuildSystemCallFromMachineCode( "GetZone", ssig, Opcodes(0xA11A, 0x2E88)); Assert.AreEqual("A11A", svc.SyscallInfo.Vector); Assert.AreEqual("a0", ((Register_v1)svc.Signature.ReturnValue.Kind).Name); }
/// <summary> /// Creates a symbol describing the location of a callable procedure. /// </summary> /// <param name="arch">Processor architecture of the procedure.</param> /// <param name="address">Address of the procedure.</param> /// <param name="name">Optional name of the procedure.</param> /// <param name="dataType">Optional data type of the procedure.</param> /// <param name="signature">Optional serialized signature.</param> /// <param name="state">Optional processor state.</param> /// <returns>A symbol</returns> public static ImageSymbol Procedure( IProcessorArchitecture arch, Address address, string name = null, DataType dataType = null, SerializedSignature signature = null, ProcessorState state = null) { return(new ImageSymbol(arch) { Type = SymbolType.Procedure, Architecture = arch, Address = address, Name = name, DataType = dataType ?? new FunctionType(), Signature = signature, ProcessorState = state, }); }
public void Ici_Load_Word_Constant_To_Register() { var ici = new InlineCodeInterpreter(constants); var ssig = new SerializedSignature { Arguments = new [] { new Argument_v1 { Name = "typecode", Type = PrimitiveType_v1.Int32(), }, new Argument_v1 { Name = "dataPtr", Type = new PrimitiveType_v1 { Domain = Domain.Pointer, ByteSize = 4 }, }, new Argument_v1 { Name = "result", Type = new ReferenceType_v1 { Referent = new TypeReference_v1 { TypeName = "AEDesc" } } } }, ReturnValue = new Argument_v1 { Type = PrimitiveType_v1.Int16() } }; var svc = ici.BuildSystemCallFromMachineCode( "AECreateDesc", ssig, Opcodes(0x303C, 0x0825, 0xA816)); Assert.AreEqual("A816", svc.SyscallInfo.Vector); Assert.AreEqual("d0", svc.SyscallInfo.RegisterValues[0].Register); Assert.AreEqual("0825", svc.SyscallInfo.RegisterValues[0].Value); }
public void PpcPs_Serialize() { Given_ProcedureSerializer(); mr.ReplayAll(); ProcedureSignature sig = new ProcedureSignature( new Identifier("qax", PrimitiveType.Word32, arch.Registers[3]), new Identifier[] { new Identifier("qbx", PrimitiveType.Word32, arch.Registers[3]) }); SerializedSignature ssig = ser.Serialize(sig); Assert.IsNotNull(ssig.ReturnValue); Assert.AreEqual("qax", ssig.ReturnValue.Name); Register_v1 sreg = (Register_v1)ssig.ReturnValue.Kind; Assert.AreEqual("r3", sreg.Name); }
public void ProcSer_Deserialize_thiscall() { var ssig = new SerializedSignature { Convention = "__thiscall", Arguments = new Argument_v1[] { new Argument_v1 { Type = new SerializedTypeReference("int"), Name = "this" } } }; Given_ProcedureSerializer("stdcall"); var sig = ser.Deserialize(ssig, arch.CreateFrame()); Assert.AreEqual("ecx", sig.Parameters[0].ToString()); }
public override FunctionType Deserialize(SerializedSignature ss, Frame frame) { if (ss == null) { return(null); } this.argDeser = new ArgumentDeserializer( this, Architecture, frame, Architecture.PointerType.Size, Architecture.WordWidth.Size); Identifier ret = null; if (ss.ReturnValue != null) { ret = argDeser.DeserializeReturnValue(ss.ReturnValue); } var args = new List <Identifier>(); int iArg = 0; if (ss.EnclosingType != null && ss.IsInstanceMethod) { var arg = DeserializeImplicitThisArgument(ss); args.Add(arg); ++iArg; } if (ss.Arguments != null) { for (iArg = 0; iArg < ss.Arguments.Length; ++iArg) { var sArg = ss.Arguments[iArg]; var arg = DeserializeArgument(sArg, iArg, ss.Convention); args.Add(arg); } } var sig = new FunctionType(ret, args.ToArray()); sig.IsInstanceMetod = ss.IsInstanceMethod; ApplyConvention(ss, sig); return(sig); }
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 override FunctionType Deserialize(SerializedSignature ss, Frame frame) { if (ss == null) { return(null); } this.argser = new ArgumentDeserializer( this, Architecture, frame, Architecture.PointerType.Size, Architecture.WordWidth.Size); Identifier ret = null; int fpuDelta = FpuStackOffset; FpuStackOffset = 0; if (ss.ReturnValue != null) { ret = argser.DeserializeReturnValue(ss.ReturnValue); fpuDelta += FpuStackOffset; } FpuStackOffset = 0; var args = new List <Identifier>(); if (ss.Arguments != null) { for (int iArg = 0; iArg < ss.Arguments.Length; ++iArg) { var sArg = ss.Arguments[iArg]; var arg = DeserializeArgument(sArg, iArg, ss.Convention); args.Add(arg); } fpuDelta -= FpuStackOffset; } FpuStackOffset = fpuDelta; var sig = new FunctionType(ret, args.ToArray()); ApplyConvention(ss, sig); return(sig); }
private Identifier DeserializeImplicitThisArgument(SerializedSignature ss) { var sArg = new Argument_v1 { Type = new PointerType_v1(ss.EnclosingType), Name = "this", }; if (ss.Convention == "__thiscall") { sArg.Kind = new Register_v1("ecx"); } else { sArg.Kind = new StackVariable_v1(); } var arg = argDeser.Deserialize(sArg); return(arg); }
public void ApplyConvention(SerializedSignature ssig, FunctionType sig) { string d = ssig.Convention; if (d == null || d.Length == 0) { d = DefaultConvention; } sig.StackDelta = Architecture.PointerType.Size; //$BUG: far/near pointers? if (d == "stdapi" || d == "stdcall" || d == "__stdcall" || d == "__thiscall" || d == "pascal") { sig.StackDelta += StackOffset; } sig.FpuStackDelta = FpuStackOffset; sig.ReturnAddressOnStack = Architecture.PointerType.Size; //$BUG: x86 real mode? }
public void SvArm32Ps_Load_cdecl() { var ssig = new SerializedSignature { Arguments = new Argument_v1[] { new Argument_v1 { Name = "foo", Type = PrimitiveType_v1.Int32(), } } }; Given_ProcedureSerializer(); mr.ReplayAll(); var sig = ser.Deserialize(ssig, arch.CreateFrame()); Assert.AreEqual(0, sig.StackDelta); }
public void SvAmdPs_Serialize() { Given_ProcedureSerializer(); mr.ReplayAll(); var sig = new FunctionType( new Identifier("rbx", PrimitiveType.Word32, arch.GetRegister("rbx")), new Identifier[] { new Identifier("rbx", PrimitiveType.Word32, arch.GetRegister("rbx")) }); SerializedSignature ssig = ser.Serialize(sig); Assert.IsNotNull(ssig.ReturnValue); Assert.AreEqual("rbx", ssig.ReturnValue.Name); Register_v1 sreg = (Register_v1)ssig.ReturnValue.Kind; Assert.AreEqual("rbx", sreg.Name); }
public void Ici_Argument_in_AddressRegister() { var ici = new InlineCodeInterpreter(constants); var ssig = new SerializedSignature { Arguments = new[] { new Argument_v1 { Name = "h", Type = new PrimitiveType_v1 { Domain = Domain.Pointer, ByteSize = 4 } }, } }; var svc = ici.BuildSystemCallFromMachineCode( "HUnlock", ssig, Opcodes(0x205F, 0xA02A)); Assert.AreEqual("A02A", svc.SyscallInfo.Vector); Assert.AreEqual("a0", ((Register_v1)svc.Signature.Arguments[0].Kind).Name); }
private Argument_v1[] ParseParameters(SerializedSignature ssig) { var args = new List <Argument_v1>(); if (PeekAndDiscard(TokenType.LPAREN)) { while (LoadParameter(ssig, args)) { ; } Expect(TokenType.RPAREN); } if (ssig.Convention == "varargs") { args.Add(new Argument_v1 { Name = "...", Type = new VoidType_v1() }); ssig.Convention = "__cdecl"; } return(args.ToArray()); }
public void PpcPs_Load_cdecl() { var ssig = new SerializedSignature { Convention = "__cdecl", Arguments = new Argument_v1[] { new Argument_v1 { Name = "foo", Type = new PrimitiveType_v1 { Domain = Domain.SignedInt, ByteSize = 4 }, } } }; Given_ProcedureSerializer(); var sig = ser.Deserialize(ssig, arch.CreateFrame()); Assert.AreEqual(0, sig.StackDelta); }
public static SerializedSignature BuildSsigAxBxCl() { SerializedSignature ssig = new SerializedSignature(); Argument_v1 sarg = new Argument_v1(); sarg.Type = new PrimitiveType_v1(Domain.SignedInt, 2); sarg.Kind = new Register_v1("ax"); ssig.ReturnValue = sarg; ssig.Arguments = new Argument_v1[] { new Argument_v1 { Kind = new Register_v1("bx") }, new Argument_v1 { Kind = new Register_v1("cl") }, }; return(ssig); }
public void Win32_Deserialize_PlatformTypes() { var types = new Dictionary <string, DataType>() { { "TESTTYPE1", PrimitiveType.Create(PrimitiveType.Byte.Domain, 1) }, { "TESTTYPE2", PrimitiveType.Create(PrimitiveType.Int16.Domain, 2) }, { "TESTTYPE3", PrimitiveType.Create(PrimitiveType.Int32.Domain, 4) }, }; Given_TypeLibraryLoaderService(); Expect_TypeLibraryLoaderService_LoadLibrary("windows.xml", types); Given_Configuration_With_Win32_Element(); mr.ReplayAll(); When_Creating_Win32_Platform(); Given_Program(); var ser = program.CreateProcedureSerializer(); var sSig = new SerializedSignature { Convention = "__cdecl", ReturnValue = new Argument_v1(null, new TypeReference_v1("TESTTYPE1"), null, false), Arguments = new Argument_v1[] { new Argument_v1("a", new TypeReference_v1("TESTTYPE2"), null, false), new Argument_v1("b", new TypeReference_v1("TESTTYPE3"), null, false) } }; var sig = ser.Deserialize(sSig, win32.Architecture.CreateFrame()); var sigExp = @"Register TESTTYPE1 foo(Stack TESTTYPE2 a, Stack TESTTYPE3 b) // stackDelta: 4; fpuStackDelta: 0; fpuMaxParam: -1 "; Assert.AreEqual(sigExp, sig.ToString("foo", FunctionType.EmitFlags.AllDetails)); Assert.AreEqual("byte", (sig.ReturnValue.DataType as TypeReference).Referent.ToString()); Assert.AreEqual("int16", (sig.Parameters[0].DataType as TypeReference).Referent.ToString()); Assert.AreEqual("int32", (sig.Parameters[1].DataType as TypeReference).Referent.ToString()); }
public void X86ProcSer_Load_thiscall() { var ssig = new SerializedSignature { EnclosingType = new StructType_v1 { Name = "CWindow" }, Convention = "__thiscall", Arguments = new Argument_v1[] { new Argument_v1 { Name = "XX", Type = new PrimitiveType_v1 { Domain = Domain.SignedInt, ByteSize = 4 }, }, new Argument_v1 { Name = "arg1", Type = new PrimitiveType_v1 { Domain = Domain.SignedInt, ByteSize = 2 }, }, } }; Given_ProcedureSerializer(ssig.Convention); mr.ReplayAll(); var sig = ser.Deserialize(ssig, arch.CreateFrame()); var sExp = @"void memfn(Register (ptr (struct ""CWindow"")) this, Stack int32 XX, Stack int16 arg1) // stackDelta: 12; fpuStackDelta: 0; fpuMaxParam: -1 "; Assert.AreEqual(sExp, sig.ToString("memfn", FunctionType.EmitFlags.AllDetails)); Assert.AreEqual(4, ((StackArgumentStorage)sig.Parameters[1].Storage).StackOffset); Assert.AreEqual(8, ((StackArgumentStorage)sig.Parameters[2].Storage).StackOffset); }
public void SvX86Ps_Load_IntArgs() { var ssig = new SerializedSignature { Arguments = new Argument_v1[] { new Argument_v1 { Name = "hArg04", Type = new PrimitiveType_v1 { Domain = Domain.SignedInt, ByteSize = 2 }, }, new Argument_v1 { Name = "wArg08", Type = new PrimitiveType_v1 { Domain = Domain.SignedInt, ByteSize = 1 }, }, new Argument_v1 { Name = "rArg0C", Type = PrimitiveType_v1.Real32(), }, } }; Given_ProcedureSerializer(); mr.ReplayAll(); var sig = ser.Deserialize(ssig, arch.CreateFrame()); var args = sig.Parameters; Assert.AreEqual( string.Format( "void foo(Stack int16 hArg04, Stack int8 wArg08, Stack real32 rArg0C){0}// stackDelta: 0; fpuStackDelta: 0; fpuMaxParam: -1{0}", nl), sig.ToString("foo", FunctionType.EmitFlags.AllDetails)); }
public Tuple <int?, SystemService> ParseLine() { try { int?ordinal = ParseOrdinal(); string callconv = ParseCallingConvention(); var options = ParseOptions(); var tok = Get(); string fnName = tok.Value; var ssig = new SerializedSignature { Convention = callconv, }; ssig.Arguments = ParseParameters(ssig); SkipToEndOfLine(); var deser = new ProcedureSerializer(platform, tlLoader, ssig.Convention); var sig = deser.Deserialize(ssig, new Frame(platform.FramePointerType)); var svc = new SystemService { ModuleName = moduleName.ToUpper(), Name = fnName, Signature = sig }; return(Tuple.Create(ordinal, svc)); } catch { Services.RequireService <DecompilerEventListener>().Warn( new NullCodeLocation(moduleName), "Line {0} in the Wine spec file could not be read; skipping.", lexer.lineNumber); SkipToEndOfLine(); return(null); } }
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 static string UnparseSignature(SerializedSignature sig, string procName) { StringBuilder sb = new StringBuilder(); if (sig.ReturnValue == null) sb.Append("void"); else sb.Append(sig.ReturnValue.Name); sb.Append(" "); sb.Append(procName); sb.Append("("); string sep = ""; foreach (var arg in sig.Arguments) { sb.Append(sep); sep = ", "; sb.Append(arg.Type); sb.Append(" "); sb.Append(arg.Name); } sb.Append(")"); return sb.ToString(); }
public void SvX86Ps_DeserializeFpuStackReturnValue() { var ssig = new SerializedSignature { ReturnValue = new Argument_v1 { Type = new PrimitiveType_v1(Domain.Real, 8), } }; Given_ProcedureSerializer(); mr.ReplayAll(); var sig = ser.Deserialize(ssig, arch.CreateFrame()); Assert.AreEqual( string.Format( "FpuStack real64 foo(){0}// stackDelta: 0; fpuStackDelta: 1; fpuMaxParam: -1{0}", nl), sig.ToString("foo", FunctionType.EmitFlags.AllDetails)); }
public EntryPoint CreateMainEntryPoint(bool isDll, Address addrEp, IPlatform platform) { string name = null; SerializedSignature ssig = null; Func <string, string, Argument_v1> Arg = (n, t) => new Argument_v1 { Name = n, Type = new TypeReference_v1 { TypeName = t } }; if (isDll) { name = "DllMain"; //$TODO: ensure users can override this name ssig = new SerializedSignature { Convention = "stdapi", Arguments = new Argument_v1[] { Arg("hModule", "HANDLE"), Arg("dwReason", "DWORD"), Arg("lpReserved", "LPVOID") }, ReturnValue = Arg(null, "BOOL") }; } else { name = "Win32CrtStartup"; ssig = new SerializedSignature { Convention = "__cdecl", ReturnValue = Arg(null, "DWORD") }; } return(new EntryPoint(addrEp, name, arch.CreateProcessorState(), ssig)); }
public void X86_64Psig_SmallStackArguments() { 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.Char8(), Name = "e" }, new Argument_v1 { Type = PrimitiveType_v1.Char8(), Name = "f" }, new Argument_v1 { Type = PrimitiveType_v1.Char8(), Name = "g" }, } }; var sig = pser.Deserialize(ssig, frame); Assert.AreEqual("rax", sig.ReturnValue.Storage.ToString()); ExpectArgs(sig, "rcx", "xmm1", "r8", "xmm3", "Stack +0008", "Stack +0010", "Stack +0018"); }
public ProcedureSignature Deserialize(SerializedSignature ss, Frame frame) { ArgumentSerializer argser = new ArgumentSerializer(this, arch, frame); Identifier ret = null; if (ss.ReturnValue != null) { ret = argser.Deserialize(ss.ReturnValue); } ArrayList args = new ArrayList(); if (ss.Arguments != null) { foreach (SerializedArgument arg in ss.Arguments) { args.Add(argser.Deserialize(arg)); } } ProcedureSignature sig = new ProcedureSignature( ret, (Identifier [])args.ToArray(typeof(Identifier))); ApplyConvention(ss, sig); return sig; }
private SerializedSignature BuildSsigStack() { SerializedSignature ssig = new SerializedSignature() { ReturnValue = new Argument_v1 { Type = new TypeReference_v1("int"), Kind = new Register_v1("ax") }, Arguments = new Argument_v1[] { new Argument_v1 { Name = "lParam", Kind = new StackVariable_v1(), Type = new PrimitiveType_v1(Domain.SignedInt, 4), }, new Argument_v1 { Kind = new StackVariable_v1(), Type = new PrimitiveType_v1(Domain.SignedInt, 2), } } }; return ssig; }
public void SsigDeserializeOutArgument() { Argument_v1 arg = new Argument_v1 { Kind = new Register_v1("bp"), OutParameter = true }; SerializedSignature sig = new SerializedSignature(); sig.Arguments = new Argument_v1[] { arg }; Given_X86ProcedureSerializer(); FunctionType ps = sser.Deserialize(sig, arch.CreateFrame()); Assert.AreEqual("void foo(Register out ptr16 bpOut)", ps.ToString("foo")); }