mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 20:23:34 +00:00
[SDK] Make gen_baseaddress.py compatible with Python 3.
This commit is contained in:
parent
e400519cb5
commit
5e6810d5d2
1 changed files with 14 additions and 14 deletions
|
@ -4,7 +4,7 @@ LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||||
PURPOSE: Update baseaddresses of all modules
|
PURPOSE: Update baseaddresses of all modules
|
||||||
COPYRIGHT: Copyright 2017,2018 Mark Jansen (mark.jansen@reactos.org)
|
COPYRIGHT: Copyright 2017,2018 Mark Jansen (mark.jansen@reactos.org)
|
||||||
'''
|
'''
|
||||||
|
from __future__ import print_function, absolute_import, division
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
@ -12,9 +12,9 @@ import sys
|
||||||
try:
|
try:
|
||||||
import pefile
|
import pefile
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print '# Please install pefile from pip or https://github.com/erocarrera/pefile'
|
print('# Please install pefile from pip or https://github.com/erocarrera/pefile')
|
||||||
print '# Using fallback'
|
print('# Using fallback')
|
||||||
print
|
print()
|
||||||
|
|
||||||
ALL_EXTENSIONS = (
|
ALL_EXTENSIONS = (
|
||||||
'.dll', '.acm', '.ax', '.cpl', '.drv', '.ocx'
|
'.dll', '.acm', '.ax', '.cpl', '.drv', '.ocx'
|
||||||
|
@ -194,18 +194,18 @@ EXCLUDE = (
|
||||||
def size_of_image_fallback(filename):
|
def size_of_image_fallback(filename):
|
||||||
with open(filename, 'rb') as fin:
|
with open(filename, 'rb') as fin:
|
||||||
if fin.read(2) != 'MZ':
|
if fin.read(2) != 'MZ':
|
||||||
print filename, 'No dos header found!'
|
print(filename, 'No dos header found!')
|
||||||
return 0
|
return 0
|
||||||
fin.seek(0x3C)
|
fin.seek(0x3C)
|
||||||
e_lfanew = struct.unpack('i', fin.read(4))[0]
|
e_lfanew = struct.unpack('i', fin.read(4))[0]
|
||||||
fin.seek(e_lfanew)
|
fin.seek(e_lfanew)
|
||||||
if fin.read(4) != 'PE\0\0':
|
if fin.read(4) != 'PE\0\0':
|
||||||
print filename, 'No PE header found!'
|
print(filename, 'No PE header found!')
|
||||||
return 0
|
return 0
|
||||||
fin.seek(e_lfanew + 0x18)
|
fin.seek(e_lfanew + 0x18)
|
||||||
pe_magic = struct.unpack('h', fin.read(2))[0]
|
pe_magic = struct.unpack('h', fin.read(2))[0]
|
||||||
if pe_magic != 0x10b:
|
if pe_magic != 0x10b:
|
||||||
print filename, 'is not a 32 bit exe!'
|
print(filename, 'is not a 32 bit exe!')
|
||||||
return 0
|
return 0
|
||||||
fin.seek(e_lfanew + 0x50)
|
fin.seek(e_lfanew + 0x50)
|
||||||
pe_size_of_image = struct.unpack('i', fin.read(4))[0]
|
pe_size_of_image = struct.unpack('i', fin.read(4))[0]
|
||||||
|
@ -233,7 +233,7 @@ class Module(object):
|
||||||
postfix = ' # should be above 0x%08x' % self.address
|
postfix = ' # should be above 0x%08x' % self.address
|
||||||
elif self._reserved:
|
elif self._reserved:
|
||||||
postfix = ' # reserved'
|
postfix = ' # reserved'
|
||||||
print 'set(baseaddress_%-30s 0x%08x)%s' % (name, self.address, postfix)
|
print('set(baseaddress_%-30s 0x%08x)%s' % (name, self.address, postfix))
|
||||||
|
|
||||||
def end(self):
|
def end(self):
|
||||||
return self.address + self.size
|
return self.address + self.size
|
||||||
|
@ -276,7 +276,7 @@ class MemoryLayout(object):
|
||||||
current_start = self._next_address(size)
|
current_start = self._next_address(size)
|
||||||
current_end = current_start + size + self.module_padding
|
current_end = current_start + size + self.module_padding
|
||||||
# Is there overlap with reserved modules?
|
# Is there overlap with reserved modules?
|
||||||
for key, reserved in self.reserved.iteritems():
|
for key, reserved in self.reserved.items():
|
||||||
res_start = reserved[0]
|
res_start = reserved[0]
|
||||||
res_end = res_start + reserved[1] + self.module_padding
|
res_end = res_start + reserved[1] + self.module_padding
|
||||||
if (res_start <= current_start <= res_end) or \
|
if (res_start <= current_start <= res_end) or \
|
||||||
|
@ -293,11 +293,11 @@ class MemoryLayout(object):
|
||||||
|
|
||||||
def update(self, priorities):
|
def update(self, priorities):
|
||||||
# sort addresses, should only contain reserved modules at this point!
|
# sort addresses, should only contain reserved modules at this point!
|
||||||
for key, reserved in self.reserved.iteritems():
|
for key, reserved in self.reserved.items():
|
||||||
assert reserved[1] != 0, key
|
assert reserved[1] != 0, key
|
||||||
for curr in priorities:
|
for curr in priorities:
|
||||||
if not curr in self.found:
|
if not curr in self.found:
|
||||||
print '# Did not find', curr, '!'
|
print('# Did not find', curr, '!')
|
||||||
else:
|
else:
|
||||||
obj = self.found[curr]
|
obj = self.found[curr]
|
||||||
del self.found[curr]
|
del self.found[curr]
|
||||||
|
@ -315,8 +315,8 @@ class MemoryLayout(object):
|
||||||
obj.gen_baseaddress()
|
obj.gen_baseaddress()
|
||||||
|
|
||||||
def run_dir(target):
|
def run_dir(target):
|
||||||
print '# Generated from', target
|
print('# Generated from', target)
|
||||||
print '# Generated by sdk/tools/gen_baseaddress.py'
|
print('# Generated by sdk/tools/gen_baseaddress.py')
|
||||||
layout = MemoryLayout(0x7c920000)
|
layout = MemoryLayout(0x7c920000)
|
||||||
layout.add_reserved('user32.dll', 0x77a20000)
|
layout.add_reserved('user32.dll', 0x77a20000)
|
||||||
for root, _, files in os.walk(target):
|
for root, _, files in os.walk(target):
|
||||||
|
@ -329,7 +329,7 @@ def run_dir(target):
|
||||||
def main(dirs):
|
def main(dirs):
|
||||||
if len(dirs) < 1:
|
if len(dirs) < 1:
|
||||||
trydir = os.getcwd()
|
trydir = os.getcwd()
|
||||||
print '# No path specified, trying', trydir
|
print('# No path specified, trying', trydir)
|
||||||
dirs = [trydir]
|
dirs = [trydir]
|
||||||
for onedir in dirs:
|
for onedir in dirs:
|
||||||
run_dir(onedir)
|
run_dir(onedir)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue