def doJobs(db_name): global db2 db2 = DBConnectManager().get_connection(db_name) global cursor cursor = db2.cursor() cursor.execute('select database();') print cursor.fetchone()[0] print (db2)
def display_PACKAGES(a, x, classes): # Open database connection db_connection = DBConnectManager().get_connection(AnalysisInitDefaultValue.APP_NAME) if db_connection is not None: # prepare a cursor object using cursor() method cursor = db_connection.cursor() # choose database working with db_helper.useDB(cursor, app_name.upper()) print "CREATED PACKAGES" for m, _ in x.get_tainted_packages().get_packages(): m.show(cursor, db_connection)
def createDatabase(db_name='test'): # Open database connection db_connection = DBConnectManager().get_connection() if db_connection is not None: # prepare a cursor object using cursor() method cursor = db_connection.cursor() print "CREATED DATABASE ", db_name # create new database with name is app name db_helper.createNewDB(cursor, db_name) db_helper.useDB(cursor, db_name) # create tables in the database just has created create_tables(cursor, db_connection)
def write_app_info_to_file(self, appName, file_obj): db_connector = DBConnectManager().get_connection(appName.upper()); if db_connector is not None: try: select_stmt = "SELECT * FROM app_info" cursor = db_connector.cursor() cursor.execute(select_stmt) app_info = cursor.fetchone() print app_info file_obj.write("\t" + "App name: " + app_info[1] +"\n") file_obj.write("\t" + "Package: " + app_info[2] +"\n") file_obj.write("\t" + "App version code: " + app_info[3] +"\n") file_obj.write("\t" + "Appwrite_app_activities_to_file version name: " + app_info[4] +"\n") file_obj.write("\t" + "Android Target: " + app_info[5] +"\n") except Exception as e: print e
def display_PackageFilter_Activity(activities): # get database connection from DBConnectionManager db_connection = DBConnectManager().get_connection(analysis_init_default_value.APP_NAME) packages_filter = [] if activities: packages_filter = dataUtils.get_PackageFilter_Activity(db_connection, activities) else: print "Must at least one activity to filter package!" if packages_filter: print "List package filter found with activities provided" cursor = db_connection.cursor() for pkg_ac in packages_filter: print pkg_ac; ## write it to db #add packages filter by activity to table PACKAGE_FILTER_ACTIVITY try: # Execute the SQL command cursor.execute("""INSERT INTO PACKAGE_FILTER_ACTIVITY (package_id,dstClass, dstMethod, dstMethodDes, srcClass, srcMethod, srcMethodDes) VALUES (%s,%s,%s,%s,%s,%s,%s)""", pkg_ac) # Commit your changes in the database db_connection.commit() except MySQLdb.Error, e: # Rollback in call print "MySQL Error [%d]: %s" % (e.args[0], e.args[1]) print "MySQL Roll back..." db_connection.rollback()
def dispaly_sensitive_apis(table): # get database connection from DBConnectionManager db_connection = DBConnectManager().get_connection(analysis_init_default_value.APP_NAME) # filter sensitive apis from table SENSITIVE_APIs_FromDB = dataUtils.get_SensitiveAPIs(db_connection, table) if SENSITIVE_APIs_FromDB: cursor = db_connection.cursor() print "-------SENSITIVE_APIs_FromDB-------------" for s_apis in SENSITIVE_APIs_FromDB: print s_apis # insert this sensitive api to db try: # Execute the SQL command cursor.execute("""INSERT INTO SENSITIVE_APIS (package_id,dstClass, dstMethod, dstMethodDes, srcClass, srcMethod, srcMethodDes) VALUES (%s,%s,%s,%s,%s,%s,%s)""", s_apis) # Commit your changes in the database db_connection.commit() except MySQLdb.Error, e: # Rollback in call print "MySQL Error [%d]: %s" % (e.args[0], e.args[1]) print "MySQL Roll back..." db_connection.rollback()
def display_PERMISSION(a, x, classes): # get database connection from DBConnectionManager db_connection = DBConnectManager().get_connection(analysis_init_default_value.APP_NAME) if db_connection is not None: cursor = db_connection.cursor() # Show methods used by permission perms_access = x.get_tainted_packages().get_permissions( [] ) for perm in perms_access: #add perm to table PERMISSIONS try: # Execute the SQL command cursor.execute("""INSERT INTO PERMISSIONS (permission_name, permission_des) VALUES (%s,%s)""", (perm, '')) # Commit your changes in the database db_connection.commit() except MySQLdb.Error, e: # Rollback in call print "MySQL Error [%d]: %s" % (e.args[0], e.args[1]) print "MySQL Roll back..." db_connection.rollback() print "PERM : ", perm analysis.show_Paths( a, perms_access[ perm ], analysis_init_default_value.A_PERMISSION, perms_access.keys().index(perm) + 1)
from database.DBConnectManager import DBConnectManager __author__ = 'congthuc' db1 = DBConnectManager().get_connection('A4T') cursor = db1.cursor() cursor.execute('select database();') print cursor.fetchone()[0] print (db1) db1 = DBConnectManager().get_connection() cursor = db1.cursor() cursor.execute('select database();') print cursor.fetchone()[0] print (db1) DBConnectManager().close_connect()