Skip to content

Commit

Permalink
Read headers from ecoff files.
Browse files Browse the repository at this point in the history
  • Loading branch information
trhodeos committed Feb 26, 2018
1 parent c45d9f7 commit d8cdf45
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
spicy
main
49 changes: 49 additions & 0 deletions cmd/print_ecoff/main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
package main

import (
"bytes"
"encoding/binary"
"fmt"
"log"
"os"
"io/ioutil"
"github.com/trhodeos/spicy"
)

func main() {
path := os.Args[1]

file, err := os.Open(path)
if err != nil {
log.Fatal("Error while opening file", err)
}

defer file.Close()

fmt.Printf("%s opened\n", path)

b, err := ioutil.ReadAll(file)
if err != nil {
log.Fatal("Error while reading file", err)
}
buffer := bytes.NewBuffer(b)

fileheader := spicy.FileHeader{}
err = binary.Read(buffer, binary.BigEndian, &fileheader)
if err != nil {
log.Fatal("binary.Read failed", err)
}
fmt.Printf("Parsed file header:\n%+v\n", fileheader)

objheader := spicy.AoutHeader{}
err = binary.Read(buffer, binary.BigEndian, &objheader)
if err != nil {
log.Fatal("binary.Read failed", err)
}
fmt.Printf("Parsed obj header:\n%+v\n", objheader)

var i uint16
for i = 0; i < fileheader.NumSections; i++ {
secheader := spicy.SectionHeader{}
err = binary.Read(buffer, binary.BigEndian, &secheader)
if err != nil {
log.Fatal("binary.Read failed", err)
}
fmt.Printf("Parsed sec header %d:\n%+v\n", i, secheader)
}
}
42 changes: 29 additions & 13 deletions ecoff.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,55 @@
package spicy

import (
"fmt"
)

type FileHeader struct {
Magic uint16
NumberSections uint16
NumSections uint16
TimeDate int32
SymbolsPointer int32
NumberSymbols int32
SymbolsPointer uint32
NumSymbols int32
OptionalHeader uint16
Flags uint16
}

func (f FileHeader) String() string {
return fmt.Sprintf("Magic: 0x%X, NumSections: %d, TimeDate: 0x%X, SymbolsPointer: 0x%X, NumSymbols: %d, OptionalHeader: 0x%X, Flags: 0x%X", f.Magic, f.NumSections, f.TimeDate, f.SymbolsPointer, f.NumSymbols, f.OptionalHeader, f.Flags)
}

type AoutHeader struct {
Magic int16
Vstamp int16
TextSize int32
DataSize int32
BssSize int32
Entry int32
TextStart int32
DataStart int32
BssStart int32
GprMask int32
CprMask [4]int32
GpValue int32
TextStart uint32
DataStart uint32
BssStart uint32
GprMask uint32
CprMask [4]uint32
GpValue uint32
}

func (h AoutHeader) String() string {
return fmt.Sprintf("Magic: 0x%X, Vstamp: 0x%X, TextSize: %d, DataSize: %d, BssSize: %d, Entry: 0x%X, TextStart: 0x%X, DataStart: 0x%X, BssStart: 0x%X, GprMask: 0x%X, CprMask: 0x%X, GpValue: 0x%X", h.Magic, h.Vstamp, h.TextSize, h.DataSize, h.BssSize, h.Entry, h.TextStart, h.DataStart, h.BssStart, h.GprMask, h.CprMask, h.GpValue)
}

type SectionHeader struct {
Name [8]uint8
PhysicalAddress int32
VirtualAddress int32
PhysicalAddress uint32
VirtualAddress uint32
Size int32
SectionPointer int32
RelocationsPointer int32
SectionPointer uint32
RelocationsPointer uint32
LnnoPtr int32
NumRelocations uint16
NumLnno uint16
Flags int32
}

func (h SectionHeader) String() string {
return fmt.Sprintf("Name: %s, PhysicalAddress: 0x%X, VirtualAddress: 0x%X, Size: %d, SectionPointer: 0x%X, RelocationsPointer: 0x%X, LnnoPtr: 0x%X, NumRelocations: %d, NumLnno: %d, Flags: 0x%X", string(h.Name[:]), h.PhysicalAddress, h.VirtualAddress, h.Size, h.SectionPointer, h.RelocationsPointer, h.LnnoPtr, h.NumRelocations, h.NumLnno, h.Flags)
}
1 change: 0 additions & 1 deletion rom_image.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package spicy

import (
"bytes"
"errors"
"fmt"
"os"
Expand Down

0 comments on commit d8cdf45

Please sign in to comment.