aboutsummaryrefslogtreecommitdiffstats
path: root/tools/syz-parse/syz-parse.go
blob: b86cecb2ca1137129565efa87f1e197cd5960a0b (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2017 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package main

import (
	"fmt"
	"io/ioutil"
	"os"

	"github.com/google/syzkaller/pkg/report"
)

func main() {
	if len(os.Args) < 2 {
		usage()
		return
	}
	switch os.Args[1] {
	case "report":
		if len(os.Args) != 4 {
			usage()
			return
		}
		parseReport(os.Args[2], os.Args[3])
	default:
		usage()
	}
}

func usage() {
	fmt.Fprintf(os.Stderr, "usage:\n")
	fmt.Fprintf(os.Stderr, "  syz-parse report <OS> <CRASH.log>\n")
	os.Exit(1)
}

func parseReport(os, file string) {
	log, err := ioutil.ReadFile(file)
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	reporter, err := report.NewReporter(os, "", "", nil, nil)
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	rep := reporter.Parse(log)
	if rep == nil {
		fmt.Printf("Couldn't find any reports\n")
		return
	}
	fmt.Printf("=======\n")
	fmt.Printf("Title: %v\n", rep.Title)
	fmt.Printf("Corrupted: %v\n", rep.Corrupted)
	fmt.Printf("Report:\n%s\n", rep.Report)
}