Fix host endian dependency in rz-gg
rz-gg -dDnN now always write numbers in little endian instead of depending on the host's endian, to fix tests on ppc. Making it target-dependent will require further refactoring (see comments).
This commit is contained in:
parent
7586b31523
commit
275b17bfee
3 changed files with 19 additions and 23 deletions
|
|
@ -588,6 +588,13 @@ RZ_API int rz_egg_patch(RzEgg *egg, int off, const ut8 *buf, int len) {
|
|||
return true;
|
||||
}
|
||||
|
||||
RZ_API bool rz_egg_patch_num(RzEgg *egg, int off, ut64 num, ut32 bits) {
|
||||
rz_return_val_if_fail(egg && bits <= 64, false);
|
||||
ut8 buf[8] = { 0 };
|
||||
rz_write_ble(buf, num, egg->endian, bits);
|
||||
return rz_egg_patch(egg, off, buf, bits / 8);
|
||||
}
|
||||
|
||||
RZ_API void rz_egg_finalize(RzEgg *egg) {
|
||||
struct egg_patch_t *ep;
|
||||
RzListIter *iter;
|
||||
|
|
|
|||
|
|
@ -218,6 +218,7 @@ RZ_API void rz_egg_append(RzEgg *egg, const char *src);
|
|||
RZ_API int rz_egg_run(RzEgg *egg);
|
||||
RZ_API int rz_egg_run_rop(RzEgg *egg);
|
||||
RZ_API int rz_egg_patch(RzEgg *egg, int off, const ut8 *b, int l);
|
||||
RZ_API bool rz_egg_patch_num(RzEgg *egg, int off, ut64 val, ut32 bits);
|
||||
RZ_API void rz_egg_finalize(RzEgg *egg);
|
||||
|
||||
/* rz_egg_Cfile.c */
|
||||
|
|
|
|||
|
|
@ -192,39 +192,27 @@ RZ_API int rz_main_rz_gg(int argc, const char **argv) {
|
|||
}
|
||||
free(arg);
|
||||
} break;
|
||||
case 'n': {
|
||||
ut32 n = rz_num_math(NULL, opt.arg);
|
||||
append = 1;
|
||||
rz_egg_patch(egg, -1, (const ut8 *)&n, 4);
|
||||
} break;
|
||||
case 'n':
|
||||
case 'N': {
|
||||
ut64 n = rz_num_math(NULL, opt.arg);
|
||||
rz_egg_patch(egg, -1, (const ut8 *)&n, 8);
|
||||
// TODO: support big endian too
|
||||
// (this is always little because rz_egg_setup is further below)
|
||||
rz_egg_patch_num(egg, -1, n, c == 'N' ? 64 : 32);
|
||||
append = 1;
|
||||
} break;
|
||||
case 'd': {
|
||||
ut32 off, n;
|
||||
char *p = strchr(opt.arg, ':');
|
||||
if (p) {
|
||||
*p = 0;
|
||||
off = rz_num_math(NULL, opt.arg);
|
||||
n = rz_num_math(NULL, p + 1);
|
||||
*p = ':';
|
||||
// TODO: honor endianness here
|
||||
rz_egg_patch(egg, off, (const ut8 *)&n, 4);
|
||||
} else {
|
||||
eprintf("Missing colon in -d\n");
|
||||
}
|
||||
} break;
|
||||
case 'd':
|
||||
case 'D': {
|
||||
char *p = strchr(opt.arg, ':');
|
||||
if (p) {
|
||||
*p = '\0';
|
||||
ut64 n, off = rz_num_math(NULL, opt.arg);
|
||||
*p = ':';
|
||||
n = rz_num_math(NULL, p + 1);
|
||||
// TODO: honor endianness here
|
||||
rz_egg_patch(egg, off, (const ut8 *)&n, 8);
|
||||
// TODO: support big endian too
|
||||
// (this is always little because rz_egg_setup is further below)
|
||||
rz_egg_patch_num(egg, off, n, c == 'D' ? 64 : 32);
|
||||
} else {
|
||||
eprintf("Missing colon in -d\n");
|
||||
eprintf("Missing colon in -%c\n", c);
|
||||
}
|
||||
} break;
|
||||
case 'S':
|
||||
|
|
|
|||
Loading…
Reference in a new issue