forked from chesvectain/PackingData
-
Notifications
You must be signed in to change notification settings - Fork 6
Automate packing with Themida
Alex edited this page Feb 12, 2022
·
5 revisions
Here is the script that was used to generate the Themida samples using GUI automation:
import os
import pyautogui as pag
import pyperclip
import time
pag.PAUSE = .2
HOME = os.path.join(os.path.expanduser("~"), "Desktop")
# setting: stick Themida's window to the left half of the screen
def pack(filename):
# does not use ":" as it does not translate to the right character (keyboard layout issue)
fin = os.path.join(HOME, "not-packed", filename)
fout = os.path.join(HOME, "Themida", "themida_" + filename)
# click on "Input Filename" field and fill in the input file
pag.click(400, 280)
pag.hotkey("ctrl", "a")
pag.press("backspace")
type_path(fin)
# click on "Output Filename" field and fill in the output file
pag.click(400, 310)
pag.hotkey("ctrl", "a")
pag.press("backspace")
type_path(fout)
# click on the "Protect" button then "OK"
pag.click(250, 150)
pag.click(980, 500)
# wait for the button to become "Close" and then click on it
button = None
while not button:
time.sleep(.5)
button = pag.locateCenterOnScreen(os.path.join(HOME, "close-button.png"), grayscale=True)
pag.click(700, 670)
# now free the input fields
pag.click(400, 280)
pag.hotkey("ctrl", "a")
pag.press("backspace")
pag.click(400, 310)
pag.hotkey("ctrl", "a")
pag.press("backspace")
# this function is a workaround to this issue:
# https://stackoverflow.com/questions/59604162/typewrite-character-with-pyautogui
def type_path(path):
if path.startswith("C:"):
path = path[2:]
pag.typewrite("C", interval=.01)
pyperclip.copy(":")
pag.hotkey("ctrl", "v", interval=.01)
pag.typewrite(path, interval=.01)
for f in os.listdir("not-packed"):
pack(f)