Cobra-complete disassembly of Python source files

Source: Internet
Author: User

Whether it is the DIS in the python standard library or the SDIs we saw earlier, we can only disassemble a piece of code at a time. For Cobra, this is not very convenient. To display complete disassembly results for A. py file on the Cobra GUI, we also need a more powerful Disassembly tool than SDIs, Which Is disassemble.

Disassemble can perform a complete disassembly of A. py file at a time, and embed the disassembly result into the source file in a good way, thus providing the foundation for Cobra display.

The following is an example of Disassemble to disassemble a. py file:

>>> From core. Disassemble import disassemble
>>> Dis = disassemble ()
>>> Result = dis. parsepyfile ('../demo. py ')
>>> Print> open ('demo _ dised. PPy ', 'w'), result

The following is the source file and the result file of disassembly:

[Source file: Demo. py]

 

Def F ():
Pass

Def g ():
Print 'Hello world'
Def fun ():
Pass

Class myclass (object ):
Def _ init _ (Self ):
Pass

A = 1
A + = 1
Print

 

[Disassembly result file: demo_dised.py]

 

Def F ():
#1 0 load_const 0 (<code object f at 00b47608, file "../demo. py", line 1>)
#1 3 make_function 0
#1 6 store_name 0 (f)
Pass
#2 0 load_const 0 (none)
#2 3 return_value

Def g ():
#4 9 load_const 1 (<code object g at 00b51380, file "../demo. py", line 4>)
#4 12 make_function 0
#4 15 store_name 1 (g)
Print 'Hello world'
#5 0 load_const 1 ('Hello World ')
#5 3 print_item
#5 4 print_newline
Def fun ():
#6 5 load_const 2 (<code object fun at 00b516e0, file "../demo. py", line 6>)
#6 8 make_function 0
#6 11 store_fast 0 (fun)
#6 14 load_const 0 (none)
#6 17 return_value
Pass
#7 0 load_const 0 (none)
#7 3 return_value

Class myclass (object ):
#9 0 load_name 0 (_ name __)
#9 3 store_name 1 (_ module __)
#9 18 load_const 2 ('myclass ')
#9 21 load_name 2 (object)
#9 24 build_tuple 1
#9 27 load_const 3 (<code object myclass at 00b514a0, file "../demo. py", line 9>)
#9 30 make_function 0
#9 33 call_function 0
#9 36 build_class
#9 37 store_name 3 (myclass)
Def _ init _ (Self ):
#10 6 load_const 0 (<code object _ init _ at 00b512f0, file "../demo. py", line 10>)
#10 9 make_function 0
#10 12 store_name 2 (_ init __)
#10 15 load_locals
#10 16 return_value
Pass
#11 0 load_const 0 (none)
#11 3 return_value

A = 1
#13 40 load_const 4 (1)
#13 43 store_name 4 ()
A + = 1
#14 46 load_name 4 ()
#14 49 load_const 4 (1)
#14 52 inplace_add
#14 53 store_name 4 ()
Print
#15 56 load_name 4 ()
#15 59 print_item
#15 60 print_newline
#15 61 load_const 5 (none)
#15 64 return_value
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.