コード例 #1
0
ファイル: mscfb.go プロジェクト: ross-spencer/siegfried
func mscfbRdr(b *siegreader.Buffer) (Reader, error) {
	m, err := mscfb.New(siegreader.ReaderFrom(b))
	if err != nil {
		return nil, err
	}
	return &mscfbReader{rdr: m}, nil
}
コード例 #2
0
ファイル: comdump.go プロジェクト: richardlehane/comdump
func process(in string, thumbs bool) error {
	thumbsSz := make([]byte, 4)

	file, err := os.Open(in)
	if err != nil {
		return err
	}
	defer file.Close()

	doc, err := mscfb.New(file)
	if doc == nil {
		return err
	}
	if *debug {
		d := doc.Debug()
		fmt.Println("DEBUGGING")
		for k, v := range d {
			fmt.Printf("%s: %v\n", k, v)
		}
		return nil
	}
	dir, base := filepath.Split(in)
	base = strings.Join(strings.Split(base, "."), "_")
	base += "_comobjects"
	path := filepath.Join(dir, base)
	if *meta {
		if err != nil {
			fmt.Println("Errors: ", err.Error())
		}
		fmt.Println("Root Object")
		fmt.Println("  CLSID:     ", doc.ID())
		fmt.Println("  Created:   ", doc.Created())
		fmt.Println("  Modified:  ", doc.Modified())
		fmt.Println()
	} else {
		err = os.Mkdir(path, os.ModePerm)
		if err != nil {
			return err
		}
	}
	for {
		entry, err := doc.Next()
		if err == io.EOF {
			break
		}
		if err != nil {
			return err
		}
		paths := []string{path}
		entry.Path = append(entry.Path, entry.Name)
		paths = append(paths, entry.Path...)
		if *meta {
			if !entry.FileInfo().IsDir() {
				fmt.Println("Stream Object")
				fmt.Println("  Name :     ", entry.Name)
				fmt.Println("  Initial:   ", entry.Initial)
				fmt.Println("  Path:      ", strings.Join(entry.Path, "/"))
				fmt.Printf("  Size:       %d", entry.Size)
			} else {
				fmt.Println("Storage Object")
				fmt.Println("  Name (raw):", entry.Name)
				fmt.Println("  Path:      ", strings.Join(entry.Path, "/"))
				fmt.Println("  CLSID:     ", entry.ID())
				fmt.Println("  Created:   ", entry.Created())
				fmt.Println("  Modified:  ", entry.Modified())
			}
			fmt.Println()
			continue
		}
		if entry.FileInfo().IsDir() {
			err = os.Mkdir(filepath.Join(paths...), os.ModePerm)
			if err != nil {
				return err
			}
			continue
		}
		if thumbs && entry.Name != "Catalog" {
			paths[len(paths)-1] += ".jpg"
			_, err = doc.Read(thumbsSz)
			if err != nil {
				return err
			}
			sz := binary.LittleEndian.Uint32(thumbsSz)
			cut := make([]byte, int(sz)-4)
			_, err = doc.Read(cut)
			if err != nil {
				return err
			}
		}
		if thumbs && entry.Name == "Catalog" {
			hdr := new(CatalogHeader)
			err = binary.Read(doc, binary.LittleEndian, hdr)
			if err != nil {
				return err
			}
			fmt.Println("Thumbs Database")
			fmt.Println("  Version:    ", hdr.Version)
			fmt.Println("  Thumbnails: ", hdr.NumEntries)
			fmt.Println("  DimensionX: ", hdr.DimensionX)
			fmt.Println("  DimensionY: ", hdr.DimensionY)
			for i := 0; i < int(hdr.NumEntries); i++ {
				thumb := new(CatalogEntry)
				err = binary.Read(doc, binary.LittleEndian, thumb)
				if err != nil {
					return err
				}
				name := make([]uint16, (int(thumb.Size)-20)/2)
				err = binary.Read(doc, binary.LittleEndian, name)
				if err != nil {
					return err
				}
				fmt.Println("  Thumbnail ", thumb.Number)
				fmt.Println("    Name: ", string(utf16.Decode(name)))
				fmt.Println("    Date: ", thumb.Date)
				pad := make([]byte, 4)
				_, err = doc.Read(pad)
				if err != nil {
					return err
				}
			}
		}
		outFile, err := os.Create(filepath.Join(paths...))
		if err != nil {
			return err
		}
		_, err = io.Copy(outFile, doc)
		if err != nil {
			return err
		}
		outFile.Close()
	}
	return nil
}