Coder Social home page Coder Social logo

Read/Write buffer. about memoryjs HOT 7 CLOSED

rob-- avatar rob-- commented on May 27, 2024
Read/Write buffer.

from memoryjs.

Comments (7)

LiamKarlMitchell avatar LiamKarlMitchell commented on May 27, 2024

Note: I'm happy to implement this should I need it, will see how I go.

from memoryjs.

RiftLurker avatar RiftLurker commented on May 27, 2024

Do I understand it correctly that this would allow me to read/write generic structs from and to memory just like the vector types?
If this is the case I would very much like to see this in a future version, as it's exactly what I'm gonna need for a project of mine.

from memoryjs.

p410n3 avatar p410n3 commented on May 27, 2024

Yes. I think he already did it if I understood his email correctly.

from memoryjs.

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

@LiamKarlMitchell to write generic structs to memory we could always just create a helper function inside the library?

// Method 1: the `value` arg contains the details (if struct data type varies):
const vector = [{
    type: memoryjs.FLOAT,
    data: 1.23,
}, {
    type: memoryjs.FLOAT,
    data: 4.56,
}, {
    type: memoryjs.INT,
    data: 420,
}];
memoryjs.writeMemory(handle, address, vector);

// Method 2: if struct data type doesn't vary:
const vector = [1.23, 4.56, 7.89];
memoryjs.writeMemory(handle, address, vector, memoryjs.FLOAT);

And inside writeMemory we do a check to see if the value is an object, in which case we know it's a struct and iterate over the array:

let offset = 0x0;
value.forEach(({ type, data }) => {
    memoryjs.writeMemory(handle, address + offset, data, type.toLowerCase());
    
    if (type === memoryjs.FLOAT) offset += 0x4;
    // etc, offset could be optionally defined by the `value` param
});

Another solution is to just use a library like node-struct and let people manually form an actual buffer themselves and then we can just write that to memory directly. I don't know too much about buffers so just let me know if I'm overthinking here or if there's a simpler solution!

from memoryjs.

LiamKarlMitchell avatar LiamKarlMitchell commented on May 27, 2024

You could yes.

I've used concentrate and dissolve modules for a project in the past.
https://github.com/deoxxa/concentrate

Found it easier to add own/new data types to them.
Also made a script to turn .h struct into .js files which made it easy :)

from memoryjs.

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

v.3.1.0: reading/writing of buffers added in c009eed

For information about writing or reading structures, refer to the generic structures section of the readme.

Functions added:
readBuffer(handle, address, size[, callback])
writeBuffer(handle, address, buffer)

@LiamKarlMitchell I've added a buffer read/write example here. Hopefully this is what you and @PostCrafter were looking for!

If you're happy to share your script here I'm sure others would find it useful :)

from memoryjs.

LiamKarlMitchell avatar LiamKarlMitchell commented on May 27, 2024

Great stuff thanks @Rob--

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.