Code Monkey home page Code Monkey logo

Comments (1)

axt avatar axt commented on May 23, 2024

Hi, sorry for my late answer!

Unfortunatelly I don't follow angr since 3 years, but as far as I know, DDG is deprecated or at least buggy. Thats why I removed the DDG samples from this repository.

Anyhow, I've looked up the script (see at the end of the message) from git history, what I've used to generate DDG graphs back in 2016, made some changes to it, to work with the current angr version, but all the graphs it produces are empty. I've checked ddg.graph.nodes(), which produced 0 result, so in this case the problem is not with visualization, but with DDG itself.

As far as I know, in the current angr there are better solutions provided which you could use to extract these kind of dependencies. Try to check ReachingDefinitionsAnalysis (which I think can produce a UseDefGraph), VariableRecovery, LightEngine in angr, or ask on the official slack channel what they propose/use instead of DDG.

Here is the script:

#! /usr/bin/env python

import angr
from angrutils import plot_cfg, plot_ddg_stmt, plot_ddg_data
from angr.sim_variable import SimMemoryVariable, SimStackVariable, SimRegisterVariable

def analyze(b, addr, name=None):
    start_state = b.factory.blank_state(addr=addr)
    start_state.stack_push(0x0)
    cfg = b.analyses.CFGEmulated(fail_fast=True, starts=[addr], initial_state=start_state, context_sensitivity_level=2, keep_state=True, call_depth=100, normalize=True)

    plot_cfg(cfg, "%s_cfg" % (name), asminst=True, vexinst=True, debug_info=False, remove_imports=True, remove_path_terminator=True)


    ddg = b.analyses.DDG(cfg=cfg)
    plot_ddg_stmt(ddg.graph, "%s_ddg_stmt" % name, project=b)

    ddg._build_function_dependency_graphs()
    for k,v in ddg._function_data_dependencies.items():
        plot_ddg_stmt(v, "%s_fdg_stmt_%x" % (name, k.addr), project=b)

    plot_ddg_data(ddg.data_graph, "%s_ddg_data" % name, project=b)
    plot_ddg_data(ddg.simplified_data_graph, "%s_ddg_simplified_data" % name, project=b)

    for node in ddg.simplified_data_graph.nodes:
        if node.initial:
            label = None
            if isinstance(node.variable, SimStackVariable):
                label = "stack_%s_%x" % (node.variable.base, node.variable.offset)
            elif isinstance(node.variable, SimMemoryVariable):
                label = "mem_"+hex(node.variable.addr)
            elif isinstance(node.variable, SimRegisterVariable):
                label = "reg_"+b.arch.register_names[node.variable.reg]
            else:
                raise NotImplementedError(type(node.variable))

            subgraph = ddg.data_sub_graph(node, simplified=False, killing_edges=True)
            plot_ddg_data(subgraph, "%s_ddg_subgraph_%s" % (name, label), format="png", project=b)


if __name__ == "__main__":
    proj = angr.Project("../samples/simple1", load_options={'auto_load_libs':False})
    main = proj.loader.main_object.get_symbol("main")
    analyze(proj, main.rebased_addr, "simple1")

Here you can check what kind of graphs it produced:
https://github.com/axt/angr-utils/tree/bc0e701e4f643cb8ea32e1393e043060f4f874c4/examples/plot_ddg

from angr-utils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.