Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PPC] Fix #2401 - incorrect operands in disassembled instructions #2403

Merged
merged 1 commit into from
Jul 24, 2024

Conversation

valdaarhun
Copy link
Contributor

@valdaarhun valdaarhun commented Jul 21, 2024

Your checklist for this pull request

  • I've documented or updated the documentation of every API function and struct this PR changes.
  • I've added tests that prove my fix is effective or that my feature works (if possible)

Detailed description

Disassembling the "slwi", "srwi" and "rldicr" PowerPC instructions with the "-d" option displays the wrong operands in detailed information. This is due to an incorrect break condition in PPC_insert_detail_op_imm_at()

Test plan

  • Before applying the fix:
$ cstool -d ppc32be 786226e4
 0  78 62 26 e4  sldi   r2, r3, 4
        ID: 868 (rldicr)
        Is alias: 2329 (sldi) with ALIAS operand set
        op_count: 3
                operands[0].type: REG = r2
                operands[0].access: WRITE
                operands[1].type: REG = r2
                operands[1].access: WRITE
                operands[2].type: IMM = 0x4
                operands[2].access: READ
  • After applying the fix:
$ cstool -d ppc32be 786226e4
 0  78 62 26 e4  sldi   r2, r3, 4
        ID: 868 (rldicr)
        Is alias: 2329 (sldi) with ALIAS operand set
        op_count: 3
                operands[0].type: REG = r2
                operands[0].access: WRITE
                operands[1].type: REG = r3
                operands[1].access: READ
                operands[2].type: IMM = 0x4
                operands[2].access: READ

Please let me know if this should be added in the testsuite too. I am not sure how one does that.

Closing issues

closes #2401

@github-actions github-actions bot added the PowerPC Arch label Jul 21, 2024
@valdaarhun valdaarhun changed the title [PPC] Fix #2401 - incorrect operand in disassembled instruction [PPC] Fix #2401 - incorrect operands in disassembled instructions Jul 21, 2024
@Rot127
Copy link
Collaborator

Rot127 commented Jul 21, 2024

Thanks a lot! I check it tomorrow. But you can add a test case in the issue.cs file. The one in <repo-root>/tests/cs_detail/. Just do it as the other tests there.

@valdaarhun
Copy link
Contributor Author

Thanks a lot! I check it tomorrow. But you can add a test case in the issue.cs file. The one in <repo-root>/tests/cs_detail/. Just do it as the other tests there.

Hi, thank you for your reply. I have added three test cases to issue.cs.

Disassembling the "slwi", "srwi" and "rldicr" PowerPC instructions
with the "-d" option displays the wrong operands in the detailed
view. This is due to an incorrect break condition in the
"PPC_insert_detail_op_imm_at" function.

This patch fixes capstone-engine#2401.
Copy link
Member

@kabeor kabeor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, Thanks for your contribution.

@kabeor kabeor merged commit 4f964a2 into capstone-engine:next Jul 24, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PowerPC instruction alias slwi and srwi have incorrect 2nd operand in detailed information
3 participants