From c787644b824dc1f30dd34a46e4033ffda6272911 Mon Sep 17 00:00:00 2001 From: Eren <66168591+Elpisdev@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:23:54 +0300 Subject: [PATCH] fix overflow and add magic check for bar --- bar.asm | 29 +++++++++++++++++++++++++++-- unarchive.asm | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/bar.asm b/bar.asm index 185c392..3699966 100644 --- a/bar.asm +++ b/bar.asm @@ -1,5 +1,7 @@ section .data FILENAME_SIZE equ 256 + BAR_CHECK1_VALUE equ 3 + BAR_CHECK2_VALUE equ -1 section .bss bar_num_files resw 1 @@ -52,11 +54,26 @@ bar_extract_loop: push 0 push bytes_read - push 8 + push 4 push bar_check1 push dword [file_handle] call _ReadFile@20 + push 0 + push bytes_read + push 4 + push bar_check2 + push dword [file_handle] + call _ReadFile@20 + + mov eax, [bar_check1] + cmp eax, BAR_CHECK1_VALUE + jne .invalid_format + + mov eax, [bar_check2] + cmp eax, BAR_CHECK2_VALUE + jne .invalid_format + call bar_read_file_size test eax, eax jz cleanup @@ -139,8 +156,14 @@ bar_process_filename: jb .trim_loop .trim_done: + test edx, edx + jz .no_increment mov edi, edx inc edi + jmp .set_null +.no_increment: + mov edi, bar_temp_filename +.set_null: mov byte [edi], 0 mov edi, bar_temp_filename @@ -148,7 +171,7 @@ bar_process_filename: mov al, [edi] test al, al jz .done - cmp al, '\\' + cmp al, 92 jne .next_char mov byte [edi], '/' .next_char: @@ -331,6 +354,8 @@ bar_extract_file_data: jmp .done .error: + test ebx, ebx + jz .done push ebx call _CloseHandle@4 xor eax, eax diff --git a/unarchive.asm b/unarchive.asm index 95e09e0..15061d1 100644 --- a/unarchive.asm +++ b/unarchive.asm @@ -28,7 +28,7 @@ section .data msg_usage_len equ $ - msg_usage msg_invalid db "Invalid archive format", 13, 10 msg_invalid_len equ $ - msg_invalid - msg_invalid_bar db "Invalid BAR!", 13, 10 + msg_invalid_bar db "Invalid archive", 13, 10 msg_invalid_bar_len equ $ - msg_invalid_bar msg_open_error db "Failed to open file: ", 13, 10 msg_open_error_len equ $ - msg_open_error