Skip to content

Conversation

@Dustin21335
Copy link

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

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));
Copy link
Collaborator

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?

Copy link
Author

Choose a reason for hiding this comment

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

image

Copy link
Collaborator

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?

Copy link
Author

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

Copy link
Collaborator

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 ulong value is less than or equal to int.MaxValue.
  • The ulong value is greater than ulong.MaxValue + int.MinValue.

Is it guaranteed to be in these ranges?

Copy link
Author

@Dustin21335 Dustin21335 Jul 30, 2025

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));

Comment on lines 100 to 101
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));
Copy link
Collaborator

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?

Copy link
Author

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?

Copy link
Collaborator

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.

Copy link
Author

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

@ds5678 ds5678 requested a review from js6pak July 30, 2025 06:34
Dustin21335 and others added 3 commits July 30, 2025 03:08
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>
@Dustin21335
Copy link
Author

Hey, did all the requested changes go through? I think I accepted them all but it still says 1 requested change

@ds5678
Copy link
Collaborator

ds5678 commented Jul 30, 2025

Hey, did all the requested changes go through? I think I accepted them all but it still says 1 requested change

It appears so.

@Dustin21335
Copy link
Author

Alright thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants