a3: memdump fast funktionstüchtig

This commit is contained in:
Johannes Theiner 2018-11-02 22:03:51 +01:00
parent 663521c5f5
commit 27127d5d4c
1 changed files with 33 additions and 23 deletions

View File

@ -5,35 +5,38 @@
#include <memory.h> #include <memory.h>
void memdump(unsigned char *string) { void memdump(unsigned char *string) {
int i;
unsigned char buffer[64];
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");
for(i = 0; i <= 64; i++) {
string++; int lineLength = 16;
if((i % 16) == 0) { char array[lineLength * 4];
if(i != 0) printf(" %s\n", string);
printf("0x%04x ", *string);
buffer[i] = string[i]; for(int i = 0; i <= 3; i++) {
//FIXME: address seems wrong
printf("0x%02x ", string[i]);
for (int j = i * lineLength; j < (i + 1) * lineLength; j++) {
printf("%02x ", string[j]);
if(string[j] < 0x20 || string[j] > 0x7e) array[j] = '.';
else array[j] = string[j];
} }
printf(" %02x", string[i]); printf(" ");
/*if ((string[i] < 0x20) || (string[i] > 0x7e))
buffer[i] = '.';
else
buffer[i] = string[i];*/
buffer[(i % 16) + 1] = '\0'; for (int j = i * lineLength; j < (i + 1) * lineLength; j++) {
printf("%c", array[j]);
}
printf("\n");
} }
while ((i % 16) != 0) {
printf(" ");
i++;
}
} }
int memreplace(char *string, char cin, char cout, char **caddr) { int memreplace(char *string, char cin, char cout, char **caddr) {
//memctl
return 42; return 42;
} }
@ -43,10 +46,17 @@ int main(int argc, char **argv) {
return -1; return -1;
} }
size_t size = 4 * 16;
unsigned char *buffer = malloc(size);
if(buffer == NULL) return -1;
memdump((unsigned char*)*argv);
char **lastAddress;
int count = memreplace(argv[1], *argv[2], *argv[3], 0);
memdump(buffer);
char **lastAddress = NULL;
int count = memreplace(argv[1], *argv[2], *argv[3], lastAddress);
printf("Laenge der Zeichenkette (inkl \\0): %i Bytes\n", (int) strlen(argv[1])); printf("Laenge der Zeichenkette (inkl \\0): %i Bytes\n", (int) strlen(argv[1]));
printf("Ersetzen: '%c' mit '%c'\n", *argv[2], *argv[3]); printf("Ersetzen: '%c' mit '%c'\n", *argv[2], *argv[3]);
@ -54,7 +64,7 @@ int main(int argc, char **argv) {
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((unsigned char*)argv[1]);
free(argv); free(buffer);
return 0; return 0;
} }