first commit! 🎉
This commit is contained in:
commit
31cfacb2cc
4 changed files with 101 additions and 0 deletions
62
axd.c
Normal file
62
axd.c
Normal file
|
@ -0,0 +1,62 @@
|
|||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 2) {
|
||||
printf("Usage: %s <file>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
FILE *file = fopen(argv[1], "r");
|
||||
|
||||
if (file == NULL) {
|
||||
fprintf(stderr, "Failed to open file: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
fseek(file, 0, SEEK_END);
|
||||
size_t filesize = ftell(file);
|
||||
fseek(file, 0, 0);
|
||||
|
||||
char buffer[filesize + 1];
|
||||
fread(buffer, 1, filesize, file);
|
||||
buffer[filesize] = '\0';
|
||||
|
||||
static int width = 0x10;
|
||||
size_t offset = 0;
|
||||
while (offset < filesize) {
|
||||
printf("%08lx: ", offset);
|
||||
|
||||
// print hex chars
|
||||
for (int c = 0; c < 0x10; c++) {
|
||||
if (offset + c >= filesize)
|
||||
printf(" ");
|
||||
else {
|
||||
if ((buffer[offset + c] & 0xff) < 0x10)
|
||||
printf("0");
|
||||
printf("%x", buffer[offset + c] & 0xff);
|
||||
}
|
||||
|
||||
if (c % 2 != 0)
|
||||
printf(" ");
|
||||
}
|
||||
|
||||
printf(" ");
|
||||
|
||||
// print ASCII chars
|
||||
for (int o = 0; o < 0x10 && offset + o < filesize; o++) {
|
||||
char c = buffer[offset + o];
|
||||
if (c > 31)
|
||||
printf("%c", c);
|
||||
else
|
||||
printf(".");
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
offset += 0x10;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue