Skip to content

Commit

Permalink
Reworking logger to fix the weird error where it dupes logs - p4
Browse files Browse the repository at this point in the history
  • Loading branch information
DefinetlyNotAI committed Sep 24, 2024
1 parent a59c0e0 commit 0fe1b6c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 52 deletions.
27 changes: 18 additions & 9 deletions CODE/Logicytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,18 @@ def special_run(file_path: str):

log.debug(execution_list)

# Check weather to use threading or not
# Check weather to use threading or not, as well as execute code
if action == "threaded":
def threaded_execution(execution_list_thread, index_thread):
thread_log = Execute(log_variable=log).file(execution_list_thread, index_thread)
if thread_log[0]:
log.info(thread_log[0])
log.info(thread_log[1])
try:
thread_log = Execute().file(execution_list_thread, index_thread)
if thread_log[0]:
log.info(thread_log[0])
log.info(thread_log[1])
except UnicodeDecodeError as err:
log.error(f"Error in thread: {err}")
except Exception as err:
log.error(f"Error in thread: {err}")
threads = []
for index, file in enumerate(execution_list):
thread = threading.Thread(
Expand All @@ -188,9 +193,14 @@ def threaded_execution(execution_list_thread, index_thread):
for thread in threads:
thread.join()
else:
for file in range(len(execution_list)): # Loop through List
log.info(Execute(log_variable=log).execute_script(execution_list[file]))
log.info(f"{execution_list[file]} executed")
try:
for file in range(len(execution_list)): # Loop through List
log.info(Execute().execute_script(execution_list[file]))
log.info(f"{execution_list[file]} executed")
except UnicodeDecodeError as e:
log.error(f"Error in thread: {e}")
except Exception as e:
log.error(f"Error in thread: {e}")

# Zip generated files
if action == "modded":
Expand Down Expand Up @@ -230,5 +240,4 @@ def threaded_execution(execution_list_thread, index_thread):

log.info("Exiting...")
input("Press Enter to exit...")
# Special feature that allows to create a `-` line only
log.debug("*-*")
50 changes: 19 additions & 31 deletions CODE/__lib_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def uac(self) -> bool:
return int(value.strip("\n")) == 1

@staticmethod
def sys_internal_zip() -> str:
def sys_internal_zip():
"""
Extracts the SysInternal_Suite zip file if it exists and is not ignored.
Expand All @@ -371,26 +371,18 @@ def sys_internal_zip() -> str:
"SysInternal_Suite/SysInternal_Suite.zip"
) as zip_ref:
zip_ref.extractall("SysInternal_Suite")
return "SysInternal_Suite zip extracted"
if __name__ == "__main__":
Log(debug=DEBUG).debug("SysInternal_Suite zip extracted")

elif ignore_file:
return (
"Found .sys.ignore file, skipping SysInternal_Suite zip extraction"
)
if __name__ == "__main__":
Log(debug=DEBUG).debug("Found .sys.ignore file, skipping SysInternal_Suite zip extraction")

except Exception as err:
exit(f"Failed to unzip SysInternal_Suite: {err}")


class Execute:
def __init__(self, log_variable=None):
"""
Initializes an instance of the class.
Sets the Actions attribute to an instance of the Actions class.
"""
self.log_variable = log_variable

@staticmethod
def get_files(directory: str, file_list: list) -> list:
"""
Expand All @@ -410,7 +402,7 @@ def get_files(directory: str, file_list: list) -> list:
file_list.append(filename)
return file_list

def file(self, execution_list: list, Index: int) -> tuple[str, str]:
def file(self, execution_list: list, Index: int):
# IT IS USED, DO NOT REMOVE
"""
Executes a file from the execution list at the specified index.
Expand All @@ -420,31 +412,26 @@ def file(self, execution_list: list, Index: int) -> tuple[str, str]:
Returns:
None
"""
log_message = self.execute_script(execution_list[Index])
return log_message, f"{execution_list[Index]} executed"
self.execute_script(execution_list[Index])
if __name__ == "__main__":
Log().info(f"{execution_list[Index]} executed")

def execute_script(self, script: str, logvar=None) -> str:
def execute_script(self, script: str):
"""
Executes a script file and handles its output based on the file extension.
Parameters:
script (str): The path of the script file to be executed.
logvar (Log): The log variable to use for logging.
Returns:
None
"""
if logvar is None:
logvar = self.log_variable
if script.endswith(".ps1"):
log_message = self.__unblock_ps1_script(script)
self.__run_other_script(script, logvar)
self.__unblock_ps1_script(script)
self.__run_other_script(script)
elif script.endswith(".py"):
self.__run_python_script(script)
else:
self.__run_other_script(script, logvar)
return log_message
self.__run_other_script(script)

@staticmethod
def __unblock_ps1_script(script: str) -> str:
def __unblock_ps1_script(script: str):
"""
Unblocks and runs a PowerShell (.ps1) script.
Parameters:
Expand All @@ -455,7 +442,8 @@ def __unblock_ps1_script(script: str) -> str:
try:
unblock_command = f'powershell.exe -Command "Unblock-File -Path {script}"'
subprocess.run(unblock_command, shell=False, check=True)
return "PS1 Script unblocked."
if __name__ == "__main__":
Log().info("PS1 Script unblocked.")
except Exception as err:
exit(f"Failed to unblock script: {err}")

Expand All @@ -475,7 +463,7 @@ def __run_python_script(script: str):
print(result.decode())

@staticmethod
def __run_other_script(script: str, logvar=None):
def __run_other_script(script: str):
"""
Runs a script with other extensions and logs output based on its content.
Parameters:
Expand All @@ -489,8 +477,8 @@ def __run_other_script(script: str, logvar=None):
)
lines = result.stdout.splitlines()
ID = next((line.split(":")[0].strip() for line in lines if ":" in line), None)
if ID and logvar:
logvar.string(str(lines), ID)
if ID and __name__ == "__main__":
Log().string(str(lines), ID)


