node/lib/metasm/samples/bindiff.rb
def match_func(a1, a2, do_colorize=true, verb=true)
		f1 = func1[a1]
		f2 = func2[a2]
		raise "dasm1 has no function at #{Expression[a1]}" if not f1
		raise "dasm2 has no function at #{Expression[a2]}" if not f2
		todo1 = [a1]
		todo2 = [a2]
		done1 = []
		done2 = []
		score = 0.0	# average of the (local best) match_block scores
		score += 0.01 if @dasm1.get_label_at(a1) != @dasm2.get_label_at(a2)	# for thunks
		score_div = [f1.length, f2.length].max.to_f
		# XXX this is stupid and only good for perfect matches (and even then it may fail)
		# TODO handle block split etc (eg instr-level diff VS block-level)
		while a1 = todo1.shift
			next if done1.include? a1
			t = todo2.map { |a| [a, match_block(@dasm1.decoded[a1].block, @dasm2.decoded[a].block)] }
			a2 = t.sort_by { |a, s| s }.first
			if not a2
				break
			end
			score += a2[1] / score_div
			a2 = a2[0]
			done1 << a1
			done2 << a2
			todo1.concat f1[a1]
			todo2.concat f2[a2]
			todo2 -= done2
			colorize_blocks(a1, a2) if do_colorize
		end

		score += (f1.length - f2.length).abs * 3 / score_div	# block count difference -> +3 per block

		score
	end
# return how much match a func in d1 and a func in d2
return how much match a func in d1 and a func in d2
return how much match a func in d1 and a func in d2
def match_func(a1, a2, do_colorize=true, verb=true)
		f1 = func1[a1]
		f2 = func2[a2]
		raise "dasm1 has no function at #{Expression[a1]}" if not f1
		raise "dasm2 has no function at #{Expression[a2]}" if not f2
		todo1 = [a1]
		todo2 = [a2]
		done1 = []
		done2 = []
		score = 0.0	
		score += 0.01 if @dasm1.get_label_at(a1) != @dasm2.get_label_at(a2)	
		score_div = [f1.length, f2.length].max.to_f
		while a1 = todo1.shift
			next if done1.include? a1
			t = todo2.map { |a| [a, match_block(@dasm1.decoded[a1].block, @dasm2.decoded[a].block)] }
			a2 = t.sort_by { |a, s| s }.first
			if not a2
				break
			end
			score += a2[1] / score_div
			a2 = a2[0]
			done1 << a1
			done2 << a2
			todo1.concat f1[a1]
			todo2.concat f2[a2]
			todo2 -= done2
			colorize_blocks(a1, a2) if do_colorize
		end
		score += (f1.length - f2.length).abs * 3 / score_div	
		score
	end
def match_func ( a1 , a2 , do_colorize = true , verb = true ) f1 = func1 [ a1 ] f2 = func2 [ a2 ] raise "dasm1 has no function at #{Expression[a1]}" if not f1 raise "dasm2 has no function at #{Expression[a2]}" if not f2 todo1 = [ a1 ] todo2 = [ a2 ] done1 = [ ] done2 = [ ] score = 0.0 score += 0.01 if @dasm1 . get_label_at ( a1 ) != @dasm2 . get_label_at ( a2 ) score_div = [ f1 . length , f2 . length ] . max . to_f while a1 = todo1 . shift next if done1 . include? a1 t = todo2 . map { | a | [ a , match_block ( @dasm1 . decoded [ a1 ] . block , @dasm2 . decoded [ a ] . block ) ] } a2 = t . sort_by { | a , s | s } . first if not a2 break end score += a2 [ 1 ] / score_div a2 = a2 [ 0 ] done1 << a1 done2 << a2 todo1 . concat f1 [ a1 ] todo2 . concat f2 [ a2 ] todo2 -= done2 colorize_blocks ( a1 , a2 ) if do_colorize end score += ( f1 . length - f2 . length ) . abs * 3 / score_div score end
return how much match a func in d1 and a func in d2
return how much match a func in d1 and a func in d2
# average of the (local best) match_block scores # for thunks # XXX this is stupid and only good for perfect matches (and even then it may fail) # TODO handle block split etc (eg instr-level diff VS block-level) # block count difference -> +3 per block
a1
a2
do_colorize
verb