Skip to content

Instantly share code, notes, and snippets.

@nokute78
Created August 8, 2019 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nokute78/46c1eb6a2f6050db4c5a87845dbdf87c to your computer and use it in GitHub Desktop.
Save nokute78/46c1eb6a2f6050db4c5a87845dbdf87c to your computer and use it in GitHub Desktop.
Golang: pe optional header
package main
import (
"debug/pe"
"fmt"
"os"
)
func main() {
file, err := pe.Open(os.Args[1])
if err != nil {
fmt.Fprintf(os.Stderr, "pe.Open:%s\n", err)
os.Exit(1)
}
defer file.Close()
var dataDir [16]pe.DataDirectory
switch file.OptionalHeader.(type) {
case *pe.OptionalHeader32:
fmt.Fprintf(os.Stdout, "Header32\n")
o := file.OptionalHeader.(*pe.OptionalHeader32)
dataDir = o.DataDirectory
case *pe.OptionalHeader64:
fmt.Fprintf(os.Stdout, "Header64\n")
o := file.OptionalHeader.(*pe.OptionalHeader64)
dataDir = o.DataDirectory
default:
fmt.Fprintf(os.Stderr, "invalid format\n")
os.Exit(1)
}
fmt.Printf("dataDir:%v\n", dataDir)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment