a3: memdump funktioniert
This commit is contained in:
parent
27127d5d4c
commit
ebd099bef6
27
src/c/a3.c
27
src/c/a3.c
@ -7,21 +7,21 @@
|
||||
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");
|
||||
|
||||
int lineLength = 16;
|
||||
char array[lineLength * 4];
|
||||
int columns = 16;
|
||||
int rows = 4;
|
||||
char array[columns * rows];
|
||||
|
||||
|
||||
for(int i = 0; i <= 3; i++) {
|
||||
//FIXME: address seems wrong
|
||||
for(int i = 0; i < rows; 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]);
|
||||
if(string[j] < 0x20 || string[j] > 0x7e) array[j] = '.';
|
||||
else array[j] = string[j];
|
||||
}
|
||||
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]);
|
||||
|
||||
}
|
||||
@ -51,20 +51,25 @@ int main(int argc, char **argv) {
|
||||
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;
|
||||
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("zuletzt an Addresse 0x%lx \n", (unsigned long) (&lastAddress));
|
||||
memdump((unsigned char*)argv[1]);
|
||||
memdump(copy);
|
||||
|
||||
free(buffer);
|
||||
free(copy);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user