Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4e50b33
Check BMP pixel data size when loading
Metabolix Nov 20, 2023
0dfc49c
Re-implement string formatting (%s, %d, %x)
Metabolix Nov 20, 2023
7dd0483
Use EFI BS FreePool, SetMem, CopyMem
Metabolix Nov 20, 2023
57ce3ae
Avoid using gnu-efi static global GUIDs
Metabolix Nov 20, 2023
a908036
Implement WaitKey without gnu-efi
Metabolix Nov 20, 2023
ebbacb7
Open ESP root dir without gnu-efi
Metabolix Nov 20, 2023
2a0f2a7
Get shell arguments without gnu-efi
Metabolix Nov 20, 2023
4379f9c
Add gnu-efi submodule for headers, don't link, just re-implement some…
Metabolix Nov 20, 2023
24c7e2b
Switch to Clang
Metabolix Nov 20, 2023
50e84e8
Add AArch64 target
Metabolix Nov 20, 2023
7ccdcc4
Add ARM (32-bit) target (without shim, though)
Metabolix Nov 20, 2023
8dfa456
Fix ARM (32-bit) build
Metabolix Nov 24, 2023
77dd2bd
If GOP is missing, use config.txt resolution or 1024x768
Metabolix Nov 25, 2023
aac8a38
Don't print HackBGRT on every output line
Metabolix Nov 25, 2023
5111897
Update Makefile (instructions, release)
Metabolix Nov 24, 2023
9ebe4e2
Add run-qemu-<arch> to Makefile
Metabolix Nov 24, 2023
6b724d5
Don't create entries higher than Boot00FF
Metabolix Nov 25, 2023
ba72b90
Add logging to verify entry creation
Metabolix Nov 25, 2023
b75dbe1
Update change log and tag v2.3.0
Metabolix Nov 27, 2023
74a143e
Make BitLocker detection more reliable
Metabolix Nov 27, 2023
835cc1b
Update change log and tag v2.3.1
Metabolix Nov 27, 2023
4096002
Update issue templates
Metabolix Dec 16, 2023
294da9c
Get rid of \EFI\HackBGRT\ in config.txt
Metabolix Dec 4, 2023
a82646a
Wipe the vendor logo as soon as possible
Metabolix Dec 8, 2023
7b7309a
Explain why the original logo is still visible
Metabolix Dec 17, 2023
5ec17a4
Detect ARM arch from MS loader
Metabolix Dec 19, 2023
6dc447a
Try to avoid some .Net Framework 4.8 features
Metabolix Dec 19, 2023
c6108ff
Warn about old .Net version if methods are missing
Metabolix Dec 16, 2023
518d7c8
Show proper message if boot log is empty
Metabolix Dec 20, 2023
9948e5a
Fix BCDEdit dry run and add more logging
Metabolix Dec 31, 2023
a44b929
Fix a shim error caused by bad load options data
Metabolix Dec 17, 2023
ea70f3c
Disable before enabling, and default to BCDEdit
Metabolix Dec 31, 2023
1a5b1df
Update change log and tag 2.4.0
Metabolix Dec 31, 2023
39596aa
Don't try to remove non-existent dir.
Metabolix Jan 20, 2024
f8763a4
Merge branch 'master' into feature/mod_multi_merge_master_240
FREEWING-JP Mar 17, 2024
fe2f9f3
resolve confict: Makefile
FREEWING-JP Mar 20, 2024
c052cfa
resolve confict: main.c
FREEWING-JP Mar 20, 2024
eec6a2f
mod Makefile
FREEWING-JP Mar 20, 2024
bd9637a
delete unused warning: expression result unused [-Wunused-value]
FREEWING-JP Mar 20, 2024
1dbf0cb
update my_efilib
FREEWING-JP Mar 20, 2024
efaef7c
patch picojpeg https://github.com/richgel999/picojpeg/pull/3
FREEWING-JP Mar 20, 2024
63ff638
Update README.md
FREEWING-JP Mar 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Bug report
about: Create a report if you encounter a bug
title: ''
labels: ''
assignees: ''

---

**What happens?**
Describe the bug.

**How this happens?**
Explain exactly the steps you did:
1. Download HackBGRT-(version).zip and extract all files.
2. Start setup.
3. Select ...
4. ...

