mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-23 06:14:53 +00:00
Add rabin2 -O e/new-entrypoint-address (ELF only atm)
This commit is contained in:
parent
6e0956f237
commit
666d457708
@ -334,6 +334,10 @@ static int rabin_do_operation(const char *op) {
|
||||
if (!output) output = file;
|
||||
|
||||
switch (arg[0]) {
|
||||
case 'e':
|
||||
rc = r_bin_wr_entry (bin, r_num_math (NULL, ptr));
|
||||
if (rc) rc = r_bin_wr_output (bin, output);
|
||||
break;
|
||||
case 'd':
|
||||
if (!ptr) goto _rabin_do_operation_error;
|
||||
switch (*ptr) {
|
||||
@ -578,6 +582,7 @@ int main(int argc, char **argv) {
|
||||
set_action (ACTION_OPERATION);
|
||||
if (isBinopHelp (op)) {
|
||||
printf ("Operation string:\n"
|
||||
" Change Entrypoint: e/0x8048000\n"
|
||||
" Dump symbols: d/s/1024\n"
|
||||
" Dump section: d/S/.text\n"
|
||||
" Resize section: r/.data/1024\n"
|
||||
|
@ -11,7 +11,7 @@ R_API ut64 r_bin_wr_scn_resize(RBin *bin, const char *name, ut64 size) {
|
||||
if (plugin && plugin->write && plugin->write->scn_resize) {
|
||||
return plugin->write->scn_resize (bin->cur, name, size);
|
||||
}
|
||||
return R_FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
R_API bool r_bin_wr_scn_perms(RBin *bin, const char *name, int perms) {
|
||||
@ -34,7 +34,16 @@ R_API bool r_bin_wr_rpath_del(RBin *bin) {
|
||||
|
||||
R_API int r_bin_wr_output(RBin *bin, const char *filename) {
|
||||
RBinFile *binfile = r_bin_cur (bin);
|
||||
if (!filename || !binfile || !binfile->buf) return R_FALSE;
|
||||
if (!filename || !binfile || !binfile->buf) return false;
|
||||
return r_file_dump (filename, binfile->buf->buf,
|
||||
binfile->buf->length, 0);
|
||||
}
|
||||
|
||||
R_API bool r_bin_wr_entry(RBin *bin, ut64 addr) {
|
||||
RBinFile *binfile = r_bin_cur (bin);
|
||||
RBinPlugin *plugin = r_bin_file_cur_plugin (binfile);
|
||||
if (plugin && plugin->write && plugin->write->entry) {
|
||||
return plugin->write->entry (bin->cur, addr);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -131,6 +131,7 @@ struct Elf_(r_bin_elf_obj_t)* Elf_(r_bin_elf_new)(const char* file);
|
||||
struct Elf_(r_bin_elf_obj_t)* Elf_(r_bin_elf_new_buf)(struct r_buf_t *buf);
|
||||
ut64 Elf_(r_bin_elf_resize_section)(struct Elf_(r_bin_elf_obj_t) *bin, const char *name, ut64 size);
|
||||
bool Elf_(r_bin_elf_section_perms)(struct Elf_(r_bin_elf_obj_t) *bin, const char *name, int perms);
|
||||
bool Elf_(r_bin_elf_entry_write)(struct Elf_(r_bin_elf_obj_t) *bin, ut64 addr);
|
||||
int Elf_(r_bin_elf_del_rpath)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
int Elf_(r_bin_elf_has_relro)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
int Elf_(r_bin_elf_has_nx)(struct Elf_(r_bin_elf_obj_t) *bin);
|
||||
|
@ -235,10 +235,22 @@ bool Elf_(r_bin_elf_section_perms)(struct Elf_(r_bin_elf_obj_t) *bin, const char
|
||||
patchoff += ((const ut8*)shdrp - (const ut8*)bin->shdr);
|
||||
patchoff += r_offsetof (Elf_(Shdr), sh_flags);
|
||||
printf ("wx %02x @ 0x%x\n", newperms, patchoff);
|
||||
eprintf ("PATCH %p\n", bin->b);
|
||||
r_buf_write_at (bin->b, patchoff, (ut8*)&newperms, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Elf_(r_bin_elf_entry_write)(struct Elf_(r_bin_elf_obj_t) *bin, ut64 addr) {
|
||||
int patchoff = 0x18;
|
||||
#if R_BIN_ELF64
|
||||
printf ("wv8 0x%"PFMT64x" @ 0x%x\n", addr, patchoff);
|
||||
eprintf ("%d\n", r_buf_write_at (bin->b, patchoff, (ut8*)&addr, sizeof (addr)));
|
||||
#else
|
||||
ut32 addr32 = (ut32)addr;
|
||||
printf ("wv4 0x%x @ 0x%x\n", addr32, patchoff);
|
||||
r_buf_write_at (bin->b, patchoff, (ut8*)&addr32, sizeof (addr32));
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2015 - pancake, nibble */
|
||||
/* radare - LGPL - Copyright 2009-2016 - pancake, nibble */
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_bin.h>
|
||||
@ -31,10 +31,20 @@ static int rpath_del(RBinFile *arch) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool chentry(RBinFile *arch, ut64 addr) {
|
||||
struct Elf_(r_bin_elf_obj_t) *obj = arch->o->bin_obj;
|
||||
int ret = Elf_(r_bin_elf_entry_write) (arch->o->bin_obj, addr);
|
||||
r_buf_free (arch->buf);
|
||||
arch->buf = obj->b;
|
||||
obj->b = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if !R_BIN_ELF64
|
||||
RBinWrite r_bin_write_elf = {
|
||||
.scn_resize = &scn_resize,
|
||||
.scn_perms = &scn_perms,
|
||||
.rpath_del = &rpath_del,
|
||||
.entry = &chentry,
|
||||
};
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2015 pancake, nibble */
|
||||
/* radare - LGPL - Copyright 2009-2016 pancake */
|
||||
|
||||
#define R_BIN_ELF64 1
|
||||
#include "bin_write_elf.c"
|
||||
@ -7,4 +7,5 @@ RBinWrite r_bin_write_elf64 = {
|
||||
.scn_resize = &scn_resize,
|
||||
.scn_perms = &scn_perms,
|
||||
.rpath_del = &rpath_del,
|
||||
.entry = &chentry,
|
||||
};
|
||||
|
@ -377,6 +377,7 @@ typedef struct r_bin_write_t {
|
||||
ut64 (*scn_resize)(RBinFile *arch, const char *name, ut64 size);
|
||||
bool (*scn_perms)(RBinFile *arch, const char *name, int perms);
|
||||
int (*rpath_del)(RBinFile *arch);
|
||||
bool (*entry)(RBinFile *arch, ut64 addr);
|
||||
} RBinWrite;
|
||||
|
||||
// TODO: deprecate r_bin_is_big_endian
|
||||
@ -506,6 +507,7 @@ R_API char *r_bin_addr2fileline(RBin *bin, ut64 addr);
|
||||
R_API ut64 r_bin_wr_scn_resize(RBin *bin, const char *name, ut64 size);
|
||||
R_API bool r_bin_wr_scn_perms(RBin *bin, const char *name, int perms);
|
||||
R_API bool r_bin_wr_rpath_del(RBin *bin);
|
||||
R_API bool r_bin_wr_entry(RBin *bin, ut64 addr);
|
||||
R_API int r_bin_wr_output(RBin *bin, const char *filename);
|
||||
R_API int r_bin_dwarf_parse_info(RBinDwarfDebugAbbrev *da, RBin *a, int mode);
|
||||
R_API RList *r_bin_dwarf_parse_line(RBin *a, int mode);
|
||||
|
Loading…
x
Reference in New Issue
Block a user