forked from chesvectain/PackingData
-
Notifications
You must be signed in to change notification settings - Fork 6
Automate packing with Alienyze
Alex edited this page May 10, 2022
·
2 revisions
Here is the script that was used to generate the Alienyze samples using GUI automation:
import codext
import os
import pyautogui as pag
import pyperclip
import time
HOME = os.path.join(os.path.expanduser("~"), "Desktop")
PBAR_IMG_B64 = b"""iVBORw0KGgoAAAANSUhEUgAAAlYAAAAjCAYAAABW1UREAAAAAXNSR0IArs4c
6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADdSURBVHhe7dZBEYAwEMBAXjj
BPwLqrUjgHvl1M7Mecm1JkiQlGStJkqQoYyVJkhRlrCRJkqKMlSRJUpSxkiRJijJWkiRJUcZKkiQpaj
RWay0AgKNNGo/V/T4AAEcyVgAAEWMFABAxVgAAEWMFABAxVgAAEWMFABAxVgAAEWMFABAxVgAAEWMFA
BAxVgAAEWMFABAxVgAAEWMFABAxVgAAkXysAABONmk0VpIkSfrPWEmSJEUZK0mSpChjJUmSFGWsJEmS
ooyVJElSlLGSJEmKMlaSJElRxkqSJClp7w8tjhssi4hCxwAAAABJRU5ErkJggg=="""
PBAR_IMG = os.path.join(HOME, "alienyze-progressbar.png")
with open(PBAR_IMG, 'wb') as f:
f.write(codext.decode(b"".join(PBAR_IMG_B64.splitlines()), "base64"))
def pack(filename):
stem, ext = os.path.splitext(filename)
fin = os.path.join(HOME, "not-packed", filename)
fpk = os.path.join(HOME, "not-packed", stem + ".alien" + ext)
fout = os.path.join(HOME, "Alienyze", "alienyze_" + filename)
# click on file input field and fill in the input file
type_path(fin)
# click on the "Build" button
pag.click(990, 520)
# wait for the progress bar to reach its maximum
pbar, cnt = None, 0
while not pbar:
if cnt >= 10:
print("FAILURE")
return
time.sleep(.5)
pbar = pag.locateCenterOnScreen(PBAR_IMG, grayscale=True)
cnt += 1
if cnt % 2 == 0:
# retype input file
type_path(fin)
# reclick on "Build"
pag.click(990, 520)
print("SUCCESS")
# now clear the input field
pag.click(1070, 330)
pag.hotkey("ctrl", "a")
pag.press("backspace")
# finally, move the packed file to the destination
os.rename(fpk, fout)
def type_path(path):
pag.click(1070, 330)
pag.hotkey("ctrl", "a")
time.sleep(.5)
pag.click(1070, 330)
pag.hotkey("ctrl", "a")
pyperclip.copy(path)
pag.hotkey("ctrl", "v")
last_one = None
for f in sorted(os.listdir("not-packed")):
fout = os.path.join(HOME, "Alienyze", "alienyze_" + f)
if os.path.exists(fout):
last_one = f
for f in sorted(os.listdir("not-packed")):
if last_one:
if f == last_one:
last_one = None
continue
if f in ["log.txt"]: # put failing files in this list
continue
m = "Packing '%s'..." % f
m += " " * (40 - len(f))
print(m, end="\t")
pack(f)
os.remove(PBAR_IMG)
try:
os.remove(os.path.join(HOME, "not-packed", "log.txt"))
except:
pass