帮酷LOGO
0 0 评论
  • 显示原文与译文双语对照的内容
文章标签:BIN  二进制  form  格式  ELF  MACH  for  Manipulation  
Abstract Binary Format Manipulation - ELF, PE and Mach-O format

  • 源代码名称:abf
  • 源代码网址:http://www.github.com/JonathanSalwan/abf
  • abf源代码文档
  • abf源代码下载
  • Git URL:
    git://www.github.com/JonathanSalwan/abf.git
  • Git Clone代码到本地:
    git clone http://www.github.com/JonathanSalwan/abf
  • Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/JonathanSalwan/abf
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    
  • 抽象二进制格式

    以抽象或者更具体的形式管理你的 ELF,英镑或者mach格式。

    安装

    
    $ sudo./setup.py install
    
    
    
    

    示例

    通过抽象:

    
    >>> from abf.abstract import * 
    
    
    >>> binary = Abstract('/usr/bin/id') 
    
    
    
    >>> binary.getFormat()
    
    
    'ELF'
    
    
    >>> hex(binary.getEntryPoint())
    
    
    '0x4022bcL'
    
    
    
    >>> binary = Abstract('./binaries/pe-Windows-x86-cmd') 
    
    
    >>> binary.getFormat()
    
    
    'PE'
    
    
    >>> hex(binary.getEntryPoint())
    
    
    '0x4ad060dcL'
    
    
    
    >>> binary = Abstract('./binaries/MachO-OSX-x86-ls') 
    
    
    >>> binary.getFormat()
    
    
    'Mach-O'
    
    
    >>> hex(binary.getEntryPoint())
    
    
    '0x1708L'
    
    
    
    >>> sectionsExec = binary.getExecSections()
    
    
    >>> len(sectionsExec)
    
    
    3
    
    
    >>> for sect in sectionsExec: 
    
    
    ... print hex(sect['vaddr']) 
    
    
    ... 
    
    
    0x1708L
    
    
    0x557cL
    
    
    0x5750L
    
    
    
    

    或者更具体地说:

    
    >>> binary = Abstract('/usr/bin/id') 
    
    
    >>> elf = binary.getBinary()
    
    
    
    >>> elf
    
    
    <abf.elf.ELF instance at 0x7ff55c24c290>
    
    
    
    >>> hex(elf.header.e_entry)
    
    
    '0x4022bcL'
    
    
    
    >>> shdrs = elf.shdrs
    
    
    >>> for shdr in shdrs: 
    
    
    ... print hex(shdr.sh_addr)
    
    
    ... 
    
    
    0x0L
    
    
    0x400270L
    
    
    0x40028cL
    
    
    0x4002b0L
    
    
    0x400570L
    
    
    0x4005d0L
    
    
    0x400c18L
    
    
    0x400ebeL
    
    
    0x400f48L
    
    
    0x400f98L
    
    
    0x401028L
    
    
    0x4015b0L
    
    
    0x4015d0L
    
    
    0x401990L
    
    
    0x40536cL
    
    
    0x405380L
    
    
    0x40648cL
    
    
    0x4066f8L
    
    
    0x607df8L
    
    
    0x607e00L
    
    
    0x607e08L
    
    
    0x607e10L
    
    
    0x607ff0L
    
    
    0x608000L
    
    
    0x608200L
    
    
    0x6082a0L
    
    
    0x0L
    
    
    
    >>> binary = Abstract('./binaries/MachO-OSX-x86-ls') 
    
    
    >>> macho = binary.getBinary()
    
    
    >>> macho
    
    
    <abf.macho.MACHO instance at 0x7ff55c27bef0>
    
    
    >>> macho.header.cpusubtype 
    
    
    3L
    
    
    >>> hex(macho.header.flags) 
    
    
    '0x1200085L'
    
    
    >>> 
    
    
    
    

    特别感谢

    • 适用于python3兼容的Wannes Rombouts ( wapiflapi )。


    文章标签:MAN  for  mac  form  BIN  格式  MACH  Manipulation  

    Copyright © 2011 HelpLib All rights reserved.    知识分享协议 京ICP备05059198号-3  |  如果智培  |  酷兔英语