stage0-uefi/amd64/kaem-minimal.hex0

595 lines
32 KiB
Plaintext

# SPDX-FileCopyrightText: 2022 Andrius Štikonas <andrius@stikonas.eu>
# SPDX-FileCopyrightText: 2017 Jeremiah Orians <jeremiah@pdp10.guru>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# DOS MZ header
4D 5A # Signature
00 00 # Number of bytes in the last page.
00 00 # Number of whole/partial pages
00 00 # Number of entries in the relocation table.
00 00 # Header size
00 00 # Minimum allocation
00 00 # Maximum allocation
00 00 # Relocatable segment address for SS
00 00 # Initial value for SP
00 00 # Checksum (I don't think is looked at)
00 00 # Initial value for IP (Seems ignored)
00 00 # Relocatable segment address for CS (Seems ignored)
00 00 # The (absolute) offset to the relocation table.
00 00 # Value used for overlay management. If zero, this is the main executable
00 00 00 00 00 00 00 00 # Reserved in PE
00 00 # OEM identifier
00 00 # OEM info
00 00 00 00 00 00 00 00 00 00 # The required reserved 20 bytes of NULLS
00 00 00 00 00 00 00 00 00 00
40 00 00 00 # Starting address of the PE header
# [0x40]
# PE header
50 45 00 00 # Signature "PE"
64 86 # Machine
01 00 # number of sections
00 00 00 00 # Timestamp supposedly
00 00 00 00 # PointerToSymbolTable
00 00 00 00 # number of symbols
F0 00 # SizeOfOptionalHeader
00 00 # 'Characteristics'
# [0x58]
# COFF header bits
0B 02 # Magic PE32+ (64 bit)
00 00 # Linker version
00 00 00 00 # size of code
00 00 00 00 # sizeOfInitializedData
00 00 00 00 # SizeOfUninitializedData
00 10 00 00 # AddressOfEntryPoint
00 10 00 00 # BaseOfCode
00 00 00 80 01 00 00 00 # ImageBase
01 00 00 00 # SectionAlignment
01 00 00 00 # FileAlignment
00 00 00 00 # OperatingSystemVersion
00 00 00 00 # ImageVersion
00 00 00 00 # SubsystemVersion
00 00 00 00 # Win32VersionValue
00 20 00 00 # SizeOfImage
70 01 00 00 # SizeOfHeaders
00 00 00 00 # CheckSum (isn't used at all)
0A 00 # Subsystem
00 00 # DllCharacteristics
00 00 00 00 # SizeOfStackReserve
00 00 00 00 # SizeOfStackCommit
00 00 00 00 # SizeOfHeapReserve
00 00 00 00 # SizeOfHeapCommit
00 00 00 00 # LoaderFlags
00 00 00 00 # NumberOfRvaAndSizes
# [0xB8]
# Data directories (has to be 16 entries always 16bytes per entry)
00 00 00 00 # Export Table
00 00 00 00 # Size of Export Table
00 00 00 00 # Import Table
10 00 00 00 # Size of Import Table
00 00 00 00 # Resource Table
00 00 00 00 # Size of Resource Table
00 00 00 00 # Exception Table
00 00 00 00 # Size of Exception Table
00 00 00 00 # Certificate Table
00 00 00 00 # Size of Certificate Table
00 00 00 00 # Base Relocation Table
00 00 00 00 # Size of Base Relocation Table
00 00 00 00 # Debug Table
00 00 00 00 # Size of Debug Table
00 00 00 00 # Architecture Data Table
00 00 00 00 # Size of Architecture Data Table
00 00 00 00 # Global Pointer
00 00 00 00 # NULL
00 00 00 00 # TLS Table
00 00 00 00 # Size of TLS Table
00 00 00 00 # Load Config Table
00 00 00 00 # Size of Load Config Table
00 00 00 00 # Bound Import Table
00 00 00 00 # Size of Bound Import Table
00 00 00 00 # Import Address Table
00 00 00 00 # Size of Import Address Table
00 00 00 00 # Delay Import Descriptor Table
00 00 00 00 # Size of Delay Import Descriptor Table
00 00 00 00 # CLR Runtime header table
00 00 00 00 # Size of CLR Runtime Header table
00 00 00 00 00 00 00 00 # MUST BE NULL
# no idea what it is yet
00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00
# [0x148]
# Start of section headers
00 00 00 00 00 00 00 00 ; Name of the section (empty) but could set to ".text"
18 04 00 00 ; VirtualSize
00 10 00 00 ; VirtualAddress
18 04 00 00 ; SizeOfRawData
70 01 00 00 ; PointerToRawData
00 00 00 00 ; PointerToRelocations
00 00 00 00 ; PointerToLinenumbers
00 00 ; NumberOfRelocations
00 00 ; NumberOfLinenumbers
00 00 00 00 ; 'Characteristics'
# [0x170]
# :PE32_text
# efi_main(void *image_handle, struct efi_system_table *system)
# :_start
4889E5 ; mov_rbp,rsp # save stack pointer
48890D E6030000 ; mov_[rip+DWORD],rcx %image_handle # save image_handle
4889CB ; mov_rbx,rcx # save image_handle
488B42 40 ; mov_rax,[rdx+BYTE] !64 # system->out
488905 F8030000 ; mov_[rip+DWORD],rax %system_out # save system->out
4C8B72 60 ; mov_r14,[rdx+BYTE] !96 # system->boot
31C9 ; xor_ecx,ecx # timeout = 0
31D2 ; xor_edx,edx # watchdog_code = 0
4D31C0 ; xor_r8,r8 # data_size = 0
4D31C9 ; xor_r9,r9 # watchdog_data = 0
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
41FF96 F0000000 ; call_[r14+DWORD] %240 # system->boot->set_watchdog_timer
# Open Loaded Image protocol
4989D9 ; mov_r9,rbx # arg4 = image_handle
488D15 3F030000 ; lea_rdx,[rip+DWORD] %LOADED_IMAGE_PROTOCOL # guid = &LOADED_IMAGE_PROTOCOL
4889D9 ; mov_rcx,rbx # arg1 = image_handle
E8 F6020000 ; call %open_protocol # open protocol
4889C7 ; mov_rdi,rax # save image
488905 AB030000 ; mov_[rip+DWORD],rax %image # save image
# Get root file system
4989D9 ; mov_r9,rbx # arg4 = image_handle
488D15 33030000 ; lea_rdx,[rip+DWORD] %SIMPLE_FS_PROTOCOL # guid = &SIMPLE_FS_PROTOCOL
488B4F 18 ; mov_rcx,[rdi+BYTE] !24 # arg1 = root_device = image->device
48890D A6030000 ; mov_[rip+DWORD],rcx %root_device # save root_device
E8 D2020000 ; call %open_protocol # open protocol
4889C1 ; mov_rcx,rax # get rootfs
# Get root directory
488D15 8F030000 ; lea_rdx,[rip+DWORD] %rootdir # arg2 = &rootdir
50 ; push_rax # allocate shadow stack space for UEFI function space for UEFI function
50 ; push_rax # allocate shadow stack space for UEFI function space for UEFI function
FF51 08 ; call_[rcx+BYTE] !8 # rootfs->open_volume(rootfs, &rootdir)
58 ; pop_rax # deallocate stack
58 ; pop_rax # deallocate stack
# Push command line arguments onto stack
488B5F 38 ; mov_rbx,[rdi+BYTE] !56 # options = image->load_options
4889DA ; mov_rdx,rbx # save beginning of load_options
48035F 30 ; add_rbx,[rdi+BYTE] !48 # go to the end of load_options
6A 00 ; push !0 # Save end of arguments (NULL) onto stack
# :loop_options [_start+0x85]
4839D3 ; cmp_rbx,rdx # Check if we are done
74 14 ; je8 !loop_options_done # We are done
4883EB 02 ; sub_rbx, !2 # --options
8A03 ; mov_al,[rbx] # *options
3C 20 ; cmp_al, !0x20 # if *options != ' '
75 F1 ; jne8 !loop_options # then continue looping
C603 00 ; mov_[rbx], !0 # zero it
4883C3 02 ; add_rbx, !2 # ++options
53 ; push_rbx # push another argument onto stack
EB E7 ; jmp8 !loop_options # next argument
# :loop_options_done [_start+0x9E]
4158 ; pop_r8 # get input file
4D85C0 ; test_r8,r8 # Check if argument is specified
75 07 ; jne8 !arg_done # then use it
# Else use default_file
4C8D05 FE020000 ; lea_r8,[rip+DWORD] %default_file # Use "kaem.amd64"
# :arg_done [_start+0xAC]
# Open file for reading
52 ; push_rdx # allocate stack for fin
4889E2 ; mov_rdx,rsp # arg2 = &fin
6A 01 ; push !1 # arg5 = EFI_FILE_READ_ONLY
6A 01 ; push !1 # prepare to set arg4 to EFI_FILE_MODE_READ
4159 ; pop_r9 # arg4 = EFI_FILE_MODE_READ
# arg3 = in
488B0D 43030000 ; mov_rcx,[rip+DWORD] %rootdir # arg1 = rootdir
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
FF51 08 ; call_[rcx+BYTE] !8 # rootdir->open()
85C0 ; test_eax,eax # if status != EFI_SUCCESS
0F85 3E020000 ; jne %abort # then exit without closing file
4C8B6424 28 ; mov_r12,[rsp+BYTE] !40 # get fin
# Allocate pool for command
31D2 ; xor_edx,edx # zero RDX
B6 10 ; mov_dh, !0x10 # arg2 = 4096 = 0x1000
E8 8B020000 ; call %allocate_pool # allocate memory
4889C3 ; mov_rbx,rax # get command
# :next_command [_start+0xDD]
31F6 ; xor_esi,esi # i = 0
4D31FF ; xor_r15,r15 # command_length = 0
# :read_command [_start+0xE2]
E8 36020000 ; call %read_byte # read another byte c
3C 0A ; cmp_al, !0xa # if c == '\n'
74 2A ; je8 !read_command_done # then we are done with this command command command
3C 20 ; cmp_al, !0x20 # if c == ' '
75 08 ; jne8 !read_command_comments
4D85FF ; test_r15,r15 # and command_length == 0
75 03 ; jne8 !read_command_comments
4989F7 ; mov_r15,rsi # command_length = i
# :read_command_comments [_start+0xF7]
3C 23 ; cmp_al, !0x23 # if c == '#' then process comment
75 0B ; jne8 !read_command_store_char # else store char
# :read_command_skip_comment [_start+0xFB]
E8 1D020000 ; call %read_byte # get another char
3C 0A ; cmp_al, !0xa # if c == '\n'
75 F7 ; jne8 !read_command_skip_comment # continue reading until newline
EB D7 ; jmp8 !next_command # deal with another line
# :read_command_store_char [_start+0x106]
4801F3 ; add_rbx,rsi # rbx = &command[i]
668903 ; mov_[rbx],ax # command[i] = c
4829F3 ; sub_rbx,rsi # rbx = &command[0]
4883C6 02 ; add_rsi, !2 # location of the next char
EB CD ; jmp8 !read_command # continue looping
# :read_command_done [_start+0x115]
4D85FF ; test_r15,r15 # if command_length == 0
74 C3 ; je8 !next_command # deal with another line
4801F3 ; add_rbx,rsi # rbx = &command[i]
66C703 0000 ; mov_[rbx],WORD @0 # command[i] = 0
4829F3 ; sub_rbx,rsi # rbx = &command[0]
4883C6 02 ; add_rsi, !2 # add 2 to get string length with NULL terminator
488D15 90020000 ; lea_rdx,[rip+DWORD] %prefix # get prefix " +> "
E8 D9010000 ; call %File_Print # print it
4889DA ; mov_rdx,rbx # get command
E8 D1010000 ; call %File_Print # print it
488D15 A6020000 ; lea_rdx,[rip+DWORD] %suffix # get suffix "\n\r"
E8 C5010000 ; call %File_Print # print it
# Remove command line options
4901DF ; add_r15,rbx # go to the space separating command and its options
6641C707 0000 ; mov_[r15],WORD @0 # zero it to hide command line options
# Open executable file for reading
52 ; push_rdx # allocate stack for fcmd
4889E2 ; mov_rdx,rsp # arg2 = &fcmd
6A 01 ; push !1 # arg5 = EFI_FILE_READ_ONLY
6A 01 ; push !1 # prepare to set arg4 to EFI_FILE_MODE_READ
4159 ; pop_r9 # arg4 = EFI_FILE_MODE_READ
4989D8 ; mov_r8,rbx # arg3 = command
488B0D 9A020000 ; mov_rcx,[rip+DWORD] %rootdir # arg1 = rootdir
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
FF51 08 ; call_[rcx+BYTE] !8 # rootdir->open()
85C0 ; test_eax,eax # if status != EFI_SUCCESS
0F85 3F010000 ; jne %print_error # then exit
4883C4 28 ; add_rsp, !40 # deallocate stack
5F ; pop_rdi # get fcmd
# Restore command line arguments
6641C707 2000 ; STOREI16_into_Address_R15 @0x20 # restore command line options by readding ' '
# Allocate pool for file_info
31D2 ; xor_edx,edx # zero RDX
B6 10 ; mov_dh, !0x10 # arg2 = 4096 = 0x1000
E8 DC010000 ; call %allocate pool # allocate memory
4989C1 ; mov_r9,rax # get file_info (arg4 for get_info)
# Get file info
50 ; push_rax # save file_info
50 ; push_rax # allocate stack for file_size
4989E0 ; mov_r8,rsp # arg3 = &file_size
49C700 00100000 ; mov_[r8], %0x1000 # file_size = 0x1000
488D15 FB010000 ; lea_rdx,[rip+DWORD] %FILE_INFO_PROTOCOL # arg2 = &EFI_FILE_INFO_PROTOCOL
4889F9 ; mov_rcx,rdi # arg1 = fcmd
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
FF51 40 ; call_[rcx+BYTE] !64 # fcmd->get_info(fcmd, &guid, &file_size, file_info)
4883C4 28 ; add_rsp, !40 # deallocate stack
59 ; pop_rcx # restore file_info
488B51 08 ; mov_rdx,[rcx+BYTE] !8 # get file_size
# Free file_info pool
52 ; push_rdx # save file_size onto stack
50 ; push_rax # allocate shadow stack space for UEFI function
41FF56 48 ; call_[r14+BYTE] !72 # system->boot->free_pool(file_info)
58 ; pop_rax # deallocate stack
5A ; pop_rdx # restore file_size from stack (arg2 for allocate_pool)
# Allocate pool for executable [_start+0x1BA]
52 ; push_rdx # save file_size onto stack
E8 A5010000 ; call %allocate_pool # allocate memory
4989C7 ; mov_r15,rax # get executable
5A ; pop_rdx # restore file_size
# Load executable into memory
52 ; push_rdx # save file_size onto stack
4D89F8 ; mov_r8,r15 # arg3 = executable
4889E2 ; mov_rdx,rsp # arg2 = &file_size
4889F9 ; mov_rcx,rdi # arg1 = fcmd
50 ; push_rax # allocate shadow stack space for UEFI
50 ; push_rax # allocate shadow stack space for UEFI
50 ; push_rax # allocate shadow stack space for UEFI
FF51 20 ; call_[rcx+BYTE] !32 # fcmd->read(fcmd, &file_size, executable)
58 ; pop_rax # deallocate stack
58 ; pop_rax # deallocate stack
58 ; pop_rax # deallocate stack
# Close fcmd
50 ; push_rax # allocate shadow stack space for UEFI
4889F9 ; mov_rcx,rdi # arg1 = fcmd
FF51 10 ; call_[rcx+BYTE] !16 # fcmd->close(fcmd)
58 ; pop_rax # deallocate stack
5F ; pop_rdi # restore file_size
# Allocate memory for device_path struct
6A 1C ; push !28 # 4 + sizeof(struct efi_device_path_protocol)
5A ; pop_rdx # arg2 = 28
E8 7D010000 ; call %allocate_pool # allocate memory
4989C0 ; mov_r8,rax # get device_path
# Initialize struct
C600 01 ; mov_[rax],BYTE !1 # device_path->type = HARDWARE_DEVICE_PATH
48FFC0 ; inc_rax # next member
C600 03 ; mov_[rax],BYTE !3 # device_path->subtype = MEMORY_MAPPED
48FFC0 ; inc_rax # next member
66C700 1800 ; mov_[rax],WORD @24 # device_path->length = 24
4883C0 02 ; add_rax, !2 # next member
C700 01000000 ; mov_[rax], %1 # device_path->memory_type = EFI_LOADER_CODE
4883C0 04 ; add_rax, !4 # next member
4C8938 ; mov_[rax],r15 # device_path->start_address = executable
4883C0 08 ; add_rax, !8 # next member
4901FF ; add_r15,rdi # end_address = executable + file_size
4C8938 ; mov_[rax],r15 # device_path->end_address = end_address
4929FF ; sub_r15,rdi # restore r15 = executable
4883C0 08 ; add_rax, !8 # next member
C600 7F ; mov_[rax],BYTE !0x7f # device_path[1].type = END_HARDWARE_DEVICE_PATH
48FFC0 ; inc_rax # next member
C600 FF ; mov_[rax],BYTE !0xff # device_path[1].subtype = END_ENTIRE_DEVICE_PATH
48FFC0 ; inc_rax # next member
66C700 0400 ; mov_[rax],WORD @4 # device_path[1].length = 4
# Load image
4150 ; push_r8 # save device_path
50 ; push_rax # allocate stack for child_ih
54 ; push_rsp # arg6 = &child_ih
57 ; push_rdi # arg5 = file size
4D89F9 ; mov_r9,r15 # arg4 = executable
# arg3 = device_path
488B15 B2010000 ; mov_rdx,[rip+DWORD] %image_handle # arg2 = image_handle
31C9 ; xor_ecx,ecx # arg1 = 0
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
41FF96 C8000000 ; call_[r14+DWORD] %200 # system->boot->load_image()
4883C4 30 ; add_rsp, !48 # deallocate stack
5F ; pop_rdi # save child_ih
# Free device_path pool
59 ; pop_rcx # arg1 = device_path
50 ; push_rax # allocate shadow stack space for UEFI function
41FF56 48 ; call_[r14+BYTE] !72 # system->boot->free_pool(device_path)
58 ; pop_rax # deallocate stack
# Free executable pool
4C89F9 ; mov_rcx,r15 # arg1 = executable
50 ; push_rax # allocate shadow stack space for UEFI function
41FF56 48 ; call_[r14+BYTE] !72 # system->boot->free_pool(executable)
58 ; pop_rax # deallocate stack
# Open Child Image [_start+0x260]
4989F9 ; mov_r9,rdi # arg4 = child_ih
488D15 10010000 ; lea_rdx,[rip+DWORD] %LOADED_IMAGE_PROTOCOL # guid = &LOADED_IMAGE_PROTOCOL
52 ; push_rdx # save &LOADED_IMAGE_PROTOCOL
4C89C9 ; mov_rcx,r9 # arg1 = child_ih
E8 C6000000 ; call %open_protocol # open protocol
488958 38 ; mov_[rax+BYTE],rbx !56 # child_image->load_options = command
488970 30 ; mov_[rax+BYTE],rsi !48 # set child_image->load_options_size
488B0D 76010000 ; mov_rcx,[rip+DWORD] %image # get image
488B49 18 ; mov_rcx,[rcx+BYTE] !24 # image->device
488948 18 ; mov_[rax+BYTE],rcx !24 # child_image->device = image->device
4989F8 ; mov_r8,rdi # arg3 = image_handle
5A ; pop_rdx # arg2 = &LOADED_IMAGE_PROTOCOL
4C89C1 ; mov_rcx,r8 # arg1 = image_handle
E8 BC000000 ; call %close_protocol # close protocol
# Run command
4D31C0 ; xor_r8,r8 # arg3 = 0 (ExitData)
31D2 ; xor_edx,edx # arg2 = 0 (ExitData size)
4889F9 ; mov_rcx,rdi # arg1 = child_ih
50 ; push_rax # allocate shadow stack space for UEFI
50 ; push_rax # allocate shadow stack space for UEFI
50 ; push_rax # allocate shadow stack space for UEFI
41FF96 D0000000 ; call_[r14+DWORD] %208 # system->boot->start_image()
59 ; pop_rcx # deallocate stack
59 ; pop_rcx # deallocate stack
59 ; pop_rcx # deallocate stack
85C0 ; test_eax,eax # check if return code is 0
75 05 ; jne8 !print_error # print error and exit
E9 29FEFFFF ; jmp %next_command # process another line from kaem script
# :print_error [_start+0x2B4]
50 ; push_rax # save exit code
488D15 0E010000 ; lea_rdx,[rip+DWORD] %subprocess_error # get error message
E8 4D000000 ; call %File_Print # print it
58 ; pop_rax # restore exit code
# Close script file and exit
# :terminate [_start+0x2C2]
# Free pool
4889D9 ; mov_rcx,rbx # arg1 = command
50 ; push_rax # save exit code
50 ; push_rax # allocate shadow stack space for UEFI function
41FF56 48 ; call_[r14+BYTE] !72 # system->boot->free_pool(commmand)
4C89E1 ; mov_rcx,r12 # arg1 = fin
FF51 10 ; call_[rcx+BYTE] !16 # fin->close(fin)
488B0D 28010000 ; mov_rcx,[rip+DWORD] %rootdir # arg1 = rootdir
FF51 10 ; call_[rcx+BYTE] !16 # rootdir->close(rootdir)
58 ; pop_rax # deallocate stack
58 ; pop_rax # restore exit code
# Exit without closing script file
# :terminate_2 [_start+0x2DD]
4C8B05 0C010000 ; mov_r8,[rip+DWORD] %image_handle # arg3 = image_handle
4150 ; push_r8 # save image_handle
488D15 9D000000 ; lea_rdx,[rip+DWORD] %SIMPLE_FS_PROTOCOL # guid = &SIMPLE_FS_PROTOCOL
488B0D 14010000 ; mov_rcx,[rip+DWORD] %root_device # arg1 = root_device
E8 59000000 ; call %close_protocol # close protocol
4158 ; pop_r8 # arg3 = image_handle
488D15 78000000 ; lea_rdx,[rip+DWORD] %LOADED_IMAGE_PROTOCOL # guid = &LOADED_IMAGE_PROTOCOL
4C89C1 ; mov_rcx,r8 # arg1 = image_handle
E8 48000000 ; call %close_protocol # close protocol
# :abort [_start+0x30A]
4889EC ; mov_rsp,rbp # restore stack
C3 ; ret # return to UEFI
# :File_Print [_start+0x30E]
488B0D FB000000 ; mov_rcx,[rip+DWORD] %system_out # get system_out
50 ; push_rax # allocate shadow stack space for UEFI function
50 ; push_rax # allocate shadow stack space for UEFI function for UEFI function
FF51 08 ; call_[rcx+BYTE] !8 # system->out->output_string(system->out, WCHAR*)
58 ; pop_rax # deallocate stack
58 ; pop_rax # deallocate stack
C3 ; ret
# read_byte function
# reads a single character
# :read_byte [_start+0x31D]
4C89E1 ; mov_rcx,r12 # arg1 = fin
6A 01 ; push !1 # size = 1
4889E2 ; mov_rdx,rsp # arg2 = &size
56 ; push_rsi # allocate stack
4989E0 ; mov_r8,rsp # arg3 = &c
50 ; push_rax # allocate shadow stack space for UEFI function
50 ; push_rax # allocate shadow stack space for UEFI function
50 ; push_rax # allocate shadow stack space for UEFI function
FF51 20 ; call_[rcx+BYTE] !32 # fin->read()
58 ; pop_rax # deallocate stack
58 ; pop_rax # deallocate stack
58 ; pop_rax # deallocate stack
58 ; pop_rax # save c to rax
59 ; pop_rcx # save size to rcx
# If the file ended (0 bytes read) terminate
85C9 ; test_ecx,ecx # if size = 0
74 8A ; je8 !terminate # then we are done
C3 ; ret # return
# rcx: handle
# rdx: &guid
# r9: agent_handle
# returns interface
# :open_protocol [_start+0x339]
50 ; push_rax # allocate stack for interface
4989E0 ; mov_r8,rsp # arg3 = &interface
6A 01 ; push !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
6A 00 ; push !0 # arg5 = NULL
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
41FF96 18010000 ; call_[r14+DWORD] %280 # system->boot->open_protocol(handle, &guid, &interface, agent_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
4883C4 30 ; add_rsp, !48 # deallocate stack
58 ; pop_rax # get image
C3 ; ret
# rcx: handle
# rdx: &guid
# r8: agent_handle
# :close_protocol [_start+0x352]
4D31C9 ; xor_r9,r9 # arg4 = NULL
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
41FF96 20010000 ; call_[r14+DWORD] %288 # system->boot->close_protocol(handle, &guid, agent_handle, 0)
4883C4 20 ; add_rsp, !32 # deallocate stack
C3 ; ret
# rdx: number of bytes to allocate
# r14: system->boot
# returns pointer in rax
# :allocate_pool [_start+0x365]
52 ; push_rdx # allocate stack for pool pointer
4989E0 ; mov_r8,rsp # arg3 = &pool
6A 02 ; push !2
59 ; pop_rcx # arg1 = EFI_LOADER_DATA
4883EC 18 ; sub_rsp, !24 # allocate shadow stack space for UEFI
41FF56 40 ; call_[r14+BYTE] !64 # system->boot->allocate_pool(EFI_LOADER_DATA, 2048, &pool)
4883C4 18 ; add_rsp, !24 # deallocate stack
58 ; pop_rax # get pool
C3 ; ret
# Protocol GUIDs
# :LOADED_IMAGE_PROTOCOL [_start+0x37A]
A1 31 1B 5B ; %0x5b1b31a1:SIMPLE_FS_PROTOCOL
62 95 ; @0x9562 22 5B 4E 96 ; %0x0964e5b22
D2 11 ; @0x11d2 59 64 ; @0x6459
8E 3F 00 A0 C9 69 72 3B ; !0x8e !0x3f !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
# :SIMPLE_FS_PROTOCOL [_start+0x38A]
22 5B 4E 96 ; %0x0964e5b22
59 64 ; @0x6459
D2 11 ; @0x11d2
8E 39 00 A0 C9 69 72 3B ; !0x8e !0x39 !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
# :FILE_INFO_PROTOCOL [_start+0x39A]
92 6E 57 09 ; %0x09576e92
3F 6D ; @0x6d3f
D2 11 ; @0x11d2
8E 39 00 A0 C9 69 72 3B ; !0x8e !0x39 !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
# :default_file [_start+0x3AA]
6B 00 61 00 65 00 6D 00 2E 00 61 00 6D 00 64 00 36 00 34 00 00 00 ; L"kaem.amd64"
# :prefix [_start+0x3C0]
20 00 2B 00 3E 00 20 00 00 00 ; L" +> "
# :subprocess_error [_start+0x3CA]
53 00 75 00 62 00 70 00 72 00 6F 00 63 00 65 00
73 00 73 00 20 00 65 00 72 00 72 00 6F 00 72 00
# :suffix [_start+0x3EA]
0A 00 0D 00 00 00 ; L"Subprocess error\n\r"
# :image_handle [_start+0x3F0]
00 00 00 00 00 00 00 00
# :image [_start+0x3F8]
00 00 00 00 00 00 00 00
# :rootdir [_start+0x400]
00 00 00 00 00 00 00 00
# :root_device [_start+0x408]
00 00 00 00 00 00 00 00
# :system_out [_start+0x410]
00 00 00 00 00 00 00 00
# :PE32_end [_start+0x418]