Add more Jamroot files and move some plugs to r2-extras

This commit is contained in:
pancake 2013-12-31 15:34:27 +01:00
parent add7a962f5
commit 3b3bbbb916
36 changed files with 212 additions and 20852 deletions

1
Jamroot Normal file
View File

@ -0,0 +1 @@
build-project libr ;

22
libr/Jamroot Normal file
View File

@ -0,0 +1,22 @@
# Build all r2 libraries in order
build-project util ;
build-project hash ;
build-project reg ;
build-project cons ;
build-project db ;
build-project magic ;
build-project lib ;
build-project diff ;
build-project bp ;
build-project search ;
build-project config ;
build-project socket ;
build-project syscall ;
build-project flags ;
build-project crypto ;
# build-project io ;
# build-project lang ;
build-project cmd ;

17
libr/anal/Jamroot Normal file
View File

@ -0,0 +1,17 @@
OBJS = meta.c reflines.c ref.c op.c fcn.c bb.c var.c ;
OBJS += cond.c value.c cc.c diff.c types.c fcnstore.c ;
OBJS += hint.c vm.c anal.c data.c xrefs.c esil.c sign.c ;
include plugins.jam ;
lib r_anal : $(OBJS) : <include>../include
<define>CORELIB
<library>../util
<library>../lib
<library>../reg
<library>../diff
<library>../syscall
<library>../db
<library>../../shlr/sdb # XXX this should be implicit by ../db
$(EXTRA)
;

View File

@ -1,253 +0,0 @@
// code from: z0mbie @ 2002
// http://vx.netlux.org/lib/vzo16.html
#include "dislen.h"
static DWORD disasm_len; // 0 if error
static DWORD disasm_flag; // C_xxx
static DWORD disasm_memsize; // value = disasm_mem
static DWORD disasm_datasize; // value = disasm_data
static DWORD disasm_defdata; // == C_66 ? 2 : 4
static DWORD disasm_defmem; // == C_67 ? 2 : 4
static BYTE disasm_seg; // CS DS ES SS FS GS
static BYTE disasm_rep; // REPZ/REPNZ
static BYTE disasm_opcode; // opcode
static BYTE disasm_opcode2; // used when opcode==0F
static BYTE disasm_modrm; // modxxxrm
static BYTE disasm_sib; // scale-index-base
static BYTE disasm_mem[8]; // mem addr value
static BYTE disasm_data[8]; // data value
// returns: 1 if success
// 0 if error
int dislen(BYTE* opcode0, int limit)
{
BYTE* opcode = opcode0;
DWORD i;
disasm_len = 0;
disasm_flag = 0;
disasm_datasize = 0;
disasm_memsize = 0;
disasm_defdata = 4;
disasm_defmem = 4;
retry:
if (!limit--)
return 0;
disasm_opcode = *opcode++;
switch (disasm_opcode)
{
case 0x00: case 0x01: case 0x02: case 0x03:
case 0x08: case 0x09: case 0x0A: case 0x0B:
case 0x10: case 0x11: case 0x12: case 0x13:
case 0x18: case 0x19: case 0x1A: case 0x1B:
case 0x20: case 0x21: case 0x22: case 0x23:
case 0x28: case 0x29: case 0x2A: case 0x2B:
case 0x30: case 0x31: case 0x32: case 0x33:
case 0x38: case 0x39: case 0x3A: case 0x3B:
case 0x62: case 0x63:
case 0x84: case 0x85: case 0x86: case 0x87:
case 0x88: case 0x89: case 0x8A: case 0x8B:
case 0x8C: case 0x8D: case 0x8E: case 0x8F:
case 0xC4: case 0xC5:
case 0xD0: case 0xD1: case 0xD2: case 0xD3:
case 0xD8: case 0xD9: case 0xDA: case 0xDB:
case 0xDC: case 0xDD: case 0xDE: case 0xDF:
case 0xFE: case 0xFF:
disasm_flag |= C_MODRM;
break;
case 0xCD: disasm_datasize += *opcode==0x20 ? 1+4 : 1;
break;
case 0xF6:
case 0xF7: disasm_flag |= C_MODRM;
if (*opcode & 0x38) break;
// continue if <test ..., xx>
case 0x04: case 0x05: case 0x0C: case 0x0D:
case 0x14: case 0x15: case 0x1C: case 0x1D:
case 0x24: case 0x25: case 0x2C: case 0x2D:
case 0x34: case 0x35: case 0x3C: case 0x3D:
if (disasm_opcode & 1)
disasm_datasize += disasm_defdata;
else
disasm_datasize++;
break;
case 0x6A:
case 0xA8:
case 0xB0: case 0xB1: case 0xB2: case 0xB3:
case 0xB4: case 0xB5: case 0xB6: case 0xB7:
case 0xD4: case 0xD5:
case 0xE4: case 0xE5: case 0xE6: case 0xE7:
case 0x70: case 0x71: case 0x72: case 0x73:
case 0x74: case 0x75: case 0x76: case 0x77:
case 0x78: case 0x79: case 0x7A: case 0x7B:
case 0x7C: case 0x7D: case 0x7E: case 0x7F:
case 0xEB:
case 0xE0: case 0xE1: case 0xE2: case 0xE3:
disasm_datasize++;
break;
case 0x26: case 0x2E: case 0x36: case 0x3E:
case 0x64: case 0x65:
if (disasm_flag & C_SEG) return 0;
disasm_flag |= C_SEG;
disasm_seg = disasm_opcode;
goto retry;
case 0xF0:
if (disasm_flag & C_LOCK) return 0;
disasm_flag |= C_LOCK;
goto retry;
case 0xF2: case 0xF3:
if (disasm_flag & C_REP) return 0;
disasm_flag |= C_REP;
disasm_rep = disasm_opcode;
goto retry;
case 0x66:
if (disasm_flag & C_66)
return 8; // workaround for # 66662e0f1f8300. o16 nop [cs:rbx+0x0]
disasm_flag |= C_66;
disasm_defdata = 2;
goto retry;
case 0x67:
if (disasm_flag & C_67) return 0;
disasm_flag |= C_67;
disasm_defmem = 2;
goto retry;
case 0x6B:
case 0x80:
case 0x82:
case 0x83:
case 0xC0:
case 0xC1:
case 0xC6: disasm_datasize++;
disasm_flag |= C_MODRM;
break;
case 0x69:
case 0x81:
case 0xC7:
disasm_datasize += disasm_defdata;
disasm_flag |= C_MODRM;
break;
case 0x9A:
case 0xEA: disasm_datasize += 2 + disasm_defdata;
break;
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3: disasm_memsize += disasm_defmem;
break;
case 0x68:
case 0xA9:
case 0xB8: case 0xB9: case 0xBA: case 0xBB:
case 0xBC: case 0xBD: case 0xBE: case 0xBF:
case 0xE8:
case 0xE9:
disasm_datasize += disasm_defdata;
break;
case 0xC2:
case 0xCA: disasm_datasize += 2;
break;
case 0xC8:
disasm_datasize += 3;
break;
case 0xF1:
return 0;
case 0x0F:
disasm_flag |= C_OPCODE2;
disasm_opcode2 = *opcode++;
switch (disasm_opcode2) {
case 0x1F:
return 6; // HACK
case 0x00: case 0x01: case 0x02: case 0x03:
case 0x90: case 0x91: case 0x92: case 0x93:
case 0x94: case 0x95: case 0x96: case 0x97:
case 0x98: case 0x99: case 0x9A: case 0x9B:
case 0x9C: case 0x9D: case 0x9E: case 0x9F:
case 0xA3:
case 0xA5:
case 0xAB:
case 0xAD:
case 0xAF:
case 0xB0: case 0xB1: case 0xB2: case 0xB3:
case 0xB4: case 0xB5: case 0xB6: case 0xB7:
case 0xBB:
case 0xBC: case 0xBD: case 0xBE: case 0xBF:
case 0xC0:
case 0xC1:
disasm_flag |= C_MODRM;
break;
case 0x06:
case 0x08: case 0x09: case 0x0A: case 0x0B:
case 0xA0: case 0xA1: case 0xA2: case 0xA8:
case 0xA9:
case 0xAA:
case 0xC8: case 0xC9: case 0xCA: case 0xCB:
case 0xCC: case 0xCD: case 0xCE: case 0xCF:
case 0x31: // rdtsc
break;
case 0x80: case 0x81: case 0x82: case 0x83:
case 0x84: case 0x85: case 0x86: case 0x87:
case 0x88: case 0x89: case 0x8A: case 0x8B:
case 0x8C: case 0x8D: case 0x8E: case 0x8F:
disasm_datasize += disasm_defdata;
break;
case 0xA4:
case 0xAC:
case 0xBA:
disasm_datasize++;
disasm_flag |= C_MODRM;
break;
default:
return 0;
} // 0F-switch
break;
} //switch
if (disasm_flag & C_MODRM)
{
if (limit<2) // it was 4
return 0;
disasm_modrm = *opcode++;
BYTE mod = disasm_modrm & 0xC0;
BYTE rm = disasm_modrm & 0x07;
if (mod != 0xC0)
{
if (mod == 0x40) disasm_memsize++;
if (mod == 0x80) disasm_memsize += disasm_defmem;
if (disasm_defmem == 2) // modrm16
{
if ((mod == 0x00)&&(rm == 0x06)) disasm_memsize+=2;
}
else // modrm32
{
if (rm==0x04)
{
disasm_flag |= C_SIB;
disasm_sib = *opcode++;
rm = disasm_sib & 0x07;
}
if ((rm==0x05)&&(mod==0x00)) disasm_memsize+=4;
}
}
} // C_MODRM
for(i=0; i<disasm_memsize; i++)
disasm_mem[i] = *opcode++;
for(i=0; i<disasm_datasize; i++)
disasm_data[i] = *opcode++;
disasm_len = opcode - opcode0;
return disasm_len;
} //disasm
#if 0
main() { //assert 3 , dislen ("\x00\x41\x57", 3);
printf ("6=%d\n", dislen ("\x66\x0f\x1f\x44\x00\x00", 8));
//printf ("%d\n", dislen ("\x66\x66\x2e\x0f\x1f\x84\x00\x00",10));
}
#endif

View File

@ -1,18 +0,0 @@
// code from: z0mbie @ 2002
// http://vx.netlux.org/lib/vzo16.html
#define DWORD unsigned long
#define BYTE unsigned char
// disasm_flag values:
#define C_66 0x00000001 // 66-prefix
#define C_67 0x00000002 // 67-prefix
#define C_LOCK 0x00000004 // lock
#define C_REP 0x00000008 // repz/repnz
#define C_SEG 0x00000010 // seg-prefix
#define C_OPCODE2 0x00000020 // 2nd opcode present (1st==0F)
#define C_MODRM 0x00000040 // modrm present
#define C_SIB 0x00000080 // sib present
#define C_ANYPREFIX (C_66|C_67|C_LOCK|C_REP|C_SEG)
int dislen(BYTE* opcode0, int limit);

File diff suppressed because it is too large Load Diff

View File

@ -1,49 +0,0 @@
//////////////////////////////////////////////////////////////
//
// x86 Instruction Manipulator: Decoder/Generator/Encoder v1.0
//
// (x) Pluf
//
//////////////////////////////////////////////////////////////
#ifndef __X86IM_H__
#define __X86IM_H__
#if __UNIX__
# define WORD unsigned short
# define DWORD unsigned int
# define BOOL int
# define TRUE 1
# define FALSE 0
#endif
# define __stdcall
# define __inout
# define __in
# define __out
#include "x86im_io.h"
#ifdef __X86IM_USE_FMT__
#include "x86im_fmt.h"
#endif
#include "x86im_gen.h"
#define X86IM_STATUS_SUCCESS 0x0
#define X86IM_STATUS_INVALID_ARGUMENTS 0x1
#define X86IM_STATUS_INVALID_OPCODE 0x2
int __stdcall x86im_dec( __inout x86im_instr_object *io,
__in unsigned long mode,
__in unsigned char *data );
int __stdcall x86im_gen( __inout x86im_instr_object *io,
__in unsigned long options,
__in unsigned long code,
__in unsigned long reg,
__in unsigned long mem,
__in unsigned long long disp,
__in unsigned long long imm );
int __stdcall x86im_enc( __inout x86im_instr_object *io,
__out unsigned char *data );
#endif // __X86IM_H__

File diff suppressed because it is too large Load Diff

View File

@ -1,36 +0,0 @@
//////////////////////////////////////////////////////////////
//
// x86 Instruction Manipulator: Decoder/Generator/Encoder v1.0
//
// (x) Pluf
//
//////////////////////////////////////////////////////////////
#ifndef __X86IM_FMT_H__
#define __X86IM_FMT_H__
#ifdef __X86IM_USE_FMT__
#ifndef __in
#define __in
#endif
#ifndef __out
#define __out
#endif
#ifndef __inout
#define __inout
#endif
char *x86f_get_imn( __in x86im_instr_object *io );
char *x86f_get_reg( __in unsigned short reg );
unsigned int x86im_fmt( __in x86im_instr_object *io );
void x86im_fmt_format_prefix( __in x86im_instr_object *io,
__out char *pfx );
void x86im_fmt_format_name( __in x86im_instr_object *io,
__in char *name );
void x86im_fmt_format_operand( __in x86im_instr_object *io,
__out char *dst,
__out char *src );
#endif
#endif // __X86IM_FMT_H__

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -10,7 +10,7 @@ all: ${ALL_TARGETS} ;
ALL_TARGETS=
# TODO: rename to enabled plugins
ARCHS=x86_im.mk x86_udis.mk x86_simple.mk ppc.mk arm.mk avr.mk csr.mk dalvik.mk sh.mk ebc.mk gb.mk
ARCHS=x86_udis.mk ppc.mk arm.mk avr.mk csr.mk dalvik.mk sh.mk ebc.mk gb.mk
include $(ARCHS)
clean:

View File

@ -7,7 +7,7 @@
#include <r_anal.h>
/* DEPRECATE ?? */
#include "arm/arm.h"
#include "arm.h"
#include "../asm/arch/arm/arm.h"
#include "../asm/arch/arm/winedbg/be_arm.h"

File diff suppressed because it is too large Load Diff

View File

