Workarounds for x86-16 and prepare bitmap
This commit is contained in:
parent
3a93f8bbbd
commit
3aeee274bf
5
TODO.md
5
TODO.md
|
@ -33,7 +33,6 @@ tothink:
|
|||
* highlight search hits in hexdump
|
||||
* Implement debugger backtrace properly
|
||||
* _ -> write string does not obeys the cursor
|
||||
* rep+ret instruction (f3c3) should be identified as RET
|
||||
* p7 : 7bit encoding (sms)
|
||||
- variant for stego print? LSB, MSB, ...
|
||||
- add base85 api
|
||||
|
@ -135,8 +134,6 @@ earada
|
|||
* remove all uses of alloca() // mingw and grep reports them all :)
|
||||
* typedef all function pointers, like in r_bp
|
||||
* Implement /. to search using a file .. isnt zignatures about this?
|
||||
* Implement /p to search for patterns
|
||||
- implement it in r_core ?? or add r_io_bind support
|
||||
* Implement search and replace /s
|
||||
- insert or append? (see r1 cfg vars)
|
||||
|
||||
|
@ -179,8 +176,8 @@ RSearch
|
|||
|
||||
Binaries
|
||||
--------
|
||||
* DEX parsing fail (invalid offset of symbols)
|
||||
* add support for .a files (r_fs supports cpio and ar archives...)
|
||||
* add support for .rar files
|
||||
|
||||
# Random
|
||||
* Implement rap:// upload/download protocol commands (maybe just system() with rsc2+wget?
|
||||
|
|
|
@ -145,6 +145,8 @@ static int anal_jmp(RAnal *anal, RAnalOp *op, x86im_instr_object io) {
|
|||
op->ref = imm;
|
||||
break;
|
||||
}
|
||||
if (anal->bits==16)
|
||||
op->jump--;
|
||||
return io.len;
|
||||
}
|
||||
|
||||
|
@ -160,6 +162,8 @@ static void anal_cjmp(RAnal *anal, RAnalOp *op, x86im_instr_object io) {
|
|||
op->dst = anal_fill_r (anal, io, op->addr);
|
||||
op->fail = op->addr + io.len;
|
||||
op->jump = op->addr + io.len + imm;
|
||||
if (anal->bits==16)
|
||||
op->jump--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -341,9 +345,8 @@ static void anal_cmp(RAnal *anal, RAnalOp *op, x86im_instr_object io) {
|
|||
op->src[0] = anal_fill_ai_mm (anal, io);
|
||||
op->src[1] = anal_fill_ai_rg (anal, io, 0);
|
||||
/* TODO: Deprecate */
|
||||
if (io.mem_base == 0) { /* cmp [0x0ff], reg */
|
||||
if (io.mem_base == 0) /* cmp [0x0ff], reg */
|
||||
op->ref = disp;
|
||||
}
|
||||
break;
|
||||
case X86IM_IO_ID_CMP_R1_R2: /* cmp reg2, reg1 */
|
||||
case X86IM_IO_ID_CMP_R2_R1:
|
||||
|
@ -810,6 +813,10 @@ static int x86_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len)
|
|||
op->jump = op->fail = -1;
|
||||
op->ref = op->value = -1;
|
||||
|
||||
if (!memcmp ("\xf3\xc3", data, 2)) {
|
||||
op->type = R_ANAL_OP_TYPE_RET;
|
||||
return op->length = 2;
|
||||
}
|
||||
ret = -1;
|
||||
if (anal->bits==64)
|
||||
ret = (x86im_dec (&io, X86IM_IO_MODE_64BIT, (ut8*)data));
|
||||
|
@ -932,6 +939,7 @@ static int x86_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *data, int len)
|
|||
op->length = io.len;
|
||||
op->nopcode = io.opcode_count;
|
||||
}
|
||||
eprintf ("LEN = %d %d \n", op->length, dislen (data, len));
|
||||
return op->length;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* radare - LGPL - Copyright 2009-2012 pancake<nopcode.org> nibble<.ds@gmail.com> */
|
||||
/* radare - LGPL - Copyright 2009-2012 pancake, nibble */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
|
|
@ -7,7 +7,7 @@ OBJS=mem.o pool.o num.o str.o hex.o file.o alloca.o range.o log.o
|
|||
OBJS+=prof.o cache.o sys.o buf.o w32-sys.o base64.o base85.o name.o
|
||||
OBJS+=list.o flist.o ht.o ht64.o mixed.o btree.o chmod.o graph.o
|
||||
OBJS+=regex/regcomp.o regex/regerror.o regex/regexec.o uleb128.o
|
||||
OBJS+=sandbox.o calc.o thread.o lock.o strpool.o
|
||||
OBJS+=sandbox.o calc.o thread.o lock.o strpool.o bitmap.o
|
||||
|
||||
# DO NOT BUILD r_big api (not yet used and its buggy)
|
||||
ifeq (1,0)
|
||||
|
|
|
@ -1,64 +1,61 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
/* radare - LGPL - Copyright 2011-2012 - pancake */
|
||||
#include <r_util.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
#define BITMAP_TEST 0
|
||||
|
||||
#define BITMAP_TEST 1
|
||||
|
||||
#define BITMAP_32_WORD 1
|
||||
|
||||
typedef struct Bitmap Bitmap;
|
||||
#if BITMAP_32_WORD
|
||||
#if R_SYS_BITS == 4
|
||||
#define BITWORD_BITS_SHIFT 5
|
||||
typedef uint32_t Bitword;
|
||||
#define RBitword ut32
|
||||
#else
|
||||
#define BITWORD_BITS_SHIFT 6
|
||||
typedef uint64_t Bitword;
|
||||
#define RBitword ut64
|
||||
#endif
|
||||
#define BITWORD_BITS (sizeof(Bitword) * 8)
|
||||
|
||||
#define BITWORD_BITS (sizeof(RBitword) * 8)
|
||||
#define BITWORD_BITS_MASK (BITWORD_BITS - 1)
|
||||
#define BITWORD_MULT(bit) ((bit + (BITWORD_BITS_MASK)) & ~(BITWORD_BITS_MASK))
|
||||
#define BITWORD_TEST(bword, bit) ((bword >> bit) & 1)
|
||||
#define BITWORD_TEST(x, y) ((x>> y) & 1)
|
||||
|
||||
#define BITMAP_WORD_COUNT(bit) (BITWORD_MULT(bit) >> BITWORD_BITS_SHIFT)
|
||||
|
||||
typedef struct r_bitmap_t {
|
||||
int length;
|
||||
RBitword *bitmap;
|
||||
} RBitmap;
|
||||
|
||||
struct Bitmap {
|
||||
size_t length;
|
||||
Bitword *bitmap;
|
||||
};
|
||||
|
||||
extern Bitmap *bitmap_new(size_t len) {
|
||||
Bitmap *bitmap = malloc(sizeof(Bitmap));
|
||||
bitmap->length = len;
|
||||
bitmap->bitmap = calloc(BITMAP_WORD_COUNT(len),sizeof(Bitword));
|
||||
return bitmap;
|
||||
extern RBitmap *r_bitmap_new(size_t len) {
|
||||
RBitmap *b = R_NEW (RBitmap);
|
||||
b->length = len;
|
||||
b->bitmap = calloc (BITMAP_WORD_COUNT (len), sizeof (RBitword));
|
||||
return b;
|
||||
}
|
||||
|
||||
extern void bitmap_free(Bitmap *bitmap) {
|
||||
free(bitmap->bitmap);
|
||||
free(bitmap);
|
||||
extern void r_bitmap_free(RBitmap *b) {
|
||||
free (b->bitmap);
|
||||
free (b);
|
||||
}
|
||||
|
||||
extern void bitmap_set(Bitmap *bitmap, size_t bit) {
|
||||
assert(bit < bitmap->length);
|
||||
bitmap->bitmap[(bit >> BITWORD_BITS_SHIFT)] |= ((Bitword)1 << (bit & BITWORD_BITS_MASK));
|
||||
extern void bitmap_set(RBitmap *b, size_t bit) {
|
||||
if (bit<b->length)
|
||||
b->bitmap[(bit >> BITWORD_BITS_SHIFT)] |= \
|
||||
((RBitword)1 << (bit & BITWORD_BITS_MASK));
|
||||
}
|
||||
|
||||
extern void bitmap_unset(Bitmap *bitmap, size_t bit) {
|
||||
assert(bit < bitmap->length);
|
||||
bitmap->bitmap[(bit >> BITWORD_BITS_SHIFT)] &= ~((Bitword)1 << (bit & BITWORD_BITS_MASK));
|
||||
extern void r_bitmap_unset(RBitmap *b, size_t bit) {
|
||||
if (bit < b->length)
|
||||
b->bitmap[(bit >> BITWORD_BITS_SHIFT)] &= \
|
||||
~((RBitword)1 << (bit & BITWORD_BITS_MASK));
|
||||
}
|
||||
|
||||
extern bool bitmap_test(Bitmap *bitmap, size_t bit) {
|
||||
assert(bit < bitmap->length);
|
||||
Bitword bword = bitmap->bitmap[(bit >> BITWORD_BITS_SHIFT)];
|
||||
return BITWORD_TEST(bword, (bit & BITWORD_BITS_MASK));
|
||||
extern int r_bitmap_test(RBitmap *b, size_t bit) {
|
||||
if (bit < b->length) {
|
||||
RBitword bword = b->bitmap[ (bit >> BITWORD_BITS_SHIFT)];
|
||||
return BITWORD_TEST (bword, (bit & BITWORD_BITS_MASK));
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef BITMAP_TEST
|
||||
#if BITMAP_TEST
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX_VALUE (2343 + 1)
|
||||
|
|
Loading…
Reference in New Issue