linux python如何反编译成源码
文件为可执行文件 ./test可执行
1、pyinstxtractor
使用pyinstxtractor报错
Error: Unsupported pyinstaller version or not a pyinstaller archive
2、uncompyle6
更改文件名后缀为.pyc或pyo,使用uncompyle6报错
KeyError: b'\x7fELF'
3、objdump
objdump -x结果如下。可知执行环境为python3.6,无壳,-d可以生成asm代码,长度约28w行
test: file format elf64-x86-64
test
architecture: i386:x86-64, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x0000000000404040
Program Header:
PHDR off 0x0000000000000040 vaddr 0x0000000000400040 paddr 0x000000000040 0040 align 2**3
filesz 0x0000000000000268 memsz 0x0000000000000268 flags r-x
INTERP off 0x00000000000002a8 vaddr 0x00000000004002a8 paddr 0x000000000040 02a8 align 2**0
filesz 0x000000000000001c memsz 0x000000000000001c flags r--
LOAD off 0x0000000000000000 vaddr 0x0000000000400000 paddr 0x000000000040 0000 align 2**21
filesz 0x0000000000132990 memsz 0x0000000000132990 flags r-x
LOAD off 0x0000000000132c90 vaddr 0x0000000000732c90 paddr 0x000000000073 2c90 align 2**21
filesz 0x0000000000016a30 memsz 0x000000000001b2a8 flags rw-
DYNAMIC off 0x0000000000132ca0 vaddr 0x0000000000732ca0 paddr 0x000000000073 2ca0 align 2**3
filesz 0x0000000000000220 memsz 0x0000000000000220 flags rw-
NOTE off 0x00000000000002c4 vaddr 0x00000000004002c4 paddr 0x000000000040 02c4 align 2**2
filesz 0x0000000000000020 memsz 0x0000000000000020 flags r--
NOTE off 0x00000000000002e8 vaddr 0x00000000004002e8 paddr 0x000000000040 02e8 align 2**3
filesz 0x0000000000000030 memsz 0x0000000000000030 flags r--
NOTE off 0x0000000000000318 vaddr 0x0000000000400318 paddr 0x000000000040 0318 align 2**2
filesz 0x0000000000000024 memsz 0x0000000000000024 flags r--
EH_FRAME off 0x00000000001265b0 vaddr 0x00000000005265b0 paddr 0x000000000052 65b0 align 2**2
filesz 0x000000000000155c memsz 0x000000000000155c flags r--
STACK off 0x0000000000000000 vaddr 0x0000000000000000 paddr 0x000000000000 0000 align 2**4
filesz 0x0000000000000000 memsz 0x0000000000000000 flags rw-
RELRO off 0x0000000000132c90 vaddr 0x0000000000732c90 paddr 0x000000000073 2c90 align 2**0
filesz 0x0000000000000370 memsz 0x0000000000000370 flags r--
Dynamic Section:
NEEDED libpython3.6m.so.1.0
NEEDED libpthread.so.0
NEEDED libdl.so.2
NEEDED libutil.so.1
NEEDED libm.so.6
NEEDED libc.so.6
INIT 0x00000000004033e0
FINI 0x000000000051f7c4
INIT_ARRAY 0x0000000000732c90
INIT_ARRAYSZ 0x0000000000000008
FINI_ARRAY 0x0000000000732c98
FINI_ARRAYSZ 0x0000000000000008
GNU_HASH 0x0000000000400340
STRTAB 0x00000000004015d0
SYMTAB 0x0000000000400400
STRSZ 0x0000000000000ca2
SYMENT 0x0000000000000018
DEBUG 0x0000000000000000
PLTGOT 0x0000000000733000
PLTRELSZ 0x0000000000000c00
PLTREL 0x0000000000000007
JMPREL 0x00000000004027e0
RELA 0x0000000000402420
RELASZ 0x00000000000003c0
RELAENT 0x0000000000000018
VERNEED 0x00000000004023f0
VERNEEDNUM 0x0000000000000001
VERSYM 0x0000000000402272
Version References:
required from libc.so.6:
0x0d696914 0x00 03 GLIBC_2.4
0x09691a75 0x00 02 GLIBC_2.2.5
Sections:
Idx Name Size VMA LMA File off Algn
0 .interp 0000001c 00000000004002a8 00000000004002a8 000002a8 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
1 .note.ABI-tag 00000020 00000000004002c4 00000000004002c4 000002c4 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .note.gnu.property 00000030 00000000004002e8 00000000004002e8 000002e8 2 **3
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 .note.gnu.build-id 00000024 0000000000400318 0000000000400318 00000318 2 **2
CONTENTS, ALLOC, LOAD, READONLY, DATA
4 .gnu.hash 000000bc 0000000000400340 0000000000400340 00000340 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
5 .dynsym 000011d0 0000000000400400 0000000000400400 00000400 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
6 .dynstr 00000ca2 00000000004015d0 00000000004015d0 000015d0 2**0
CONTENTS, ALLOC, LOAD, READONLY, DATA
7 .gnu.version 0000017c 0000000000402272 0000000000402272 00002272 2**1
CONTENTS, ALLOC, LOAD, READONLY, DATA
8 .gnu.version_r 00000030 00000000004023f0 00000000004023f0 000023f0 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
9 .rela.dyn 000003c0 0000000000402420 0000000000402420 00002420 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
10 .rela.plt 00000c00 00000000004027e0 00000000004027e0 000027e0 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
11 .init 00000017 00000000004033e0 00000000004033e0 000033e0 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
12 .plt 00000810 0000000000403400 0000000000403400 00003400 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
13 .text 0011bbb1 0000000000403c10 0000000000403c10 00003c10 2**4
CONTENTS, ALLOC, LOAD, READONLY, CODE
14 .fini 00000009 000000000051f7c4 000000000051f7c4 0011f7c4 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
15 .rodata 00006dce 000000000051f7e0 000000000051f7e0 0011f7e0 2**5
CONTENTS, ALLOC, LOAD, READONLY, DATA
16 .eh_frame_hdr 0000155c 00000000005265b0 00000000005265b0 001265b0 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
17 .eh_frame 0000ae80 0000000000527b10 0000000000527b10 00127b10 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
18 .init_array 00000008 0000000000732c90 0000000000732c90 00132c90 2**3
CONTENTS, ALLOC, LOAD, DATA
19 .fini_array 00000008 0000000000732c98 0000000000732c98 00132c98 2**3
CONTENTS, ALLOC, LOAD, DATA
20 .dynamic 00000220 0000000000732ca0 0000000000732ca0 00132ca0 2**3
CONTENTS, ALLOC, LOAD, DATA
21 .got 00000140 0000000000732ec0 0000000000732ec0 00132ec0 2**3
CONTENTS, ALLOC, LOAD, DATA
22 .got.plt 00000418 0000000000733000 0000000000733000 00133000 2**3
CONTENTS, ALLOC, LOAD, DATA
23 .data 000162a0 0000000000733420 0000000000733420 00133420 2**5
CONTENTS, ALLOC, LOAD, DATA
24 .bss 00004878 00000000007496c0 00000000007496c0 001496c0 2**5
ALLOC
25 .comment 00000058 0000000000000000 0000000000000000 001496c0 2**0
CONTENTS, READONLY
26 .gnu.build.attributes 000007e8 0000000000000000 0000000000000000 00149718 2**2
CONTENTS, READONLY
SYMBOL TABLE:
no symbols
汇编部分截图
问题如何把test文件转为打包前的py文件?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
理论上,这种无法还原到最初的 python 源码,但可以先用反汇编工具分析,得到近似的 c 源码,再转成 python 源码。
据我所知,目前(2018年8月22日)尚无完整的工具链。
反汇编工具首选 IDA Pro。
不同于 pyinstaller 生成的文件,这种文件通常是 cython + gcc 生成,它依赖 libpythonX.Ym.so 库文件,但不需要 python 环境。
你可以运行
ldd <file>
确认。附上生成的示例
编写 python 源码,如 a.pyx
将 python 源码转成 c 源码,得到 a.c
编译 c 文件