* r_anal
- Added initial anal_x86_bea plugin (op analysis using bea engine)
'ao' command in radare2
- Minor fixups
* r_asm
- Modified r_asm_aop_t to fit r_anal requirements
- Updated r_asm plugins
* r_parse
- Removed several warnings from mreplace
- Removed unnecessary includes
This commit is contained in:
parent
1d5162d8e3
commit
ea44bb103a
23 changed files with 449 additions and 54 deletions
|
|
@ -51,7 +51,7 @@ int r_anal_set(struct r_anal_t *anal, const char *name)
|
|||
int r_anal_aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
|
||||
{
|
||||
if (anal->cur && anal->cur->aop)
|
||||
return anal->cur->aop(aop, data);
|
||||
return anal->cur->aop(anal, aop, data);
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,19 @@
|
|||
CFLAGS=-I../../include -Wall
|
||||
BINDEPS=
|
||||
CFLAGS=-I../../include -I../../asm/arch/ -I../arch/include -Wall -fPIC -shared -Wl,-R..
|
||||
|
||||
all: anal_dummy.so anal_x86.so
|
||||
all: anal_dummy.so anal_x86.so anal_x86_bea.so
|
||||
@true
|
||||
|
||||
anal_dummy.so: anal_dummy.o
|
||||
${CC} ${CFLAGS} -fPIC -shared -o anal_dummy.so anal_dummy.c -Wl,-R..
|
||||
${CC} ${CFLAGS} -o anal_dummy.so anal_dummy.o
|
||||
@#strip -s anal_dummy.so
|
||||
|
||||
anal_x86.so: anal_x86.o
|
||||
${CC} ${CFLAGS} -fPIC -shared -o anal_x86.so anal_x86.c -Wl,-R..
|
||||
${CC} ${CFLAGS} -o anal_x86.so anal_x86.o
|
||||
@#strip -s anal_x86.so
|
||||
|
||||
anal_x86_bea.so: anal_x86_bea.o
|
||||
${CC} ${CFLAGS} -o anal_x86_bea.so anal_x86_bea.o
|
||||
@#strip -s anal_x86_bea.so
|
||||
|
||||
clean:
|
||||
-rm -f *.so *.o
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include <r_lib.h>
|
||||
#include <r_anal.h>
|
||||
|
||||
static int aop(struct r_anal_aop_t *aop, void *data)
|
||||
static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
|
||||
{
|
||||
printf("Dummy analysis plugin");
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ static int aop(struct r_anal_aop_t *aop, void *data)
|
|||
}
|
||||
|
||||
static struct r_anal_handle_t r_anal_plugin_dummy = {
|
||||
.name = "dummy",
|
||||
.name = "anal_dummy",
|
||||
.desc = "Dummy analysis plugin",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
|
|
|
|||
|
|
@ -23,8 +23,9 @@
|
|||
|
||||
// NOTE: buf should be at least 16 bytes!
|
||||
// XXX addr should be off_t for 64 love
|
||||
static int aop(struct r_anal_aop_t *aop, void *data)
|
||||
static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
|
||||
{
|
||||
#if 0
|
||||
struct r_asm_aop_t *asmdata = (struct r_asm_t*)data;
|
||||
u8 *buf = asmdata->buf;
|
||||
|
||||
|
|
@ -399,6 +400,8 @@ static int aop(struct r_anal_aop_t *aop, void *data)
|
|||
aop->jump &= 0xFFFFFFFF; // XXX may break on 64 bits here
|
||||
|
||||
return aop->length;
|
||||
#endif
|
||||
return R_FALSE;
|
||||
}
|
||||
|
||||
static struct r_anal_handle_t r_anal_plugin_x86 = {
|
||||
|
|
|
|||
383
libr/anal/p/anal_x86_bea.c
Normal file
383
libr/anal/p/anal_x86_bea.c
Normal file
|
|
@ -0,0 +1,383 @@
|
|||
/* radare - GPL3 - Copyright 2009 nibble<.ds@gmail.com> */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_util.h>
|
||||
#include <r_anal.h>
|
||||
|
||||
#include "x86/bea/BeaEngine.h"
|
||||
|
||||
|
||||
static int aop(struct r_anal_t *anal, struct r_anal_aop_t *aop, void *data)
|
||||
{
|
||||
DISASM *disasm_obj = (DISASM *)data;
|
||||
ARGTYPE *argptr;
|
||||
char category[1024], argtype[1024];
|
||||
int i;
|
||||
|
||||
|
||||
printf( "[Instruction]\n"
|
||||
" Opcode: %lx\n"
|
||||
" Mnemonic: %s\n"
|
||||
" AddrValue: 0x%llx\n"
|
||||
" Immediate: 0x%llx\n",
|
||||
disasm_obj->Instruction.Opcode,
|
||||
disasm_obj->Instruction.Mnemonic,
|
||||
disasm_obj->Instruction.AddrValue,
|
||||
disasm_obj->Instruction.Immediat);
|
||||
|
||||
category[0] = '\0';
|
||||
if (disasm_obj->Instruction.Category & GENERAL_PURPOSE_INSTRUCTION)
|
||||
strcat(category, "GENERAL_PURPOSE_INSTRUCTION ");
|
||||
if (disasm_obj->Instruction.Category & FPU_INSTRUCTION)
|
||||
strcat(category, "FPU_INSTRUCTION ");
|
||||
if (disasm_obj->Instruction.Category & MMX_INSTRUCTION)
|
||||
strcat(category, "MMX_INSTRUCTION ");
|
||||
if (disasm_obj->Instruction.Category & SSE_INSTRUCTION)
|
||||
strcat(category, "SSE_INSTRUCTION ");
|
||||
if (disasm_obj->Instruction.Category & SSE2_INSTRUCTION)
|
||||
strcat(category, "SSE2_INSTRUCTION ");
|
||||
if (disasm_obj->Instruction.Category & SSE3_INSTRUCTION)
|
||||
strcat(category, "SSE3_INSTRUCTION ");
|
||||
if (disasm_obj->Instruction.Category & SSSE3_INSTRUCTION)
|
||||
strcat(category, "SSSE3_INSTRUCTION ");
|
||||
if (disasm_obj->Instruction.Category & SSE41_INSTRUCTION)
|
||||
strcat(category, "SSE41_INSTRUCTION ");
|
||||
if (disasm_obj->Instruction.Category & SSE42_INSTRUCTION)
|
||||
strcat(category, "SSE42_INSTRUCTION ");
|
||||
if (disasm_obj->Instruction.Category & SYSTEM_INSTRUCTION)
|
||||
strcat(category, "SYSTEM_INSTRUCTION ");
|
||||
if (disasm_obj->Instruction.Category & VM_INSTRUCTION)
|
||||
strcat(category, "VM_INSTRUCTION ");
|
||||
if (disasm_obj->Instruction.Category & UNDOCUMENTED_INSTRUCTION)
|
||||
strcat(category, "UNDOCUMENTED_INSTRUCTION ");
|
||||
if (disasm_obj->Instruction.Category & AMD_INSTRUCTION)
|
||||
strcat(category, "AMD_INSTRUCTION ");
|
||||
if (disasm_obj->Instruction.Category & ILLEGAL_INSTRUCTION)
|
||||
strcat(category, "ILLEGAL_INSTRUCTION ");
|
||||
if (disasm_obj->Instruction.Category & INCOMPATIBLE_TYPE)
|
||||
strcat(category, "INCOMPATIBLE_TYPE ");
|
||||
disasm_obj->Instruction.Category &= 0xFFFF;
|
||||
|
||||
switch (disasm_obj->Instruction.Category) {
|
||||
case DATA_TRANSFER:
|
||||
strcat(category, "DATA_TRANSFER ");
|
||||
break;
|
||||
case ARITHMETIC_INSTRUCTION:
|
||||
strcat(category, "ARITHMETIC_INSTRUCTION ");
|
||||
break;
|
||||
case LOGICAL_INSTRUCTION:
|
||||
strcat(category, "LOGICAL_INSTRUCTION ");
|
||||
break;
|
||||
case SHIFT_ROTATE:
|
||||
strcat(category, "SHIFT_ROTATE ");
|
||||
break;
|
||||
case BIT_BYTE:
|
||||
strcat(category, "BIT_BYTE ");
|
||||
break;
|
||||
case CONTROL_TRANSFER:
|
||||
strcat(category, "CONTROL_TRANSFER ");
|
||||
break;
|
||||
case STRING_INSTRUCTION:
|
||||
strcat(category, "STRING_INSTRUCTION ");
|
||||
break;
|
||||
case InOutINSTRUCTION:
|
||||
strcat(category, "InOutINSTRUCTION ");
|
||||
break;
|
||||
case ENTER_LEAVE_INSTRUCTION:
|
||||
strcat(category, "ENTER_LEAVE_INSTRUCTION ");
|
||||
break;
|
||||
case FLAG_CONTROL_INSTRUCTION:
|
||||
strcat(category, "FLAG_CONTROL_INSTRUCTION ");
|
||||
break;
|
||||
case SEGMENT_REGISTER:
|
||||
strcat(category, "SEGMENT_REGISTER ");
|
||||
break;
|
||||
case MISCELLANEOUS_INSTRUCTION:
|
||||
strcat(category, "MISCELLANEOUS_INSTRUCTION ");
|
||||
break;
|
||||
case COMPARISON_INSTRUCTION:
|
||||
strcat(category, "COMPARISON_INSTRUCTION ");
|
||||
break;
|
||||
case LOGARITHMIC_INSTRUCTION:
|
||||
strcat(category, "LOGARITHMIC_INSTRUCTION ");
|
||||
break;
|
||||
case TRIGONOMETRIC_INSTRUCTION:
|
||||
strcat(category, "TRIGONOMETRIC_INSTRUCTION ");
|
||||
break;
|
||||
case UNSUPPORTED_INSTRUCTION:
|
||||
strcat(category, "UNSUPPORTED_INSTRUCTION ");
|
||||
break;
|
||||
case LOAD_CONSTANTS:
|
||||
strcat(category, "LOAD_CONSTANTS ");
|
||||
break;
|
||||
case FPUCONTROL:
|
||||
strcat(category, "FPUCONTROL ");
|
||||
break;
|
||||
case STATE_MANAGEMENT:
|
||||
strcat(category, "STATE_MANAGEMENT ");
|
||||
break;
|
||||
case CONVERSION_INSTRUCTION:
|
||||
strcat(category, "CONVERSION_INSTRUCTION ");
|
||||
break;
|
||||
case SHUFFLE_UNPACK:
|
||||
strcat(category, "SHUFFLE_UNPACK ");
|
||||
break;
|
||||
case PACKED_SINGLE_PRECISION:
|
||||
strcat(category, "PACKED_SINGLE_PRECISION ");
|
||||
break;
|
||||
case SIMD128bits:
|
||||
strcat(category, "SIMD128bits ");
|
||||
break;
|
||||
case SIMD64bits:
|
||||
strcat(category, "SIMD64bits ");
|
||||
break;
|
||||
case CACHEABILITY_CONTROL:
|
||||
strcat(category, "CACHEABILITY_CONTROL ");
|
||||
break;
|
||||
case FP_INTEGER_CONVERSION:
|
||||
strcat(category, "FP_INTEGER_CONVERSION ");
|
||||
break;
|
||||
case SPECIALIZED_128bits:
|
||||
strcat(category, "SPECIALIZED_128bits ");
|
||||
break;
|
||||
case SIMD_FP_PACKED:
|
||||
strcat(category, "SIMD_FP_PACKED ");
|
||||
break;
|
||||
case SIMD_FP_HORIZONTAL :
|
||||
strcat(category, "SIMD_FP_HORIZONTAL ");
|
||||
break;
|
||||
case AGENT_SYNCHRONISATION:
|
||||
strcat(category, "AGENT_SYNCHRONISATION ");
|
||||
break;
|
||||
case PACKED_ALIGN_RIGHT :
|
||||
strcat(category, "PACKED_ALIGN_RIGHT ");
|
||||
break;
|
||||
case PACKED_SIGN:
|
||||
strcat(category, "PACKED_SIGN ");
|
||||
break;
|
||||
case PACKED_BLENDING_INSTRUCTION:
|
||||
strcat(category, "PACKED_BLENDING_INSTRUCTION ");
|
||||
break;
|
||||
case PACKED_TEST:
|
||||
strcat(category, "PACKED_TEST ");
|
||||
break;
|
||||
case PACKED_MINMAX:
|
||||
strcat(category, "PACKED_MINMAX ");
|
||||
break;
|
||||
case HORIZONTAL_SEARCH:
|
||||
strcat(category, "HORIZONTAL_SEARCH ");
|
||||
break;
|
||||
case PACKED_EQUALITY:
|
||||
strcat(category, "PACKED_EQUALITY ");
|
||||
break;
|
||||
case STREAMING_LOAD:
|
||||
strcat(category, "STREAMING_LOAD ");
|
||||
break;
|
||||
case INSERTION_EXTRACTION:
|
||||
strcat(category, "INSERTION_EXTRACTION ");
|
||||
break;
|
||||
case DOT_PRODUCT:
|
||||
strcat(category, "DOT_PRODUCT ");
|
||||
break;
|
||||
case SAD_INSTRUCTION:
|
||||
strcat(category, "SAD_INSTRUCTION ");
|
||||
break;
|
||||
case ACCELERATOR_INSTRUCTION:
|
||||
strcat(category, "ACCELERATOR_INSTRUCTION ");
|
||||
break;
|
||||
case ROUND_INSTRUCTION:
|
||||
strcat(category, "ROUND_INSTRUCTION ");
|
||||
break;
|
||||
default:
|
||||
strcat(category, "UNKNOWN_INSTRUCTION ");
|
||||
}
|
||||
printf(" Category: %s\n", category);
|
||||
|
||||
switch (disasm_obj->Instruction.BranchType) {
|
||||
case JO:
|
||||
printf(" BranchType: JO\n");
|
||||
break;
|
||||
case JC:
|
||||
printf(" BranchType: JC\n");
|
||||
break;
|
||||
case JE:
|
||||
printf(" BranchType: JE\n");
|
||||
break;
|
||||
case JA:
|
||||
printf(" BranchType: JA\n");
|
||||
break;
|
||||
case JS:
|
||||
printf(" BranchType: JS\n");
|
||||
break;
|
||||
case JP:
|
||||
printf(" BranchType: JP\n");
|
||||
break;
|
||||
case JL:
|
||||
printf(" BranchType: JL\n");
|
||||
break;
|
||||
case JG:
|
||||
printf(" BranchType: JG\n");
|
||||
break;
|
||||
case JB:
|
||||
printf(" BranchType: JB\n");
|
||||
break;
|
||||
case JECXZ:
|
||||
printf(" BranchType: JECXZ\n");
|
||||
break;
|
||||
case JmpType:
|
||||
printf(" BranchType: JmpType\n");
|
||||
break;
|
||||
case CallType:
|
||||
printf(" BranchType: CallType\n");
|
||||
break;
|
||||
case RetType:
|
||||
printf(" BranchType: RetType\n");
|
||||
break;
|
||||
case JNO:
|
||||
printf(" BranchType: JNO\n");
|
||||
break;
|
||||
case JNC:
|
||||
printf(" BranchType: JNC\n");
|
||||
break;
|
||||
case JNE:
|
||||
printf(" BranchType: JNE\n");
|
||||
break;
|
||||
case JNA:
|
||||
printf(" BranchType: JNA\n");
|
||||
break;
|
||||
case JNS:
|
||||
printf(" BranchType: JNS\n");
|
||||
break;
|
||||
case JNP:
|
||||
printf(" BranchType: JNP\n");
|
||||
break;
|
||||
case JNL:
|
||||
printf(" BranchType: JNL\n");
|
||||
break;
|
||||
case JNG:
|
||||
printf(" BranchType: JNG\n");
|
||||
break;
|
||||
case JNB:
|
||||
printf(" BranchType: JNB\n");
|
||||
break;
|
||||
default:
|
||||
printf(" BranchType: Unknown (0x%lx)\n", disasm_obj->Instruction.BranchType);
|
||||
}
|
||||
|
||||
|
||||
for(argptr = &disasm_obj->Argument1, i = 0; i< 3; i++) {
|
||||
if (argptr[i].ArgMnemonic[0] == '\0')
|
||||
continue;
|
||||
|
||||
printf( "[ARG%i]\n"
|
||||
" Mnemonic: %s\n"
|
||||
" ArgSize: 0x%lx\n"
|
||||
" BaseRegister: 0x%lx\n"
|
||||
" IndexRegister: 0x%lx\n"
|
||||
" Scale: 0x%lx\n"
|
||||
" Displacement: 0x%llx\n"
|
||||
" SegmentReg: 0x%lx\n",
|
||||
i + 1,
|
||||
argptr[i].ArgMnemonic,
|
||||
argptr[i].ArgSize,
|
||||
argptr[i].Memory.BaseRegister,
|
||||
argptr[i].Memory.IndexRegister,
|
||||
argptr[i].Memory.Scale,
|
||||
argptr[i].Memory.Displacement,
|
||||
argptr[i].SegmentReg
|
||||
);
|
||||
|
||||
printf(" AccesMode: ");
|
||||
if (argptr[i].AccessMode == 0x1)
|
||||
printf("READ\n");
|
||||
else if (argptr[i].AccessMode == 0x2)
|
||||
printf("WRITE\n");
|
||||
else printf("UNKNOWN\n");
|
||||
|
||||
argtype[0] = '\0';
|
||||
if (argptr[i].ArgType & NO_ARGUMENT)
|
||||
strcat(argtype, "NO_ARGUMENT ");
|
||||
if (argptr[i].ArgType & REGISTER_TYPE)
|
||||
strcat(argtype, "REGISTER_TYPE ");
|
||||
if (argptr[i].ArgType & MEMORY_TYPE)
|
||||
strcat(argtype, "MEMORY_TYPE ");
|
||||
if (argptr[i].ArgType & CONSTANT_TYPE)
|
||||
strcat(argtype, "CONSTANT_TYPE ");
|
||||
if (argptr[i].ArgType & MMX_REG)
|
||||
strcat(argtype, "MMX_REG ");
|
||||
if (argptr[i].ArgType & GENERAL_REG)
|
||||
strcat(argtype, "GENERAL_REG ");
|
||||
if (argptr[i].ArgType & FPU_REG)
|
||||
strcat(argtype, "FPU_REG ");
|
||||
if (argptr[i].ArgType & SSE_REG)
|
||||
strcat(argtype, "SSE_REG ");
|
||||
if (argptr[i].ArgType & CR_REG)
|
||||
strcat(argtype, "CR_REG ");
|
||||
if (argptr[i].ArgType & DR_REG)
|
||||
strcat(argtype, "DR_REG ");
|
||||
if (argptr[i].ArgType & SPECIAL_REG)
|
||||
strcat(argtype, "SPECIAL_REG ");
|
||||
if (argptr[i].ArgType & MEMORY_MANAGEMENT_REG)
|
||||
strcat(argtype, "MEMORY_MANAGEMENT_REG ");
|
||||
if (argptr[i].ArgType & SEGMENT_REG)
|
||||
strcat(argtype, "SEGMENT_REG ");
|
||||
if (argptr[i].ArgType & RELATIVE_)
|
||||
strcat(argtype, "RELATIVE_ ");
|
||||
if (argptr[i].ArgType & ABSOLUTE_)
|
||||
strcat(argtype, "ABSOLUTE_ ");
|
||||
if (argptr[i].ArgType & REG0)
|
||||
strcat(argtype, "REG0 ");
|
||||
if (argptr[i].ArgType & REG1)
|
||||
strcat(argtype, "REG1 ");
|
||||
if (argptr[i].ArgType & REG2)
|
||||
strcat(argtype, "REG2 ");
|
||||
if (argptr[i].ArgType & REG3)
|
||||
strcat(argtype, "REG3 ");
|
||||
if (argptr[i].ArgType & REG4)
|
||||
strcat(argtype, "REG4 ");
|
||||
if (argptr[i].ArgType & REG5)
|
||||
strcat(argtype, "REG5 ");
|
||||
if (argptr[i].ArgType & REG6)
|
||||
strcat(argtype, "REG6 ");
|
||||
if (argptr[i].ArgType & REG7)
|
||||
strcat(argtype, "REG7 ");
|
||||
if (argptr[i].ArgType & REG8)
|
||||
strcat(argtype, "REG8 ");
|
||||
if (argptr[i].ArgType & REG9)
|
||||
strcat(argtype, "REG9 ");
|
||||
if (argptr[i].ArgType & REG10)
|
||||
strcat(argtype, "REG10 ");
|
||||
if (argptr[i].ArgType & REG11)
|
||||
strcat(argtype, "REG11 ");
|
||||
if (argptr[i].ArgType & REG12)
|
||||
strcat(argtype, "REG12 ");
|
||||
if (argptr[i].ArgType & REG13)
|
||||
strcat(argtype, "REG13 ");
|
||||
if (argptr[i].ArgType & REG14)
|
||||
strcat(argtype, "REG14 ");
|
||||
if (argptr[i].ArgType & REG15)
|
||||
strcat(argtype, "REG15 ");
|
||||
printf(" ArgType: %s\n", argtype);
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
static struct r_anal_handle_t r_anal_plugin_x86_bea = {
|
||||
.name = "anal_x86_bea",
|
||||
.desc = "X86 analysis plugin (Bea engine)",
|
||||
.init = NULL,
|
||||
.fini = NULL,
|
||||
.aop = &aop
|
||||
};
|
||||
|
||||
struct r_lib_struct_t radare_plugin = {
|
||||
.type = R_LIB_TYPE_ANAL,
|
||||
.data = &r_anal_plugin_x86_bea
|
||||
};
|
||||
|
|
@ -58,7 +58,7 @@ static int buf_fprintf(void *stream, const char *format, ...)
|
|||
|
||||
static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64 len)
|
||||
{
|
||||
struct disassemble_info disasm_obj;
|
||||
static struct disassemble_info disasm_obj;
|
||||
|
||||
buf_global = aop->buf_asm;
|
||||
Offset = a->pc;
|
||||
|
|
@ -80,6 +80,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
|
||||
aop->buf_asm[0]='\0';
|
||||
aop->inst_len = print_insn_arm((bfd_vma)Offset, &disasm_obj);
|
||||
aop->disasm_obj = &disasm_obj;
|
||||
|
||||
if (aop->inst_len == -1)
|
||||
strcpy(aop->buf_asm, " (data)");
|
||||
|
|
|
|||
|
|
@ -61,6 +61,8 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
if (i>0) sprintf(aop->buf_asm, "%s, %d", aop->buf_asm, i+1);
|
||||
if (i<1) i=1; else i++;
|
||||
|
||||
aop->disasm_obj = NULL;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
arch_csr_disasm(aop->buf_asm, buf, a->pc);
|
||||
memcpy(aop->buf, buf, 2);
|
||||
aop->inst_len = 2;
|
||||
aop->disasm_obj = NULL;
|
||||
|
||||
return aop->inst_len;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
char opcode[256];
|
||||
char operands[256];
|
||||
|
||||
struct DisasmPara_68k dp;
|
||||
static struct DisasmPara_68k dp;
|
||||
/* initialize DisasmPara */
|
||||
memcpy(bof, buf, 4);
|
||||
dp.opcode = opcode;
|
||||
|
|
@ -26,6 +26,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
dp.iaddr = &iaddr;
|
||||
dp.instr = bof;
|
||||
M68k_Disassemble(&dp);
|
||||
aop->disasm_obj = &dp;
|
||||
sprintf(aop->buf_asm, "%s %s", opcode, operands);
|
||||
r_hex_bin2str((u8*)bof, 4, aop->buf_hex);
|
||||
memcpy(aop->buf, bof, 4);
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ static int buf_fprintf(void *stream, const char *format, ...)
|
|||
|
||||
static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64 len)
|
||||
{
|
||||
struct disassemble_info disasm_obj;
|
||||
static struct disassemble_info disasm_obj;
|
||||
|
||||
buf_global = aop->buf_asm;
|
||||
Offset = a->pc;
|
||||
|
|
@ -84,6 +84,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
if (a->big_endian)
|
||||
aop->inst_len = print_insn_big_mips((bfd_vma)Offset, &disasm_obj);
|
||||
else aop->inst_len = print_insn_little_mips((bfd_vma)Offset, &disasm_obj);
|
||||
aop->disasm_obj = &disasm_obj;
|
||||
|
||||
if (aop->inst_len == -1)
|
||||
strcpy(aop->buf_asm, " (data)");
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
char opcode[128];
|
||||
char operands[128];
|
||||
|
||||
struct DisasmPara_PPC dp;
|
||||
static struct DisasmPara_PPC dp;
|
||||
/* initialize DisasmPara */
|
||||
memcpy(bof, buf, 4);
|
||||
dp.opcode = opcode;
|
||||
|
|
@ -26,6 +26,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
dp.iaddr = &iaddr;
|
||||
dp.instr = bof;
|
||||
PPC_Disassemble(&dp, a->big_endian);
|
||||
aop->disasm_obj = &dp;
|
||||
r_hex_bin2str((u8*)bof, 4, aop->buf_hex);
|
||||
sprintf(aop->buf_asm, "%s %s", opcode, operands);
|
||||
memcpy(aop->buf, bof, 4);
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ static int buf_fprintf(void *stream, const char *format, ...)
|
|||
|
||||
static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64 len)
|
||||
{
|
||||
struct disassemble_info disasm_obj;
|
||||
static struct disassemble_info disasm_obj;
|
||||
|
||||
buf_global = aop->buf_asm;
|
||||
Offset = a->pc;
|
||||
|
|
@ -79,6 +79,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
|
||||
aop->buf_asm[0]='\0';
|
||||
aop->inst_len = print_insn_sparc((bfd_vma)Offset, &disasm_obj);
|
||||
aop->disasm_obj = &disasm_obj;
|
||||
|
||||
if (aop->inst_len == -1)
|
||||
strcpy(aop->buf_asm, " (data)");
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64 len)
|
||||
{
|
||||
ud_t disasm_obj;
|
||||
static ud_t disasm_obj;
|
||||
|
||||
ud_init(&disasm_obj);
|
||||
if (a->syntax == R_ASM_SYN_ATT)
|
||||
|
|
@ -24,6 +24,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
ud_set_pc(&disasm_obj, a->pc);
|
||||
ud_set_input_buffer(&disasm_obj, buf, len);
|
||||
ud_disassemble(&disasm_obj);
|
||||
aop->disasm_obj = &disasm_obj;
|
||||
aop->inst_len = ud_insn_len(&disasm_obj);
|
||||
snprintf(aop->buf_asm, 256, "%s", ud_insn_asm(&disasm_obj));
|
||||
snprintf(aop->buf_hex, 256, "%s", ud_insn_hex(&disasm_obj));
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64 len)
|
||||
{
|
||||
DISASM disasm_obj;
|
||||
static DISASM disasm_obj;
|
||||
|
||||
memset(&disasm_obj, '\0', sizeof(DISASM));
|
||||
disasm_obj.EIP = (long long)buf;
|
||||
|
|
@ -26,6 +26,7 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
disasm_obj.Options = 0;
|
||||
|
||||
aop->inst_len = Disasm(&disasm_obj);
|
||||
aop->disasm_obj = &disasm_obj;
|
||||
|
||||
snprintf(aop->buf_asm, 256, disasm_obj.CompleteInstr);
|
||||
|
||||
|
|
|
|||
|
|
@ -27,13 +27,14 @@ static int disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, u8 *buf, u64
|
|||
|
||||
static int assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
|
||||
{
|
||||
t_asmmodel asm_obj;
|
||||
static t_asmmodel asm_obj;
|
||||
int idx;
|
||||
|
||||
aop->buf_err[0] = '\0';
|
||||
/* constsize == 0: Address constants and inmediate data of 16/32b */
|
||||
/* attempt == 0: First attempt */
|
||||
aop->inst_len = Assemble(buf, a->pc, &asm_obj, 0, 0, aop->buf_err);
|
||||
aop->disasm_obj = &asm_obj;
|
||||
if (aop->buf_err[0])
|
||||
aop->inst_len = 0;
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@
|
|||
#include "r_flags.h"
|
||||
#include "r_hash.h"
|
||||
#include "r_asm.h"
|
||||
#include "r_anal.h"
|
||||
|
||||
/* Ugly */
|
||||
#include "../asm/arch/x86/bea/BeaEngine.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
|
|
@ -415,28 +419,25 @@ static int cmd_anal(void *data, const char *input)
|
|||
r_anal_list(&core->anal);
|
||||
break;
|
||||
case 'o':
|
||||
#if 0
|
||||
{
|
||||
/* XXX hardcoded */
|
||||
int ret, idx;
|
||||
u8 *buf = core->block;
|
||||
struct r_asm_t a;// TODO: move to core.h
|
||||
struct r_anal_aop_t aop;
|
||||
r_asm_init(&a);
|
||||
r_asm_set_pc(&a, core->seek);
|
||||
r_anal_set(&core->anal, "anal_x86");
|
||||
struct r_asm_aop_t aop;
|
||||
struct r_anal_aop_t analop;
|
||||
DISASM *disasm_obj;
|
||||
r_asm_set(&core->assembler, "asm_x86_bea");
|
||||
r_anal_set(&core->anal, "anal_x86_bea");
|
||||
r_asm_set_pc(&core->assembler, core->seek);
|
||||
r_anal_set_pc(&core->anal, core->seek);
|
||||
|
||||
for(idx=ret=0; idx < len; idx+=ret) {
|
||||
r_asm_set_pc(&a, a.pc + ret);
|
||||
ret = r_asm_disasm(&a, buf+idx, len-idx);
|
||||
r_cons_printf("0x%08llx %14s %s\n",
|
||||
core->seek+idx, a.buf_hex, a.buf_asm);
|
||||
r_anal_aop(&core->anal, &aop, &a);
|
||||
r_cons_printf("JUMP: 0x%08llx\n",
|
||||
aop.jump);
|
||||
r_asm_set_pc(&core->assembler, core->assembler.pc + ret);
|
||||
ret = r_asm_disassemble(&core->assembler, &aop, buf+idx, len-idx);
|
||||
disasm_obj = aop.disasm_obj;
|
||||
r_anal_aop(&core->anal, &analop, disasm_obj);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Usage: a[o] [len]\n"
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ struct r_anal_handle_t {
|
|||
char *desc;
|
||||
int (*init)(void *user);
|
||||
int (*fini)(void *user);
|
||||
int (*aop)(struct r_anal_aop_t *aop, void *data);
|
||||
int (*aop)(struct r_anal_t *a, struct r_anal_aop_t *aop, void *data);
|
||||
struct list_head list;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ struct r_asm_aop_t {
|
|||
char buf_asm[256];
|
||||
char buf_hex[256];
|
||||
char buf_err[256];
|
||||
void *disasm_obj;
|
||||
};
|
||||
|
||||
struct r_asm_t {
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ void memCopy(memChunk *dest,memChunk *source){
|
|||
}
|
||||
|
||||
void memStrCat(memChunk *dest,char *string){
|
||||
long nbytes;
|
||||
//long nbytes;
|
||||
memChunk result,*temp;
|
||||
|
||||
temp = memReserve(dest->size+strlen(string)+1);
|
||||
|
|
|
|||
|
|
@ -62,15 +62,15 @@ void sreplace(char *s,char *orig,char *rep,char multi,long dsize){
|
|||
|
||||
char *mreplace(char *string, char *se,char *rep)
|
||||
{
|
||||
int status,m,i;
|
||||
char *s;
|
||||
int status,i; //,m;
|
||||
//char *s;
|
||||
regex_t re;
|
||||
size_t nmatch = 16;
|
||||
regmatch_t pm[nmatch];
|
||||
char regError[64],*p;
|
||||
char *p; //,regError[64];
|
||||
ulong offset = 0;
|
||||
char field[16];
|
||||
char *sData;
|
||||
//char *sData;
|
||||
memChunk *result,*temp,*found,*ffound;
|
||||
char *search;
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ char *mreplace(char *string, char *se,char *rep)
|
|||
if(matchs(search,"\\d")) sreplace(search,"\\d","[0-9]\0",1,6);
|
||||
|
||||
if(regcomp(&re, search, REG_EXTENDED) != 0) if(regcomp(&re, search, REG_EXTENDED<<1)) return (char*)string;
|
||||
if(status = regexec(&re, string, nmatch, pm, 0)) return (char*)string;
|
||||
if((status = regexec(&re, string, nmatch, pm, 0))) return (char*)string;
|
||||
found = memReserve(INPUTLINE_BUFFER_REPLACE_SIZE);
|
||||
ffound = memReserve(INPUTLINE_BUFFER_REPLACE_SIZE);
|
||||
while(!status){
|
||||
|
|
@ -140,11 +140,11 @@ char *mreplace(char *string, char *se,char *rep)
|
|||
}
|
||||
|
||||
char *treplace(char *data,char *search,char *replace){
|
||||
long offset=0,f;
|
||||
//long offset=0,f;
|
||||
char line[INPUTLINE_BUFFER_REPLACE_SIZE],*newline,*p;
|
||||
|
||||
memChunk *result;
|
||||
ulong resultAllocSize;
|
||||
//ulong resultAllocSize;
|
||||
|
||||
#if DEBUG2
|
||||
DBG("treplace(string,se,re)","string : %s",data);
|
||||
|
|
@ -174,7 +174,7 @@ char *treplace(char *data,char *search,char *replace){
|
|||
|
||||
void doChecks(){
|
||||
char *checkBuffer,*checkresult,*sIn;
|
||||
long i,n,total,invalid=0;
|
||||
long i,n,total; //,invalid=0;
|
||||
typedef struct {char *in,*s,*r,*out;} sCheck;
|
||||
sCheck checks[]={
|
||||
{"{{div.cOptions}}go {{tag.tag56}} {{get.link.parent.html}}/ edit {{tag.tag57}} / edit {{tag.tag58}} / rename {{tag.tag59}} / move {{tag.tag60}} / add {{tag.tag61}}{{get.delete.html}} / {{get.link.login.html}}{{enddiv}}", ".*(\\{\\{\\w+\\.\\w+(\\.\\w+)?\\}\\}).*","\\1","{{get.delete.html}}"},
|
||||
|
|
@ -207,12 +207,12 @@ void doChecks(){
|
|||
sIn=strdup(checks[i].in);
|
||||
if(strlen(sIn)>20) memcpy(sIn+15," ...\0",5);
|
||||
if(strcmp(checkresult,checks[i].out)){
|
||||
fprintf(stderr,"\r[%d/%d] %-20s s: %-30s r: %-20s => %-25s ",i+1,total,sIn,checks[i].s,checks[i].r,checkresult);
|
||||
fprintf(stderr,"\r[%ld/%ld] %-20s s: %-30s r: %-20s => %-25s ",i+1,total,sIn,checks[i].s,checks[i].r,checkresult);
|
||||
fprintf(stdout," ERR :(\n");
|
||||
exit(0);
|
||||
}else{
|
||||
if(!n){
|
||||
fprintf(stderr,"\r[%d/%d] %-20s s: %-30s r: %-20s => %-25s ",i+1,total,sIn,checks[i].s,checks[i].r,checkresult);
|
||||
fprintf(stderr,"\r[%ld/%ld] %-20s s: %-30s r: %-20s => %-25s ",i+1,total,sIn,checks[i].s,checks[i].r,checkresult);
|
||||
fprintf(stdout," OK :)\n");
|
||||
}
|
||||
}
|
||||
|
|
@ -220,7 +220,7 @@ void doChecks(){
|
|||
}
|
||||
|
||||
for(n=1;n<=CHECKS_CHUNCK_COUNT;n+=1+CHECKS_CHUNCK_COUNT/10){
|
||||
fprintf(stdout,"\r[ + ] Checking stability for different input sizes consistence %d bytes, memory allocated: %d bytes",n*CHECKS_CHUNCK_COUNT*CHECKS_CHUNCK_SIZE,memAllocated());
|
||||
fprintf(stdout,"\r[ + ] Checking stability for different input sizes consistence %ld bytes, memory allocated: %ld bytes",n*CHECKS_CHUNCK_COUNT*CHECKS_CHUNCK_SIZE,memAllocated());
|
||||
fflush(stdout);
|
||||
memset(checkBuffer,'.',n*CHECKS_CHUNCK_SIZE-1);
|
||||
checkBuffer[n*CHECKS_CHUNCK_SIZE]=0;
|
||||
|
|
@ -228,8 +228,9 @@ void doChecks(){
|
|||
treplace(checkBuffer,"_",".");
|
||||
}
|
||||
fprintf(stdout,"\n");
|
||||
fprintf(stdout,"[ m ] Memory allocated final: %d bytes\n",memAllocated());
|
||||
fprintf(stdout,"[ m ] Memory allocated final: %ld bytes\n",memAllocated());
|
||||
}
|
||||
#if 0
|
||||
#if !defined LIB
|
||||
/*
|
||||
builds a binary for command line "search & replace" tests
|
||||
|
|
@ -250,3 +251,4 @@ int main(char argc,char **argv){
|
|||
return 1;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
/* radare - LGPL - Copyright 2009 nibble<.ds@gmail.com> */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_util.h>
|
||||
#include <r_parse.h>
|
||||
|
||||
static int parse(struct r_parse_t *p, void *data, char *str)
|
||||
|
|
|
|||
|
|
@ -2,13 +2,10 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mreplace/mreplace.h"
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_util.h>
|
||||
#include <r_parse.h>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <r_types.h>
|
||||
#include <r_lib.h>
|
||||
#include <r_util.h>
|
||||
#include <r_parse.h>
|
||||
|
||||
static int replace(int argc, const char *argv[], char *newstr)
|
||||
|
|
|
|||
Loading…
Reference in a new issue