Add new opcodes for x86.nz assembler

- Fix search counter
This commit is contained in:
pancake 2012-08-03 02:05:50 +02:00
parent 526a8a66fe
commit 3e7c4ad992
7 changed files with 25 additions and 16 deletions

3
TODO
View File

@ -6,13 +6,14 @@
------8<-------------------8<--------------------8<-----------------8<----------
====[[ 0.9.1 ]]====
* Implement r_bin_size() - get estimated binary file size from headers
* Implement grep+count (afl~fcn?)
* Analysis
- assume there's a function at the end of each function
* Allow to seek to branch N like in visual, but from cmdline
* Colorize multiple ranges of chars in hexdump
* List functions
- calculate and show ciclomatic complexity
* Searching for asm opcodes does not increase the hit count?
* insert assembly in visual should be more userfriendly (keep unwritten bytes)
* Search in io.va=true must be fixed
- search.infile=true (ignore va and offset)

View File

@ -98,8 +98,10 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
memmove (op, op+4, strlen (op+4)+1);
}
if (!strcmp (str, "outsd")) { data[0] = 0x6f; return 1; }
if (!strcmp (str, "outsb")) { data[0] = 0x6e; return 1; }
if (!strcmp (str, "insb")) { data[0] = 0x6c; return 1; }
if (!strcmp (str, "hlt")) { data[0] = 0xf4; return 1; }
if (!strcmp (str, "call $$")) {
memcpy (data, "\xE8\xFF\xFF\xFF\xFF\xC1", 6);
@ -454,7 +456,9 @@ static int assemble(RAsm *a, RAsmOp *ao, const char *str) {
}
dst = r_num_math (NULL, arg);
if (dst == 0) {
data[l++] = getreg (arg) | 0x58;
ut8 r = getreg (arg);
if (r==(ut8)-1) return 0;
data[l++] = r | 0x58;
return l;
}
eprintf ("Invalid pop syntax\n");

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2008-2010 nibble<.ds@gmail.com>, pancake<nopcode.org> */
/* radare - LGPL - Copyright 2008-2012 nibble, pancake */
#include <stdio.h>
#include <stdlib.h>
@ -286,7 +286,9 @@ struct r_bin_pe_addr_t* PE_(r_bin_pe_get_entrypoint)(struct PE_(r_bin_pe_obj_t)*
return NULL;
}
entry->rva = bin->nt_headers->optional_header.AddressOfEntryPoint;
entry->offset = PE_(r_bin_pe_rva_to_offset)(bin, bin->nt_headers->optional_header.AddressOfEntryPoint);
if (entry->rva == 0) // in PE if EP = 0 then EP = baddr
entry->rva = bin->nt_headers->optional_header.ImageBase;
entry->offset = PE_(r_bin_pe_rva_to_offset)(bin, entry->rva);
return entry;
}
@ -365,7 +367,7 @@ int PE_(r_bin_pe_get_file_alignment)(struct PE_(r_bin_pe_obj_t)* bin)
ut64 PE_(r_bin_pe_get_image_base)(struct PE_(r_bin_pe_obj_t)* bin)
{
return(ut64)bin->nt_headers->optional_header.ImageBase;
return (ut64)bin->nt_headers->optional_header.ImageBase;
}
struct r_bin_pe_import_t* PE_(r_bin_pe_get_imports)(struct PE_(r_bin_pe_obj_t) *bin)

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2011 nibble<.ds@gmail.com>, pancake<nopcode.org> */
/* radare - LGPL - Copyright 2009-2012 nibble<.ds@gmail.com>, pancake<nopcode.org> */
#include <r_types.h>
#include <r_util.h>

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2011 */
/* radare - LGPL - Copyright 2009-2012 */
/* nibble<.ds@gmail.com> */
#include <r_types.h>
@ -7,11 +7,10 @@
R_API RCoreAsmHit *r_core_asm_hit_new() {
RCoreAsmHit *hit = R_NEW (RCoreAsmHit);
if (hit) {
hit->code = NULL;
hit->len = 0;
hit->addr = -1;
}
if (!hit) return NULL;
hit->code = NULL;
hit->len = 0;
hit->addr = -1;
return hit;
}

View File

@ -12,7 +12,7 @@ static int __prelude_cb_hit(RSearchKeyword *kw, void *user, ut64 addr) {
RCore *core = (RCore *)user;
int depth = r_config_get_i (core->config, "anal.depth");
//eprintf ("ap: Found function prelude %d at 0x%08"PFMT64x"\n", preludecnt, addr);
searchhits = kw->count;
searchhits = kw->count+1;
r_core_anal_fcn (core, addr, -1, R_ANAL_REF_TYPE_NULL, depth);
preludecnt++;
return R_TRUE;
@ -77,7 +77,7 @@ R_API int r_core_search_preludes(RCore *core) {
static int __cb_hit(RSearchKeyword *kw, void *user, ut64 addr) {
RCore *core = (RCore *)user;
searchhits = kw->count;
searchhits = kw->count+1;
if (searchcount) {
if (!--searchcount) {
eprintf ("\nsearch stop: search.count reached\n");
@ -495,7 +495,7 @@ static int cmd_search(void *data, const char *input) {
break;
}
if (core->io->va)
eprintf ("Search is broken in io.va. Please fix or e io.va=0\n");
eprintf ("Searching with io.va enabled can be wrong.\n");
searchhits = 0;
r_config_set_i (core->config, "search.kwidx", core->search->n_kws);
if (dosearch) {

View File

@ -18,7 +18,7 @@ static int cmd_seek(void *data, const char *input) {
int sign = 1;
st32 delta = (input[1]==' ')? 2: 1;
off = r_num_math (core->num, input + delta);
if ((st64)off<0)off =-off; // hack to fix s-2;s -2
if ((st64)off<0) off = -off; // hack to fix s-2;s -2
if (isalpha (input[delta]) && off == 0) {
if (delta==1 && !r_flag_get (core->flags, input+delta)) {
eprintf ("Cannot find address for '%s'\n", input+delta);
@ -148,6 +148,8 @@ static int cmd_seek(void *data, const char *input) {
r_core_seek_align (core, off, 0);
break;
case 'b':
if (off == 0)
off = core->offset;
r_io_sundo_push (core->io, core->offset);
r_core_anal_bb_seek (core, off);
break;
@ -175,6 +177,7 @@ static int cmd_seek(void *data, const char *input) {
" s/ DATA ; search for next occurrence of 'DATA'\n"
" s/x 9091 ; search for next occurrence of \\x90\\x91\n"
" sb ; seek aligned to bb start\n"
//" sp [page] ; seek page N (page = block)\n"
" sn ; seek to next opcode\n"
" sC str ; seek to comment matching given string\n"
" sr pc ; seek to register\n");