Coder Social home page Coder Social logo

Comments (16)

Mystraht avatar Mystraht commented on May 28, 2024

I found why bug happen.

In memory.h, the type of the second parameter is DWORD instead of DWORD64.
It's why we cant pass number that is bigger than 32bits uint maximum value.

I fix it by replacing DWORD to DWORD64.

But we have another problem, in memoryjs.cc line 348, we get function argument with args[0]->Uint32Value() method, this break number that is bigger than 4294967295.

I'm not native C programmer so i quickfix that by adding 4294967296 to args[0]->Uint32Value()

int result = Memory.readMemory<int>(process::hProcess, 4294967296 + args[0]->Uint32Value());

This way i can handle 64 bits memory address

from memoryjs.

JaiPe avatar JaiPe commented on May 28, 2024

#14 Should help fix this?

from memoryjs.

LiamKarlMitchell avatar LiamKarlMitchell commented on May 28, 2024

Was there a better type to use that was sized depending on what it's compiled for.
DWORD_PTR or was it LPVOID but would need a way to transmit the x64 numbers through to native?

Is there really no Uint64Value methods?
Seems not... https://bugs.chromium.org/p/v8/issues/detail?id=1339
Mozilla have a draft idea on this though. https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/js-ctypes_reference/UInt64

We could pass parameters with buffers.
https://community.risingstack.com/using-buffers-node-js-c-plus-plus/

Or have the wrapper function pass an extra argument to flag it as an x64address then just internally in the native add the amount or subtract the amount.

Or by use of another module?
https://github.com/candu/node-int64-native

ffi gets around it by returning strings as double-precision floating point numbers are imprecise.
https://www.npmjs.com/package/ffi#v8-and-64-bit-types

A solution could also take into consideration if the methods should work with other architecture.
Undocumented methods also exist to read/write x64 from x86 but seems hacky....

from memoryjs.

karlrobertjanicki avatar karlrobertjanicki commented on May 28, 2024

I found out that uintptr_t is only part of the answer. https://github.com/Rob--/memoryjs/pull/14
After changing Uint32Value() to IntegerValue() in readMemory and DWORD to DWORD64 for the base address it was possible to get the correct values in 64 bit programs for pointers as well as for values.

from memoryjs.

karlrobertjanicki avatar karlrobertjanicki commented on May 28, 2024

You can see the changes in 3792f5d

from memoryjs.

Rob-- avatar Rob-- commented on May 28, 2024

@karlrobertjanicki awesome, it seems as though IntegerValue is the solution for 64 bit integers:

V8EXPORT uint32_t v8::Value::Uint32Value() const;
V8EXPORT int64_t v8::Value::IntegerValue() const;

In your fork you don't replace all instances of Uint32Value() with IntegerValue() though? Any time an address is passed from the Node.js user space to the add-on we should use IntegerValue() to access it. I will look into updating the library soon with the relevant fixes.

Thanks!

from memoryjs.

karlrobertjanicki avatar karlrobertjanicki commented on May 28, 2024

I didn't replace all the instances of Uint32Value() with IntegerValue() because I only used pointer, float and dword. Long story short: because of laziness ;)

from memoryjs.

Rob-- avatar Rob-- commented on May 28, 2024

@karlrobertjanicki added in 646eb28.
Hopefully the library will be much more 64 bit compatible. Soon I will add explicit types such as int32_t, uint32_t and int64_t. Right now, the library's int type is simply int32_t.

Also, there is no support for getting type uint64_t from v8::Value (but there is support for int64_t). One solution I've seen for this is getting the double value (NumberValue()) and casting it to uint64_t.

from memoryjs.

Rob-- avatar Rob-- commented on May 28, 2024

Closing for now, if there is still problems with 64 bit compatibility I will reopen the issue!

from memoryjs.

karlrobertjanicki avatar karlrobertjanicki commented on May 28, 2024

Thank you

from memoryjs.

karlrobertjanicki avatar karlrobertjanicki commented on May 28, 2024

One more thing. I think that the base address is only correct in 64 Bit addresses with:
https://github.com/karlrobertjanicki/memoryjs/blob/3792f5d44f465c09ce2d12f098d1eba26ed73fe5/lib/memoryjs.cc#L107
and
https://github.com/karlrobertjanicki/memoryjs/blob/3792f5d44f465c09ce2d12f098d1eba26ed73fe5/lib/module.cc#L17
DWORD64 did the trick.

from memoryjs.

Rob-- avatar Rob-- commented on May 28, 2024

@karlrobertjanicki addressed in abc9ee0.

from memoryjs.

karlrobertjanicki avatar karlrobertjanicki commented on May 28, 2024

Perfect :)

from memoryjs.

karlrobertjanicki avatar karlrobertjanicki commented on May 28, 2024

I have used memoryjs in a project. You can see the results on youtube
https://www.youtube.com/watch?v=gNiegwbILPg

from memoryjs.

Rob-- avatar Rob-- commented on May 28, 2024

@karlrobertjanicki Interesting project and awesome video!

from memoryjs.

karlrobertjanicki avatar karlrobertjanicki commented on May 28, 2024

Thank you. Without memoryjs this would not be possible. Awesome work

from memoryjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.