Skip to content

Commit

Permalink
WIP: pe: Add decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Aug 15, 2023
1 parent 0e27492 commit 9990e7e
Show file tree
Hide file tree
Showing 5 changed files with 525 additions and 0 deletions.
1 change: 1 addition & 0 deletions format/all/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
_ "github.com/wader/fq/format/ogg"
_ "github.com/wader/fq/format/opus"
_ "github.com/wader/fq/format/pcap"
_ "github.com/wader/fq/format/pe"
_ "github.com/wader/fq/format/png"
_ "github.com/wader/fq/format/postgres"
_ "github.com/wader/fq/format/prores"
Expand Down
3 changes: 3 additions & 0 deletions format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ var (
Opus_Packet = &decode.Group{Name: "opus_packet"}
PCAP = &decode.Group{Name: "pcap"}
PCAPNG = &decode.Group{Name: "pcapng"}
PE = &decode.Group{Name: "pe"}
PE_COFF = &decode.Group{Name: "pe_coff"}
PE_MSDOS_Stub = &decode.Group{Name: "pe_msdos_stub"}
Pg_BTree = &decode.Group{Name: "pg_btree"}
Pg_Control = &decode.Group{Name: "pg_control"}
Pg_Heap = &decode.Group{Name: "pg_heap"}
Expand Down
37 changes: 37 additions & 0 deletions format/pe/pe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package pe

// https://osandamalith.com/2020/07/19/exploring-the-ms-dos-stub/

import (
"github.com/wader/fq/format"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
)

// TODO: probe?
// TODO: not pe_ prefix for format names?

var peMSDosStubGroup decode.Group
var peCOFFGroup decode.Group

func init() {
interp.RegisterFormat(
format.PE,
&decode.Format{
Description: "Portable Executable",
Groups: []*decode.Group{format.Probe},
Dependencies: []decode.Dependency{
{Groups: []*decode.Group{format.PE_MSDOS_Stub}, Out: &peMSDosStubGroup},
{Groups: []*decode.Group{format.PE_COFF}, Out: &peCOFFGroup},
},
DecodeFn: peDecode,
})
}

func peDecode(d *decode.D) any {

d.FieldFormat("ms_dos_stub", &peMSDosStubGroup, nil)
d.FieldFormat("coff", &peCOFFGroup, nil)

return nil
}
Loading

0 comments on commit 9990e7e

Please sign in to comment.