Esempio n. 1
0
func (f fdds) Signatures() ([]frames.Signature, []string, error) {
	var errs []error
	var puidsIDs map[string][]string
	if len(f.p.IDs()) > 0 {
		puidsIDs = make(map[string][]string)
	}
	sigs, ids := make([]frames.Signature, 0, len(f.f)), make([]string, 0, len(f.f))
	for _, v := range f.f {
		ss, e := magics(v.Magics)
		if e != nil {
			errs = append(errs, e)
		}
		for _, s := range ss {
			sigs = append(sigs, s)
			ids = append(ids, v.ID)
		}
		if puidsIDs != nil {
			for _, puid := range v.PUIDs() {
				puidsIDs[puid] = append(puidsIDs[puid], v.ID)
			}
		}
	}
	if puidsIDs != nil {
		puids := make([]string, 0, len(puidsIDs))
		for p := range puidsIDs {
			puids = append(puids, p)
		}
		np := identifier.Filter(puids, f.p)
		ns, ps, e := np.Signatures()
		if e != nil {
			errs = append(errs, e)
		}
		for i, v := range ps {
			for _, id := range puidsIDs[v] {
				sigs = append(sigs, ns[i])
				ids = append(ids, id)
			}
		}
	}
	var err error
	if len(errs) > 0 {
		errStrs := make([]string, len(errs))
		for i, e := range errs {
			errStrs[i] = e.Error()
		}
		err = errors.New(strings.Join(errStrs, "; "))
	}
	return sigs, ids, err
}
Esempio n. 2
0
func (f fdds) containers(typ string) ([][]string, [][]frames.Signature, []string, error) {
	if _, ok := f.p.(identifier.Blank); ok {
		return nil, nil, nil, nil
	}
	puidsIDs := make(map[string][]string)
	for _, v := range f.f {
		for _, puid := range v.PUIDs() {
			puidsIDs[puid] = append(puidsIDs[puid], v.ID)
		}
	}
	puids := make([]string, 0, len(puidsIDs))
	for p := range puidsIDs {
		puids = append(puids, p)
	}

	np := identifier.Filter(puids, f.p)

	names, sigs, ids := make([][]string, 0, len(f.f)), make([][]frames.Signature, 0, len(f.f)), make([]string, 0, len(f.f))
	var (
		ns  [][]string
		ss  [][]frames.Signature
		is  []string
		err error
	)
	switch typ {
	default:
		err = errors.New("Unknown container type " + typ)
	case "ZIP":
		ns, ss, is, err = np.Zips()
	case "OLE2":
		ns, ss, is, err = np.MSCFBs()
	}

	if err != nil {
		return nil, nil, nil, err
	}
	for i, puid := range is {
		for _, id := range puidsIDs[puid] {
			names = append(names, ns[i])
			sigs = append(sigs, ss[i])
			ids = append(ids, id)
		}
	}
	return names, sigs, ids, nil
}
Esempio n. 3
0
func (db doublesFilter) Signatures() ([]frames.Signature, []string, error) {
	filter := identifier.Filter(db.ids, db.Parseable)
	return filter.Signatures()
}