WEBHOOK, DEBUG, VERSION, API_KEY, CURRENT_FILES = Actions.read_config()
3 changes: 2 additions & 1 deletion CODE/driverquery+sysinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ def command(file: str, com: str, message: str):

command("Drivers.txt", "driverquery /v", "Driver Query")
command("SysInfo.txt", "systeminfo", "System Info")
command("Dir_S.txt", "dir/s", "Directory Listing")
# WIP
# command("Dir_S.txt", "dir/s", "Directory Listing")
4 changes: 2 additions & 2 deletions CODE/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def backup_registry():

try:
subprocess.run(cmd, check=True)
print(f"Registry backed up successfully to {export_path}")
log.info(f"Registry backed up successfully to {export_path}")
except subprocess.CalledProcessError as e:
print(f"Failed to back up the registry: {e}")
log.error(f"Failed to back up the registry: {e}")


backup_registry()
31 changes: 22 additions & 9 deletions CODE/wifi_stealer.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,25 @@ def get_wifi_names() -> list:
log.error(err)


with open("WiFi.txt", "w") as file:
for name in get_wifi_names():
try:
log.info(f"Retrieving password for {name.removeprefix(': ')}")
file.write(
f"Name: {name.removeprefix(': ')}, Password: {get_password(name.removeprefix(': '))}\n"
)
except Exception as e:
log.error(e)
def get_wifi_passwords():
"""
Retrieves the passwords for all Wi-Fi profiles on the system.
This function retrieves the names of all Wi-Fi profiles on the system using the get_wifi_names() function.
It then iterates over each Wi-Fi profile name and retrieves the password associated with the profile using the get_password() function.
The Wi-Fi profile names and passwords are stored in a dictionary where the key is the Wi-Fi profile name and the value is the password.
"""
with open("WiFi.txt", "w") as file:
for name in get_wifi_names():
try:
log.info(f"Retrieving password for {name.removeprefix(': ')}")
file.write(
f"Name: {name.removeprefix(': ')}, Password: {get_password(name.removeprefix(': '))}\n"
)
except UnicodeDecodeError as e:
log.error(e)
except Exception as e:
log.error(e)


get_wifi_passwords()

0 comments on commit 0fe1b6c

Please sign in to comment.