namedstruct使用按名称访问的结果封装struct.unpack()

namedstruct的Python项目详细描述


模块名称结构

namedstruct用按名称访问的结果封装struct.unpack()和struct.pack()。

课程

class namedstruct.namedstruct

__init__( description, struct_definition )

The description is used to title a dump of unpacked data.

struct_definition is a single string that defines the type and name of each field as a space seperated list. Each field’s type and name are seperated by a “:”. If the name is left blank that field cannot be accessed by name, useful for padding fields. If a field’s type has a repeat count the value returned with be a tuple of all the fields parts.

len()

Returns the size of the struct.

解包(字节)

Unpack the bytes into a namestruct.namestructresults object used to access the decoded fields.

打包机(未打包=无)

Return a namedstructpacker object that can be used to pack the fields into a buffer. The optional from_unpacked will initialise the fields from a previously unpacked buffer.

类namedStruct.namedStructResults

.*name*

Returns the value of the field called name.

转储(写入程序)

Using the writer function to output a formatted dump of the whole struct.

类namedstruct.namedstructpacker

.*name* = value

Assign a value to the named field

初始化自(从未打包的)

Assign each field from a previous unpacked buffer’s namedstructresults.

pack()

Pack the fields and return the bytes buffer.

示例

import namedstruct

# Windows EXE files start with a DOS header
struct_windows_exe_header = namedstruct.namedstruct( 'DOS header', '<'
  '2s:dos_magic '
  'h:lastsize '
  'h:nblocks '
  'h:nreloc '
  'h:hdrsize '
  'h:minalloc '
  'h:maxalloc '
  'H:ss '
  'H:sp '
  'h:checksum '
  'H:ip '
  'H:cs '
  'h:relocpos '
  'h:noverlay '
  '4H:reserved1 '
  'h:oem_id '
  'h:oem_info '
  '10H:reserved2 '
  'L:pe_offset'
  )

dos_image = open( 'c:\\windows\\system32\\cmd.exe', 'rb' ).read()
header = struct_windows_exe_header.unpack( dos_image[0:len(struct_windows_exe_header)] )

if debug:
  header.dump( print )

print( 'dos_magic %r' % (header.dos_magic,) )
print( 'PE header offer: 0x%8.8x' % (header.pe_offset,) )

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
主类中的java访问方法   Javalog4j不读取它的log4j。属性文件   雅加达ee通过Java(web应用程序)使用iText/任何其他使用现成数据的库生成PDF报告   lua使用java阅读TeamSpeak 3消息   将日期转换为BST java   java Spring引用ProxyFactoryBean中带有ref的protoyype bean   如何使java只打印一条带有if语句的消息   java如何通过JavaMail从雅虎服务器发送电子邮件?   使用百分比和BigDecimal的java测试   java如何对字符串数组排序   java验证器+MVC+REST::更新问题   java如何阻止eclipse如此频繁地挂起?   java从AsyncTask(片段内)访问TextView   IDEJava:制作可调整大小和拖动的组件