Example #1
0
func TestProcessFmt134(t *testing.T) {
	m, _, _ := Add(nil, SignatureSet{}, nil)
	b := m.(*Matcher)
	config.SetDistance(1000)
	config.SetRange(500)
	config.SetChoices(3)
	b.addSignature(tests.TestFmts[134])
	saver := persist.NewLoadSaver(nil)
	Save(b, saver)
	loader := persist.NewLoadSaver(saver.Bytes())
	b = Load(loader).(*Matcher)
	if len(b.keyFrames[0]) != 8 {
		for _, v := range b.keyFrames[0] {
			t.Errorf("%s\n", v)
		}
	}
	for _, t := range b.tests {
		t.maxLeftDistance = maxLength(t.left)
		t.maxRightDistance = maxLength(t.right)
	}
	if len(b.tests) != 8 {
		for _, v := range b.tests {
			t.Error(v.maxRightDistance)
			t.Error(v.right)
		}
	}
}
Example #2
0
func TestProcess(t *testing.T) {
	m, _, _ := Add(nil, SignatureSet{}, nil)
	b := m.(*Matcher)
	config.SetDistance(8192)()
	config.SetRange(2059)()
	config.SetChoices(9)()
	for i, v := range tests.TestSignatures {
		err := b.addSignature(v)
		if err != nil {
			t.Errorf("Unexpected error adding persist; sig %v; error %v", i, v)
		}
	}
	saver := persist.NewLoadSaver(nil)
	Save(b, saver)
	loader := persist.NewLoadSaver(saver.Bytes())
	b = Load(loader).(*Matcher)
	if len(b.keyFrames) != 6 {
		t.Errorf("Expecting 6 keyframe slices, got %d", len(b.keyFrames))
	}
	var tl int
	for _, v := range b.keyFrames {
		tl += len(v)
	}
	if tl != 12 {
		t.Errorf("Expecting a total of 12 keyframes, got %d", tl)
	}
	if len(b.tests) != 9 {
		t.Errorf("Expecting a total of 9 tests, got %d", len(b.tests))
	}
	if len(b.bofSeq.set) != 4 {
		t.Errorf("Expecting 4 BOF seqs, got %d", len(b.bofSeq.set))
	}
	e1 := wac.Seq{[]int64{0}, []wac.Choice{{[]byte{'t', 'e', 's', 't'}}}}
	if !seqEquals(b.bofSeq.set[0], e1) {
		t.Errorf("Expecting %v to equal %v", b.bofSeq.set[0], e1)
	}
	e2 := wac.Seq{[]int64{-1}, []wac.Choice{{[]byte{'t', 'e', 's', 't'}}}}
	if seqEquals(b.bofSeq.set[0], e2) {
		t.Errorf("Not expecting %v to equal %v", b.bofSeq.set[0], e2)
	}
	if len(b.eofSeq.set) != 2 {
		t.Errorf("Expecting two EOF seqs, got %d, first is %v", len(b.eofSeq.set), b.eofSeq.set[0])
	}
	if len(b.bofFrames.set) != 1 {
		t.Errorf("Expecting one BOF Frame, got %d", len(b.bofFrames.set))
	}
	if len(b.eofFrames.set) != 0 {
		t.Errorf("Expecting no EOF frame, got %d", len(b.eofFrames.set))
	}
}
Example #3
0
func TestProcessFmt418(t *testing.T) {
	m, _, _ := Add(nil, SignatureSet{}, nil)
	b := m.(*Matcher)
	config.SetDistance(2000)()
	config.SetRange(500)()
	config.SetChoices(10)()
	b.addSignature(tests.TestFmts[418])
	saver := persist.NewLoadSaver(nil)
	Save(b, saver)
	loader := persist.NewLoadSaver(saver.Bytes())
	b = Load(loader).(*Matcher)
	if len(b.keyFrames[0]) != 2 {
		for _, v := range b.keyFrames[0] {
			t.Errorf("%s\n", v)
		}
	}
}
Example #4
0
func getOptions() []config.Option {
	if *home != config.Home() {
		config.SetHome(*home)
	}
	if *inspectHome != config.Home() {
		config.SetHome(*inspectHome)
	}
	opts := []config.Option{}
	// build options
	if *droid != config.Droid() {
		opts = append(opts, config.SetDroid(*droid))
	}
	if *container != config.Container() {
		opts = append(opts, config.SetContainer(*container))
	}
	if *mi != "" {
		opts = append(opts, config.SetMIMEInfo(*mi))
	}
	if *fdd != "" {
		opts = append(opts, config.SetLOC(*fdd))
	}
	if *locfdd {
		opts = append(opts, config.SetLOC(""))
	}
	if *nopronom {
		opts = append(opts, config.SetNoPRONOM())
	}
	if *name != "" {
		opts = append(opts, config.SetName(*name))
	}
	if *details != config.Details() {
		opts = append(opts, config.SetDetails(*details))
	}
	if *extend != "" {
		opts = append(opts, config.SetExtend(expandSets(*extend)))
	}
	if *extendc != "" {
		if *extend == "" {
			fmt.Println(
				`roy: warning! Unless the container extension only extends formats defined in 
the DROID signature file you should also include a regular signature extension 
(-extend) that includes a FileFormatCollection element describing the new formats.`)
		}
		opts = append(opts, config.SetExtendC(expandSets(*extendc)))
	}
	if *include != "" {
		opts = append(opts, config.SetLimit(expandSets(*include)))
	}
	if *exclude != "" {
		opts = append(opts, config.SetExclude(expandSets(*exclude)))
	}
	if *bof != 0 {
		opts = append(opts, config.SetBOF(*bof))
	}
	if *eof != 0 {
		opts = append(opts, config.SetEOF(*eof))
	}
	if *noeof {
		opts = append(opts, config.SetNoEOF())
	}
	if *multi != "" {
		opts = append(opts, config.SetMulti(strings.ToLower(*multi)))
	}
	if *nocontainer {
		opts = append(opts, config.SetNoContainer())
	}
	if *notext {
		opts = append(opts, config.SetNoText())
	}
	if *noname {
		opts = append(opts, config.SetNoName())
	}
	if *nomime {
		opts = append(opts, config.SetNoMIME())
	}
	if *noxml {
		opts = append(opts, config.SetNoXML())
	}
	if *noriff {
		opts = append(opts, config.SetNoRIFF())
	}
	if *noreports {
		opts = append(opts, config.SetNoReports())
	}
	if *doubleup {
		opts = append(opts, config.SetDoubleUp())
	}
	if *rng != config.Range() {
		opts = append(opts, config.SetRange(*rng))
	}
	if *distance != config.Distance() {
		opts = append(opts, config.SetDistance(*distance))
	}
	if *choices != config.Choices() {
		opts = append(opts, config.SetChoices(*choices))
	}
	// inspect options
	if *inspectMI != "" {
		opts = append(opts, config.SetMIMEInfo(*inspectMI))
	}
	if *inspectFDD != "" {
		opts = append(opts, config.SetLOC(*fdd))
	}
	if *inspectLOC {
		opts = append(opts, config.SetLOC(""))
	}
	if *inspectInclude != "" {
		opts = append(opts, config.SetLimit(expandSets(*inspectInclude)))
	}
	if *inspectExclude != "" {
		opts = append(opts, config.SetExclude(expandSets(*inspectExclude)))
	}
	if *inspectExtend != "" {
		opts = append(opts, config.SetExtend(expandSets(*inspectExtend)))
	}
	if *inspectExtendc != "" {
		if *inspectExtend == "" {
			fmt.Println(
				`roy: warning! Unless the container extension only extends formats defined in 
the DROID signature file you should also include a regular signature extension 
(-extend) that includes a FileFormatCollection element describing the new formats.`)
		}
		opts = append(opts, config.SetExtendC(expandSets(*inspectExtendc)))
	}
	return opts
}