-
Notifications
You must be signed in to change notification settings - Fork 89
Support cs_disasm_iter #115
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
Conversation
This is a big improvement over the last PR. 😄 Overall, I like the approach of having separate type to "own" the I have some comments that I will make in-line. |
I just pushed a fix (#116) for the GitHub action failure; please rebase to the current |
Codecov Report
@@ Coverage Diff @@
## master #115 +/- ##
=======================================
Coverage 94.90% 94.90%
=======================================
Files 22 22
Lines 2670 2670
=======================================
Hits 2534 2534
Misses 136 136
Continue to review full report at Codecov.
|
I would prefer to create a rust-style Iterator that wraps the |
See issue #1 and pr #115. Co-authored-by: denis <[email protected]> Co-authored-by: @HanabishiRecca
Benchmarking result on i9-14900K:
|
/// | ||
/// If `cs_malloc` failed due to OOM, [`Err(Error::OutOfMemory)`](Error::OutOfMemory) is returned. | ||
pub fn disasm_iter<'a, 'b>( | ||
&'a self, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use lifetime names cs
/buf
like below to make this more clear
code: &'b [u8], | ||
addr: u64, | ||
) -> CsResult<DisasmIter<'a, 'b>> { | ||
let insn = unsafe { cs_malloc(self.csh()) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid reallocating on each call to disasm_iter()
we could have a new type (e.g. "DisasBuffer") that contains the underlying buffer. Callers would pass in the "buffer" which would let them amortize the cost of the allocations by only doing it once.
Since this would be more complicated, we should create a new method and also have the simpler interface.
/// # Errors | ||
/// | ||
/// If `cs_malloc` failed due to OOM, [`Err(Error::OutOfMemory)`](Error::OutOfMemory) is returned. | ||
pub fn disasm_iter<'a, 'b>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that this disasm_iter()
is more efficient than disasm_all()
and has the same interface, we should delete disasm_all()
/disasm_count()
/disasm()
and only keep disasm_iter()
as written.
We can simplify the naming by renaming disasm_iter()
to just disasm()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea!
There is a problem, though: for Therefore, we must either:
Performance of the
In summary, the current |
What do you think about this API?