Fix remaining issues that prevented hex0 from running.
This commit is contained in:
parent
c1df626dc6
commit
54e0c80f9f
|
@ -31,8 +31,9 @@ DEFINE COPY_EAX_to_EDI 89C7
|
|||
DEFINE COPY_RBX_to_R12 4989DC
|
||||
DEFINE COPY_RBX_to_R13 4989DD
|
||||
DEFINE COPY_RCX_to_RAX 4889C1
|
||||
DEFINE COPY_RDX_to_RSP 4889E2
|
||||
DEFINE COPY_RSP_to_RBP 4889E5
|
||||
DEFINE COPY_RSP_to_RDX 4889E2
|
||||
DEFINE COPY_RSP_to_R8 4989E0
|
||||
DEFINE COPY_RBP_to_RSP 4889EC
|
||||
DEFINE COPY_R8_to_RSP 4989E0
|
||||
DEFINE COPY_RCX_to_R9 4989C9
|
||||
|
@ -41,7 +42,8 @@ DEFINE COPY_R12_to_R8 4D89E0
|
|||
DEFINE COPY_R13_to_RCX 4C89E9
|
||||
DEFINE COPY_R13_to_R8 4D89E8
|
||||
DEFINE COPY_R14_to_RCX 4C89F1
|
||||
DEFINE COPY_R15_to_RCX 4889CF
|
||||
DEFINE COPY_R15_to_RCX 4989CF
|
||||
DEFINE COPY_R15_to_R9 4D89F9
|
||||
DEFINE DEC_EBX FFCB
|
||||
DEFINE JE8 74
|
||||
DEFINE JGE8 7D
|
||||
|
@ -57,7 +59,7 @@ DEFINE LOAD64_into_R13_from_Address_RSP_Immediate8 4C8B6C24
|
|||
DEFINE LOAD64_into_R14_from_Address_RDX_Immediate8 4C8B72
|
||||
DEFINE LOAD64_into_R14_from_Address_R14_Immediate32 4D8BB6
|
||||
DEFINE LOAD8_AL_from_Address_RBX 8A03
|
||||
DEFINE LOADI64_rel_RDX 488905
|
||||
DEFINE LOADI64_rel_RDX 488B15
|
||||
DEFINE POP_RAX 58
|
||||
DEFINE POP_RBX 5B
|
||||
DEFINE POP_RSI 5E
|
||||
|
@ -70,8 +72,8 @@ DEFINE PUSH_RDX 52
|
|||
DEFINE PUSH_RSI 56
|
||||
DEFINE RET C3
|
||||
DEFINE ROR_R9 49D1C9
|
||||
DEFINE SHL_EBP_Immediate8 C1E5
|
||||
DEFINE STOREI8_into_Address_RBX CB03
|
||||
DEFINE SHL_EDI_Immediate8 C1E7
|
||||
DEFINE STOREI8_into_Address_RBX C603
|
||||
DEFINE SUBI8_RSP 4883EC
|
||||
DEFINE SUBI8_AL 2C
|
||||
DEFINE XOR_EBX_EBX 31DB
|
||||
|
@ -89,15 +91,15 @@ DEFINE TEST_ESI_ESI 85F6
|
|||
|
||||
# Open Loaded Image protocol
|
||||
PUSH_RAX # allocate stack for image
|
||||
COPY_R8_to_RSP # arg3 = &image
|
||||
COPY_RSP_to_R8 # arg3 = &image
|
||||
LOADI64_rel_RDX %LOADED_IMAGE_PROTOCOL_8 # EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
||||
PUSH_RDX # push last 64 bits onto stack
|
||||
LOADI64_rel_RDX %LOADED_IMAGE_PROTOCOL # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
||||
PUSH_RDX # push first 64 bits onto stack
|
||||
COPY_RDX_to_RSP # arg2 = &guid
|
||||
COPY_RSP_to_RDX # arg2 = &guid
|
||||
PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||
PUSH !0 # arg5 = NULL
|
||||
COPY_R8_to_RSP # arg4 = image_handle
|
||||
COPY_RCX_to_R9 # arg4 = image_handle
|
||||
# arg1 = ImageHandle (already set)
|
||||
SUBI8_RSP !32 # allocate shadow stack space for UEFI function
|
||||
CALL_R14 # system->boot->open_protocol(image_handle, &guid, &image, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||
|
@ -122,21 +124,21 @@ DEFINE TEST_ESI_ESI 85F6
|
|||
CMPI8_AL !0x20 # if *options != ' '
|
||||
JNE8 !loop_options2 # then jump
|
||||
|
||||
STOREI8_into_Address_RBX # *options = 0;
|
||||
STOREI8_into_Address_RBX !0 # *options = 0;
|
||||
ADDI8_RBX !2 # ++options
|
||||
COPY_RBX_to_R13 # save output file
|
||||
|
||||
# Get root device
|
||||
PUSH_RAX # allocate stack for rootfs
|
||||
COPY_R8_to_RSP # arg3 = &rootfs
|
||||
COPY_RSP_to_R8 # arg3 = &rootfs
|
||||
LOADI64_rel_RDX %SIMPLE_FS_PROTOCOL_8 # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
||||
PUSH_RDX # push last 64 bits onto stack
|
||||
LOADI64_rel_RDX %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
||||
PUSH_RDX # push first 64 bits onto stack
|
||||
COPY_RDX_to_RSP # arg2 = &guid
|
||||
COPY_RSP_to_RDX # arg2 = &guid
|
||||
PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||
PUSH !0 # arg5 = NULL
|
||||
COPY_R8_to_RSP # arg4 = image_handle
|
||||
COPY_R15_to_R9 # arg4 = image_handle
|
||||
LOAD64_into_RCX_from_Address_RCX_Immediate8 !24 # arg1 = root_device = image->device
|
||||
SUBI8_RSP !32 # allocate shadow stack space for UEFI function
|
||||
CALL_R14 # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||
|
@ -144,7 +146,7 @@ DEFINE TEST_ESI_ESI 85F6
|
|||
|
||||
# Get root directory
|
||||
PUSH_RDX # allocate stack for rootdir
|
||||
COPY_RDX_to_RSP # arg2 = &rootdir
|
||||
COPY_RSP_to_RDX # arg2 = &rootdir
|
||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
||||
CALL_RCX_Immediate8 !8 # rootfs->open_volume(rootfs, &rootdir)
|
||||
|
@ -154,7 +156,7 @@ DEFINE TEST_ESI_ESI 85F6
|
|||
|
||||
# Open file for writing
|
||||
PUSH_RDX # allocate stack for fout
|
||||
COPY_RDX_to_RSP # arg2 = &fout
|
||||
COPY_RSP_to_RDX # arg2 = &fout
|
||||
PUSH !0 # arg5 = 0
|
||||
PUSH !7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
||||
POP_R9 # and then do right rotation by 1
|
||||
|
@ -167,7 +169,7 @@ DEFINE TEST_ESI_ESI 85F6
|
|||
|
||||
# Open file for reading
|
||||
PUSH_RDX # allocate stack for fin
|
||||
COPY_RDX_to_RSP # arg2 = &fin
|
||||
COPY_RSP_to_RDX # arg2 = &fin
|
||||
PUSH !1 # arg5 = EFI_FILE_READ_ONLY
|
||||
PUSH !1 # prepare to set arg4 to EFI_FILE_MODE_READ
|
||||
POP_R9 # arg4 = EFI_FILE_MODE_READ
|
||||
|
@ -207,7 +209,7 @@ DEFINE TEST_ESI_ESI 85F6
|
|||
# process second byte of pair
|
||||
:print
|
||||
# update the sum and store in output
|
||||
SHL_EBP_Immediate8 !4
|
||||
SHL_EDI_Immediate8 !4
|
||||
ADD_EAX_EDI
|
||||
|
||||
# flip the toggle
|
||||
|
@ -283,9 +285,9 @@ DEFINE TEST_ESI_ESI 85F6
|
|||
:write_byte
|
||||
COPY_R13_to_RCX # arg1 = fout
|
||||
PUSH !1 # size = 1
|
||||
COPY_RDX_to_RSP # arg2 = &size
|
||||
COPY_RSP_to_RDX # arg2 = &size
|
||||
PUSH_RAX # allocate stack
|
||||
COPY_R8_to_RSP # arg3 = &output
|
||||
COPY_RSP_to_R8 # arg3 = &output
|
||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
||||
|
@ -297,9 +299,9 @@ DEFINE TEST_ESI_ESI 85F6
|
|||
:read_byte
|
||||
COPY_R12_to_RCX # arg1 = fin
|
||||
PUSH !1 # size = 1
|
||||
COPY_RDX_to_RSP # arg2 = &size
|
||||
COPY_RSP_to_RDX # arg2 = &size
|
||||
PUSH_RSI # allocate stack
|
||||
COPY_R8_to_RSP # arg3 = &input
|
||||
COPY_RSP_to_R8 # arg3 = &input
|
||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
||||
PUSH_RAX # allocate shadow stack space for UEFI function
|
||||
|
|
|
@ -23,21 +23,21 @@
|
|||
# efi_main(void *image_handle, struct efi_system_table *system)
|
||||
:_start
|
||||
4889E5 ; COPY_RSP_to_RBP # save stack pointer
|
||||
4889CF ; COPY_R15_to_RCX # save image_handle
|
||||
4989CF ; COPY_R15_to_RCX # save image_handle
|
||||
4C8B72 60 ; LOAD64_into_R14_from_Address_RDX_Immediate8 !96 # system->boot
|
||||
4D8BB6 18010000 ; LOAD64_into_R14_from_Address_R14_Immediate32 %280 # system->boot->open_protocol
|
||||
|
||||
# Open Loaded Image protocol
|
||||
50 ; PUSH_RAX # allocate stack for image
|
||||
4989E0 ; COPY_R8_to_RSP # arg3 = &image
|
||||
488905 %LOADED_IMAGE_PROTOCOL_8 ; LOADI64_rel_RDX !LOADED_IMAGE_PROTOCOL_8 # EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &image
|
||||
488B15 %LOADED_IMAGE_PROTOCOL_8 ; LOADI64_rel_RDX !LOADED_IMAGE_PROTOCOL_8 # EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
||||
52 ; PUSH_RDX # push last 64 bits onto stack
|
||||
488905 %LOADED_IMAGE_PROTOCOL ; LOADI64_rel_RDX !LOADED_IMAGE_PROTOCOL # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
||||
488B15 %LOADED_IMAGE_PROTOCOL ; LOADI64_rel_RDX !LOADED_IMAGE_PROTOCOL # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
||||
52 ; PUSH_RDX # push first 64 bits onto stack
|
||||
4889E2 ; COPY_RDX_to_RSP # arg2 = &guid
|
||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &guid
|
||||
6A 01 ; PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||
6A 00 ; PUSH !0 # arg5 = NULL
|
||||
4989E0 ; COPY_R8_to_RSP # arg4 = image_handle
|
||||
4989C9 ; COPY_RCX_to_R9 # arg4 = image_handle
|
||||
# arg1 = ImageHandle (already set)
|
||||
4883EC 20 ; SUBI8_RSP !32 # allocate shadow stack space for UEFI function
|
||||
41FFD6 ; CALL_R14 # system->boot->open_protocol(image_handle, &guid, &image, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||
|
@ -62,21 +62,21 @@
|
|||
3C 20 ; CMPI8_AL !0x20 # if *options != ' '
|
||||
75 !loop_options2 ; JNE8 !loop_options2 # then jump
|
||||
|
||||
CB03 ; STOREI8_into_Address_RBX # *options = 0;
|
||||
C603 00 ; STOREI8_into_Address_RBX !0 # *options = 0;
|
||||
4883C3 02 ; ADDI8_RBX !2 # ++options
|
||||
4989DD ; COPY_RBX_to_R13 # save output file
|
||||
|
||||
# Get root device
|
||||
50 ; PUSH_RAX # allocate stack for rootfs
|
||||
4989E0 ; COPY_R8_to_RSP # arg3 = &rootfs
|
||||
488905 %SIMPLE_FS_PROTOCOL_8 ; LOADI64_rel_RDX %SIMPLE_FS_PROTOCOL_8 # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &rootfs
|
||||
488B15 %SIMPLE_FS_PROTOCOL_8 ; LOADI64_rel_RDX %SIMPLE_FS_PROTOCOL_8 # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
||||
52 ; PUSH_RDX # push last 64 bits onto stack
|
||||
488905 %SIMPLE_FS_PROTOCOL ; LOADI64_rel_RDX %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
||||
488B15 %SIMPLE_FS_PROTOCOL ; LOADI64_rel_RDX %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
||||
52 ; PUSH_RDX # push first 64 bits onto stack
|
||||
4889E2 ; COPY_RDX_to_RSP # arg2 = &guid
|
||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &guid
|
||||
6A 01 ; PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||
6A 00 ; PUSH !0 # arg5 = NULL
|
||||
4989E0 ; COPY_R8_to_RSP # arg4 = image_handle
|
||||
4D89F9 ; COPY_R15_to_R9 # arg4 = image_handle
|
||||
488B49 18 ; LOAD64_into_RCX_from_Address_RCX_Immediate8 !24 # arg1 = root_device = image->device
|
||||
4883EC 20 ; SUBI8_RSP !32 # allocate shadow stack space for UEFI function
|
||||
41FFD6 ; CALL_R14 # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||
|
@ -84,7 +84,7 @@
|
|||
|
||||
# Get root directory
|
||||
52 ; PUSH_RDX # allocate stack for rootdir
|
||||
4889E2 ; COPY_RDX_to_RSP # arg2 = &rootdir
|
||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &rootdir
|
||||
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
||||
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
||||
FF51 08 ; CALL_RCX_Immediate8 !8 # rootfs->open_volume(rootfs, &rootdir)
|
||||
|
@ -94,7 +94,7 @@
|
|||
|
||||
# Open file for writing
|
||||
52 ; PUSH_RDX # allocate stack for fout
|
||||
4889E2 ; COPY_RDX_to_RSP # arg2 = &fout
|
||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &fout
|
||||
6A 00 ; PUSH !0 # arg5 = 0
|
||||
6A 07 ; PUSH !7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
||||
4159 ; POP_R9 # and then do right rotation by 1
|
||||
|
@ -107,7 +107,7 @@
|
|||
|
||||
# Open file for reading
|
||||
52 ; PUSH_RDX # allocate stack for fin
|
||||
4889E2 ; COPY_RDX_to_RSP # arg2 = &fin
|
||||
4889E2 ; COPY_RSP_to_RDX # 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
|
||||
|
@ -147,7 +147,7 @@
|
|||
# process second byte of pair
|
||||
:print
|
||||
# update the sum and store in output
|
||||
C1E5 04 ; SHL_EBP_Immediate8 !4
|
||||
C1E7 04 ; SHL_EDI_Immediate8 !4
|
||||
01F8 ; ADD_EAX_EDI
|
||||
|
||||
# flip the toggle
|
||||
|
@ -223,9 +223,9 @@
|
|||
:write_byte
|
||||
4C89E9 ; COPY_R13_to_RCX # arg1 = fout
|
||||
6A 01 ; PUSH !1 # size = 1
|
||||
4889E2 ; COPY_RDX_to_RSP # arg2 = &size
|
||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &size
|
||||
50 ; PUSH_RAX # allocate stack
|
||||
4989E0 ; COPY_R8_to_RSP # arg3 = &output
|
||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &output
|
||||
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
|
||||
|
@ -237,9 +237,9 @@
|
|||
:read_byte
|
||||
4C89E1 ; COPY_R12_to_RCX # arg1 = fin
|
||||
6A 01 ; PUSH !1 # size = 1
|
||||
4889E2 ; COPY_RDX_to_RSP # arg2 = &size
|
||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &size
|
||||
56 ; PUSH_RSI # allocate stack
|
||||
4989E0 ; COPY_R8_to_RSP # arg3 = &input
|
||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &input
|
||||
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
|
||||
|
|
|
@ -56,7 +56,7 @@ F0 00 # SizeOfOptionalHeader
|
|||
# COFF header bits
|
||||
0B 02 # Magic PE32+ (64 bit)
|
||||
00 00 # Linker version
|
||||
A2 01 00 00 # size of code
|
||||
A3 01 00 00 # size of code
|
||||
00 00 00 00 # sizeOfInitializedData
|
||||
00 00 00 00 # SizeOfUninitializedData
|
||||
00 10 00 00 # AddressOfEntryPoint
|
||||
|
@ -136,9 +136,9 @@ A2 01 00 00 # size of code
|
|||
# [0x148]
|
||||
# Start of section headers
|
||||
2E 74 65 78 74 00 00 00 ; Name: ".text"
|
||||
A2 01 00 00 ; VirtualSize
|
||||
A3 01 00 00 ; VirtualSize
|
||||
00 10 00 00 ; VirtualAddress
|
||||
A2 01 00 00 ; SizeOfRawData
|
||||
A3 01 00 00 ; SizeOfRawData
|
||||
70 01 00 00 ; PointerToRawData
|
||||
00 00 00 00 ; PointerToRelocations
|
||||
00 00 00 00 ; PointerToLinenumbers
|
||||
|
@ -151,23 +151,23 @@ A2 01 00 00 ; SizeOfRawData
|
|||
# efi_main(void *image_handle, struct efi_system_table *system)
|
||||
# :_start
|
||||
4889E5 ; COPY_RSP_to_RBP # save stack pointer
|
||||
4889CF ; COPY_R15_to_RCX # save image_handle
|
||||
4989CF ; COPY_R15_to_RCX # save image_handle
|
||||
4C8B72 60 ; LOAD64_into_R14_from_Address_RDX_Immediate8 !96 # system->boot
|
||||
4D8BB6 18010000 ; LOAD64_into_R14_from_Address_R14_Immediate32 %280 # system->boot->open_protocol
|
||||
|
||||
# Open Loaded Image protocol
|
||||
50 ; PUSH_RAX # allocate stack for image
|
||||
4989E0 ; COPY_R8_to_RSP # arg3 = &image
|
||||
488905 6E010000 ; LOADI64_rel_RDX !LOADED_IMAGE_PROTOCOL_8 # EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &image
|
||||
488B15 6F010000 ; LOADI64_rel_RDX !LOADED_IMAGE_PROTOCOL_8 # EFI_LOADED_IMAGE_PROTOCOL_GUID (last 64 bits)
|
||||
# [_start+0x1C]
|
||||
52 ; PUSH_RDX # push last 64 bits onto stack
|
||||
488905 5E010000 ; LOADI64_rel_RDX !LOADED_IMAGE_PROTOCOL # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
||||
488B15 5F010000 ; LOADI64_rel_RDX !LOADED_IMAGE_PROTOCOL # EFI_LOADED_IMAGE_PROTOCOL_GUID (first 64 bits)
|
||||
# [_start+0x24]
|
||||
52 ; PUSH_RDX # push first 64 bits onto stack
|
||||
4889E2 ; COPY_RDX_to_RSP # arg2 = &guid
|
||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &guid
|
||||
6A 01 ; PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||
6A 00 ; PUSH !0 # arg5 = NULL
|
||||
4989E0 ; COPY_R8_to_RSP # arg4 = image_handle
|
||||
4989C9 ; COPY_RCX_to_R9 # arg4 = image_handle
|
||||
# arg1 = ImageHandle (already set)
|
||||
4883EC 20 ; SUBI8_RSP !32 # allocate shadow stack space for UEFI function
|
||||
41FFD6 ; CALL_R14 # system->boot->open_protocol(image_handle, &guid, &image, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||
|
@ -192,21 +192,21 @@ A2 01 00 00 ; SizeOfRawData
|
|||
3C 20 ; CMPI8_AL !0x20 # if *options != ' '
|
||||
75 F6 ; JNE8 !loop_options2 # then jump
|
||||
|
||||
CB03 ; STOREI8_into_Address_RBX # *options = 0;
|
||||
C603 00 ; STOREI8_into_Address_RBX !0 # *options = 0;
|
||||
4883C3 02 ; ADDI8_RBX !2 # ++options
|
||||
4989DD ; COPY_RBX_to_R13 # save output file
|
||||
|
||||
# Get root device [_start+0x66]
|
||||
# Get root device [_start+0x67]
|
||||
50 ; PUSH_RAX # allocate stack for rootfs
|
||||
4989E0 ; COPY_R8_to_RSP # arg3 = &rootfs
|
||||
488905 29010000 ; LOADI64_rel_RDX %SIMPLE_FS_PROTOCOL_8 # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
||||
488B15 29010000 ; LOADI64_rel_RDX %SIMPLE_FS_PROTOCOL_8 # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (last 64 bits)
|
||||
52 ; PUSH_RDX # push last 64 bits onto stack
|
||||
488905 19010000 ; LOADI64_rel_RDX %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
||||
488B15 19010000 ; LOADI64_rel_RDX %SIMPLE_FS_PROTOCOL # EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID (first 64 bits)
|
||||
52 ; PUSH_RDX # push first 64 bits onto stack
|
||||
4889E2 ; COPY_RDX_to_RSP # arg2 = &guid
|
||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &guid
|
||||
6A 01 ; PUSH !1 # arg6 = EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
|
||||
6A 00 ; PUSH !0 # arg5 = NULL
|
||||
4989E0 ; COPY_R8_to_RSP # arg4 = image_handle
|
||||
4D89F9 ; COPY_R15_to_R9 # arg4 = image_handle
|
||||
488B49 18 ; LOAD64_into_RCX_from_Address_RCX_Immediate8 !24 # arg1 = root_device = image->device
|
||||
4883EC 20 ; SUBI8_RSP !32 # allocate shadow stack space for UEFI function
|
||||
41FFD6 ; CALL_R14 # system->boot->open_protocol(root_device, &guid, &rootfs, image_handle, 0, EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)
|
||||
|
@ -214,7 +214,7 @@ A2 01 00 00 ; SizeOfRawData
|
|||
|
||||
# Get root directory
|
||||
52 ; PUSH_RDX # allocate stack for rootdir
|
||||
4889E2 ; COPY_RDX_to_RSP # arg2 = &rootdir
|
||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &rootdir
|
||||
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
||||
50 ; PUSH_RAX # allocate shadow stack space for UEFI function
|
||||
FF51 08 ; CALL_RCX_Immediate8 !8 # rootfs->open_volume(rootfs, &rootdir)
|
||||
|
@ -224,7 +224,7 @@ A2 01 00 00 ; SizeOfRawData
|
|||
|
||||
# Open file for writing
|
||||
52 ; PUSH_RDX # allocate stack for fout
|
||||
4889E2 ; COPY_RDX_to_RSP # arg2 = &fout
|
||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &fout
|
||||
6A 00 ; PUSH !0 # arg5 = 0
|
||||
6A 07 ; PUSH !7 # to get 0x8000000000000003 we set the rightmost 3 bits
|
||||
4159 ; POP_R9 # and then do right rotation by 1
|
||||
|
@ -237,7 +237,7 @@ A2 01 00 00 ; SizeOfRawData
|
|||
|
||||
# Open file for reading
|
||||
52 ; PUSH_RDX # allocate stack for fin
|
||||
4889E2 ; COPY_RDX_to_RSP # arg2 = &fin
|
||||
4889E2 ; COPY_RSP_to_RDX # 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
|
||||
|
@ -254,7 +254,7 @@ A2 01 00 00 ; SizeOfRawData
|
|||
# temp storage for the sum
|
||||
31FF ; XOR_EDI_EDI # rdi = 0
|
||||
|
||||
# :loop # [_start+0xE1]
|
||||
# :loop # [_start+0xE2]
|
||||
# Read a byte
|
||||
E8 6F000000 ; CALLI32 %read_byte
|
||||
|
||||
|
@ -275,9 +275,9 @@ A2 01 00 00 ; SizeOfRawData
|
|||
EB E8 ; JMP8 !loop
|
||||
|
||||
# process second byte of pair
|
||||
# :print [_start+0xF9]
|
||||
# :print [_start+0xFA]
|
||||
# update the sum and store in output
|
||||
C1E5 04 ; SHL_EBP_Immediate8 !4
|
||||
C1E7 04 ; SHL_EDI_Immediate8 !4
|
||||
01F8 ; ADD_EAX_EDI
|
||||
|
||||
# flip the toggle
|
||||
|
@ -287,7 +287,7 @@ A2 01 00 00 ; SizeOfRawData
|
|||
|
||||
EB DA ; JMP8 !loop
|
||||
|
||||
# :hex [_start+0x107]
|
||||
# :hex [_start+0x108]
|
||||
# Purge Comment Lines (#)
|
||||
3C 23 ; CMPI8_AL !35
|
||||
74 1E ; JE8 !purge_comment
|
||||
|
@ -323,7 +323,7 @@ A2 01 00 00 ; SizeOfRawData
|
|||
# The rest that remains needs to be ignored
|
||||
EB 09 ; JMP8 !ascii_other
|
||||
|
||||
# :purge_comment [_start+0x129]
|
||||
# :purge_comment [_start+0x12A]
|
||||
# Read a byte
|
||||
E8 27000000 ; CALLI32 %read_byte
|
||||
|
||||
|
@ -333,29 +333,29 @@ A2 01 00 00 ; SizeOfRawData
|
|||
|
||||
# Otherwise return -1
|
||||
|
||||
# :ascii_other [_start+0x132]
|
||||
# :ascii_other [_start+0x133]
|
||||
6A FF ; PUSH !-1
|
||||
58 ; POP_RAX # return = -1
|
||||
C3 ; RET
|
||||
|
||||
# :ascii_num [_start+0x136]
|
||||
# :ascii_num [_start+0x137]
|
||||
2C 30 ; SUBI8_AL !48
|
||||
C3 ; RET
|
||||
|
||||
# :ascii_low [_start+0x139]
|
||||
# :ascii_low [_start+0x13A]
|
||||
2C 20 ; SUBI8_AL !32 # convert to uppercase
|
||||
|
||||
# :ascii_high [_start+0x13B]
|
||||
# :ascii_high [_start+0x13C]
|
||||
2C 37 ; SUBI8_AL !55
|
||||
C3 ; RET
|
||||
|
||||
# Writes byte stored in al
|
||||
# :write_byte [_start+0x13E]
|
||||
# :write_byte [_start+0x13F]
|
||||
4C89E9 ; COPY_R13_to_RCX # arg1 = fout
|
||||
6A 01 ; PUSH !1 # size = 1
|
||||
4889E2 ; COPY_RDX_to_RSP # arg2 = &size
|
||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &size
|
||||
50 ; PUSH_RAX # allocate stack
|
||||
4989E0 ; COPY_R8_to_RSP # arg3 = &output
|
||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &output
|
||||
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
|
||||
|
@ -364,12 +364,12 @@ A2 01 00 00 ; SizeOfRawData
|
|||
|
||||
C3 ; RET # return
|
||||
|
||||
# :read_byte [_start+0x155]
|
||||
# :read_byte [_start+0x156]
|
||||
4C89E1 ; COPY_R12_to_RCX # arg1 = fin
|
||||
6A 01 ; PUSH !1 # size = 1
|
||||
4889E2 ; COPY_RDX_to_RSP # arg2 = &size
|
||||
4889E2 ; COPY_RSP_to_RDX # arg2 = &size
|
||||
56 ; PUSH_RSI # allocate stack
|
||||
4989E0 ; COPY_R8_to_RSP # arg3 = &input
|
||||
4989E0 ; COPY_RSP_to_R8 # arg3 = &input
|
||||
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
|
||||
|
@ -386,7 +386,7 @@ A2 01 00 00 ; SizeOfRawData
|
|||
|
||||
C3 ; RET # return
|
||||
|
||||
# :terminate [_start+0x171]
|
||||
# :terminate [_start+0x172]
|
||||
53 ; PUSH_RBX # allocate stack
|
||||
4C89E1 ; COPY_R12_to_RCX # arg1 = fin
|
||||
FF51 10 ; CALL_RCX_Immediate8 !16 # fin->close()
|
||||
|
@ -398,18 +398,18 @@ A2 01 00 00 ; SizeOfRawData
|
|||
|
||||
|
||||
# Protocol GUIDs
|
||||
# :LOADED_IMAGE_PROTOCOL [_start+0x182]
|
||||
# :LOADED_IMAGE_PROTOCOL [_start+0x183]
|
||||
A1 31 1B 5B ; %0x5b1b31a1
|
||||
62 95 ; @0x9562
|
||||
D2 11 ; @0x11d2
|
||||
# :LOADED_IMAGE_PROTOCOL_8 [_start+0x18A]
|
||||
# :LOADED_IMAGE_PROTOCOL_8 [_start+0x18B]
|
||||
8E 3F 00 A0 C9 69 72 3B ; !0x8e !0x3f !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
|
||||
|
||||
# :SIMPLE_FS_PROTOCOL [_start+0x192]
|
||||
# :SIMPLE_FS_PROTOCOL [_start+0x193]
|
||||
22 5B 4E 96 ; %0x0964e5b22
|
||||
59 64 ; @0x6459
|
||||
D2 11 ; @0x11d2
|
||||
# :SIMPLE_FS_PROTOCOL_8 [_start+0x19A]
|
||||
# :SIMPLE_FS_PROTOCOL_8 [_start+0x19B]
|
||||
8E 39 00 A0 C9 69 72 3B ; !0x8e !0x39 !0 !0xa0 !0xc9 !0x69 !0x72 !0x3b
|
||||
|
||||
# [0x1A2]
|
||||
# [0x1A3]
|
||||
|
|
Loading…
Reference in New Issue