From 15b3bffb7ff8f0ee8091e62cddb1682f2bf8d2d2 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Sat, 12 Feb 2011 18:30:26 -0500 Subject: SCI: Fix the console's hexgrep command --- engines/sci/console.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index 562b770afa..9510ed0afb 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -773,17 +773,16 @@ bool Console::cmdResourceTypes(int argc, const char **argv) { bool Console::cmdHexgrep(int argc, const char **argv) { if (argc < 4) { - DebugPrintf("Searches some resources for a particular sequence of bytes, represented as hexadecimal numbers.\n"); + DebugPrintf("Searches some resources for a particular sequence of bytes, represented as decimal or hexadecimal numbers.\n"); DebugPrintf("Usage: %s \n", argv[0]); DebugPrintf(" can be a specific resource number, or \"all\" for all of the resources of the specified type\n"); - DebugPrintf("EXAMPLES:\n hexgrep script all e8 03 c8 00\n hexgrep pic 042 fe"); + DebugPrintf("EXAMPLES:\n hexgrep script all 0xe8 0x03 0xc8 0x00\n hexgrep pic 0x42 0xfe\n"); cmdResourceTypes(argc, argv); return true; } ResourceType restype = parseResourceType(argv[1]); int resNumber = 0, resMax = 0; - char seekString[500]; Resource *script = NULL; if (restype == kResourceTypeInvalid) { @@ -798,12 +797,13 @@ bool Console::cmdHexgrep(int argc, const char **argv) { resNumber = resMax = atoi(argv[2]); } - strcpy(seekString, argv[3]); + // Convert the bytes + Common::Array byteString; + byteString.resize(argc - 3); - // Construct the seek string - for (int i = 4; i < argc; i++) { - strcat(seekString, argv[i]); - } + for (uint i = 0; i < byteString.size(); i++) + if (!parseInteger(argv[i + 3], byteString[i])) + return true; for (; resNumber <= resMax; resNumber++) { script = _engine->getResMan()->findResource(ResourceId(restype, resNumber), 0); @@ -813,13 +813,13 @@ bool Console::cmdHexgrep(int argc, const char **argv) { int output_script_name = 0; while (seeker < script->size) { - if (script->data[seeker] == seekString[comppos]) { + if (script->data[seeker] == byteString[comppos]) { if (comppos == 0) seekerold = seeker; comppos++; - if (comppos == strlen(seekString)) { + if (comppos == byteString.size()) { comppos = 0; seeker = seekerold + 1; -- cgit v1.2.3