其他记录

python opcode置换

2019-02-13  本文已影响0人  鸣人的大哥

我使用的python版本是2.7.14

一、打乱opcode顺序

1.文件
需要改的文件有Include/opcode.h Lib/opcode.py Python/opcode_targets.h三个文件
2.打乱
打乱opcode之后该解释器编译出来的pyc只能有该python解释器执行,可以欺骗常规的反编译工具。
3.例子
如下图修改,一个简单的加减法交换:


image.png
image.png
image.png

二、make 编译python源码

make编译完成后,python 解释器的加减法opcode是被交换了的,找个加减法demo测试下就明白了。
如果编译出现错误如下:

  File "/tools/python/Python-2.7.14/Lib/encodings/__init__.py", line 99, in search_function
    mod = __import__('encodings.' + modname, fromlist=_import_tail,
TypeError: unsupported operand type(s) for -: 'str' and 'str'
generate-posix-vars failed
make: *** [pybuilddir.txt] Error 1

原因就是修改的位置没有同步起来,可能就是opcode_targets.h没修改或者顺序不对,opcode_targets.h数组的顺序与opcode.h 的顺序是一一对应的。

上一篇下一篇

猜你喜欢

热点阅读