summaryrefslogtreecommitdiff
path: root/src/ukify
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2023-03-31 13:13:00 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2023-04-01 14:31:22 +0200
commit7f72dca7620fd4cbd50b483d419f074b912595ec (patch)
tree815fe65d92ee45256803c6b972967eb17a3b88ce /src/ukify
parent86c20937c29da637878a1282444b057bc1a519fb (diff)
downloadsystemd-7f72dca7620fd4cbd50b483d419f074b912595ec.tar.gz
ukify: Strip symbol/string table for old stubs
Diffstat (limited to 'src/ukify')
-rwxr-xr-xsrc/ukify/ukify.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py
index b847f2ed87..b319f2dc91 100755
--- a/src/ukify/ukify.py
+++ b/src/ukify/ukify.py
@@ -450,6 +450,19 @@ class PeError(Exception):
def pe_add_sections(uki: UKI, output: str):
pe = pefile.PE(uki.executable, fast_load=True)
+ # Old stubs do not have the symbol/string table stripped, even though image files should not have one.
+ if symbol_table := pe.FILE_HEADER.PointerToSymbolTable:
+ symbol_table_size = 18 * pe.FILE_HEADER.NumberOfSymbols
+ if string_table_size := pe.get_dword_from_offset(symbol_table + symbol_table_size):
+ symbol_table_size += string_table_size
+
+ # Let's be safe and only strip it if it's at the end of the file.
+ if symbol_table + symbol_table_size == len(pe.__data__):
+ pe.__data__ = pe.__data__[:symbol_table]
+ pe.FILE_HEADER.PointerToSymbolTable = 0
+ pe.FILE_HEADER.NumberOfSymbols = 0
+ pe.FILE_HEADER.IMAGE_FILE_LOCAL_SYMS_STRIPPED = True
+
# Old stubs might have been stripped, leading to unaligned raw data values, so let's fix them up here.
for i, section in enumerate(pe.sections):
oldp = section.PointerToRawData