-
-
Notifications
You must be signed in to change notification settings - Fork 356
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
RzIL: add aezsue
to support Step until PC equals given address and output VM changes
#4466
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,17 +228,20 @@ RZ_API bool rz_analysis_il_vm_sync_to_reg(RzAnalysisILVM *vm, RZ_NONNULL RzReg * | |
return rz_il_vm_sync_to_reg(vm->vm, vm->reg_binding, reg); | ||
} | ||
|
||
/** | ||
* Repeatedly perform steps in the VM until the condition callback returns false | ||
* | ||
* If given, this syncs the contents of \p reg into the vm. | ||
* Then it repeatedly disassembles an instruction at the program counter of the vm and executes it as long as cond() returns true. | ||
* Finally the contents are optionally synced back to \p reg. | ||
* | ||
* \return and indicator for which error occured, if any, or RZ_ANALYSIS_IL_STEP_RESULT_SUCCESS if cond() returned false | ||
*/ | ||
RZ_API RzAnalysisILStepResult rz_analysis_il_vm_step_while(RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnalysisILVM *vm, RZ_NULLABLE RzReg *reg, | ||
bool (*cond)(RzAnalysisILVM *vm, void *user), void *user) { | ||
static void il_events(RzILVM *vm, RzStrBuf *sb) { | ||
void **it; | ||
rz_pvector_foreach (vm->events, it) { | ||
RzILEvent *evt = *it; | ||
rz_il_event_stringify(evt, sb); | ||
rz_strbuf_append(sb, "\n"); | ||
} | ||
} | ||
|
||
typedef bool (*cond_callback)(RzAnalysisILVM *vm, void *user); | ||
|
||
static RzAnalysisILStepResult analysis_il_vm_step_while( | ||
RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnalysisILVM *vm, RZ_NULLABLE RzReg *reg, | ||
bool with_events, RZ_NONNULL cond_callback cond, RZ_NULLABLE void *user) { | ||
|
||
rz_return_val_if_fail(analysis && vm, false); | ||
RzAnalysisPlugin *cur = analysis->cur; | ||
|
@@ -257,14 +260,30 @@ RZ_API RzAnalysisILStepResult rz_analysis_il_vm_step_while(RZ_NONNULL RzAnalysis | |
analysis->read_at(analysis, addr, code, sizeof(code)); | ||
RzAnalysisOp op = { 0 }; | ||
rz_analysis_op_init(&op); | ||
int r = rz_analysis_op(analysis, &op, addr, code, sizeof(code), RZ_ANALYSIS_OP_MASK_IL | RZ_ANALYSIS_OP_MASK_HINT); | ||
int r = rz_analysis_op(analysis, &op, addr, code, sizeof(code), RZ_ANALYSIS_OP_MASK_IL | RZ_ANALYSIS_OP_MASK_HINT | RZ_ANALYSIS_OP_MASK_DISASM); | ||
RzILOpEffect *ilop = r < 0 ? NULL : op.il_op; | ||
|
||
if (ilop) { | ||
bool succ = rz_il_vm_step(vm->vm, ilop, addr + (op.size > 0 ? op.size : 1)); | ||
if (!succ) { | ||
res = RZ_ANALYSIS_IL_STEP_IL_RUNTIME_ERROR; | ||
} | ||
|
||
if (with_events) { | ||
RzStrBuf sb; | ||
rz_strbuf_init(&sb); | ||
rz_il_op_effect_stringify(op.il_op, &sb, true); | ||
rz_strbuf_append(&sb, "\n"); | ||
il_events(vm->vm, &sb); | ||
|
||
char *il_stmt = rz_strbuf_get(&sb); | ||
rz_cons_printf("0x%llx [%x%x%x%x] %s\n" | ||
"0x%llx %s\n", | ||
addr, code[0], code[1], code[2], code[3], | ||
op.mnemonic, addr, il_stmt); | ||
rz_strbuf_fini(&sb); | ||
} | ||
|
||
pelijah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
res = RZ_ANALYSIS_IL_STEP_INVALID_OP; | ||
} | ||
|
@@ -280,6 +299,53 @@ RZ_API RzAnalysisILStepResult rz_analysis_il_vm_step_while(RZ_NONNULL RzAnalysis | |
return res; | ||
} | ||
|
||
/** | ||
* \brief Repeatedly perform steps in the VM until the \p cond callback returns false | ||
* | ||
* \param analysis Pointer to an RzAnalysis struct, likely representing the analysis context. | ||
* \param vm Pointer to an RzAnalysisILVM struct, representing the IL virtual machine to be stepped. | ||
* \param reg Optional pointer to an RzReg struct, potentially holding register values to be used during the step. | ||
* \param cond Pointer to a function that determines the loop's continuation condition. This function takes two arguments: | ||
* * vm: Pointer to the same RzAnalysisILVM struct passed to rz_analysis_il_vm_step_while. | ||
* * user: Pointer to user-provided data that can be used by the condition function. | ||
* \param user Pointer to user-defined data that can be passed to the condition function. | ||
* | ||
* \return RZ_ANALYSIS_IL_STEP_RESULT: Enumeration value indicating the outcome of the stepping operation. | ||
* Possible values (implementation specific): | ||
* - RZ_ANALYSIS_IL_STEP_OK: Successful execution of the while loop step. | ||
* - RZ_ANALYSIS_IL_STEP_ERROR: Encountered an error during execution. | ||
* - RZ_ANALYSIS_IL_STEP_INVALID: Invalid arguments or state resulted in undefined behavior. | ||
*/ | ||
RZ_API RzAnalysisILStepResult rz_analysis_il_vm_step_while( | ||
RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnalysisILVM *vm, RZ_NULLABLE RzReg *reg, | ||
RZ_NONNULL cond_callback cond, RZ_NULLABLE void *user) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
return analysis_il_vm_step_while(analysis, vm, reg, false, cond, user); | ||
} | ||
|
||
/** | ||
* \brief Repeatedly perform steps in the VM until the \p cond callback returns false | ||
* and output VM changes (read & write) | ||
* | ||
* \param analysis Pointer to an RzAnalysis struct, likely representing the analysis context. | ||
* \param vm Pointer to an RzAnalysisILVM struct, representing the IL virtual machine to be stepped. | ||
* \param reg Optional pointer to an RzReg struct, potentially holding register values to be used during the step. | ||
* \param cond Pointer to a function that determines the loop's continuation condition. This function takes two arguments: | ||
* * vm: Pointer to the same RzAnalysisILVM struct passed to rz_analysis_il_vm_step_while. | ||
* * user: Pointer to user-provided data that can be used by the condition function. | ||
* \param user Pointer to user-defined data that can be passed to the condition function. | ||
* | ||
* \return RZ_ANALYSIS_IL_STEP_RESULT: Enumeration value indicating the outcome of the stepping operation. | ||
* Possible values (implementation specific): | ||
* - RZ_ANALYSIS_IL_STEP_OK: Successful execution of the while loop step. | ||
* - RZ_ANALYSIS_IL_STEP_ERROR: Encountered an error during execution. | ||
* - RZ_ANALYSIS_IL_STEP_INVALID: Invalid arguments or state resulted in undefined behavior. | ||
*/ | ||
RZ_API RzAnalysisILStepResult rz_analysis_il_vm_step_while_with_events( | ||
RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnalysisILVM *vm, RZ_NULLABLE RzReg *reg, | ||
RZ_NONNULL cond_callback cond, RZ_NULLABLE void *user) { | ||
return analysis_il_vm_step_while(analysis, vm, reg, true, cond, user); | ||
} | ||
|
||
static bool step_cond_once(RzAnalysisILVM *vm, void *user) { | ||
bool *stepped = user; | ||
if (*stepped) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Move it outside
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.
I don't get it. It seems to me that
rz_analysis_op_init
needs to be called before every call torz_analysis_op
andrz_analysis_op_fini
needs to be called after every call torz_analysis_op
.So ‘Move it outside’ doesn't work? @pelijah
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.
Weird,
rz_analysis_op_fini()
doesn't work as expected so leave it as is.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.
@XVilka We definetely should standardize
*_fini()
APIs behaviour.