Skip to content

Commit

Permalink
decode: Make compound range sort optional
Browse files Browse the repository at this point in the history
Some formats might want to control child order
mp4: Keep tracks in track id order
dns: Keep label component order
elf: Keep seciton order
macho: Keep command and section order
  • Loading branch information
wader committed May 3, 2022
1 parent 81a58c7 commit c4dd518
Show file tree
Hide file tree
Showing 37 changed files with 2,445 additions and 2,415 deletions.
4 changes: 4 additions & 0 deletions format/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ func fieldDecodeLabel(d *decode.D, pointerOffset int64, name string) {
d.FieldStruct(name, func(d *decode.D) {
var ls []string
d.FieldArray("labels", func(d *decode.D) {
d.RangeSorted = false

seenTermintor := false
for !seenTermintor {
d.FieldStruct("label", func(d *decode.D) {
Expand Down Expand Up @@ -176,6 +178,8 @@ func fieldDecodeLabel(d *decode.D, pointerOffset int64, name string) {

func dnsDecodeRR(d *decode.D, pointerOffset int64, resp bool, count uint64, name string, structName string) {
d.FieldArray(name, func(d *decode.D) {
d.RangeSorted = false

for i := uint64(0); i < count; i++ {
d.FieldStruct(structName, func(d *decode.D) {
fieldDecodeLabel(d, pointerOffset, "name")
Expand Down
32 changes: 16 additions & 16 deletions format/dns/testdata/cern-rsp.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ $ fq -d dns dv /cern-rsp
| | | value: "www.cern.ch" 0x19-NA (0)
| | | cname{}: 0x10-0x33.7 (36)
| | | labels[0:4]: 0x10-0x33.7 (36)
| | | [0]{}: label 0x10-0x33.7 (36)
| | | [0]{}: label 0x29-0x31.7 (9)
0x20| 08 | . | length: 8 0x29-0x29.7 (1)
0x20| 77 65 62 72 6c 62| webrlb| value: "webrlb02" 0x2a-0x31.7 (8)
0x30|30 32 |02 |
| | | [1]{}: label 0x10-0x33.7 (36)
0x10|04 |. | length: 4 0x10-0x10.7 (1)
0x10| 63 65 72 6e | cern | value: "cern" 0x11-0x14.7 (4)
0x30| c0 | . | is_pointer: 3 0x32-0x32.1 (0.2)
0x30| c0 10 | .. | pointer: 16 0x32.2-0x33.7 (1.6)
| | | [1]{}: label 0x15-0x17.7 (3)
| | | [2]{}: label 0x15-0x17.7 (3)
0x10| 02 | . | length: 2 0x15-0x15.7 (1)
0x10| 63 68 | ch | value: "ch" 0x16-0x17.7 (2)
| | | [2]{}: label 0x18-0x18.7 (1)
| | | [3]{}: label 0x18-0x18.7 (1)
0x10| 00 | . | length: 0 0x18-0x18.7 (1)
| | | [3]{}: label 0x29-0x31.7 (9)
0x20| 08 | . | length: 8 0x29-0x29.7 (1)
0x20| 77 65 62 72 6c 62| webrlb| value: "webrlb02" 0x2a-0x31.7 (8)
0x30|30 32 |02 |
| | | value: "webrlb02.cern.ch" 0x19-NA (0)
0x10| 00| .| type: "cname" (5) 0x1f-0x20.7 (2)
0x20|05 |. |
Expand All @@ -75,22 +75,22 @@ $ fq -d dns dv /cern-rsp
| | | [1]{}: answer 0x10-0x4f.7 (64)
| | | name{}: 0x10-0x35.7 (38)
| | | labels[0:4]: 0x10-0x35.7 (38)
| | | [0]{}: label 0x10-0x33.7 (36)
| | | [0]{}: label 0x29-0x35.7 (13)
0x20| 08 | . | length: 8 0x29-0x29.7 (1)
0x20| 77 65 62 72 6c 62| webrlb| value: "webrlb02" 0x2a-0x31.7 (8)
0x30|30 32 |02 |
0x30| c0 | . | is_pointer: 3 0x34-0x34.1 (0.2)
0x30| c0 29 | .) | pointer: 41 0x34.2-0x35.7 (1.6)
| | | [1]{}: label 0x10-0x33.7 (36)
0x10|04 |. | length: 4 0x10-0x10.7 (1)
0x10| 63 65 72 6e | cern | value: "cern" 0x11-0x14.7 (4)
0x30| c0 | . | is_pointer: 3 0x32-0x32.1 (0.2)
0x30| c0 10 | .. | pointer: 16 0x32.2-0x33.7 (1.6)
| | | [1]{}: label 0x15-0x17.7 (3)
| | | [2]{}: label 0x15-0x17.7 (3)
0x10| 02 | . | length: 2 0x15-0x15.7 (1)
0x10| 63 68 | ch | value: "ch" 0x16-0x17.7 (2)
| | | [2]{}: label 0x18-0x18.7 (1)
| | | [3]{}: label 0x18-0x18.7 (1)
0x10| 00 | . | length: 0 0x18-0x18.7 (1)
| | | [3]{}: label 0x29-0x35.7 (13)
0x20| 08 | . | length: 8 0x29-0x29.7 (1)
0x20| 77 65 62 72 6c 62| webrlb| value: "webrlb02" 0x2a-0x31.7 (8)
0x30|30 32 |02 |
0x30| c0 | . | is_pointer: 3 0x34-0x34.1 (0.2)
0x30| c0 29 | .) | pointer: 41 0x34.2-0x35.7 (1.6)
| | | value: "webrlb02.cern.ch" 0x19-NA (0)
0x30| 00 1c | .. | type: "aaaa" (28) 0x36-0x37.7 (2)
0x30| 00 01 | .. | class: "in" (1) (Internet) 0x38-0x39.7 (2)
Expand Down
10 changes: 8 additions & 2 deletions format/elf/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,14 @@ func elfDecode(d *decode.D, in interface{}) interface{} {
d.Endian = ec.endian
// a first pass to find all sections and string table information etc
elfReadSectionHeaders(d, &ec)
d.FieldArray("program_headers", func(d *decode.D) { elfDecodeProgramHeaders(d, ec) })
d.FieldArray("section_headers", func(d *decode.D) { elfDecodeSectionHeaders(d, ec) })
d.FieldArray("program_headers", func(d *decode.D) {
d.RangeSorted = false
elfDecodeProgramHeaders(d, ec)
})
d.FieldArray("section_headers", func(d *decode.D) {
d.RangeSorted = false
elfDecodeSectionHeaders(d, ec)
})

return nil
}
Loading

0 comments on commit c4dd518

Please sign in to comment.