Sha256: c44e2f07a7b5fc5a7648d9aff927a01fdd0d1e00e3f60c8eb67afb1543f1f70e

Contents?: true

Size: 1019 Bytes

Versions: 4

Compression:

Stored size: 1019 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 the memory for a 'ret' which could indicate the beginning of the current function
# (x86 only)
def scanfuncstart(addr)
	if o = (1..16).find { |off| @decoded[addr-off].kind_of? DecodedInstruction } and @decoded[addr-o].bin_length == o
		addr -= o
	end
	if @decoded[addr].kind_of? DecodedInstruction
		fs = find_function_start(addr)
		return fs if fs != addr
	end
	edata = get_edata_at(addr)
	if o = (1..1000).find { |off|
		@decoded[addr-off-1] or
		edata.data[edata.ptr-off-1] == ?\xcc or
		edata.data[edata.ptr-off-1] == ?\xc3 or
		edata.data[edata.ptr-off-3] == ?\xc2
	}
		o -= @decoded[addr-o-1].bin_length-1 if @decoded[addr-o-1].kind_of? DecodedInstruction
		addr-o
	end
end

if gui
	gui.keyboard_callback_ctrl[?P] = lambda { |*a|
		if o = scanfuncstart(gui.curaddr)
			gui.focus_addr(o)
		end
		true
	}
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
metasm-1.0.5 samples/dasm-plugins/scanfuncstart.rb
metasm-1.0.4 samples/dasm-plugins/scanfuncstart.rb
metasm-1.0.3 samples/dasm-plugins/scanfuncstart.rb
metasm-1.0.2 samples/dasm-plugins/scanfuncstart.rb