From e1d48107436b0e81eab3c7a0a57d49ccbdd46463 Mon Sep 17 00:00:00 2001 From: Will Xyen Date: Sat, 24 Oct 2020 11:15:58 -0700 Subject: [PATCH] mempatch-hook: fix CRLF --- src/main/mempatch-hook/main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/mempatch-hook/main.c b/src/main/mempatch-hook/main.c index 7ba3571..2c4279f 100644 --- a/src/main/mempatch-hook/main.c +++ b/src/main/mempatch-hook/main.c @@ -78,6 +78,7 @@ static bool patch_memory_apply(char *script) char *pos_line; char *ctx_line; uint32_t line_tokens; + bool use_crlf; char *module; char *address_str = NULL; @@ -99,7 +100,12 @@ static bool patch_memory_apply(char *script) error = false; line_cnt = 0; - pos_lines = strtok_r(script, "\n", &ctx_lines); + + use_crlf = false; + if (strstr(script, "\r\n")) { + use_crlf = true; + } + pos_lines = strtok_r(script, use_crlf ? "\r\n" : "\n", &ctx_lines); while (pos_lines != NULL) { /* ignore comments and empty lines */ @@ -243,7 +249,7 @@ static bool patch_memory_apply(char *script) error = true; next_line: - pos_lines = strtok_r(NULL, "\n", &ctx_lines); + pos_lines = strtok_r(NULL, use_crlf ? "\r\n" : "\n", &ctx_lines); line_cnt++; }