Fix librgdbr makefiles and add capstone-sync shlr target

This commit is contained in:
pancake 2014-03-07 02:00:27 +01:00
parent bb7958342b
commit 99cd0fee14
8 changed files with 172 additions and 147 deletions

View File

@ -1,6 +1,13 @@
include ../config-user.mk
include ../mk/${COMPILER}.mk
CS_URL=https://github.com/aquynh/capstone.git
CS_UPD=20140307
CS_BRA=next
CS_TIP=c76d8d03ba32cd9ab81266a99011220009c720d6
.PHONY: capstone-sync capstone-build all clean mrproper libgdbr
HOST_CC?=gcc
SHLR?=$(shell pwd)
AR?=ar
@ -10,13 +17,15 @@ URL=git://github.com/radare/sdb
PWD=$(shell pwd)
SDB_CONFIG=${PWD}/sdb-config.mk
all: sdb/sdb libgdbr
all: sdb/sdb libgdbr capstone-build
@for a in ${MODS} ; do \
echo ${MAKE} -C $$a ; \
${MAKE} -C $$a RANLIB="$(RANLIB)" CC_AR="$(CC_AR)" HAVE_VALA= ROOT="${PWD}/../" CC="${CC}" ; \
done
clean mrproper:
-cd capstone ; $(MAKE) clean
cd gdb ; $(MAKE) clean
rm -f sdb/src/.sdb sdb/sdb
cd sdb ; ${MAKE} clean
@for a in ${MODS} ; do ${MAKE} -C $$a clean ; done
@ -41,8 +50,7 @@ SYNCFILES=$(addprefix sdb.vc/,${F})
I=../libr/include
libgdbr:
cd gdb ; $(MAKE) clean
cd gdb ; $(MAKE) lib
cd gdb ; $(MAKE) all
sdb-sync sync-sdb:
rm -rf sdb sdb.vc
@ -102,3 +110,20 @@ install-symlink symstall:
uninstall deinstall:
#rm -f ${D}/lib/libr_tcc*
#rm -f ${D}/lib/libr_z*
capstone:
$(MAKE) capstone-sync
$(MAKE) $(MAKEFLAGS) capstone-build
capstone-build: capstone
cd capstone ; $(MAKE) $(MAKEFLAGS) all CC="$(CC)"
capstone-sync:
if [ -d capstone ]; then \
( cd capstone ; git pull ) ; \
else \
git clone $(CS_URL) ; \
fi
cd capstone ; \
git co $(CS_BRA) ; \
git reset --hard $(CS_TIP)

View File

@ -6,6 +6,7 @@ RANLIB?=ranlib
LIBNAME=libgdbr
LIBFILE=$(LIBNAME).$(EXT_SO)
CFLAGS+=-I$(LIBR)/include
CFLAGS+=-Iinclude
MAJOR=0
MINOR=1
#CFLAGS=-Wall -g -O0 -ggdb # -std=gnu11
@ -23,29 +24,29 @@ CLIENT=$(TEST_D)/client.c
PWD=$(shell pwd)
TEST=test
LIB=lib
INCLUDES=-I $(PWD)/include
TEST_INCLUDES += $(INCLUDES) -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include
SRC_D=$(PWD)/src
SRC_D=src
SRC_C=$(wildcard $(SRC_D)/*.c)
SRC_O=$(SRC_C:.c=.o)
TEST_C=$(wildcard $(TEST_D)/*.c)
TEST_O=$(TEST_C:.c=.o)
all: $(LIB)/$(LIBNAME).a
# make
$(SRC_O): %.o : %.c
$(CC) $(CFLAGS) $(INCLUDES) -c -fPIC $< -o $@
all: make
default: make
prepare:
mkdir -p $(LIB)
lib: prepare $(SRC_O)
#$(LD) -shared -Wl,-soname,$(LIBNAME).so -o $(LIB)/$(LIBNAME).so $(SRC_O)
#$(LD) -shared -Wl,-soname,$(LIBNAME).so -o $(LIB)/$(LIBNAME).so $(SRC_O)
$(LIB):
mkdir -p $(LIB)
$(LIB)/$(LIBNAME).a: $(LIB) $(SRC_O)
$(LD) -shared -o $(LIB)/$(LIBFILE) $(SRC_O) $(LDFLAGS)
$(AR) rvs $(LIB)/$(LIBNAME).a $(SRC_O)
# required for solaris and w32

View File

@ -16,113 +16,4 @@ typedef struct registers_t {
uint64_t value; /*! Saves the value of the register */
} registers_t;
static registers_t x86_64[] = {
{"rax", 0, 8, 0},
{"rbx", 8, 8, 0},
{"rcx", 16, 8, 0},
{"rdx", 24, 8, 0},
{"rsi", 32, 8, 0},
{"rdi", 40, 8, 0},
{"rbp", 48, 8, 0},
{"rsp", 56, 8, 0},
{"r8", 64, 8, 0},
{"r9", 72, 8, 0},
{"r10", 80, 8, 0},
{"r11", 88, 8, 0},
{"r12", 96, 8, 0},
{"r13", 104, 8, 0},
{"r14", 112, 8, 0},
{"r15", 120, 8, 0},
{"rip", 128, 8, 0},
{"eflags",136, 4, 0},
{"cs", 140, 4, 0},
{"ss", 144, 4, 0},
{"ds", 148, 4, 0},
{"es", 152, 4, 0},
{"fs", 156, 4, 0},
{"gs", 160, 4, 0},
{"st0", 164, 10, 0},
{"st1", 174, 10, 0},
{"st2", 184, 10, 0},
{"st3", 194, 10, 0},
{"st4", 204, 10, 0},
{"st5", 214, 10, 0},
{"st6", 224, 10, 0},
{"st7", 234, 10, 0},
{"fctrl", 244, 4, 0},
{"fstat", 248, 4, 0},
{"ftag", 252, 4, 0},
{"fiseg", 256, 4, 0},
{"fioff", 260, 4, 0},
{"foseg", 264, 4, 0},
{"fooff", 268, 4, 0},
{"fop", 272, 4, 0},
{"xmm0", 276, 16, 0},
{"xmm1", 292, 16, 0},
{"xmm2", 308, 16, 0},
{"xmm3", 324, 16, 0},
{"xmm4", 340, 16, 0},
{"xmm5", 356, 16, 0},
{"xmm6", 372, 16, 0},
{"xmm7", 388, 16, 0},
{"xmm8", 404, 16, 0},
{"xmm9", 420, 16, 0},
{"xmm10", 436, 16, 0},
{"xmm11", 452, 16, 0},
{"xmm12", 468, 16, 0},
{"xmm13", 484, 16, 0},
{"xmm14", 500, 16, 0},
{"xmm15", 516, 16, 0},
{"mxcsr", 532, 4, 0},
{"", 0, 0, 0}
};
static registers_t x86_32[] = {
{"eax", 0, 4, 0},
{"ecx", 4, 4, 0},
{"edx", 8, 4, 0},
{"ebx", 12, 4, 0},
{"esp", 16, 4, 0},
{"ebp", 20, 4, 0},
{"esi", 24, 4, 0},
{"edi", 28, 4, 0},
{"eip", 32, 4, 0},
{"eflags", 36, 4, 0},
{"cs", 40, 4, 0},
{"ss", 44, 4, 0},
{"ds", 48, 4, 0},
{"es", 52, 4, 0},
{"fs", 56, 4, 0},
{"gs", 60, 4, 0},
{"st0", 64, 10, 0},
{"st1", 74, 10, 0},
{"st2", 84, 10, 0},
{"st3", 94, 10, 0},
{"st4", 104, 10, 0},
{"st5", 114, 10, 0},
{"st6", 124, 10, 0},
{"st7", 134, 10, 0},
{"fctrl", 144, 4, 0},
{"fstat", 148, 4, 0},
{"ftag", 152, 4, 0},
{"fiseg", 156, 4, 0},
{"fioff", 160, 4, 0},
{"foseg", 164, 4, 0},
{"fooff", 168, 4, 0},
{"fop", 172, 4, 0},
{"xmm0", 176, 16, 0},
{"xmm1", 192, 16, 0},
{"xmm2", 208, 16, 0},
{"xmm3", 224, 16, 0},
{"xmm4", 240, 16, 0},
{"xmm5", 256, 16, 0},
{"xmm6", 272, 16, 0},
{"xmm7", 288, 16, 0},
{"mxcsr", 304, 4, 0},
{"", 0, 0, 0}
};
#endif

View File

