public void SsigReadAxBxCl() { SerializedSignature ssig; var fsSvc = sc.RequireService <IFileSystemService>(); using (Stream stm = fsSvc.CreateFileStream(FileUnitTester.MapTestPath("Core/AxBxCl.xml"), FileMode.Open)) { XmlTextReader rdr = new XmlTextReader(stm); XmlSerializer ser = SerializedLibrary.CreateSerializer_v1(typeof(SerializedSignature)); ssig = (SerializedSignature)ser.Deserialize(rdr); } Given_X86ProcedureSerializer(); Assert.AreEqual("Register word16 AxBxCl(Register word16 bx, Register byte cl)", sser.Deserialize(ssig, arch.CreateFrame()).ToString("AxBxCl")); }
public void LoadProcedure(Procedure_v1 sp) { try { var sser = new ProcedureSerializer(platform, this, this.defaultConvention); var signature = sser.Deserialize(sp.Signature, platform.Architecture.CreateFrame()); library.Signatures[sp.Name] = signature; var mod = EnsureModule(this.moduleName, this.library); var svc = new SystemService { ModuleName = mod.ModuleName, Name = sp.Name, Signature = signature, }; mod.ServicesByName[sp.Name] = svc; //$BUGBUG: catch dupes? if (sp.Ordinal != Procedure_v1.NoOrdinal) { mod.ServicesByOrdinal[sp.Ordinal] = svc; } } catch (Exception ex) { Debug.Print("An error occurred when loading the signature of procedure {0}.", sp.Name); throw new ApplicationException( string.Format("An error occurred when loading the signature of procedure {0}.", sp.Name), ex); } }
private void OnMemoryMapChanged() { //var tlSvc = Services.RequireService<ITypeLibraryLoaderService>(); var tser = new TypeLibraryDeserializer(this, true, Metadata); var sser = new ProcedureSerializer(this, tser, DefaultCallingConvention); var disps = new Dictionary <Address, DispatchProcedure>(); foreach (var callable in this.MemoryMap.Segments.SelectMany(s => s.Procedures)) { if (callable is DispatchProcedure_v1 sDisp) { if (sDisp.Services == null) { continue; } var svcs = sDisp.Services .Where(s => s.SyscallInfo != null) .Select(s => ( s.SyscallInfo.Build(this), new ExternalProcedure( s.Name, sser.Deserialize(s.Signature, Architecture.CreateFrame())))) .ToList(); if (Architecture.TryParseAddress(sDisp.Address, out var addr)) { var disp = new DispatchProcedure( sDisp.Name, svcs); disps.Add(addr, disp); } } } this.dispatchProcedures = disps; }
private Dictionary <int, SystemService> LoadLibraryDef(string lib_name, int version, TypeLibrary libDst) { var tlSvc = Services.RequireService <ITypeLibraryLoaderService>(); var fsSvc = Services.RequireService <IFileSystemService>(); var tser = new TypeLibraryDeserializer(this, true, libDst); var sser = new ProcedureSerializer(this, tser, DefaultCallingConvention); using (var rdr = new StreamReader(fsSvc.CreateFileStream(tlSvc.InstalledFileLocation(lib_name + ".funcs"), FileMode.Open, FileAccess.Read))) { var fpp = new FuncsFileParser((M68kArchitecture)this.Architecture, rdr); fpp.Parse(); return(fpp.FunctionsByLibBaseOffset.Values .Select(amiSvc => new SystemService { Name = amiSvc.Name, SyscallInfo = new SyscallInfo { Vector = amiSvc.Offset, }, Signature = sser.Deserialize(amiSvc.Signature, Architecture.CreateFrame()), //$BUGBUG: catch dupes? Characteristics = new ProcedureCharacteristics { } }) .ToDictionary(de => de.SyscallInfo.Vector, de => de)); }; }
public void ProcessDeclaration(Decl declaration, IPlatform platform, TypeLibraryDeserializer tldser, SymbolTable symbolTable) { var types = symbolTable.AddDeclaration(declaration); var type = types[0]; int?vectorOffset = GetVectorOffset(declaration); if (vectorOffset.HasValue) { var ntde = new NamedDataTypeExtractor(platform, declaration.decl_specs, symbolTable, 4); foreach (var declarator in declaration.init_declarator_list) { var nt = ntde.GetNameAndType(declarator.Declarator); var ssig = (SerializedSignature?)nt.DataType; if (ssig != null && ssig.ReturnValue != null) { ssig.ReturnValue.Kind = ntde.GetArgumentKindFromAttributes( "returns", declaration.attribute_list); } var sser = new ProcedureSerializer(platform, tldser, platform.DefaultCallingConvention); var sig = sser.Deserialize(ssig, platform.Architecture.CreateFrame()); SystemServices.Add( vectorOffset.Value, new SystemService { Name = nt.Name, SyscallInfo = new SyscallInfo { Vector = vectorOffset.Value, }, Signature = sig, }); } } }
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 ExternalProcedure LoadExternalProcedure(ProcedureBase_v1 sProc) { var sSig = sProc.Signature; var sser = new ProcedureSerializer(platform, this, this.defaultConvention); var sig = sser.Deserialize(sSig, platform.Architecture.CreateFrame()); //$BUGBUG: catch dupes? return(new ExternalProcedure(sProc.Name, sig) { EnclosingType = sSig.EnclosingType }); }
public void LoadProcedure(Procedure_v1 sp) { try { var sser = new ProcedureSerializer(platform, this, this.defaultConvention ?? ""); var signature = sser.Deserialize(sp.Signature, platform.Architecture.CreateFrame()); if (sp.Name is null || signature is null) { return; } library.Signatures[sp.Name !] = signature;
public void LoadProcedure(Procedure_v1 sp) { try { if (sp.Name is null) { return; } if (sp.Characteristics != null) { library.Characteristics[sp.Name] = sp.Characteristics; } var sser = new ProcedureSerializer(platform, this, this.defaultConvention ?? ""); var signature = sser.Deserialize(sp.Signature, platform.Architecture.CreateFrame()); if (signature is null) { return; } library.Signatures[sp.Name] = signature; if (platform.TryParseAddress(sp.Address, out var addr)) { this.library.Procedures[addr] = (sp.Name, signature); } else { var mod = EnsureModule(this.moduleName, this.library); var svc = new SystemService { ModuleName = mod.ModuleName, Name = sp.Name, Signature = signature, }; mod.ServicesByName[sp.Name] = svc; //$BUGBUG: catch dupes? if (sp.Ordinal != Procedure_v1.NoOrdinal) { mod.ServicesByOrdinal[sp.Ordinal] = svc; } } } catch (Exception ex) { Debug.Print("An error occurred when loading the signature of procedure {0}.", sp.Name); throw new ApplicationException( string.Format("An error occurred when loading the signature of procedure {0}.", sp.Name), ex); } }
public ExternalProcedure?LoadExternalProcedure( ProcedureBase_v1 sProc, ProcedureCharacteristics?chr = null) { if (sProc.Name is null) { return(null); } var sSig = sProc.Signature; var sser = new ProcedureSerializer(platform, this, this.defaultConvention ?? ""); var sig = sser.Deserialize(sSig, platform.Architecture.CreateFrame()); //$BUGBUG: catch dupes? if (sig is null) { return(null); } return(new ExternalProcedure(sProc.Name, sig, chr) { EnclosingType = sSig?.EnclosingType }); }
public void X86ps_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(4, sig.StackDelta); Assert.AreEqual("Register int test(FpuStack real64 fpArg0)", sig.ToString("test")); }
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); } }
private Dictionary <Address, ExternalProcedure> LoadPlatformProcedures(Platform platform) { if (platform.MemoryMap != null && platform.MemoryMap.Segments != null) { platform.EnsureTypeLibraries(platform.Name); var tser = new TypeLibraryDeserializer(platform, true, platform.Metadata); var sser = new ProcedureSerializer(platform, tser, platform.DefaultCallingConvention); return(platform.MemoryMap.Segments.SelectMany(s => s.Procedures) .OfType <Procedure_v1>() .Where(p => p.Name != null) .Select(p => (addr: platform.Architecture.TryParseAddress(p.Address, out var addr) ? addr : null, ext: new ExternalProcedure( p.Name !, sser.Deserialize(p.Signature, platform.Architecture.CreateFrame()) ?? new Types.FunctionType()))) .Where(p => p.addr != null) .ToDictionary(p => p.addr !, p => p.ext)); } else { return(new Dictionary <Address, ExternalProcedure>()); } }
public DataType VisitSignature(SerializedSignature sSig) { var sser = new ProcedureSerializer(platform, this, this.defaultConvention); return(sser.Deserialize(sSig, platform.Architecture.CreateFrame())); }