--- mon/src/mon_cmd.cpp 2003/06/19 15:07:46 1.14 +++ mon/src/mon_cmd.cpp 2004/04/20 19:39:03 1.18 @@ -1,7 +1,7 @@ /* * mon_cmd.cpp - cxmon standard commands * - * cxmon (C) 1997-2002 Christian Bauer, Marc Hellwig + * cxmon (C) 1997-2004 Christian Bauer, Marc Hellwig * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -67,10 +67,12 @@ static bool range_args(uintptr *adr, uin * byte_string = (expression | STRING) {COMMA (expression | STRING)} END */ -static bool byte_string(uint8 *s, uintptr &len) +static bool byte_string(uint8 *&str, uintptr &len) { uintptr value; + static const int GRANULARITY = 16; // must be a power of 2 + str = NULL; len = 0; goto start; @@ -81,20 +83,27 @@ static bool byte_string(uint8 *s, uintpt start: if (mon_token == T_STRING) { uint8 *p = (uint8 *)mon_string; - while ((*s++ = *p++) != 0) ; - s--; - len += strlen(mon_string); + unsigned n = strlen(mon_string); + str = (uint8 *)realloc(str, (len + n - 1 + GRANULARITY) & ~(GRANULARITY - 1)); + memcpy(str + len, mon_string, n); + len += n; mon_get_token(); } else if (mon_expression(&value)) { - *s++ = value; + str = (uint8 *)realloc(str, (len + GRANULARITY) & ~(GRANULARITY - 1)); + str[len] = value; len++; - } else + } else { + if (str) + free(str); return false; + } - } else if (mon_token == T_END) + } else if (mon_token == T_END) { return true; - else { + } else { mon_error("',' expected"); + if (str) + free(str); return false; } } @@ -118,7 +127,7 @@ static inline uint8 char2print(uint8 c) void version(void) { - fprintf(monout, "mon V" VERSION "\n"); + fprintf(monout, "cxmon V" VERSION "\n"); } @@ -420,7 +429,7 @@ void disassemble_x86_64(void) void modify(void) { uintptr adr, len, src_adr = 0; - uint8 str[256]; + uint8 *str; if (!mon_expression(&adr)) return; @@ -429,8 +438,9 @@ void modify(void) while (src_adr < len) mon_write_byte(adr++, str[src_adr++]); - mon_dot_address = adr; + + free(str); } @@ -442,7 +452,7 @@ void modify(void) void fill(void) { uintptr adr, end_adr, len, src_adr = 0; - uint8 str[256]; + uint8 *str; if (!mon_expression(&adr)) return; @@ -453,6 +463,8 @@ void fill(void) while (adr <= end_adr) mon_write_byte(adr++, str[src_adr++ % len]); + + free(str); } @@ -535,7 +547,7 @@ void compare(void) void hunt(void) { uintptr adr, end_adr, len; - uint8 str[256]; + uint8 *str; int num = 0; if (!mon_expression(&adr)) @@ -563,6 +575,8 @@ void hunt(void) adr++; } + free(str); + if (num & 7) fputc('\n', monout); fprintf(monout, "Found %d occurrences\n", num);