forked from mdbtools/mdbtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdb-dump.c
More file actions
96 lines (87 loc) · 2.39 KB
/
mdb-dump.c
File metadata and controls
96 lines (87 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* utility program to make a hex dump of a binary file (such as a mdb file) */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <ctype.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
/** \addtogroup mdb-dump
* @{
*/
int main(int argc, char **argv)
{
unsigned long i=0;
unsigned int j;
unsigned char data[17];
FILE *in;
size_t length;
int pg=0;
char addr[10];
int jet4 = 0;
int pg_size = 2048;
if (argc < 2) {
fprintf(stderr, "Usage: mdb-dump <filename> [<page number>]\n\n");
exit(1);
}
fputs("mdb-hexdump is deprecated and will disappear in a future version of mdbtools.\n", stderr);
fputs("Please drop us a line if you have any use of it.\n", stderr);
fputs("See https://github.com/mdbtools/mdbtools/issues/197\n", stderr);
fputs("\n", stderr);
if (argc>2) {
if (!strncmp(argv[2],"0x",2)) {
for (i=2;i<strlen(argv[2]);i++) {
pg *= 16;
//if (islower(argv[2][i]))
//argv[2][i] += 0x20;
printf("char %c\n", (int)argv[2][i]);
pg += argv[2][i] > '9' ? argv[2][i] - 'a' + 10 : argv[2][i] - '0';
}
} else {
pg = atol(argv[2]);
}
}
printf("page num %d\n", pg);
if ((in = fopen(argv[1],"r"))==NULL) {
fprintf(stderr, "Couldn't open file %s\n", argv[1]);
exit(1);
}
fseek(in,0x14,SEEK_SET);
length = fread(data,1,1,in);
if (!length) {
fprintf(stderr, "fread failed at position 0x14\n");
exit(1);
}
if (data[0]) {
jet4 = 1;
pg_size = 4096;
}
fseek(in,(pg*pg_size),SEEK_SET);
i = 0;
while ((length = fread(data,1,16,in))) {
snprintf(addr, sizeof(addr), "%06lx", i);
//if (!strcmp(&addr[3],"000") || (!jet4 && !strcmp(&addr[3],"800")) &&
//pg) break;
if (!strcmp(&addr[3],"000") || (!jet4 && !strcmp(&addr[3],"800"))) {
fprintf(stdout,"-- Page 0x%04x (%d) --\n", pg, pg);
pg++;
}
fprintf(stdout,"%s ", addr);
i+=length;
for(j=0; j<length; j++) {
fprintf(stdout, "%02x ", data[j]);
}
fprintf(stdout, " |");
for(j=0; j<length; j++) {
fprintf(stdout, "%c", (isprint(data[j])) ? data[j] : '.');
}
fprintf(stdout, "|\n");
}
exit(0);
}
/** @}*/