diff options
Diffstat (limited to 'crypto-search.cpp')
-rw-r--r-- | crypto-search.cpp | 212 |
1 files changed, 106 insertions, 106 deletions
diff --git a/crypto-search.cpp b/crypto-search.cpp index 164c001..c5cb785 100644 --- a/crypto-search.cpp +++ b/crypto-search.cpp @@ -1,106 +1,106 @@ -/* - * PSX-Tools Bundle Pack - * Copyright (C) 2002 Nicolas "Pixel" Noble - * - * 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 - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include <stdio.h> -#include <stdlib.h> -#ifdef __linux__ -#include <values.h> -#else -#define MAXINT INT_MAX -#define MININT INT_MIN -#endif -#include <string.h> -#include "generic.h" -#include "Input.h" -#include "Main.h" - -CODE_BEGINS -int startup(void) throw (GeneralException) { - int size, mind, maxd, delta, len, i, j; - char * buffer, * str; - Handle * h; - - if (argc != 3) { - printm(M_BARE, "Usage: %s <inputfile> <needle>\n", argv[0]); - exit(-1); - } - - verbosity = M_INFO; - - h = new Input(argv[1]); - - str = argv[2]; - size = h->GetSize(); - -#if 0 - printm(M_STATUS, "Requesting memory (%i bytes)\n", size); - - if (!(buffer = (char *) malloc(size))) { - printm(M_ERROR, "Not enough memory.\n"); - delete h; - exit(-1); - } - - printm(M_STATUS, "Loading file...\n"); - h->read(buffer, size); -#else - printm(M_STATUS, "Mapping file\n"); - - buffer = (char *) h->mmap(); -#endif - printm(M_STATUS, "Done, initialising the search.\n"); - len = strlen(argv[2]); - - mind = MININT; - maxd = MAXINT; - - for (i = 0; i < len; i++) { - mind = (mind < (-str[i])) ? -str[i] : mind; - maxd = (maxd > (255 - str[i])) ? 255 - str[i] : maxd; - } - - printm(M_STATUS, "Min Delta = %i, Max Delta = %i\n", mind, maxd); - - printm(M_STATUS, "Beginning searching...\n"); - - for (i = 0; i < (size - len); i++) { - delta = buffer[i] - str[0]; - if ((delta >= mind) && (delta <= maxd)) { - int good = 1; - for (j = 1; j < len; j++) { - if (((delta + str[j]) != buffer[i + j]) && (str[j] != '.')) { - good = 0; - break; - } - } - if (good) { - printm(M_STATUS, "Found a needle at %i = 0x%08x with delta %i:", i, i, delta); - for (j = 0; j < len; j++) { - printm(M_BARE, "%c", buffer[j + i]); - } - printm(M_BARE, "\n"); - } - } - } - - delete h; - - return 0; -} -CODE_ENDS +/*
+ * PSX-Tools Bundle Pack
+ * Copyright (C) 2002 Nicolas "Pixel" Noble
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#ifdef __linux__
+#include <values.h>
+#else
+#define MAXINT INT_MAX
+#define MININT INT_MIN
+#endif
+#include <string.h>
+#include "generic.h"
+#include "Input.h"
+#include "Main.h"
+
+CODE_BEGINS
+int startup(void) throw (GeneralException) {
+ int size, mind, maxd, delta, len, i, j;
+ char * buffer, * str;
+ Handle * h;
+
+ if (argc != 3) {
+ printm(M_BARE, "Usage: %s <inputfile> <needle>\n", argv[0]);
+ exit(-1);
+ }
+
+ verbosity = M_INFO;
+
+ h = new Input(argv[1]);
+
+ str = argv[2];
+ size = h->GetSize();
+
+#if 0
+ printm(M_STATUS, "Requesting memory (%i bytes)\n", size);
+
+ if (!(buffer = (char *) malloc(size))) {
+ printm(M_ERROR, "Not enough memory.\n");
+ delete h;
+ exit(-1);
+ }
+
+ printm(M_STATUS, "Loading file...\n");
+ h->read(buffer, size);
+#else
+ printm(M_STATUS, "Mapping file\n");
+
+ buffer = (char *) h->mmap();
+#endif
+ printm(M_STATUS, "Done, initialising the search.\n");
+ len = strlen(argv[2]);
+
+ mind = MININT;
+ maxd = MAXINT;
+
+ for (i = 0; i < len; i++) {
+ mind = (mind < (-str[i])) ? -str[i] : mind;
+ maxd = (maxd > (255 - str[i])) ? 255 - str[i] : maxd;
+ }
+
+ printm(M_STATUS, "Min Delta = %i, Max Delta = %i\n", mind, maxd);
+
+ printm(M_STATUS, "Beginning searching...\n");
+
+ for (i = 0; i < (size - len); i++) {
+ delta = buffer[i] - str[0];
+ if ((delta >= mind) && (delta <= maxd)) {
+ int good = 1;
+ for (j = 1; j < len; j++) {
+ if (((delta + str[j]) != buffer[i + j]) && (str[j] != '.')) {
+ good = 0;
+ break;
+ }
+ }
+ if (good) {
+ printm(M_STATUS, "Found a needle at %i = 0x%08x with delta %i:", i, i, delta);
+ for (j = 0; j < len; j++) {
+ printm(M_BARE, "%c", buffer[j + i]);
+ }
+ printm(M_BARE, "\n");
+ }
+ }
+ }
+
+ delete h;
+
+ return 0;
+}
+CODE_ENDS
|