Skip to content

Fix uncaught exception when trying to retrieve negative addresses #3

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

Merged
merged 4 commits into from
Dec 7, 2018

Conversation

TETYYS
Copy link
Contributor

@TETYYS TETYYS commented Dec 7, 2018

No description provided.

@KN4CK3R
Copy link
Member

KN4CK3R commented Dec 7, 2018

Did you test a negative address intentional or how did you get this exception? Your patch doesn't fix the problem. Now you can't access offsets greater than int.MaxValue (2GB). I'm a little bit shocked that y and z are both negative...

var x = new IntPtr(-1);
var y = x.ToInt32();
var z = x.ToInt64();

I expected z to show a large number instead of -1.

@TETYYS
Copy link
Contributor Author

TETYYS commented Dec 7, 2018

I think I got the exception when the program tried to construct a BaseHexCommentNode, presumably dereferencing an address, my file is exactly 2,147,516,415 bytes in size.

@TETYYS
Copy link
Contributor Author

TETYYS commented Dec 7, 2018

I think the problem with this is that when pointer in IntPtr is 0x8000_0000, the ToInt64() operation does not cast bit-wise, resulting in same negative value

@TETYYS
Copy link
Contributor Author

TETYYS commented Dec 7, 2018

I think this should work. The plugin fails to read valid bytes if you try to read after the file, but that's a different issue, I think I saw 64 byte blocks hardcoded somewhere, this might be related to that.

stream.Read(buffer, 0, size);

return true;
}
using (var stream = info.File.CreateViewStream(address.ToInt64(), size))
Copy link
Member

Choose a reason for hiding this comment

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

Now you are missing the addressInt64 here.

@TETYYS
Copy link
Contributor Author

TETYYS commented Dec 7, 2018

There are some places in C# library methods I really wish that would just accept or provide unsigned values.

@KN4CK3R
Copy link
Member

KN4CK3R commented Dec 7, 2018

I will add a new extension method for IntPtr in the ReClass.NET project to make the logic reusable.

@KN4CK3R KN4CK3R merged commit d80c8fe into ReClassNET:master Dec 7, 2018
KN4CK3R added a commit that referenced this pull request Dec 14, 2018
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy