add: cli mode support
This commit is contained in:
@@ -38,14 +38,20 @@ from obfuscation import obfuscate
|
||||
from metadata import change_metadata
|
||||
import os, shutil, glob
|
||||
import pefile
|
||||
import argparse
|
||||
|
||||
class Ui_mainWindow(object):
|
||||
def __init__(self) :
|
||||
self.climode = False
|
||||
self.xor = False
|
||||
self.cflow = False
|
||||
self.junk = False
|
||||
self.filepath = ""
|
||||
self.icon_path = ""
|
||||
self.filename = ""
|
||||
self.xor_key = ""
|
||||
self.junk_pass = 0
|
||||
self.cflow_pass = 0
|
||||
|
||||
def setupUi(self, mainWindow):
|
||||
mainWindow.setObjectName("mainWindow")
|
||||
@@ -144,15 +150,22 @@ class Ui_mainWindow(object):
|
||||
def generate(self) :
|
||||
is_64bit = False
|
||||
in_filename = self.filepath
|
||||
out_filename = "../bin/" + self.pushButton.text().split(".")[0] + "_out.exe"
|
||||
out_filename = "../bin/" + self.filename + "_out.exe"
|
||||
xor_key = ''
|
||||
|
||||
if self.xor :
|
||||
if self.xor_key != "" :
|
||||
xor_key = self.xor_key
|
||||
else :
|
||||
xor_key = self.lineEdit.text()
|
||||
|
||||
if not self.climode :
|
||||
self.label_2.show()
|
||||
|
||||
if not os.path.exists(in_filename):
|
||||
if self.climode :
|
||||
print(f"\"{in_filename}\" does not exist!")
|
||||
return
|
||||
self.label_2.setText(f"\"{in_filename}\" does not exist!")
|
||||
QCoreApplication.processEvents()
|
||||
return
|
||||
@@ -160,18 +173,30 @@ class Ui_mainWindow(object):
|
||||
try :
|
||||
pe = pefile.PE(in_filename)
|
||||
except :
|
||||
if self.climode :
|
||||
print("File is not a binary.")
|
||||
return
|
||||
self.label_2.setText("File is not a binary.")
|
||||
QCoreApplication.processEvents()
|
||||
return
|
||||
if hex(pe.FILE_HEADER.Machine) == '0x14c':
|
||||
if self.climode :
|
||||
print("File is a 32-bit binary")
|
||||
else :
|
||||
self.label_2.setText("File is a 32-bit binary")
|
||||
else:
|
||||
if self.climode :
|
||||
print("File is a 64-bit binary")
|
||||
else :
|
||||
self.label_2.setText("File is a 64-bit binary")
|
||||
is_64bit = True
|
||||
if not self.climode :
|
||||
QCoreApplication.processEvents()
|
||||
|
||||
self.label_2.setText("Creating sample header...")
|
||||
QCoreApplication.processEvents()
|
||||
else :
|
||||
print("Creating sample header...")
|
||||
|
||||
print(f"Filename : {in_filename}")
|
||||
file = bytearray(open(in_filename, 'rb').read())
|
||||
@@ -187,6 +212,9 @@ class Ui_mainWindow(object):
|
||||
|
||||
output.write("};")
|
||||
|
||||
if self.climode :
|
||||
print("done.")
|
||||
else :
|
||||
self.label_2.setText("done.")
|
||||
QCoreApplication.processEvents()
|
||||
|
||||
@@ -197,16 +225,30 @@ class Ui_mainWindow(object):
|
||||
with open("../Crypter/config.h", "w") as c :
|
||||
c.write(f'#pragma once\n#define KEY "{xor_key}"')
|
||||
|
||||
if self.climode :
|
||||
print("Adding junk code...")
|
||||
else :
|
||||
self.label_2.setText("Adding junk code...")
|
||||
QCoreApplication.processEvents()
|
||||
if self.climode :
|
||||
obfuscate(self.junk_pass, self.cflow_pass, self.cflow, self.junk, is_64bit)
|
||||
else :
|
||||
obfuscate(self.spinBox.value(), self.spinBox_2.value(), self.cflow, self.junk, is_64bit)
|
||||
self.label_2.setText("done.")
|
||||
QCoreApplication.processEvents()
|
||||
|
||||
if self.climode :
|
||||
print("Changing metadata...")
|
||||
change_metadata(self.icon_path)
|
||||
else :
|
||||
self.label_2.setText("Changing metadata...")
|
||||
QCoreApplication.processEvents()
|
||||
change_metadata(self.icon_path)
|
||||
|
||||
if self.climode :
|
||||
print("done.")
|
||||
print("Compiling...")
|
||||
else :
|
||||
self.label_2.setText("done.")
|
||||
QCoreApplication.processEvents()
|
||||
|
||||
@@ -223,6 +265,9 @@ class Ui_mainWindow(object):
|
||||
|
||||
|
||||
if return_code :
|
||||
if self.climode :
|
||||
print("Build failed.")
|
||||
else :
|
||||
self.label_2.setText("build failed.")
|
||||
QCoreApplication.processEvents()
|
||||
|
||||
@@ -241,11 +286,17 @@ class Ui_mainWindow(object):
|
||||
pass
|
||||
|
||||
if not return_code :
|
||||
if self.climode :
|
||||
print(f"--> {out_filename}")
|
||||
else :
|
||||
self.label_2.setText(f"--> {out_filename}")
|
||||
QCoreApplication.processEvents()
|
||||
else :
|
||||
return
|
||||
|
||||
if self.climode :
|
||||
print("Signing the file...")
|
||||
else :
|
||||
self.label_2.setText("Signing the file...")
|
||||
QCoreApplication.processEvents()
|
||||
|
||||
@@ -256,6 +307,9 @@ class Ui_mainWindow(object):
|
||||
os.remove(out_filename)
|
||||
os.rename(out_filename.replace(".exe","")+"_signed.exe", out_filename)
|
||||
|
||||
if self.climode :
|
||||
print("done.")
|
||||
return
|
||||
self.label_2.setText("done.")
|
||||
QCoreApplication.processEvents()
|
||||
|
||||
@@ -268,6 +322,7 @@ class Ui_mainWindow(object):
|
||||
# Display the selected file path in the QLineEdit
|
||||
self.pushButton.setText(filePath.split("/")[-1:][0])
|
||||
self.filepath = filePath
|
||||
self.filename = filePath.split("/")[-1:][0]
|
||||
|
||||
|
||||
def IconfileDialog(self):
|
||||
@@ -290,6 +345,42 @@ class Ui_mainWindow(object):
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
if len(sys.argv) > 1 :
|
||||
parser = argparse.ArgumentParser(description="patate crypter")
|
||||
parser.add_argument('--file', type=str, required=True, help="Path to the file to be processed")
|
||||
parser.add_argument('--xor', type=str, required=False, help="XOR key for encryption/decryption")
|
||||
parser.add_argument('--junk', type=int, required=False, help="Number of junk passes")
|
||||
parser.add_argument('--control_flow', type=int, required=False, help="Number of control flow passes")
|
||||
parser.add_argument('--icon', type=str, required=False, help="Path to the icon file")
|
||||
args = parser.parse_args()
|
||||
|
||||
ui = Ui_mainWindow()
|
||||
|
||||
if args.icon :
|
||||
if not os.path.exists(args.icon):
|
||||
print(f"Could not find icon file {args.icon}")
|
||||
if args.icon[-4:] != ".ico" :
|
||||
print("Icon should be a .ico file.")
|
||||
ui.icon_path = args.icon
|
||||
|
||||
ui.climode = True
|
||||
ui.xor = args.xor != None
|
||||
ui.cflow = args.control_flow != None
|
||||
ui.junk = args.junk != None
|
||||
ui.filepath = args.file
|
||||
ui.filename = args.file.split("/")[-1:][0]
|
||||
|
||||
if args.xor :
|
||||
ui.xor_key = args.xor
|
||||
if args.junk :
|
||||
ui.junk_pass = args.junk
|
||||
if args.control_flow :
|
||||
ui.cflow_pass = args.control_flow
|
||||
ui.generate()
|
||||
|
||||
sys.exit()
|
||||
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
mainWindow = QtWidgets.QMainWindow()
|
||||
ui = Ui_mainWindow()
|
||||
|
||||
Reference in New Issue
Block a user