@ -1,536 +0,0 @@
/* radare - LGPL - Copyright 2009-2010 */
/* pancake<nopcode.org> */
/* nibble<.ds@gmail.com> */
#include <string.h>
#include <r_types.h>
#include <r_lib.h>
#include <r_asm.h>
#include <r_anal.h>
#include "x86/dislen/dislen.h"
/* code analysis functions */
/* arch_op for x86 */
// CMP ARG1
// 837d0801 cmp dword [ebp+0x8], 0x1
// 803db501060800 cmp byte [0x80601b5], 0x0
// SET VAR_41c
// 8985e4fbffff mov [ebp-41C],eax
// GET VAR_41c
// 8b85e4fbffff mov eax,[ebp-41C]
// 8b450c mov eax,[ebp+C]
// 8d85e8fbffff lea eax,[ebp-418]
// c68405e7fbffff. mov byte ptr [ebp+eax-419],0x0
//3d00400000 cmp eax, 0x4000
//81fa00c00000 cmp edx, 0xc000
//83fa01 cmp edx, 0x1
static const char *testregs[] = {
"eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi" };
// NOTE: buf should be at least 16 bytes!
// XXX addr should be off_t for 64 love
static int myop(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
if (buf == NULL)
return 0;
memset (op, 0, sizeof (RAnalOp));
op->type = R_ANAL_OP_TYPE_UNK;
op->addr = addr;
op->jump = op->fail = -1;
op->ptr = op->val = -1;
switch (buf[0]) {
case 0x8a:
case 0x8b:
case 0x03: // 034518 add eax, [ebp+0x18]
switch (buf[1]) {
case 0x45:
case 0x46:
case 0x55:
case 0x5d:
case 0x7d:
/* mov -0xc(%ebp, %eax */
op->ptr = (st64)((char)buf[2]);
op->stackop = R_ANAL_STACK_GET;
break;
case 0x95:
if (buf[2]==0xe0) { // ebp
op->ptr = (st64)((int)(buf[3]+(buf[4]<<8)+(buf[5]<<16)+(buf[6]<<24)));
op->stackop = R_ANAL_STACK_GET;
}
//op->ptr = -(buf[2]+(buf[3]<<8)+(buf[4]<<16)+(buf[5]<<24));
break;
case 0xbd:
op->ptr = (st64)((int)(buf[2]+(buf[3]<<8)+(buf[4]<<16)+(buf[5]<<24)));
//op->ptr = -(buf[2]+(buf[3]<<8)+(buf[4]<<16)+(buf[5]<<24));
op->stackop = R_ANAL_STACK_GET;
break;
}
break;
case 0x88:
case 0x89: // move
switch (buf[1]) {
case 0x45:
case 0x4d: // 894de0 mov [ebp-0x20], ecx
case 0x55:
op->stackop = R_ANAL_STACK_SET;
op->ptr = (st64)((char)buf[2]);
break;
case 0x85:
op->stackop = R_ANAL_STACK_SET;
op->ptr = (st64)((int)(buf[2]+(buf[3]<<8)+(buf[4]<<16)+(buf[5]<<24)));
break;
case 0x75:
op->stackop = R_ANAL_STACK_GET;
op->ptr = (st64)((char)buf[2]); //+(buf[3]<<8)+(buf[4]<<16)+(buf[5]<<24));
break;
}
// XXX: maybe store or mov depending on opcode
// 89c3 mov ebx, eax
// 897c2408 mov [esp+0x8], edi
op->type = R_ANAL_OP_TYPE_STORE;
break;
case 0xf4: // hlt
op->type = R_ANAL_OP_TYPE_RET;
op->size = 1;
break;
case 0xc3: // ret
case 0xc2: // ret + 2 bytes
case 0xcb: // lret
case 0xcf: // iret
op->type = R_ANAL_OP_TYPE_RET;
op->eob = 1;
break;
//case 0xea: // far jmp
// TODO moar
case 0x3b: //cmp
op->ptr = (st64)((char)buf[2]);
op->stackop = R_ANAL_STACK_GET;
case 0x39:
case 0x3c:
case 0x3d:
// 3d 00 40 00 00 cmp eax, 0x4000
op->src[0] = r_anal_value_new ();
op->src[0]->reg = r_reg_get (anal->reg, testregs[(buf[0]&7)%8], R_REG_TYPE_GPR);
op->src[1] = r_anal_value_new ();
op->src[1]->base = buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
op->type = R_ANAL_OP_TYPE_CMP;
break;
case 0x80:
op->type = R_ANAL_OP_TYPE_CMP;
switch (buf[1]) {
case 0x3d: // 80 3d b5010608 00 cmp byte [0x80601b5], 0x0
op->src[0] = r_anal_value_new ();
op->src[0]->memref = 1;
op->src[0]->base = buf[2]+(buf[3]<<8)+(buf[4]<<16)+(buf[5]<<24);
op->src[1] = r_anal_value_new ();
op->src[1]->base = buf[6];
break;
}
break;
case 0x85:
op->type = R_ANAL_OP_TYPE_CMP;
if (buf[1]>=0xc0) {
int src = buf[1]&7;
int dst = (buf[1]&0x38)>>3;
op->src[0] = r_anal_value_new ();
op->src[0]->reg = r_reg_get (anal->reg, testregs[src%8], R_REG_TYPE_GPR);
op->src[1] = r_anal_value_new ();
op->src[1]->reg = r_reg_get (anal->reg, testregs[dst%8], R_REG_TYPE_GPR);
op->src[2] = NULL;
//eprintf ("REGZ (%s)\n", anal->reg);
//eprintf ("REG IZ: (%s)\n", testregs[src%8]);
//eprintf ("REG IZ: %p (%s)\n", op->src[0], op->src[0]->reg->name);
if (op->src[0]->reg == op->src[1]->reg) {
//eprintf ("fruity\n");
r_anal_value_free (op->src[1]);
op->src[1] = NULL;
}
//eprintf ("0x%"PFMT64x": (%02x) %d %d\n", addr, buf[1], src, dst);
} else if (buf[1]<0xc0) { // test [eax+delta], eax
/* not yet supported */
}
// c0-c7 : eax, ecx, edx, ebx, esp, ebp, esi, edi
// 83f821 cmp eax, 0x21
// 85c0 test eax, eax
// 85c9 test ecx, ecx
break;
case 0x90:
op->type = R_ANAL_OP_TYPE_NOP;
op->size = 1;
break;
case 0x0f: // 3 byte nop
//0fbe55ff movsx edx, byte [ebp-0x1]
if (buf[1]==0xbe) {
op->ptr = (st64)((char)buf[3]);
op->stackop = R_ANAL_STACK_GET;
} else
if (buf[1]==0x31) {
// RDTSC // colorize or sthg?
op->eob = 0;
} else
if (buf[1]>=0x18 && buf[1]<=0x1f) {
op->type = R_ANAL_OP_TYPE_NOP;
op->size = 3;
} else
if (buf[1]>=0x80 && buf[1]<=0x8f) {
op->type = R_ANAL_OP_TYPE_CJMP;
op->jump = addr+6+buf[2]+(buf[3]<<8)+(buf[4]<<16)+(buf[5]<<24);//((unsigned long)((buf+2))+6);
op->fail = addr+6;
op->size = 6;
//op->eob = 1;
} else
if (buf[1]>=0x40 && buf[1]<=0x4f) { /* Conditional MOV */
op->type = R_ANAL_OP_TYPE_MOV;
op->eob = 0;
op->size = 4;
return 4;
}
break;
case 0xcc: // int3
// op->eob = 1;
op->val = 3;
op->type = R_ANAL_OP_TYPE_SWI;
break;
case 0xf1: // int1
op->size = 1;
op->val = 1;
op->type = R_ANAL_OP_TYPE_SWI;
break;
case 0xb8: // mov eax, <inmedate>
case 0xb9: // mov ecx, <inmedate>
case 0xba: // mov edx, <inmedate>
case 0xbb: // mov ebx, <inmedate>
case 0xbc: // mov esp, <inmedate>
case 0xbd: // mov esp, <inmedate>
case 0xbf:
op->type = R_ANAL_OP_TYPE_MOV; // bfdc054000 mov edi, 0x4005dc
op->ptr = (st64)((int)buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24));//((unsigned long)((buf+2))+6);
break;
case 0xcd:
op->size = 2;
op->type = R_ANAL_OP_TYPE_SWI;
op->val = buf[1];
break;
case 0xe8: // call
op->type = R_ANAL_OP_TYPE_CALL;
op->size = 5;
//op->jump = addr+*ptr+5; //(unsigned long)((buf+1)+5);
op->jump = addr+5+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);//((unsigned long)((buf+2))+6);
op->fail = addr+5;
//printf("addr: %08"PFMT64x"\n call %08"PFMT64x" \n ret %08"PFMT64x"\n", addr, op->jump, op->fail);
// op->eob = 1;
break;
case 0xe9: // jmp
op->type = R_ANAL_OP_TYPE_JMP;
op->size = 5;
//op->jump = (unsigned long)((buf+1)+5);
op->jump = addr+5+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);//((unsigned long)((buf+2))+6);
op->fail = 0L;
op->eob = 1;
break;
case 0xeb: // short jmp
op->type = R_ANAL_OP_TYPE_JMP;
op->size = 2;
op->jump = addr+((unsigned long)((char)buf[1])+2);
op->fail = 0L;
op->eob = 1;
break;
case 0xf2: // repnz
case 0xf3: // repz
op->type = R_ANAL_OP_TYPE_REP;
//op->size = dislen((unsigned char *)&buf); //instLength(buf, 16, 0);
op->jump = 0L;
op->fail = 0L;
break;
case 0xff:
if (buf[1]== 0x75) {
op->type = R_ANAL_OP_TYPE_PUSH;
op->stackop = R_ANAL_STACK_GET;
op->ptr = 0LL;
op->ptr = (st64)((char)(buf[2]));
op->stackptr = 4;
} else
if (buf[1]== 0x45) {
op->type = R_ANAL_OP_TYPE_ADD;
op->stackop = R_ANAL_STACK_SET;
op->ptr = (st64)((char)buf[2]);
} else
if (buf[1]>=0x50 && buf[1]<=0x6f) {
op->type = R_ANAL_OP_TYPE_UJMP;
op->eob = 1;
} else
if (buf[1]>=0xd0 && buf[1]<=0xd7) {
op->type = R_ANAL_OP_TYPE_CALL;
op->size = 2;
op->eob = 1;
//op->jump = vm_arch_x86_regs[VM_X86_EAX+buf[1]-0xd0];
op->fail = addr+2;
} else
if (buf[1]>=0xe0 && buf[1]<=0xe7) {
op->type = R_ANAL_OP_TYPE_UJMP;
op->size = 2;
//op->jump = vm_arch_x86_regs[VM_X86_EAX+buf[1]-0xd0];
op->eob = 1;
}
break;
case 0x50:
case 0x51:
case 0x52:
case 0x53:
case 0x54:
case 0x55:
case 0x56:
case 0x57:
case 0x58:
case 0x59:
op->type = R_ANAL_OP_TYPE_UPUSH;
op->ptr = 0; // TODO value of register here! get_offset
op->stackptr = 4;
break;
case 0x6a: // push $7
op->type = R_ANAL_OP_TYPE_PUSH;
op->ptr = buf[1];
op->stackptr = 4;
break;
break;
case 0x5a:
case 0x5b:
case 0x5c:
case 0x5d:
case 0x5e:
case 0x5f:
op->type = R_ANAL_OP_TYPE_POP;
op->size = 1;
op->stackptr = -4;
break;
case 0x2e: // 2e64796e jns 0xb770a4ab !!
if (buf[1]>=0x64 && buf[1]<=0x67) {
int ret = myop (anal, op, addr, buf+1, len-1);
op->jump++;
op->size++;
return ret;
}
break;
case 0x64:
case 0x65:
case 0x66:
case 0x67:
op->type = R_ANAL_OP_TYPE_CJMP;
op->jump = addr+3+buf[2]; //+(buf[2]<<8)+(buf[3]<<16); // XXX
op->size = 3;
op->fail = addr+op->size;
//op->eob = 1;
break;
case 0x68:
op->type = R_ANAL_OP_TYPE_PUSH;
op->ptr = (st64)((int)buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24));
op->stackptr = 4;
break;
case 0x81:
op->type = R_ANAL_OP_TYPE_ADD;
if (buf[1] == 0xec) {
/* sub $0x????????, $esp*/
// 81ece00d0000 sub esp, 0xde0 ;
op->val = buf[2]+(buf[3]<<8)+(buf[4]<<16)+(buf[5]<<24);
op->stackop = R_ANAL_STACK_INC;
op->stackptr = op->val;
break;
} else
if (buf[1] == 0xfa) {
op->type = R_ANAL_OP_TYPE_CMP;
// 81fa00c00000 cmp edx, 0xc000
// XXX TODO
}
break;
case 0x83:
switch (buf[1]) {
case 0xe4: // and
op->val = (ut64)(unsigned char)buf[2];
op->type = R_ANAL_OP_TYPE_AND;
break;
case 0xc4:
/* inc $0x????????, $esp*/
op->val = -(ut64)(unsigned char)buf[2];
op->stackop = R_ANAL_STACK_INC;
op->stackptr = op->val;
break;
case 0xf8:
case 0xf9:
case 0xfa:
{
int src = buf[1]&7;
op->src[0] = r_anal_value_new ();
op->src[0]->reg = r_reg_get (anal->reg, testregs[src%8], R_REG_TYPE_GPR);
op->src[1] = r_anal_value_new ();
op->src[1]->base = buf[2];
// 83f821 cmp eax, 0x21
op->type = R_ANAL_OP_TYPE_CMP;
op->size = 3;
}
break;
case 0xec:
/* sub $0x????????, $esp*/
op->val = (ut64)(unsigned char)buf[2];
op->stackop = R_ANAL_STACK_INC;
op->stackptr = op->val;
break;
case 0xbd: /* 837dfc02 cmp dword [ebp-0x4], 0x2 */
switch (buf[2]) {
case 0xe0: // ebp
if ((char)buf[2]>0) {
op->stackop = R_ANAL_STACK_GET;
op->val = buf[3]+(buf[4]<<8)+(buf[5]<<16)+(buf[6]<<24);
} else {
op->stackop = R_ANAL_STACK_GET;
op->val = buf[3]+(buf[4]<<8)+(buf[5]<<16)+(buf[6]<<24);
}
op->type = R_ANAL_OP_TYPE_CMP;
break;
}
break;
case 0x7d: /* 837dfc02 cmp dword [ebp-0x4], 0x2 */
if ((char)buf[2]>0) {
op->stackop = R_ANAL_STACK_GET;
op->val = (ut64)(char)buf[2];
} else {
op->stackop = R_ANAL_STACK_GET;
op->val = (ut64)-(char)buf[2];
}
op->type = R_ANAL_OP_TYPE_CMP;
break;
}
break;
case 0x8d:
/* LEA */
if (buf[1] == 0x85) {
op->ptr = (st64)((int)(buf[2]+(buf[3]<<8)+(buf[4]<<16)+(buf[5]<<24)));
op->stackop = R_ANAL_STACK_GET;
}
op->type =R_ANAL_OP_TYPE_MOV;
break;
case 0xc6:
case 0xc7:
/* mov dword [ebp-0xc], 0x0 || c7 45 f4 00000000 */
switch (buf[1]) {
case 0x85:
op->ptr = (st64)(((int)(buf[2]+(buf[3]<<8)+(buf[4]<<16)+(buf[5]<<24))));
break;
//c785 e4fbffff 00. mov dword [ebp+0xfffffbe4], 0x0
case 0x45:
op->stackop = R_ANAL_STACK_SET;
op->ptr = (st64)((char)buf[2]);
break;
case 0x05:
// c7050c0106080000. mov dword [0x806010c], 0x0
// c605b401060800 mov byte [0x80601b4], 0x0
// TODO:
break;
case 0x04:
// c7042496850408 dword [esp] = 0x8048596 ; LOL
op->refptr = 4;
op->ptr = (st64)(((int)(buf[3]+(buf[4]<<8)+(buf[5]<<16)+(buf[6]<<24))));
break;
}
op->type = R_ANAL_OP_TYPE_STORE;
break;
case 0x82:
op->type = R_ANAL_OP_TYPE_ADD;
break;
case 0x29:
op->type = R_ANAL_OP_TYPE_SUB;
break;
case 0x31:
op->type = R_ANAL_OP_TYPE_XOR;
break;
case 0x32:
op->type = R_ANAL_OP_TYPE_AND;
break;
case 0xa1: // mov eax, [addr]
op->type = R_ANAL_OP_TYPE_MOV;
//vm_arch_x86_regs[VM_X86_EAX] = addr+buf[1]+(buf[2]<<8)+(buf[3]<<16)+(buf[4]<<24);
//radare_read_at((ut64)vm_arch_x86_regs[VM_X86_EAX], (unsigned char *)&(vm_arch_x86_regs[VM_X86_EAX]), 4);
break;
#if 0
case0xF
/* conditional jump */
if (buf[1]>=0x80&&buf[1]<=0x8F) {
op->type = R_ANAL_OP_TYPE_CJMP;
op->size = 6;
op->jump = (unsigned long)((buf+2)+6);
op->fail = addr+6;
op->eob = 1;
return 5;
}
break;
#endif
case 0x70:
case 0x71:
case 0x72:
case 0x73:
case 0x74:
case 0x75:
case 0x76:
case 0x77:
case 0x78:
case 0x79:
case 0x7a:
case 0x7b:
case 0x7c:
case 0x7d:
case 0x7e:
case 0x7f: {
int bo = (int)((char) buf[1]);
/* conditional jump */
//if (buf[1]>=0x80&&buf[1]<=0x8F) {
op->type = R_ANAL_OP_TYPE_CJMP;
op->size = 2;
// op->jump = (unsigned long)((buf+2)+6);
op->jump = addr+bo+2; //(unsigned long)((buf+1)+5);
op->fail = addr+2;
op->eob = 1;
//return 2;
}
break;
//default:
//op->type = R_ANAL_OP_TYPE_UNK;
}
//if (op->size == 0)
op->size = dislen ((unsigned char *)buf, 64); //instLength(buf, 16, 0);
//op->size = instLength(buf, 16, 0);
if (!(op->jump>>33))
op->jump &= 0xFFFFFFFF; // XXX may break on 64 bits here
return op->size;
}
struct r_anal_plugin_t r_anal_plugin_x86_simple = {
.name = "x86.simple",
.desc = "X86 analysis plugin",
.license = "LGPL3",
.arch = R_SYS_ARCH_X86,
.bits = 32,
.init = NULL,
.fini = NULL,
.op = &myop,
.set_reg_profile = NULL,
.fingerprint_bb = NULL,
.fingerprint_fcn = NULL,
.diff_bb = NULL,
.diff_fcn = NULL,
.diff_eval = NULL
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ANAL,
.data = &r_anal_plugin_x86_simple
};
#endif

