angr.analyses.decompiler.optimization_passes.duplication_reverter¶
- class angr.analyses.decompiler.optimization_passes.duplication_reverter.DuplicationReverter
Bases:
StructuringOptimizationPassThis (de)optimization reverts the effects of many compiler optimizations that cause code duplication in the decompilation. This deoptimization is the implementation of the USENIX 2024 paper SAILR’s ISD doptimization. As such, the main goal of this optimization is to remove code duplication by merging semantically similar blocks in the AIL graph.
- NAME = 'Revert Statement Duplication Optimizations'¶
- DESCRIPTION = "This (de)optimization reverts the effects of many compiler optimizations that cause code duplication in\n the decompilation. This deoptimization is the implementation of the USENIX 2024 paper SAILR's ISD\n doptimization. As such, the main goal of this optimization is to remove code duplication by merging\n semantically similar blocks in the AIL graph."¶
- __init__(*args, max_guarding_conditions=4, **kwargs)
- write_graph: DiGraph | None
- read_graph: DiGraph | None
- static boolean_operators_in_condition(condition)
TODO: this entire boolean checking semantic we use needs to be removed, see how it is used for other dels needed we need to replace it with a boolean variable insertion on both branches that lead to the new block.
Say we have:
if (A()) { do_thing(); } if (B()) { do_thing(): }
We want to translate it to:
int should_do_thing = 0; if (A()) should_do_thing = 1; if (B()) should_do_thing = 1; if (should_do_thing): do_thing();
Although longer, this code can be optimized to look like:
int should_do_thing = A() || B(); if (should_do_thing) do_thing();
- Parameters:
condition (Expression)
- stmt_can_move_to(stmt, block, new_idx, io_finder=None)
- maximize_similarity_of_blocks(block1, block2, graph)
This attempts to rearrange the order of statements in block1 and block2 to maximize the similarity between them. This implementation is a little outdated since CodeMotion optimization was implemented, but it should be disabled until we have a good SSA implementation.
TODO: reimplement me when we have better SSA
- create_merged_subgraph(blocks, graph, maximize_similarity=False)
- Return type:
- Parameters:
graph (DiGraph)
- similar_conditional_when_single_corrected(block1, block2, graph)
- collect_conditions_between_nodes(graph, source, sinks, max_depth=15)
- shared_common_conditional_dom(nodes, graph)
Takes n nodes and returns True only if all the nodes are dominated by the same node, which must be a ConditionalJump
@param nodes: @param graph: @return:
- Parameters:
graph (DiGraph)
Submodules