Skip to content

Instantly share code, notes, and snippets.

@Cojad
Last active June 9, 2021 23:19
Show Gist options
  • Save Cojad/cc1c7b4160f2f5b22331b7b7dc1c5a51 to your computer and use it in GitHub Desktop.
Save Cojad/cc1c7b4160f2f5b22331b7b7dc1c5a51 to your computer and use it in GitHub Desktop.
tiny exe to detect uefi/legacy boot
/*
Orignal Detect UEFI/Legacy https://github.com/xcat2/xcat-core/blob/master/xCAT-server/share/xcat/netboot/windows/detectefi.cpp
Reduce binary size method https://www.jianshu.com/p/6b675c99fb49
Other ways to detect UEFI/Legacy http://bbs.c3.wuyou.net/forum.php?mod=viewthread&tid=413675
*/
#include <windows.h>
#include <stdio.h>
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"ucrt.lib")
#pragma comment(linker, "/align:16")
#pragma comment(linker, "/subsystem:console")
#pragma comment(linker, "/ENTRY:main")
void main()
{
GetFirmwareEnvironmentVariableA("","{00000000-0000-0000-0000-000000000000}",NULL,0);
if (GetLastError() == ERROR_INVALID_FUNCTION) { // This.. is.. LEGACY BIOOOOOOOOS....
printf("Legacy");
ExitProcess(1);
} else {
printf("UEFI");
ExitProcess(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment