diff --git a/TheMatrix/TheMatrix.vcxproj b/TheMatrix/TheMatrix.vcxproj index 95b6883..55b6970 100644 --- a/TheMatrix/TheMatrix.vcxproj +++ b/TheMatrix/TheMatrix.vcxproj @@ -149,7 +149,7 @@ true - C:\Workspace\TheMatrix\Baseline\add_resource_x64.bat + ..\add_resource_x64.bat diff --git a/TheMatrix/const.inc b/TheMatrix/const.inc index 8305e30..bf3f370 100644 --- a/TheMatrix/const.inc +++ b/TheMatrix/const.inc @@ -14,9 +14,8 @@ GENERIC_WRITE equ 40000000h GENERIC_READ_WRITE equ GENERIC_READ or GENERIC_WRITE CREATE_NEW equ 1 OPEN_EXISTING equ 3 -ERROR_FILE_NOT_FOUND equ 2 INVALID_FILE_SIZE equ 0FFFFFFFFh -INVALID_HANDLE_VALUE equ 0FFFFFFFFh +INVALID_HANDLE_VALUE equ -1 MEM_COMMIT equ 1000h MEM_DECOMMIT equ 4000h PAGE_READWRITE equ 4h diff --git a/TheMatrix/x64_builder.inc b/TheMatrix/x64_builder.inc index 8a498eb..eb40fc4 100644 --- a/TheMatrix/x64_builder.inc +++ b/TheMatrix/x64_builder.inc @@ -11,10 +11,14 @@ add_resource proc frame _CreateFrame ar_,LOCALS_SIZE,0,rdi _EndProlog + _AllocHomeArea mov qword ptr ar_OffsetHomeRCX[rbp], rcx mov qword ptr ar_OffsetHomeRDX[rbp], rdx + ; used for stack alignment + sub rsp, sizeof qword + ; get the size of the file to embed push 0h push 0h @@ -23,10 +27,9 @@ add_resource proc frame xor r8, r8 mov rdx, GENERIC_READ mov rcx, qword ptr ar_OffsetHomeRDX[rbp] - _AllocHomeArea call CreateFileW - test rax, rax + cmp rax, INVALID_HANDLE_VALUE jz @fail mov qword ptr ar_hFile[rbp], rax @@ -47,6 +50,9 @@ add_resource proc frame jz @fail mov qword ptr ar_buffer[rbp], rax + ; used for stack alignment + sub rsp, 3 * sizeof qword + ; read the file content push 0 lea r9, qword ptr LOCALS.Local4[rbp] @@ -73,6 +79,9 @@ add_resource proc frame jz @fail mov qword ptr ar_hRes[rbp], rax + ; used for stack alignment + sub rsp, 2 * sizeof qword + push qword ptr ar_file_size[rbp] push qword ptr ar_buffer[rbp] xor r9, r9 @@ -201,6 +210,9 @@ clone_file proc frame cmp dword ptr LOCALS.Local3[rbp], 'lld.' jne @f + ; used for stack alignment + sub rsp, sizeof qword + ; read the file content push 0h push 0h @@ -229,6 +241,9 @@ clone_file proc frame jz @fail mov rdi, rax ; save buffer ptr + ; used for stack alignment + sub rsp, 3 * sizeof qword + ; read the file content push 0 lea r9, qword ptr LOCALS.Local4[rbp] @@ -262,12 +277,15 @@ clone_file proc frame cmp rax, INVALID_SET_FILE_POINTER je @fail + ; used for stack alignment + sub rsp, 3 * sizeof qword + ; write back the result + push 0h mov rcx, rsi mov rdx, rdi mov r8, rbx - lea r9, qword ptr LOCALS.Local4[rbp] - push 0h + lea r9, qword ptr LOCALS.Local4[rbp] _AllocHomeArea call WriteFile test rax, rax @@ -281,7 +299,6 @@ clone_file proc frame call heap_free @@: - ; return the name of the cloned file mov rax, qword ptr LOCALS.Local2[rbp] diff --git a/TheMatrix/x64_console.inc b/TheMatrix/x64_console.inc index bcfc196..a97f20f 100644 --- a/TheMatrix/x64_console.inc +++ b/TheMatrix/x64_console.inc @@ -16,6 +16,9 @@ print_buffer proc frame test rax, rax jz @fail + ; used for stack alignment + sub rsp, 3 * sizeof qword + push 0 lea r9, LOCALS.Local1[rbp] mov r8, qword ptr pb_OffsetHomeRDX[rbp] diff --git a/TheMatrix/x86_builder.inc b/TheMatrix/x86_builder.inc index 5175a4d..70d0240 100644 --- a/TheMatrix/x86_builder.inc +++ b/TheMatrix/x86_builder.inc @@ -12,7 +12,7 @@ add_resource proc file_to_add:ptr char , target_file:ptr char ; get file to add size invoke CreateFileW, file_to_add, GENERIC_READ, 0h, 0h, OPEN_EXISTING, 0h, 0h - cmp eax, ERROR_FILE_NOT_FOUND + cmp eax, INVALID_HANDLE_VALUE je @fail mov hFile, eax invoke GetFileSize, hFile, 0h