Esempio n. 1
0
def getVisibleNodes(projectName):
    db = DBInterface()
    db.connectToDatabase(projectName)

    visibleStatementTypes = [
        'CustomNode', 'ClassDef', 'DeclByClass', 'DeclByType', 'FunctionDef',
        'CompoundStatement', 'Statement', 'DeclStmt', 'StructUnionEnum',
        'FunctionPointerDeclare', 'TryStatement', 'CatchStatement',
        'IfStatement', 'ElseStatement', 'SwitchStatement', 'ForStatement',
        'DoStatement', 'WhileStatement', 'BreakStatement', 'ContinueStatement',
        'GotoStatement', 'Label', 'ReturnStatement', 'ThrowStatement',
        'ExpressionStatement', 'IdentifierDeclStatement', 'PreIfStatement',
        'PreElIfStatement', 'PreElseStatement', 'PreEndIfStatement',
        'PreDefine', 'PreUndef', 'PreDiagnostic', 'PreOther', 'PreInclude',
        'PreIncludeNext', 'PreLine', 'PrePragma', 'UsingDirective',
        'BlockCloser', 'Comment', 'File', 'Directory'
    ]

    # Remove unneeded nodes (we need to exclude IdentifierDeclStatement that have a ForInit or StructUnionEnum as parent)
    query = """g.V().has('type', within(%s))
                .not(__.repeat(__.in(AST_EDGE)).emit().has('type', within('ForInit','StructUnionEnum')))
                .id()""" % (visibleStatementTypes)
    result = db.runGremlinQuery(query)

    # Finally close db connection and release the shell
    db.runGremlinQuery("quit")

    return result
Esempio n. 2
0
    def _runImpl(self):
        query = self._constructQuery()

        self.dbInterface = DBInterface()
        self.dbInterface.connectToDatabase()

        res = self.dbInterface.runGremlinQuery(query)
        self._handleResult(res)
Esempio n. 3
0
def initialize():
    # Get the ids from the SemanticUnit (first line is the projectName)
    idList = [line.rstrip('\n') for line in open('result.txt')]

    # Connect to project DB
    projectName = idList.pop(0)
    db = DBInterface()
    db.connectToDatabase(projectName)

    return [db, idList]
Esempio n. 4
0
    def _runImpl(self):
        
        self.dbInterface = DBInterface()
        self.dbInterface.connectToDatabase()

        self._start()

        query = self._constructIdQuery()
        ids = self.dbInterface.runGremlinQuery(query)
        
        for chunk in self.dbInterface.chunks(ids, CHUNK_SIZE):
            query = self._constructQueryForChunk(chunk)
            res = self.dbInterface.runGremlinQuery(query)
            self._handleChunkResult(res, chunk)

        self._stop()
Esempio n. 5
0
    def run(self):
        if self.args.file != None:
            f = open(self.args.file, "r")
        else:
            f = sys.stdin
        lines = __class__._parseScript(f)
        query = "\n".join(lines)
        db = DBInterface()
        if self.args.no_json:
            db.disable_json()
        db.connectToDatabase(self.args.project)

        result = db.runGremlinQuery(query)
        pp = pprint.PrettyPrinter(indent=4, compact=True)
        for x in result:
            if self.args.raw:
                print(repr(x))
            elif self.args.pretty:
                pp.pprint(x)
            else:
                print(x)
        db.runGremlinQuery("quit")
Esempio n. 6
0
#File -> #PreDefine -> PreMacroIdentifier -> Identifier
#File -> Function -IS_FUNCTION_OF_AST-> #FunctionDef -> Identifier
#File -> #StructUnionEnum -> Identifier
#File -> #DeclStatement -Declares-> Decl (first word is the identifier?)

# List of all types that can use identifiers to do something (sorted by declarations)
#Function: FunctionDef and CallExpression (need parent ExpressionStatement). Declares.
#Macro: MacroDef and Callee or enywhere where we can identify a preMacroIdentifer?
#Declares: ?
#Enum:?

prefix = "semanticUnit__"

print("Adding prefixes...")
# Connect to SU projectfile:///C:/Users/Lea/git/Joern_Advanced/testProjects/Collection/Plot.png
db = DBInterface()
db.connectToDatabase("EvoDiss.tar.gz")

# Get the names of all functions
query = """g.V().has('type', 'FunctionDef').out('IS_AST_PARENT').has('type', 'Identifier').values('code').as('function')"""
functions = db.runGremlinQuery(query)

# Get the names of all macros
query = """g.V().has('type', 'PreDefine').out('IS_AST_PARENT').has('type','PreMacroIdentifier').values('code').as('macro')"""
macros = db.runGremlinQuery(query)

# Get the names of all declarations that can be declared on file scope
query = """g.V().has('type', 'DeclStmt').out('DECLARES').has('type', 'Decl').values('identifier').as('declaration')"""
declarations = db.runGremlinQuery(query)

# Get the names of all StructUnionEnums
Esempio n. 7
0
 def _initializeDBConnection(self):
     self.dbInterface = DBInterface()
Esempio n. 8
0
 def streamStart(self):
     self.dbInterface = DBInterface()
     self.dbInterface.connectToDatabase(self.args.project)