WEB开发网
开发学院软件开发Python 以Python为例讨论高级编程语言程序的wire format与... 阅读

以Python为例讨论高级编程语言程序的wire format与校验

 2010-09-22 11:26:23 来源:WEB开发网   
核心提示: 注意到这个顶层PyCodeObject的字节码的地址范围是0-101,与PyCodeObject.co_code这个PyStringObject的长度信息吻合,以Python为例讨论高级编程语言程序的wire format与校验(9), 现在让我们修改字节码的2个字节,在字节码内偏移量为4

注意到这个顶层PyCodeObject的字节码的地址范围是0-101,与PyCodeObject.co_code这个PyStringObject的长度信息吻合。

现在让我们修改字节码的2个字节,在字节码内偏移量为42-43、在文件内地址为0x48-0x49的位置。原本内容为:

Python bytecode代码 

  8          42 LOAD_NAME                0 (A)

也就是0x65 0x00 0x00。修改为0x71 0x70 0x00,改后对应的字节码是JUMP_ABSOLUTE 112,也就是跳转到顶层代码的字节码中从头开始算偏移量为112的地方。

修改后保存为_demo.pyc,内容是:

Hex代码

Offset      0  1  2  3  4  5  6  7   8  9  A  B  C  D  E  F

00000000   D1 F2 0D 0A B3 34 04 4A  63 00 00 00 00 00 00 00   羊..?.Jc.......
00000010   00 03 00 00 00 40 00 00  00 73 66 00 00 00 64 00   .....@...sf...d.
00000020   00 64 05 00 64 01 00 84  00 00 83 00 00 59 5A 00   .d..d..?.?.YZ.
00000030   00 65 00 00 69 01 00 47  48 65 00 00 04 69 01 00   .e..i..GHe...i..
00000040   64 02 00 37 02 5F 01 00  71 70 00 69 01 00 47 48   d..7._..qp.i..GH
00000050   65 00 00 83 00 00 5A 02  00 65 02 00 69 01 00 47   e..?.Z..e..i..G
00000060   48 65 02 00 04 69 01 00  64 03 00 37 02 5F 01 00   He...i..d..7._..
00000070   65 02 00 69 01 00 47 48  65 00 00 69 01 00 47 48   e..i..GHe..i..GH
00000080   64 04 00 53 28 06 00 00  00 74 01 00 00 00 41 63   d..S(....t....Ac
00000090   00 00 00 00 00 00 00 00  01 00 00 00 42 00 00 00   ............B...
000000A0   73 0E 00 00 00 65 00 00  5A 01 00 64 00 00 5A 02   s....e..Z..d..Z.
000000B0   00 52 53 28 01 00 00 00  69 01 00 00 00 28 03 00   .RS(....i....(..
000000C0   00 00 74 08 00 00 00 5F  5F 6E 61 6D 65 5F 5F 74   ..t....__name__t
000000D0   0A 00 00 00 5F 5F 6D 6F  64 75 6C 65 5F 5F 74 01   ....__module__t.
000000E0   00 00 00 78 28 00 00 00  00 28 00 00 00 00 28 00   ...x(....(....(.
000000F0   00 00 00 73 07 00 00 00  64 65 6D 6F 2E 70 79 52   ...s....demo.pyR
00000100   00 00 00 00 01 00 00 00  73 02 00 00 00 06 01 69   ........s......i
00000110   02 00 00 00 69 04 00 00  00 4E 28 00 00 00 00 28   ....i....N(....(
00000120   03 00 00 00 52 00 00 00  00 52 03 00 00 00 74 01   ....R....R....t.
00000130   00 00 00 61 28 00 00 00  00 28 00 00 00 00 28 00   ...a(....(....(.
00000140   00 00 00 73 07 00 00 00  64 65 6D 6F 2E 70 79 74   ...s....demo.pyt
00000150   08 00 00 00 3C 6D 6F 64  75 6C 65 3E 01 00 00 00   ....<module>....
00000160   73 10 00 00 00 13 03 08  03 0F 01 08 03 09 01 08   s...............
00000170   03 0F 01 08 01                                     .....

上一页  4 5 6 7 8 9 10  下一页

Tags:Python 讨论 高级

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接