View File

@ -1,11 +0,0 @@
OBJ_X86=anal_x86_im.o
OBJ_X86+=../arch/x86/x86im/x86im.o ../arch/x86/x86im/x86im_fmt.o
STATIC_OBJ+=${OBJ_X86}
TARGET_X86=anal_x86.${EXT_SO}
ALL_TARGETS+=${TARGET_X86}
CFLAGS+=-D__X86IM_USE_FMT__
${TARGET_X86}: ${OBJ_X86}
${CC} $(call libname,anal_x86) ${CFLAGS} -o anal_x86_im.${EXT_SO} ${OBJ_X86}

View File

@ -1,12 +0,0 @@
OBJ_X86_SIMPLE=anal_x86_simple.o
OBJ_X86_SIMPLE+=../arch/x86/dislen/dislen.o
STATIC_OBJ+=${OBJ_X86_SIMPLE}
TARGET_X86_SIMPLE=anal_x86_simple.${EXT_SO}
ALL_TARGETS+=${TARGET_X86_SIMPLE}
LIBS_X86_SIMPLE=r_anal r_reg r_lib r_syscall r_diff
MYLIBS=$(subst r_,-L../../,$(LIBS_X86_SIMPLE))
${TARGET_X86_SIMPLE}: ${OBJ_X86_SIMPLE}
${CC} $(call libname,anal_x86_simple) ${MYLIBS} ${LDFLAGS} ${CFLAGS} -o anal_x86_simple.${EXT_SO} ${OBJ_X86_SIMPLE}

