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
Provide an api to get raw data pointer from ArrayBuffer? #320
Comments
can't you use type arrays like this? new Uint8Array(bytes)[0]=0xff |
You basically have no idea what I was talking about |
nope you're probably right. but I guess the ticket was not clear. It looked like you are trying to read from an ArrayBuffer. That's how you read/write to an array buffer. |
@ChiChou Hmm, would adding a Memory.sharedByteArray() that returns a SharedArrayBuffer work for your use case? |
@Manouchehri Thanks a lot! |
@Manouchehri @oleavr Oh wait. This is not what I mean. I know nothing about internal implementation of v8 and Duktape (otherwise I'll submit a PR) but I guess there must be a vector in the backing store of an ArrayBuffer. What I need is to get the raw pointer of this continuous storage. If that's not clear, I mean something like |
@ChiChou That's I also landed @Manouchehri's PR in eec44a1, which is a different thing: when you want to wrap an |
A few ideas:
|
Yeah that works! Though an ArrayBuffer has different semantic to a pointer, but in most cases that a native function accepts a pointer and the length of buffer, this works perfectly. So now the problem is how much the difference matters for frida scripts.
|
Anyway thank you for your reply. I've updated the thread for less confusion |
One vote for |
@ChiChou Thanks! The only advantage of the implementation in current And you have a good point regarding I do like the "purer" nature of a separate function though. Hmm. Will need to sleep on this. |
How about:
So our current |
Hmm, leaning more towards |
Some more ideas: ptr(buf: ArrayBuffer): NativePointer;
p.castToBuffer(size: number): ArrayBuffer;
p.toLiveBuffer(size: number): ArrayBuffer;
p.toVolatileBuffer(size: number): ArrayBuffer;
p.toArrayBuffer(size: number): ArrayBuffer; |
And a few more: ArrayBuffer.wrap(address: NativePointer, size: number): ArrayBuffer;
ArrayBuffer.prototype.unwrap(): NativePointer; ArrayBuffer.fromLiveMemory(address: NativePointer, size: number): ArrayBuffer;
// ArrayBuffer.fromMemoryNoCopy(address: NativePointer, size: number): ArrayBuffer;
ArrayBuffer.prototype.getBaseAddress(): NativePointer; |
Think I'm going for these unless anyone has any objections: ArrayBuffer.wrap(address: NativePointer, size: number): ArrayBuffer;
ArrayBuffer.prototype.unwrap(): NativePointer; |
Cool! |
Some api only returns ArrayBuffer (like
frida-fs
).When I have to pass them to ffi, looks like the best way is
That is an unnecessary extra
memcpy
.Update: What I mean is something like
std::string::data
in C++.The text was updated successfully, but these errors were encountered: