Mercurial > touhou
comparison pytouhou/utils/pe.py @ 590:e15672733c93
Switch to Python 3.x instead of 2.7.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 30 Sep 2014 17:14:24 +0200 |
parents | 5afc75f71fed |
children | d1f0bb0b7a17 |
comparison
equal
deleted
inserted
replaced
589:0768122da817 | 590:e15672733c93 |
---|---|
63 def read_image_optional_header(cls, file): | 63 def read_image_optional_header(cls, file): |
64 format = Struct('<HBBIIIIIIIIIHHHHHHIIIIHHIIIIII') | 64 format = Struct('<HBBIIIIIIIIIHHHHHHIIIIHHIIIIII') |
65 directory_format = Struct('<II') | 65 directory_format = Struct('<II') |
66 directory = [] | 66 directory = [] |
67 partial_header = format.unpack(file.read(format.size)) | 67 partial_header = format.unpack(file.read(format.size)) |
68 directory = [cls._IMAGE_DATA_DIRECTORY(*directory_format.unpack(file.read(directory_format.size))) for i in xrange(16)] | 68 directory = [cls._IMAGE_DATA_DIRECTORY(*directory_format.unpack(file.read(directory_format.size))) for i in range(16)] |
69 return cls._IMAGE_OPTIONAL_HEADER(*(partial_header + (directory,))) | 69 return cls._IMAGE_OPTIONAL_HEADER(*(partial_header + (directory,))) |
70 | 70 |
71 _IMAGE_SECTION_HEADER = namedtuple('_IMAGE_SECTION_HEADER', | 71 _IMAGE_SECTION_HEADER = namedtuple('_IMAGE_SECTION_HEADER', |
72 ('Name', 'VirtualSize', | 72 ('Name', 'VirtualSize', |
73 'VirtualAddress', | 73 'VirtualAddress', |
103 | 103 |
104 # Read image base | 104 # Read image base |
105 self.image_base = pe_optional_header.ImageBase | 105 self.image_base = pe_optional_header.ImageBase |
106 | 106 |
107 self.sections = [PEStructs.read_image_section_header(file) | 107 self.sections = [PEStructs.read_image_section_header(file) |
108 for i in xrange(pe_file_header.NumberOfSections)] | 108 for i in range(pe_file_header.NumberOfSections)] |
109 | 109 |
110 | 110 |
111 def seek_to_va(self, va): | 111 def seek_to_va(self, va): |
112 self.file.seek(self.va_to_offset(va)) | 112 self.file.seek(self.va_to_offset(va)) |
113 | 113 |