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, }); } } }
private bool TryParseSignature(string txtSignature, out Core.Serialization.Procedure_v1 sProc) { // save the user a keystroke. txtSignature = txtSignature + ";"; var lexer = new Core.CLanguage.CLexer(new StringReader(txtSignature)); var cstate = new Core.CLanguage.ParserState(); var cParser = new CParser(cstate, lexer); try { var decl = cParser.Parse_Decl(); sProc = null; if (decl == null) { return(false); } var syms = new SymbolTable(); syms.AddDeclaration(decl); if (syms.Procedures.Count != 1) { return(false); } sProc = (Core.Serialization.Procedure_v1)syms.Procedures[0]; return(true); } catch { sProc = null; return(false); } }
public void Convert() { var lexer = new CLexer(rdr); var parser = new CParser(parserState, lexer); var declarations = parser.Parse(); var symbolTable = new SymbolTable(platform) { NamedTypes = { { "size_t", new PrimitiveType_v1 { Domain = Domain.UnsignedInt, ByteSize = 4 } }, //$BUGBUG: arch-dependent! { "va_list", new PrimitiveType_v1 { Domain = Domain.Pointer, ByteSize = platform.PointerType.Size } } } }; foreach (var decl in declarations) { symbolTable.AddDeclaration(decl); } var lib = new SerializedLibrary { Types = symbolTable.Types.ToArray(), Procedures = symbolTable.Procedures.ToList(), }; var ser = SerializedLibrary.CreateSerializer(); ser.Serialize(writer, lib); }
public ProcedureSignature BuildSignature(string str, Frame frame) { try { var lexer = new CLexer(new StringReader(str + ";")); var cstate = new ParserState(); var cParser = new CParser(cstate, lexer); var decl = cParser.Parse_ExternalDecl(); var sSig = symbolTable.AddDeclaration(decl) .OfType <SerializedSignature>() .FirstOrDefault(); if (sSig == null) { return(null); } var ser = program.Platform.CreateProcedureSerializer(); return(ser.Deserialize(sSig, frame)); } catch (Exception ex) { Debug.Print("{0}\r\n{1}", ex.Message, ex.StackTrace); return(null); } }