-
Notifications
You must be signed in to change notification settings - Fork 1
/
ewf_gen.go
532 lines (429 loc) · 16 KB
/
ewf_gen.go
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
package parser
// Autogenerated code from ewf_profile.json. Do not edit.
import (
"encoding/binary"
"fmt"
"bytes"
"io"
"sort"
"strings"
"unicode/utf16"
"unicode/utf8"
)
var (
// Depending on autogenerated code we may use this. Add a reference
// to shut the compiler up.
_ = bytes.MinRead
_ = fmt.Sprintf
_ = utf16.Decode
_ = binary.LittleEndian
_ = utf8.RuneError
_ = sort.Strings
_ = strings.Join
_ = io.Copy
)
func indent(text string) string {
result := []string{}
lines := strings.Split(text,"\n")
for _, line := range lines {
result = append(result, " " + line)
}
return strings.Join(result, "\n")
}
type EWFProfile struct {
Off_EWF_file_header_v1_EVF_sig int64
Off_EWF_file_header_v1_Fields_start int64
Off_EWF_file_header_v1_Segment_number int64
Off_EWF_file_header_v1_Fields_end int64
Off_EWF_file_header_v1_Descriptor int64
Off_EWF_file_header_v2_EVF_sig int64
Off_EWF_file_header_v2_Major_version int64
Off_EWF_file_header_v2_Minor_version int64
Off_EWF_file_header_v2_Compression_method int64
Off_EWF_file_header_v2_Segment_number int64
Off_EWF_file_header_v2_Set_identifier int64
Off_EWF_section_descriptor_v1_Type int64
Off_EWF_section_descriptor_v1_Next int64
Off_EWF_section_descriptor_v1_SectionSize int64
Off_EWF_section_descriptor_v1_Checksum int64
Off_EWF_table_entry_Compressed int64
Off_EWF_table_entry_ChunkOffset int64
Off_EWF_table_header_v1_Number_of_entries int64
Off_EWF_table_header_v1_Base_offset int64
Off_EWF_table_header_v1_Checksum int64
Off_EWF_table_header_v1_Entries int64
Off_EWF_volume_Media_type int64
Off_EWF_volume_Number_of_chunks int64
Off_EWF_volume_Sectors_per_chunk int64
Off_EWF_volume_Bytes_per_sector int64
Off_EWF_volume_Number_of_sectors int64
Off_EWF_volume_Chs_cylinders int64
Off_EWF_volume_Chs_heads int64
Off_EWF_volume_Chs_sectors int64
Off_EWF_volume_Media_flags int64
Off_EWF_volume_Compression_level int64
Off_EWF_volume_Checksum int64
}
func NewEWFProfile() *EWFProfile {
// Specific offsets can be tweaked to cater for slight version mismatches.
self := &EWFProfile{0,8,9,11,13,0,9,10,11,13,15,0,16,24,72,0,0,0,8,20,24,0,4,8,12,16,24,28,32,36,52,90}
return self
}
func (self *EWFProfile) EWF_file_header_v1(reader io.ReaderAt, offset int64) *EWF_file_header_v1 {
return &EWF_file_header_v1{Reader: reader, Offset: offset, Profile: self}
}
func (self *EWFProfile) EWF_file_header_v2(reader io.ReaderAt, offset int64) *EWF_file_header_v2 {
return &EWF_file_header_v2{Reader: reader, Offset: offset, Profile: self}
}
func (self *EWFProfile) EWF_section_descriptor_v1(reader io.ReaderAt, offset int64) *EWF_section_descriptor_v1 {
return &EWF_section_descriptor_v1{Reader: reader, Offset: offset, Profile: self}
}
func (self *EWFProfile) EWF_table_entry(reader io.ReaderAt, offset int64) *EWF_table_entry {
return &EWF_table_entry{Reader: reader, Offset: offset, Profile: self}
}
func (self *EWFProfile) EWF_table_header_v1(reader io.ReaderAt, offset int64) *EWF_table_header_v1 {
return &EWF_table_header_v1{Reader: reader, Offset: offset, Profile: self}
}
func (self *EWFProfile) EWF_volume(reader io.ReaderAt, offset int64) *EWF_volume {
return &EWF_volume{Reader: reader, Offset: offset, Profile: self}
}
type EWF_file_header_v1 struct {
Reader io.ReaderAt
Offset int64
Profile *EWFProfile
}
func (self *EWF_file_header_v1) Size() int {
return 13
}
func (self *EWF_file_header_v1) EVF_sig() string {
return ParseString(self.Reader, self.Profile.Off_EWF_file_header_v1_EVF_sig + self.Offset, 8)
}
func (self *EWF_file_header_v1) Fields_start() int8 {
return ParseInt8(self.Reader, self.Profile.Off_EWF_file_header_v1_Fields_start + self.Offset)
}
func (self *EWF_file_header_v1) Segment_number() uint16 {
return ParseUint16(self.Reader, self.Profile.Off_EWF_file_header_v1_Segment_number + self.Offset)
}
func (self *EWF_file_header_v1) Fields_end() uint16 {
return ParseUint16(self.Reader, self.Profile.Off_EWF_file_header_v1_Fields_end + self.Offset)
}
func (self *EWF_file_header_v1) Descriptor() *EWF_section_descriptor_v1 {
return self.Profile.EWF_section_descriptor_v1(self.Reader, self.Profile.Off_EWF_file_header_v1_Descriptor + self.Offset)
}
func (self *EWF_file_header_v1) DebugString() string {
result := fmt.Sprintf("struct EWF_file_header_v1 @ %#x:\n", self.Offset)
result += fmt.Sprintf(" EVF_sig: %v\n", string(self.EVF_sig()))
result += fmt.Sprintf(" Fields_start: %#0x\n", self.Fields_start())
result += fmt.Sprintf(" Segment_number: %#0x\n", self.Segment_number())
result += fmt.Sprintf(" Fields_end: %#0x\n", self.Fields_end())
result += fmt.Sprintf(" Descriptor: {\n%v}\n", indent(self.Descriptor().DebugString()))
return result
}
type EWF_file_header_v2 struct {
Reader io.ReaderAt
Offset int64
Profile *EWFProfile
}
func (self *EWF_file_header_v2) Size() int {
return 0
}
func (self *EWF_file_header_v2) EVF_sig() string {
return ParseString(self.Reader, self.Profile.Off_EWF_file_header_v2_EVF_sig + self.Offset, 8)
}
func (self *EWF_file_header_v2) Major_version() int8 {
return ParseInt8(self.Reader, self.Profile.Off_EWF_file_header_v2_Major_version + self.Offset)
}
func (self *EWF_file_header_v2) Minor_version() int8 {
return ParseInt8(self.Reader, self.Profile.Off_EWF_file_header_v2_Minor_version + self.Offset)
}
func (self *EWF_file_header_v2) Compression_method() *Enumeration {
value := ParseUint16(self.Reader, self.Profile.Off_EWF_file_header_v2_Compression_method + self.Offset)
name := "Unknown"
switch value {
case 0:
name = "NONE"
case 1:
name = "DEFLATE"
case 2:
name = "BZIP2"
}
return &Enumeration{Value: uint64(value), Name: name}
}
func (self *EWF_file_header_v2) Segment_number() uint16 {
return ParseUint16(self.Reader, self.Profile.Off_EWF_file_header_v2_Segment_number + self.Offset)
}
func (self *EWF_file_header_v2) Set_identifier() string {
return ParseString(self.Reader, self.Profile.Off_EWF_file_header_v2_Set_identifier + self.Offset, 16)
}
func (self *EWF_file_header_v2) DebugString() string {
result := fmt.Sprintf("struct EWF_file_header_v2 @ %#x:\n", self.Offset)
result += fmt.Sprintf(" EVF_sig: %v\n", string(self.EVF_sig()))
result += fmt.Sprintf(" Major_version: %#0x\n", self.Major_version())
result += fmt.Sprintf(" Minor_version: %#0x\n", self.Minor_version())
result += fmt.Sprintf(" Compression_method: %v\n", self.Compression_method().DebugString())
result += fmt.Sprintf(" Segment_number: %#0x\n", self.Segment_number())
result += fmt.Sprintf(" Set_identifier: %v\n", string(self.Set_identifier()))
return result
}
type EWF_section_descriptor_v1 struct {
Reader io.ReaderAt
Offset int64
Profile *EWFProfile
}
func (self *EWF_section_descriptor_v1) Size() int {
return 76
}
func (self *EWF_section_descriptor_v1) Type() string {
return ParseString(self.Reader, self.Profile.Off_EWF_section_descriptor_v1_Type + self.Offset, 16)
}
func (self *EWF_section_descriptor_v1) Next() *EWF_section_descriptor_v1 {
deref := ParseUint64(self.Reader, self.Profile.Off_EWF_section_descriptor_v1_Next + self.Offset)
return self.Profile.EWF_section_descriptor_v1(self.Reader, int64(deref))
}
func (self *EWF_section_descriptor_v1) SectionSize() uint64 {
return ParseUint64(self.Reader, self.Profile.Off_EWF_section_descriptor_v1_SectionSize + self.Offset)
}
func (self *EWF_section_descriptor_v1) Checksum() uint32 {
return ParseUint32(self.Reader, self.Profile.Off_EWF_section_descriptor_v1_Checksum + self.Offset)
}
func (self *EWF_section_descriptor_v1) DebugString() string {
result := fmt.Sprintf("struct EWF_section_descriptor_v1 @ %#x:\n", self.Offset)
result += fmt.Sprintf(" Type: %v\n", string(self.Type()))
result += fmt.Sprintf(" SectionSize: %#0x\n", self.SectionSize())
result += fmt.Sprintf(" Checksum: %#0x\n", self.Checksum())
return result
}
type EWF_table_entry struct {
Reader io.ReaderAt
Offset int64
Profile *EWFProfile
}
func (self *EWF_table_entry) Size() int {
return 4
}
func (self *EWF_table_entry) Compressed() uint64 {
value := ParseUint64(self.Reader, self.Profile.Off_EWF_table_entry_Compressed + self.Offset)
return (uint64(value) & 0xffffffff) >> 0x1f
}
func (self *EWF_table_entry) ChunkOffset() uint64 {
value := ParseUint64(self.Reader, self.Profile.Off_EWF_table_entry_ChunkOffset + self.Offset)
return (uint64(value) & 0x7fffffff) >> 0x0
}
func (self *EWF_table_entry) DebugString() string {
result := fmt.Sprintf("struct EWF_table_entry @ %#x:\n", self.Offset)
result += fmt.Sprintf(" Compressed: %#0x\n", self.Compressed())
result += fmt.Sprintf(" ChunkOffset: %#0x\n", self.ChunkOffset())
return result
}
type EWF_table_header_v1 struct {
Reader io.ReaderAt
Offset int64
Profile *EWFProfile
}
func (self *EWF_table_header_v1) Size() int {
return 0
}
func (self *EWF_table_header_v1) Number_of_entries() uint64 {
return ParseUint64(self.Reader, self.Profile.Off_EWF_table_header_v1_Number_of_entries + self.Offset)
}
func (self *EWF_table_header_v1) Base_offset() uint64 {
return ParseUint64(self.Reader, self.Profile.Off_EWF_table_header_v1_Base_offset + self.Offset)
}
func (self *EWF_table_header_v1) Checksum() uint32 {
return ParseUint32(self.Reader, self.Profile.Off_EWF_table_header_v1_Checksum + self.Offset)
}
func (self *EWF_table_header_v1) Entries() *EWF_table_entry {
return self.Profile.EWF_table_entry(self.Reader, self.Profile.Off_EWF_table_header_v1_Entries + self.Offset)
}
func (self *EWF_table_header_v1) DebugString() string {
result := fmt.Sprintf("struct EWF_table_header_v1 @ %#x:\n", self.Offset)
result += fmt.Sprintf(" Number_of_entries: %#0x\n", self.Number_of_entries())
result += fmt.Sprintf(" Base_offset: %#0x\n", self.Base_offset())
result += fmt.Sprintf(" Checksum: %#0x\n", self.Checksum())
result += fmt.Sprintf(" Entries: {\n%v}\n", indent(self.Entries().DebugString()))
return result
}
type EWF_volume struct {
Reader io.ReaderAt
Offset int64
Profile *EWFProfile
}
func (self *EWF_volume) Size() int {
return 94
}
func (self *EWF_volume) Media_type() *Enumeration {
value := ParseUint64(self.Reader, self.Profile.Off_EWF_volume_Media_type + self.Offset)
name := "Unknown"
switch value {
case 0:
name = "remobable_disk"
case 1:
name = "fixed_disk"
case 2:
name = "optical_disk"
case 3:
name = "LVF"
case 4:
name = "memory"
}
return &Enumeration{Value: uint64(value), Name: name}
}
func (self *EWF_volume) Number_of_chunks() uint32 {
return ParseUint32(self.Reader, self.Profile.Off_EWF_volume_Number_of_chunks + self.Offset)
}
func (self *EWF_volume) Sectors_per_chunk() uint32 {
return ParseUint32(self.Reader, self.Profile.Off_EWF_volume_Sectors_per_chunk + self.Offset)
}
func (self *EWF_volume) Bytes_per_sector() uint32 {
return ParseUint32(self.Reader, self.Profile.Off_EWF_volume_Bytes_per_sector + self.Offset)
}
func (self *EWF_volume) Number_of_sectors() uint64 {
return ParseUint64(self.Reader, self.Profile.Off_EWF_volume_Number_of_sectors + self.Offset)
}
func (self *EWF_volume) Chs_cylinders() uint32 {
return ParseUint32(self.Reader, self.Profile.Off_EWF_volume_Chs_cylinders + self.Offset)
}
func (self *EWF_volume) Chs_heads() uint32 {
return ParseUint32(self.Reader, self.Profile.Off_EWF_volume_Chs_heads + self.Offset)
}
func (self *EWF_volume) Chs_sectors() uint32 {
return ParseUint32(self.Reader, self.Profile.Off_EWF_volume_Chs_sectors + self.Offset)
}
func (self *EWF_volume) Media_flags() *Flags {
value := ParseUint64(self.Reader, self.Profile.Off_EWF_volume_Media_flags + self.Offset)
names := make(map[string]bool)
if value & 1 != 0 {
names["image"] = true
}
if value & 2 != 0 {
names["physical"] = true
}
if value & 4 != 0 {
names["Fastblock Tableau write blocker"] = true
}
if value & 8 != 0 {
names["Tableau write blocker"] = true
}
return &Flags{Value: uint64(value), Names: names}
}
func (self *EWF_volume) Compression_level() *Enumeration {
value := ParseUint64(self.Reader, self.Profile.Off_EWF_volume_Compression_level + self.Offset)
name := "Unknown"
switch value {
case 0:
name = "no compression"
case 1:
name = "fast/good compression"
case 2:
name = "best compression"
}
return &Enumeration{Value: uint64(value), Name: name}
}
func (self *EWF_volume) Checksum() int32 {
return ParseInt32(self.Reader, self.Profile.Off_EWF_volume_Checksum + self.Offset)
}
func (self *EWF_volume) DebugString() string {
result := fmt.Sprintf("struct EWF_volume @ %#x:\n", self.Offset)
result += fmt.Sprintf(" Media_type: %v\n", self.Media_type().DebugString())
result += fmt.Sprintf(" Number_of_chunks: %#0x\n", self.Number_of_chunks())
result += fmt.Sprintf(" Sectors_per_chunk: %#0x\n", self.Sectors_per_chunk())
result += fmt.Sprintf(" Bytes_per_sector: %#0x\n", self.Bytes_per_sector())
result += fmt.Sprintf(" Number_of_sectors: %#0x\n", self.Number_of_sectors())
result += fmt.Sprintf(" Chs_cylinders: %#0x\n", self.Chs_cylinders())
result += fmt.Sprintf(" Chs_heads: %#0x\n", self.Chs_heads())
result += fmt.Sprintf(" Chs_sectors: %#0x\n", self.Chs_sectors())
result += fmt.Sprintf(" Media_flags: %v\n", self.Media_flags().DebugString())
result += fmt.Sprintf(" Compression_level: %v\n", self.Compression_level().DebugString())
result += fmt.Sprintf(" Checksum: %#0x\n", self.Checksum())
return result
}
type Enumeration struct {
Value uint64
Name string
}
func (self Enumeration) DebugString() string {
return fmt.Sprintf("%s (%d)", self.Name, self.Value)
}
type Flags struct {
Value uint64
Names map[string]bool
}
func (self Flags) DebugString() string {
names := []string{}
for k, _ := range self.Names {
names = append(names, k)
}
sort.Strings(names)
return fmt.Sprintf("%d (%s)", self.Value, strings.Join(names, ","))
}
func (self Flags) IsSet(flag string) bool {
result, _ := self.Names[flag]
return result
}
func (self Flags) Values() []string {
result := make([]string, 0, len(self.Names))
for k, _ := range self.Names {
result = append(result, k)
}
return result
}
func ParseInt32(reader io.ReaderAt, offset int64) int32 {
data := make([]byte, 4)
_, err := reader.ReadAt(data, offset)
if err != nil {
return 0
}
return int32(binary.LittleEndian.Uint32(data))
}
func ParseInt8(reader io.ReaderAt, offset int64) int8 {
result := make([]byte, 1)
_, err := reader.ReadAt(result, offset)
if err != nil {
return 0
}
return int8(result[0])
}
func ParseUint16(reader io.ReaderAt, offset int64) uint16 {
data := make([]byte, 2)
_, err := reader.ReadAt(data, offset)
if err != nil {
return 0
}
return binary.LittleEndian.Uint16(data)
}
func ParseUint32(reader io.ReaderAt, offset int64) uint32 {
data := make([]byte, 4)
_, err := reader.ReadAt(data, offset)
if err != nil {
return 0
}
return binary.LittleEndian.Uint32(data)
}
func ParseUint64(reader io.ReaderAt, offset int64) uint64 {
data := make([]byte, 8)
_, err := reader.ReadAt(data, offset)
if err != nil {
return 0
}
return binary.LittleEndian.Uint64(data)
}
func ParseTerminatedString(reader io.ReaderAt, offset int64) string {
data := make([]byte, 1024)
n, err := reader.ReadAt(data, offset)
if err != nil && err != io.EOF {
return ""
}
idx := bytes.Index(data[:n], []byte{0})
if idx < 0 {
idx = n
}
return string(data[0:idx])
}
func ParseString(reader io.ReaderAt, offset int64, length int64) string {
data := make([]byte, length)
n, err := reader.ReadAt(data, offset)
if err != nil && err != io.EOF {
return ""
}
return string(data[:n])
}