-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathinspect.cc
231 lines (190 loc) · 5.85 KB
/
inspect.cc
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#include <fcntl.h>
#include <unistd.h>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <string>
/// Big-endian 16-bit unsigned integer
class RUInt16BE {
private:
std::uint16_t fValBE = 0;
static std::uint16_t Swap(std::uint16_t val) {
return (val & 0x00FF) << 8 | (val & 0xFF00) >> 8;
}
public:
RUInt16BE() = default;
explicit RUInt16BE(const std::uint16_t val) : fValBE(Swap(val)) {}
operator std::uint16_t() const {
return Swap(fValBE);
}
RUInt16BE& operator =(const std::uint16_t val) {
fValBE = Swap(val);
return *this;
}
};
/// Big-endian 32-bit unsigned integer
class RUInt32BE {
private:
std::uint32_t fValBE = 0;
static std::uint32_t Swap(std::uint32_t val) {
auto x = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16;
return (x & 0x00FF00FF) << 8 | (x & 0xFF00FF00) >> 8;
}
public:
RUInt32BE() = default;
explicit RUInt32BE(const std::uint32_t val) : fValBE(Swap(val)) {}
operator std::uint32_t() const {
return Swap(fValBE);
}
RUInt32BE& operator =(const std::uint32_t val) {
fValBE = Swap(val);
return *this;
}
};
/// Big-endian 32-bit signed integer
class RInt32BE {
private:
std::int32_t fValBE = 0;
static std::int32_t Swap(std::int32_t val) {
auto x = (val & 0x0000FFFF) << 16 | (val & 0xFFFF0000) >> 16;
return (x & 0x00FF00FF) << 8 | (x & 0xFF00FF00) >> 8;
}
public:
RInt32BE() = default;
explicit RInt32BE(const std::int32_t val) : fValBE(Swap(val)) {}
operator std::int32_t() const {
return Swap(fValBE);
}
RInt32BE& operator =(const std::int32_t val) {
fValBE = Swap(val);
return *this;
}
};
/// Big-endian 64-bit unsigned integer
class RUInt64BE {
private:
std::uint64_t fValBE = 0;
static std::uint64_t Swap(std::uint64_t val) {
auto x = (val & 0x00000000FFFFFFFF) << 32 | (val & 0xFFFFFFFF00000000) >> 32;
x = (x & 0x0000FFFF0000FFFF) << 16 | (x & 0xFFFF0000FFFF0000) >> 16;
return (x & 0x00FF00FF00FF00FF) << 8 | (x & 0xFF00FF00FF00FF00) >> 8;
}
public:
RUInt64BE() = default;
explicit RUInt64BE(const std::uint64_t val) : fValBE(Swap(val)) {}
operator std::uint64_t() const {
return Swap(fValBE);
}
RUInt64BE& operator =(const std::uint64_t val) {
fValBE = Swap(val);
return *this;
}
};
void Usage(char *progname) {
printf("Usage: %s <ROOT file> [-b(ig file)]\n", progname);
}
int main(int argc, char **argv) {
if (argc < 2) {
Usage(argv[0]);
return 1;
}
bool bigFile = false;
if ((argc >= 3) && (std::string(argv[2]) == "-b")) {
bigFile = true;
}
std::string path = argv[1];
int fd = open(path.c_str(), O_RDONLY);
if (fd < 0) {
fprintf(stderr, "Cannot open %s\n", path.c_str());
return 1;
}
lseek(fd, 100, SEEK_SET);
RUInt32BE nbytes;
read(fd, &nbytes, sizeof(nbytes));
printf("NBytes: %u\n", (std::uint32_t)nbytes);
RUInt16BE version;
read(fd, &version, sizeof(version));
printf("Version: %u\n", (std::uint16_t)version);
RUInt32BE objlen;
read(fd, &objlen, sizeof(objlen));
printf("ObjLen: %u\n", (std::uint32_t)objlen);
RUInt32BE datetime;
read(fd, &datetime, sizeof(datetime));
RUInt16BE keylen;
read(fd, &keylen, sizeof(keylen));
printf("KeyLen: %u\n", (std::uint16_t)keylen);
RUInt16BE cycle;
read(fd, &cycle, sizeof(cycle));
printf("Cycle: %u\n", (std::uint16_t)cycle);
RUInt32BE seekkey;
read(fd, &seekkey, sizeof(seekkey));
printf("SeekKey: %u\n", (std::uint32_t)seekkey);
RUInt32BE seekpdir;
read(fd, &seekpdir, sizeof(seekpdir));
printf("SeekPDir: %u\n", (std::uint32_t)seekpdir);
char lclname;
read(fd, &lclname, sizeof(lclname));
printf("lclname: %u\n", lclname);
unsigned char buf[1000];
read(fd, buf, lclname);
char lobjname;
read(fd, &lobjname, sizeof(lobjname));
printf("lobjname: %u\n", lobjname);
read(fd, buf, lobjname);
char ltitle;
read(fd, <itle, sizeof(ltitle));
printf("ltitle: %u\n", ltitle);
read(fd, buf, ltitle);
// TFILE DATA
read(fd, &lobjname, sizeof(lobjname));
printf("lobjname(TFile): %u\n", lobjname);
read(fd, buf, lobjname);
read(fd, <itle, sizeof(ltitle));
printf("ltitle(TFile): %u\n", ltitle);
read(fd, buf, ltitle);
RUInt16BE tfileversion;
read(fd, &tfileversion, sizeof(tfileversion));
printf("TFile version: %u\n", (std::uint16_t)tfileversion);
// char modified;
// read(fd, &modified, sizeof(modified));
// printf("modified: %u\n", modified);
//
// char writable;
// read(fd, &writable, sizeof(writable));
// printf("writable: %u\n", writable);
read(fd, &datetime, sizeof(datetime));
read(fd, &datetime, sizeof(datetime));
RUInt32BE nbyteskeys;
read(fd, &nbyteskeys, sizeof(nbyteskeys));
printf("NByteKeys: %u\n", (std::uint32_t)nbyteskeys);
RUInt32BE nbytesname;
read(fd, &nbytesname, sizeof(nbytesname));
printf("NByteName: %u\n", (std::uint32_t)nbytesname);
if (bigFile) {
RUInt64BE seekdir;
read(fd, &seekdir, sizeof(seekdir));
printf("SeekDir: %lu\n", (std::uint64_t)seekdir);
RUInt64BE seekparent;
read(fd, &seekparent, sizeof(seekparent));
printf("SeekParent: %lu\n", (std::uint64_t)seekparent);
RUInt64BE seekkeys;
read(fd, &seekkeys, sizeof(seekkeys));
printf("SeekKeys: %lu\n", (std::uint64_t)seekkeys);
} else {
RUInt32BE seekdir;
read(fd, &seekdir, sizeof(seekdir));
printf("SeekDir: %u\n", (std::uint32_t)seekdir);
RUInt32BE seekparent;
read(fd, &seekparent, sizeof(seekparent));
printf("SeekParent: %u\n", (std::uint32_t)seekparent);
RUInt32BE seekkeys;
read(fd, &seekkeys, sizeof(seekkeys));
printf("SeekKeys: %u\n", (std::uint32_t)seekkeys);
}
RUInt16BE uuidversion;
read(fd, &uuidversion, sizeof(uuidversion));
printf("UUID version: %u\n", (std::uint16_t)uuidversion);
off_t pos = lseek(fd, 0, SEEK_CUR);
printf("Object size: %lu\n", pos + 16 - 100);
return 0;
}