-
Notifications
You must be signed in to change notification settings - Fork 232
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
Is there a way to decode from byte stream? #517
Comments
Whats preventing you to fetch a bunch of bytes into a buffer and process that? Its usually the most efficient way to handle things (and actually what most stream implementations are doing anyways), so using a stream is just a wrapper around the buffered read concept, something you can easily implement yourself, and not providing any performance benefit on top of that. PS: I'm not related to this repo, just subscribed to it. |
@weltkante Thank you for your quick response:) From my experience dealing with emulated memory model, I cannot come up with an "easily"-implemented buffered reader of bytes in emulated memories. A I admit that the above explanation is hard to understand, I'm happy to explain any details I did not explain clearly. |
I don't think it'll solve your performance issues if you can't do bulk data transfers, but ignoring that it sounds like you could just implement [edit] thinking about, you didn't mention which language you're using, for C# the solution seems so obvious that you're probably using a different version of the API? |
Thank you for notifying me this API. Yes, StreamCodeReader is a perfect API for my problem. However, I'm using Rust, and the Rust version doesn't have such API. Strange... |
Yes it's not possible at the moment with the Rust version but something that's useful so will add it to my to do list. |
When implementing an emulator like QEMU (not KVM mode), there is a decoding stage where instructions are decoded to determine what to do with this instruction, and iced-x86 is the fastest decoder I have ever met, which is the best choice to do this work.
However, it is hard to extract a
&[u8]
slice which contains the instruction bytes in a common emulator's framework, where the memory itself is also emulated. Though we CAN access any address with any length by issuing emulated page faults and coping the memory values to a temp buffer, and I do know that x86 instruction has a max length (16 maybe?), it may be not a best practice to always get a slice of bytes with this maximum length, since there will always be some bytes unnecessary.In QEMU, its self-implemented instruction decoder (you can see it here) uses APIs like
x86_ldub_code
to get bytes to decode, which means "load unsigned byte in code section". This pattern may be more appropriate in this situation, and I wonder if iced-x86 could have a stream decoder which does the same thing, i.e., not directly access a slice, but call.next()
on an iterator ofu8
to get next byte or peek the next byte.The text was updated successfully, but these errors were encountered: