]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 6 Feb 2025 16:13:51 +0000 (17:13 +0100)
committerRoland Häder <roland@mxchange.org>
Thu, 6 Feb 2025 16:13:51 +0000 (17:13 +0100)
- added new command 'check_obfuscations'

fba/boot.py
fba/commands.py

index 891978ce15236b57b85915d2cb83f1a4c1760d86..d8f290a847b5906429120bda32a35c71c67a20c3 100644 (file)
@@ -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:
index b2aac60e22b7277703103d6bc13f1b6077c8ef97..3aee14cd0ae514676c7c0f2511fba499d31e542a 100644 (file)
@@ -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