class Metasm::Gui::FuncGraphViewWidget

Attributes

graph_mode[RW]

:full / :from / :to / :both :from = graph of functions called by addr :to = graph of functions calling addr

Public Class Methods

new(*a) click to toggle source
Calls superclass method
# File metasm/gui/dasm_funcgraph.rb, line 15
def initialize(*a)
        super(*a)
        @graph_mode = :full
end

Public Instance Methods

build_ctx(ctx) click to toggle source
# File metasm/gui/dasm_funcgraph.rb, line 20
def build_ctx(ctx)
        addr = @curcontext.root_addrs[0]
        case @graph_mode
        when :full
                g = @dasm.function_graph
        when :from
                g = @dasm.function_graph_from(addr)
        when :to
                g = @dasm.function_graph_to(addr)
        when :both
                # merge from+to
                g = @dasm.function_graph_to(addr)
                @dasm.function_graph_from(addr).each { |k, v|
                        g[k] ||= v
                        g[k] |= v
                }
        end
        g = {addr => []} if not g or g.empty?

        # create boxes
        (g.keys + g.values).flatten.uniq.each { |a|
                # box text
                txt = @dasm.get_label_at(a)
                txt ||= Expression[a].to_s
                b = ctx.new_box a, :addresses => [a], :line_text_col => [], :line_address => [a]
                b[:line_text_col] << [[txt, :label]]
                b.w = txt.length * @font_width + 2
                b.h = @font_height
        }

        # link boxes
        g.each { |f, tl| tl.each { |t| ctx.link_boxes(f, t) } }

end
doubleclick(x, y) click to toggle source
Calls superclass method
# File metasm/gui/dasm_funcgraph.rb, line 55
def doubleclick(x, y)
        if find_box_xy(x, y) and @hl_word and @zoom >= 0.90 and @zoom <= 1.1
                @mousemove_origin = nil
                @parent_widget.focus_addr(@hl_word, :graph)
        else
                super(x, y)
        end
end
focus_addr(addr, mode=@graph_mode) click to toggle source
# File metasm/gui/dasm_funcgraph.rb, line 75
def focus_addr(addr, mode=@graph_mode)
        if mode == false
                # simply center the view on addr in the current graph
                raise 'fu' if not b = @curcontext.box.find { |b_| b_[:line_address][0] == addr }
                @caret_box, @caret_x, @caret_y = b, 0, 0
                @curcontext.view_x += (width/2 / @zoom - width/2)
                @curcontext.view_y += (height/2 / @zoom - height/2)
                @zoom = 1.0

                focus_xy(b.x, b.y)
                update_caret
                return
        end

        return if not addr = @dasm.normalize(addr)
        if not @dasm.function[addr]
                return if not addr = @dasm.find_function_start(addr)
        end
        return true if @curcontext.root_addrs == [addr] and @graph_mode == mode
        @graph_mode = mode
        @curcontext = Graph.new('fu')
        @curcontext.root_addrs = [addr]
        @want_focus_addr = addr
        gui_update
        true
end
get_cursor_pos() click to toggle source
# File metasm/gui/dasm_funcgraph.rb, line 64
def get_cursor_pos
        [@curcontext.root_addrs[0], @graph_mode]
end
set_cursor_pos(p) click to toggle source
# File metasm/gui/dasm_funcgraph.rb, line 68
def set_cursor_pos(p)
        addr, m = p
        focus_addr(addr, m)
        @caret_x = 0
        update_caret
end