a3: memdump fast funktionstüchtig

This commit is contained in:
Johannes Theiner 2018-11-02 22:03:51 +01:00
parent 663521c5f5
commit 27127d5d4c

View File

@ -5,35 +5,38 @@
#include <memory.h>
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");
for(i = 0; i <= 64; i++) {
string++;
if((i % 16) == 0) {
if(i != 0) printf(" %s\n", string);
printf("0x%04x ", *string);
buffer[i] = string[i];
int lineLength = 16;
char array[lineLength * 4];
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]);
/*if ((string[i] < 0x20) || (string[i] > 0x7e))
buffer[i] = '.';
else
buffer[i] = string[i];*/
printf(" ");
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) {
//memctl
return 42;
}
@ -43,10 +46,17 @@ int main(int argc, char **argv) {
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("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));
memdump((unsigned char*)argv[1]);
free(argv);
free(buffer);
return 0;
}