a3: weiterer Fortschritt
This commit is contained in:
parent
ffe9cb19b9
commit
ed1dde77f3
61
src/c/a3.c
61
src/c/a3.c
|
@ -1,39 +1,32 @@
|
||||||
#include "a3.h"
|
#include "a3.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <mem.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <memory.h>
|
||||||
|
|
||||||
void memdump(unsigned char *string) {
|
void memdump(unsigned char *string) {
|
||||||
int i;
|
int i;
|
||||||
unsigned char *pc = string;
|
unsigned char buffer[16];
|
||||||
int length = strlen((const char *) string);
|
|
||||||
unsigned char buff[length];
|
|
||||||
|
|
||||||
for (i = 0; i < length; i++) {
|
printf("ADDR 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 0123456789ABCDEF\n");
|
||||||
|
for(i = 0; i <= 32; i++) {
|
||||||
if ((i % 16) == 0) {
|
if((i % 16) == 0) {
|
||||||
if (i != 0)
|
if(i != 0) printf(" %s\n", string++);
|
||||||
printf(" %s\n", buff);
|
printf("0x%04x ", *string);
|
||||||
printf(" 0x%04x ", i);
|
|
||||||
}
|
}
|
||||||
|
printf(" %02x", string[i]);
|
||||||
printf(" %02x", pc[i]);
|
if ((string[i] < 0x20) || (string[i] > 0x7e)) {
|
||||||
|
buffer[i % 16] = '.';
|
||||||
if ((pc[i] < 0x20) || (pc[i] > 0x7e)) {
|
|
||||||
buff[i % 16] = '.';
|
|
||||||
} else {
|
} else {
|
||||||
buff[i % 16] = pc[i];
|
buffer[i % 16] = string[i];
|
||||||
}
|
}
|
||||||
|
buffer[(i % 16) + 1] = '\0';
|
||||||
buff[(i % 16) + 1] = '\0';
|
|
||||||
}
|
}
|
||||||
while ((i % 16) != 0) {
|
while ((i % 16) != 0) {
|
||||||
printf(" ");
|
printf(" ");
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
printf(" %s\n", buffer);
|
||||||
printf(" %s\n", buff);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,38 +40,16 @@ int main(int argc, char **argv) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t size = 1;
|
|
||||||
for (int i = 1; i < argc; i++) {
|
|
||||||
size += strlen(argv[i]) + 1;
|
|
||||||
}
|
|
||||||
char *str = malloc(size);
|
|
||||||
if (!str) {
|
|
||||||
fprintf(stderr, "No memory\n");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
size = 0;
|
memdump((unsigned char*)argv);
|
||||||
for (int i = 1; i < argc; i++) {
|
|
||||||
|
|
||||||
size += sprintf(str + size, "%s ", argv[i]);
|
|
||||||
|
|
||||||
assert(str[size] == '\0');
|
|
||||||
}
|
|
||||||
|
|
||||||
str[--size] = '\0';
|
|
||||||
|
|
||||||
printf("%s\n", str);
|
|
||||||
|
|
||||||
|
|
||||||
memdump((unsigned char*)str);
|
|
||||||
char **lastAddress;
|
char **lastAddress;
|
||||||
int count = memreplace(argv[1], *argv[2], *argv[3], 0);
|
int count = memreplace(argv[1], *argv[2], *argv[3], 0);
|
||||||
|
|
||||||
printf("Laenge der Zeichenkette (inkl \\0): %i Bytes\n", 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]);
|
||||||
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((unsigned char*)argv[1]);
|
||||||
|
|
||||||
free(str);
|
free(argv);
|
||||||
}
|
}
|
Loading…
Reference in New Issue