binaryninja-api icon indicating copy to clipboard operation
binaryninja-api copied to clipboard

Copying a basic block and modifying its predecessor's branch targets can cause confusion in the mapping of instructions to basic blocks.

Open mFallW1nd opened this issue 1 year ago • 0 comments

Version and Platform (required):

  • Binary Ninja Version: 4.1.5902-stable
  • OS: MacOS
  • OS Version: 14.5
  • CPU Architecture: M2

Bug Description: First of all, my purpose is: at 0x26ef0 in the main function of the sample, there is a common sub-basic block (perhaps it should be called a common sub-expression). I want to copy this basic block to each of its predecessor basic blocks, thereby eliminating this "common sub-basic block". image To this end, I developed a simple workflow plug-in. In the main function, execute Plugin->Optimizer->Propagate the Common Sub-BasicBlock (test) to achieve the above functions. The execution results are as follows. Judging from the CFG alone, the effect of the workflow is in line with expectations. image But if you try to use current_il_instruction.il_basic_block on an instruction in the copied basic block, you will get a strange error like the following: image However, in the SSA form, everything is normal again. image This is my sample and workflow plugin source code. The binja version I use is 4.1.5902-stable

Steps To Reproduce: Please provide all steps required to reproduce the behavior:

  1. Compile the block_propagate workflow
  2. Go to the "main" function, Go to address 0x26ef0
  3. Run Plugin->Optimizer->Propagate the Common Sub-BasicBlock (test)
  4. Execute current_il_instruction.il_basic_block for the copied block's instruction
  5. See error

Expected Behavior: Please provide a clear and concise description of what you expected to happen.

Screenshots/Video Recording: If applicable, please add screenshots/video recording here to help explain your problem.

Binary: If applicable, please provide us with the binary to help us work with the issue faster. Here are a few options: sock1_unpacked (1).zip

Workflow Source Code block_propagate.zip

  1. Directly attach it to this issue in a ZIP archive
  2. Share a publicly accessible link to it (For malware samples, we do not have access to VirusTotal; Malshare is an option)
  3. Email it to binaryninja at vector35.com, or join our slack and share with us in private
  4. We understand sometimes it is not possible to share the binary -- sure, no worries, we can still work with it!
  5. If your issue is general and not related to a specific binary, then there is no need to attach the binary as well

Additional Information: Please add any other context about the problem here.

mFallW1nd avatar Sep 05 '24 02:09 mFallW1nd