97
libr/anal/plugins.jam Normal file
View File

@ -0,0 +1,97 @@
# plugins
OBJS += p/anal_8051.c ;
OBJS += p/anal_bf.c ;
OBJS += p/anal_i8080.c ;
OBJS += p/anal_z80.c ;
# udis86
OBJS += p/anal_x86_udis.c ;
OBJS += p/esil_x86_udis.c ;
EXTRA =
<library>../../shlr/udis86
<include>../../shlr/
;
# sparc
OBJS += p/anal_sparc.c
../asm/arch/sparc/gnu/sparc-dis.c
../asm/arch/sparc/gnu/sparc-opc.c
;
EXTRA += <include>../asm/arch/include ;
# arm
OBJS += p/anal_arm.c
../asm/arch/arm/gnu/arm-dis.c
../asm/arch/arm/aarch64/aarch64-asm-2.c
# ../asm/arch/arm/aarch64/aarch64-gen.c
../asm/arch/arm/aarch64/aarch64-asm.c
../asm/arch/arm/aarch64/aarch64-opc-2.c
../asm/arch/arm/aarch64/aarch64-dis-2.c
../asm/arch/arm/aarch64/aarch64-opc.c
../asm/arch/arm/aarch64/aarch64-dis.c
../asm/arch/arm/winedbg/be_arm.c
;
EXTRA +=
<include>../asm/arch/include
<include>../asm/arch/arm/aarch64/
;
# SH
OBJS += p/anal_sh.c
../asm/arch/sh/gnu/sh-dis.c
;
# MIPS
OBJS += p/anal_mips.c
../asm/arch/mips/gnu/mips-dis.c
../asm/arch/mips/gnu/mips-opc.c
../asm/arch/mips/gnu/mips16-opc.c
;
# PPC
OBJS += p/anal_ppc.c
../asm/arch/ppc/gnu/ppc-dis.c
../asm/arch/ppc/gnu/ppc-opc.c
;
# CSR
OBJS += p/anal_csr.c
../asm/arch/csr/dis.c
;
# M68K
OBJS += p/anal_m68k.c
../asm/arch/m68k/m68k_disasm/m68k_disasm.c
;
# AVR
OBJS += p/anal_avr.c ;
# ARC
OBJS += p/anal_arc.c
../asm/arch/arc/gnu/arc-dis.c
../asm/arch/arc/gnu/arcompact-dis.c
../asm/arch/arc/gnu/arc-ext.c
../asm/arch/arc/gnu/arc-opc.c
;
# EBC
OBJS += p/anal_ebc.c
../asm/arch/ebc/ebc_disas.c
;
# Java
OBJS += p/anal_java.c
../../shlr/java/ops.c
;
# C55PLUS
OBJS += p/anal_c55plus.c
../asm/arch/c55plus/ins.c
;
# DALVIK
OBJS += p/anal_dalvik.c ;
# GB
OBJS += p/anal_gb.c ;

8
libr/asm/Jamroot Normal file
View File

@ -0,0 +1,8 @@
OBJS = asm.c code.c ;
lib r_asm : $(OBJS) : <include>../include <library>../util
<library>../lib
<library>../parse
<library>../syscall
<library>../db
;

View File

@ -2118,6 +2118,7 @@ print_insn_aarch64_word (bfd_vma pc,
uint32_t word,
struct disassemble_info *info)
{
#if 0
static const char *err_msg[6] =
{
[ERR_OK] = "_",
@ -2125,6 +2126,7 @@ print_insn_aarch64_word (bfd_vma pc,
[-ERR_UNP] = "unpredictable",
[-ERR_NYI] = "NYI"
};
#endif
int ret;
aarch64_inst inst;

8
libr/cmd/Jamroot Normal file
View File

@ -0,0 +1,8 @@
OBJS = cmd.c plugin.c macro.c ;
OBJS += p/cmd_dummy.c ;
lib r_cmd : $(OBJS) : <include>../include
<library>../util
<library>../lib
<library>../cons
;

View File

@ -23,12 +23,12 @@ R_API void r_cmd_macro_init(RCmdMacro *mac) {
R_API int r_cmd_macro_add(RCmdMacro *mac, const char *oname) {
struct r_cmd_macro_item_t *macro;
char *name, *args = NULL;
char buf[R_CMD_MAXLEN];
//char buf[R_CMD_MAXLEN];
RCmdMacroItem *m;
int macro_update;
RListIter *iter;
char *pbody;
char *bufp;
// char *bufp;
char *ptr;
int lidx;

11
libr/egg/Jamroot Normal file
View File

@ -0,0 +1,11 @@
OBJS = egg.c lang.c ;
OBJS += emit_x86.c ;
OBJS += emit_arm.c ;
OBJS += emit_x64.c ;
OBJS += emit_trace.c ;
lib r_egg : $(OBJS) : <include>../include
<library>../syscall
<library>../db
<library>../asm
<library>../util ;

View File

@ -633,7 +633,7 @@ void SHA256_Final(sha2_byte digest[], R_SHA256_CTX* context) {
}
/* Clean up state data: */
MEMSET_BZERO(context, sizeof(context));
MEMSET_BZERO(context, sizeof(*context));
usedspace = 0;
}
@ -654,7 +654,7 @@ char *SHA256_End(R_SHA256_CTX* context, char buffer[]) {
}
*buffer = (char)0;
} else {
MEMSET_BZERO(context, sizeof(context));
MEMSET_BZERO(context, sizeof(*context));
}
MEMSET_BZERO(digest, SHA256_DIGEST_LENGTH);
return buffer;
@ -963,7 +963,7 @@ void SHA512_Final(sha2_byte digest[], R_SHA512_CTX* context) {
}
/* Zero out state data */
MEMSET_BZERO(context, sizeof(context));
MEMSET_BZERO(context, sizeof(*context));
}
char *SHA512_End(R_SHA512_CTX* context, char buffer[]) {
@ -983,7 +983,7 @@ char *SHA512_End(R_SHA512_CTX* context, char buffer[]) {
}
*buffer = (char)0;
} else {
MEMSET_BZERO(context, sizeof(context));
MEMSET_BZERO(context, sizeof(*context));
}
MEMSET_BZERO(digest, SHA512_DIGEST_LENGTH);
return buffer;
@ -1038,7 +1038,7 @@ void SHA384_Final(sha2_byte digest[], R_SHA384_CTX* context) {
}
/* Zero out state data */
MEMSET_BZERO(context, sizeof(context));
MEMSET_BZERO(context, sizeof(*context));
}
char *SHA384_End(R_SHA384_CTX* context, char buffer[]) {
@ -1058,17 +1058,15 @@ char *SHA384_End(R_SHA384_CTX* context, char buffer[]) {
}
*buffer = (char)0;
} else {
MEMSET_BZERO(context, sizeof(context));
MEMSET_BZERO(context, sizeof(*context));
}
MEMSET_BZERO(digest, SHA384_DIGEST_LENGTH);
return buffer;
}
char* SHA384_Data(const sha2_byte* data, size_t len, char digest[SHA384_DIGEST_STRING_LENGTH]) {
R_SHA384_CTX context;
SHA384_Init(&context);
SHA384_Update(&context, data, len);
return SHA384_End(&context, digest);
R_SHA384_CTX context;
SHA384_Init (&context);
SHA384_Update (&context, data, len);
return SHA384_End (&context, digest);
}

View File

@ -160,8 +160,8 @@ typedef void (*PrintfCallback)(const char *str, ...);
#define R_ROUND(x,y) ((x)%(y))?(x)+((y)-((x)%(y))):(x)
#define R_DIM(x,y,z) (((x)<(y))?(y):((x)>(z))?(z):(x))
#define R_MAX(x,y) ((x)>(y))?x:y
#define R_MIN(x,y) ((x)>(y))?y:x
#define R_MAX(x,y) (((x)>(y))?(x):(y))
#define R_MIN(x,y) (((x)>(y))?(y):(x))
#define R_ABS(x) (((x)<0)?-(x):(x))
#define R_BTW(x,y,z) (((x)>=(y))&&((y)<=(z)))?y:x

14
libr/parse/Jamroot Normal file
View File

@ -0,0 +1,14 @@
OBJS = parse.c code.c ;
OBJS += p/parse_att2intel.c
p/parse_dalvik_pseudo.c
p/parse_mips_pseudo.c
p/parse_mreplace.c
p/parse_x86_pseudo.c
;
lib r_parse : $(OBJS) : <include>../include
<library>../flags
<library>../lib
<library>../anal
<library>../util
;

4
libr/search/Jamroot Normal file
View File

@ -0,0 +1,4 @@
OBJS = search.c bytepat.c strings.c aes-find.c ;
OBJS += regexp.c xrefs.c keyword.c ;
lib r_search : $(OBJS) : <include>../include <library>../util ;

View File

@ -1229,7 +1229,7 @@ mcadd( struct parse *p, cset *cs, char *cp)
}
cs->multis = np;
strlcpy(cs->multis + oldend - 1, cp, cs->smultis - oldend + 1);
STRLCPY(cs->multis + oldend - 1, cp, cs->smultis - oldend + 1);
}
/*

View File

@ -93,7 +93,7 @@ r_regex_error(int errcode, const RRegex *preg, char *errbuf, size_t errbuf_size)
if (errcode&R_REGEX_ITOA) {
if (r->code != 0) {
(void) strlcpy(convbuf, r->name, sizeof (convbuf)-1);
(void) STRLCPY(convbuf, r->name, sizeof (convbuf)-1);
} else
(void)snprintf(convbuf, sizeof convbuf,
"R_REGEX_0x%x", target);
@ -103,7 +103,7 @@ r_regex_error(int errcode, const RRegex *preg, char *errbuf, size_t errbuf_size)
len = strlen(s) + 1;
if (errbuf_size > 0)
strlcpy(errbuf, s, errbuf_size);
STRLCPY(errbuf, s, errbuf_size);
return(len);
}

View File

@ -41,7 +41,7 @@
#define INFINITY (DUPMAX + 1)
#define NC (CHAR_MAX - CHAR_MIN + 1)
#define strlcpy(x,y,z) strncpy((x),(y),(z));(x)[(z)]=0;
#define STRLCPY(x,y,z) strncpy((x),(y),(z));(x)[(z)]=0;
/* switch off assertions (if not already off) if no REDEBUG */
#ifndef REDEBUG

View File

@ -33,9 +33,7 @@ asm.gb
asm.snes
asm.ebc
anal.sh
anal.x86_im
anal.x86_udis
anal.x86_simple
anal.z80
anal.8051
anal.i8080

5
shlr/java/Jamroot Normal file
View File

@ -0,0 +1,5 @@
lib java : code.c class.c ops.c :
<include>../../libr/include
<library>../../libr/util
<library>../sdb
;

3
shlr/udis86/Jamroot Normal file
View File

@ -0,0 +1,3 @@
OBJS = decode.c itab.c syn-att.c syn-intel.c syn.c udis86.c ;
lib udis86 : $(OBJS) : <link>static ;

View File

@ -28,11 +28,7 @@
#include "extern.h"
#include "decode.h"
#if !defined(__UD_STANDALONE__)
# if HAVE_STRING_H
# include <string.h>
# endif
#endif /* !__UD_STANDALONE__ */
static void ud_inp_init(struct ud *u);