-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (37 loc) · 1.13 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"strings"
"github.com/richardlehane/mscfb"
"gopkg.in/alecthomas/kingpin.v2"
)
var (
app = kingpin.New("cfbfdump", "A dead simple tool to dump the contents of some cfbf file")
cfbffile = kingpin.Arg("file", "The CFBF file to dump.").Required().File()
)
func main() {
log.Print("Started")
kingpin.Version("0.0.1")
kingpin.Parse()
doc, err := mscfb.New(*cfbffile)
kingpin.FatalIfError(err, "Failed to parse file")
log.Print("Read file")
dir, err := ioutil.TempDir(".", (*cfbffile).Name())
kingpin.FatalIfError(err, "Cant create temp directory")
log.Printf("Creating output directory: %s", dir)
for entry, err := doc.Next(); err == nil; entry, err = doc.Next() {
p := strings.Join(entry.Path, string(os.PathSeparator))
fullPath := dir + string(os.PathSeparator) + p
_ = os.Mkdir(fullPath, os.ModePerm)
buf := make([]byte, entry.Size)
i, _ := doc.Read(buf)
if i > 0 {
ioutil.WriteFile(fullPath+string(os.PathSeparator)+entry.Name, buf, os.ModePerm)
entryData, _ := json.Marshal(entry)
log.Printf("Writing entry: %s", string(entryData[:]))
}
}
}