Created
April 25, 2018 11:03
-
-
Save kawakami-o3/4e091add6309a11da4dd696c281764d4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 ( | |
| "bytes" | |
| "os" | |
| "github.com/k0kubun/pp" | |
| u "github.com/kawakami-o3/undergo" | |
| ) | |
| // https://en.wikipedia.org/wiki/Executable_and_Linkable_Format | |
| type Elf struct { | |
| magicNumber []byte | |
| } | |
| var magicNumber = []byte{0x7f, 0x45, 0x4c, 0x46} | |
| func parse(path string) (*Elf, error) { | |
| cnt, err := u.ReadBytes(path) | |
| if err != nil { | |
| return nil, err | |
| } | |
| //elf := p.Println(cnt[1:5]) | |
| buf := bytes.NewBuffer(cnt) | |
| pp.Println(buf) | |
| magic := buf.Next(4) | |
| pp.Println(magicNumber) | |
| pp.Println(bytes.Equal(magic, magicNumber)) | |
| //for i:=0 ; i<5 ; i++ { fmt.Println(i, } | |
| return &Elf{cnt}, nil | |
| } | |
| func main() { | |
| //args := os.Args | |
| //fmt.Println(os.Args[1:len(args)]) | |
| //fmt.Println(os.Args[1:]) | |
| for _, path := range os.Args[1:] { | |
| parse(path) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment