-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
[Decompiler][Function Editor] Custom storage XMM registers are changed automatically by Ghidra to incorrect registers #7427
Comments
@CebbyS , I am very confused by your problem scenario description. Could you please provide a step-by-step procedure for reproducing the problem you are trying to describe. |
Hi, @ghidra1! Sorry, just now noticed the message. I will update the description for step by step to reproduce the issue I am having |
So I chaned the description and added the steps: Steps to reproduce
|
@CebbyS ,You would have produced multiple change transactions within the decompiler:
Did you try to undo both of these transactions? You only did a single undo. I suggest watching the param storage in the assembly listing for the function to see which of the two actions caused the storage to change since I was unable to trigger the storage change. If it was the param rename - you did not undo that first transaction. A local register variable declared at the function entry point (i.e., first use offset) will conflict with a parameter using the same storage. I would be curious to know what param storage changes are observed for the function in the assembly listing param/variable listing. Specifically, what param changes are observed when the local variable is renamed, and what changes are observed when the second commit action is performed. |
So what I did here:
What happened:
Sometimes, if I save the project with the changes performed - function parameter set to use XMM1_Qa register, close and reopen the project, the parameter once again is changed to use XMM2_Qa register. I cannot find the exact trigger point, I suspected the synchronization with the database, but I don't have a clue how to debug this problem. What I can tell, is that if I only work on this single function, without moving into another function, Ctrl+Z does not cause the issue anymore. And closing/reopening project either. |
While you are doing this in the decompiler I am most interested in seeing all the listed variables in the assembly listing rather than the operand field. I was hoping to see how the param storage was affected with each action. Still images of this block may help:
Unfortunately, the param storage display is off the top of the assembly listing. I wish I could pause your animation which is quite useful but everything happens so fast - my eyes can't see all the areas at once to see what is changing. I think I will need to see it first hand some how to troubleshoot. This is what I see/assume:
After these two changes you should have two things on the undo stack. Clicking the little down-arrow on the undo button should provide a general description of the transactions. Before doing your Ctrl-Z, could you verify on the Undo button what the undo descriptions are. The first undo should just be reverting the rename of the local hash variable and not affect the parameters in any way. I can't tell what is happening after the undo in your animation. Could you try simply doing an undo and redo after using the Function Editor without the local variable rename and see how that behaves. |
It would appear in my trying this that an Auto Analysis transaction is added in between the Rename Local Variable and the Edit Function transactions. It is possible that the auto-analysis made its own change if this is your case. You should check the parameter storage in the assembly listing after each step to see when it changes. |
The key to the problem is the interaction between the in_XMM1_Qa local variable and the parameter with the same storage. When you first started both the custom param storage and the local variable occupied the same storage. Was this initial state using custom storage for the parameter? Any chance you can copy all the bytes for the function (Copy Special... on selected function body -> Byte String). It may help to reproduce the situation - although unclear if it will be enough. |
Here is the byte string of the function: And I assume yes, it was the initial state, when the parameter occupied the same storage. As when the function originally was decompiled, XMM0 was considered to be local param with the prefix in_XMM0_... (Do not recall whether it was W, DW, QW) I have this project for ~4 years, so I have been working on it through several Ghidra versions, if it changes anything about the database, the way how the data/models/entities were stored then and now. |
@CebbyS , I can't click on any of your images anymore to view them - not sure why the fullsize got removed from GitHub. Kinda complicates things. |
I can't seem to get your exact situation to occur using your bytes. Is your binary x86 32 or 64-bit? Which compiler spec ID? I tried both but the decompilation differs too much. What happens if you delete and re-create the Function with the latest version of Ghidra? Doing this are you able to reproduce the problem? I also tried with 11.2.1 with no luck. I also puzzled why your Edit Function did not trigger an Auto Analysis transaction. |
Describe the bug
Ghidra does not automatically detect function arguments when they are passed through XMM registers. Such parameters have to be manually defined enabling custom storage for function definition. Example - doubles and floats can be passed through the XMM registers.
When the custom storage option is enabled and custom arguments are added with the storage pointing to XMM{N} registers, strange issue occurs - after performing local variable name changes, commiting parameters, performing undo operation (not immediately after changing function definition, but later). All XMM registers change with the following pattern:
It indicates that there is a bug for the register indexing/mapping
Steps to reproduce
Expected behavior
XMM registers should not be changed by when specified for function with custom storage enabled
Screenshots
![Image](https://private-user-images.githubusercontent.com/56877579/408120358-2ea2ad54-47f0-480c-b151-5681ab5e47d7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MjgzNTMsIm5iZiI6MTczOTUyODA1MywicGF0aCI6Ii81Njg3NzU3OS80MDgxMjAzNTgtMmVhMmFkNTQtNDdmMC00ODBjLWIxNTEtNTY4MWFiNWU0N2Q3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDEwMTQxM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWNmOTRhYmY2OTM1M2FkN2VjMjIyZGJjM2ExNmQ3NDhkMmQ0MjcwN2EzMDNiYzg2MzVmNjUwZmVhYTcxZmZiNjAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.bLuJP-_LPxYaMJJBx60Nqdg61AowXFMw8KtlYVYw4z8)
How the function definition should look like (Uses the XMM1_Qa register)
How it is retyped after performing operations (Changed to the XMM2_Qa register)
![Image](https://private-user-images.githubusercontent.com/56877579/408125081-6db777db-c4a6-4df1-8f06-b0ae0134c5f8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MjgzNTMsIm5iZiI6MTczOTUyODA1MywicGF0aCI6Ii81Njg3NzU3OS80MDgxMjUwODEtNmRiNzc3ZGItYzRhNi00ZGYxLThmMDYtYjBhZTAxMzRjNWY4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDEwMTQxM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPThkOGQ1NWMzNjA1YWJkNzRmMzRhNDExZWE0OWY2YTk5OGU2NzJmOTRmYWQ4MzFlMmJiNWQzYjgxNTgzNDI0NTMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.YRAtP0A-p04CkBwHcpd-SXE9B_iUT0ucK2OiPLzIlLw)
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: