Exemple #1
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)
}
Exemple #2
0
func extractCFSMs(files []string) {
	logFile, err := RootCmd.PersistentFlags().GetString("log")
	if err != nil {
		log.Fatal(err)
	}
	noLogging, err := RootCmd.PersistentFlags().GetBool("no-logging")
	if err != nil {
		log.Fatal(err)
	}
	noColour, err := RootCmd.PersistentFlags().GetBool("no-colour")
	if err != nil {
		log.Fatal(err)
	}
	l := logwriter.NewFile(logFile, !noLogging, !noColour)
	if err := l.Create(); err != nil {
		log.Fatal(err)
	}
	defer l.Cleanup()

	conf, err := ssabuilder.NewConfig(files)
	conf.BuildLog = l.Writer
	if err != nil {
		log.Fatal(err)
	}
	ssainfo, err := conf.Build()
	if err != nil {
		log.Fatal(err)
	}
	extract := cfsmextract.New(ssainfo, prefix, outdir)
	go extract.Run()

	select {
	case <-extract.Error:
		log.Fatal(err)
	case <-extract.Done:
		log.Println("Analysis finished in", extract.Time)
		extract.WriteOutput()
	}
}