a3: memdump funktioniert

This commit is contained in:
Johannes Theiner 2018-11-08 10:16:07 +01:00
parent 27127d5d4c
commit ebd099bef6
1 changed files with 16 additions and 11 deletions

View File

@ -7,21 +7,21 @@
void memdump(unsigned char *string) { void memdump(unsigned char *string) {
printf("ADDR 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n"); printf("ADDR 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n");
int lineLength = 16; int columns = 16;
char array[lineLength * 4]; int rows = 4;
char array[columns * rows];
for(int i = 0; i <= 3; i++) { for(int i = 0; i < rows; i++) {
//FIXME: address seems wrong
printf("0x%02x ", string[i]); printf("0x%02x ", string[i]);
for (int j = i * lineLength; j < (i + 1) * lineLength; j++) { for (int j = i * columns; j < (i + 1) * columns; j++) {
printf("%02x ", string[j]); printf("%02x ", string[j]);
if(string[j] < 0x20 || string[j] > 0x7e) array[j] = '.'; if(string[j] < 0x20 || string[j] > 0x7e) array[j] = '.';
else array[j] = string[j]; else array[j] = string[j];
} }
printf(" "); printf(" ");
for (int j = i * lineLength; j < (i + 1) * lineLength; j++) { for (int j = i * columns; j < (i + 1) * columns; j++) {
printf("%c", array[j]); printf("%c", array[j]);
} }
@ -51,20 +51,25 @@ int main(int argc, char **argv) {
if(buffer == NULL) return -1; if(buffer == NULL) return -1;
memdump((unsigned char *) argv[1]);
memdump(buffer); printf("Laenge der Zeichenkette (inkl \\0): %i Bytes\n", (int) strlen(argv[1]));
printf("Ersetzen: '%c' mit '%c'\n", *argv[2], *argv[3]);
unsigned char *copy = malloc(4 * 16 * sizeof(char));
strcpy((char *) copy, argv[1]);
char **lastAddress = NULL; char **lastAddress = NULL;
int count = memreplace(argv[1], *argv[2], *argv[3], lastAddress); int count = memreplace(argv[1], *argv[2], *argv[3], lastAddress);
printf("Laenge der Zeichenkette (inkl \\0): %i Bytes\n", (int) strlen(argv[1]));
printf("Ersetzen: '%c' mit '%c'\n", *argv[2], *argv[3]);
printf("Suchzeichen wurde %i mal gefunden und ersetzt\n", count); printf("Suchzeichen wurde %i mal gefunden und ersetzt\n", count);
printf("zuletzt an Addresse 0x%lx \n", (unsigned long) (&lastAddress)); printf("zuletzt an Addresse 0x%lx \n", (unsigned long) (&lastAddress));
memdump((unsigned char*)argv[1]); memdump(copy);
free(buffer); free(copy);
return 0; return 0;
} }