手上有个简单的小程序,用来识别公司应用的登录窗口,自动填写用户名密码,点击登录(要是有保存用户名密码功能多好啊)
今天忽然想看一下实现原理是啥,源码是啥
DIE pyinstxtractor uncompyle6 pycdc 编译好的pycdc vs2019 win10x64 python3.9.6
下载Detect It Easy 软件,并打开我们的小程序
上面的PyInstaller表明这是一个python程序,使用pyinstaller打包成exe
既然是python打包的,先解包看看里面有啥
E:\xxxx>python pyinstxtractor.py xxxx.exe
[+] Processing xxxx.exe
[+] Pyinstaller version: 2.1+
[+] Python version: 309
[+] Length of package: 59527603 bytes
[+] Found 1053 files in CArchive
[+] Beginning extraction…please standby
will make file struct.pyc
will make file pyimod01_os_path.pyc
will make file pyimod02_archive.pyc
will make file pyimod03_importers.pyc
will make file pyimod04_ctypes.pyc
[+] Possible entry point: pyiboot01_bootstrap.pyc
[+] Possible entry point: pyi_rth_subprocess.pyc
[+] Possible entry point: pyi_rth_pkgutil.pyc
[+] Possible entry point: pyi_rth_multiprocessing.pyc
[+] Possible entry point: pyi_rth_inspect.pyc
[+] Possible entry point: pyi_rth__tkinter.pyc
[+] Possible entry point: xxxx.pyc
…
will make file tk\xmfbox.tcl
will make file PYZ-00.pyz
[+] Found 536 files in PYZ archive
[+] Successfully extracted pyinstaller archive: xxxx.exe
You can now use a python decompiler on the pyc files within the extracted directory
解出来了一堆pyc文件,pyc是py文件编译后生成的,需要反编译一下
pip install uncompyle6
,也可从网站下载源码uncompyle6 xxxx_extracted\xxxx.pyc
由于这个exe是python3.9生成的,uncompyle6不支持。只能另觅他法,我们换pycdc再试一下
pycdc xxxx_extracted\xxxx.pyc > xxxx.py
既然不能直接得到py文件,我们使用大杀器吧
执行命令pycdas.exe xxxx.exe_extracted\xxxx.pyc > xxxx.txt
打开xxxx.txt
我们看到已经得到了完整的字节码,LOAD_GLOBAL 读取一个全局变量,类似java字节码的感觉,对照一下左右的代码很容易读懂。
随后就需要我们耐心的读xxxx.txt中的字节码,将pycdc生成的xxxx.py中缺少的部分自行补上,
最后由于生成的xxxx.py部分语句并不符合语法,需要自己修改一下,再通读一下代码进行修正。