Created
August 8, 2019 11:23
-
-
Save nokute78/46c1eb6a2f6050db4c5a87845dbdf87c to your computer and use it in GitHub Desktop.
Golang: pe optional header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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