Sha256: ec22d9179d972f37b3dfcb4dd3c66725af2854eef06b68bf76f6bfb480f61326

Contents?: true

Size: 829 Bytes

Versions: 1

Compression:

Stored size: 829 Bytes

Contents

#    This file is part of Metasm, the Ruby assembly manipulation suite
#    Copyright (C) 2006-2009 Yoann GUILLOT
#
#    Licence is LGPL, see LICENCE in the top-level directory


# metasm dasm plugin: scan for xrefs to the target address, incl. relative offsets (eg near call/jmp)
def scanxrefs(target)
	ans = []
	msk = (1 << cpu.size) - 1
	sections.sort.each { |s_addr, edata|
		raw = edata.data.to_str
		(0..raw.length-4).each { |off|
			r = raw[off, 4].unpack('V').first
			ans << (s_addr + off) if (r + off+4 + s_addr) & msk == target or r == target
		}
	}
	ans
end

gui.keyboard_callback[?X] = lambda { |*a|
	target = gui.curaddr
	ans = scanxrefs(target)
	list = [['addr']] + ans.map { |off| [Expression[off].to_s] }
	gui.listwindow("scanned xrefs to #{Expression[target]}", list) { |i| gui.focus_addr i[0] }
	true
} if gui

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
metasm-1.0.3 samples/dasm-plugins/scanxrefs.rb