**Log file**
Run the setup again and select menu option `L` (or add parameter `show-boot-log` on command line). Attach the `setup.log` to this report.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "gnu-efi"]
path = gnu-efi
url = https://github.com/rhboot/gnu-efi.git
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

All notable changes to this project will be documented in this file.

## 2.4.0 - 2023-12-31

### Fixed
- Fix BCDEdit boot entries to avoid *shim* error messages.
- Combine BCDEdit and own code to create boot entries more reliably.

### Changed
- Clear the screen to wipe the vendor logo as soon as possible.
- Image paths in `config.txt` may be relative (just file names).

## 2.3.1 - 2023-11-27

### Fixed
- BitLocker detection is more reliable.

## 2.3.0 - 2023-11-27

### Added
- AArch64 and ARM builds, and *shim* for AArch64.

### Fixed
- Boot entry is more reliable, avoids conflicts with firmware entries.

## 2.2.0 - 2023-11-17

### Added
Expand Down
226 changes: 130 additions & 96 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,101 +1,135 @@
# for Windows 10 WSL Debian build
# use Normal GCC
CROSS_COMPILE =
# PREFIX=/usr/local/
PREFIX = ./gnu-efi/usr/local/
TARGET = HackBGRT_MULTI_$(ARCH)
_OBJS = main.o config.o types.o util.o sbat.o
_OBJS += picojpeg.o
_OBJS += upng.o
_OBJS += my_efilib.o
ODIR = obj
SDIR = src
OBJS = $(patsubst %,$(ODIR)/%,$(_OBJS))
ARCH = x86_64

CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJCOPY = $(CROSS_COMPILE)objcopy

# Linker script
LDSCRIPT = $(PREFIX)/lib/elf_$(ARCH)_efi.lds
# PE header and startup code
STARTOBJ = $(PREFIX)/lib/crt0-efi-$(ARCH).o
# include header
EFI_INCLUDE = $(PREFIX)/include/efi/
INCLUDES = -I. \
-I$(EFI_INCLUDE) \
-I$(EFI_INCLUDE)/$(ARCH) \
-I$(EFI_INCLUDE)/protocol

# CFLAGS
CFLAGS = -std=c11 -O2 -ffreestanding -mno-red-zone -fno-stack-protector \
-Wshadow -Wall -Wunused -Werror-implicit-function-declaration \
-DCONFIG_$(GNUEFI_ARCH) -DGNU_EFI_USE_MS_ABI \
-fpic -D__KERNEL__ \
-maccumulate-outgoing-args \
-fshort-wchar -fno-strict-aliasing \
-fno-merge-all-constants -fno-stack-check
# -Werror
GIT_DESCRIBE = $(firstword $(shell git describe --tags) unknown)
CC = clang
CFLAGS = -target $(CLANG_TARGET) -ffreestanding -fshort-wchar
CFLAGS += -std=c17 -Wshadow -Wall -Wunused -Werror-implicit-function-declaration
CFLAGS += -I$(GNUEFI_INC) -I$(GNUEFI_INC)/$(GNUEFI_ARCH) -I$(GNUEFI_INC)/protocol
CFLAGS += $(ARCH_CFLAGS)
LDFLAGS = -target $(CLANG_TARGET) -nostdlib -Wl,-entry:efi_main -Wl,-subsystem:efi_application -fuse-ld=lld
ARCH_CFLAGS = -O2 -mno-red-zone

GNUEFI_INC = gnu-efi/inc

