stage0-uefi/amd64/kaem-optional.hex0

596 lines
31 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
2B 00 00 00 # SizeOfUninitializedData
00 10 00 00 # AddressOfEntryPoint
00 00 00 00 # BaseOfCode
00 00 00 00 00 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"
53 04 00 00 ; VirtualSize
00 10 00 00 ; VirtualAddress
28 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
# Save non-volatile registers
55 ; push_rbp
53 ; push_rbx
57 ; push_rdi
56 ; push_rsi
4154 ; push_r12
4155 ; push_r13
4156 ; push_r14
4157 ; push_r15
4889E5 ; mov_rbp,rsp
48890D 15040000 ; 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 27040000 ; 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 28 ; sub_rsp, !40 # allocate shadow stack space for UEFI function and align stack
41FF96 F0000000 ; call_[r14+DWORD] %240 # system->boot->set_watchdog_timer
# Open Loaded Image protocol
4989D9 ; mov_r9,rbx # arg4 = image_handle
488D15 6E030000 ; lea_rdx,[rip+DWORD] %LOADED_IMAGE_PROTOCOL # guid = &LOADED_IMAGE_PROTOCOL
4889D9 ; mov_rcx,rbx # arg1 = image_handle
E8 25030000 ; call %open_protocol # open protocol
4889C7 ; mov_rdi,rax # save image
488905 DA030000 ; mov_[rip+DWORD],rax %image # save image
# Get root file system
4989D9 ; mov_r9,rbx # arg4 = image_handle
488D15 62030000 ; lea_rdx,[rip+DWORD] %SIMPLE_FS_PROTOCOL # guid = &SIMPLE_FS_PROTOCOL
488B4F 18 ; mov_rcx,[rdi+BYTE] !24 # arg1 = root_device = image->device
48890D D5030000 ; mov_[rip+DWORD],rcx %root_device # save root_device
E8 01030000 ; call %open_protocol # open protocol
4889C1 ; mov_rcx,rax # get rootfs
# Get root directory
488D15 BE030000 ; lea_rdx,[rip+DWORD] %rootdir # arg2 = &rootdir
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
FF51 08 ; call_[rcx+BYTE] !8 # rootfs->open_volume(rootfs, &rootdir)
4883C4 20 ; add_rsp, !32 # 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+0x95]
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+0xAE]
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 29030000 ; lea_r8,[rip+DWORD] %default_file # Use "kaem.amd64"
# :arg_done [_start+0xBC]
# Open file for reading
4883E4 F0 ; and_rsp, !-16 # align stack to 16 bytes
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 6A030000 ; 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
50 ; push_rax # store error code
0F85 21020000 ; jne %terminate_2 # then exit without closing file
58 ; pop_rax # deallocate stack
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 B0020000 ; call %allocate_pool # allocate memory
4889C3 ; mov_rbx,rax # get command
# :next_command [_start+0xF3]
31F6 ; xor_esi,esi # i = 0
4D31FF ; xor_r15,r15 # command_length = 0
# :read_command [_start+0xF8]
E8 45020000 ; 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+0x10D]
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+0x111]
E8 2C020000 ; 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+0x11C]
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+0x12B]
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 B5020000 ; lea_rdx,[rip+DWORD] %prefix # get prefix " +> "
E8 16020000 ; call %File_Print # print it
4889DA ; mov_rdx,rbx # get command
E8 0E020000 ; call %File_Print # print it
488D15 CB020000 ; lea_rdx,[rip+DWORD] %suffix # get suffix "\n\r"
E8 02020000 ; 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 BF020000 ; 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 47010000 ; 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 01020000 ; 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 20020000 ; 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
4883EC 28 ; sub_rsp, !40 # allocate shadow stack space for UEFI function and align stack
41FF56 48 ; call_[r14+BYTE] !72 # system->boot->free_pool(file_info)
4883C4 28 ; add_rsp, !40 # deallocate stack
5A ; pop_rdx # restore file_size from stack (arg2 for allocate_pool)
# Allocate pool for executable [_start+0x1D6]
52 ; push_rdx # save file_size onto stack
50 ; push_rax # align stack
E8 C3010000 ; call %allocate_pool # allocate memory
4989C7 ; mov_r15,rax # get executable
5A ; pop_rdx # deallocate stack
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
4883EC 28 ; sub_rsp, !40 # allocate shadow stack space for UEFI function and align stack
FF51 20 ; call_[rcx+BYTE] !32 # fcmd->read(fcmd, &file_size, executable)
# Close fcmd
4889F9 ; mov_rcx,rdi # arg1 = fcmd
FF51 10 ; call_[rcx+BYTE] !16 # fcmd->close(fcmd)
4883C4 28 ; add_rsp, !40 # 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 9A010000 ; 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 CF010000 ; 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
4883EC 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI function
41FF56 48 ; call_[r14+BYTE] !72 # system->boot->free_pool(device_path)
# Free executable pool
4C89F9 ; mov_rcx,r15 # arg1 = executable
41FF56 48 ; call_[r14+BYTE] !72 # system->boot->free_pool(executable)
# Open Child Image [_start+0x27E]
4989F9 ; mov_r9,rdi # arg4 = child_ih
52 ; push_rdx # align stack
488D15 2C010000 ; 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 E2000000 ; 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 92010000 ; 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
58 ; pop_rax # deallocate stack
4C89C1 ; mov_rcx,r8 # arg1 = image_handle
E8 D7000000 ; 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
41FF96 D0000000 ; call_[r14+DWORD] %208 # system->boot->start_image()
4883C4 20 ; add_rsp, !32 # deallocate stack
85C0 ; test_eax,eax # check if return code is 0
75 05 ; jne8 !print_error # print error and exit
E9 21FEFFFF ; jmp %next_command # process another line from kaem script
# :print_error [_start+0x2D2]
50 ; push_rax # align stack
50 ; push_rax # save exit code
488D15 2A010000 ; lea_rdx,[rip+DWORD] %subprocess_error # get error message
E8 81000000 ; call %File_Print # print it
58 ; pop_rax # restore exit code
# Close script file and exit
# :terminate [_start+0x2E1]
50 ; push_rax # align stack
# Free pool
4889D9 ; mov_rcx,rbx # arg1 = command
50 ; push_rax # save exit code
4883EC 28 ; sub_rsp, !40 # 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 40010000 ; mov_rcx,[rip+DWORD] %rootdir # arg1 = rootdir
FF51 10 ; call_[rcx+BYTE] !16 # rootdir->close(rootdir)
4883C4 28 ; add_rsp, !40 # deallocate stack
# Exit without closing script file
# :terminate_2 [_start+0x302]
4C8B05 22010000 ; mov_r8,[rip+DWORD] %image_handle # arg3 = image_handle
4150 ; push_r8 # save image_handle
488D15 B3000000 ; lea_rdx,[rip+DWORD] %SIMPLE_FS_PROTOCOL # guid = &SIMPLE_FS_PROTOCOL
488B0D 2A010000 ; mov_rcx,[rip+DWORD] %root_device # arg1 = root_device
E8 6F000000 ; call %close_protocol # close protocol
4158 ; pop_r8 # arg3 = image_handle
50 ; push_rax # align stack to 16 bytes
488D15 8D000000 ; lea_rdx,[rip+DWORD] %LOADED_IMAGE_PROTOCOL # guid = &LOADED_IMAGE_PROTOCOL
4C89C1 ; mov_rcx,r8 # arg1 = image_handle
E8 5D000000 ; call %close_protocol # close protocol
58 ; pop_rax # deallocate stack
58 ; pop_rax # restore exit code
# :abort [_start+0x332]
# Restore non-volatile registers
4889EC ; mov_rsp,rbp # restore stack
415F ; pop_r15
415E ; pop_r14
415D ; pop_r13
415C ; pop_r12
5E ; pop_rsi
5F ; pop_rdi
5B ; pop_rbx
5D ; pop_rbp
C3 ; ret # return to UEFI
# read_byte function
# reads a single character
# :read_byte [_start+0x342]
4C89E1 ; mov_rcx,r12 # arg1 = fin
6A 01 ; push !1 # size = 1
4889E2 ; mov_rdx,rsp # arg2 = &size
6A 00 ; push !0 # allocate stack
4989E0 ; mov_r8,rsp # arg3 = &c
4883EC 28 ; sub_rsp, !40 # allocate shadow stack space for UEFI and align stack
FF51 20 ; call_[rcx+BYTE] !32 # fin->read()
4883C4 28 ; add_rsp, !40 # 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 81 ; je8 !terminate # then we are done
C3 ; ret # return
# :File_Print [_start+0x361]
488B0D E3000000 ; mov_rcx,[rip+DWORD] %system_out # get system_out
4883EC 28 ; sub_rsp, !40 # allocate shadow stack space for UEFI function
FF51 08 ; call_[rcx+BYTE] !8 # system->out->output_string(system->out, WCHAR*)
4883C4 28 ; add_rsp, !40 # deallocate stack
C3 ; ret
# rcx: handle
# rdx: &guid
# r9: agent_handle
# returns interface
# :open_protocol [_start+0x374]
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 interface
C3 ; ret
# rcx: handle
# rdx: &guid
# r8: agent_handle
# :close_protocol [_start+0x38D]
4D31C9 ; xor_r9,r9 # arg4 = NULL
4883EC 28 ; sub_rsp, !40 # allocate shadow stack space for UEFI function
41FF96 20010000 ; call_[r14+DWORD] %288 # system->boot->close_protocol(handle, &guid, agent_handle, 0)
4883C4 28 ; add_rsp, !40 # deallocate stack
C3 ; ret
# rdx: number of bytes to allocate
# r14: system->boot
# returns pointer in rax
# :allocate_pool [_start+0x3A0]
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 20 ; sub_rsp, !32 # allocate shadow stack space for UEFI and align stack
41FF56 40 ; call_[r14+BYTE] !64 # system->boot->allocate_pool(EFI_LOADER_DATA, 2048, &pool)
4883C4 20 ; add_rsp, !32 # deallocate stack
58 ; pop_rax # get pool
C3 ; ret
# Protocol GUIDs
# :LOADED_IMAGE_PROTOCOL [_start+0x3B5]
A1 31 1B 5B ; %0x5b1b31a1
62 95 ; $0x9562
D2 11 ; $0x11d2
8E 3F 00 A0 C9 69 72 3B ; !0x8e !0x3f !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
# :SIMPLE_FS_PROTOCOL [_start+0x3C5]
22 5B 4E 96 ; %0x964e5b22
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+0x3D5]
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+0x3E5]
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+0x3FB]
20 00 2B 00 3E 00 20 00 00 00 ; L" +> "
# :subprocess_error [_start+0x405]
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+0x425]
0A 00 0D ; L"Subprocess error\n\r"
# :ELF_end [_start+0x428]
# :image_handle [_start+0x42B]
# :image [_start+0x433]
# :rootdir [_start+0x43B]
# :root_device [_start+0x443]
# :system_out [_start+0x44B]
# :VirtualSizeEnd [_start+0x453]