mirror of
https://github.com/radareorg/radare2-extras.git
synced 2026-11-09 17:48:00 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ec6dbcf88 | ||
|
|
bc6d3f36da | ||
|
|
96d68f14ed | ||
|
|
a67e7f0adb | ||
|
|
7125f795b4 | ||
|
|
6ad247901d | ||
|
|
7ecb70cd26 | ||
|
|
f90380fc23 | ||
|
|
a0d0c360da | ||
|
|
80e37a663d | ||
|
|
fb3c96694e | ||
|
|
2ee3d1153b | ||
|
|
972e774df8 |
No files matched your search
+13
-13
@@ -32,33 +32,33 @@ addons:
|
||||
env:
|
||||
- TESTS="r2pm -i armthumb"
|
||||
- TESTS="r2pm -i baleful"
|
||||
# - TESTS="r2pm -i bcl" [BR] https://travis-ci.org/radare/radare2-extras/builds/157522362
|
||||
# - TESTS="r2pm -i bcl" [BR] https://travis-ci.org/radareorg/radare2-extras/builds/157522362
|
||||
- TESTS="r2pm -i blackfin"
|
||||
- TESTS="r2pm -i blessr2"
|
||||
# - TESTS="r2pm -i bpf" [BR] https://travis-ci.org/radare/radare2-extras/builds/157522362
|
||||
# - TESTS="r2pm -i dlang" [BR] https://travis-ci.org/radare/radare2-extras/builds/157522362
|
||||
# - TESTS="r2pm -i bpf" [BR] https://travis-ci.org/radareorg/radare2-extras/builds/157522362
|
||||
# - TESTS="r2pm -i dlang" [BR] https://travis-ci.org/radareorg/radare2-extras/builds/157522362
|
||||
- TESTS="r2pm -i dirtycow"
|
||||
- TESTS="r2pm -i lang-duktape"
|
||||
- TESTS="git clone git://git.code.sf.net/p/libdwarf/code libdwarf-code && cd libdwarf-code && ./configure && make && cd .. && r2pm -i dwarf-parser && cd radare2-regressions && ./r2r dwarf && cd .. && r2pm -u libdwarf && rm -rf libdwarf-code" #need to remove libdwarf? or travis destroys the vm so no issue in that?
|
||||
- TESTS="r2pm -i r2frida"
|
||||
# - TESTS="r2pm -i io-ewf" # https://github.com/travis-ci/apt-package-whitelist/issues/3205
|
||||
# - TESTS="r2pm -i keystone-lib && r2pm -i keystone && cd radare2-regressions && make keystone && cd .." [BR] https://travis-ci.org/radare/radare2-extras/builds/157522362
|
||||
# - TESTS="r2pm -i keystone-lib && r2pm -i keystone && cd radare2-regressions && make keystone && cd .." [BR] https://travis-ci.org/radareorg/radare2-extras/builds/157522362
|
||||
- TESTS="r2pm -i mc6809"
|
||||
- TESTS="r2pm -i microblaze"
|
||||
- TESTS="r2pm -i microblaze && cd radare2-regressions && make microblaze"
|
||||
- TESTS="r2pm -i msil"
|
||||
- TESTS="r2pm -i pcap"
|
||||
- TESTS="r2pm -i ppcdisasm"
|
||||
- TESTS="r2pm -i psosvm"
|
||||
- TESTS="r2pm -i pyc"
|
||||
# - TESTS="r2pm -i vala && r2pm -i valabind && r2pm -i r2api-python" [BR] https://travis-ci.org/radare/radare2-extras/builds/387043680
|
||||
# - TESTS="r2pm -i r2pipe-cs" [BR] https://travis-ci.org/radare/radare2-extras/builds/157522362
|
||||
# - TESTS="r2pm -i r2pipe-go" [BR] https://travis-ci.org/radare/radare2-extras/builds/387043680
|
||||
# - TESTS="r2pm -i vala && r2pm -i valabind && r2pm -i r2api-python" [BR] https://travis-ci.org/radareorg/radare2-extras/builds/387043680
|
||||
# - TESTS="r2pm -i r2pipe-cs" [BR] https://travis-ci.org/radareorg/radare2-extras/builds/157522362
|
||||
# - TESTS="r2pm -i r2pipe-go" [BR] https://travis-ci.org/radareorg/radare2-extras/builds/387043680
|
||||
- TESTS="r2pm -i r2pipe-js"
|
||||
- TESTS="r2pm -i r2pipe-py"
|
||||
- TESTS="r2pm -i r2pipe-rb"
|
||||
# - TESTS="r2pm -i r2pipe-vala" https://travis-ci.org/radare/radare2-extras/builds/157522362
|
||||
# - TESTS="r2pm -i r2pipe-vala" https://travis-ci.org/radareorg/radare2-extras/builds/157522362
|
||||
- TESTS="r2pm -i radare2"
|
||||
# - TESTS="r2pm -i r2snow" https://travis-ci.org/radare/radare2-extras/jobs/199500082
|
||||
# - TESTS="r2pm -i r2snow" https://travis-ci.org/radareorg/radare2-extras/jobs/199500082
|
||||
# - TESTS="r2pm -i radeco" [BR] https://travis-ci.org/radare/radare2-extras/builds/157522362
|
||||
- TESTS="r2pm -i retdec"
|
||||
- TESTS="r2pm -i swf && cd radare2-regressions && make swf && cd .."
|
||||
@@ -94,9 +94,9 @@ cache:
|
||||
before_script:
|
||||
- export WORKING_DIR=${TRAVIS_BUILD_DIR}/..
|
||||
- cd ${WORKING_DIR}
|
||||
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install 7
|
||||
- git clone https://github.com/radare/radare2-regressions
|
||||
- git clone https://github.com/radare/radare2 && cd radare2
|
||||
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install 10
|
||||
- git clone https://github.com/radareorg/radare2-regressions
|
||||
- git clone https://github.com/radareorg/radare2 && cd radare2
|
||||
- export CC=gcc-7
|
||||
- ./configure --prefix=${WORKING_DIR}/install > /dev/null
|
||||
- make -s -j2 > /dev/null
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
radare2-extras [](https://travis-ci.org/radare/radare2-extras)
|
||||
radare2-extras [](https://travis-ci.org/radareorg/radare2-extras)
|
||||
==============
|
||||
This repository contains extra plugins for radare2.
|
||||
|
||||
@@ -33,4 +33,4 @@ Building
|
||||
The recommended way to build and install those plugins for users
|
||||
is to use r2pm. See the radare2-pm repository for details:
|
||||
|
||||
https://github.com/radare/radare2-pm
|
||||
https://github.com/radareorg/radare2-pm
|
||||
@@ -5,7 +5,7 @@
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/radare/radare2-bindings.git"
|
||||
"url": "https://github.com/radareorg/radare2-bindings.git"
|
||||
},
|
||||
"keywords": [
|
||||
"radare",
|
||||
@@ -24,7 +24,7 @@
|
||||
},
|
||||
"license": "LGPL-3.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/radare/radare2-extras/issues"
|
||||
"url": "https://github.com/radareorg/radare2-extras/issues"
|
||||
},
|
||||
"homepage": "http://www.radare.org",
|
||||
"devDependencies": {
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ make install
|
||||
|
||||
There are two known warnings:
|
||||
|
||||
* be sure to have the latest [radare2 from git](https://github.com/radare/radare2)
|
||||
* be sure to have the latest [radare2 from git](https://github.com/radareorg/radare2)
|
||||
* on mac systems radare2 should be installed with sys/install.sh (and not sys/user.sh) because the Makefile relies on a properly working `pkg-config`
|
||||
|
||||
## Example
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
This is the r2 plugin to read/write memory using the checkm8 exploit.
|
||||
|
||||
1. Clone https://github.com/axi0mX/ipwndfu
|
||||
2. Copy this file into the root directory of this repository
|
||||
3. r2 -I r2io.py ipwndfu://
|
||||
4. enjoy
|
||||
|
||||
NOTES
|
||||
|
||||
* This is very unstable, reading on unallocated regions results in device reboot
|
||||
* Requires python3 .. so maybe better use @geohot's fork
|
||||
@@ -0,0 +1,65 @@
|
||||
# iOS pwndfu checkm8 io plugin for radare2
|
||||
# ========================================
|
||||
#
|
||||
# -- pancake @ nopcode.org
|
||||
#
|
||||
# Usage:
|
||||
# r2 -I test-py-io.py pwndfu://
|
||||
#
|
||||
# The r2lang.plugin function exposes a way to register new plugins
|
||||
# into the RCore instance. This API is only available from RLang.
|
||||
# You must call with with '#!python test.py' or 'r2 -i test.py ..'
|
||||
|
||||
import r2lang
|
||||
from dfuexec import *
|
||||
|
||||
FAKESIZE = 512
|
||||
|
||||
device = None
|
||||
|
||||
def pyio(a):
|
||||
def _open(path, rw, perm):
|
||||
global device
|
||||
device = dfu.acquire_device()
|
||||
serial_number = device.serial_number
|
||||
dfu.release_device(device)
|
||||
device = PwnedDFUDevice()
|
||||
print("MyPyIO Opening %s"%(path))
|
||||
return 1234
|
||||
def _check(path, many):
|
||||
print("python-check %s"%(path))
|
||||
return path[0:9] == "pwndfu://"
|
||||
def _read(offset, length):
|
||||
global device
|
||||
res = device.read_memory(address, length)
|
||||
print("python-read")
|
||||
return res
|
||||
def _seek(offset, whence):
|
||||
print("python-seek")
|
||||
if whence == 0: # SET
|
||||
return offset
|
||||
if whence == 1: # CUR
|
||||
return offset
|
||||
if whence == 2: # END
|
||||
return ROM_SIZE
|
||||
return ROM_SIZE
|
||||
def _write(offset, data, length):
|
||||
print("TODO: python-write")
|
||||
return True
|
||||
def _system(cmd):
|
||||
print("pwndfu://%s"%(cmd))
|
||||
return True
|
||||
return {
|
||||
"name": "pwndfu",
|
||||
"license": "GPL",
|
||||
"desc": "pwndfu IO plugin (pwndfu://3)",
|
||||
"check": _check,
|
||||
"open": _open,
|
||||
"read": _read,
|
||||
"seek": _seek,
|
||||
"write": _write,
|
||||
"system": _system,
|
||||
}
|
||||
|
||||
print("Registering Python IO plugin...")
|
||||
print(r2lang.plugin("io", pyio))
|
||||
@@ -105,12 +105,12 @@ done
|
||||
: ${INSTALL_PROGRAM_STRIP:=${INSTALL} -m 755 -s}
|
||||
: ${INSTALL_MAN:=${INSTALL} -m 444}
|
||||
: ${INSTALL_LIB:=${INSTALL} -m 755 -c}
|
||||
PKGNAME='radare2-extras' ; VERSION='3.9.0' ; CONTACT_MAIL="[email protected]" ; CONTACT_NAME="pancake" ; CONTACT="pancake <[email protected]>" ;
|
||||
PKGNAME='radare2-extras' ; VERSION='4.0.0' ; CONTACT_MAIL="[email protected]" ; CONTACT_NAME="pancake" ; CONTACT="pancake <[email protected]>" ;
|
||||
}
|
||||
|
||||
show_usage() {
|
||||
cat <<EOF2
|
||||
'configure' configures radare2-extras-3.9.0 to adapt to many kinds of systems.
|
||||
'configure' configures radare2-extras-4.0.0 to adapt to many kinds of systems.
|
||||
|
||||
Usage: ./configure [OPTION]... [VAR=VALUE]...
|
||||
|
||||
@@ -180,7 +180,7 @@ take_environ() {
|
||||
}
|
||||
|
||||
show_version() {
|
||||
echo "radare2-extras-3.9.0 configuration script done with acr v1.7.2.
|
||||
echo "radare2-extras-4.0.0 configuration script done with acr v1.7.2.
|
||||
The 'Free Software Foundation' message is only for autodetection.
|
||||
Originally written by pancake <nopcode.org>."
|
||||
exit 0
|
||||
@@ -204,7 +204,7 @@ case $flag in
|
||||
show_version ; ;;
|
||||
-r|--r|--report)
|
||||
echo "PKGNAME: radare2-extras"
|
||||
echo "VERSION: 3.9.0"
|
||||
echo "VERSION: 4.0.0"
|
||||
echo "LANGS: c"
|
||||
echo "OPTIONAL: libewf libyara"
|
||||
echo "PKG-CONFIG: r_core libewf unicorn yara"
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
PKGNAME radare2-extras
|
||||
VERSION 3.9.0
|
||||
VERSION 4.0.0
|
||||
CONTACT pancake ; [email protected]
|
||||
|
||||
REPORT PREFIX ;
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ RUN cd /opt/code && \
|
||||
tar -Jxf ${VALA_TAR}.tar.xz
|
||||
RUN cd /opt/code/${VALA_TAR}; ./configure --prefix=/usr ; make && make install
|
||||
# compile radare and bindings
|
||||
RUN cd /opt/code; git clone https://github.com/radare/radare2.git; cd radare2; ./sys/all.sh
|
||||
RUN cd /opt/code; git clone https://github.com/radareorg/radare2.git; cd radare2; ./sys/all.sh
|
||||
|
||||
#install Go
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ RUN cd /opt/code && \
|
||||
tar -Jxf ${VALA_TAR}.tar.xz
|
||||
RUN cd /opt/code/${VALA_TAR}; ./configure --prefix=/usr ; make && make install
|
||||
# compile radare and bindings
|
||||
RUN cd /opt/code; git clone https://github.com/radare/radare2.git; cd radare2; ./sys/all.sh
|
||||
RUN cd /opt/code; git clone https://github.com/radareorg/radare2.git; cd radare2; ./sys/all.sh
|
||||
|
||||
#install Go
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ RUN apt-get install -y python-pip jython
|
||||
RUN cd /opt/code; wget http://download.gnome.org/sources/vala/0.24/vala-0.24.0.tar.xz; tar -Jxf vala-0.24.0.tar.xz
|
||||
RUN cd /opt/code/vala-0.24.0; ./configure --prefix=/usr ; make && make install
|
||||
# compile radare
|
||||
RUN cd /opt/code; git clone https://github.com/radare/radare2.git; cd radare2; ./sys/all.sh
|
||||
RUN cd /opt/code; git clone https://github.com/radareorg/radare2.git; cd radare2; ./sys/all.sh
|
||||
|
||||
# Clean up APT when done.
|
||||
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
@@ -48,7 +48,7 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
RUN cd /opt/code; wget http://download.gnome.org/sources/vala/0.24/vala-0.24.0.tar.xz; tar -Jxf vala-0.24.0.tar.xz
|
||||
RUN cd /opt/code/vala-0.24.0; ./configure --prefix=/usr ; make && make install
|
||||
# compile radare
|
||||
RUN cd /opt/code; git clone https://github.com/radare/radare2.git; cd radare2; ./sys/all.sh
|
||||
RUN cd /opt/code; git clone https://github.com/radareorg/radare2.git; cd radare2; ./sys/all.sh
|
||||
|
||||
|
||||
#install oracle jre stuffs
|
||||
|
||||
@@ -23,7 +23,7 @@ RUN apt-get install -y python-pip jython
|
||||
RUN cd /opt/code; wget http://download.gnome.org/sources/vala/0.24/vala-0.24.0.tar.xz; tar -Jxf vala-0.24.0.tar.xz
|
||||
RUN cd /opt/code/vala-0.24.0; ./configure --prefix=/usr ; make && make install
|
||||
# compile radare
|
||||
RUN cd /opt/code; git clone https://github.com/radare/radare2.git; cd radare2; ./sys/all.sh
|
||||
RUN cd /opt/code; git clone https://github.com/radareorg/radare2.git; cd radare2; ./sys/all.sh
|
||||
|
||||
# Clean up APT when done.
|
||||
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
@@ -32,7 +32,7 @@ RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
RUN cd /opt/code; wget http://download.gnome.org/sources/vala/0.24/vala-0.24.0.tar.xz; tar -Jxf vala-0.24.0.tar.xz
|
||||
RUN cd /opt/code/vala-0.24.0; ./configure --prefix=/usr ; make && make install
|
||||
# compile radare
|
||||
RUN cd /opt/code; git clone https://github.com/radare/radare2.git; cd radare2; ./sys/all.sh
|
||||
RUN cd /opt/code; git clone https://github.com/radareorg/radare2.git; cd radare2; ./sys/all.sh
|
||||
|
||||
|
||||
#install oracle jre stuffs
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "microblaze-opc.h"
|
||||
#include "dis-asm.h"
|
||||
|
||||
#define UT15_MAX 0x7fff
|
||||
#define UT32_16U UT16_MAX << 16
|
||||
#define UT32_16L UT16_MAX
|
||||
|
||||
@@ -59,7 +60,7 @@ ut32 microblaze_our_get_target_address(long inst, bool immfound, int immval,
|
||||
if (op->name == 0) {
|
||||
*targetvalid = false;
|
||||
}
|
||||
else if (op->instr_type == branch_inst) {
|
||||
else if ((op->instr_type == branch_inst) || (op->instr_type == branch_inst_imm)) {
|
||||
switch (op->inst_type) {
|
||||
case INST_TYPE_R2:
|
||||
*unconditionalbranch = true;
|
||||
@@ -150,12 +151,19 @@ static unsigned long read_insn_microblaze(bfd_vma memaddr,
|
||||
|
||||
static char *get_imm(struct mb_anal_ctx *ctx, int instr) {
|
||||
char *tmpstr;
|
||||
int immval = 0;
|
||||
st16 immval = 0;
|
||||
immval = get_int_field_imm (instr);
|
||||
tmpstr = r_str_newf ("%u", immval);
|
||||
tmpstr = r_str_newf ("%d", immval);
|
||||
return tmpstr;
|
||||
}
|
||||
|
||||
static char *get_field_imm15 (long instr)
|
||||
{
|
||||
char *tmpstr;
|
||||
tmpstr = r_str_newf ("%u", (short)((instr & IMM15_MASK) >> IMM_LOW));
|
||||
return (tmpstr);
|
||||
}
|
||||
|
||||
static char *
|
||||
get_field_special (long instr, struct op_code_struct * op)
|
||||
{
|
||||
@@ -211,7 +219,7 @@ get_field_special (long instr, struct op_code_struct * op)
|
||||
break;
|
||||
default :
|
||||
strcpy (spr, "pc");
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
tmpstr = r_str_newf ("%s", spr);
|
||||
@@ -228,16 +236,72 @@ static void handle_immediate_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
ctx->immfound_addr = ctx->op->addr;
|
||||
tmpstr = r_str_newf ("%u", (ctx->immval << 16) & UT32_16U);
|
||||
r_strbuf_setf (&op->esil, "%s,_imm,=", tmpstr);
|
||||
r_strbuf_appendf (&op->esil, ",1,_immf,=");
|
||||
}
|
||||
}
|
||||
|
||||
static void analyse_arithmetic_inst_imm(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
struct op_code_struct *mb_op) {
|
||||
RAnalOp *op = ctx->op;
|
||||
char *ra = get_field_r1 (insn);
|
||||
char *rb = get_field_r2 (insn);
|
||||
char *rd = get_field_rd (insn);
|
||||
char *imm = get_imm (ctx, insn);
|
||||
|
||||
r_strbuf_setf (&op->esil, "1,_immf,==,$z,?{,%s,%u,&,_imm,|,_imm,=,},", imm, UT16_MAX);
|
||||
r_strbuf_appendf (&op->esil, "0,_immf,==,$z,?{,%s,_imm,=,},", imm);
|
||||
|
||||
switch (mb_op->instr) {
|
||||
case addi:
|
||||
r_strbuf_appendf (&op->esil, "_imm,%s,+,%s,=", ra, rd);
|
||||
op->type = R_ANAL_OP_TYPE_ADD;
|
||||
break;
|
||||
case rsubi:
|
||||
r_strbuf_appendf (&op->esil, "_imm,%s,-,%s,=", ra, rd);
|
||||
op->type = R_ANAL_OP_TYPE_SUB;
|
||||
break;
|
||||
case addic:
|
||||
/* should use carry */
|
||||
r_strbuf_appendf (&op->esil, "_imm,%s,+,%s,=", ra, rd);
|
||||
op->type = R_ANAL_OP_TYPE_ADD;
|
||||
break;
|
||||
case rsubic:
|
||||
/* should use carry */
|
||||
r_strbuf_appendf (&op->esil, "_imm,%s,-,%s,=", ra, rd);
|
||||
op->type = R_ANAL_OP_TYPE_SUB;
|
||||
break;
|
||||
case addik:
|
||||
/* should keep carry */
|
||||
r_strbuf_appendf (&op->esil, "_imm,%s,+,%s,=", ra, rd);
|
||||
op->type = R_ANAL_OP_TYPE_ADD;
|
||||
break;
|
||||
case rsubik:
|
||||
/* should keep carry */
|
||||
r_strbuf_appendf (&op->esil, "_imm,%s,-,%s,=", ra, rd);
|
||||
op->type = R_ANAL_OP_TYPE_SUB;
|
||||
break;
|
||||
case addikc:
|
||||
/* should use and keep carry */
|
||||
r_strbuf_appendf (&op->esil, "_imm,%s,+,%s,=", ra, rd);
|
||||
op->type = R_ANAL_OP_TYPE_ADD;
|
||||
break;
|
||||
case rsubikc:
|
||||
/* should use and keep carry */
|
||||
r_strbuf_appendf (&op->esil, "_imm,%s,-,%s,=", ra, rd);
|
||||
op->type = R_ANAL_OP_TYPE_SUB;
|
||||
break;
|
||||
}
|
||||
// Reset _immf to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_immf,=");
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
}
|
||||
|
||||
static void analyse_arithmetic_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
struct op_code_struct *mb_op) {
|
||||
RAnalOp *op = ctx->op;
|
||||
char *ra = get_field_r1 (insn);
|
||||
char *rb = get_field_r2 (insn);
|
||||
char *rd = get_field_rd (insn);
|
||||
char *imm = get_imm (ctx, insn);
|
||||
|
||||
switch (mb_op->instr) {
|
||||
case add:
|
||||
@@ -249,6 +313,8 @@ static void analyse_arithmetic_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
op->type = R_ANAL_OP_TYPE_SUB;
|
||||
break;
|
||||
case addc:
|
||||
r_strbuf_setf (&op->esil, "%s,%s,c,+,+,%s,=", ra, rb, rd);
|
||||
r_strbuf_appendf (&op->esil, "32,%s,>>,c,+=", rd);
|
||||
op->type = R_ANAL_OP_TYPE_ADD;
|
||||
break;
|
||||
case rsubc:
|
||||
@@ -265,55 +331,22 @@ static void analyse_arithmetic_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
op->type = R_ANAL_OP_TYPE_SUB;
|
||||
break;
|
||||
case cmp:
|
||||
r_strbuf_setf (&op->esil, "%s,%s,-,0x7fffffff,&,%s,=,", ra, rb, rd);
|
||||
r_strbuf_appendf (&op->esil, "31,%s,%s,>,<<,%s,|=", ra, rb, rd);
|
||||
op->type = R_ANAL_OP_TYPE_CMP;
|
||||
break;
|
||||
case cmpu:
|
||||
r_strbuf_setf (&op->esil, "%s,%s,-,0x7fffffff,&,%s,=,", ra, rb, rd);
|
||||
r_strbuf_appendf (&op->esil, "31,%s,%s,>,<<,%s,|=", ra, rb, rd);
|
||||
op->type = R_ANAL_OP_TYPE_CMP;
|
||||
break;
|
||||
case addkc:
|
||||
r_strbuf_setf (&op->esil, "%s,%s,c,+,+,%s,=", ra, rb, rd);
|
||||
op->type = R_ANAL_OP_TYPE_ADD;
|
||||
break;
|
||||
case rsubkc:
|
||||
op->type = R_ANAL_OP_TYPE_SUB;
|
||||
break;
|
||||
case addi:
|
||||
r_strbuf_setf (&op->esil, "%s,_imm,|,%s,+,%s,=", ra, imm, rd);
|
||||
op->type = R_ANAL_OP_TYPE_ADD;
|
||||
break;
|
||||
case rsubi:
|
||||
r_strbuf_setf (&op->esil, "%s,_imm,|,%s,-,%s,=", ra, imm, rd);
|
||||
op->type = R_ANAL_OP_TYPE_SUB;
|
||||
break;
|
||||
case addic:
|
||||
/* should use carry */
|
||||
r_strbuf_setf (&op->esil, "%s,_imm,|,%s,+,%s,=", ra, imm, rd);
|
||||
op->type = R_ANAL_OP_TYPE_ADD;
|
||||
break;
|
||||
case rsubic:
|
||||
/* should use carry */
|
||||
r_strbuf_setf (&op->esil, "%s,_imm,|,%s,-,%s,=", ra, imm, rd);
|
||||
op->type = R_ANAL_OP_TYPE_SUB;
|
||||
break;
|
||||
case addik:
|
||||
/* should keep carry */
|
||||
r_strbuf_setf (&op->esil, "%s,_imm,|,%s,+,%s,=", imm, ra, rd);
|
||||
op->type = R_ANAL_OP_TYPE_ADD;
|
||||
break;
|
||||
case rsubik:
|
||||
/* should keep carry */
|
||||
r_strbuf_setf (&op->esil, "%s,%s,-,%s,=", ra, imm, rd);
|
||||
op->type = R_ANAL_OP_TYPE_SUB;
|
||||
break;
|
||||
case addikc:
|
||||
/* should use and keep carry */
|
||||
r_strbuf_setf (&op->esil, "%s,%s,+,%s,=", ra, imm, rd);
|
||||
op->type = R_ANAL_OP_TYPE_ADD;
|
||||
break;
|
||||
case rsubikc:
|
||||
/* should use and keep carry */
|
||||
r_strbuf_setf (&op->esil, "%s,%s,-,%s,=", ra, imm, rd);
|
||||
op->type = R_ANAL_OP_TYPE_SUB;
|
||||
break;
|
||||
case swapb:
|
||||
break;
|
||||
case swaph:
|
||||
@@ -321,8 +354,9 @@ static void analyse_arithmetic_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Reset _imm value to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
// Reset _immf to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_immf,=");
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
}
|
||||
|
||||
static void analyse_logical_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
@@ -359,6 +393,8 @@ static void analyse_logical_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
case pcmpne:
|
||||
break;
|
||||
case sra:
|
||||
r_strbuf_setf (&op->esil, "1,%s,>>>,%s,=", ra, rd);
|
||||
op->type = R_ANAL_OP_TYPE_SAR;
|
||||
break;
|
||||
case src:
|
||||
break;
|
||||
@@ -387,8 +423,9 @@ static void analyse_logical_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Reset _imm value to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
// Reset _immf to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_immf,=");
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
}
|
||||
|
||||
static void analyse_mult_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
@@ -423,8 +460,9 @@ static void analyse_mult_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Reset _imm value to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
// Reset _immf to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_immf,=");
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
}
|
||||
|
||||
static void analyse_div_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
@@ -447,8 +485,9 @@ static void analyse_div_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Reset _imm value to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
// Reset _immf to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_immf,=");
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
}
|
||||
|
||||
static char *long_to_string(long imm) {
|
||||
@@ -457,6 +496,154 @@ static char *long_to_string(long imm) {
|
||||
return tmpstr;
|
||||
}
|
||||
|
||||
static void analyse_branch_inst_imm(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
struct op_code_struct *mb_op) {
|
||||
RAnalOp *op = ctx->op;
|
||||
bool targetvalid;
|
||||
bool unconditionalbranch;
|
||||
long r1 = get_int_field_r1 (insn);
|
||||
long r2 = get_int_field_r2 (insn);
|
||||
char *ra = get_field_r1 (insn);
|
||||
char *rb = get_field_r2 (insn);
|
||||
char *rd = get_field_rd (insn);
|
||||
char *imm;
|
||||
ut32 jump_addr = 0;
|
||||
r_strbuf_setf (&op->esil, "");
|
||||
|
||||
jump_addr = microblaze_our_get_target_address(
|
||||
insn, ctx->immfound, ctx->immval, ctx->op->addr, r1, r2, &targetvalid,
|
||||
&unconditionalbranch);
|
||||
|
||||
imm = get_imm (ctx, insn);
|
||||
r_strbuf_setf (&op->esil, "1,_immf,==,$z,?{,%s,%u,&,_imm,|,_imm,=,},", imm, UT16_MAX);
|
||||
r_strbuf_appendf (&op->esil, "0,_immf,==,$z,?{,%s,_imm,=,},", imm);
|
||||
|
||||
switch (mb_op->instr) {
|
||||
case bri:
|
||||
r_strbuf_appendf (&op->esil, "_imm,$$,+,pc,=");
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
op->jump = jump_addr;
|
||||
break;
|
||||
case brid:
|
||||
r_strbuf_appendf (&op->esil, "_imm,$$,+,pc,=");
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
break;
|
||||
case brlid:
|
||||
r_strbuf_appendf (&op->esil, "$$,%s,=,_imm,$$,+,pc,=", rd);
|
||||
op->type = R_ANAL_OP_TYPE_UCALL;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
break;
|
||||
case brai:
|
||||
r_strbuf_setf (&op->esil, "_imm,pc,=");
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
op->jump = jump_addr;
|
||||
break;
|
||||
case braid:
|
||||
r_strbuf_appendf (&op->esil, "_imm,|,pc,=");
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
break;
|
||||
case bralid:
|
||||
r_strbuf_appendf (&op->esil, "$$,%s,=,_imm,pc,=", rd);
|
||||
op->type = R_ANAL_OP_TYPE_UCALL;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
break;
|
||||
case brki:
|
||||
r_strbuf_appendf (&op->esil, "TRAP");
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
op->jump = jump_addr;
|
||||
break;
|
||||
case beqi:
|
||||
r_strbuf_appendf (&op->esil, "0,%s,==,?{,_imm,$$,+,pc,=,}", ra);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case beqid:
|
||||
r_strbuf_appendf (&op->esil, "0,%s,==,?{,_imm,$$,+,pc,=,}", ra);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size * 2;
|
||||
break;
|
||||
case bnei:
|
||||
r_strbuf_appendf (&op->esil, "0,%s,==,!,?{,_imm,$$,+,pc,=,}", ra);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case bneid:
|
||||
r_strbuf_appendf (&op->esil, "0,%s,==,!,?{,_imm,$$,+,pc,=,}", ra);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size * 2;
|
||||
break;
|
||||
case blti:
|
||||
r_strbuf_appendf (&op->esil, "0,%s,<,?{,_imm,$$,+,pc,=,}", ra);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case bltid:
|
||||
r_strbuf_appendf (&op->esil, "0,%s,<,?{,_imm,$$,+,pc,=,}", ra);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size * 2;
|
||||
break;
|
||||
case bleid:
|
||||
r_strbuf_appendf (&op->esil, "0,%s,<=,?{,_imm,$$,+,pc,=,}", ra);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size * 2;
|
||||
break;
|
||||
case bgti:
|
||||
r_strbuf_appendf (&op->esil, "0,%s,>,?{,_imm,$$,+,pc,=,}", ra);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case bgtid:
|
||||
r_strbuf_appendf (&op->esil, "0,%s,>,?{,_imm,$$,+,pc,=,}", ra);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size * 2;
|
||||
break;
|
||||
case blei:
|
||||
r_strbuf_appendf (&op->esil, "0,%s,<=,?{,_imm,$$,+,pc,=,}", ra);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case bgeid:
|
||||
r_strbuf_appendf (&op->esil, "0,%s,>=,?{,_imm,$$,+,pc,=,}", ra);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size * 2;
|
||||
break;
|
||||
case bgei:
|
||||
r_strbuf_appendf (&op->esil, "0,%s,>=,?{,_imm,$$,+,pc,=,}", ra);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Reset _immf to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_immf,=");
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
}
|
||||
|
||||
static void analyse_branch_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
struct op_code_struct *mb_op) {
|
||||
RAnalOp *op = ctx->op;
|
||||
@@ -475,20 +662,19 @@ static void analyse_branch_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
insn, ctx->immfound, ctx->immval, ctx->op->addr, r1, r2, &targetvalid,
|
||||
&unconditionalbranch);
|
||||
|
||||
imm = long_to_string (jump_addr);
|
||||
|
||||
switch (mb_op->instr) {
|
||||
case br:
|
||||
r_strbuf_setf (&op->esil, "%s,pc,=+", rb);
|
||||
r_strbuf_setf (&op->esil, "%s,$$,+,pc,=", rb);
|
||||
op->type = R_ANAL_OP_TYPE_UJMP;
|
||||
break;
|
||||
case brd:
|
||||
r_strbuf_setf (&op->esil, "%s,pc,=+", rb);
|
||||
r_strbuf_setf (&op->esil, "%s,$$,+,pc,=", rb);
|
||||
op->type = R_ANAL_OP_TYPE_UJMP;
|
||||
op->delay = 1;
|
||||
break;
|
||||
case brld:
|
||||
r_strbuf_setf (&op->esil, "%s,pc,=+,pc,%s,=,", rb, rd);
|
||||
op->type = R_ANAL_OP_TYPE_UJMP;
|
||||
op->type = R_ANAL_OP_TYPE_UCALL;
|
||||
op->delay = 1;
|
||||
break;
|
||||
case bra:
|
||||
@@ -502,7 +688,7 @@ static void analyse_branch_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
break;
|
||||
case brald:
|
||||
r_strbuf_setf (&op->esil, "%s,pc,=,pc,%s,=,", rb, rd);
|
||||
op->type = R_ANAL_OP_TYPE_UJMP;
|
||||
op->type = R_ANAL_OP_TYPE_UCALL;
|
||||
op->delay = 1;
|
||||
break;
|
||||
case microblaze_brk:
|
||||
@@ -558,176 +744,55 @@ static void analyse_branch_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
op->type = R_ANAL_OP_TYPE_UCJMP;
|
||||
op->delay = 1;
|
||||
break;
|
||||
case bri:
|
||||
r_strbuf_setf (&op->esil, "%s,pc,=", imm);
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
op->jump = jump_addr;
|
||||
break;
|
||||
case brid:
|
||||
r_strbuf_setf (&op->esil, "%s,pc,=", imm);
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
break;
|
||||
case brlid:
|
||||
r_strbuf_setf (&op->esil, "pc,%s,=,%s,pc,=", rd, imm);
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
break;
|
||||
case brai:
|
||||
r_strbuf_setf (&op->esil, "%s,pc,=", imm);
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
op->jump = jump_addr;
|
||||
break;
|
||||
case braid:
|
||||
r_strbuf_setf (&op->esil, "%s,pc,=", imm);
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
break;
|
||||
case bralid:
|
||||
r_strbuf_setf (&op->esil, "%s,pc,=", imm);
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
break;
|
||||
case brki:
|
||||
r_strbuf_setf (&op->esil, "TRAP", imm);
|
||||
op->type = R_ANAL_OP_TYPE_JMP;
|
||||
op->jump = jump_addr;
|
||||
break;
|
||||
case beqi:
|
||||
r_strbuf_setf (&op->esil, "0,%s,==,?{,%s,pc,=,}", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case beqid:
|
||||
r_strbuf_setf (&op->esil, "0,%s,==,?{,%s,pc,=,}", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case bnei:
|
||||
r_strbuf_setf (&op->esil, "0,%s,==,!,?{,%s,pc,=,}", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case bneid:
|
||||
r_strbuf_setf (&op->esil, "0,%s,==,!,?{,%s,pc,=,}", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case blti:
|
||||
r_strbuf_setf (&op->esil, "0,%s,<,?{,%s,pc,=,}", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case bltid:
|
||||
r_strbuf_setf (&op->esil, "0,%s,<,?{,%s,pc,=,}", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case blei:
|
||||
r_strbuf_setf (&op->esil, "0,%s,<=,?{,%s,pc,=,}", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case bleid:
|
||||
r_strbuf_setf (&op->esil, "0,%s,<=,?{,%s,pc,=,}", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case bgti:
|
||||
r_strbuf_setf (&op->esil, "0,%s,>,?{,%s,pc,=,}", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case bgtid:
|
||||
r_strbuf_setf (&op->esil, "0,%s,>,?{,%s,pc,=,}", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case bgei:
|
||||
r_strbuf_setf (&op->esil, "0,%s,>=,?{,%s,pc,=,}", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
case bgeid:
|
||||
r_strbuf_setf (&op->esil, "0,%s,>=,?{,%s,pc,=,}", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_CJMP;
|
||||
op->delay = 1;
|
||||
op->jump = jump_addr;
|
||||
op->fail = op->addr + op->size;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Reset _imm value to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
// Reset _immf to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_immf,=");
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
}
|
||||
|
||||
static void analyse_return_inst(struct mb_anal_ctx *ctx, unsigned long insn,
|
||||
struct op_code_struct *mb_op) {
|
||||
RAnalOp *op = ctx->op;
|
||||
long r1 = get_int_field_r1 (insn);
|
||||
long r2 = get_int_field_r2 (insn);
|
||||
char *ra = get_field_r1 (insn);
|
||||
char *imm;
|
||||
bool targetvalid, unconditionalbranch;
|
||||
ut32 jump_addr = microblaze_our_get_target_address(
|
||||
insn, ctx->immfound, ctx->immval, ctx->op->addr, r1, r2, &targetvalid,
|
||||
&unconditionalbranch);
|
||||
|
||||
imm = long_to_string (jump_addr);
|
||||
char *imm = get_imm (ctx, insn);
|
||||
|
||||
switch (mb_op->instr) {
|
||||
case rtsd:
|
||||
r_strbuf_setf (&op->esil, "%s,+,%s,pc,=", ra, imm);
|
||||
r_strbuf_setf (&op->esil, "%s,%s,+,pc,=", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_RET;
|
||||
op->delay = 1;
|
||||
break;
|
||||
case rtid:
|
||||
r_strbuf_setf (&op->esil, "%s,+,%s,pc,=", ra, imm);
|
||||
r_strbuf_setf (&op->esil, "%s,%s,+,pc,=", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_RET;
|
||||
op->delay = 1;
|
||||
break;
|
||||
case rtbd:
|
||||
r_strbuf_setf (&op->esil, "%s,+,%s,pc,=", ra, imm);
|
||||
r_strbuf_setf (&op->esil, "%s,%s,+,pc,=", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_RET;
|
||||
op->delay = 1;
|
||||
break;
|
||||
case rted:
|
||||
r_strbuf_setf (&op->esil, "%s,+,%s,pc,=", ra, imm);
|
||||
r_strbuf_setf (&op->esil, "%s,%s,+,pc,=", ra, imm);
|
||||
op->type = R_ANAL_OP_TYPE_RET;
|
||||
op->delay = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Reset _imm value to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
// Reset _immf to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_immf,=");
|
||||
}
|
||||
|
||||
static void analyse_special_inst(struct mb_anal_ctx *ctx, unsigned long insn, struct op_code_struct *mb_op) {
|
||||
RAnalOp *op = ctx->op;
|
||||
char *rd = get_field_r1 (insn);
|
||||
char *ra = get_field_r1 (insn);
|
||||
char *rd = get_field_rd (insn);
|
||||
char *rs = get_field_special (insn, mb_op);
|
||||
char *imm15 = get_field_imm15 (insn);
|
||||
|
||||
switch (mb_op->instr) {
|
||||
case wic:
|
||||
break;
|
||||
@@ -742,16 +807,29 @@ static void analyse_special_inst(struct mb_anal_ctx *ctx, unsigned long insn, st
|
||||
case wdcextflush:
|
||||
break;
|
||||
case mts:
|
||||
r_strbuf_setf (&op->esil, "%s,%s,=", rd, rs);
|
||||
r_strbuf_setf (&op->esil, "%s,%s,=", ra, rs);
|
||||
op->type = R_ANAL_OP_TYPE_MOV;
|
||||
break;
|
||||
case mfs:
|
||||
r_strbuf_setf (&op->esil, "%s,%s,=", rs, rd);
|
||||
op->type = R_ANAL_OP_TYPE_MOV;
|
||||
break;
|
||||
case msrclr:
|
||||
r_strbuf_setf (&op->esil, "msr,%s,=", rd);
|
||||
r_strbuf_appendf (&op->esil, ",%s,UT15_MAX,^⁼,msr,&=", imm15);
|
||||
op->type = R_ANAL_OP_TYPE_MOV;
|
||||
break;
|
||||
case msrset:
|
||||
r_strbuf_setf (&op->esil, "msr,%s,=", rd);
|
||||
r_strbuf_appendf (&op->esil, ",%s,msr,|=", imm15);
|
||||
op->type = R_ANAL_OP_TYPE_MOV;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Reset _imm value to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
// Reset _immf to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_immf,=");
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
}
|
||||
static void analyse_anyware_inst(struct mb_anal_ctx *ctx, unsigned long insn, struct op_code_struct *mb_op) {
|
||||
RAnalOp *op = ctx->op;
|
||||
@@ -775,8 +853,9 @@ static void analyse_anyware_inst(struct mb_anal_ctx *ctx, unsigned long insn, st
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Reset _imm value to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
// Reset _immf to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_immf,=");
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
}
|
||||
|
||||
static void analyse_memory_load_inst(struct mb_anal_ctx *ctx, unsigned long insn, struct op_code_struct *mb_op) {
|
||||
@@ -830,8 +909,9 @@ static void analyse_memory_load_inst(struct mb_anal_ctx *ctx, unsigned long insn
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Reset _imm value to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
// Reset _immf to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_immf,=");
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
}
|
||||
|
||||
static void analyse_memory_store_inst(struct mb_anal_ctx *ctx, unsigned long insn, struct op_code_struct *mb_op) {
|
||||
@@ -888,8 +968,9 @@ static void analyse_memory_store_inst(struct mb_anal_ctx *ctx, unsigned long ins
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Reset _imm value to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
// Reset _immf to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_immf,=");
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
}
|
||||
|
||||
static void analyse_barrel_shift_inst(struct mb_anal_ctx *ctx, unsigned long insn, struct op_code_struct *mb_op) {
|
||||
@@ -916,8 +997,8 @@ static void analyse_barrel_shift_inst(struct mb_anal_ctx *ctx, unsigned long ins
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// Reset _imm value to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_imm,=");
|
||||
// Reset _immf to zero even if not used.
|
||||
r_strbuf_appendf (&op->esil, ",0,_immf,=");
|
||||
}
|
||||
|
||||
|
||||
@@ -985,6 +1066,9 @@ static int microblaze_op(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l
|
||||
case arithmetic_inst:
|
||||
analyse_arithmetic_inst (&ctx, insn, mb_op);
|
||||
break;
|
||||
case arithmetic_inst_imm:
|
||||
analyse_arithmetic_inst_imm (&ctx, insn, mb_op);
|
||||
break;
|
||||
case logical_inst:
|
||||
analyse_logical_inst (&ctx, insn, mb_op);
|
||||
break;
|
||||
@@ -997,6 +1081,9 @@ static int microblaze_op(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l
|
||||
case branch_inst:
|
||||
analyse_branch_inst (&ctx, insn, mb_op);
|
||||
break;
|
||||
case branch_inst_imm:
|
||||
analyse_branch_inst_imm (&ctx, insn, mb_op);
|
||||
break;
|
||||
case return_inst:
|
||||
analyse_return_inst (&ctx, insn, mb_op);
|
||||
break;
|
||||
@@ -1072,6 +1159,7 @@ static int microblaze_set_reg_profile(RAnal* anal) {
|
||||
"gpr r31 .32 124 0\n"
|
||||
"gpr pc .32 128 0\n"
|
||||
"gpr msr .32 132 0\n" /* machine status register */
|
||||
"gpr c .1 132.29 0\n" /* arithmetic carry */
|
||||
"gpr ear .32 136 0\n" /* exception address register */
|
||||
"gpr esr .32 140 0\n" /* exception status register */
|
||||
"gpr btr .32 144 0\n" /* branch target register */
|
||||
@@ -1081,7 +1169,10 @@ static int microblaze_set_reg_profile(RAnal* anal) {
|
||||
// _imm
|
||||
// this is the temporary upper immadiate value used internally by
|
||||
// the CPU for the following type B instruction.
|
||||
"gpr _imm .32 160 0\n";
|
||||
"gpr _imm .32 160 0\n"
|
||||
// _immf
|
||||
// this is the temporary flag set when an imm value has been set.
|
||||
"gpr _immf .8 164 0\n";
|
||||
return r_reg_set_profile_string(anal->reg, p);
|
||||
}
|
||||
|
||||
|
||||
@@ -476,7 +476,7 @@ microblaze_get_target_address (long inst, bfd_boolean immfound, int immval,
|
||||
{
|
||||
*targetvalid = FALSE;
|
||||
}
|
||||
else if (op->instr_type == branch_inst)
|
||||
else if ((op->instr_type == branch_inst) || (op->instr_type == branch_inst_imm))
|
||||
{
|
||||
switch (op->inst_type)
|
||||
{
|
||||
|
||||
@@ -130,14 +130,14 @@ static struct op_code_struct
|
||||
{"cmpu", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x14000003, OPCODE_MASK_H4, cmpu, arithmetic_inst },
|
||||
{"addkc", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x18000000, OPCODE_MASK_H4, addkc, arithmetic_inst },
|
||||
{"rsubkc",INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x1C000000, OPCODE_MASK_H4, rsubkc, arithmetic_inst },
|
||||
{"addi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x20000000, OPCODE_MASK_H, addi, arithmetic_inst },
|
||||
{"rsubi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x24000000, OPCODE_MASK_H, rsubi, arithmetic_inst },
|
||||
{"addic", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x28000000, OPCODE_MASK_H, addic, arithmetic_inst },
|
||||
{"rsubic",INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x2C000000, OPCODE_MASK_H, rsubic, arithmetic_inst },
|
||||
{"addik", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x30000000, OPCODE_MASK_H, addik, arithmetic_inst },
|
||||
{"rsubik",INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x34000000, OPCODE_MASK_H, rsubik, arithmetic_inst },
|
||||
{"addikc",INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x38000000, OPCODE_MASK_H, addikc, arithmetic_inst },
|
||||
{"rsubikc",INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x3C000000, OPCODE_MASK_H, rsubikc, arithmetic_inst },
|
||||
{"addi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x20000000, OPCODE_MASK_H, addi, arithmetic_inst_imm },
|
||||
{"rsubi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x24000000, OPCODE_MASK_H, rsubi, arithmetic_inst_imm },
|
||||
{"addic", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x28000000, OPCODE_MASK_H, addic, arithmetic_inst_imm },
|
||||
{"rsubic",INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x2C000000, OPCODE_MASK_H, rsubic, arithmetic_inst_imm },
|
||||
{"addik", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x30000000, OPCODE_MASK_H, addik, arithmetic_inst_imm },
|
||||
{"rsubik",INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x34000000, OPCODE_MASK_H, rsubik, arithmetic_inst_imm },
|
||||
{"addikc",INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x38000000, OPCODE_MASK_H, addikc, arithmetic_inst_imm },
|
||||
{"rsubikc",INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x3C000000, OPCODE_MASK_H, rsubikc, arithmetic_inst_imm },
|
||||
{"mul", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x40000000, OPCODE_MASK_H4, mul, mult_inst },
|
||||
{"mulh", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x40000001, OPCODE_MASK_H4, mulh, mult_inst },
|
||||
{"mulhu", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x40000003, OPCODE_MASK_H4, mulhu, mult_inst },
|
||||
@@ -208,25 +208,25 @@ static struct op_code_struct
|
||||
{"rtid", INST_TYPE_R1_IMM, INST_NO_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB6200000, OPCODE_MASK_H1, rtid, return_inst },
|
||||
{"rtbd", INST_TYPE_R1_IMM, INST_NO_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB6400000, OPCODE_MASK_H1, rtbd, return_inst },
|
||||
{"rted", INST_TYPE_R1_IMM, INST_NO_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB6800000, OPCODE_MASK_H1, rted, return_inst },
|
||||
{"bri", INST_TYPE_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8000000, OPCODE_MASK_H12, bri, branch_inst },
|
||||
{"brid", INST_TYPE_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8100000, OPCODE_MASK_H12, brid, branch_inst },
|
||||
{"brlid", INST_TYPE_RD_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8140000, OPCODE_MASK_H2, brlid, branch_inst },
|
||||
{"brai", INST_TYPE_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8080000, OPCODE_MASK_H12, brai, branch_inst },
|
||||
{"braid", INST_TYPE_IMM, INST_NO_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8180000, OPCODE_MASK_H12, braid, branch_inst },
|
||||
{"bralid",INST_TYPE_RD_IMM, INST_NO_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB81C0000, OPCODE_MASK_H2, bralid, branch_inst },
|
||||
{"brki", INST_TYPE_RD_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB80C0000, OPCODE_MASK_H2, brki, branch_inst },
|
||||
{"beqi", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBC000000, OPCODE_MASK_H1, beqi, branch_inst },
|
||||
{"beqid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBE000000, OPCODE_MASK_H1, beqid, branch_inst },
|
||||
{"bnei", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBC200000, OPCODE_MASK_H1, bnei, branch_inst },
|
||||
{"bneid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBE200000, OPCODE_MASK_H1, bneid, branch_inst },
|
||||
{"blti", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBC400000, OPCODE_MASK_H1, blti, branch_inst },
|
||||
{"bltid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBE400000, OPCODE_MASK_H1, bltid, branch_inst },
|
||||
{"blei", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBC600000, OPCODE_MASK_H1, blei, branch_inst },
|
||||
{"bleid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBE600000, OPCODE_MASK_H1, bleid, branch_inst },
|
||||
{"bgti", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBC800000, OPCODE_MASK_H1, bgti, branch_inst },
|
||||
{"bgtid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBE800000, OPCODE_MASK_H1, bgtid, branch_inst },
|
||||
{"bgei", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBCA00000, OPCODE_MASK_H1, bgei, branch_inst },
|
||||
{"bgeid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBEA00000, OPCODE_MASK_H1, bgeid, branch_inst },
|
||||
{"bri", INST_TYPE_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8000000, OPCODE_MASK_H12, bri, branch_inst_imm },
|
||||
{"brid", INST_TYPE_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8100000, OPCODE_MASK_H12, brid, branch_inst_imm },
|
||||
{"brlid", INST_TYPE_RD_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8140000, OPCODE_MASK_H2, brlid, branch_inst_imm },
|
||||
{"brai", INST_TYPE_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8080000, OPCODE_MASK_H12, brai, branch_inst_imm },
|
||||
{"braid", INST_TYPE_IMM, INST_NO_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8180000, OPCODE_MASK_H12, braid, branch_inst_imm },
|
||||
{"bralid",INST_TYPE_RD_IMM, INST_NO_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB81C0000, OPCODE_MASK_H2, bralid, branch_inst_imm },
|
||||
{"brki", INST_TYPE_RD_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB80C0000, OPCODE_MASK_H2, brki, branch_inst_imm },
|
||||
{"beqi", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBC000000, OPCODE_MASK_H1, beqi, branch_inst_imm },
|
||||
{"beqid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBE000000, OPCODE_MASK_H1, beqid, branch_inst_imm },
|
||||
{"bnei", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBC200000, OPCODE_MASK_H1, bnei, branch_inst_imm },
|
||||
{"bneid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBE200000, OPCODE_MASK_H1, bneid, branch_inst_imm },
|
||||
{"blti", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBC400000, OPCODE_MASK_H1, blti, branch_inst_imm },
|
||||
{"bltid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBE400000, OPCODE_MASK_H1, bltid, branch_inst_imm },
|
||||
{"blei", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBC600000, OPCODE_MASK_H1, blei, branch_inst_imm },
|
||||
{"bleid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBE600000, OPCODE_MASK_H1, bleid, branch_inst_imm },
|
||||
{"bgti", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBC800000, OPCODE_MASK_H1, bgti, branch_inst_imm },
|
||||
{"bgtid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBE800000, OPCODE_MASK_H1, bgtid, branch_inst_imm },
|
||||
{"bgei", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBCA00000, OPCODE_MASK_H1, bgei, branch_inst_imm },
|
||||
{"bgeid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBEA00000, OPCODE_MASK_H1, bgeid, branch_inst_imm },
|
||||
{"lbu", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC0000000, OPCODE_MASK_H4, lbu, memory_load_inst },
|
||||
{"lbur", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC0000200, OPCODE_MASK_H4, lbur, memory_load_inst },
|
||||
{"lhu", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC4000000, OPCODE_MASK_H4, lhu, memory_load_inst },
|
||||
|
||||
@@ -25,45 +25,45 @@
|
||||
|
||||
enum microblaze_instr
|
||||
{
|
||||
add, rsub, addc, rsubc, addk, rsubk, addkc, rsubkc, clz, cmp, cmpu,
|
||||
addi, rsubi, addic, rsubic, addik, rsubik, addikc, rsubikc, mul,
|
||||
mulh, mulhu, mulhsu,swapb,swaph,
|
||||
idiv, idivu, bsll, bsra, bsrl, get, put, nget, nput, cget, cput,
|
||||
ncget, ncput, muli, bslli, bsrai, bsrli, mului, or, and, xor,
|
||||
andn, pcmpbf, pcmpbc, pcmpeq, pcmpne, sra, src, srl, sext8, sext16,
|
||||
wic, wdc, wdcclear, wdcextclear, wdcflush, wdcextflush, mts, mfs, mbar,
|
||||
br, brd, brld, bra, brad, brald, microblaze_brk, beq, beqd, bne, bned,
|
||||
blt, bltd, ble, bled, bgt, bgtd, bge, bged, ori, andi, xori, andni,
|
||||
imm, rtsd, rtid, rtbd, rted, bri, brid, brlid, brai, braid, bralid,
|
||||
brki, beqi, beqid, bnei, bneid, blti, bltid, blei, bleid, bgti,
|
||||
bgtid, bgei, bgeid, lbu, lbur, lhu, lhur, lw, lwr, lwx, sb, sbr, sh,
|
||||
shr, sw, swr, swx, lbui, lhui, lwi,
|
||||
sbi, shi, swi, msrset, msrclr, tuqula, fadd, frsub, fmul, fdiv,
|
||||
fcmp_lt, fcmp_eq, fcmp_le, fcmp_gt, fcmp_ne, fcmp_ge, fcmp_un, flt,
|
||||
fint, fsqrt,
|
||||
tget, tcget, tnget, tncget, tput, tcput, tnput, tncput,
|
||||
eget, ecget, neget, necget, eput, ecput, neput, necput,
|
||||
teget, tecget, tneget, tnecget, teput, tecput, tneput, tnecput,
|
||||
aget, caget, naget, ncaget, aput, caput, naput, ncaput,
|
||||
taget, tcaget, tnaget, tncaget, taput, tcaput, tnaput, tncaput,
|
||||
eaget, ecaget, neaget, necaget, eaput, ecaput, neaput, necaput,
|
||||
teaget, tecaget, tneaget, tnecaget, teaput, tecaput, tneaput, tnecaput,
|
||||
getd, tgetd, cgetd, tcgetd, ngetd, tngetd, ncgetd, tncgetd,
|
||||
putd, tputd, cputd, tcputd, nputd, tnputd, ncputd, tncputd,
|
||||
egetd, tegetd, ecgetd, tecgetd, negetd, tnegetd, necgetd, tnecgetd,
|
||||
eputd, teputd, ecputd, tecputd, neputd, tneputd, necputd, tnecputd,
|
||||
agetd, tagetd, cagetd, tcagetd, nagetd, tnagetd, ncagetd, tncagetd,
|
||||
aputd, taputd, caputd, tcaputd, naputd, tnaputd, ncaputd, tncaputd,
|
||||
eagetd, teagetd, ecagetd, tecagetd, neagetd, tneagetd, necagetd, tnecagetd,
|
||||
eaputd, teaputd, ecaputd, tecaputd, neaputd, tneaputd, necaputd, tnecaputd,
|
||||
invalid_inst
|
||||
add, rsub, addc, rsubc, addk, rsubk, addkc, rsubkc, clz, cmp, cmpu,
|
||||
addi, rsubi, addic, rsubic, addik, rsubik, addikc, rsubikc, mul,
|
||||
mulh, mulhu, mulhsu,swapb,swaph,
|
||||
idiv, idivu, bsll, bsra, bsrl, get, put, nget, nput, cget, cput,
|
||||
ncget, ncput, muli, bslli, bsrai, bsrli, mului, or, and, xor,
|
||||
andn, pcmpbf, pcmpbc, pcmpeq, pcmpne, sra, src, srl, sext8, sext16,
|
||||
wic, wdc, wdcclear, wdcextclear, wdcflush, wdcextflush, mts, mfs, mbar,
|
||||
br, brd, brld, bra, brad, brald, microblaze_brk, beq, beqd, bne, bned,
|
||||
blt, bltd, ble, bled, bgt, bgtd, bge, bged, ori, andi, xori, andni,
|
||||
imm, rtsd, rtid, rtbd, rted, bri, brid, brlid, brai, braid, bralid,
|
||||
brki, beqi, beqid, bnei, bneid, blti, bltid, blei, bleid, bgti,
|
||||
bgtid, bgei, bgeid, lbu, lbur, lhu, lhur, lw, lwr, lwx, sb, sbr, sh,
|
||||
shr, sw, swr, swx, lbui, lhui, lwi,
|
||||
sbi, shi, swi, msrset, msrclr, tuqula, fadd, frsub, fmul, fdiv,
|
||||
fcmp_lt, fcmp_eq, fcmp_le, fcmp_gt, fcmp_ne, fcmp_ge, fcmp_un, flt,
|
||||
fint, fsqrt,
|
||||
tget, tcget, tnget, tncget, tput, tcput, tnput, tncput,
|
||||
eget, ecget, neget, necget, eput, ecput, neput, necput,
|
||||
teget, tecget, tneget, tnecget, teput, tecput, tneput, tnecput,
|
||||
aget, caget, naget, ncaget, aput, caput, naput, ncaput,
|
||||
taget, tcaget, tnaget, tncaget, taput, tcaput, tnaput, tncaput,
|
||||
eaget, ecaget, neaget, necaget, eaput, ecaput, neaput, necaput,
|
||||
teaget, tecaget, tneaget, tnecaget, teaput, tecaput, tneaput, tnecaput,
|
||||
getd, tgetd, cgetd, tcgetd, ngetd, tngetd, ncgetd, tncgetd,
|
||||
putd, tputd, cputd, tcputd, nputd, tnputd, ncputd, tncputd,
|
||||
egetd, tegetd, ecgetd, tecgetd, negetd, tnegetd, necgetd, tnecgetd,
|
||||
eputd, teputd, ecputd, tecputd, neputd, tneputd, necputd, tnecputd,
|
||||
agetd, tagetd, cagetd, tcagetd, nagetd, tnagetd, ncagetd, tncagetd,
|
||||
aputd, taputd, caputd, tcaputd, naputd, tnaputd, ncaputd, tncaputd,
|
||||
eagetd, teagetd, ecagetd, tecagetd, neagetd, tneagetd, necagetd, tnecagetd,
|
||||
eaputd, teaputd, ecaputd, tecaputd, neaputd, tneaputd, necaputd, tnecaputd,
|
||||
invalid_inst
|
||||
};
|
||||
|
||||
enum microblaze_instr_type
|
||||
{
|
||||
arithmetic_inst, logical_inst, mult_inst, div_inst, branch_inst,
|
||||
return_inst, immediate_inst, special_inst, memory_load_inst,
|
||||
memory_store_inst, barrel_shift_inst, anyware_inst
|
||||
arithmetic_inst, arithmetic_inst_imm, logical_inst, mult_inst, div_inst, branch_inst,
|
||||
branch_inst_imm, return_inst, immediate_inst, special_inst, memory_load_inst,
|
||||
memory_store_inst, barrel_shift_inst, anyware_inst
|
||||
};
|
||||
|
||||
#define INST_WORD_SIZE 4
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
language: python
|
||||
python:
|
||||
- "2.7"
|
||||
- "3.4"
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# radare2ida
|
||||
|
||||
This repository contains a collection of documents, scripts
|
||||
and utilities that will allow you to use IDA and R2, converting
|
||||
projects metadata from one tool to the other and providing
|
||||
tools to integrate them in a more useful way.
|
||||
|
||||
In progress:
|
||||
|
||||
* Documentation about how to use the tool
|
||||
* Export IDB from IDA into a radare2 script
|
||||
* Import radare2 project metadata into IDA database
|
||||
* Launch r2 from IDA
|
||||
* Use IDA as an IO backend for R2
|
||||
* Expose R2 functionalities into IDA
|
||||
* Assembler/Disassembler
|
||||
* Base converter
|
||||
* ROP gadget search
|
||||
* ...
|
||||
|
||||
## ida2r2
|
||||
|
||||
**Note:** This requires the [python-idb](https://github.com/williballenthin/python-idb) installed
|
||||
and available for python imports. It is recommended to use the latest version of
|
||||
`python-idb` by cloning the repository and installing it using `python setup.py install`.
|
||||
@@ -0,0 +1,4 @@
|
||||
Migration from IDA to Radare2
|
||||
=============================
|
||||
|
||||
https://radare.gitbooks.io/radare2book/content/debugger/migration.html
|
||||
@@ -0,0 +1,494 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
""" Convert IDB and IDC from IDA into a radare2 script
|
||||
|
||||
$ ida2r2.py -h
|
||||
|
||||
usage: ida2r2.py [-h] (-idb IDB_FILE | -idc IDC_FILE) -o OUT_FILE [-nc | -nf | -nn]
|
||||
|
||||
Export IDB or IDC from IDA into a radare2 initialization script
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
-idb IDB_FILE, --IDBFile IDB_FILE
|
||||
Path to the IDB file
|
||||
-idc IDC_FILE, --IDCFile IDC_FILE
|
||||
Path to the IDC file
|
||||
-o OUT_FILE, --OutputFile OUT_FILE
|
||||
Export to a specified file path
|
||||
-nc, --no-comments Don't convert comments
|
||||
-nf, --no-functions Don't convert functions
|
||||
-nn, --no-names Don't convert names
|
||||
|
||||
"""
|
||||
|
||||
__author__ = "Itay Cohen (@megabeets_), Maxime Morin (@maijin), Sergi Alvarez (@pancake)"
|
||||
|
||||
|
||||
import argparse
|
||||
import idb
|
||||
import sys
|
||||
import re
|
||||
import base64
|
||||
|
||||
|
||||
# CONSTANTS
|
||||
FLAG_PREFIX="ida."
|
||||
|
||||
def get_args():
|
||||
''' Handle arguments using argparse
|
||||
'''
|
||||
|
||||
arg_parser = argparse.ArgumentParser(
|
||||
description="Export IDB or IDC from IDA into a radare2 initialization script")
|
||||
|
||||
arg_group_files = arg_parser.add_mutually_exclusive_group(required=True)
|
||||
|
||||
arg_group_files.add_argument("-idb", "--IDBFile",
|
||||
action="store",
|
||||
dest="idb_file",
|
||||
help="Path to the IDB file")
|
||||
|
||||
arg_group_files.add_argument("-idc", "--IDCFile",
|
||||
action="store",
|
||||
dest="idc_file",
|
||||
help="Path to the IDC file")
|
||||
|
||||
arg_parser.add_argument("-o", "--OutputFile",
|
||||
action="store",
|
||||
dest="out_file",
|
||||
required=True,
|
||||
help="Export to a specified file path")
|
||||
|
||||
arg_parser.add_argument("-nc", "--no-comments",
|
||||
dest="is_comments",
|
||||
action="store_false",
|
||||
help="Don't convert comments")
|
||||
|
||||
arg_parser.add_argument("-nf", "--no-functions",
|
||||
dest="is_functions",
|
||||
action="store_false",
|
||||
help="Don't convert functions")
|
||||
|
||||
arg_parser.add_argument("-nn", "--no-names",
|
||||
dest="is_names",
|
||||
action="store_false",
|
||||
help="Don't convert names")
|
||||
|
||||
arg_parser.set_defaults(is_comments=True, is_functions=True, is_names=True)
|
||||
|
||||
args = arg_parser.parse_args()
|
||||
return args
|
||||
|
||||
|
||||
|
||||
def write_header():
|
||||
outfile.write("""########################################################
|
||||
#
|
||||
# This file was generated by the ida2r2.py script.
|
||||
# Source: https://github.com/radare/radare2ida
|
||||
#
|
||||
########################################################
|
||||
""")
|
||||
|
||||
###
|
||||
# IDB Parsing
|
||||
#
|
||||
|
||||
def idb2r2_comments(api, textseg):
|
||||
''' Convert comments from a specific text segments in the IDB
|
||||
'''
|
||||
|
||||
for ea in range(textseg, api.idc.SegEnd(textseg)):
|
||||
try:
|
||||
flags = api.ida_bytes.get_cmt(ea, True)
|
||||
if flags != "":
|
||||
outfile.write("CCu base64:{b64} @ {addr}\n".format(
|
||||
b64=base64.b64encode(flags.encode(encoding='UTF-8')).decode("utf-8"),
|
||||
addr=str(ea)
|
||||
))
|
||||
except Exception as e:
|
||||
try:
|
||||
flags = api.ida_bytes.get_cmt(ea, False)
|
||||
outfile.write("CCu base64:{b64} @ {addr}\n".format(
|
||||
b64=base64.b64encode(flags.encode(encoding='UTF-8')).decode("utf-8"),
|
||||
addr=str(ea)
|
||||
))
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def idb2r2_functions(api):
|
||||
''' Convert all functions from the IDB
|
||||
'''
|
||||
outfile.write("\n# IDB Functions\n")
|
||||
|
||||
for ea in api.idautils.Functions():
|
||||
outfile.write("f {prefix}{name} @ {addr}\n".format(
|
||||
prefix=FLAG_PREFIX,
|
||||
name=api.idc.GetFunctionName(ea).replace("@", "_"),
|
||||
addr=str(ea)
|
||||
))
|
||||
# Write the command responsible to analyze these functions
|
||||
outfile.write("aF @@ {prefix}*\n".format(prefix=FLAG_PREFIX))
|
||||
|
||||
def idb2r2_names(api):
|
||||
''' Convert all names from the IDB
|
||||
'''
|
||||
outfile.write("\n# IDB Names\n")
|
||||
|
||||
for ea, name in api.idautils.Names():
|
||||
outfile.write("f {prefix}{name} @ {addr}\n".format(
|
||||
prefix=FLAG_PREFIX,
|
||||
name=name.replace("@", "_"),
|
||||
addr=str(ea)
|
||||
))
|
||||
|
||||
def idb_parse(args):
|
||||
global outfile
|
||||
with idb.from_file(args.idb_file) as db:
|
||||
api = idb.IDAPython(db)
|
||||
# Compatability check for those who install python-idb from pip
|
||||
try:
|
||||
baddr = hex(api.ida_nalt.get_imagebase())
|
||||
except:
|
||||
baddr = "[base address]"
|
||||
outfile = open(args.out_file, 'w')
|
||||
write_header()
|
||||
|
||||
print("[+] Starting conversion from '%s' to '%s'" %
|
||||
(args.idb_file, args.out_file))
|
||||
|
||||
if args.is_functions:
|
||||
idb2r2_functions(api)
|
||||
|
||||
if args.is_names:
|
||||
idb2r2_names(api)
|
||||
|
||||
if args.is_comments:
|
||||
segs = idb.analysis.Segments(db).segments
|
||||
outfile.write("\n# IDB Comments\n")
|
||||
for segment in segs.values():
|
||||
idb2r2_comments(api, segment.startEA)
|
||||
|
||||
print("[+] Conversion done.\n")
|
||||
print("[!] Execute: r2 -i %s -B %s [program]\n" %
|
||||
(args.out_file, baddr))
|
||||
|
||||
#
|
||||
# End of IDB Parsing
|
||||
###
|
||||
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
|
||||
###
|
||||
# IDC Parsing
|
||||
#
|
||||
|
||||
class Func(object):
|
||||
# FIXME: parse ftype into params and values
|
||||
def __init__(self, name="unknown", params=[], values=[], address=0, size=0, ftype=""):
|
||||
self.name = name
|
||||
self.params = params
|
||||
self.values = values
|
||||
self.address = address
|
||||
self.size = size
|
||||
self.ftype = ftype
|
||||
|
||||
class Llabel(object):
|
||||
def __init__(self, name="unknown", address=0):
|
||||
self.name = name
|
||||
self.address = address
|
||||
|
||||
class Comm(object):
|
||||
def __init__(self, text="", address=0):
|
||||
self.text = text
|
||||
self.address = address
|
||||
|
||||
class Enum(object):
|
||||
def __init__(self, name="unknown", members=[]):
|
||||
self.name = name
|
||||
self.members = members
|
||||
|
||||
class Struct(object):
|
||||
def __init__(self, name="unknown", members=[]):
|
||||
self.name = name
|
||||
self.members = members
|
||||
|
||||
class Union(object):
|
||||
def __init__(self, name="unknown", members=[]):
|
||||
self.name = name
|
||||
self.members = members
|
||||
|
||||
class Type(object):
|
||||
def __init__(self, name="unknown"):
|
||||
self.name = name
|
||||
self.members = members
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
functions = []
|
||||
llabels = []
|
||||
comments = []
|
||||
structs = []
|
||||
enums = []
|
||||
types = []
|
||||
|
||||
def idc_functions_parse(idc):
|
||||
|
||||
# MakeFunction (0XF3C99,0XF3CA8);
|
||||
mkfun_re = re.compile("""
|
||||
(?m) # Multiline
|
||||
^[ \t]*MakeFunction[ \t]*\(
|
||||
(?P<fstart>0[xX][\dA-Fa-f]{1,8}) # Function start
|
||||
[ \t]*\,[ \t]*
|
||||
(?P<fend>0[xX][\dA-Fa-f]{1,8}) # Function end
|
||||
[ \t]*\);[ \t]*$
|
||||
""", re.VERBOSE)
|
||||
mkfun_group_name = dict([(v,k) for k,v in mkfun_re.groupindex.items()])
|
||||
mkfun = mkfun_re.finditer(idc)
|
||||
for match in mkfun :
|
||||
fun = Func()
|
||||
for group_index,group in enumerate(match.groups()) :
|
||||
if group :
|
||||
if mkfun_group_name[group_index+1] == "fstart" :
|
||||
fun.address = int(group, 16)
|
||||
if mkfun_group_name[group_index+1] == "fend" :
|
||||
fun.size = int(group, 16) - fun.address
|
||||
|
||||
functions.append(fun)
|
||||
|
||||
# SetFunctionFlags (0XF3C99, 0x400);
|
||||
mkfunflags_re = re.compile("""
|
||||
(?m) # Multiline
|
||||
^[ \t]*SetFunctionFlags[ \t*]\(
|
||||
(?P<fstart>0[xX][\dA-Fa-f]{1,8}) # Function start
|
||||
[ \t]*\,[ \t]*
|
||||
(?P<flags>0[xX][\dA-Fa-f]{1,8}) # Flags
|
||||
[ \t]*\);[ \t]*$
|
||||
""", re.VERBOSE)
|
||||
mkfunflags_group_name = dict([(v,k) for k,v in mkfunflags_re.groupindex.items()])
|
||||
mkfunflags = mkfunflags_re.finditer(idc)
|
||||
for match in mkfunflags :
|
||||
for group_index,group in enumerate(match.groups()) :
|
||||
if group :
|
||||
if mkfunflags_group_name[group_index+1] == "fstart" :
|
||||
addr = int(group, 16)
|
||||
if mkfunflags_group_name[group_index+1] == "flags" :
|
||||
for fun in functions :
|
||||
if fun.address == addr :
|
||||
pass # TODO: parse flags
|
||||
|
||||
|
||||
# MakeFrame (0XF3C99, 0, 0, 0);
|
||||
# MakeName (0XF3C99, "SIO_port_setup_S");
|
||||
mkname_re = re.compile("""
|
||||
(?m) # Multiline
|
||||
^[ \t]*MakeName[ \t]*\(
|
||||
(?P<fstart>0[xX][\dA-Fa-f]{1,8}) # Function start
|
||||
[ \t]*\,[ \t]*
|
||||
"(?P<fname>.*)" # Function name
|
||||
[ \t]*\);[ \t]*$
|
||||
""", re.VERBOSE)
|
||||
mkname_group_name = dict([(v,k) for k,v in mkname_re.groupindex.items()])
|
||||
mkname = mkname_re.finditer(idc)
|
||||
for match in mkname :
|
||||
for group_index,group in enumerate(match.groups()) :
|
||||
if group :
|
||||
if mkname_group_name[group_index+1] == "fstart" :
|
||||
addr = int(group, 16)
|
||||
if mkname_group_name[group_index+1] == "fname" :
|
||||
for fun in functions :
|
||||
if fun.address == addr :
|
||||
fun.name = group
|
||||
|
||||
# SetType (0XFFF72, "__int32 __cdecl PCI_ByteWrite_SL(__int32 address, __int32 value)");
|
||||
mkftype_re = re.compile("""
|
||||
(?m) # Multiline
|
||||
^[ \t]*SetType[ \t]*\(
|
||||
(?P<fstart>0[xX][\dA-Fa-f]{1,8}) # Function start
|
||||
[ \t]*\,[ \t]*
|
||||
"(?P<ftype>.*)" # Function type
|
||||
[ \t]*\);[ \t]*$
|
||||
""", re.VERBOSE)
|
||||
mkftype_group_name = dict([(v,k) for k,v in mkftype_re.groupindex.items()])
|
||||
mkftype = mkftype_re.finditer(idc)
|
||||
for match in mkftype :
|
||||
for group_index,group in enumerate(match.groups()) :
|
||||
if group :
|
||||
if mkftype_group_name[group_index+1] == "fstart" :
|
||||
addr = int(group, 16)
|
||||
if mkftype_group_name[group_index+1] == "ftype" :
|
||||
for fun in functions :
|
||||
if fun.address == addr :
|
||||
fun.ftype = group
|
||||
|
||||
# MakeNameEx (0xF3CA0, "return", SN_LOCAL);
|
||||
mklocal_re = re.compile("""
|
||||
(?m) # Multiline
|
||||
^[ \t]*MakeNameEx[ \t]*\(
|
||||
(?P<laddr>0[xX][\dA-Fa-f]{1,8}) # Local label address
|
||||
[ \t]*\,[ \t]*
|
||||
"(?P<lname>.*)" # Local label name
|
||||
[ \t]*\,[ \t]*SN_LOCAL
|
||||
[ \t]*\);[ \t]*$
|
||||
""", re.VERBOSE)
|
||||
mklocal_group_name = dict([(v,k) for k,v in mklocal_re.groupindex.items()])
|
||||
mklocal = mklocal_re.finditer(idc)
|
||||
for match in mklocal :
|
||||
lab = Llabel()
|
||||
for group_index,group in enumerate(match.groups()) :
|
||||
if group :
|
||||
if mklocal_group_name[group_index+1] == "laddr" :
|
||||
lab.address = int(group, 16)
|
||||
if mklocal_group_name[group_index+1] == "lname" :
|
||||
lab.name = group
|
||||
llabels.append(lab)
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
def idc_enums_parse(idc):
|
||||
pass
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
def idc_structs_parse(idc):
|
||||
# id = AddStrucEx (-1, "struct_MTRR", 0);
|
||||
mkstruct_re = re.compile("""
|
||||
(?m) # Multiline
|
||||
^[ \t]*id[ \t]*=[ \t]*AddStrucEx[ \t]*\(
|
||||
[ \t]*-1[ \t]*,[ \t]*
|
||||
"(?P<sname>.*)" # Structure name
|
||||
[ \t]*\,[ \t]*0
|
||||
[ \t]*\);[ \t]*$
|
||||
""", re.VERBOSE)
|
||||
mkstruct_group_name = dict([(v,k) for k,v in mkstruct_re.groupindex.items()])
|
||||
mkstruct = mkstruct_re.finditer(idc)
|
||||
for match in mkstruct :
|
||||
s = Struct()
|
||||
for group_index,group in enumerate(match.groups()) :
|
||||
if group :
|
||||
if mkstruct_group_name[group_index+1] == "sname" :
|
||||
s.name = group
|
||||
structs.append(s)
|
||||
|
||||
# Case 1: not nested structures
|
||||
# =============================
|
||||
# id = GetStrucIdByName ("struct_header");
|
||||
# mid = AddStructMember(id,"BCPNV", 0, 0x5000c500, 0, 7);
|
||||
# mid = AddStructMember(id,"_", 0X7, 0x00500, -1, 1);
|
||||
# mid = AddStructMember(id, "BCPNV_size",0X8, 0x004500, -1, 1);
|
||||
mkstruct_re = re.compile("""
|
||||
(?m) # Multiline
|
||||
^[ \t]*id[ \t]*=[ \t]*GetStrucIdByName[ \t]*\(
|
||||
[ \t]*-1[ \t]*,[ \t]*
|
||||
"(?P<sname>.*)" # Structure name
|
||||
[ \t]*\,[ \t]*0
|
||||
[ \t]*\);[ \t]*$
|
||||
""", re.VERBOSE)
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
def idc_comments_parse(idc):
|
||||
# MakeComm (0XFED3D, "PCI class 0x600 - Host/PCI bridge");
|
||||
mkcomm_re = re.compile("""
|
||||
(?m) # Multiline
|
||||
^[ \t]*MakeComm[ \t]*\(
|
||||
(?P<caddr>0[xX][\dA-Fa-f]{1,8}) # Comment address
|
||||
[ \t]*\,[ \t]*
|
||||
"(?P<ctext>.*)" # Comment
|
||||
[ \t]*\);[ \t]*$
|
||||
""", re.VERBOSE)
|
||||
mkcomm_group_name = dict([(v,k) for k,v in mkcomm_re.groupindex.items()])
|
||||
mkcomm = mkcomm_re.finditer(idc)
|
||||
for match in mkcomm :
|
||||
for group_index,group in enumerate(match.groups()) :
|
||||
if group :
|
||||
if mkcomm_group_name[group_index+1] == "caddr" :
|
||||
address = int(group, 16)
|
||||
if mkcomm_group_name[group_index+1] == "ctext" :
|
||||
com_multi = group.split('\\n')
|
||||
for a in com_multi :
|
||||
com = Comm()
|
||||
com.address = address
|
||||
com.text = a
|
||||
comments.append(com)
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
# print("af+ 0x%08lx %d %s" % (func.address, func.size, func.name))
|
||||
|
||||
def idc_generate_r2(out_file):
|
||||
global outfile
|
||||
outfile = open(out_file, 'w')
|
||||
write_header()
|
||||
for f in functions :
|
||||
if f.name != "unknown" :
|
||||
outfile.write("af+ {addr} {size} {name}\n".format(
|
||||
addr=hex(f.address),
|
||||
size=f.size,
|
||||
name=f.name))
|
||||
outfile.write("\"CCa {addr} {type}\"\n".format(
|
||||
addr=hex(f.address),
|
||||
type=f.ftype))
|
||||
|
||||
for l in llabels :
|
||||
if l.name != "unknown" :
|
||||
for f in functions :
|
||||
if (l.address > f.address) and (l.address < (f.address + f.size)) :
|
||||
outfile.write("f. {name} @ {addr}\n".format(
|
||||
name=l.name,
|
||||
addr=hex(l.address)))
|
||||
|
||||
for c in comments :
|
||||
if c.text != "" :
|
||||
outfile.write("\"CCa {addr} {text}\"\n".format(
|
||||
addr=c.address,
|
||||
text=c.text))
|
||||
|
||||
outfile.seek(0,2)
|
||||
if outfile.tell() == 0:
|
||||
print("[-] Found nothing to convert :-(")
|
||||
exit()
|
||||
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
def idc_parse(args):
|
||||
print("[+] Starting convertion from '%s' to '%s'" %
|
||||
(args.idc_file, args.out_file))
|
||||
idc_file = open(args.idc_file, "r")
|
||||
idc = idc_file.read()
|
||||
idc_enums_parse(idc)
|
||||
idc_structs_parse(idc)
|
||||
if args.is_functions:
|
||||
idc_functions_parse(idc)
|
||||
if args.is_comments:
|
||||
idc_comments_parse(idc)
|
||||
idc_generate_r2(args.out_file)
|
||||
print("[+] Convertion done.\n")
|
||||
print("[!] Execute: r2 -i %s [program]\n" %
|
||||
(args.out_file))
|
||||
|
||||
#
|
||||
# End of IDC Parsing
|
||||
###
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
def main():
|
||||
''' Gets arguments from the user. Perform convertion of the chosen data from the IDB into a radare2 initialization script
|
||||
'''
|
||||
args = get_args()
|
||||
|
||||
if args.idb_file:
|
||||
idb_parse(args)
|
||||
elif args.idc_file:
|
||||
idc_parse(args)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* ida2rdb.idc
|
||||
* ===========
|
||||
*
|
||||
* Exports an ida database in a format to be handled by radare
|
||||
*
|
||||
* author: pancake <@youterm.com>
|
||||
*
|
||||
* TODO:
|
||||
* * Add stack frame related information (stack size, and so) as comments
|
||||
*
|
||||
*/
|
||||
|
||||
#include <idc.idc>
|
||||
|
||||
static dumpMeNot(fd, ea) {
|
||||
auto func, comment, sz, i, ref;
|
||||
|
||||
// Loop from start to end in the current segment
|
||||
//SegStart(ea);
|
||||
for (func=ea; func != BADADDR && func < SegEnd(ea); func=NextFunction(func)) {
|
||||
// If the current address is function process it
|
||||
// if (GetFunctionFlags(func) != -1) {
|
||||
sz = FindFuncEnd(func) - func;
|
||||
fprintf(fd, "afr %s 0x%08lx\n", GetFunctionName(func), func);
|
||||
|
||||
comment = GetFunctionCmt(func, 0);
|
||||
if (comment != "")
|
||||
fprintf(fd, "CC %s@0x%08x\n", comment, func);
|
||||
|
||||
fprintf(fd, "CC framesize=%d@0x%08x\n", func, GetFrameSize(func));
|
||||
|
||||
// Find all code references to func
|
||||
for (ref=RfirstB(func); ref != BADADDR; ref=RnextB(func, ref)) {
|
||||
//fprintf(fd, "; xref from %08lX (%s)\n", ref, GetFunctionName(ref));
|
||||
fprintf(fd, "Cx 0x%08lx 0x%08lx\n", func, ref);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
func=ea;
|
||||
while (func != BADADDR && func < SegEnd(ea)) {
|
||||
comment = CommentEx(func, 0);
|
||||
if (comment != "")
|
||||
fprintf(fd, "CC %s@0x%08x\n", comment, func);
|
||||
comment = GetConstCmt(func, 0);
|
||||
if (comment != "")
|
||||
fprintf(fd, "CC %s@0x%08x\n", comment, func);
|
||||
comment = GetEnumCmt(func, 0);
|
||||
if (comment != "")
|
||||
fprintf(fd, "CC %s@0x%08x\n", comment, func);
|
||||
comment = RptCmt(func);
|
||||
if (comment != "")
|
||||
fprintf(fd, "CC %s@0x%08x\n", comment, func);
|
||||
func = func + ItemSize(func);
|
||||
}
|
||||
}
|
||||
|
||||
static main() {
|
||||
auto fd;
|
||||
auto file;
|
||||
auto i, func, ref,sz;
|
||||
auto ord,ea;
|
||||
auto comment;
|
||||
auto entry;
|
||||
|
||||
file = GetInputFile()+".txt";
|
||||
fd = fopen(file, "w");
|
||||
if (!fd) {
|
||||
Message("Cannot open '"+file+"'\n");
|
||||
Exit(1);
|
||||
}
|
||||
|
||||
entry="";
|
||||
// Walk entrypoints
|
||||
for ( i=0; ; i++ ) {
|
||||
ord = GetEntryOrdinal(i);
|
||||
if ( ord == 0 ) break;
|
||||
ea = GetEntryPoint(ord);
|
||||
fprintf(fd, "entry=0x%08lx %s\n", ea, Name(ea));
|
||||
entry = ea;
|
||||
}
|
||||
|
||||
// XXX last entrypoint taken as ok??
|
||||
dumpMeNot(fd, entry);
|
||||
|
||||
// eof
|
||||
fclose(fd);
|
||||
|
||||
Message(file+"file generated.\n");
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/perl
|
||||
# author: pancake <youterm.com>
|
||||
# MakeName (0X804C1AF, "the_forker");
|
||||
# MakeRptCmt (0X804C1B6, "comentari chachi\n");
|
||||
|
||||
open FD, "<".$ARGV[0] or die "Cannot open file\n";
|
||||
print "fs symbols\n";
|
||||
while(<FD>) {
|
||||
$str=$_;
|
||||
if ($str=~/MakeName[^X]*.([^,]*)[^"]*.([^"]*)/) {
|
||||
print "f sym.$2 @ 0x$1\n";
|
||||
}
|
||||
elsif ($str=~/MakeRptCmt[^X]*.([^,]*)[^"]*.([^"]*)/) {
|
||||
$cmt = $2;
|
||||
$off = $1;
|
||||
$cmt=~s/\\n//g;
|
||||
print "CC $cmt @ 0x$off\n";
|
||||
}
|
||||
}
|
||||
Generated
+10
-7
@@ -592,10 +592,13 @@
|
||||
}
|
||||
},
|
||||
"eslint-utils": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.3.1.tgz",
|
||||
"integrity": "sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q==",
|
||||
"dev": true
|
||||
"version": "1.4.2",
|
||||
"resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.4.2.tgz",
|
||||
"integrity": "sha512-eAZS2sEUMlIeCjBeubdj45dmBHQwPHWyBcT1VSYB7o9x9WRRqKxyUoiXlRjyAwzN7YEzHJlYg0NmzDRWx6GP4Q==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"eslint-visitor-keys": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"eslint-visitor-keys": {
|
||||
"version": "1.0.0",
|
||||
@@ -1013,9 +1016,9 @@
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.11",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
|
||||
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==",
|
||||
"version": "4.17.15",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
||||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
|
||||
"dev": true
|
||||
},
|
||||
"loose-envify": {
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
# r2k
|
||||
kernel module for radare2
|
||||
|
||||
This module is going to be part of radare2 (https://github.com/radare/radare2).
|
||||
This module is going to be part of radare2 (https://github.com/radareorg/radare2).
|
||||
|
||||
It will work together with an userland program (https://github.com/radare/radare2/blob/master/libr/io/p/io_r2k.c)
|
||||
It will work together with an userland program (https://github.com/radareorg/radare2/blob/master/libr/io/p/io_r2k.c)
|
||||
|
||||
This module allows to:
|
||||
|
||||
|
||||
+2
-2
@@ -63,7 +63,7 @@ Q&A
|
||||
|
||||
Where can I find some sample programs to take as a template?
|
||||
---
|
||||
https://github.com/radare/radare2-extras/tree/master/r2wars/t
|
||||
https://github.com/radareorg/radare2-extras/tree/master/r2wars/t
|
||||
|
||||
How to make awesome warrior that wins r2wars if I'm a n00b?
|
||||
---
|
||||
@@ -79,7 +79,7 @@ ARM and MIPS have memory alignment restrictions, so you dont want to run code or
|
||||
|
||||
This is pending to be implemented, but will be done before r2con. See those bugs for more details
|
||||
|
||||
https://github.com/radare/radare2/labels/r2wars
|
||||
https://github.com/radareorg/radare2/labels/r2wars
|
||||
|
||||
How is this code executed?
|
||||
---
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
},
|
||||
"license": "LGPL-3.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/radare/radare2-extras/issues"
|
||||
"url": "https://github.com/radareorg/radare2-extras/issues"
|
||||
},
|
||||
"homepage": "http://www.radare.org",
|
||||
"dependencies": {
|
||||
|
||||
Reference in new issue
Block a user