From 6b857fc253fd5d6c34627f80f6898a0f423bac34 Mon Sep 17 00:00:00 2001 From: n-a-c-h Date: Tue, 27 May 2008 15:35:03 +0000 Subject: [PATCH] Fixed unprotect_buffer(). git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@536 a31d4220-a93d-0410-bf67-fe4944624d44 --- src/win32/protect.c | 25 +++++++++++++------------ src/win32/protect.h | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/win32/protect.c b/src/win32/protect.c index 284f8a27..696d4883 100644 --- a/src/win32/protect.c +++ b/src/win32/protect.c @@ -16,18 +16,19 @@ int ExecutableValid(const char *executable_filename) #else -void unprotect_buf(char *buffer, size_t buffer_len) -{ - char *end_p = buffer+buffer_len, previous = 0x11; - while (buffer < end_p) - { - char current = *buffer; - *buffer ^= previous; - previous = current; - *buffer -= 25; - *buffer ^= 0x87; - ++buffer; - } +char *unprotect_buffer(char *buffer, size_t buffer_len) +{ + char *p = buffer, *end_p = p+buffer_len-1, previous = 0x11; + while (p < end_p) + { + char current = *p; + *p ^= previous; + previous = current; + *p -= 25; + *p ^= 0x87; + ++p; + } + return(buffer); } static uint8_t *memmem(const uint8_t *haystack, size_t haystacklen, const uint8_t *needle, size_t needlelen) diff --git a/src/win32/protect.h b/src/win32/protect.h index c99ace29..2393cbae 100644 --- a/src/win32/protect.h +++ b/src/win32/protect.h @@ -8,7 +8,7 @@ extern "C" { //Returns 0 on success, 1 on failure, and <0 when an error occured //Note, can only be called once per execution int ExecutableValid(const char *executable_filename); -void unprotect_buf(char *buffer, size_t buffer_len) +char *unprotect_buffer(char *buffer, size_t buffer_len); #if defined(__cplusplus) }