def main(): if len(sys.argv) == 1: fil = "/usr/lib64/libxerces-c-3.1.so" else: fil = sys.argv[1] readelf = lib_elf.ReadElf(fil) listNotes = readelf.display_notes() for pr in listNotes: sys.stdout.write("%s %s\n" % pr ) sys.stdout.write("\n") listSyms, setClasses = readelf.display_symbol_tables() setMoreClasses = lib_elf.GetClassesFromCTorDTor(listSyms) unionClasses = setClasses.union( setMoreClasses ) # setNamespaces = GetNamespacesHeuristics( unionClasses ) # PROBLEM: What is the difference between a namespace # and a non-virtual class with static methods and members only ??? # ALSO: The symbol name gives no information about the return type # and the object parameter whose presence would indicate with certainty # a class as opposed to a namespace. for sm in listSyms: sys.stdout.write("%s\n" % sm.m_name ) sys.stdout.write("%s\n" % str(sm) ) sys.stdout.write("\n")
def Main(): cgiEnv = lib_common.ScriptEnvironment() file_shared_lib = cgiEnv.GetId() grph = cgiEnv.GetGraph() node_shared_lib = lib_uris.gUriGen.FileUri(file_shared_lib) try: readelf = lib_elf.ReadElf(file_shared_lib) except Exception as exc: lib_common.ErrorMessageHtml("Caught:" + str(exc)) list_notes = readelf.display_notes() for pr in list_notes: infoMsg = pr[0] + ":" + pr[1] grph.add((node_shared_lib, pc.property_information, lib_util.NodeLiteral(infoMsg))) list_syms, set_classes = readelf.display_symbol_tables() Main.nodesByClass = dict() def class_to_node(class_split, idx): cls_nam = "::".join(class_split[:idx]) try: node_class = Main.nodesByClass[cls_nam] except KeyError: node_class = lib_uris.gUriGen.ClassUri(cls_nam, file_shared_lib) # TODO: Create base classes ? Main.nodesByClass[cls_nam] = node_class if idx > 1: node_base_class = class_to_node(class_split, idx - 1) grph.add((node_base_class, pc.property_member, node_class)) else: grph.add((node_shared_lib, pc.property_member, node_class)) return node_class cnt = 0 for sym in list_syms: cnt += 1 # TODO: How to process big libraries ? # TODO: Maybe group by symbols. if cnt > 500: logging.error("Exceeded number of symbols") break if not sym.m_splt[0].startswith("std"): continue sym_nod = lib_uris.gUriGen.SymbolUri(sym.m_name_demang, file_shared_lib) grph.add((sym_nod, lib_common.MakeProp("Version"), lib_util.NodeLiteral(sym.m_vers))) len_split = len(sym.m_splt) if len_split > 1: cls_nod = class_to_node(sym.m_splt, len_split - 1) grph.add((cls_nod, pc.property_symbol_defined, sym_nod)) else: grph.add((node_shared_lib, pc.property_symbol_defined, sym_nod)) # TODO: Fix this when adding pc.property_member cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_symbol_defined])
def Main(): cgiEnv = lib_common.CgiEnv() fileSharedLib = cgiEnv.GetId() grph = cgiEnv.GetGraph() nodeSharedLib = lib_common.gUriGen.FileUri(fileSharedLib) try: readelf = lib_elf.ReadElf(fileSharedLib) except Exception: exc = sys.exc_info()[1] lib_common.ErrorMessageHtml("Caught:" + str(exc)) listNotes = readelf.display_notes() for pr in listNotes: infoMsg = pr[0] + ":" + pr[1] grph.add((nodeSharedLib, pc.property_information, lib_common.NodeLiteral(infoMsg))) listSyms, setClasses = readelf.display_symbol_tables() Main.nodesByClass = dict() def ClassToNode(classSplit, idx): clsNam = "::".join(classSplit[:idx]) try: nodeClass = Main.nodesByClass[clsNam] except KeyError: nodeClass = lib_common.gUriGen.ClassUri(clsNam, fileSharedLib) # TODO: Create base classes ? Main.nodesByClass[clsNam] = nodeClass if idx > 1: nodeBaseClass = ClassToNode(classSplit, idx - 1) grph.add((nodeBaseClass, pc.property_member, nodeClass)) else: grph.add((nodeSharedLib, pc.property_member, nodeClass)) return nodeClass cnt = 0 for sym in listSyms: cnt += 1 # TODO: Beaucoup de mal a parser de grandes librairies. # On va essayer de decouper par niveaux, en creant un nouveau script. # On affiche le premier niveau exclusivement, et on cree des liens vers # les classes (ou les namespaces) en mentionnant toujours le fichier. if cnt > 500: break if not sym.m_splt[0].startswith("std"): continue symNod = lib_common.gUriGen.SymbolUri(sym.m_name_demang, fileSharedLib) grph.add((symNod, lib_common.MakeProp("Version"), lib_common.NodeLiteral(sym.m_vers))) lenSplit = len(sym.m_splt) if lenSplit > 1: clsNod = ClassToNode(sym.m_splt, lenSplit - 1) grph.add((clsNod, pc.property_symbol_defined, symNod)) else: grph.add((nodeSharedLib, pc.property_symbol_defined, symNod)) # TODO: Fix this when adding pc.property_member # cgiEnv.OutCgiRdf("LAYOUT_RECT",[ pc.property_symbol_defined, pc.property_member ] ) cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_symbol_defined])
def Main(): paramkeyMaxDepth = "Maximum depth" cgiEnv = lib_common.CgiEnv( parameters = { paramkeyMaxDepth : 1 }) maxDepth = int(cgiEnv.GetParameters( paramkeyMaxDepth )) fileSharedLib = cgiEnv.GetId() grph = cgiEnv.GetGraph() nodeSharedLib = lib_common.gUriGen.FileUri( fileSharedLib ) nodeGlobalNamespace = lib_common.gUriGen.ClassUri( "__global_namespace", fileSharedLib ) grph.add( ( nodeSharedLib, pc.property_member, nodeGlobalNamespace ) ) try: readelf = lib_elf.ReadElf(fileSharedLib) except Exception: exc = sys.exc_info()[1] lib_common.ErrorMessageHtml("Caught:"+str(exc)) listNotes = readelf.display_notes() for pr in listNotes: infoMsg = pr[0] + ":" + pr[1] grph.add( ( nodeSharedLib, pc.property_information, lib_common.NodeLiteral(infoMsg) ) ) listSyms, setClasses = readelf.display_symbol_tables() Main.nodesByClass = dict() def ClassToNode( classSplit, idx ): clsNam = "::".join( classSplit[ : idx ] ) try: nodeClass = Main.nodesByClass[clsNam] except KeyError: nodeClass = lib_common.gUriGen.ClassUri( clsNam, fileSharedLib ) # TODO: Create base classes ? Main.nodesByClass[clsNam] = nodeClass if idx > 1: nodeBaseClass = ClassToNode( classSplit, idx - 1 ) grph.add( ( nodeBaseClass, pc.property_member, nodeClass ) ) else: grph.add( ( nodeSharedLib, pc.property_member, nodeClass ) ) return nodeClass classAlreadyDone = set() for sym in listSyms: lenSplit = len(sym.m_splt) if lenSplit > maxDepth: spltShort = sym.m_splt[:maxDepth] # TODO: Do the join only once. joinShort = "::".join(spltShort) # TODO: Should test and insert in one lookup only. if joinShort in classAlreadyDone: continue classAlreadyDone.add( joinShort ) # So it cannot be a symbol but a class or a namespace. clsNod = ClassToNode( spltShort, maxDepth ) # It is already linked to its ancestors. else: spltShort = sym.m_splt # symNod = lib_common.gUriGen.SymbolUri( lib_util.EncodeUri(sym.m_name), fileSharedLib ) symNod = lib_common.gUriGen.SymbolUri( sym.m_name_demang, fileSharedLib ) grph.add( ( symNod, lib_common.MakeProp("Version"), lib_common.NodeLiteral(sym.m_vers) ) ) if lenSplit > 1: clsNod = ClassToNode( sym.m_splt, lenSplit - 1 ) grph.add( ( clsNod, pc.property_symbol_defined, symNod ) ) else: grph.add( ( nodeGlobalNamespace, pc.property_symbol_defined, symNod ) ) cgiEnv.OutCgiRdf("LAYOUT_RECT",[ pc.property_symbol_defined, pc.property_member ] )
def Main(): paramkey_max_depth = "Maximum depth" cgiEnv = lib_common.ScriptEnvironment(parameters={paramkey_max_depth: 2}) max_depth = int(cgiEnv.get_parameters(paramkey_max_depth)) name_top_class = cgiEnv.m_entity_id_dict["Name"] # An executable, shared library. Maybe static library. file_name = cgiEnv.m_entity_id_dict["File"] grph = cgiEnv.GetGraph() # This expects that the string is not a symbol name but a class or a namespace. # Otherwise we would have scan the list of symbols, to find out. node_shared_lib = lib_uris.gUriGen.FileUri(file_name) try: readelf = lib_elf.ReadElf(file_name) except Exception as exc: lib_common.ErrorMessageHtml("Caught:" + str(exc)) list_notes = readelf.display_notes() for pr in list_notes: info_msg = pr[0] + ":" + pr[1] grph.add((node_shared_lib, pc.property_information, lib_util.NodeLiteral(info_msg))) # TODO: List of classes is not needed. # TODO: Just read the symbols we need. list_syms, set_classes = readelf.display_symbol_tables() Main.nodesByClass = dict() def class_to_node(classSplit, idx): cls_nam = "::".join(classSplit[:idx]) try: node_class = Main.nodesByClass[cls_nam] except KeyError: node_class = lib_uris.gUriGen.ClassUri(cls_nam, file_name) # TODO: Create base classes ? Main.nodesByClass[cls_nam] = node_class if idx > 1: node_base_class = class_to_node(classSplit, idx - 1) grph.add((node_base_class, pc.property_member, node_class)) else: grph.add((node_shared_lib, pc.property_member, node_class)) return node_class class_already_done = set() class_prefix = name_top_class + "::" len_prefix = len(name_top_class.split("::")) max_depth_total = max_depth + len_prefix for sym in list_syms: if not sym.m_name.startswith(class_prefix): continue len_split = len(sym.m_splt) if len_split > max_depth_total: splt_short = sym.m_splt[:max_depth] # TODO: Do the join only once. join_short = "::".join(splt_short) # TODO: Should test and insert in one lookup only. if join_short in class_already_done: continue class_already_done.add(join_short) # So it cannot be a symbol but a class or a namespace. cls_nod = class_to_node(splt_short, max_depth) # It is already linked to its ancestors. else: splt_short = sym.m_splt sym_nod = lib_uris.gUriGen.SymbolUri(sym.m_name, file_name) grph.add((sym_nod, lib_common.MakeProp("Version"), lib_util.NodeLiteral(sym.m_vers))) if len_split > 1: cls_nod = class_to_node(sym.m_splt, len_split - 1) grph.add((cls_nod, pc.property_symbol_defined, sym_nod)) else: node_global_namespace = lib_uris.gUriGen.ClassUri( "__global_namespace", file_name) grph.add((node_global_namespace, pc.property_symbol_defined, sym_nod)) # TODO: Fix or check this when adding pc.property_member cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_symbol_defined, pc.property_member])
def Main(): paramkeyMaxDepth = "Maximum depth" cgiEnv = lib_common.CgiEnv(parameters={paramkeyMaxDepth: 2}) maxDepth = int(cgiEnv.GetParameters(paramkeyMaxDepth)) nameTopClass = cgiEnv.m_entity_id_dict["Name"] # An executable, shared library. Maybe static library. fileName = cgiEnv.m_entity_id_dict["File"] grph = cgiEnv.GetGraph() # This expects that the string is not a symbol name but a class or a namespace. # Otherwise we would have scan the list of symbols, to find out. # nodeTopClass = lib_common.gUriGen.ClassUri( nameTopClass, fileSharedLib ) nodeSharedLib = lib_common.gUriGen.FileUri(fileName) try: readelf = lib_elf.ReadElf(fileName) except Exception: exc = sys.exc_info()[1] lib_common.ErrorMessageHtml("Caught:" + str(exc)) listNotes = readelf.display_notes() for pr in listNotes: infoMsg = pr[0] + ":" + pr[1] grph.add((nodeSharedLib, pc.property_information, lib_common.NodeLiteral(infoMsg))) # TODO: List of classes is not needed. # TODO: Just read the symbols we need. listSyms, setClasses = readelf.display_symbol_tables() Main.nodesByClass = dict() def ClassToNode(classSplit, idx): clsNam = "::".join(classSplit[:idx]) try: nodeClass = Main.nodesByClass[clsNam] except KeyError: nodeClass = lib_common.gUriGen.ClassUri(clsNam, fileName) # TODO: Create base classes ? Main.nodesByClass[clsNam] = nodeClass if idx > 1: nodeBaseClass = ClassToNode(classSplit, idx - 1) grph.add((nodeBaseClass, pc.property_member, nodeClass)) else: grph.add((nodeSharedLib, pc.property_member, nodeClass)) return nodeClass classAlreadyDone = set() classPrefix = nameTopClass + "::" lenPrefix = len(nameTopClass.split("::")) maxDepthTotal = maxDepth + lenPrefix # sys.stderr.write("top=%s\n" % nameTopClass) for sym in listSyms: # symName = "::".join(sym.m_splt) if not sym.m_name.startswith(classPrefix): continue # sys.stderr.write("name=%s\n" % sym.m_name) lenSplit = len(sym.m_splt) if lenSplit > maxDepthTotal: spltShort = sym.m_splt[:maxDepth] # TODO: Do the join only once. joinShort = "::".join(spltShort) # TODO: Should test and insert in one lookup only. if joinShort in classAlreadyDone: continue classAlreadyDone.add(joinShort) # So it cannot be a symbol but a class or a namespace. clsNod = ClassToNode(spltShort, maxDepth) # It is already linked to its ancestors. else: spltShort = sym.m_splt # symNam = sym.m_splt[-1] # symNod = lib_common.gUriGen.SymbolUri( lib_util.EncodeUri(symNam), fileName ) symNod = lib_common.gUriGen.SymbolUri(sym.m_name, fileName) grph.add((symNod, lib_common.MakeProp("Version"), lib_common.NodeLiteral(sym.m_vers))) if lenSplit > 1: clsNod = ClassToNode(sym.m_splt, lenSplit - 1) grph.add((clsNod, pc.property_symbol_defined, symNod)) else: grph.add( (nodeGlobalNamespace, pc.property_symbol_defined, symNod)) # TODO: Fix or check this when adding pc.property_member cgiEnv.OutCgiRdf("LAYOUT_RECT", [pc.property_symbol_defined, pc.property_member])