From 070005db5d7f96e0ee3964c4bb43f60548a9237e Mon Sep 17 00:00:00 2001 From: paravoid Date: Sat, 2 Jul 2022 05:17:13 +0300 Subject: [PATCH] screenshot: Initial command implementation --- efigop/screenshot/cmd_i386.c | 1 + efigop/screenshot/efiboot.c | 33 +++++++++++++++++++++++++++++++++ efigop/screenshot/efiboot.h | 1 + 3 files changed, 35 insertions(+) diff --git a/efigop/screenshot/cmd_i386.c b/efigop/screenshot/cmd_i386.c index f79e2b1..454a607 100644 --- a/efigop/screenshot/cmd_i386.c +++ b/efigop/screenshot/cmd_i386.c @@ -59,6 +59,7 @@ const struct cmd_table cmd_machine[] = { { "gop", CMDT_CMD, Xgop_efi }, { "exit", CMDT_CMD, Xexit_efi }, { "poweroff", CMDT_CMD, Xpoweroff_efi }, + { "screenshot", CMDT_CMD, Xscreenshot_efi }, #ifdef DEBUG { "regs", CMDT_CMD, Xregs }, #endif diff --git a/efigop/screenshot/efiboot.c b/efigop/screenshot/efiboot.c index a8d8c76..129ffc9 100644 --- a/efigop/screenshot/efiboot.c +++ b/efigop/screenshot/efiboot.c @@ -1059,3 +1059,36 @@ Xgop_efi(void) return (0); } + +int +Xscreenshot_efi() { + if (cmd.argc < 2) { + printf("Error: file name needed\n"); + /* Returning a non-zero value causes a weird boot attempt for some reason */ + return (0); + } + + void *FrameBufferBase; + UINTN FrameBufferSize; + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *gopi; + EFI_GUID fs_guid = SIMPLE_FILE_SYSTEM_PROTOCOL; + EFI_FILE_IO_INTERFACE *IOVolume; + EFI_FILE_HANDLE Volume; + EFI_FILE_HANDLE FileHandle; + CHAR16 FileName[] = {cmd.argv[1][0], '\0'}; + UINTN nhandles; + EFI_HANDLE *handles = NULL; + + BS->LocateProtocol(&gop_guid, NULL, (void **)&gop); + gopi = gop->Mode->Info; + FrameBufferBase = (void *)gop->Mode->FrameBufferBase; + FrameBufferSize = gopi->VerticalResolution * gopi->PixelsPerScanLine * 4; + + BS->LocateHandleBuffer(ByProtocol, &fs_guid, NULL, &nhandles, &handles); + BS->HandleProtocol(handles[0], &fs_guid, (void **)&IOVolume); + IOVolume->OpenVolume(IOVolume, &Volume); + Volume->Open(Volume, &FileHandle, FileName, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0); + FileHandle->Write(FileHandle, &FrameBufferSize, FrameBufferBase); + FileHandle->Close(FileHandle); + return (0); +} diff --git a/efigop/screenshot/efiboot.h b/efigop/screenshot/efiboot.h index 5f50525..330280f 100644 --- a/efigop/screenshot/efiboot.h +++ b/efigop/screenshot/efiboot.h @@ -36,6 +36,7 @@ int Xexit_efi(void); void efi_makebootargs(void); int Xpoweroff_efi(void); +int Xscreenshot_efi(void); extern void (*run_i386)(u_long, u_long, int, int, int, int, int, int, int, int) __attribute__ ((noreturn)); -- 2.45.2