Example #1
0
func getDeps(name string, dirs []string, deps map[string]bool) (err error) {
	f, err := bre.Open(name)
	if err != nil {
		return
	}
	defer f.Close()

	libs, err := f.ImportedLibraries()
	if err != nil {
		return
	}

	if runtime.GOOS == "windows" {
		libsMap := map[string]bool{}
		syms, err := f.ImportedSymbols()
		if err != nil {
			return err
		}
		for _, sym := range syms {
			symInLib := strings.Split(sym, ":")
			libsMap[symInLib[1]] = true
		}
		for lib := range libsMap {
			libs = append(libs, lib)
		}
	}

	deps[name] = true

	for _, lib := range libs {
		for _, dir := range dirs {
			path := filepath.Join(dir, lib)
			if fi, err := os.Stat(path); !os.IsNotExist(err) && !fi.IsDir() {
				err = getDeps(path, dirs, deps)
				if err != nil {
					return err
				}
			}
		}
	}
	return
}
Example #2
0
func main() {
	f, err := bre.Open(os.Args[1])
	if err != nil {
		panic(err)
	}

	fmt.Println("format", f.Format())
	fmt.Println("os", f.Os())
	fmt.Println("arch", f.Arch())
	fmt.Println("type", f.Type())

	for _, section := range f.Sections() {
		if section.Perm()&binaryx.PermExecute != 0 {
			fmt.Println("Disassembly of section", section.Name()+":")

			code := section.Open()

			err = disasm.Disasm(code, os.Stdout, section.Addr(), f.Arch())
			if err != nil {
				log.Fatalln(err)
			}
		}
	}
}