fkie-cad / dewolf

A research decompiler implemented as a Binary Ninja plugin.
GNU Lesser General Public License v2.1
162 stars 9 forks source link

[ValueError@switch_variable_detection.py:117] ValueError: No switch variable candidate found. But with actual switch. #306

Closed mm4rks closed 10 months ago

mm4rks commented 11 months ago

What happened?

Traceback (most recent call last):
  File "/home/user/dewolf/decompile.py", line 76, in <module>
    main(Decompiler)
  File "/home/user/dewolf/decompiler/util/commandline.py", line 80, in main
    task = decompiler.decompile(function_name, options)
  File "/home/user/dewolf/decompile.py", line 51, in decompile
    pipeline.run(task)
  File "/home/user/dewolf/decompiler/pipeline/pipeline.py", line 109, in run
    raise e
  File "/home/user/dewolf/decompiler/pipeline/pipeline.py", line 102, in run
    instance.run(task)
  File "/home/user/dewolf/decompiler/pipeline/preprocessing/switch_variable_detection.py", line 91, in run
    self._handle_switch_block(switch_block)
  File "/home/user/dewolf/decompiler/pipeline/preprocessing/switch_variable_detection.py", line 106, in _handle_switch_block
    switch_expression = self.find_switch_expression(switch_instruction)
  File "/home/user/dewolf/decompiler/pipeline/preprocessing/switch_variable_detection.py", line 117, in find_switch_expression
    raise ValueError("No switch variable candidate found.")
ValueError: No switch variable candidate found.

How to reproduce?

pub fn test1(day: usize) {
    match day {
        1 => println!("Monady"),
        2 => println!("Tuesday"),
        3 => {},
        4 => println!("Thursday"),
        5 => println!("Friday"),
        6 => println!("Saturday"),
        7 => println!("Sunday"),
        _ => println!("Invalid input")
    }
}

sample.zip

dewolf rustTest.exe sub_140001020 --debug -v

Affected Binary Ninja Version(s)

3.4.4271

mm4rks commented 11 months ago

/cib

github-actions[bot] commented 11 months ago

Branch issue-306-_ValueError_switch_variable_detection_py_117_ValueError_No_switch_variable_candidate_found_But_with_actual_switch created!

mm4rks commented 11 months ago

related: #279

mm4rks commented 11 months ago

rust

switching on day#0 (function arg) seems to be correct. However, _is_bounds_checked fails due to arguments not being in defmap. This is similar to the problem of switching on global variables, which are not in the defmap either.