From: Roland Häder Date: Thu, 6 Feb 2025 16:13:51 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=055ce950016a6f9fb16d3a5e4a605b445193c318;p=fba.git Continued: - added new command 'check_obfuscations' --- diff --git a/fba/boot.py b/fba/boot.py index 891978c..d8f290a 100644 --- a/fba/boot.py +++ b/fba/boot.py @@ -276,6 +276,13 @@ def init_parser() -> None: ) parser.set_defaults(command=commands.remove_invalid) + ### Check obfuscations ### + parser = subparser_command.add_parser( + "check_obfuscations", + help="Checks obfuscation patterns if they are already solved (should not happen).", + ) + parser.set_defaults(command=commands.check_obfuscations) + logger.debug("EXIT!") def run_command() -> None: diff --git a/fba/commands.py b/fba/commands.py index b2aac60..3aee14c 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -2042,3 +2042,40 @@ def remove_invalid(args: argparse.Namespace) -> int: logger.debug("Success! - EXIT!") return 0 + +def check_obfuscations(args: argparse.Namespace) -> int: + logger.debug("args[]='%s' - CALLED!", type(args)) + + logger.debug("Invoking locking.acquire() ...") + locking.acquire() + + # Init variables + deleted = 0 + + database.cursor.execute("SELECT pattern FROM obfuscation ORDER BY pattern ASC") + rows = database.cursor.fetchall() + + logger.info("Checking %d obfuscations ...", len(rows)) + for row in rows: + logger.debug("row[pattern]='%s'", row["pattern"]) + pattern = row["pattern"].replace("*", "_").replace("?", "_") + + database.cursor.execute("SELECT domain FROM instances WHERE domain LIKE '" + pattern + "' LIMIT 1") + check = database.cursor.fetchone() + + logger.debug("check[]='%s'", type(check)) + if check is not None: + logger.info("Deleting row[pattern]='%s', solved to check[domain]='%s' ...", row["pattern"], check["domain"]) + database.cursor.execute("DELETE FROM instances WHERE domain=? LIMIT 1", [row["pattern"]]) + deleted = deleted + 1 + + logger.info("Deleted %d patterns ...", deleted) + + logger.debug("Invoking commit() ...") + database.connection.commit() + + logger.debug("Vaccum cleaning database ...") + database.cursor.execute("VACUUM") + + logger.debug("Success! - EXIT!") + return 0