From 5b406be13e3e0d8745908d3c0468c1d06b5b9eaa Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Fri, 28 May 2021 10:29:12 +0200 Subject: [PATCH] build: Fixup PE section headers. For FH4. --- build/makefile_base.mak | 8 ++++++-- make/pefixup.py | 25 +++++++++++++++++++++++++ make/rules-common.mk | 6 ++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100755 make/pefixup.py diff --git a/build/makefile_base.mak b/build/makefile_base.mak index 2e28c066..ddece3c6 100644 --- a/build/makefile_base.mak +++ b/build/makefile_base.mak @@ -367,12 +367,16 @@ redist: dist | $(filter-out dist deploy install redist,$(MAKECMDGOALS)) module32: private SHELL := $(CONTAINER_SHELL) module32: CONTAINERGOALS := $(CONTAINERGOALS) wine-configure32 module32: | all-source wine-configure32 - +$(MAKE) -j$(J) $(filter -j%,$(MAKEFLAGS)) $(MFLAGS) $(MAKEOVERRIDES) -C $(WINE_OBJ32)/dlls/$(module) + +$(MAKE) -j$(J) $(filter -j%,$(MAKEFLAGS)) $(MFLAGS) $(MAKEOVERRIDES) -C $(WINE_OBJ32)/dlls/$(module) && \ + find $(WINE_OBJ32)/dlls/$(module) -type f -name '*.dll' -printf '%p\0' | \ + xargs --verbose -0 -r -P$(J) -n1 $(SRC)/make/pefixup.py module64: private SHELL := $(CONTAINER_SHELL) module64: CONTAINERGOALS := $(CONTAINERGOALS) wine-configure64 module64: | all-source wine-configure64 - +$(MAKE) -j$(J) $(filter -j%,$(MAKEFLAGS)) $(MFLAGS) $(MAKEOVERRIDES) -C $(WINE_OBJ64)/dlls/$(module) + +$(MAKE) -j$(J) $(filter -j%,$(MAKEFLAGS)) $(MFLAGS) $(MAKEOVERRIDES) -C $(WINE_OBJ64)/dlls/$(module) && \ + find $(WINE_OBJ64)/dlls/$(module) -type f -name '*.dll' -printf '%p\0' | \ + xargs --verbose -0 -r -P$(J) -n1 $(SRC)/make/pefixup.py module: CONTAINERGOALS := $(CONTAINERGOALS) wine-configure module: | all-source wine-configure diff --git a/make/pefixup.py b/make/pefixup.py new file mode 100755 index 00000000..5d6d727f --- /dev/null +++ b/make/pefixup.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import sys +import os +import stat +import pefile + +for path in sys.argv[1:]: + pe = pefile.PE(path) + + for section in pe.sections: + if section.Name.decode("utf-8")[0:5] == ".text": + section.Characteristics &= ~pefile.SECTION_CHARACTERISTICS['IMAGE_SCN_CNT_INITIALIZED_DATA'] + section.Characteristics &= ~pefile.SECTION_CHARACTERISTICS['IMAGE_SCN_ALIGN_MASK'] + + pe.OPTIONAL_HEADER.CheckSum = pe.generate_checksum() + + perm = stat.S_IMODE(os.stat(path).st_mode) + if (perm & stat.S_IWUSR) == 0: + os.chmod(path, perm | stat.S_IWUSR) + + pe.write(path) + + if (perm & stat.S_IWUSR) == 0: + os.chmod(path, perm) diff --git a/make/rules-common.mk b/make/rules-common.mk index 0ec68c61..481b3100 100644 --- a/make/rules-common.mk +++ b/make/rules-common.mk @@ -63,6 +63,9 @@ $$(OBJ)/.$(1)-dist$(3): cd $$($(2)_LIBDIR$(3)) && find -type f -not '(' -iname '*.pc' -or -iname '*.cmake' -or -iname '*.a' -or -iname '*.def' ')' \ -printf '--add-gnu-debuglink=$$(DST_LIBDIR$(3))/%p.debug\0--strip-debug\0%p\0$$(DST_LIBDIR$(3))/%p\0' | \ xargs --verbose -0 -r -P8 -n4 objcopy --file-alignment=4096 + cd $$($(2)_LIBDIR$(3)) && find -type f -name '*.dll' \ + -printf '$$(DST_LIBDIR$(3))/%p\0' | \ + xargs --verbose -0 -r -P8 -n1 $$(SRC)/make/pefixup.py touch $$@ else $$(OBJ)/.$(1)-dist$(3): @@ -75,6 +78,9 @@ $$(OBJ)/.$(1)-dist$(3): cd $$($(2)_LIBDIR$(3)) && find -type f -not '(' -iname '*.pc' -or -iname '*.cmake' -or -iname '*.a' -or -iname '*.def' ')' \ -printf '--strip-debug\0%p\0$$(DST_LIBDIR$(3))/%p\0' | \ xargs --verbose -0 -r -P8 -n3 objcopy --file-alignment=4096 + cd $$($(2)_LIBDIR$(3)) && find -type f -name '*.dll' \ + -printf '$$(DST_LIBDIR$(3))/%p\0' | \ + xargs --verbose -0 -r -P8 -n1 $$(SRC)/make/pefixup.py touch $$@ endif endif