fixed some issues with finding bootmgfw...

merge-requests/1/merge
xerox 4 years ago
parent dfbbf14ff6
commit 615e624c7b

@ -136,7 +136,6 @@ EFI_DEVICE_PATH* EFIAPI GetBootMgfwPath(VOID)
UINTN HandleCount = NULL; UINTN HandleCount = NULL;
EFI_STATUS Result; EFI_STATUS Result;
EFI_HANDLE* Handles = NULL; EFI_HANDLE* Handles = NULL;
EFI_DEVICE_PATH* DevicePath = NULL;
EFI_FILE_HANDLE VolumeHandle; EFI_FILE_HANDLE VolumeHandle;
EFI_FILE_HANDLE BootMgfwHandle; EFI_FILE_HANDLE BootMgfwHandle;
EFI_FILE_IO_INTERFACE* FileSystem = NULL; EFI_FILE_IO_INTERFACE* FileSystem = NULL;
@ -144,34 +143,36 @@ EFI_DEVICE_PATH* EFIAPI GetBootMgfwPath(VOID)
if (EFI_ERROR((Result = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &HandleCount, &Handles)))) if (EFI_ERROR((Result = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &HandleCount, &Handles))))
{ {
Print(L"error getting file system handles -> 0x%p\n", Result); Print(L"error getting file system handles -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
for (UINT32 Idx = 0u; Idx < HandleCount && !FileSystem; ++Idx) for (UINT32 Idx = 0u; Idx < HandleCount; ++Idx)
{ {
if (EFI_ERROR((Result = gBS->OpenProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, (VOID**)&FileSystem, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL)))) if (EFI_ERROR((Result = gBS->OpenProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, (VOID**)&FileSystem, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL))))
{ {
Print(L"error opening protocol -> 0x%p\n", Result); Print(L"error opening protocol -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
if (EFI_ERROR((Result = FileSystem->OpenVolume(FileSystem, &VolumeHandle)))) if (EFI_ERROR((Result = FileSystem->OpenVolume(FileSystem, &VolumeHandle))))
{ {
Print(L"error opening file system -> 0x%p\n", Result); Print(L"error opening file system -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
if (!EFI_ERROR(VolumeHandle->Open(VolumeHandle, &BootMgfwHandle, WINDOWS_BOOTMGFW_PATH, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY))) if (!EFI_ERROR(VolumeHandle->Open(VolumeHandle, &BootMgfwHandle, WINDOWS_BOOTMGFW_PATH, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY)))
DevicePath = FileDevicePath(Handles[Idx], WINDOWS_BOOTMGFW_PATH); {
VolumeHandle->Close(BootMgfwHandle);
return FileDevicePath(Handles[Idx], WINDOWS_BOOTMGFW_PATH);
}
VolumeHandle->Close(BootMgfwHandle);
if (EFI_ERROR((Result = gBS->CloseProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, gImageHandle, NULL)))) if (EFI_ERROR((Result = gBS->CloseProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, gImageHandle, NULL))))
{ {
Print(L"error closing protocol -> 0x%p\n", Result); Print(L"error closing protocol -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
} }
return DevicePath; return NULL;
} }
EFI_STATUS EFIAPI InstallBootMgfwHooks(EFI_HANDLE ImageHandle) EFI_STATUS EFIAPI InstallBootMgfwHooks(EFI_HANDLE ImageHandle)
@ -192,9 +193,6 @@ EFI_STATUS EFIAPI InstallBootMgfwHooks(EFI_HANDLE ImageHandle)
START_BOOT_APPLICATION_MASK START_BOOT_APPLICATION_MASK
); );
if (!ArchStartBootApplication)
return EFI_ABORTED;
Print(L"BootMgfw.ArchStartBootApplication -> 0x%p\n", ArchStartBootApplication); Print(L"BootMgfw.ArchStartBootApplication -> 0x%p\n", ArchStartBootApplication);
MakeShitHook(&BootMgfwShitHook, RESOLVE_RVA(ArchStartBootApplication, 5, 1), &ArchStartBootApplicationHook, TRUE); MakeShitHook(&BootMgfwShitHook, RESOLVE_RVA(ArchStartBootApplication, 5, 1), &ArchStartBootApplicationHook, TRUE);
return EFI_SUCCESS; return EFI_SUCCESS;
@ -214,6 +212,7 @@ EFI_STATUS EFIAPI ArchStartBootApplicationHook(VOID* AppEntry, VOID* ImageBase,
gST->ConOut->ClearScreen(gST->ConOut); gST->ConOut->ClearScreen(gST->ConOut);
gST->ConOut->OutputString(gST->ConOut, AsciiArt); gST->ConOut->OutputString(gST->ConOut, AsciiArt);
Print(L"\n"); Print(L"\n");
Print(L"PE PayLoad Size -> 0x%x\n", PayLoadSize()); Print(L"PE PayLoad Size -> 0x%x\n", PayLoadSize());
Print(L"winload.BlImgLoadPEImageEx -> 0x%p\n", RESOLVE_RVA(ImgLoadPEImageEx, 5, 1)); Print(L"winload.BlImgLoadPEImageEx -> 0x%p\n", RESOLVE_RVA(ImgLoadPEImageEx, 5, 1));

@ -136,7 +136,6 @@ EFI_DEVICE_PATH* EFIAPI GetBootMgfwPath(VOID)
UINTN HandleCount = NULL; UINTN HandleCount = NULL;
EFI_STATUS Result; EFI_STATUS Result;
EFI_HANDLE* Handles = NULL; EFI_HANDLE* Handles = NULL;
EFI_DEVICE_PATH* DevicePath = NULL;
EFI_FILE_HANDLE VolumeHandle; EFI_FILE_HANDLE VolumeHandle;
EFI_FILE_HANDLE BootMgfwHandle; EFI_FILE_HANDLE BootMgfwHandle;
EFI_FILE_IO_INTERFACE* FileSystem = NULL; EFI_FILE_IO_INTERFACE* FileSystem = NULL;
@ -144,34 +143,36 @@ EFI_DEVICE_PATH* EFIAPI GetBootMgfwPath(VOID)
if (EFI_ERROR((Result = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &HandleCount, &Handles)))) if (EFI_ERROR((Result = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &HandleCount, &Handles))))
{ {
Print(L"error getting file system handles -> 0x%p\n", Result); Print(L"error getting file system handles -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
for (UINT32 Idx = 0u; Idx < HandleCount && !FileSystem; ++Idx) for (UINT32 Idx = 0u; Idx < HandleCount; ++Idx)
{ {
if (EFI_ERROR((Result = gBS->OpenProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, (VOID**)&FileSystem, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL)))) if (EFI_ERROR((Result = gBS->OpenProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, (VOID**)&FileSystem, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL))))
{ {
Print(L"error opening protocol -> 0x%p\n", Result); Print(L"error opening protocol -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
if (EFI_ERROR((Result = FileSystem->OpenVolume(FileSystem, &VolumeHandle)))) if (EFI_ERROR((Result = FileSystem->OpenVolume(FileSystem, &VolumeHandle))))
{ {
Print(L"error opening file system -> 0x%p\n", Result); Print(L"error opening file system -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
if (!EFI_ERROR(VolumeHandle->Open(VolumeHandle, &BootMgfwHandle, WINDOWS_BOOTMGFW_PATH, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY))) if (!EFI_ERROR(VolumeHandle->Open(VolumeHandle, &BootMgfwHandle, WINDOWS_BOOTMGFW_PATH, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY)))
DevicePath = FileDevicePath(Handles[Idx], WINDOWS_BOOTMGFW_PATH); {
VolumeHandle->Close(BootMgfwHandle);
return FileDevicePath(Handles[Idx], WINDOWS_BOOTMGFW_PATH);
}
VolumeHandle->Close(BootMgfwHandle);
if (EFI_ERROR((Result = gBS->CloseProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, gImageHandle, NULL)))) if (EFI_ERROR((Result = gBS->CloseProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, gImageHandle, NULL))))
{ {
Print(L"error closing protocol -> 0x%p\n", Result); Print(L"error closing protocol -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
} }
return DevicePath; return NULL;
} }
EFI_STATUS EFIAPI InstallBootMgfwHooks(EFI_HANDLE BootMgfwPath) EFI_STATUS EFIAPI InstallBootMgfwHooks(EFI_HANDLE BootMgfwPath)

@ -27,7 +27,7 @@ EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable
return Result; return Result;
} }
// the payload is sitting on disk... we are going to load it into memory... // the payload is sitting on disk... we are going to load it into memory then delete it...
if (EFI_ERROR((Result = LoadPayLoadFromDisk(&PayLoad)))) if (EFI_ERROR((Result = LoadPayLoadFromDisk(&PayLoad))))
{ {
Print(L"failed to read payload from disk... reason -> %r\n", Result); Print(L"failed to read payload from disk... reason -> %r\n", Result);

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "ShitHook.h" #include "ShitHook.h"
#define WINVER 1709 #define WINVER 2004
#define PORT_NUM 0x2F8 #define PORT_NUM 0x2F8
#define BL_MEMORY_ATTRIBUTE_RWX 0x424000 #define BL_MEMORY_ATTRIBUTE_RWX 0x424000
#define SECTION_RWX (EFI_IMAGE_SCN_MEM_READ | EFI_IMAGE_SCN_MEM_WRITE | EFI_IMAGE_SCN_MEM_EXECUTE) #define SECTION_RWX (EFI_IMAGE_SCN_MEM_READ | EFI_IMAGE_SCN_MEM_WRITE | EFI_IMAGE_SCN_MEM_EXECUTE)

@ -136,7 +136,6 @@ EFI_DEVICE_PATH* EFIAPI GetBootMgfwPath(VOID)
UINTN HandleCount = NULL; UINTN HandleCount = NULL;
EFI_STATUS Result; EFI_STATUS Result;
EFI_HANDLE* Handles = NULL; EFI_HANDLE* Handles = NULL;
EFI_DEVICE_PATH* DevicePath = NULL;
EFI_FILE_HANDLE VolumeHandle; EFI_FILE_HANDLE VolumeHandle;
EFI_FILE_HANDLE BootMgfwHandle; EFI_FILE_HANDLE BootMgfwHandle;
EFI_FILE_IO_INTERFACE* FileSystem = NULL; EFI_FILE_IO_INTERFACE* FileSystem = NULL;
@ -144,34 +143,36 @@ EFI_DEVICE_PATH* EFIAPI GetBootMgfwPath(VOID)
if (EFI_ERROR((Result = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &HandleCount, &Handles)))) if (EFI_ERROR((Result = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &HandleCount, &Handles))))
{ {
Print(L"error getting file system handles -> 0x%p\n", Result); Print(L"error getting file system handles -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
for (UINT32 Idx = 0u; Idx < HandleCount && !FileSystem; ++Idx) for (UINT32 Idx = 0u; Idx < HandleCount; ++Idx)
{ {
if (EFI_ERROR((Result = gBS->OpenProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, (VOID**)&FileSystem, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL)))) if (EFI_ERROR((Result = gBS->OpenProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, (VOID**)&FileSystem, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL))))
{ {
Print(L"error opening protocol -> 0x%p\n", Result); Print(L"error opening protocol -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
if (EFI_ERROR((Result = FileSystem->OpenVolume(FileSystem, &VolumeHandle)))) if (EFI_ERROR((Result = FileSystem->OpenVolume(FileSystem, &VolumeHandle))))
{ {
Print(L"error opening file system -> 0x%p\n", Result); Print(L"error opening file system -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
if (!EFI_ERROR(VolumeHandle->Open(VolumeHandle, &BootMgfwHandle, WINDOWS_BOOTMGFW_PATH, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY))) if (!EFI_ERROR(VolumeHandle->Open(VolumeHandle, &BootMgfwHandle, WINDOWS_BOOTMGFW_PATH, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY)))
DevicePath = FileDevicePath(Handles[Idx], WINDOWS_BOOTMGFW_PATH); {
VolumeHandle->Close(BootMgfwHandle);
return FileDevicePath(Handles[Idx], WINDOWS_BOOTMGFW_PATH);
}
VolumeHandle->Close(BootMgfwHandle);
if (EFI_ERROR((Result = gBS->CloseProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, gImageHandle, NULL)))) if (EFI_ERROR((Result = gBS->CloseProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, gImageHandle, NULL))))
{ {
Print(L"error closing protocol -> 0x%p\n", Result); Print(L"error closing protocol -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
} }
return DevicePath; return NULL;
} }
EFI_STATUS EFIAPI InstallBootMgfwHooks(EFI_HANDLE ImageHandle) EFI_STATUS EFIAPI InstallBootMgfwHooks(EFI_HANDLE ImageHandle)

@ -136,7 +136,6 @@ EFI_DEVICE_PATH* EFIAPI GetBootMgfwPath(VOID)
UINTN HandleCount = NULL; UINTN HandleCount = NULL;
EFI_STATUS Result; EFI_STATUS Result;
EFI_HANDLE* Handles = NULL; EFI_HANDLE* Handles = NULL;
EFI_DEVICE_PATH* DevicePath = NULL;
EFI_FILE_HANDLE VolumeHandle; EFI_FILE_HANDLE VolumeHandle;
EFI_FILE_HANDLE BootMgfwHandle; EFI_FILE_HANDLE BootMgfwHandle;
EFI_FILE_IO_INTERFACE* FileSystem = NULL; EFI_FILE_IO_INTERFACE* FileSystem = NULL;
@ -144,34 +143,36 @@ EFI_DEVICE_PATH* EFIAPI GetBootMgfwPath(VOID)
if (EFI_ERROR((Result = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &HandleCount, &Handles)))) if (EFI_ERROR((Result = gBS->LocateHandleBuffer(ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &HandleCount, &Handles))))
{ {
Print(L"error getting file system handles -> 0x%p\n", Result); Print(L"error getting file system handles -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
for (UINT32 Idx = 0u; Idx < HandleCount && !FileSystem; ++Idx) for (UINT32 Idx = 0u; Idx < HandleCount; ++Idx)
{ {
if (EFI_ERROR((Result = gBS->OpenProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, (VOID**)&FileSystem, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL)))) if (EFI_ERROR((Result = gBS->OpenProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, (VOID**)&FileSystem, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL))))
{ {
Print(L"error opening protocol -> 0x%p\n", Result); Print(L"error opening protocol -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
if (EFI_ERROR((Result = FileSystem->OpenVolume(FileSystem, &VolumeHandle)))) if (EFI_ERROR((Result = FileSystem->OpenVolume(FileSystem, &VolumeHandle))))
{ {
Print(L"error opening file system -> 0x%p\n", Result); Print(L"error opening file system -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
if (!EFI_ERROR(VolumeHandle->Open(VolumeHandle, &BootMgfwHandle, WINDOWS_BOOTMGFW_PATH, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY))) if (!EFI_ERROR(VolumeHandle->Open(VolumeHandle, &BootMgfwHandle, WINDOWS_BOOTMGFW_PATH, EFI_FILE_MODE_READ, EFI_FILE_READ_ONLY)))
DevicePath = FileDevicePath(Handles[Idx], WINDOWS_BOOTMGFW_PATH); {
VolumeHandle->Close(BootMgfwHandle);
return FileDevicePath(Handles[Idx], WINDOWS_BOOTMGFW_PATH);
}
VolumeHandle->Close(BootMgfwHandle);
if (EFI_ERROR((Result = gBS->CloseProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, gImageHandle, NULL)))) if (EFI_ERROR((Result = gBS->CloseProtocol(Handles[Idx], &gEfiSimpleFileSystemProtocolGuid, gImageHandle, NULL))))
{ {
Print(L"error closing protocol -> 0x%p\n", Result); Print(L"error closing protocol -> 0x%p\n", Result);
return DevicePath; return NULL;
} }
} }
return DevicePath; return NULL;
} }
EFI_STATUS EFIAPI InstallBootMgfwHooks(EFI_HANDLE BootMgfwPath) EFI_STATUS EFIAPI InstallBootMgfwHooks(EFI_HANDLE BootMgfwPath)

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "ShitHook.h" #include "ShitHook.h"
#define WINVER 1709 #define WINVER 2004
#define PORT_NUM 0x2F8 #define PORT_NUM 0x2F8
#define BL_MEMORY_ATTRIBUTE_RWX 0x424000 #define BL_MEMORY_ATTRIBUTE_RWX 0x424000
#define SECTION_RWX (EFI_IMAGE_SCN_MEM_READ | EFI_IMAGE_SCN_MEM_WRITE | EFI_IMAGE_SCN_MEM_EXECUTE) #define SECTION_RWX (EFI_IMAGE_SCN_MEM_READ | EFI_IMAGE_SCN_MEM_WRITE | EFI_IMAGE_SCN_MEM_EXECUTE)

Loading…
Cancel
Save