@ -15,10 +15,8 @@
#include "arch.h"
static int X86_64 = ARCH_X86_64;
static int X86_32 = ARCH_X86_32;
#define X86_64 ARCH_X86_64
#define X86_32 ARCH_X86_32
/*!
* Structure that saves a gdb message

View File

@ -20,5 +20,6 @@ int handle_cont(libgdbr_t* instance);
int handle_connect(libgdbr_t* instance);
int handle_setbp(libgdbr_t* instance);
int handle_unsetbp(libgdbr_t* instance);
int handle_G(libgdbr_t* instance);
#endif

View File

@ -3,6 +3,115 @@
#include "packet.h"
#include "messages.h"
extern char hex2char(char* hex);
static registers_t x86_64[] = {
{"rax", 0, 8, 0},
{"rbx", 8, 8, 0},
{"rcx", 16, 8, 0},
{"rdx", 24, 8, 0},
{"rsi", 32, 8, 0},
{"rdi", 40, 8, 0},
{"rbp", 48, 8, 0},
{"rsp", 56, 8, 0},
{"r8", 64, 8, 0},
{"r9", 72, 8, 0},
{"r10", 80, 8, 0},
{"r11", 88, 8, 0},
{"r12", 96, 8, 0},
{"r13", 104, 8, 0},
{"r14", 112, 8, 0},
{"r15", 120, 8, 0},
{"rip", 128, 8, 0},
{"eflags",136, 4, 0},
{"cs", 140, 4, 0},
{"ss", 144, 4, 0},
{"ds", 148, 4, 0},
{"es", 152, 4, 0},
{"fs", 156, 4, 0},
{"gs", 160, 4, 0},
{"st0", 164, 10, 0},
{"st1", 174, 10, 0},
{"st2", 184, 10, 0},
{"st3", 194, 10, 0},
{"st4", 204, 10, 0},
{"st5", 214, 10, 0},
{"st6", 224, 10, 0},
{"st7", 234, 10, 0},
{"fctrl", 244, 4, 0},
{"fstat", 248, 4, 0},
{"ftag", 252, 4, 0},
{"fiseg", 256, 4, 0},
{"fioff", 260, 4, 0},
{"foseg", 264, 4, 0},
{"fooff", 268, 4, 0},
{"fop", 272, 4, 0},
{"xmm0", 276, 16, 0},
{"xmm1", 292, 16, 0},
{"xmm2", 308, 16, 0},
{"xmm3", 324, 16, 0},
{"xmm4", 340, 16, 0},
{"xmm5", 356, 16, 0},
{"xmm6", 372, 16, 0},
{"xmm7", 388, 16, 0},
{"xmm8", 404, 16, 0},
{"xmm9", 420, 16, 0},
{"xmm10", 436, 16, 0},
{"xmm11", 452, 16, 0},
{"xmm12", 468, 16, 0},
{"xmm13", 484, 16, 0},
{"xmm14", 500, 16, 0},
{"xmm15", 516, 16, 0},
{"mxcsr", 532, 4, 0},
{"", 0, 0, 0}
};
static registers_t x86_32[] = {
{"eax", 0, 4, 0},
{"ecx", 4, 4, 0},
{"edx", 8, 4, 0},
{"ebx", 12, 4, 0},
{"esp", 16, 4, 0},
{"ebp", 20, 4, 0},
{"esi", 24, 4, 0},
{"edi", 28, 4, 0},
{"eip", 32, 4, 0},
{"eflags", 36, 4, 0},
{"cs", 40, 4, 0},
{"ss", 44, 4, 0},
{"ds", 48, 4, 0},
{"es", 52, 4, 0},
{"fs", 56, 4, 0},
{"gs", 60, 4, 0},
{"st0", 64, 10, 0},
{"st1", 74, 10, 0},
{"st2", 84, 10, 0},
{"st3", 94, 10, 0},
{"st4", 104, 10, 0},
{"st5", 114, 10, 0},
{"st6", 124, 10, 0},
{"st7", 134, 10, 0},
{"fctrl", 144, 4, 0},
{"fstat", 148, 4, 0},
{"ftag", 152, 4, 0},
{"fiseg", 156, 4, 0},
{"fioff", 160, 4, 0},
{"foseg", 164, 4, 0},
{"fooff", 168, 4, 0},
{"fop", 172, 4, 0},
{"xmm0", 176, 16, 0},
{"xmm1", 192, 16, 0},
{"xmm2", 208, 16, 0},
{"xmm3", 224, 16, 0},
{"xmm4", 240, 16, 0},
{"xmm5", 256, 16, 0},
{"xmm6", 272, 16, 0},
{"xmm7", 288, 16, 0},
{"mxcsr", 304, 4, 0},
{"", 0, 0, 0}
};
int gdbr_init(libgdbr_t* instance) {
memset(instance,0, sizeof(libgdbr_t));
@ -114,7 +223,7 @@ int gdbr_read_registers(libgdbr_t* instance) {
int gdbr_read_memory(libgdbr_t* instance, uint64_t address, uint64_t len) {
char command[255] = {};
int ret = snprintf(command, 255, "%s%016lx,%ld", CMD_READMEM, address, len);
int ret = snprintf(command, 255, "%s%016"PFMT64x",%"PFMT64d, CMD_READMEM, address, len);
if (ret < 0) return ret;
send_command(instance, command);
@ -129,7 +238,7 @@ int gdbr_read_memory(libgdbr_t* instance, uint64_t address, uint64_t len) {
int gdbr_write_memory(libgdbr_t* instance, uint64_t address, char* data, uint64_t len) {
char command[255] = {};
int command_len = snprintf(command, 255, "%s%016lx,%ld:", CMD_WRITEMEM, address, len);
int command_len = snprintf(command, 255, "%s%016"PFMT64x",%"PFMT64d":", CMD_WRITEMEM, address, len);
char* tmp = calloc(command_len + (len * 2), sizeof(char));
memcpy(tmp, command, command_len);
pack_hex(data, len, (tmp + command_len));
@ -186,7 +295,6 @@ int gdbr_write_bin_registers(libgdbr_t* instance, char* registers) {
int gdbr_write_registers(libgdbr_t* instance, char* registers) {
int ret = 0;
// read current register set
gdbr_read_registers(instance);

View File

@ -16,7 +16,7 @@ void handle_escape(parsing_object_t* current) {
void handle_chk(parsing_object_t* current) {
if (current->position >= current->length) return;
char checksum[2];
char checksum[3];
checksum[0] = get_next_token(current);
checksum[1] = get_next_token(current);
checksum[2] = '\0';

View File

@ -1,5 +1,7 @@
#include "r_util.h"
#include "utils.h"
// XXX: most of those functions are already implemented in r_util. reuse!
/**
* Function creates the checksum
@ -17,27 +19,27 @@ uint8_t cmd_checksum(const char* command) {
/**
* Converts str to uint64_t
* Converts str to ut64
*/
uint64_t unpack_uint64(char *buff, int len) {
int nibble;
uint64_t retval = 0;
while (len) {
ut64 unpack_uint64(char *buff, int len) {
int nibble;
ut64 retval = 0;
while (len) {
nibble = hex2int(*buff++);
retval |= nibble;
len--;
if (len) retval = retval << 4;
}
return retval;
len--;
if (len) retval = retval << 4;
}
return retval;
}
/**
* Changed byte order and
* converts the value into uint64_t
* converts the value into ut64
*/
uint64_t unpack_uint64_co(char* buff, int len) {
uint64_t result = 0;
ut64 unpack_uint64_co(char* buff, int len) {
ut64 result = 0;
int i;
for (i = len - 2; i >= 0; i-=2) {
result |= unpack_uint64(&buff[i], 2);
@ -78,7 +80,7 @@ char hex2char(char* hex) {
}
int unpack_hex(char* src, uint64_t len, char* dst) {
int unpack_hex(char* src, ut64 len, char* dst) {
int i = 0;
while (i < (len / 2)) {
int val = hex2int(src[(i*2)]);
@ -91,7 +93,7 @@ int unpack_hex(char* src, uint64_t len, char* dst) {
}
int pack_hex(char* src, uint64_t len, char* dst) {
int pack_hex(char* src, ut64 len, char* dst) {
int i = 0;
int x = 0;
while (i < (len*2)) {
@ -104,12 +106,12 @@ int pack_hex(char* src, uint64_t len, char* dst) {
}
void hexdump(void* ptr, uint64_t len, uint64_t offset) {
void hexdump(void* ptr, ut64 len, ut64 offset) {
unsigned char* data = (unsigned char*)ptr;
int x = 0;
char hex[49], *p;
char txt[17], *c;
uint64_t curr_offset;
ut64 curr_offset;
while (x < len) {
p = hex;
c = txt;
@ -118,10 +120,9 @@ void hexdump(void* ptr, uint64_t len, uint64_t offset) {
do {
p += sprintf(p, "%02hhx ", data[x]);
*c++ = (data[x] >= 32 && data[x] <= 127) ? data[x] : '.';
}while (++x % 16 && x < len);
} while (++x % 16 && x < len);
*c = '\0';
printf("0x%016lx: %-48s- %s\n", (curr_offset), hex, txt);
eprintf ("0x%016"PFMT64x": %-48s- %s\n", (curr_offset), hex, txt);
}
}