Skip to content

Commit

Permalink
Standardize the handling of the "cave_exec" breakpoint parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmlgc committed Aug 4, 2014
1 parent 2325832 commit c22be49
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions thcrap/src/breakpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ size_t* json_object_get_register(json_t *object, x86_reg_t *regs, const char *ke
return reg(regs, json_object_get_string(object, key));
}

int breakpoint_cave_exec_flag(json_t *bp_info)
{
return !json_is_false(json_object_get(bp_info, "cave_exec"));
}

BreakpointFunc_t breakpoint_func_get(const char *key)
{
BreakpointFunc_t ret = NULL;
Expand Down
6 changes: 6 additions & 0 deletions thcrap/src/breakpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ size_t* reg(x86_reg_t *regs, const char *regname);
// Returns a pointer to the register in [regs] specified by [key] in [object]
size_t* json_object_get_register(json_t *object, x86_reg_t *regs, const char *key);

// Returns 0 if "cave_exec" in [bp_info] is set to false, 1 otherwise.
// Should be used as the return value for a breakpoint function after it made
// changes to a register which could require original code to be skipped
// (since that code might overwrite the modified data otherwise).
int breakpoint_cave_exec_flag(json_t *bp_info);

// Looks up the breakpoint function for [key] in the list of exported functions.
// [key] is delimited by the first '#' character. This can be used to call a
// single breakpoint function at any number of points in the original code.
Expand Down
1 change: 1 addition & 0 deletions thcrap/thcrap.def
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ EXPORTS
; -----------
reg
json_object_get_register
breakpoint_cave_exec_flag
breakpoint_func_get
breakpoint_process
breakpoints_apply
Expand Down
6 changes: 2 additions & 4 deletions thcrap_tsa/src/spells.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ int BP_spell_name(x86_reg_t *regs, json_t *bp_info)
// Parameters
// ----------
const char **spell_name = (const char**)json_object_get_register(bp_info, regs, "spell_name");
json_t *cave_exec = json_object_get(bp_info, "cave_exec");
// ----------

// Other breakpoints
Expand All @@ -62,7 +61,7 @@ int BP_spell_name(x86_reg_t *regs, json_t *bp_info)

if(new_name) {
*spell_name = new_name;
return !json_is_false(cave_exec);
return breakpoint_cave_exec_flag(bp_info);
}
}
return 1;
Expand All @@ -75,7 +74,6 @@ int BP_spell_comment_line(x86_reg_t *regs, json_t *bp_info)
const char **str = (const char**)json_object_get_register(bp_info, regs, "str");
size_t comment_num = json_object_get_hex(bp_info, "comment_num");
size_t line_num = json_object_get_hex(bp_info, "line_num");
json_t *cave_exec = json_object_get(bp_info, "cave_exec");
// ----------

// Other breakpoints
Expand All @@ -101,7 +99,7 @@ int BP_spell_comment_line(x86_reg_t *regs, json_t *bp_info)

if(json_is_array(json_cmt)) {
*str = json_array_get_string_safe(json_cmt, line_num);
return !json_is_false(cave_exec);
return breakpoint_cave_exec_flag(bp_info);
}
}
return 1;
Expand Down

0 comments on commit c22be49

Please sign in to comment.