mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-28 15:41:38 +00:00
* r_bin_elf
- Fixed error opening "sstripped" elfs * r_asm - Added r_asm_massemble Assemble several instructions separated by ';' * rasm2 - Updated assembly using r_asm_massemble * core - Updated 'wa' cmd using r_asm_massemble
This commit is contained in:
parent
8744e9f86a
commit
38b47d2481
@ -134,3 +134,37 @@ R_API int r_asm_assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, const char
|
||||
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
R_API int r_asm_massemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
|
||||
{
|
||||
char *lbuf=NULL, *ptr = NULL, *tokens[1024], buf_hex[1024];
|
||||
u8 buf_bin[1024];
|
||||
int ret, idx, ctr, i, j;
|
||||
|
||||
if (buf == NULL)
|
||||
return 0;
|
||||
lbuf = strdup(buf);
|
||||
|
||||
for (tokens[0] = lbuf, ctr = 0;
|
||||
(ptr = strchr(tokens[ctr], ';'));
|
||||
tokens[++ctr] = ptr+1)
|
||||
*ptr = '\0';
|
||||
|
||||
for (ret = idx = i = 0, *buf_hex='\0'; i <= ctr; i++, idx+=ret) {
|
||||
r_asm_set_pc(a, a->pc + ret);
|
||||
ret = r_asm_assemble(a, aop, tokens[i]);
|
||||
if (ret) {
|
||||
for (j = 0; j < ret; j++)
|
||||
buf_bin[idx+j] = aop->buf[j];
|
||||
strcat(buf_hex, aop->buf_hex);
|
||||
} else {
|
||||
fprintf(stderr, "invalid\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(aop->buf, buf_bin, 1024);
|
||||
memcpy(aop->buf_hex, buf_hex, 1024);
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
@ -73,8 +73,7 @@ static int rasm_disasm(char *buf, u64 offset, u64 len, int ascii, int bin)
|
||||
static int rasm_asm(char *buf, u64 offset, u64 len, int bin)
|
||||
{
|
||||
struct r_asm_aop_t aop;
|
||||
char *ptr = NULL, *tokens[1024];
|
||||
int ret, idx, ctr, i, j;
|
||||
int ret, idx, i;
|
||||
|
||||
#if 0
|
||||
/* TODO: Arch, syntax... */
|
||||
@ -84,31 +83,19 @@ static int rasm_asm(char *buf, u64 offset, u64 len, int bin)
|
||||
}
|
||||
#endif
|
||||
|
||||
for (tokens[0] = buf, ctr = 0;
|
||||
(ptr = strchr(tokens[ctr], ';'));
|
||||
tokens[++ctr] = ptr+1)
|
||||
*ptr = '\0';
|
||||
|
||||
for (ret = idx = i = 0; i <= ctr; i++, idx+=ret) {
|
||||
r_asm_set_pc(&a, offset + idx);
|
||||
ret = r_asm_assemble(&a, &aop, tokens[i]);
|
||||
if (ret) {
|
||||
r_asm_set_pc(&a, offset);
|
||||
idx = r_asm_massemble(&a, &aop, buf);
|
||||
if (bin)
|
||||
for (j = 0; j < ret; j++)
|
||||
printf("%c", aop.buf[j]);
|
||||
for (i = 0; i < idx; i++)
|
||||
printf("%c", aop.buf[i]);
|
||||
else printf("%s\n", aop.buf_hex);
|
||||
} else {
|
||||
fprintf(stderr, "invalid\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (ret = 0; idx < len; idx+=ret) {
|
||||
ret = r_asm_assemble(&a, &aop, "nop");
|
||||
if (ret) {
|
||||
if (bin)
|
||||
for (j = 0; j < ret; j++)
|
||||
printf("%c", aop.buf[j]);
|
||||
for (i = 0; i < ret; i++)
|
||||
printf("%c", aop.buf[i]);
|
||||
else printf("%s", aop.buf_hex);
|
||||
} else {
|
||||
fprintf(stderr, "invalid\n");
|
||||
|
@ -288,10 +288,5 @@ u64 r_bin_get_section_size(struct r_bin_t *bin, char *name)
|
||||
int r_bin_get_libs()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int r_bin_get_strings()
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
|
@ -319,12 +319,13 @@ static int ELF_(r_bin_elf_init)(ELF_(r_bin_elf_obj) *bin)
|
||||
|
||||
if (lseek(bin->fd, strtabhdr->sh_offset, SEEK_SET) != strtabhdr->sh_offset) {
|
||||
perror("lseek");
|
||||
return -1;
|
||||
//return -1;
|
||||
}
|
||||
|
||||
if (read(bin->fd, bin->string, strtabhdr->sh_size) != strtabhdr->sh_size) {
|
||||
perror("read");
|
||||
return -1;
|
||||
ERR("Warning: Cannot read strtabhdr.\n");
|
||||
//return -1;
|
||||
}
|
||||
|
||||
bin->bss = -1;
|
||||
@ -703,6 +704,7 @@ int ELF_(r_bin_elf_is_big_endian)(ELF_(r_bin_elf_obj) *bin)
|
||||
|
||||
/* TODO: Take care of endianess */
|
||||
/* TODO: Real error handling */
|
||||
/* TODO: Resize sections before .init */
|
||||
u64 ELF_(r_bin_elf_resize_section)(ELF_(r_bin_elf_obj) *bin, const char *name, u64 size)
|
||||
{
|
||||
ELF_(Ehdr) *ehdr = &bin->ehdr;
|
||||
|
@ -628,16 +628,15 @@ static int cmd_write(void *data, const char *input)
|
||||
int ret = 0;
|
||||
struct r_asm_aop_t aop;
|
||||
char buf[128];
|
||||
r_asm_set_pc(&core->assembler, core->seek);
|
||||
/* XXX ULTRAUGLY , needs fallback support in rasm */
|
||||
r_asm_set(&core->assembler, "asm_x86_olly");
|
||||
r_asm_set_pc(&core->assembler, core->seek);
|
||||
if (input[1]==' ')input=input+1;
|
||||
if (strchr(input, ';')) {
|
||||
eprintf("TODO: No support for ';' multiple opcodes yet\n");
|
||||
}
|
||||
ret = r_asm_assemble(&core->assembler, &aop, input+1);
|
||||
ret = r_asm_massemble(&core->assembler, &aop, input+1);
|
||||
eprintf("Written %d bytes (%s)=wx %s\n", ret, input+1, aop.buf_hex);
|
||||
r_core_write_at(core, core->seek, aop.buf, ret);
|
||||
r_core_block_read(core, 0);
|
||||
r_asm_set(&core->assembler, "asm_x86"); /* XXX */
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
|
@ -15,10 +15,10 @@ enum {
|
||||
|
||||
struct r_asm_aop_t {
|
||||
int inst_len;
|
||||
u8 buf[256];
|
||||
char buf_asm[256];
|
||||
char buf_hex[256];
|
||||
char buf_err[256];
|
||||
u8 buf[1024];
|
||||
char buf_asm[1024];
|
||||
char buf_hex[1024];
|
||||
char buf_err[1024];
|
||||
void *disasm_obj;
|
||||
};
|
||||
|
||||
@ -56,6 +56,7 @@ R_API int r_asm_set_syntax(struct r_asm_t *a, int syntax);
|
||||
R_API int r_asm_set_pc(struct r_asm_t *a, u64 pc);
|
||||
R_API int r_asm_disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64 len);
|
||||
R_API int r_asm_assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, const char *buf);
|
||||
R_API int r_asm_massemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf);
|
||||
|
||||
/* plugin pointers */
|
||||
extern struct r_asm_handle_t r_asm_plugin_dummy;
|
||||
|
Loading…
Reference in New Issue
Block a user