-
Notifications
You must be signed in to change notification settings - Fork 104
Fix XrefScanUtilFinder for 32 bit games #222
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
base: master
Are you sure you want to change the base?
Conversation
It tried to convert IPRelativeMemoryAddress to IntPtr and that caused OverflowExceptions on 32 bit games when the value exceeded int.MaxValue.
| instruction.Op1Kind == OpKind.Memory && instruction.IsIPRelativeMemoryOperand) | ||
| { | ||
| var movTarget = (IntPtr)instruction.IPRelativeMemoryAddress; | ||
| var movTarget = new IntPtr(unchecked((long)instruction.IPRelativeMemoryAddress)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this fix the problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly. Why does this not throw too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It converts the ulong to a long with unchecked wrapping, then creates a new IntPtr
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/checked-and-unchecked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only ways I see that not throwing is either:
- The
ulongvalue is less than or equal toint.MaxValue. - The
ulongvalue is greater thanulong.MaxValue + int.MinValue.
Is it guaranteed to be in these ranges?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yea your right I apologize. I believe this would work without throwing
IntPtr movTarget;
if (Environment.Is64BitProcess) movTarget = address <= long.MaxValue ? new IntPtr((long)address) : new IntPtr(unchecked((long)address));
else movTarget = address <= int.MaxValue ? new IntPtr((int)address) : new IntPtr(unchecked((int)address));
| if (Environment.Is64BitProcess) return address <= long.MaxValue ? new IntPtr((long)address) : new IntPtr(unchecked((long)address)); | ||
| else return address <= int.MaxValue ? new IntPtr((int)address) : new IntPtr(unchecked((int)address)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just return unchecked((IntPtr)address);
However, dropping the upper 32 bits seems like a massive bug. Did you actually verify that this works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes would you like a clip?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm extremely hesitant to merge this kind of change. I want a review by one of the other maintainers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright thank you that's fine, let me know if you need anything from me. My apologies I was bad at explaining
Co-authored-by: Jeremy Pritts <49847914+ds5678@users.noreply.github.com>
Co-authored-by: Jeremy Pritts <49847914+ds5678@users.noreply.github.com>
Co-authored-by: Jeremy Pritts <49847914+ds5678@users.noreply.github.com>
|
Hey, did all the requested changes go through? I think I accepted them all but it still says 1 requested change |
It appears so. |
|
Alright thank you |

It tried to convert IPRelativeMemoryAddress to IntPtr and that caused OverflowException on 32 bit games when the value exceeded int.MaxValue.