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

64 bit constants are truncated to 32 bit on windows #333

Closed
rihi opened this issue Sep 13, 2023 · 3 comments · Fixed by #341
Closed

64 bit constants are truncated to 32 bit on windows #333

rihi opened this issue Sep 13, 2023 · 3 comments · Fixed by #341
Assignees
Labels
bug Something isn't working priority-high High priority issue

Comments

@rihi
Copy link
Collaborator

rihi commented Sep 13, 2023

When decompiling functions on windows, 64 bit constants are truncated to 32 bit.

This is caused by the following code in the backend:

SIGNED_FORMATS = {
8: lambda x: c_byte(x).value,
16: lambda x: c_short(x).value,
32: lambda x: c_int(x).value,
64: lambda x: c_long(x).value,
}
UNSIGNED_FORMATS = {
8: lambda x: c_ubyte(x).value,
16: lambda x: c_ushort(x).value,
32: lambda x: c_uint(x).value,
64: lambda x: c_ulong(x).value,

def _get_integer_literal_value(self, literal: expressions.Constant) -> int:
"""
Return the right integer value for the given type, assuming that the
re-compilation host has the same sizes as the decompilation host.
"""
if literal.type.is_signed:
if handler := self.SIGNED_FORMATS.get(literal.type.size, None):
return handler(literal.value)
elif literal.value < 0:
if handler := self.UNSIGNED_FORMATS.get(literal.type.size, None):
return handler(literal.value)
return literal.value

This code uses ctypes to normalize the constant values to their respective bit sizes, but erroneously assumes c_long/c_ulong to always be 64 bit in size. This is however platform dependent, as the c standard only guarantees the following minimum bit sizes: char: 8, short: 16, int: 16,, long: 32

@rihi
Copy link
Collaborator Author

rihi commented Sep 13, 2023

This should be easy to fix as soon as #318 is merged, because that pull request adds a new method normalize_int(v: int, size: int, signed: bool) -> int which could be reused here to replace the ctypes usage.

@rihi rihi added bug Something isn't working priority-high High priority issue labels Sep 13, 2023
@rihi rihi self-assigned this Sep 21, 2023
@rihi
Copy link
Collaborator Author

rihi commented Sep 21, 2023

/cib

@github-actions
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-high High priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant