Esempio n. 1
0
func (p pronom) contMatcher(m core.Matcher) error {
	// when no container is set
	if p.c == nil {
		return nil
	}
	var zpuids, mpuids []string
	var zsigs, msigs [][]frames.Signature
	var znames, mnames [][]string
	cpuids := make(map[int]string)
	for _, fm := range p.c.FormatMappings {
		cpuids[fm.Id] = fm.Puid
	}
	for _, c := range p.c.ContainerSignatures {
		puid := cpuids[c.Id]
		// only include the included fmts
		// warning - this will mean no standalone container extensions
		if !p.hasPuid(puid) {
			continue
		}
		typ := c.ContainerType
		names := make([]string, 0, 1)
		sigs := make([]frames.Signature, 0, 1)
		for _, f := range c.Files {
			names = append(names, f.Path)
			sig, err := processDROID(puid, f.Signature.ByteSequences)
			if err != nil {
				return err
			}
			sigs = append(sigs, sig)
		}
		switch typ {
		case "ZIP":
			zpuids = append(zpuids, puid)
			znames = append(znames, names)
			zsigs = append(zsigs, sigs)
		case "OLE2":
			mpuids = append(mpuids, puid)
			mnames = append(mnames, names)
			msigs = append(msigs, sigs)
		default:
			return fmt.Errorf("Pronom: container parsing - unknown type %s", typ)
		}
	}
	// apply no priority config
	var zplist, mplist priority.List
	if !config.NoPriority() {
		zplist, mplist = p.pm.List(zpuids), p.pm.List(mpuids)
	}
	_, err := m.Add(containermatcher.SignatureSet{containermatcher.Zip, znames, zsigs}, zplist)
	if err != nil {
		return err
	}
	l, err := m.Add(containermatcher.SignatureSet{containermatcher.Mscfb, mnames, msigs}, mplist)
	if err != nil {
		return err
	}
	p.cPuids = append(zpuids, mpuids...)
	p.cStart = l - len(p.cPuids)
	return nil
}
Esempio n. 2
0
// add adds extension, bytematcher or containermatcher signatures to the identifier
func (p *pronom) add(m core.Matcher, t core.MatcherType) error {
	switch t {
	default:
		return fmt.Errorf("Pronom: unknown matcher type %d", t)
	case core.ExtensionMatcher:
		if !config.NoExt() {
			var exts [][]string
			exts, p.ePuids = p.j.Globs()
			l, err := m.Add(stringmatcher.SignatureSet(exts), nil)
			if err != nil {
				return err
			}
			p.eStart = l - len(p.ePuids)
			return nil
		}
	case core.MIMEMatcher:
		if !config.NoMIME() {
			var mimes [][]string
			mimes, p.mPuids = p.j.MIMEs()
			l, err := m.Add(stringmatcher.SignatureSet(mimes), nil)
			if err != nil {
				return err
			}
			p.mStart = l - len(p.mPuids)
			return nil
		}
	case core.ContainerMatcher:
		return p.contMatcher(m)
	case core.ByteMatcher:
		var sigs []frames.Signature
		var err error
		sigs, p.bPuids, err = p.j.Signatures()
		if err != nil {
			return err
		}
		var plist priority.List
		if !config.NoPriority() {
			plist = p.pm.List(p.bPuids)
		}
		l, err := m.Add(bytematcher.SignatureSet(sigs), plist)
		if err != nil {
			return err
		}
		p.bStart = l - len(p.bPuids)
	case core.TextMatcher:
		if !config.NoText() && p.hasPuid(config.TextPuid()) {
			l, _ := m.Add(textmatcher.SignatureSet{}, nil)
			p.tStart = l
		}
	}
	return nil
}
Esempio n. 3
0
// add adds extension, bytematcher or containermatcher signatures to the identifier
func (p *pronom) add(m core.Matcher) error {
	switch t := m.(type) {
	default:
		return fmt.Errorf("Pronom: unknown matcher type %T", t)
	case extensionmatcher.Matcher:
		if !config.NoExt() {
			var exts [][]string
			exts, p.ePuids = p.j.extensions()
			l, err := m.Add(extensionmatcher.SignatureSet(exts), nil)
			if err != nil {
				return err
			}
			p.eStart = l - len(p.ePuids)
			return nil
		}
	case containermatcher.Matcher:
		return p.contMatcher(m)
	case *bytematcher.Matcher:
		var sigs []frames.Signature
		var err error
		sigs, p.bPuids, err = p.j.signatures()
		if err != nil {
			return err
		}
		var plist priority.List
		if !config.NoPriority() {
			plist = p.pm.List(p.bPuids)
		}
		l, err := m.Add(bytematcher.SignatureSet(sigs), plist)
		if err != nil {
			return err
		}
		p.bStart = l - len(p.bPuids)
	case *textmatcher.Matcher:
		if !config.NoText() && p.hasPuid(config.TextPuid()) {
			l, _ := m.Add(textmatcher.SignatureSet{}, nil)
			p.tStart = l
		}
	}
	return nil
}