FILES_C = src/main.c src/util.c src/types.c src/config.c src/sbat.c src/efi.c
FILES_C += $(wildcard picojpeg/picojpeg.c)
FILES_C += $(wildcard upng/upng.c)
FILES_C += $(wildcard my_efilib/my_efilib.c)
FILES_H = $(wildcard src/*.h)
# */
FILES_H += $(wildcard picojpeg/picojpeg.h)
FILES_H += $(wildcard upng/upng.h)
FILES_H += $(wildcard my_efilib/my_efilib.h)
FILES_CS = src/Setup.cs src/Esp.cs src/Efi.cs
GIT_DESCRIBE := $(firstword $(GIT_DESCRIBE) $(shell git describe --tags) unknown)
CFLAGS += '-DGIT_DESCRIBE_W=L"$(GIT_DESCRIBE)"' '-DGIT_DESCRIBE="$(GIT_DESCRIBE)"'
RELEASE_NAME = HackBGRT-$(GIT_DESCRIBE:v%=%)

# EFI_ARCH_LIST = x64 ia32 aa64 arm
EFI_ARCH_LIST = x64
EFI_SIGNED_FILES = $(patsubst %,efi-signed/boot%.efi,$(EFI_ARCH_LIST))

.PHONY: all efi efi-signed setup release clean

# all: efi setup
all: efi
@echo "Run 'make efi-signed' to sign the EFI executables."
@echo "Run 'make release' to build a release-ready ZIP archive."
@echo "Run 'make run-qemu-<arch>' to test the EFI executables with QEMU."

efi: $(patsubst %,efi/boot%.efi,$(EFI_ARCH_LIST))
@echo "EFI executables are in the efi/ directory."

efi-signed: $(patsubst %,efi-signed/boot%.efi,$(EFI_ARCH_LIST))
@echo "Signed EFI executables are in the efi-signed/ directory."

setup: setup.exe

release: release/$(RELEASE_NAME).zip
@echo "Current version is packaged: $<"

release/$(RELEASE_NAME): $(EFI_SIGNED_FILES) certificate.cer config.txt splash.bmp setup.exe README.md CHANGELOG.md README.efilib LICENSE shim-signed/* shim.md
rm -rf $@
tar c --transform=s,^,$@/, $^ | tar x

# */
release/$(RELEASE_NAME).zip: release/$(RELEASE_NAME)
rm -rf $@
(cd release; 7z a -mx=9 "$(RELEASE_NAME).zip" "$(RELEASE_NAME)" -bd -bb1)

src/GIT_DESCRIBE.cs: $(FILES_CS) $(FILES_C) $(FILES_H)
echo 'public class GIT_DESCRIBE { public const string data = "$(GIT_DESCRIBE)"; }' > $@

setup.exe: $(FILES_CS) src/GIT_DESCRIBE.cs
csc /nologo /define:GIT_DESCRIBE /out:$@ $^

certificate.cer pki:
@echo
@echo "You need proper keys to sign the EFI executables."
@echo "Example:"
@echo "mkdir -p pki"
@echo "certutil --empty-password -N -d pki"
@echo "efikeygen -d pki -n HackBGRT-signer -S -k -c 'CN=HackBGRT Secure Boot Signer,OU=HackBGRT,O=Unknown,MAIL=unknown@example.com' -u 'URL'"
@echo "certutil -d pki -n HackBGRT-signer -Lr > certificate.cer"
@echo "Modify and run the commands yourself."
@echo
@false

efi-signed/%.efi: efi/%.efi pki
@mkdir -p efi-signed
pesign --force -n pki -i $< -o $@ -c HackBGRT-signer -s

efi/bootx64.efi: CLANG_TARGET = x86_64-pc-windows-msvc
efi/bootx64.efi: GNUEFI_ARCH = x86_64

efi/bootia32.efi: CLANG_TARGET = i386-pc-windows-msvc
efi/bootia32.efi: GNUEFI_ARCH = ia32

efi/bootaa64.efi: CLANG_TARGET = aarch64-pc-windows-msvc
efi/bootaa64.efi: GNUEFI_ARCH = aa64

efi/boot%.efi: $(FILES_C)
@mkdir -p efi
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@

efi/bootarm.efi: CLANG_TARGET = armv6-pc-windows-msvc
efi/bootarm.efi: GNUEFI_ARCH = arm
efi/bootarm.efi: ARCH_CFLAGS = -O # skip -O2 and -mno-red-zone
efi/bootarm.efi: $(FILES_C)
@mkdir -p efi
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
@echo "Fix $@ architecture code (IMAGE_FILE_MACHINE_ARMTHUMB_MIXED = 0x01C2)"
echo -en "\xc2\x01" | dd of=$@ bs=1 seek=124 count=2 conv=notrunc status=none

# LDFLAGS
LDFLAGS = -nostdlib --warn-common --no-undefined \
--fatal-warnings --build-id=sha1 \
-shared -Bsymbolic
# set EFI_SUBSYSTEM: Application(0x0a)
LDFLAGS += --defsym=EFI_SUBSYSTEM=0x0a
LDFLAGS += -L$(PREFIX)/lib
# ld: warning: ./gnu-efi/usr/local//lib/crt0-efi-x86_64.o: missing .note.GNU-stack section implies executable stack
# ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
LDFLAGS += -z noexecstack


####### rules #########

all: $(TARGET).efi

# rebuild shared object to PE binary
$(TARGET).efi: $(TARGET).so
$(OBJCOPY) \
-j .text \
-j .sdata \
-j .data \
-j .dynamic \
-j .dynsym \
-j .rel \
-j .rela \
-j .rel.* \
-j .rela.* \
-j .rel* \
-j .rela* \
-j .reloc \
-O binary \
--target efi-app-$(ARCH) \
$(TARGET).so $@

# build shared object
$(TARGET).so: $(OBJS)
$(LD) $(LDFLAGS) $(STARTOBJ) $^ -o $@ \
-lefi -lgnuefi \
-T $(LDSCRIPT)

./obj/%.o: ./src/%.c
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

# PNG upng
./obj/%.o: ./upng/%.c
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

# JPEG picojpeg
./obj/%.o: ./picojpeg/%.c
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

# my_efilib
./obj/%.o: ./my_efilib/%.c
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@

# clean rule
clean:
rm -f ./obj/*.o *.so s*.efi
rm -rf setup.exe efi efi-signed
rm -f src/GIT_DESCRIBE.cs
rm -rf release
rm -rf test

.PHONY: test $(patsubst %,run-qemu-%,$(EFI_ARCH_LIST))

test: run-qemu-x64
@echo "Run 'make run-qemu-<arch>' to test other architectures."

test/esp-%: efi/boot%.efi splash.bmp
rm -rf $@
mkdir -p $@/EFI/HackBGRT
cp efi/boot$*.efi splash.bmp $@/EFI/HackBGRT
echo -en "FS0:\n cd EFI\n cd HackBGRT\n boot$*.efi resolution=-1x-1 debug=1 image=path=splash.bmp" > $@/startup.nsh

QEMU_ARGS = -bios $(word 2, $^) -net none -drive media=disk,file=fat:rw:./$<,format=raw

run-qemu-x64: test/esp-x64 /usr/share/ovmf/x64/OVMF.fd
qemu-system-x86_64 $(QEMU_ARGS)

run-qemu-ia32: test/esp-ia32 /usr/share/ovmf/ia32/OVMF.fd
qemu-system-i386 $(QEMU_ARGS)

run-qemu-aa64: test/esp-aa64 /usr/share/ovmf/aarch64/QEMU_EFI.fd
@echo "Press Ctrl+Alt+2 to switch to QEMU console."
qemu-system-aarch64 -machine virt -cpu max $(QEMU_ARGS)

run-qemu-arm: test/esp-arm /usr/share/ovmf/arm/QEMU_EFI.fd
@echo "Press Ctrl+Alt+2 to switch to QEMU console."
qemu-system-arm -machine virt -cpu max $(QEMU_ARGS)

13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# FREE WING mod version 2020/11 to 2023/11
# FREE WING mod version 2020/11 to 2024/03
.|.|.|.
---|---|---|---
2023/10|v2.1.0| [Merge master Metabolix Update change log and tag v2.1.0 da9909b #7](https://github.com/FREEWING-JP/HackBGRT/pull/7) | ---
2023/11|v2.2.0| [Merge master Metabolix Update change log and tag v2.2.0 5856d25 #9](https://github.com/FREEWING-JP/HackBGRT/pull/9) | Works fine
2024/03|v2.4.0| [Merge master Metabolix Update change log and tag v2.4.0 1a5b1df #10](https://github.com/FREEWING-JP/HackBGRT/pull/10) | Works fine

## HackBGRT_MULTI
* Support PNG format image file
Expand Down Expand Up @@ -67,6 +68,8 @@ HackBGRT is intended as a boot logo changer for UEFI-based Windows systems.

When booting on a UEFI-based computer, Windows may show a vendor-defined logo which is stored on the UEFI firmware in a section called Boot Graphics Resource Table (BGRT). It's usually very difficult to change the image permanently, but a custom UEFI application may be used to overwrite it during the boot. HackBGRT does exactly that.

**Note:** The original logo is often visible for a moment before HackBGRT is started. This is expected, please do not report this "bug". This can't be changed without modifying computer firmware, which this project will not do.

## Usage

**Important:** If you mess up the installation, your system may become unbootable! Create a rescue disk before use. This software comes with no warranty. Use at your own risk.
Expand Down Expand Up @@ -131,20 +134,18 @@ The configuration options are described in `config.txt`, which the installer cop

## Images

The image path can be changed in the configuration file. The default path is `[EFI System Partition]\EFI\HackBGRT\splash.bmp`.
If you only need one image, just edit `splash.bmp` to your needs.

The installer copies and converts files whose `path` starts with `\EFI\HackBGRT\`. For example, to use a file named `my.jpg`, copy it in the installer folder (same folder as `setup.exe`) and set the image path in `config.txt` to `path=\EFI\HackBGFT\my.jpg`.
Advanced users may edit the `config.txt` to define multiple images, in which case one is picked at random. The installer copies and converts the images. For example, to use a file named `my.jpg`, copy it in the installer folder (same folder as `setup.exe`) and set the image path in `config.txt` to `path=my.jpg` before running the installer.

If you copy an image file to ESP manually, note that the image must be a 24-bit BMP file with a 54-byte header. That's a TrueColor BMP3 in Imagemagick, or 24-bit BMP/DIB in Microsoft Paint.

Advanced users may edit the `config.txt` to define multiple images, in which case one is picked at random.

## Recovery

If something breaks and you can't boot to Windows, you need to use the Windows installation disk (or recovery disk) to fix boot issues.

## Building

* Compiler: GCC targeting w64-mingw32
* Compiler: Clang
* Compiler flags: see Makefile
* Libraries: gnu-efi
14 changes: 6 additions & 8 deletions config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,22 @@ boot=MS
# - "keep" to keep the firmware logo. Also keeps coordinates by default.
# - "remove" to remove the BGRT. Makes x and y meaningless.
# - "black" to use only a black image. Makes x and y meaningless.
# - "path=..." to read a BMP file.
# * NOTE: For path=\EFI\HackBGRT\*, the installer will copy and convert the file if necessary.
# * NOTE: For other paths, make sure that the file is a 24-bit BMP file with a 54-byte header.
# * NOTE: The file must be on the EFI System Partition. Do not add a drive letter!
# - "path=file.bmp" to read an image file.
# * NOTE: The installer can copy and convert BMP, PNG, JPEG, GIF.
# Examples:
# - image=remove
# - image=black
# - image= x=0 y=-200 path=\EFI\HackBGRT\topimage.bmp
# - image= n=1 o=90 path=\EFI\HackBGRT\sideways.bmp
# - image= n=50 y=999999 o=keep path=\EFI\HackBGRT\probable.bmp
# - image= x=0 y=-200 path=topimage.bmp
# - image= n=1 o=90 path=sideways.bmp
# - image= n=50 y=999999 o=keep path=probable.bmp
# The above examples together would produce
# - 1/54 chance for the default OS logo
# - 1/54 chance for black screen
# - 1/54 chance for topimage.bmp, 200 px above the center of the screen
# - 1/54 chance for splash.bmp, centered, orientation set to 90 degrees
# - 50/54 chance for probable.bmp, at the bottom edge, explicitly default orientation
# Default: just one image.
image= y=-200 path=\EFI\HackBGRT\splash.bmp
image= y=-200 path=splash.bmp

# Preferred resolution. Use 0x0 for maximum and -1x-1 for original.
resolution=0x0
Expand Down
1 change: 1 addition & 0 deletions gnu-efi
Submodule gnu-efi added at 965f55
9 changes: 8 additions & 1 deletion my_efilib/my_efilib.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "my_efilib.h"

extern EFI_BOOT_SERVICES *BS;

// #include <stdlib.h>
// Memory Allocation
void *malloc(size_t size) {
Expand All @@ -20,7 +22,7 @@ void *calloc(size_t nmemb, size_t size) {
}

void free(void *ptr) {
FreePool(ptr);
BS->FreePool(ptr);
}

void *realloc(void *ptr, size_t size) {
Expand All @@ -46,3 +48,8 @@ int memcmp(const void *cs, const void *ct, size_t count) {
return res;
}

// lld-link: error: undefined symbol: __chkstk
void __chkstk(void *ptr) {
;
}

Loading