func (r *Recorder) Satisfied(mt core.MatcherType) (bool, int) {
	if r.NoPriority() {
		return false, 0
	}
	if r.cscore < incScore {
		if mt == core.ByteMatcher || mt == core.XMLMatcher || mt == core.RIFFMatcher {
			return false, 0
		}
		if len(r.ids) == 0 {
			return false, 0
		}
		for _, res := range r.ids {
			if res.ID == config.TextPuid() {
				return false, 0
			}
		}
	}
	r.satisfied = true
	if mt == core.ByteMatcher {
		return true, r.Start(mt)
	}
	return true, 0
}
func (r *Recorder) Report() []core.Identification {
	// no results
	if len(r.ids) == 0 {
		return []core.Identification{Identification{
			Namespace: r.Name(),
			ID:        "UNKNOWN",
			Warning:   "no match",
		}}
	}
	sort.Sort(r.ids)
	// exhaustive
	if r.Multi() == config.Exhaustive {
		ret := make([]core.Identification, len(r.ids))
		for i, v := range r.ids {
			ret[i] = r.updateWarning(v)
		}
		return ret
	}
	conf := r.ids[0].confidence
	// if we've only got extension / mime matches, check if those matches are ruled out by lack of byte match
	// only permit a single extension or mime only match
	// add warnings too
	if conf <= textScore {
		nids := make([]Identification, 0, 1)
		for _, v := range r.ids {
			// if overall confidence is greater than mime or ext only, then rule out any lesser confident matches
			if conf > mimeScore && v.confidence != conf {
				break
			}
			// if we have plain text result that is based on ext or mime only,
			// and not on a text match, and if text matcher is on for this identifier,
			// then don't report a text match
			if v.ID == config.TextPuid() && conf < textScore && r.textActive {
				continue
			}
			// if the match has no corresponding byte or container signature...
			if ok := r.HasSig(v.ID, core.ContainerMatcher, core.ByteMatcher); !ok {
				// break immediately if more than one match
				if len(nids) > 0 {
					nids = nids[:0]
					break
				}
				nids = append(nids, v)
			}
		}
		if len(nids) != 1 {
			poss := make([]string, len(r.ids))
			for i, v := range r.ids {
				poss[i] = v.ID
				conf = conf | v.confidence
			}
			return []core.Identification{Identification{
				Namespace: r.Name(),
				ID:        "UNKNOWN",
				Warning:   fmt.Sprintf("no match; possibilities based on %v are %v", lowConfidence(conf), strings.Join(poss, ", ")),
			}}
		}
		r.ids = nids
	}
	// handle single result only
	if r.Multi() == config.Single && len(r.ids) > 1 && r.ids[0].confidence == r.ids[1].confidence {
		poss := make([]string, 0, len(r.ids))
		for _, v := range r.ids {
			if v.confidence < conf {
				break
			}
			poss = append(poss, v.ID)
		}
		return []core.Identification{Identification{
			Namespace: r.Name(),
			ID:        "UNKNOWN",
			Warning:   fmt.Sprintf("multiple matches %v", strings.Join(poss, ", ")),
		}}
	}
	ret := make([]core.Identification, len(r.ids))
	for i, v := range r.ids {
		if i > 0 {
			switch r.Multi() {
			case config.Single:
				return ret[:i]
			case config.Conclusive:
				if v.confidence < conf {
					return ret[:i]
				}
			default:
				if v.confidence < incScore {
					return ret[:i]
				}
			}
		}
		ret[i] = r.updateWarning(v)
	}
	return ret
}
Exemple #3
0
func (d *droid) Texts() []string {
	return []string{config.TextPuid()}
}
Exemple #4
0
func (r *reports) Texts() []string {
	return []string{config.TextPuid()}
}