Exemple #1
0
func main() {
	flag.Parse()

	for _, pattern := range flag.Args() {
		files, err := filepath.Glob(pattern)
		if err != nil {
			log.Fatal(err)
		}
		for _, f := range files {
			fi, err := os.Stat(f)
			if err != nil {
				log.Fatal(err)
			}
			if !fi.IsDir() {
				fmt.Println("\n*** ", f, " ***")
				fil, err := os.Open(f)
				if err != nil {
					log.Fatal(err)
				}
				func(fil io.Reader, f string) {
					var lex vblexer.Lex
					defer func() {
						if r := recover(); r != nil {
							log.Print("PARSE ERROR ", f, ":", lex.Line, ": ", r)
						}
					}()
					lex.Init(fil, f, vbscanner.HTML_MODE)
					for k, t, v := lex.Lex(); k != vblexer.EOF; k, t, v = lex.Lex() {
						fmt.Printf("%-10s %v %#v\n", k, t, v)
					}
				}(fil, f)
				fil.Close()
			}
		}
	}
}
Exemple #2
0
func main() {
	var root string
	var obj bool
	flag.StringVar(&root, "root", ".", "Root folder to search")
	flag.BoolVar(&obj, "obj", false, "Show COM objects used in each file")
	flag.Parse()

	filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			fmt.Println(err.Error())
			return err
		}
		if !info.IsDir() && filepath.Ext(info.Name()) == ".asp" {
			messages := make([]string, 0)
			fil, err := os.Open(path)
			if err != nil {
				return err
			}
			defer fil.Close()
			func(fil io.Reader, f string) {
				var lex vblexer.Lex
				defer func() {
					if r := recover(); r != nil {
						fmt.Println("*** ", f, " ***")
						fmt.Println("PARSE ERROR:", lex.Line, ": ", r)
						fmt.Println()
					}
				}()
				lex.Init(fil, f, vbscanner.HTML_MODE)
				creatingObj := false
				for k, t, v := lex.Lex(); k != vblexer.EOF; k, t, v = lex.Lex() {
					switch k {
					case vblexer.STATEMENT:
						switch t {
						case "Stop":
							messages = append(messages, fmt.Sprintf("%d: Statement [Stop] should not be used in production code", lex.Line))
						case "Execute", "Executeglobal":
							messages = append(messages, fmt.Sprintf("%d: Statement [%s] is not recommended", lex.Line, t))
						}
					case vblexer.FUNCTION:
						switch t {
						case "Eval":
							messages = append(messages, fmt.Sprintf("%d: Function [%s] is not recommended", lex.Line, t))
						}
					case vblexer.IDENTIFIER:
						switch strings.ToLower(v) {
						case "createobject", "server.createobject", "wscript.createobject":
							creatingObj = true
						default:
							if creatingObj && obj {
								messages = append(messages, fmt.Sprintf("%d: Using object [%s]", lex.Line, v))
							}
							creatingObj = false
						}
					case vblexer.STRING:
						if creatingObj && obj {
							messages = append(messages, fmt.Sprintf("%d: Using object [%s]", lex.Line, v))
						}
						creatingObj = false
					}
				}
				if len(messages) > 0 {
					fmt.Println("*** ", f, " ***")
					for _, m := range messages {
						fmt.Println(m)
					}
					fmt.Println()
				}
			}(fil, path)
		}
		return nil
	})
}