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

JavaScript API can't handle 64-bit integers #18

Closed
tyilo opened this issue Feb 18, 2015 · 4 comments
Closed

JavaScript API can't handle 64-bit integers #18

tyilo opened this issue Feb 18, 2015 · 4 comments

Comments

@tyilo
Copy link
Contributor

tyilo commented Feb 18, 2015

As Numbers in JavaScript are stored as doubles, they can't represent all 64-bit integers.

Problematic example:

$ cat > fail.c
#include <stdio.h>
#include <stdint.h>

uint64_t a = 0x8888888888888888;
uint64_t b = 0x8888888888888889;

int main(void) {
    printf("&a, a: 0x%p, %llu\n", &a, a);
    printf("&b, b: 0x%p, %llu\n", &b, b);
    getchar();

    return 0;
}
^D
$ cc fail.c -o fail
$ ./fail
&a, a: 0x0x108520020, 9838263505978427528
&b, b: 0x0x108520028, 9838263505978427529

(leave running)
$ frida-repl fail
Attaching...
>>> a = Memory.readU64(ptr(0x108520020))
9838263505978427000
>>> b = Memory.readU64(ptr(0x108520028))
9838263505978427000
>>> a == b
true

As you can see the JavaScript API thinks that the memory contents of a and b are the same, when they in fact differ by 1.

@oleavr
Copy link
Member

oleavr commented Feb 18, 2015

This is not a bug per se, as the ptr() constructor is not meant to be used with JavaScript Number as an argument when dealing with actual pointers. It's helpful if you want to stick an enum value into a pointer, but probably more confusing than useful. Maybe the issue here is that we should remove that option entirely. ptr() (alias for new NativePointer()) is meant to be used like this: ptr("0xdeadbeef").

@tyilo
Copy link
Contributor Author

tyilo commented Feb 18, 2015

The problem is not ptr it's the return value from Memory.readU64.
You can use Memory.readU64(ptr('0x108520020')) and Memory.readU64(ptr('0x108520028')) instead and you will still get the same output.

@oleavr
Copy link
Member

oleavr commented Feb 18, 2015

Ahh sorry I missed that part. You're absolutely right. Memory.readU64() / Memory.readS64() are fundamentally broken, they should not return Number objects.

@tyilo
Copy link
Contributor Author

tyilo commented Feb 21, 2015

Moved issue to frida-gum (frida/frida-gum#16)

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

No branches or pull requests

2 participants