Exemple #1
0
func (extract *CFSMExtract) WriteOutput() {
	fmt.Printf(" ----- Results ----- \n%s\n", extract.session.String())

	sesstype.PrintNodeSummary(extract.session)

	dotFile, err := os.OpenFile(fmt.Sprintf("%s.dot", extract.prefix), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
	if err != nil {
		panic(err)
	}
	defer dotFile.Close()

	dot := sesstype.NewGraphvizDot(extract.session)
	if _, err = dot.WriteTo(dotFile); err != nil {
		panic(err)
	}

	os.MkdirAll(extract.outdir, 0750)
	cfsmPath := fmt.Sprintf("%s/%s_cfsms", extract.outdir, extract.prefix)
	cfsmFile, err := os.OpenFile(cfsmPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
	if err != nil {
		panic(err)
	}
	defer cfsmFile.Close()

	cfsms := sesstype.NewCFSMs(extract.session)
	if _, err := cfsms.WriteTo(cfsmFile); err != nil {
		log.Fatalf("Cannot write CFSMs to file: %v", err)
	}

	fmt.Fprintf(os.Stderr, "CFSMs written to %s\n", cfsmPath)
	cfsms.PrintSummary()
}
Exemple #2
0
func cfsmHandler(w http.ResponseWriter, req *http.Request) {
	b, err := ioutil.ReadAll(req.Body)
	if err != nil {
		NewErrInternal(err, "Cannot read input Go source code").Report(w)
	}
	req.Body.Close()
	conf, err := ssabuilder.NewConfigFromString(string(b))
	if err != nil {
		NewErrInternal(err, "Cannot initialise SSA").Report(w)
	}
	ssainfo, err := conf.Build()
	if err != nil {
		NewErrInternal(err, "Cannot build SSA").Report(w)
	}
	extract := cfsmextract.New(ssainfo, "extract", "/tmp")
	go extract.Run()

	select {
	case <-extract.Error:
		NewErrInternal(err, "CFSM extraction failed").Report(w)
	case <-extract.Done:
		log.Println("CFSMs: analysis completed in", extract.Time)
	}
	cfsms := sesstype.NewCFSMs(extract.Session())
	bufCfsm := new(bytes.Buffer)
	cfsms.WriteTo(bufCfsm)
	dot := sesstype.NewGraphvizDot(extract.Session())
	bufDot := new(bytes.Buffer)
	dot.WriteTo(bufDot)
	reply := struct {
		CFSM string `json:"CFSM"`
		Dot  string `json:"dot"`
		Time string `json:"time"`
	}{
		CFSM: bufCfsm.String(),
		Dot:  bufDot.String(),
		Time: extract.Time.String(),
	}
	json.NewEncoder(w).Encode(&reply)
}