Skip to content

Commit

Permalink
If genpeimg is missing, use python3-pefile to add NX compat
Browse files Browse the repository at this point in the history
  • Loading branch information
superm1 committed Jan 26, 2023
1 parent c24b084 commit 81164c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions contrib/fwupd-efi.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ExclusiveArch: x86_64 aarch64
BuildRequires: meson
BuildRequires: gnu-efi-devel
BuildRequires: pesign
BuildRequires: python3-pefile

%description
fwupd is a daemon to allow session software to update device firmware, and this
Expand Down
18 changes: 18 additions & 0 deletions efi/generate_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ def _run_genpeimg(args):
sys.exit(1)


def _add_nx_pefile(args):
# unnecessary if we have genpeimg
if args.genpeimg:
return
try:
import pefile
except ImportError:
print("Unable to add NX support to binaries without genpeimg or python3-pefile")
sys.exit(1)

pe = pefile.PE(args.outfile)
pe.OPTIONAL_HEADER.DllCharacteristics |= pefile.DLL_CHARACTERISTICS[
"IMAGE_DLLCHARACTERISTICS_NX_COMPAT"
]
pe.write(args.outfile)


if __name__ == "__main__":

parser = argparse.ArgumentParser()
Expand All @@ -85,5 +102,6 @@ def _run_genpeimg(args):
_args = parser.parse_args()
_run_objcopy(_args)
_run_genpeimg(_args)
_add_nx_pefile(_args)

sys.exit(0)

0 comments on commit 81164c8

Please sign in to comment.