-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
436 additions
and
538 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
main.exe | ||
*.bak | ||
*.bat.* | ||
*_obf.bat | ||
__pycache__ | ||
somalifuscatorv2.log | ||
tests/test*_obf.bat | ||
src_paid | ||
test_all.bat | ||
fun_stuff/ | ||
*.rar | ||
settings.json | ||
obf | ||
simple_debug.py | ||
settings.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ BatchParse | |
requests | ||
kdot | ||
primefac | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,217 +1,158 @@ | ||
import os | ||
import sys | ||
import time | ||
import cProfile | ||
import re | ||
import json | ||
from dataclasses import dataclass | ||
|
||
from util.supporting.settings import Settings | ||
from util.obfuscation.obfuscate import Obfuscator as OBF | ||
|
||
from util.ui.ui import Ui, UiLinux | ||
from util.obfuscation.obfuscate import Obfuscator | ||
from util.supporting.settings import conf_file, Settings | ||
|
||
from util.auto_updating.updater import AutoUpdate | ||
|
||
from rich import print | ||
from rich.panel import Panel | ||
from rich.align import Align | ||
from rich.syntax import Syntax | ||
from rich.traceback import install | ||
|
||
install() | ||
try: | ||
from tkinter import Tk | ||
from tkinter import filedialog as fd | ||
except: | ||
pass | ||
|
||
from argparse import ArgumentParser | ||
|
||
from textual.app import App, ComposeResult | ||
from textual.containers import Horizontal, ScrollableContainer, Center | ||
from textual.widgets import Footer, Header, Button, Static, RichLog | ||
from textual.events import Print | ||
from textual.binding import Binding | ||
from textual import work | ||
from rich.syntax import Syntax | ||
from rich.text import Text | ||
|
||
|
||
@dataclass | ||
class settings: | ||
file: str = "" | ||
debug: bool = False | ||
|
||
|
||
class Code_Display(ScrollableContainer): | ||
def compose(self) -> ComposeResult: | ||
settings.file = SomalifuscatorV2.get_user_file() | ||
with open(settings.file, "r") as f: | ||
code = f.read() | ||
yield Static( | ||
Syntax( | ||
code, | ||
"bat", | ||
theme="monokai", | ||
line_numbers=True, | ||
word_wrap=True, | ||
) | ||
) | ||
|
||
|
||
class SomalifuscatorV2(App): | ||
CSS_PATH = "util\\ui\\style.tcss" | ||
BINDINGS = [Binding("d", "toggle_debug", "Toggle Debug")] | ||
|
||
def on_button_pressed(self, _: Button.Pressed) -> None: | ||
OBF( | ||
settings.file, | ||
double_click_check=Settings.double_click_check, | ||
utf_16_bom=Settings.utf_16_bom, | ||
) | ||
self.query_one(RichLog).write("Obfuscating...") | ||
|
||
def compose(self) -> ComposeResult: | ||
yield Header() | ||
with Horizontal(): | ||
yield RichLog() | ||
yield Code_Display() | ||
with Center(): | ||
yield Button("Obfuscate", variant="success") | ||
yield Footer() | ||
|
||
def action_toggle_debug(self) -> None: | ||
settings.debug = not settings.debug | ||
color = "red" if not settings.debug else "green" | ||
debug_msg = Text.from_markup( | ||
f"Debug is now [{color} italic]{settings.debug}[/]" | ||
) | ||
self.query_one(RichLog).write(debug_msg) | ||
|
||
def on_print(self, event: Print) -> None: | ||
self.query_one(RichLog).write(Text.from_markup(event.text.strip())) | ||
# ill fix this soon | ||
# with open("test.txt", "a+") as f: | ||
# f.write(str(Text.from_markup(event.text))) | ||
|
||
@work(thread=True) | ||
def run_my_worker(self): | ||
self.begin_capture_print(self, True, True) | ||
|
||
def on_mount(self) -> None: | ||
self.query_one(RichLog).border_title = "Log" | ||
self.query_one(Code_Display).border_title = "Code" | ||
|
||
self.query_one(RichLog).write(Text.from_markup(self.pretty_print_settings())) | ||
|
||
self.query_one(Button).focus() | ||
self.run_my_worker() | ||
|
||
@staticmethod | ||
def pretty_print_settings() -> str: | ||
with open(conf_file, "r") as f: | ||
settings = json.load(f) | ||
# print(Align.center(f"[cyan]Settings: {conf_file}[/cyan]")) | ||
# print( | ||
# Align.center( | ||
# f"[bold white]{'-' * (14 + len(conf_file.strip()))}[/bold white]" | ||
# ) | ||
# ) | ||
# for key, value in settings.items(): | ||
# print(Align.center(f"[bold white]{key}: [/bold white]{value}")) | ||
to_print = "" | ||
to_print += f"[bold blue]Settings:[/] [bold white]{conf_file}[/]\n" | ||
for key, value in settings.items(): | ||
color = "green" if value else "red" | ||
to_print += f"[bold blue]{key}:[/] [bold {color}]{value}[/]\n" | ||
return to_print | ||
|
||
@staticmethod | ||
def get_user_file() -> str: | ||
""" | ||
Prompts the user to select a batch file. | ||
Returns the file path of the selected file. | ||
Returns: | ||
- str: The file path of the selected file. | ||
""" | ||
file_path = "" | ||
# keep prompting user until they select a valid file | ||
root = Tk() | ||
root.withdraw() | ||
root.wm_attributes("-topmost", 1) | ||
while not os.path.isfile(file_path): | ||
# make sure file is bat file | ||
file_path = fd.askopenfilename( | ||
title="Select a batch file", | ||
filetypes=[("Batch Files", ("*.bat", "*.cmd"))], | ||
initialdir=os.getcwd(), | ||
parent=root, | ||
) | ||
root.destroy() | ||
return file_path | ||
|
||
__version__ = "2.7.3" | ||
|
||
|
||
class Main: | ||
def main(self): | ||
super_obf = Settings.super_obf | ||
if any([args.file]): | ||
current_time = time.time() | ||
Obfuscator(args.file, double_click_check=False, utf_16_bom=False) | ||
finish_time = time.time() | ||
print(f"It only took {finish_time - current_time} to finish!") | ||
return | ||
|
||
AutoUpdate(__version__) | ||
|
||
# initialize UI | ||
if os.name == "nt": | ||
self.ui = Ui() | ||
else: | ||
self.ui = UiLinux() | ||
|
||
# show main ui | ||
self.ui.main_ui() | ||
|
||
# hot asf settings | ||
Ui.pretty_print_settings() | ||
|
||
# get file location | ||
file_location = self.ui.get_user_file() | ||
|
||
current_time = time.time() | ||
|
||
# show inside of file (aesthetic trust) | ||
with open(file_location, encoding="utf8", errors="ignore") as f: | ||
syntax = Syntax(f.read(), "bat", line_numbers=True) | ||
print(Align.center(Panel.fit(syntax, title="Batch Content", border_style="bold blue", padding=(1, 2), subtitle=f"SomalifuscatorV{__version__}"))) | ||
if super_obf: | ||
print("This is only available in the paid version of Somalifuscator.") | ||
input("Press any key to exit...") | ||
else: | ||
Obfuscator(file_location, double_click_check=Settings.double_click_check, utf_16_bom=Settings.utf_16_bom) | ||
finish_time = time.time() | ||
print(f"It only took {finish_time - current_time} to finish!") | ||
input("Press any key to exit...") | ||
|
||
|
||
TIME_CHECK = False | ||
|
||
if TIME_CHECK: | ||
parse = ArgumentParser() | ||
parse.add_argument("-f", "--file", help="File to obfuscate", type=str) | ||
parse.add_argument("-nu", "--no-utf-16-bom", help="No UTF-16 BOM", action="store_true") | ||
args = parse.parse_args() | ||
# profile the Main().main() function and show what functions took the longest to execute and write the info to a file | ||
with cProfile.Profile() as pr: | ||
Main().main() | ||
pr.print_stats(sort="cumtime") | ||
with open("profile.txt", "w") as f: | ||
sys.stdout = f | ||
pr.print_stats(sort="time") | ||
sys.exit(0) | ||
|
||
if __name__ == "__main__": | ||
parse = ArgumentParser() | ||
parse.add_argument("-f", "--file", help="File to obfuscate", type=str) | ||
parse.add_argument("-nu", "--no-utf-16-bom", help="No UTF-16 BOM", action="store_true") | ||
parse.add_argument( | ||
"-nu", "--no-utf-16-bom", help="No UTF-16 BOM", action="store_true" | ||
) | ||
args = parse.parse_args() | ||
Main().main() | ||
|
||
# import os | ||
# import sys | ||
# import time | ||
# import json | ||
# from dataclasses import dataclass | ||
# | ||
# from util.methods.common.common import console | ||
# | ||
# from util.supporting.settings import conf_file | ||
# | ||
# try: | ||
# from tkinter import Tk | ||
# from tkinter import filedialog as fd | ||
# except: | ||
# pass | ||
# | ||
# from rich.align import Align | ||
# | ||
# from textual.app import App, ComposeResult | ||
# from textual.containers import Container, Horizontal, ScrollableContainer | ||
# from textual.widgets import Footer, Header, Button, Static, Placeholder, Pretty, RichLog | ||
# from textual.events import Print | ||
# from textual.reactive import Reactive | ||
# from textual.binding import Binding | ||
# from rich.syntax import Syntax | ||
# from textual import work, events | ||
# | ||
# | ||
# @dataclass | ||
# class settings: | ||
# file: str = "" | ||
# debug: bool = False | ||
# | ||
# | ||
# class Code_Console1(Static): | ||
# code: str = Reactive("test") | ||
# | ||
# def compose(self) -> ComposeResult: | ||
# yield RichLog(highlight=True, markup=True) | ||
# | ||
# | ||
# class Code_Console2(Static): | ||
# def compose(self) -> ComposeResult: | ||
# settings.file = SomalifuscatorV2.get_user_file() | ||
# with open(settings.file, "r") as f: | ||
# code = f.read() | ||
# yield Static( | ||
# Syntax(code, "bat", theme="monokai", line_numbers=True, word_wrap=True), | ||
# ) | ||
# | ||
# | ||
# class Obfuscator(Static): | ||
# def compose(self) -> ComposeResult: | ||
# yield Button("Obfuscate", id="start", variant="success") | ||
# | ||
# | ||
# class SomalifuscatorV2(App): | ||
# CSS_PATH = "util\\ui\\style.tcss" | ||
# BINDINGS = [Binding("d", "toggle_debug", "Toggle Debug")] | ||
# | ||
# def on_button_pressed(self, event: Button.Pressed) -> None: | ||
# if event.button.id == "start": | ||
# OBF(settings.file, double_click_check=all_.double_click_check, utf_16_bom=all_.utf_16_bom) | ||
# else: | ||
# print("Unknown button pressed!") | ||
# | ||
# def compose(self) -> ComposeResult: | ||
# yield Header() | ||
# yield Footer() | ||
# with Container(id="MainContainer"): | ||
# yield Horizontal( | ||
# ScrollableContainer(Code_Console1()), | ||
# ScrollableContainer(Code_Console2()), | ||
# ) | ||
# yield Obfuscator() | ||
# | ||
# def action_toggle_debug(self) -> None: | ||
# settings.debug = not settings.debug | ||
# print(f"Debug is now {settings.debug}") | ||
# | ||
# def on_print(self, event: Print) -> None: | ||
# # check if any text in events.text is not in string.printable | ||
# # if so, then it's probably a key event | ||
# self.query_one(RichLog).write(event.text) | ||
# | ||
# def on_mount(self) -> None: | ||
# self.run_my_worker() | ||
# | ||
# @work(thread=True) | ||
# def run_my_worker(self): | ||
# self.begin_capture_print(self, True, True) | ||
# | ||
# @staticmethod | ||
# def pretty_print_settings() -> None: | ||
# with open(conf_file, "r") as f: | ||
# settings = json.load(f) | ||
# print(Align.center(f"[cyan]Settings: {conf_file}[/cyan]")) | ||
# print(Align.center(f"[bold white]{'-' * (14 + len(conf_file.strip()))}[/bold white]")) | ||
# for key, value in settings.items(): | ||
# print(Align.center(f"[bold white]{key}: [/bold white]{value}")) | ||
# | ||
# @staticmethod | ||
# def get_user_file() -> str: | ||
# """ | ||
# Prompts the user to select a batch file. | ||
# Returns the file path of the selected file. | ||
# | ||
# Returns: | ||
# - str: The file path of the selected file. | ||
# """ | ||
# file_path = "" | ||
# # keep prompting user until they select a valid file | ||
# root = Tk() | ||
# root.withdraw() | ||
# root.wm_attributes("-topmost", 1) | ||
# while not os.path.isfile(file_path): | ||
# # make sure file is bat file | ||
# file_path = fd.askopenfilename( | ||
# title="Select a batch file", | ||
# filetypes=[("Batch Files", ("*.bat", "*.cmd"))], | ||
# initialdir=os.getcwd(), | ||
# parent=root, | ||
# ) | ||
# root.destroy() | ||
# return file_path | ||
if any([args.file]): | ||
OBF( | ||
args.file, | ||
double_click_check=False, | ||
utf_16_bom=False, | ||
) | ||
exit(0) | ||
SomalifuscatorV2().run() | ||
exit(0) |
Oops, something went wrong.