Compare commits

...
42 Commits
Author SHA1 Message Date
pancake dc5887818e Release 4.4.0 2020-04-14 04:59:48 +02:00
FXTi ac22c81ada Fix (#243) 2020-04-12 10:50:35 +02:00
pancake 859c307cb5 Optimize travis 2020-04-12 02:04:12 +02:00
pancake 249e782a2e Fix crash in swf 2020-04-12 01:00:37 +02:00
pancake 097a5f56e4 Fix build of the unicorn plugin 2020-04-12 00:51:58 +02:00
FXTi d65bb20b65 .pyc anal plugin (#237)
* Add symbols in pyc's bin
2020-04-12 00:40:21 +02:00
dependabot[bot] e9993f8fdf Bump acorn from 6.1.1 to 6.4.1 in /r2jadx (#239)
Bumps [acorn](https://github.com/acornjs/acorn) from 6.1.1 to 6.4.1.
- [Release notes](https://github.com/acornjs/acorn/releases)
- [Commits](https://github.com/acornjs/acorn/compare/6.1.1...6.4.1)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-04-05 01:42:38 +02:00
Itay Cohen db29d60aa9 Merge pull request #238 from sylvainpelissier/yara
Update yara  module according to yara API changes
2020-04-04 17:01:29 +03:00
Sylvain Pelissier e9a74be52c Update yara module according to yara API changes 2020-03-22 18:57:07 +01:00
FXTi 72a43824b1 Correct entries function and fixes (#236) 2020-03-18 00:05:54 +01:00
FXTi 8a5936eb64 Improvement of Bin and Asm of pyc plugin (#235) 2020-03-15 09:00:39 +01:00
pancake e4a73ccf07 Release 4.3.0 2020-03-04 01:25:03 +01:00
Sylvain Pelissier fc564166bd Update test folder to radare2/test and add test for yara in Travis (#233) 2020-03-02 21:36:20 +08:00
pancake 7cc5d343af Enable bcl in travis 2020-03-02 12:24:32 +01:00
pancake 854e6f38ed Fix build of BCL plugins (asm, anal, bin) 2020-03-02 12:23:57 +01:00
Sylvain Pelissier 8da191d171 Add print string option to yara 2020-03-01 20:57:48 +01:00
pancake 2749dedb1e The retdec pkg doesnt needs to be tested by us 2020-02-12 00:25:10 +01:00
pancake 327898bac1 Fix build for pcap and swf 2020-02-12 00:22:22 +01:00
pancake 046efbdae8 Fix more plugins 2020-02-11 15:58:45 +01:00
pancake cc4a103ff3 Fix swf build 2020-02-11 15:53:42 +01:00
pancake b9723c5629 Fix nios build 2020-02-11 15:48:36 +01:00
pancake ae90621fe0 Initial implementation of the r2svd tool 2020-02-11 12:23:20 +01:00
Khairulmizam Samsudin 2e53b36308 Code cleanup 2020-02-06 17:55:28 +01:00
Khairulmizam Samsudin 26838fc56f Implement disassembler for Python >=3.6
- Used architecture bits to diffrentiate Python operand size
- Default to Python >=3.6
2020-02-06 17:55:28 +01:00
Khairulmizam Samsudin 986b99a6fe Implement disassembler for Python <3.6 2020-02-06 17:55:28 +01:00
Khairulmizam Samsudin 4c9a552d06 Change line ending to unix 2020-02-06 17:55:28 +01:00
Khairulmizam Samsudin ef5771f7ce Various fix for section detection (#226)
- Correct pointer offset after finding entry point
- Define the right size for Python object type
- Prevent memory corruption problem when naming section
2020-02-04 17:57:38 +01:00
Sylvain Pelissier 8ba3432f5c Microblaze ESIL load and store with immediate 2020-02-03 15:13:39 +01:00
Sylvain Pelissier 271369f8ee Move RAnalOpMask into parameter 2020-02-03 15:13:39 +01:00
Sylvain Pelissier 145e685c60 Logical instructions with immediate 2020-02-03 15:13:39 +01:00
Sylvain Pelissier 730433360e Microblaze ESIL: handle carry flag 2020-02-03 15:13:39 +01:00
Khairulmizam Samsudin f1f617f791 Implement new method to find entrypoint
- Detect entrypoint for ALL cpython version
- Detection does not depend on correct bytecode magic number
2020-02-02 11:13:26 +01:00
Khairulmizam Samsudin c3d8e433bd Refactor pyc_version struct
- Update latest magic from github.com/python/cpython
- Simplify the structure of pyc_version
- remove unicode information from pyc_version struct
2020-02-02 11:13:26 +01:00
Khairulmizam Samsudin 934c08364f Add base address information 2020-01-28 18:07:58 +01:00
Khairulmizam Samsudin 6e8b2ed5db Fix bytecode version detection 2020-01-28 18:07:58 +01:00
Khairulmizam Samsudin 2434f97937 Replace CORELIB with R2_PLUGIN_INCORE 2020-01-28 18:07:58 +01:00
procfs 3319911179 fix overflow bugs in pyc module 2020-01-27 16:58:39 +01:00
Khairulmizam Samsudin 5eb18b3e3b Disable TYPE_LONG due to dependencies to libgmp 2020-01-27 07:45:37 +01:00
Khairulmizam Samsudin 91eeb7b154 Updated using new RBuffer struct 2020-01-27 07:45:37 +01:00
Khairulmizam Samsudin b01f0180ea Updated using new RBinPlugin struct 2020-01-27 07:45:37 +01:00
Khairulmizam Samsudin 16e27dc9e9 Ignore tags 2020-01-27 07:45:37 +01:00
Sylvain Pelissier 5f6f945498 Microblaze ESIL for shift and sign extension (#216) 2019-10-28 16:53:50 +01:00
80 changed files with 5616 additions and 2186 deletions

No files matched your search

+3
View File
@@ -18,3 +18,6 @@
*.un~
/Makefile
/options.mk
# misc
tags
+8 -9
View File
@@ -32,19 +32,19 @@ addons:
env:
- TESTS="r2pm -i armthumb"
- TESTS="r2pm -i baleful"
# - TESTS="r2pm -i bcl" [BR] https://travis-ci.org/radareorg/radare2-extras/builds/157522362
- TESTS="r2pm -i bcl"
- TESTS="r2pm -i blackfin"
- TESTS="r2pm -i blessr2"
# - 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"
# ONLY FOR LINUX - 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="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/radareorg/radare2-extras/builds/157522362
- TESTS="r2pm -i mc6809"
- TESTS="r2pm -i microblaze && cd radare2-regressions && make microblaze"
- TESTS="r2pm -i microblaze && cd radare2/test && make microblaze && cd ../.."
- TESTS="r2pm -i msil"
- TESTS="r2pm -i pcap"
- TESTS="r2pm -i ppcdisasm"
@@ -60,8 +60,8 @@ env:
- TESTS="r2pm -i radare2"
# - 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 .."
# - TESTS="r2pm -i retdec"
- TESTS="r2pm -i swf && make -C radare2/test swf"
# - TESTS="r2pm -i m68k-net && cd radare2-regressions && make m68k-extras && cd .." [BR] https://travis-ci.org/radare/radare2-extras/builds/387043680
# - TESTS="r2pm -i swig" Sorry. This package cannot be installed in your home.
- TESTS="r2pm -i syms2elf"
@@ -79,9 +79,9 @@ env:
- TESTS="r2pm -i x86udis"
- TESTS="r2pm -i x86bea"
- TESTS="r2pm -i x86tab"
- TESTS="r2pm -i x86olly && cd radare2-regressions && make olly-extras && cd .."
- TESTS="r2pm -i x86olly && cd radare2/test && make olly-extras && cd ../.."
- TESTS="r2pm -i z80-nc"
- TESTS="r2pm -i yara && r2pm -i yara-r2"
- TESTS="r2pm -i yara && r2pm -i yara-r2 && cd radare2/test && make yara && cd ../.."
- TESTS="r2pm -i x86zyan"
language:
- rust
@@ -95,7 +95,6 @@ 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 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
+1 -1
View File
@@ -37,7 +37,7 @@ static int findpair(ut64 addr, const ut8 *buf, int len, int base) {
return 0;
}
static int bcl_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
static int bcl_op(RAnal *anal, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) {
int i;
char cache[256] = {0};
ut64 dst = 0LL;
+6 -3
View File
@@ -9,21 +9,23 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
const char *bases = "ACGT";
if (a->pc == 0) {
ut32 *clusters = (ut32*)buf;
snprintf (op->buf_asm, sizeof (op->buf_asm), "clusters %d\n", *clusters);
r_strbuf_setf (&op->buf_asm, "clusters %d", *clusters);
// snprintf (op->buf_asm, sizeof (op->buf_asm), "clusters %d\n", *clusters);
return op->size = 4;
}
if (*buf != 0) {
char base = bases[*buf & 3];
int qual = *buf >> 2;
snprintf (op->buf_asm, sizeof (op->buf_asm), "%c ; %d", base, qual);
r_strbuf_setf (&op->buf_asm, "%c ; %d", base, qual);
op->size = 1;
return 1;
}
strcpy (op->buf_asm, ".");
r_strbuf_setf (&op->buf_asm, ".");
return 0;
}
static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
#if 0
bool qmode = false;
int quality = 0;
int outsz = 128;
@@ -76,6 +78,7 @@ static int assemble(RAsm *a, RAsmOp *op, const char *buf) {
out[op->size] = (quality<<2) | base;
op->size ++;
}
#endif
return op->size;
}
+65 -90
View File
@@ -5,8 +5,11 @@
#include <r_lib.h>
#include <r_bin.h>
static int check_bytes(const ut8 *buf, ut64 length) {
if (buf && length >= 4) {
static bool __check_buffer(RBuffer *b) {
ut8 buf[8];
int length = r_buf_size (b);
int r = r_buf_read_at (b, 0, buf, sizeof (buf));
if (r == sizeof (buf)) {
ut32 cls = r_mem_get_num (buf, 4);
ut32 cls2 = r_mem_get_num (buf + 4, 4);
if (cls + 4 == length && !cls2) {
@@ -16,64 +19,49 @@ static int check_bytes(const ut8 *buf, ut64 length) {
return false;
}
static int check(RBinFile *arch) {
const ut8 *bytes = arch ? r_buf_buffer (arch->buf) : NULL;
ut64 sz = arch ? r_buf_size (arch->buf): 0;
return check_bytes (bytes, sz);
static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) {
return __check_buffer (buf);
}
static Sdb* get_sdb (RBinObject *o) {
if (!o) return NULL;
//struct r_bin_[NAME]_obj_t *bin = (struct r_bin_r_bin_[NAME]_obj_t *) o->bin_obj;
//if (bin->kv) return kv;
return NULL;
}
static void * load_bytes(RBinFile *arch, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){
return (void*)(size_t)check_bytes (buf, sz);
}
static int load(RBinFile *arch) {
return check(arch);
}
static int destroy (RBinFile *arch) {
return true;
}
static ut64 baddr(RBinFile *arch) {
static ut64 baddr(RBinFile *bf) {
return 4;
}
static RBinAddr* binsym(RBinFile *arch, int type) {
static RBinAddr* binsym(RBinFile *bf, int type) {
return NULL; // TODO
}
static ut64 findEntry(RBuffer *buf, int n) {
ut8 b;
ut64 buf_size = r_buf_size (buf);
int i;
for (i=4;i<buf->length; i++) {
if (buf->buf[i] != 0) {
for (i = 4; i < buf_size; i++) {
if (r_buf_read_at (buf, i, &b, 1) != 1) {
break;
}
if (b != 0) {
if (n == 0) {
return i;
}
n--;
for (++i; i<buf->length; i++) {
if (!buf->buf[i])
for (++i; i < buf_size && b; i++) {
if (r_buf_read_at (buf, i, &b, 1) != 1) {
break;
}
}
}
}
return 0;
}
static RList* entries(RBinFile *arch) {
static RList* entries(RBinFile *bf) {
RList* ret = r_list_newf (free);
RBinAddr *ptr = NULL;
if (ret) {
if ((ptr = R_NEW0 (RBinAddr))) {
ut64 entry = findEntry (arch->buf, 2);
if (!entry) entry = findEntry (arch->buf, 1);
if (!entry) entry = findEntry (arch->buf, 0);
ut64 entry = findEntry (bf->buf, 2);
if (!entry) entry = findEntry (bf->buf, 1);
if (!entry) entry = findEntry (bf->buf, 0);
if (!entry) entry = 4;
ptr->paddr = entry;
ptr->vaddr = entry;
@@ -86,79 +74,74 @@ static RList* entries(RBinFile *arch) {
return ret;
}
static RList* sections(RBinFile *arch) {
static RList* sections(RBinFile *bf) {
RList *ret = NULL;
RBinSection *ptr = NULL;
ut64 textsize, datasize, symssize, spszsize, pcszsize;
ut64 entry0 = findEntry (arch->buf, 0);
ut64 entry1 = findEntry (arch->buf, 1);
ut64 entry2 = findEntry (arch->buf, 2);
ut64 entry0 = findEntry (bf->buf, 0);
ut64 entry1 = findEntry (bf->buf, 1);
ut64 entry2 = findEntry (bf->buf, 2);
if (!(ret = r_list_newf (free))) {
return NULL;
}
// add text segment
textsize = r_mem_get_num (arch->buf->buf + 4, 4);
ut8 str[4] = {0};
r_buf_read_at (bf->buf, 4, str, 4);
textsize = r_mem_get_num (str, 4);
if (!(ptr = R_NEW0 (RBinSection))) {
return ret;
}
if (!entry1) {
entry1 = arch->buf->length;
entry1 = r_buf_size (bf->buf);
}
strncpy (ptr->name, "init", R_BIN_SIZEOF_STRINGS);
ptr->size = entry1-entry0;
ptr->vsize = entry1-entry0;
ptr->name = strdup ("init");
ptr->size = entry1 - entry0;
ptr->vsize = entry1 - entry0;
ptr->paddr = entry0 + 4;
ptr->vaddr = entry0;
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE | R_BIN_SCN_MAP; // r-x
ptr->add = true;
ptr->perm = R_PERM_RX;
r_list_append (ret, ptr);
if (entry1) {
if (entry2) {
if (!(ptr = R_NEW0 (RBinSection)))
if (!(ptr = R_NEW0 (RBinSection))) {
return ret;
strncpy (ptr->name, "fini", R_BIN_SIZEOF_STRINGS);
ptr->size = entry2-entry1;
ptr->vsize = entry2-entry1;
}
ptr->name = strdup ("fini");
ptr->size = entry2 - entry1;
ptr->vsize = entry2 - entry1;
ptr->paddr = entry1 + 4;
ptr->vaddr = entry1;
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE | R_BIN_SCN_MAP; // r-x
ptr->perm = R_PERM_RX;
ptr->add = true;
r_list_append (ret, ptr);
} else {
entry2 = entry1;
}
}
if (entry2) {
if (!(ptr = R_NEW0 (RBinSection)))
if (!(ptr = R_NEW0 (RBinSection))) {
return ret;
strncpy (ptr->name, "text", R_BIN_SIZEOF_STRINGS);
ptr->size = arch->buf->length - entry2;
ptr->vsize = arch->buf->length - entry2;
}
ptr->name = strdup ("text");
ut64 filesize = r_buf_size (bf->buf);
ptr->size = filesize - entry2;
ptr->vsize = filesize - entry2;
ptr->paddr = entry2 + 4;
ptr->vaddr = entry2;
ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE | R_BIN_SCN_MAP; // r-x
ptr->perm = R_PERM_RX;
ptr->add = true;
r_list_append (ret, ptr);
}
return ret;
}
static RList* symbols(RBinFile *arch) {
// TODO: parse symbol table
return NULL;
}
static RList* imports(RBinFile *arch) {
return NULL;
}
static RList* libs(RBinFile *arch) {
return NULL;
}
static RBinInfo* info(RBinFile *arch) {
static RBinInfo* info(RBinFile *bf) {
RBinInfo *ret = R_NEW0 (RBinInfo);
if (ret) {
ret->file = strdup (arch->file);
ret->file = strdup (bf->file);
ret->bclass = strdup ("dna");
ret->rclass = strdup ("bcl");
ret->os = strdup ("Illumina DNA Sequences");
@@ -174,18 +157,17 @@ static RBinInfo* info(RBinFile *arch) {
return ret;
}
static ut64 size(RBinFile *arch) {
ut64 text, data, syms, spsz;
int big_endian;
if (!arch->o->info) {
arch->o->info = info (arch);
static ut64 size(RBinFile *bf) {
if (!bf->o->info) {
bf->o->info = info (bf);
}
big_endian = arch->o->info->big_endian;
ut8 str[32] = {0};
r_buf_read_at (bf->buf, 0, str, 32);
// TODO: reuse section list
text = r_mem_get_num (arch->buf->buf + 4, 4);
data = r_mem_get_num (arch->buf->buf + 8, 4);
syms = r_mem_get_num (arch->buf->buf + 16, 4);
spsz = r_mem_get_num (arch->buf->buf + 24, 4);
ut64 text = r_mem_get_num (str + 4, 4);
ut64 data = r_mem_get_num (str + 8, 4);
ut64 syms = r_mem_get_num (str + 16, 4);
ut64 spsz = r_mem_get_num (str + 24, 4);
return text + data + syms + spsz + (6 * 4);
}
@@ -193,25 +175,18 @@ RBinPlugin r_bin_plugin_bcl = {
.name = "bcl",
.desc = "Base Call DNA Illumina",
.license = "BSD",
.get_sdb = &get_sdb,
.load = &load,
.load_bytes = &load_bytes,
.load_buffer = &load_buffer,
.check_buffer = &__check_buffer,
.size = &size,
.destroy = &destroy,
.check = &check,
.check_bytes = &check_bytes,
.baddr = &baddr,
.binsym = &binsym,
.entries = &entries,
.sections = &sections,
.symbols = &symbols,
.imports = &imports,
.info = &info,
.libs = &libs,
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
RLibStruct radare_plugin = {
.type = R_LIB_TYPE_BIN,
.data = &r_bin_plugin_bcl,
.version = R2_VERSION
Vendored
+6 -6
View File
@@ -1,5 +1,5 @@
#!/bin/sh
# This script was automatically generated by ACR v1.7.2
# This script was automatically generated by ACR v1.8.1
# @author: pancake <nopcode.org>
# @url: http://www.nopcode.org
# @repo: git clone https://github.com/radare/acr
@@ -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='4.0.0' ; CONTACT_MAIL="[email protected]" ; CONTACT_NAME="pancake" ; CONTACT="pancake <[email protected]>" ;
PKGNAME='radare2-extras' ; VERSION='4.4.0' ; VERSION_MAJOR=4; VERSION_MINOR=4; VERSION_PATCH=0; VERSION_NUMBER=40400; CONTACT_MAIL="[email protected]" ; CONTACT_NAME="pancake" ; CONTACT="pancake <[email protected]>" ;
}
show_usage() {
cat <<EOF2
'configure' configures radare2-extras-4.0.0 to adapt to many kinds of systems.
'configure' configures radare2-extras-4.4.0 to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
@@ -180,7 +180,7 @@ take_environ() {
}
show_version() {
echo "radare2-extras-4.0.0 configuration script done with acr v1.7.2.
echo "radare2-extras-4.4.0 configuration script done with acr v1.8.1.
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: 4.0.0"
echo "VERSION: 4.4.0"
echo "LANGS: c"
echo "OPTIONAL: libewf libyara"
echo "PKG-CONFIG: r_core libewf unicorn yara"
@@ -273,7 +273,7 @@ parse_options "$1"
shift
done
ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU PKGNAME VPATH VERSION CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C R2_CFLAGS R2_LDFLAGS HAVE_PKGCFG_R_CORE USEROSTYPE HAVE_LIB_EWF EWF_CFLAGS EWF_LDFLAGS HAVE_PKGCFG_LIBEWF WANT_EWF UC_CFLAGS UC_LDFLAGS HAVE_PKGCFG_UNICORN HAVE_LIB_YARA YARA_CFLAGS YARA_LDFLAGS HAVE_PKGCFG_YARA"
ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU VERSION VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION_NUMBER PKGNAME VPATH CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C R2_CFLAGS R2_LDFLAGS HAVE_PKGCFG_R_CORE USEROSTYPE HAVE_LIB_EWF EWF_CFLAGS EWF_LDFLAGS HAVE_PKGCFG_LIBEWF WANT_EWF UC_CFLAGS UC_LDFLAGS HAVE_PKGCFG_UNICORN HAVE_LIB_YARA YARA_CFLAGS YARA_LDFLAGS HAVE_PKGCFG_YARA"
create_environ
+1 -1
View File
@@ -1,5 +1,5 @@
PKGNAME radare2-extras
VERSION 4.0.0
VERSION 4.4.0
CONTACT pancake ; [email protected]
REPORT PREFIX ;
+4 -4
View File
@@ -1,5 +1,5 @@
#!/bin/sh
# This script was automatically generated by ACR v1.7.2
# This script was automatically generated by ACR v1.8.1
# @author: pancake <nopcode.org>
# @url: http://www.nopcode.org
# @repo: git clone https://github.com/radare/acr
@@ -103,7 +103,7 @@ done
: ${INSTALL_PROGRAM_STRIP:=${INSTALL} -m 755 -s}
: ${INSTALL_MAN:=${INSTALL} -m 444}
: ${INSTALL_LIB:=${INSTALL} -m 755 -c}
PKGNAME='radare2-keystone' ; VERSION='0.1' ; CONTACT_MAIL="[email protected]" ; CONTACT_NAME="pancake" ; CONTACT="pancake <[email protected]>" ;
PKGNAME='radare2-keystone' ; VERSION='0.1' ; VERSION_MAJOR=0; VERSION_MINOR=1; VERSION_PATCH=0; VERSION_NUMBER=00100; CONTACT_MAIL="[email protected]" ; CONTACT_NAME="pancake" ; CONTACT="pancake <[email protected]>" ;
}
show_usage() {
@@ -177,7 +177,7 @@ take_environ() {
}
show_version() {
echo "radare2-keystone-0.1 configuration script done with acr v1.7.2.
echo "radare2-keystone-0.1 configuration script done with acr v1.8.1.
The 'Free Software Foundation' message is only for autodetection.
Originally written by pancake <nopcode.org>."
exit 0
@@ -267,7 +267,7 @@ parse_options "$1"
shift
done
ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU PKGNAME VPATH VERSION CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C CXX CXXFLAGS HAVE_LANG_CXX HAVE_LIB_KEYSTONE R2_CFLAGS R2_LDFLAGS HAVE_PKGCFG_R_ASM"
ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU VERSION VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION_NUMBER PKGNAME VPATH CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C CXX CXXFLAGS HAVE_LANG_CXX HAVE_LIB_KEYSTONE R2_CFLAGS R2_LDFLAGS HAVE_PKGCFG_R_ASM"
create_environ
+4
View File
@@ -13,9 +13,13 @@ atombios:
evm:
cd p ; $(MAKE) anal_evm.$(LIBEXT)
pyc:
cd p ; $(MAKE) anal_pyc.$(LIBEXT)
clean:
rm -f p/anal_x86_bea.$(LIBEXT)
rm -f p/anal_m68k_net.$(LIBEXT)
rm -f p/anal_atombios.{$(LIBEXT),o}
rm -f p/anal_pyc.$(LIBEXT)
include ../../options.mk
+1
View File
@@ -7,5 +7,6 @@ ARCHS+=x86_udis.mk
ARCHS+=m68k_net.mk
ARCHS+=evm.mk
ARCHS+=atombios.mk
ARCHS+=pyc.mk
include ../../plugs.mk
+154
View File
@@ -0,0 +1,154 @@
/* radare - LGPL3 - Copyright 2016-2020 - FXTi */
#include <r_types.h>
#include <r_lib.h>
#include <r_util.h>
#include <r_asm.h>
#include "../../asm/arch/pyc/opcode.h"
#include "../../asm/arch/pyc/pyc_dis.h"
static int archinfo (RAnal *anal, int query) {
if (!strcmp (anal->cpu, "x86")) {
return -1;
} else {
switch (query) {
case R_ANAL_ARCHINFO_MIN_OP_SIZE:
return (anal->bits == 16) ? 1 : 2;
case R_ANAL_ARCHINFO_MAX_OP_SIZE:
return (anal->bits == 16) ? 3 : 2;
default:
return -1;
}
}
}
static char *get_reg_profile (RAnal *anal) {
return strdup (
"=PC pc\n"
"=BP bp\n"
"=SP sp\n"
"gpr sp .32 0 0\n" // stack pointer
"gpr pc .32 4 0\n" // program counter
"gpr bp .32 8 0\n" // base pointer // unused
);
}
static RList *get_pyc_code_obj (RAnal *anal) {
RBin *b = anal->binb.bin;
RBinPlugin *plugin = b->cur && b->cur->o ? b->cur->o->plugin : NULL;
ut8 is_pyc = (plugin && strcmp (plugin->name, "pyc") == 0) ? 1 : 0;
return is_pyc ? b->cur->o->bin_obj : NULL;
}
static int pyc_op (RAnal *a, RAnalOp *op, ut64 addr, const ut8 *data, int len, RAnalOpMask mask) {
RList *cobjs = r_list_get_n (get_pyc_code_obj (a), 0);
RListIter *iter = NULL;
pyc_code_object *func = NULL, *t = NULL;
r_list_foreach (cobjs, iter, t) {
if (t->start_offset <= addr && addr < t->end_offset) { // addr in [start_offset, end_offset)
func = t;
break;
}
}
if (func == NULL) {
return -1;
}
ut64 func_base = func->start_offset;
ut32 extended_arg = 0, oparg;
ut8 op_code = data[0];
pyc_opcodes *ops;
op->jump = UT64_MAX;
op->fail = UT64_MAX;
op->ptr = op->val = UT64_MAX;
op->addr = addr;
op->sign = true;
op->type = R_ANAL_OP_TYPE_ILL;
op->id = op_code;
if (!(ops = get_opcode_by_version (a->cpu))) {
return -1;
}
bool is_python36 = a->bits == 8;
pyc_opcode_object *op_obj = &ops->opcodes[op_code];
if (!op_obj->op_name) {
op->type = R_ANAL_OP_TYPE_ILL;
op->size = 1;
goto anal_end;
}
if (is_python36) {
op->size = 2;
} else {
op->size = (op_code >= ops->have_argument) ? 3 : 1;
}
if (op_code >= ops->have_argument) {
if (!is_python36) {
oparg = data[1] + data[2] * 256 + extended_arg;
} else {
oparg = data[1] + extended_arg;
}
extended_arg = 0;
if (op_code == ops->extended_arg) {
if (!is_python36) {
extended_arg = oparg * 65536;
} else {
extended_arg = oparg << 8;
}
}
}
if (op_obj->type & HASJABS) {
op->type = R_ANAL_OP_TYPE_JMP;
op->jump = func_base + oparg;
if (op_obj->type & HASCONDITION) {
op->type = R_ANAL_OP_TYPE_CJMP;
op->fail = addr + ((is_python36) ? 2 : 3);
}
goto anal_end;
}
if (op_obj->type & HASJREL) {
op->type = R_ANAL_OP_TYPE_JMP;
op->jump = addr + oparg + ((is_python36) ? 2 : 3);
if (op_obj->type & HASCONDITION) {
op->type = R_ANAL_OP_TYPE_CJMP;
op->fail = addr + ((is_python36) ? 2 : 3);
}
goto anal_end;
}
if (op_obj->type & HASCOMPARE) {
op->type = R_ANAL_OP_TYPE_CMP;
goto anal_end;
}
anal_pyc_op (op, op_obj, oparg);
anal_end:
free_opcode (ops);
return op->size;
}
RAnalPlugin r_anal_plugin_pyc = {
.name = "pyc",
.desc = "Python bytecode analysis plugin",
.license = "LGPL3",
.arch = "pyc",
.bits = 16 | 8, // Partially agree with this
.archinfo = archinfo,
.get_reg_profile = get_reg_profile,
.op = &pyc_op,
.esil = false,
};
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ANAL,
.data = &r_anal_plugin_pyc,
.version = R2_VERSION
};
#endif
+40
View File
@@ -0,0 +1,40 @@
OBJ_PYC=anal_pyc.o
OBJ_PYC+=../../asm/arch/pyc/opcode_10.o
OBJ_PYC+=../../asm/arch/pyc/opcode_11.o
OBJ_PYC+=../../asm/arch/pyc/opcode_12.o
OBJ_PYC+=../../asm/arch/pyc/opcode_13.o
OBJ_PYC+=../../asm/arch/pyc/opcode_14.o
OBJ_PYC+=../../asm/arch/pyc/opcode_15.o
OBJ_PYC+=../../asm/arch/pyc/opcode_16.o
OBJ_PYC+=../../asm/arch/pyc/opcode_20.o
OBJ_PYC+=../../asm/arch/pyc/opcode_21.o
OBJ_PYC+=../../asm/arch/pyc/opcode_22.o
OBJ_PYC+=../../asm/arch/pyc/opcode_23.o
OBJ_PYC+=../../asm/arch/pyc/opcode_24.o
OBJ_PYC+=../../asm/arch/pyc/opcode_25.o
OBJ_PYC+=../../asm/arch/pyc/opcode_26.o
OBJ_PYC+=../../asm/arch/pyc/opcode_27.o
OBJ_PYC+=../../asm/arch/pyc/opcode_2x.o
OBJ_PYC+=../../asm/arch/pyc/opcode_30.o
OBJ_PYC+=../../asm/arch/pyc/opcode_31.o
OBJ_PYC+=../../asm/arch/pyc/opcode_32.o
OBJ_PYC+=../../asm/arch/pyc/opcode_33.o
OBJ_PYC+=../../asm/arch/pyc/opcode_34.o
OBJ_PYC+=../../asm/arch/pyc/opcode_35.o
OBJ_PYC+=../../asm/arch/pyc/opcode_36.o
OBJ_PYC+=../../asm/arch/pyc/opcode_37.o
OBJ_PYC+=../../asm/arch/pyc/opcode_38.o
OBJ_PYC+=../../asm/arch/pyc/opcode_39.o
OBJ_PYC+=../../asm/arch/pyc/opcode_3x.o
OBJ_PYC+=../../asm/arch/pyc/opcode_anal.o
OBJ_PYC+=../../asm/arch/pyc/opcode_arg_fmt.o
OBJ_PYC+=../../asm/arch/pyc/opcode.o
STATIC_OBJ+=${OBJ_PYC}
TARGET_PYC=anal_pyc.$(LIBEXT)
ALL_TARGETS+=${TARGET_PYC}
CFLAGS+=-I../../asm/arch/pyc
${TARGET_PYC}: ${OBJ_PYC}
${CC} ${CFLAGS} $(LDFLAGS) -o ${TARGET_PYC} ${OBJ_PYC} -lr_util
+1
View File
@@ -53,6 +53,7 @@ clean:
rm -f p/asm_x86_bea.$(LIBEXT)
rm -f p/asm_x86_tab.$(LIBEXT)
rm -f p/asm_x86_olly.$(LIBEXT)
rm -f p/asm_pyc.$(LIBEXT)
rm -f p/asm_m68k.$(LIBEXT)
rm -f p/asm_x86_zyan.$(LIBEXT)
rm -f p/asm_atombios.{$(LIBEXT),o}
+2
View File
@@ -37,6 +37,7 @@ static void add_insn_to_hash_chain (CGEN_INSN_LIST *,
CGEN_INSN_LIST **,
unsigned int);
#if 0
bfd_uint64_t
bfd_get_bits (const void *p, int bits, bfd_boolean big_p)
{
@@ -59,6 +60,7 @@ bfd_get_bits (const void *p, int bits, bfd_boolean big_p)
return data;
}
#endif
void
bfd_put_bits (bfd_uint64_t data, void *p, int bits, bfd_boolean big_p)
+2
View File
@@ -1054,10 +1054,12 @@ nios_cgen_assemble_insn (CGEN_CPU_DESC cd,
str = start;
#if 0
/* Skip this insn if str doesn't look right lexically. */
if (CGEN_INSN_RX (insn) != NULL &&
regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
continue;
#endif
/* Allow parse/insert handlers to obtain length of insn. */
CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
+4 -2
View File
@@ -1612,9 +1612,10 @@ nios_cgen_cpu_open_1 (const char *mach_name, enum cgen_endian endian)
void
nios_cgen_cpu_close (CGEN_CPU_DESC cd)
{
unsigned int i;
const CGEN_INSN *insns;
#if 0
const CGEN_INSN *insns;
unsigned int i;
if (cd->macro_insn_table.init_entries)
{
insns = cd->macro_insn_table.init_entries;
@@ -1630,6 +1631,7 @@ nios_cgen_cpu_close (CGEN_CPU_DESC cd)
if (CGEN_INSN_RX (insns))
regfree (CGEN_INSN_RX (insns));
}
#endif
if (cd->macro_insn_table.init_entries)
free ((CGEN_INSN *) cd->macro_insn_table.init_entries);
+284
View File
@@ -0,0 +1,284 @@
#include "opcode.h"
static version_opcode version_op[] = {
{ "1.0.1", opcode_10 },
{ "1.1", opcode_11 },
{ "1.2", opcode_12 },
{ "1.3b1", opcode_13 },
{ "1.4", opcode_14 },
{ "1.4b1", opcode_14 },
{ "1.5a1", opcode_15 },
{ "1.6a2", opcode_16 },
{ "2.0b1", opcode_20 },
{ "2.1a1", opcode_21 },
{ "2.1a2", opcode_21 },
{ "2.2a0", opcode_22 },
{ "2.2a1", opcode_22 },
{ "2.3a0", opcode_23 },
{ "2.4a0", opcode_24 },
{ "2.4a2", opcode_24 },
{ "2.4a3", opcode_24 },
{ "2.5a0", opcode_25 },
{ "2.5b2", opcode_25 },
{ "2.5c3", opcode_25 },
{ "2.6a0", opcode_26 },
{ "2.6a1+", opcode_26 },
{ "2.7a0", opcode_27 },
{ "2.7a2+", opcode_27 },
{ "3.0a1", opcode_30 },
{ "3.0a1+", opcode_30 },
{ "3.0a2", opcode_30 },
{ "3.0a2+", opcode_30 },
{ "3.0a3+", opcode_30 },
{ "3.0a5+", opcode_30 },
{ "3.0x", opcode_30 },
{ "3.1a0", opcode_31 },
{ "3.2a0", opcode_32 },
{ "3.2a1+", opcode_32 },
{ "3.2a2+", opcode_33 },
{ "3.3.0a0", opcode_33 },
{ "3.3.0a1+", opcode_33 },
{ "3.3.0a3+", opcode_33 },
{ "3.3a0", opcode_33 },
{ "3.4.0a0", opcode_34 },
{ "3.4.0a3+", opcode_34 },
{ "3.4.0rc1+", opcode_34 },
{ "3.5.0a0", opcode_35 },
{ "3.5.0a4+", opcode_35 },
{ "3.5.0b1+", opcode_35 },
{ "3.5.0b2+", opcode_35 },
{ "3.6.0a0", opcode_36 },
{ "v3.6.0", opcode_36 },
{ "v3.6.0a2", opcode_36 },
{ "v3.6.0a3", opcode_36 },
{ "v3.6.0a4", opcode_36 },
{ "v3.6.0b1", opcode_36 },
{ "v3.6.0b2", opcode_36 },
{ "v3.6.0b3", opcode_36 },
{ "v3.6.0b4", opcode_36 },
{ "v3.6.0rc1", opcode_36 },
{ "v3.6.0rc2", opcode_36 },
{ "v3.6.1", opcode_36 },
{ "v3.6.10", opcode_36 },
{ "v3.6.10rc", opcode_36 },
{ "v3.6.1rc1", opcode_36 },
{ "v3.6.2", opcode_36 },
{ "v3.6.2rc1", opcode_36 },
{ "v3.6.2rc2", opcode_36 },
{ "v3.6.3", opcode_36 },
{ "v3.6.3rc1", opcode_36 },
{ "v3.6.4", opcode_36 },
{ "v3.6.4rc1", opcode_36 },
{ "v3.6.5", opcode_36 },
{ "v3.6.5rc1", opcode_36 },
{ "v3.6.6", opcode_36 },
{ "v3.6.6rc1", opcode_36 },
{ "v3.6.7", opcode_36 },
{ "v3.6.7rc1", opcode_36 },
{ "v3.6.7rc2", opcode_36 },
{ "v3.6.8", opcode_36 },
{ "v3.6.8rc1", opcode_36 },
{ "v3.6.9", opcode_36 },
{ "v3.6.9rc1", opcode_36 },
{ "v3.7.0", opcode_37 },
{ "v3.7.0a1", opcode_37 },
{ "v3.7.0a2", opcode_37 },
{ "v3.7.0a3", opcode_37 },
{ "v3.7.0a4", opcode_37 },
{ "v3.7.0b1", opcode_37 },
{ "v3.7.0b2", opcode_37 },
{ "v3.7.0b3", opcode_37 },
{ "v3.7.0b4", opcode_37 },
{ "v3.7.0b5", opcode_37 },
{ "v3.7.0rc1", opcode_37 },
{ "v3.7.1", opcode_37 },
{ "v3.7.1rc1", opcode_37 },
{ "v3.7.1rc2", opcode_37 },
{ "v3.7.2", opcode_37 },
{ "v3.7.2rc1", opcode_37 },
{ "v3.7.3", opcode_37 },
{ "v3.7.3rc1", opcode_37 },
{ "v3.7.4", opcode_37 },
{ "v3.7.4rc1", opcode_37 },
{ "v3.7.4rc2", opcode_37 },
{ "v3.7.5", opcode_37 },
{ "v3.7.5rc1", opcode_37 },
{ "v3.7.6", opcode_37 },
{ "v3.7.6rc1", opcode_37 },
{ "v3.8.0", opcode_38 },
{ "v3.8.0a1", opcode_38 },
{ "v3.8.0a2", opcode_38 },
{ "v3.8.0a3", opcode_38 },
{ "v3.8.0a4", opcode_38 },
{ "v3.8.0b1", opcode_38 },
{ "v3.8.0b2", opcode_38 },
{ "v3.8.0b3", opcode_38 },
{ "v3.8.0b4", opcode_38 },
{ "v3.8.0rc1", opcode_38 },
{ "v3.8.1", opcode_38 },
{ "v3.8.1rc1", opcode_38 },
{ "v3.9.0a1", opcode_39 },
{ "v3.9.0a2", opcode_39 },
{ "v3.9.0a3", opcode_39 },
};
bool pyc_opcodes_equal (pyc_opcodes *op, const char *version) {
for (ut32 i = 0; i < sizeof(version_op) / sizeof(version_opcode); i++) {
if (!strcmp (version_op[i].version, version)) {
if (version_op[i].opcode_func == op->version_sig)
return true;
}
}
return false;
}
pyc_opcodes *get_opcode_by_version(char *version) {
for (ut32 i = 0; i < sizeof(version_op) / sizeof(version_opcode); i++) {
if (!strcmp (version_op[i].version, version)) {
return version_op[i].opcode_func ();
}
}
return NULL; // No match version
}
pyc_opcodes *new_pyc_opcodes() {
pyc_opcodes *ret = R_NEW0 (pyc_opcodes);
if (!ret) {
return NULL;
}
ret->have_argument = 90;
ret->opcodes = malloc (sizeof(pyc_opcode_object) * 256);
if (!ret->opcodes) {
R_FREE (ret);
return NULL;
}
ut16 i = 0;
for (i = 0; i < 256; i++) {
ret->opcodes[i].op_name = r_str_newf ("<%u>", i);
if (!ret->opcodes[i].op_name) {
for (ut8 j = 0; j < i; j++) {
free (ret->opcodes[j].op_name);
}
free (ret->opcodes);
R_FREE(ret);
return NULL;
}
ret->opcodes[i].type = 0;
ret->opcodes[i].op_code = i;
ret->opcodes[i].op_push = 0;
ret->opcodes[i].op_pop = 0;
}
ret->opcode_arg_fmt = r_list_new ();
return ret;
}
void free_opcode(pyc_opcodes *opcodes) {
for(ut16 i = 0; i < 256; i++)
free (opcodes->opcodes[i].op_name);
free (opcodes->opcodes);
r_list_free (opcodes->opcode_arg_fmt);
R_FREE (opcodes);
}
void add_arg_fmt(pyc_opcodes *ret, const char *op_name, const char *(*formatter) (ut32 oparg)) {
pyc_arg_fmt *fmt = R_NEW0 (pyc_arg_fmt);
fmt->op_name = op_name;
fmt->formatter = formatter;
r_list_append (ret->opcode_arg_fmt, fmt);
}
void (def_op) (struct op_parameter par) {
free (par.op_obj[par.op_code].op_name);
par.op_obj[par.op_code].op_name = strdup (par.op_name);
par.op_obj[par.op_code].op_code = par.op_code;
par.op_obj[par.op_code].op_pop = par.pop;
par.op_obj[par.op_code].op_push = par.push;
if (!par.fallthrough) {
par.op_obj[par.op_code].type |= NOFOLLOW;
}
}
void (name_op) (struct op_parameter par) {
def_op(.op_obj = par.op_obj, .op_name = par.op_name, .op_code = par.op_code, .pop = par.pop, .push = par.push);
par.op_obj[par.op_code].type |= HASNAME;
}
void (local_op) (struct op_parameter par) {
def_op(.op_obj = par.op_obj, .op_name = par.op_name, .op_code = par.op_code, .pop = par.pop, .push = par.push);
par.op_obj[par.op_code].type |= HASLOCAL;
}
void (free_op) (struct op_parameter par) {
def_op(.op_obj = par.op_obj, .op_name = par.op_name, .op_code = par.op_code, .pop = par.pop, .push = par.push);
par.op_obj[par.op_code].type |= HASFREE;
}
void (store_op) (struct op_parameter par) {
switch (par.func) {
case NAME_OP:
name_op (.op_obj = par.op_obj, .op_name = par.op_name, .op_code = par.op_code, .pop = par.pop, .push = par.push);
break;
case LOCAL_OP:
local_op (.op_obj = par.op_obj, .op_name = par.op_name, .op_code = par.op_code, .pop = par.pop, .push = par.push);
break;
case FREE_OP:
free_op (.op_obj = par.op_obj, .op_name = par.op_name, .op_code = par.op_code, .pop = par.pop, .push = par.push);
break;
case DEF_OP:
def_op (.op_obj = par.op_obj, .op_name = par.op_name, .op_code = par.op_code, .pop = par.pop, .push = par.push);
break;
default:
eprintf ("Error in store_op in opcode.c, call function %u.\n", par.func);
return ;
}
par.op_obj[par.op_code].type |= HASSTORE;
}
void (varargs_op) (struct op_parameter par) {
def_op(.op_obj = par.op_obj, .op_name = par.op_name, .op_code = par.op_code, .pop = par.pop, .push = par.push);
par.op_obj[par.op_code].type |= HASVARGS;
}
void (const_op) (struct op_parameter par) {
def_op(.op_obj = par.op_obj, .op_name = par.op_name, .op_code = par.op_code, .pop = par.pop, .push = par.push);
par.op_obj[par.op_code].type |= HASCONST;
}
void (compare_op) (struct op_parameter par) {
def_op(.op_obj = par.op_obj, .op_name = par.op_name, .op_code = par.op_code, .pop = par.pop, .push = par.push);
par.op_obj[par.op_code].type |= HASCOMPARE;
}
void (jabs_op) (struct op_parameter par) {
def_op(.op_obj = par.op_obj, .op_name = par.op_name, .op_code = par.op_code, .pop = par.pop, .push = par.push, .fallthrough = par.fallthrough);
par.op_obj[par.op_code].type |= HASJABS;
if (par.conditional) {
par.op_obj[par.op_code].type |= HASCONDITION;
}
}
void (jrel_op) (struct op_parameter par) {
def_op(.op_obj = par.op_obj, .op_name = par.op_name, .op_code = par.op_code, .pop = par.pop, .push = par.push, .fallthrough = par.fallthrough);
par.op_obj[par.op_code].type |= HASJREL;
if (par.conditional) {
par.op_obj[par.op_code].type |= HASCONDITION;
}
}
void (nargs_op) (struct op_parameter par) {
def_op(.op_obj = par.op_obj, .op_name = par.op_name, .op_code = par.op_code, .pop = par.pop, .push = par.push);
par.op_obj[par.op_code].type |= HASNARGS;
}
void (rm_op) (struct op_parameter par) {
pyc_opcode_object *op_obj = &par.op_obj[par.op_code];
if (op_obj->op_code == par.op_code && !strcmp(op_obj->op_name, par.op_name)) {
free (op_obj->op_name);
op_obj->op_name = malloc (sizeof(char) * 6);
snprintf (op_obj->op_name, 6, "<%u>", par.op_code);
op_obj->type = op_obj->op_pop = op_obj->op_push = 0;
} else {
eprintf("Error in rm_op() while constructing opcodes for .pyc file: \n .op_code = %u, .op_name = %s", par.op_code, par.op_name);
}
}
+152 -154
View File
@@ -1,154 +1,152 @@
#define STOP_CODE 0
#define POP_TOP 1
#define ROT_TWO 2
#define ROT_THREE 3
#define DUP_TOP 4
#define ROT_FOUR 5
#define NOP 9
#define UNARY_POSITIVE 10
#define UNARY_NEGATIVE 11
#define UNARY_NOT 12
#define UNARY_CONVERT 13
#define UNARY_INVERT 15
#define BINARY_POWER 19
#define BINARY_MULTIPLY 20
#define BINARY_DIVIDE 21
#define BINARY_MODULO 22
#define BINARY_ADD 23
#define BINARY_SUBTRACT 24
#define BINARY_SUBSCR 25
#define BINARY_FLOOR_DIVIDE 26
#define BINARY_TRUE_DIVIDE 27
#define INPLACE_FLOOR_DIVIDE 28
#define INPLACE_TRUE_DIVIDE 29
#define SLICE 30
/* Also uses 31-33 */
#define SLICE_1 31
#define SLICE_2 32
#define SLICE_3 33
#define STORE_SLICE 40
/* Also uses 41-43 */
#define STORE_SLICE_1 41
#define STORE_SLICE_2 42
#define STORE_SLICE_3 43
#define DELETE_SLICE 50
/* Also uses 51-53 */
#define DELETE_SLICE_1 51
#define DELETE_SLICE_2 52
#define DELETE_SLICE_3 53
#define STORE_MAP 54
#define INPLACE_ADD 55
#define INPLACE_SUBTRACT 56
#define INPLACE_MULTIPLY 57
#define INPLACE_DIVIDE 58
#define INPLACE_MODULO 59
#define STORE_SUBSCR 60
#define DELETE_SUBSCR 61
#define BINARY_LSHIFT 62
#define BINARY_RSHIFT 63
#define BINARY_AND 64
#define BINARY_XOR 65
#define BINARY_OR 66
#define INPLACE_POWER 67
#define GET_ITER 68
#define PRINT_EXPR 70
#define PRINT_ITEM 71
#define PRINT_NEWLINE 72
#define PRINT_ITEM_TO 73
#define PRINT_NEWLINE_TO 74
#define INPLACE_LSHIFT 75
#define INPLACE_RSHIFT 76
#define INPLACE_AND 77
#define INPLACE_XOR 78
#define INPLACE_OR 79
#define BREAK_LOOP 80
#define WITH_CLEANUP 81
#define LOAD_LOCALS 82
#define RETURN_VALUE 83
#define IMPORT_STAR 84
#define EXEC_STMT 85
#define YIELD_VALUE 86
#define POP_BLOCK 87
#define END_FINALLY 88
#define BUILD_CLASS 89
#define HAVE_ARGUMENT 90 /* Opcodes from here have an argument: */
#define STORE_NAME 90 /* Index in name list */
#define DELETE_NAME 91 /* "" */
#define UNPACK_SEQUENCE 92 /* Number of sequence items */
#define FOR_ITER 93
#define LIST_APPEND 94
#define STORE_ATTR 95 /* Index in name list */
#define DELETE_ATTR 96 /* "" */
#define STORE_GLOBAL 97 /* "" */
#define DELETE_GLOBAL 98 /* "" */
#define DUP_TOPX 99 /* number of items to duplicate */
#define LOAD_CONST 100 /* Index in const list */
#define LOAD_NAME 101 /* Index in name list */
#define BUILD_TUPLE 102 /* Number of tuple items */
#define BUILD_LIST 103 /* Number of list items */
#define BUILD_SET 104 /* Number of set items */
#define BUILD_MAP 105 /* Always zero for now */
#define LOAD_ATTR 106 /* Index in name list */
#define COMPARE_OP 107 /* Comparison operator */
#define IMPORT_NAME 108 /* Index in name list */
#define IMPORT_FROM 109 /* Index in name list */
#define JUMP_FORWARD 110 /* Number of bytes to skip */
#define JUMP_IF_FALSE_OR_POP 111 /* Target byte offset from beginning
of code */
#define JUMP_IF_TRUE_OR_POP 112 /* "" */
#define JUMP_ABSOLUTE 113 /* "" */
#define POP_JUMP_IF_FALSE 114 /* "" */
#define POP_JUMP_IF_TRUE 115 /* "" */
#define LOAD_GLOBAL 116 /* Index in name list */
#define CONTINUE_LOOP 119 /* Start of loop (absolute) */
#define SETUP_LOOP 120 /* Target address (relative) */
#define SETUP_EXCEPT 121 /* "" */
#define SETUP_FINALLY 122 /* "" */
#define LOAD_FAST 124 /* Local variable number */
#define STORE_FAST 125 /* Local variable number */
#define DELETE_FAST 126 /* Local variable number */
#define RAISE_VARARGS 130 /* Number of raise arguments (1, 2 or 3) */
/* CALL_FUNCTION_XXX opcodes defined below depend on this definition */
#define CALL_FUNCTION 131 /* #args + (#kwargs<<8) */
#define MAKE_FUNCTION 132 /* #defaults */
#define BUILD_SLICE 133 /* Number of items */
#define MAKE_CLOSURE 134 /* #free vars */
#define LOAD_CLOSURE 135 /* Load free variable from closure */
#define LOAD_DEREF 136 /* Load and dereference from closure cell */
#define STORE_DEREF 137 /* Store into cell */
/* The next 3 opcodes must be contiguous and satisfy
(CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1 */
#define CALL_FUNCTION_VAR 140 /* #args + (#kwargs<<8) */
#define CALL_FUNCTION_KW 141 /* #args + (#kwargs<<8) */
#define CALL_FUNCTION_VAR_KW 142 /* #args + (#kwargs<<8) */
#define SETUP_WITH 143
/* Support for opargs more than 16 bits long */
#define EXTENDED_ARG 145
#define SET_ADD 146
#define MAP_ADD 147
char *op_name[0xff + 1];
/* radare - LGPL3 - Copyright 2016-2020 - c0riolis, x0urc3 */
#ifndef OPCODE_H
#define OPCODE_H
#include <r_types.h>
#include <r_list.h>
#include <r_util.h>
#include <r_anal.h>
#define OBJECT_SIZE_ON_STACK 1
typedef enum {
HASCOMPARE = 0x1,
HASCONDITION = 0x2, // conditional operator; has jump offset
HASCONST = 0x4,
HASFREE = 0x8,
HASJABS = 0x10, // Will appear with HASCONDITION sometimes
HASJREL = 0x20, // Will appear with HASCONDITION sometimes
HASLOCAL = 0x40,
HASNAME = 0x80,
HASNARGS = 0x100, // For function-like calls
HASSTORE = 0x200, // Some sort of store operation
HASVARGS = 0x400, // Similar but for operators BUILD_xxx
NOFOLLOW = 0x800, // Instruction doesn't fall to the next opcode
} pyc_opcode_type;
typedef enum {
NAME_OP = 0x1,
LOCAL_OP = 0x2,
FREE_OP = 0x4,
DEF_OP = 0x8,
} pyc_store_op_func;
typedef struct {
char *op_name;
ut16 type;
ut8 op_code;
st8 op_push;
st8 op_pop;
} pyc_opcode_object;
typedef struct {
ut8 extended_arg;
ut8 have_argument;
ut8 bits;
void *(*version_sig) ();
RList *opcode_arg_fmt;
pyc_opcode_object *opcodes;
} pyc_opcodes;
typedef struct {
char *op_name;
const char *(*formatter) (ut32 oparg);
} pyc_arg_fmt;
typedef struct {
char *version;
pyc_opcodes *(*opcode_func) ();
} version_opcode;
typedef struct {
char *op_name;
void (*func) (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg);
} op_anal_func;
void anal_pyc_op(RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg);
pyc_opcodes *opcode_2x();
pyc_opcodes *opcode_3x();
pyc_opcodes *opcode_10();
pyc_opcodes *opcode_11();
pyc_opcodes *opcode_12();
pyc_opcodes *opcode_13();
pyc_opcodes *opcode_14();
pyc_opcodes *opcode_15();
pyc_opcodes *opcode_16();
pyc_opcodes *opcode_20();
pyc_opcodes *opcode_21();
pyc_opcodes *opcode_22();
pyc_opcodes *opcode_23();
pyc_opcodes *opcode_24();
pyc_opcodes *opcode_25();
pyc_opcodes *opcode_26();
pyc_opcodes *opcode_27();
pyc_opcodes *opcode_30();
pyc_opcodes *opcode_31();
pyc_opcodes *opcode_32();
pyc_opcodes *opcode_33();
pyc_opcodes *opcode_34();
pyc_opcodes *opcode_35();
pyc_opcodes *opcode_36();
pyc_opcodes *opcode_37();
pyc_opcodes *opcode_38();
pyc_opcodes *opcode_39();
pyc_opcodes *get_opcode_by_version(char *version);
pyc_opcodes *new_pyc_opcodes();
void free_opcode(pyc_opcodes *opcodes);
bool pyc_opcodes_equal (pyc_opcodes *op, const char *version);
void add_arg_fmt(pyc_opcodes *ret, const char *op_name, const char *(*formatter) (ut32 oparg));
const char *format_MAKE_FUNCTION_arg_3x (ut32 oparg);
const char *format_extended_arg (ut32 oparg);
const char *format_CALL_FUNCTION_pos_name_encoded (ut32 oparg);
const char *format_CALL_FUNCTION_KW_36 (ut32 oparg);
const char *format_CALL_FUNCTION_EX_36 (ut32 oparg);
const char *format_MAKE_FUNCTION_arg_36 (ut32 oparg);
const char *format_value_flags_36 (ut32 oparg);
const char *format_extended_arg_36 (ut32 oparg);
struct op_parameter { pyc_opcode_object* op_obj; const char *op_name; ut8 op_code; st8 pop; st8 push; pyc_store_op_func func; bool conditional; bool fallthrough; };
#define def_op(...) def_op ((struct op_parameter) {.pop = -2, .push = -2, .fallthrough = true, __VA_ARGS__})
void (def_op) (struct op_parameter par);
#define name_op(...) name_op ((struct op_parameter) {.pop = -2, .push = -2, __VA_ARGS__})
void (name_op) (struct op_parameter par);
#define local_op(...) local_op ((struct op_parameter) {.pop = 0, .push = 1, __VA_ARGS__})
void (local_op) (struct op_parameter par);
#define free_op(...) free_op ((struct op_parameter) {.pop = 0, .push = 1, __VA_ARGS__})
void (free_op) (struct op_parameter par);
#define store_op(...) store_op ((struct op_parameter) {.pop = 0, .push = 1, .func = DEF_OP, __VA_ARGS__})
void (store_op) (struct op_parameter par);
#define varargs_op(...) varargs_op ((struct op_parameter) {.pop = -1, .push = 1, __VA_ARGS__})
void (varargs_op) (struct op_parameter par);
#define const_op(...) const_op ((struct op_parameter) {.pop = 0, .push = 1, __VA_ARGS__})
void (const_op) (struct op_parameter par);
#define compare_op(...) compare_op ((struct op_parameter) {.pop = 2, .push = 1, __VA_ARGS__})
void (compare_op) (struct op_parameter par);
#define jabs_op(...) jabs_op ((struct op_parameter) {.pop = 0, .push = 0, .conditional = false, .fallthrough = true, __VA_ARGS__})
void (jabs_op) (struct op_parameter par);
#define jrel_op(...) jrel_op ((struct op_parameter) {.pop = 0, .push = 0, .conditional = false, .fallthrough = true, __VA_ARGS__})
void (jrel_op) (struct op_parameter par);
#define nargs_op(...) nargs_op ((struct op_parameter) {.pop = -2, .push = -2, __VA_ARGS__})
void (nargs_op) (struct op_parameter par);
#define rm_op(...) rm_op ((struct op_parameter) {__VA_ARGS__})
void (rm_op) (struct op_parameter par);
#endif
+18
View File
@@ -0,0 +1,18 @@
#include "opcode.h"
pyc_opcodes *opcode_10 () {
pyc_opcodes *ret = opcode_11 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_10;
// 1.0 - 1.1 bytecodes differences
rm_op (.op_obj = ret->opcodes, .op_name = "LOAD_GLOBALS", .op_code = 84);
rm_op (.op_obj = ret->opcodes, .op_name = "EXEC_STMT", .op_code = 85);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+14
View File
@@ -0,0 +1,14 @@
#include "opcode.h"
pyc_opcodes *opcode_11 () {
pyc_opcodes *ret = opcode_13 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_11;
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+14
View File
@@ -0,0 +1,14 @@
#include "opcode.h"
pyc_opcodes *opcode_12 () {
pyc_opcodes *ret = opcode_13 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_12;
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+18
View File
@@ -0,0 +1,18 @@
#include "opcode.h"
pyc_opcodes *opcode_13 () {
pyc_opcodes *ret = opcode_14 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_13;
// 1.3 - 1.4 bytecodes differences
rm_op (.op_obj = ret->opcodes, .op_name = "BINARY_POWER", .op_code = 19);
def_op (.op_obj = ret->opcodes, .op_name = "LOAD_GLOBALS", .op_code = 84);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+25
View File
@@ -0,0 +1,25 @@
#include "opcode.h"
pyc_opcodes *opcode_14 () {
pyc_opcodes *ret = opcode_15 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_14;
// 1.4 Bytecodes not in 1.5
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_CALL", .op_code = 14);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_CALL", .op_code = 26);
def_op (.op_obj = ret->opcodes, .op_name = "RAISE_EXCEPTION", .op_code = 81);
def_op (.op_obj = ret->opcodes, .op_name = "BUILD_FUNCTION", .op_code = 86);
varargs_op (.op_obj = ret->opcodes, .op_name = "UNPACK_ARG", .op_code = 94); // Number of arguments expected
varargs_op (.op_obj = ret->opcodes, .op_name = "UNPACK_VARARG", .op_code = 99); // Minimal number of arguments
name_op (.op_obj = ret->opcodes, .op_name = "LOAD_LOCAL", .op_code = 115);
varargs_op (.op_obj = ret->opcodes, .op_name = "SET_FUNC_ARGS", .op_code = 117); // Argcount
varargs_op (.op_obj = ret->opcodes, .op_name = "RESERVE_FAST", .op_code = 123); // Number of local variables
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+124
View File
@@ -0,0 +1,124 @@
#include "opcode.h"
pyc_opcodes *opcode_15 () {
pyc_opcodes *ret = new_pyc_opcodes ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_15;
def_op (.op_obj = ret->opcodes, .op_name = "STOP_CODE", .op_code = 0, .pop = 0, .push = 0, .fallthrough = false);
def_op (.op_obj = ret->opcodes, .op_name = "POP_TOP", .op_code = 1);
def_op (.op_obj = ret->opcodes, .op_name = "ROT_TWO", .op_code = 2);
def_op (.op_obj = ret->opcodes, .op_name = "ROT_THREE", .op_code = 3);
def_op (.op_obj = ret->opcodes, .op_name = "DUP_TOP", .op_code = 4);
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_POSITIVE", .op_code = 10, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_NEGATIVE", .op_code = 11, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_NOT", .op_code = 12, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_CONVERT", .op_code = 13, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_INVERT", .op_code = 15, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_POWER", .op_code = 19, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_MULTIPLY", .op_code = 20, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_DIVIDE", .op_code = 21, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_MODULO", .op_code = 22, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_ADD", .op_code = 23, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_SUBTRACT", .op_code = 24, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_SUBSCR", .op_code = 25, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "SLICE_0", .op_code = 30, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "SLICE_1", .op_code = 31, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "SLICE_2", .op_code = 32, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "SLICE_3", .op_code = 33, .pop = 3, .push = 1);
store_op (.op_obj = ret->opcodes, .op_name = "STORE_SLICE_0", .op_code = 40, .pop = 2, .push = 0);
store_op (.op_obj = ret->opcodes, .op_name = "STORE_SLICE_1", .op_code = 41, .pop = 3, .push = 0);
store_op (.op_obj = ret->opcodes, .op_name = "STORE_SLICE_2", .op_code = 42, .pop = 3, .push = 0);
store_op (.op_obj = ret->opcodes, .op_name = "STORE_SLICE_3", .op_code = 43, .pop = 4, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "DELETE_SLICE_0", .op_code = 50, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "DELETE_SLICE_1", .op_code = 51, .pop = 2, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "DELETE_SLICE_2", .op_code = 52, .pop = 2, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "DELETE_SLICE_3", .op_code = 53, .pop = 3, .push = 0);
store_op (.op_obj = ret->opcodes, .op_name = "STORE_SUBSCR", .op_code = 60, .pop = 3, .push = 0); // Implements TOS1[TOS] = TOS2.
def_op (.op_obj = ret->opcodes, .op_name = "DELETE_SUBSCR", .op_code = 61, .pop = 2, .push = 0); // Implements del TOS1[TOS].
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_LSHIFT", .op_code = 62, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_RSHIFT", .op_code = 63, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_AND", .op_code = 64, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_XOR", .op_code = 65, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_OR", .op_code = 66, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "PRINT_EXPR", .op_code = 70, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "PRINT_ITEM", .op_code = 71, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "PRINT_NEWLINE", .op_code = 72, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "BREAK_LOOP", .op_code = 80, .pop = 0, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "LOAD_LOCALS", .op_code = 82, .pop = 0, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "RETURN_VALUE", .op_code = 83, .pop = 1, .push = 0, .fallthrough = false);
def_op (.op_obj = ret->opcodes, .op_name = "EXEC_STMT", .op_code = 85, .pop = 3, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "POP_BLOCK", .op_code = 87, .pop = 0, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "END_FINALLY", .op_code = 88, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "BUILD_CLASS", .op_code = 89, .pop = 3, .push = 0);
ret->have_argument = 90; // Opcodes from here have an argument:
store_op (.op_obj = ret->opcodes, .op_name = "STORE_NAME", .op_code = 90, .pop = 1, .push = 0, .func = NAME_OP); // Operand is in name list
name_op (.op_obj = ret->opcodes, .op_name = "DELETE_NAME", .op_code = 91, .pop = 0, .push = 0); // ""
varargs_op (.op_obj = ret->opcodes, .op_name = "UNPACK_TUPLE", .op_code = 92); // Number of tuple items
def_op (.op_obj = ret->opcodes, .op_name = "UNPACK_LIST", .op_code = 93); // Number of list items
store_op (.op_obj = ret->opcodes, .op_name = "STORE_ATTR", .op_code = 95, .pop = 2, .push = 0, .func = NAME_OP); // Operand is in name list
name_op (.op_obj = ret->opcodes, .op_name = "DELETE_ATTR", .op_code = 96, .pop = 1, .push = 0); // ""
store_op (.op_obj = ret->opcodes, .op_name = "STORE_GLOBAL", .op_code = 97, .pop = 1, .push = 0, .func = NAME_OP); // ""
name_op (.op_obj = ret->opcodes, .op_name = "DELETE_GLOBAL", .op_code = 98, .pop = 0, .push = 0); // ""
const_op (.op_obj = ret->opcodes, .op_name = "LOAD_CONST", .op_code = 100, .pop = 0, .push = 1); // Operand is in const list
name_op (.op_obj = ret->opcodes, .op_name = "LOAD_NAME", .op_code = 101, .pop = 0, .push = 1); // Operand is in name list
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_TUPLE", .op_code = 102, .pop = -1, .push = 1); // Number of tuple items
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_LIST", .op_code = 103, .pop = -1, .push = 1); // Number of list items
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_MAP", .op_code = 104, .pop = -1, .push = 1); // Always zero for now
name_op (.op_obj = ret->opcodes, .op_name = "LOAD_ATTR", .op_code = 105, .pop = 1, .push = 1); // Operand is in name list
compare_op (.op_obj = ret->opcodes, .op_name = "COMPARE_OP", .op_code = 106, .pop = 2, .push = 1); // Comparison operator
name_op (.op_obj = ret->opcodes, .op_name = "IMPORT_NAME", .op_code = 107, .pop = 2, .push = 1); // Operand is in name list
name_op (.op_obj = ret->opcodes, .op_name = "IMPORT_FROM", .op_code = 108, .pop = 0, .push = 1); // Operand is in name list
jrel_op (.op_obj = ret->opcodes, .op_name = "JUMP_FORWARD", .op_code = 110, .pop = 0, .push = 0); // Number of bytes to skip
jrel_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_FALSE", .op_code = 111, .pop = 1, .push = 1, .conditional = true); // ""
jrel_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_TRUE", .op_code = 112, .pop = 1, .push = 1, .conditional = true); // ""
jabs_op (.op_obj = ret->opcodes, .op_name = "JUMP_ABSOLUTE", .op_code = 113, .pop = 0, .push = 0); // Target byte offset from beginning of code
def_op (.op_obj = ret->opcodes, .op_name = "FOR_LOOP", .op_code = 114); // Number of bytes to skip
name_op (.op_obj = ret->opcodes, .op_name = "LOAD_GLOBAL", .op_code = 116, .pop = 0, .push = 1); // Operand is in name list
jrel_op (.op_obj = ret->opcodes, .op_name = "SETUP_LOOP", .op_code = 120, .pop = 0, .push = 0, .conditional = true); // Distance to target address
jrel_op (.op_obj = ret->opcodes, .op_name = "SETUP_EXCEPT", .op_code = 121, .pop = 0, .push = 0); // ""
jrel_op (.op_obj = ret->opcodes, .op_name = "SETUP_FINALLY", .op_code = 122, .pop = 0, .push = 0); // ""
local_op (.op_obj = ret->opcodes, .op_name = "LOAD_FAST", .op_code = 124, .pop = 0, .push = 1); // Local variable number
store_op (.op_obj = ret->opcodes, .op_name = "STORE_FAST", .op_code = 125, .pop = 1, .push = 0, .func = LOCAL_OP); // Local variable number
local_op (.op_obj = ret->opcodes, .op_name = "DELETE_FAST", .op_code = 126); // Local variable number
def_op (.op_obj = ret->opcodes, .op_name = "SET_LINENO", .op_code = 127); // Current line number
def_op (.op_obj = ret->opcodes, .op_name = "RAISE_VARARGS", .op_code = 130, .pop = -1, .push = 0, .fallthrough = false);
// Number of raise arguments (1, 2, or 3)
nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION", .op_code = 131, .pop = -1, .push = 1); // //args + (//kwargs << 8)
def_op (.op_obj = ret->opcodes, .op_name = "MAKE_FUNCTION", .op_code = 132, .pop = -1, .push = 1); // Number of args with default values
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_SLICE", .op_code = 133, .pop = -1, .push = 1); // Number of items
def_op (.op_obj = ret->opcodes, .op_name = "EXTENDED_ARG", .op_code = 143);
ret->extended_arg = 143;
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+19
View File
@@ -0,0 +1,19 @@
#include "opcode.h"
pyc_opcodes *opcode_16 () {
pyc_opcodes *ret = opcode_15 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_16;
// 1.6 Bytecodes not in 1.5
nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION_VAR", .op_code = 140, .pop = -1, .push = 1); // #args + (#kwargs << 8)
nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION_KW", .op_code = 141, .pop = -1, .push = 1); // #args + (#kwargs << 8)
nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION_VAR_KW", .op_code = 142, .pop = -1, .push = 1); // #args + (#kwargs << 8)
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+21
View File
@@ -0,0 +1,21 @@
#include "opcode.h"
pyc_opcodes *opcode_20 () {
pyc_opcodes *ret = opcode_21 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_20;
// 2.1 Bytecodes not in 2.0
rm_op (.op_obj = ret->opcodes, .op_name = "CONTINUE_LOOP", .op_code = 119);
rm_op (.op_obj = ret->opcodes, .op_name = "MAKE_CLOSURE", .op_code = 134);
rm_op (.op_obj = ret->opcodes, .op_name = "LOAD_CLOSURE", .op_code = 135);
rm_op (.op_obj = ret->opcodes, .op_name = "LOAD_DEREF", .op_code = 136);
rm_op (.op_obj = ret->opcodes, .op_name = "STORE_DEREF", .op_code = 137);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+23
View File
@@ -0,0 +1,23 @@
#include "opcode.h"
pyc_opcodes *opcode_21 () {
pyc_opcodes *ret = opcode_22 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_21;
// 2.1 bytecodes changes from 2.2
rm_op (.op_obj = ret->opcodes, .op_name = "BINARY_FLOOR_DIVIDE", .op_code = 26);
rm_op (.op_obj = ret->opcodes, .op_name = "BINARY_TRUE_DIVIDE", .op_code = 27);
rm_op (.op_obj = ret->opcodes, .op_name = "INPLACE_FLOOR_DIVIDE", .op_code = 28);
rm_op (.op_obj = ret->opcodes, .op_name = "INPLACE_TRUE_DIVIDE", .op_code = 29);
rm_op (.op_obj = ret->opcodes, .op_name = "GET_ITER", .op_code = 68);
rm_op (.op_obj = ret->opcodes, .op_name = "YIELD_VALUE", .op_code = 86);
rm_op (.op_obj = ret->opcodes, .op_name = "FOR_ITER", .op_code = 93);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+18
View File
@@ -0,0 +1,18 @@
#include "opcode.h"
pyc_opcodes *opcode_22 () {
pyc_opcodes *ret = opcode_2x ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_22;
// 2.2 Bytecodes not in 2.3
def_op (.op_obj = ret->opcodes, .op_name = "FOR_LOOP", .op_code = 114);
def_op (.op_obj = ret->opcodes, .op_name = "SET_LINENO", .op_code = 127, .pop = 0, .push = 0);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+14
View File
@@ -0,0 +1,14 @@
#include "opcode.h"
pyc_opcodes *opcode_23 () {
pyc_opcodes *ret = opcode_2x ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_23;
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+20
View File
@@ -0,0 +1,20 @@
#include "opcode.h"
pyc_opcodes *opcode_24 () {
pyc_opcodes *ret = opcode_2x ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_24;
// Bytecodes added since 2.3
def_op (.op_obj = ret->opcodes, .op_name = "NOP", .op_code = 9, .pop = 0, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "LIST_APPEND", .op_code = 18, .pop = 2, .push = 1); // Calls list.append(TOS[-i], TOS).
// Used to implement list comprehensions.
def_op (.op_obj = ret->opcodes, .op_name = "YIELD_VALUE", .op_code = 86, .pop = 1, .push = 0);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+17
View File
@@ -0,0 +1,17 @@
#include "opcode.h"
pyc_opcodes *opcode_25 () {
pyc_opcodes *ret = opcode_24 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_25;
// Bytecodes added in 2.5 from 2.4
def_op (.op_obj = ret->opcodes, .op_name = "WITH_CLEANUP", .op_code = 81);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+17
View File
@@ -0,0 +1,17 @@
#include "opcode.h"
pyc_opcodes *opcode_26 () {
pyc_opcodes *ret = opcode_25 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_26;
// Below are opcode changes since Python 2.5
store_op (.op_obj = ret->opcodes, .op_name = "STORE_MAP", .op_code = 54, .pop = 3, .push = 1);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+47
View File
@@ -0,0 +1,47 @@
#include "opcode.h"
pyc_opcodes *opcode_27 () {
pyc_opcodes *ret = opcode_26 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_27;
// Below are opcode changes since Python 2.6
rm_op (.op_obj = ret->opcodes, .op_name = "BUILD_MAP", .op_code = 104);
rm_op (.op_obj = ret->opcodes, .op_name = "LOAD_ATTR", .op_code = 105);
rm_op (.op_obj = ret->opcodes, .op_name = "COMPARE_OP", .op_code = 106);
rm_op (.op_obj = ret->opcodes, .op_name = "IMPORT_NAME", .op_code = 107);
rm_op (.op_obj = ret->opcodes, .op_name = "IMPORT_FROM", .op_code = 108);
rm_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_FALSE", .op_code = 111);
rm_op (.op_obj = ret->opcodes, .op_name = "EXTENDED_ARG", .op_code = 143);
rm_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_TRUE", .op_code = 112);
def_op (.op_obj = ret->opcodes, .op_name = "LIST_APPEND", .op_code = 94, .pop = 2, .push = 1); // Calls list.append(TOS[-i], TOS).
// Used to implement list comprehensions.
def_op (.op_obj = ret->opcodes, .op_name = "BUILD_SET", .op_code = 104); // Number of set items
def_op (.op_obj = ret->opcodes, .op_name = "BUILD_MAP", .op_code = 105);
name_op (.op_obj = ret->opcodes, .op_name = "LOAD_ATTR", .op_code = 106);
compare_op (.op_obj = ret->opcodes, .op_name = "COMPARE_OP", .op_code = 107);
name_op (.op_obj = ret->opcodes, .op_name = "IMPORT_NAME", .op_code = 108, .pop = 2, .push = 1); // Index in name list
name_op (.op_obj = ret->opcodes, .op_name = "IMPORT_FROM", .op_code = 109, .pop = 0, .push = 1);
jabs_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_FALSE_OR_POP", .op_code = 111); // Target byte offset from beginning of code
jabs_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_TRUE_OR_POP", .op_code = 112); // ""
jabs_op (.op_obj = ret->opcodes, .op_name = "POP_JUMP_IF_FALSE", .op_code = 114); // ""
jabs_op (.op_obj = ret->opcodes, .op_name = "POP_JUMP_IF_TRUE", .op_code = 115); // ""
jrel_op (.op_obj = ret->opcodes, .op_name = "SETUP_WITH", .op_code = 143, .pop = 0, .push = 2);
def_op (.op_obj = ret->opcodes, .op_name = "EXTENDED_ARG", .op_code = 145);
def_op (.op_obj = ret->opcodes, .op_name = "SET_ADD", .op_code = 146, .pop = 1, .push = 0); // Calls set.add(TOS1[-i], TOS).
// Used to implement set comprehensions.
def_op (.op_obj = ret->opcodes, .op_name = "MAP_ADD", .op_code = 147, .pop = 2, .push = 1); // Calls dict.setitem(TOS1[-i], TOS, TOS1)
// Used to implement dict comprehensions.
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
add_arg_fmt (ret, "CALL_FUNCTION", format_CALL_FUNCTION_pos_name_encoded);
return ret;
}
+151
View File
@@ -0,0 +1,151 @@
#include "opcode.h"
pyc_opcodes *opcode_2x () {
pyc_opcodes *ret = new_pyc_opcodes ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_2x;
def_op (.op_obj = ret->opcodes, .op_name = "STOP_CODE", .op_code = 0, .pop = 0, .push = 0, .fallthrough = false);
def_op (.op_obj = ret->opcodes, .op_name = "POP_TOP", .op_code = 1, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "ROT_TWO", .op_code = 2, .pop = 2, .push = 2);
def_op (.op_obj = ret->opcodes, .op_name = "ROT_THREE", .op_code = 3, .pop = 3, .push = 3);
def_op (.op_obj = ret->opcodes, .op_name = "DUP_TOP", .op_code = 4, .pop = 0, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "ROT_FOUR", .op_code = 5, .pop = 4, .push = 4);
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_POSITIVE", .op_code = 10, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_NEGATIVE", .op_code = 11, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_NOT", .op_code = 12, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_CONVERT", .op_code = 13, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_INVERT", .op_code = 15, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_POWER", .op_code = 19, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_MULTIPLY", .op_code = 20, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_DIVIDE", .op_code = 21, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_MODULO", .op_code = 22, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_ADD", .op_code = 23, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_SUBTRACT", .op_code = 24, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_SUBSCR", .op_code = 25, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_FLOOR_DIVIDE", .op_code = 26, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_TRUE_DIVIDE", .op_code = 27, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_FLOOR_DIVIDE", .op_code = 28, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_TRUE_DIVIDE", .op_code = 29, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "SLICE_0", .op_code = 30, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "SLICE_1", .op_code = 31, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "SLICE_2", .op_code = 32, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "SLICE_3", .op_code = 33, .pop = 3, .push = 1);
store_op (.op_obj = ret->opcodes, .op_name = "STORE_SLICE_0", .op_code = 40, .pop = 2, .push = 0);
store_op (.op_obj = ret->opcodes, .op_name = "STORE_SLICE_1", .op_code = 41, .pop = 3, .push = 0);
store_op (.op_obj = ret->opcodes, .op_name = "STORE_SLICE_2", .op_code = 42, .pop = 3, .push = 0);
store_op (.op_obj = ret->opcodes, .op_name = "STORE_SLICE_3", .op_code = 43, .pop = 4, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "DELETE_SLICE_0", .op_code = 50, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "DELETE_SLICE_1", .op_code = 51, .pop = 2, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "DELETE_SLICE_2", .op_code = 52, .pop = 2, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "DELETE_SLICE_3", .op_code = 53, .pop = 3, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_ADD", .op_code = 55, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_SUBTRACT", .op_code = 56, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_MULTIPLY", .op_code = 57, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_DIVIDE", .op_code = 58, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_MODULO", .op_code = 59, .pop = 2, .push = 1);
store_op (.op_obj = ret->opcodes, .op_name = "STORE_SUBSCR", .op_code = 60, .pop = 3, .push = 0); // Implements TOS1[TOS] = TOS2.
def_op (.op_obj = ret->opcodes, .op_name = "DELETE_SUBSCR", .op_code = 61, .pop = 2, .push = 0); // Implements del TOS1[TOS].
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_LSHIFT", .op_code = 62, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_RSHIFT", .op_code = 63, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_AND", .op_code = 64, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_XOR", .op_code = 65, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_OR", .op_code = 66, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_POWER", .op_code = 67, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "GET_ITER", .op_code = 68, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "PRINT_EXPR", .op_code = 70, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "PRINT_ITEM", .op_code = 71, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "PRINT_NEWLINE", .op_code = 72, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "PRINT_ITEM_TO", .op_code = 73, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "PRINT_NEWLINE_TO", .op_code = 74, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_LSHIFT", .op_code = 75, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_RSHIFT", .op_code = 76, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_AND", .op_code = 77, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_XOR", .op_code = 78, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_OR", .op_code = 79, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BREAK_LOOP", .op_code = 80, .pop = 0, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "LOAD_LOCALS", .op_code = 82, .pop = 0, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "RETURN_VALUE", .op_code = 83, .pop = 1, .push = 0, .fallthrough = false);
def_op (.op_obj = ret->opcodes, .op_name = "IMPORT_STAR", .op_code = 84, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "EXEC_STMT", .op_code = 85, .pop = 3, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "YIELD_VALUE", .op_code = 86, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "POP_BLOCK", .op_code = 87, .pop = 0, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "END_FINALLY", .op_code = 88, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "BUILD_CLASS", .op_code = 89, .pop = 3, .push = 0);
ret->have_argument = 90; // Opcodes from here have an argument:
store_op (.op_obj = ret->opcodes, .op_name = "STORE_NAME", .op_code = 90, .pop = 1, .push = 0, .func = NAME_OP); // Operand is in name list
name_op (.op_obj = ret->opcodes, .op_name = "DELETE_NAME", .op_code = 91, .pop = 0, .push = 0); // ""
varargs_op (.op_obj = ret->opcodes, .op_name = "UNPACK_SEQUENCE", .op_code = 92, .pop = 9, .push = 1); // TOS is number of tuple items
jrel_op (.op_obj = ret->opcodes, .op_name = "FOR_ITER", .op_code = 93, .pop = 9, .push = 1); // TOS is read
store_op (.op_obj = ret->opcodes, .op_name = "STORE_ATTR", .op_code = 95, .pop = 2, .push = 0, .func = NAME_OP); // Operand is in name list
name_op (.op_obj = ret->opcodes, .op_name = "DELETE_ATTR", .op_code = 96, .pop = 1, .push = 0); // ""
store_op (.op_obj = ret->opcodes, .op_name = "STORE_GLOBAL", .op_code = 97, .pop = 1, .push = 0, .func = NAME_OP); // ""
name_op (.op_obj = ret->opcodes, .op_name = "DELETE_GLOBAL", .op_code = 98, .pop = 0, .push = 0); // ""
def_op (.op_obj = ret->opcodes, .op_name = "DUP_TOPX", .op_code = 99, .pop = 1, .push = -1); // number of items to duplicate
const_op (.op_obj = ret->opcodes, .op_name = "LOAD_CONST", .op_code = 100, .pop = 0, .push = 1); // Operand is in const list
name_op (.op_obj = ret->opcodes, .op_name = "LOAD_NAME", .op_code = 101, .pop = 0, .push = 1); // Operand is in name list
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_TUPLE", .op_code = 102, .pop = 9, .push = 1); // TOS is number of tuple items
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_LIST", .op_code = 103, .pop = 9, .push = 1); // TOS is number of list items
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_MAP", .op_code = 104, .pop = 0, .push = 1); // TOS is number of kwark items. Always zero for now
name_op (.op_obj = ret->opcodes, .op_name = "LOAD_ATTR", .op_code = 105, .pop = 1, .push = 1); // Operand is in name list
compare_op (.op_obj = ret->opcodes, .op_name = "COMPARE_OP", .op_code = 106, .pop = 2, .push = 1); // Comparison operator
name_op (.op_obj = ret->opcodes, .op_name = "IMPORT_NAME", .op_code = 107, .pop = 2, .push = 1); // Operand is in name list
name_op (.op_obj = ret->opcodes, .op_name = "IMPORT_FROM", .op_code = 108, .pop = 0, .push = 1); // Operand is in name list
jrel_op (.op_obj = ret->opcodes, .op_name = "JUMP_FORWARD", .op_code = 110, .pop = 0, .push = 0, .fallthrough = false); // Number of bytes to skip
jrel_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_FALSE", .op_code = 111, .pop = 1, .push = 1, .conditional = true); // ""
jrel_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_TRUE", .op_code = 112, .pop = 1, .push = 1, .conditional = true); // ""
jabs_op (.op_obj = ret->opcodes, .op_name = "JUMP_ABSOLUTE", .op_code = 113, .pop = 0, .push = 0, .fallthrough = false); // Target byte offset from beginning of code
name_op (.op_obj = ret->opcodes, .op_name = "LOAD_GLOBAL", .op_code = 116, .pop = 0, .push = 1); // Operand is in name list
jabs_op (.op_obj = ret->opcodes, .op_name = "CONTINUE_LOOP", .op_code = 119, .pop = 0, .push = 0, .fallthrough = false); // Target address
jrel_op (.op_obj = ret->opcodes, .op_name = "SETUP_LOOP", .op_code = 120, .pop = 0, .push = 0, .conditional = true); // Distance to target address
jrel_op (.op_obj = ret->opcodes, .op_name = "SETUP_EXCEPT", .op_code = 121, .pop = 0, .push = 6, .conditional = true); // ""
jrel_op (.op_obj = ret->opcodes, .op_name = "SETUP_FINALLY", .op_code = 122, .pop = 0, .push = 7, .conditional = true); // ""
local_op (.op_obj = ret->opcodes, .op_name = "LOAD_FAST", .op_code = 124, .pop = 0, .push = 1); // Local variable number
store_op (.op_obj = ret->opcodes, .op_name = "STORE_FAST", .op_code = 125, .pop = 1, .push = 0, .func = LOCAL_OP); // Local variable number
local_op (.op_obj = ret->opcodes, .op_name = "DELETE_FAST", .op_code = 126); // Local variable number
def_op (.op_obj = ret->opcodes, .op_name = "RAISE_VARARGS", .op_code = 130, .pop = 1, .push = 0, .fallthrough = false); // Number of raise arguments (1, 2, or 3)
nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION", .op_code = 131, .pop = 9, .push = 1); // TOS is //args + (//kwargs << 8)
def_op (.op_obj = ret->opcodes, .op_name = "MAKE_FUNCTION", .op_code = 132, .pop = 9, .push = 1); // TOS is number of args with default values
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_SLICE", .op_code = 133, .pop = 9, .push = 1); // TOS is number of items
def_op (.op_obj = ret->opcodes, .op_name = "MAKE_CLOSURE", .op_code = 134, .pop = 9, .push = 1);
free_op (.op_obj = ret->opcodes, .op_name = "LOAD_CLOSURE", .op_code = 135, .pop = 0, .push = 1);
free_op (.op_obj = ret->opcodes, .op_name = "LOAD_DEREF", .op_code = 136, .pop = 0, .push = 1);
store_op (.op_obj = ret->opcodes, .op_name = "STORE_DEREF", .op_code = 137, .pop = 1, .push = 0, .func = FREE_OP);
nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION_VAR", .op_code = 140, .pop = -1, .push = 1); // #args + (#kwargs << 8)
nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION_KW", .op_code = 141, .pop = -1, .push = 1); // #args + (#kwargs << 8)
nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION_VAR_KW", .op_code = 142, .pop = -1, .push = 1); // #args + (#kwargs << 8)
def_op (.op_obj = ret->opcodes, .op_name = "EXTENDED_ARG", 143);
ret->extended_arg = 143;
r_list_purge (ret->opcode_arg_fmt);
return ret;
}
+35
View File
@@ -0,0 +1,35 @@
#include "opcode.h"
pyc_opcodes *opcode_30 () {
pyc_opcodes *ret = opcode_31 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_30;
// These are in Python 3.x but not in Python 3.0
rm_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_FALSE_OR_POP", .op_code = 111);
rm_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_TRUE_OR_POP", .op_code = 112);
rm_op (.op_obj = ret->opcodes, .op_name = "POP_JUMP_IF_FALSE", .op_code = 114);
rm_op (.op_obj = ret->opcodes, .op_name = "POP_JUMP_IF_TRUE", .op_code = 115);
rm_op (.op_obj = ret->opcodes, .op_name = "LIST_APPEND", .op_code = 145);
rm_op (.op_obj = ret->opcodes, .op_name = "MAP_ADD", .op_code = 147);
// These are are in 3.0 but are not in 3.1 or they have
// different opcode numbers. Note: As a result of opcode value
// changes, these have to be applied *after* removing ops (with
// the same name).
def_op (.op_obj = ret->opcodes, .op_name = "SET_ADD", .op_code = 17, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "LIST_APPEND", .op_code = 18, .pop = 2, .push = 1);
jrel_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_FALSE", .op_code = 111, .pop = 1, .push = 1);
jrel_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_TRUE", .op_code = 112, .pop = 1, .push = 1);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_3x);
return ret;
}
+27
View File
@@ -0,0 +1,27 @@
#include "opcode.h"
pyc_opcodes *opcode_31 () {
pyc_opcodes *ret = opcode_32 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_31;
// These are in Python 3.2 but not in Python 3.1
rm_op (.op_obj = ret->opcodes, .op_name = "DUP_TOP_TWO", .op_code = 5);
rm_op (.op_obj = ret->opcodes, .op_name = "DELETE_DEREF", .op_code = 138);
rm_op (.op_obj = ret->opcodes, .op_name = "SETUP_WITH", .op_code = 143);
// These are in Python 3.1 but not Python 3.2
def_op (.op_obj = ret->opcodes, .op_name = "ROT_FOUR", .op_code = 5);
def_op (.op_obj = ret->opcodes, .op_name = "DUP_TOPX", .op_code = 99);
// This op is in 3.2 but its opcode is a 144 instead
def_op (.op_obj = ret->opcodes, .op_name = "EXTENDED_ARG", .op_code = 143);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_3x);
return ret;
}
+18
View File
@@ -0,0 +1,18 @@
#include "opcode.h"
pyc_opcodes *opcode_32 () {
pyc_opcodes *ret = opcode_3x ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_32;
// There are no opcodes to add or change.
// If there were, they'd be listed below.
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_3x);
return ret;
}
+20
View File
@@ -0,0 +1,20 @@
#include "opcode.h"
pyc_opcodes *opcode_33 () {
pyc_opcodes *ret = opcode_3x ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_33;
// Below are opcode changes since Python 3.2
rm_op (.op_obj = ret->opcodes, .op_name = "STOP_CODE", .op_code = 0);
def_op (.op_obj = ret->opcodes, .op_name = "YIELD_FROM", .op_code = 72, .pop = 1, .push = 0);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_3x);
return ret;
}
+22
View File
@@ -0,0 +1,22 @@
#include "opcode.h"
pyc_opcodes *opcode_34 () {
pyc_opcodes *ret = opcode_33 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_34;
// These are removed since Python 3.3
rm_op (.op_obj = ret->opcodes, .op_name = "STORE_LOCALS", .op_code = 69);
// These are new since Python 3.3
def_op (.op_obj = ret->opcodes, .op_name = "YIELD_FROM", .op_code = 72);
free_op (.op_obj = ret->opcodes, .op_name = "LOAD_CLASSDEREF", .op_code = 148);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_3x);
return ret;
}
+42
View File
@@ -0,0 +1,42 @@
#include "opcode.h"
pyc_opcodes *opcode_35 () {
pyc_opcodes *ret = opcode_34 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_35;
// These are removed since Python 3.5.
// Removals happen before adds since
// some opcodes are reused
rm_op (.op_obj = ret->opcodes, .op_name = "STORE_MAP", .op_code = 54);
rm_op (.op_obj = ret->opcodes, .op_name = "WITH_CLEANUP", .op_code = 81);
// These are new since Python 3.5
// OP NAME OPCODE POP PUSH
//---------------------------------------------------
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_MATRIX_MULTIPLY", .op_code = 16, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_MATRIX_MULTIPLY", .op_code = 17, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "GET_AITER", .op_code = 50, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "GET_ANEXT", .op_code = 51, .pop = 0, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BEFORE_ASYNC_WITH", .op_code = 52);
def_op (.op_obj = ret->opcodes, .op_name = "GET_YIELD_FROM_ITER", .op_code = 69, .pop = 0, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "GET_AWAITABLE", .op_code = 73, .pop = 0, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "WITH_CLEANUP_START", .op_code = 81, .pop = 0, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "WITH_CLEANUP_FINISH", .op_code = 82, .pop = -1, .push = 1);
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_LIST_UNPACK", .op_code = 149, .pop = -1, .push = 1);
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_MAP_UNPACK", .op_code = 150, .pop = -1, .push = 1);
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_MAP_UNPACK_WITH_CALL", .op_code = 151, .pop = -1, .push = 1);
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_TUPLE_UNPACK", .op_code = 152, .pop = -1, .push = 1);
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_SET_UNPACK", .op_code = 153, .pop = -1, .push = 1);
jrel_op (.op_obj = ret->opcodes, .op_name = "SETUP_ASYNC_WITH", .op_code = 154, .pop = 0, .push = 6);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_3x);
return ret;
}
+33
View File
@@ -0,0 +1,33 @@
#include "opcode.h"
pyc_opcodes *opcode_36 () {
pyc_opcodes *ret = opcode_35 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_36;
// These are removed since Python 3.6
rm_op (.op_obj = ret->opcodes, .op_name = "MAKE_CLOSURE", .op_code = 134);
rm_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION_VAR", .op_code = 140);
rm_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION_VAR_KW", .op_code = 142);
// These are new since Python 3.6
store_op (.op_obj = ret->opcodes, .op_name = "STORE_ANNOTATION", .op_code = 127, .func = NAME_OP); // Index in name list
jrel_op (.op_obj = ret->opcodes, .op_name = "SETUP_ASYNC_WITH", .op_code = 154);
def_op (.op_obj = ret->opcodes, .op_name = "FORMAT_VALUE", .op_code = 155);
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_CONST_KEY_MAP", .op_code = 156, .pop = -1, .push = 1); // TOS is count of kwargs
nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION_EX", .op_code = 142, .pop = -1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "SETUP_ANNOTATIONS", .op_code = 85);
def_op (.op_obj = ret->opcodes, .op_name = "BUILD_STRING", .op_code = 157);
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_TUPLE_UNPACK_WITH_CALL", .op_code = 158);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "CALL_FUNCTION_KW", format_CALL_FUNCTION_KW_36);
add_arg_fmt (ret, "CALL_FUNCTION_EX", format_CALL_FUNCTION_EX_36);
add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_36);
add_arg_fmt (ret, "FORMAT_VALUE", format_value_flags_36);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg_36);
return ret;
}
+26
View File
@@ -0,0 +1,26 @@
#include "opcode.h"
pyc_opcodes *opcode_37 () {
pyc_opcodes *ret = opcode_36 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_37;
// These are removed since 3.6...
// and STORE_ANNOTATION introduced in 3.6!
rm_op (.op_obj = ret->opcodes, .op_name = "STORE_ANNOTATION", .op_code = 127);
// These are new since Python 3.7
name_op (.op_obj = ret->opcodes, .op_name = "LOAD_METHOD", .op_code = 160);
nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_METHOD", .op_code = 161);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "CALL_FUNCTION_KW", format_CALL_FUNCTION_KW_36);
add_arg_fmt (ret, "CALL_FUNCTION_EX", format_CALL_FUNCTION_EX_36);
add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_36);
add_arg_fmt (ret, "FORMAT_VALUE", format_value_flags_36);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg_36);
return ret;
}
+35
View File
@@ -0,0 +1,35 @@
#include "opcode.h"
pyc_opcodes *opcode_38 () {
pyc_opcodes *ret = opcode_37 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_38;
// These are removed since 3.7...
rm_op (.op_obj = ret->opcodes, .op_name = "BREAK_LOOP", .op_code = 80);
rm_op (.op_obj = ret->opcodes, .op_name = "CONTINUE_LOOP", .op_code = 119);
rm_op (.op_obj = ret->opcodes, .op_name = "SETUP_LOOP", .op_code = 120);
rm_op (.op_obj = ret->opcodes, .op_name = "SETUP_EXCEPT", .op_code = 121);
// These are new since Python 3.7
// OP NAME OPCODE POP PUSH
// --------------------------------------------
def_op (.op_obj = ret->opcodes, .op_name = "ROT_FOUR", .op_code = 6, .pop = 4, .push = 4);
def_op (.op_obj = ret->opcodes, .op_name = "BEGIN_FINALLY", .op_code = 53, .pop = 0, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "END_ASYNC_FOR", .op_code = 54, .pop = 7, .push = 0); // POP is 0, when not 7
def_op (.op_obj = ret->opcodes, .op_name = "END_FINALLY", .op_code = 88, .pop = 1, .push = 0); // POP is 6, when not 1
jrel_op (.op_obj = ret->opcodes, .op_name = "CALL_FINALLY", .op_code = 162, .pop = 0, .push = 1);
nargs_op (.op_obj = ret->opcodes, .op_name = "POP_FINALLY", .op_code = 163, .pop = 0, .push = 0); // PUSH/POP vary
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "CALL_FUNCTION_KW", format_CALL_FUNCTION_KW_36);
add_arg_fmt (ret, "CALL_FUNCTION_EX", format_CALL_FUNCTION_EX_36);
add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_36);
add_arg_fmt (ret, "FORMAT_VALUE", format_value_flags_36);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg_36);
return ret;
}
+32
View File
@@ -0,0 +1,32 @@
#include "opcode.h"
pyc_opcodes *opcode_39 () {
pyc_opcodes *ret = opcode_38 ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_39;
// These are removed since 3.8...
rm_op (.op_obj = ret->opcodes, .op_name = "BEGIN_FINALLY", .op_code = 53);
rm_op (.op_obj = ret->opcodes, .op_name = "WITH_CLEANUP_START", .op_code = 81);
rm_op (.op_obj = ret->opcodes, .op_name = "WITH_CLEANUP_FINISH", .op_code = 82);
rm_op (.op_obj = ret->opcodes, .op_name = "END_FINALLY", .op_code = 88);
rm_op (.op_obj = ret->opcodes, .op_name = "CALL_FINALLY", .op_code = 162);
rm_op (.op_obj = ret->opcodes, .op_name = "POP_FINALLY", .op_code = 163);
// These are new since Python 3.9
// OP NAME OPCODE POP PUSH
def_op (.op_obj = ret->opcodes, .op_name = "RERAISE", .op_code = 48, .pop = 0, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "WITH_EXCEPT_START", .op_code = 49, .pop = 3, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "LOAD_ASSERTION_ERROR", .op_code = 74, .pop = 0, .push = 1);
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "CALL_FUNCTION_KW", format_CALL_FUNCTION_KW_36);
add_arg_fmt (ret, "CALL_FUNCTION_EX", format_CALL_FUNCTION_EX_36);
add_arg_fmt (ret, "MAKE_FUNCTION", format_MAKE_FUNCTION_arg_36);
add_arg_fmt (ret, "FORMAT_VALUE", format_value_flags_36);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg_36);
return ret;
}
+164
View File
@@ -0,0 +1,164 @@
#include "opcode.h"
pyc_opcodes *opcode_3x () {
pyc_opcodes *ret = new_pyc_opcodes ();
if (!ret)
return NULL;
ret->version_sig = (void * (*)())opcode_3x;
def_op (.op_obj = ret->opcodes, .op_name = "STOP_CODE", .op_code = 0, .pop = 0, .push = 0, .fallthrough = false);
def_op (.op_obj = ret->opcodes, .op_name = "POP_TOP", .op_code = 1, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "ROT_TWO", .op_code = 2, .pop = 2, .push = 2);
def_op (.op_obj = ret->opcodes, .op_name = "ROT_THREE", .op_code = 3, .pop = 3, .push = 3);
def_op (.op_obj = ret->opcodes, .op_name = "DUP_TOP", .op_code = 4, .pop = 0, .push = 1);
// Python 3.2+
def_op (.op_obj = ret->opcodes, .op_name = "DUP_TOP_TWO", .op_code = 5, .pop = 0, .push = 2);
def_op (.op_obj = ret->opcodes, .op_name = "NOP", 9);
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_POSITIVE", .op_code = 10, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_NEGATIVE", .op_code = 11, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_NOT", .op_code = 12, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "UNARY_INVERT", .op_code = 15, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_POWER", .op_code = 19, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_MULTIPLY", .op_code = 20, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_MODULO", .op_code = 22, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_ADD", .op_code = 23, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_SUBTRACT", .op_code = 24, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_SUBSCR", .op_code = 25, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_FLOOR_DIVIDE", .op_code = 26, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_TRUE_DIVIDE", .op_code = 27, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_FLOOR_DIVIDE", .op_code = 28, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_TRUE_DIVIDE", .op_code = 29, .pop = 2, .push = 1);
// Gone from Python 3 are Python2's
// SLICE+0 .. SLICE+3
// STORE_SLICE+0 .. STORE_SLICE+3
// DELETE_SLICE+0 .. DELETE_SLICE+3
store_op (.op_obj = ret->opcodes, .op_name = "STORE_MAP", .op_code = 54, .pop = 3, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_ADD", .op_code = 55, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_SUBTRACT", .op_code = 56, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_MULTIPLY", .op_code = 57, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_MODULO", .op_code = 59, .pop = 2, .push = 1);
store_op (.op_obj = ret->opcodes, .op_name = "STORE_SUBSCR", .op_code = 60, .pop = 3, .push = 0); // Implements TOS1[TOS] = TOS2.
def_op (.op_obj = ret->opcodes, .op_name = "DELETE_SUBSCR", .op_code = 61, .pop = 2, .push = 0); // Implements del TOS1[TOS].
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_LSHIFT", .op_code = 62, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_RSHIFT", .op_code = 63, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_AND", .op_code = 64, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_XOR", .op_code = 65, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BINARY_OR", .op_code = 66, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_POWER", .op_code = 67, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "GET_ITER", .op_code = 68, .pop = 1, .push = 1);
store_op (.op_obj = ret->opcodes, .op_name = "STORE_LOCALS", .op_code = 69, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "PRINT_EXPR", .op_code = 70, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "LOAD_BUILD_CLASS", .op_code = 71, .pop = 0, .push = 1);
// Python3 drops/changes:
// def_op(.op_obj = ret->opcodes, .op_name = "PRINT_ITEM", 71)
// def_op(.op_obj = ret->opcodes, .op_name = "PRINT_NEWLINE", 72)
// def_op(.op_obj = ret->opcodes, .op_name = "PRINT_ITEM_TO", 73)
// def_op(.op_obj = ret->opcodes, .op_name = "PRINT_NEWLINE_TO", 74)
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_LSHIFT", .op_code = 75, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_RSHIFT", .op_code = 76, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_AND", .op_code = 77, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_XOR", .op_code = 78, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "INPLACE_OR", .op_code = 79, .pop = 2, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "BREAK_LOOP", .op_code = 80, .pop = 0, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "WITH_CLEANUP", .op_code = 81, .pop = 1, .push = 0); // Cleans up the stack when a with statement
// block exits. Handle stack special
def_op (.op_obj = ret->opcodes, .op_name = "RETURN_VALUE", .op_code = 83, .pop = 1, .push = 0, .fallthrough = false);
def_op (.op_obj = ret->opcodes, .op_name = "IMPORT_STAR", .op_code = 84, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "YIELD_VALUE", .op_code = 86, .pop = 1, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "POP_BLOCK", .op_code = 87, .pop = 0, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "END_FINALLY", .op_code = 88, .pop = 1, .push = 0);
def_op (.op_obj = ret->opcodes, .op_name = "POP_EXCEPT", .op_code = 89, .pop = 1, .push = -1);
ret->have_argument = 90; // Opcodes from here have an argument:
store_op (.op_obj = ret->opcodes, .op_name = "STORE_NAME", .op_code = 90, .pop = 1, .push = 0, .func = NAME_OP); // Operand is in name list
name_op (.op_obj = ret->opcodes, .op_name = "DELETE_NAME", .op_code = 91, .pop = 0, .push = 0); // ""
varargs_op (.op_obj = ret->opcodes, .op_name = "UNPACK_SEQUENCE", .op_code = 92, .pop = 9, .push = 1); // TOS is number of tuple items
jrel_op (.op_obj = ret->opcodes, .op_name = "FOR_ITER", .op_code = 93, .pop = 9, .push = 1);
def_op (.op_obj = ret->opcodes, .op_name = "UNPACK_EX", .op_code = 94, .pop = 9, .push = 1); // assignment with a starred target; TOS is #entries
// argument has a count
store_op (.op_obj = ret->opcodes, .op_name = "STORE_ATTR", .op_code = 95, .pop = 2, .push = 0, .func = NAME_OP); // Operand is in name list
name_op (.op_obj = ret->opcodes, .op_name = "DELETE_ATTR", .op_code = 96, .pop = 1, .push = 0); // ""
store_op (.op_obj = ret->opcodes, .op_name = "STORE_GLOBAL", .op_code = 97, .pop = 1, .push = 0, .func = NAME_OP); // ""
name_op (.op_obj = ret->opcodes, .op_name = "DELETE_GLOBAL", .op_code = 98, .pop = 0, .push = 0); // ""
// Python 2's DUP_TOPX is gone starting in Python 3.2
const_op (.op_obj = ret->opcodes, .op_name = "LOAD_CONST", .op_code = 100, .pop = 0, .push = 1); // Operand is in const list
name_op (.op_obj = ret->opcodes, .op_name = "LOAD_NAME", .op_code = 101, .pop = 0, .push = 1); // Operand is in name list
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_TUPLE", .op_code = 102, .pop = 9, .push = 1); // TOS is count of tuple items
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_LIST", .op_code = 103, .pop = 9, .push = 1); // TOS is count of list items
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_SET", .op_code = 104, .pop = 9, .push = 1); // TOS is count of set items
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_MAP", .op_code = 105, .pop = 0, .push = 1); // TOS is count of kwarg items
name_op (.op_obj = ret->opcodes, .op_name = "LOAD_ATTR", .op_code = 106, .pop = 1, .push = 1); // Operand is in name list
compare_op (.op_obj = ret->opcodes, .op_name = "COMPARE_OP", .op_code = 107, .pop = 2, .push = 1); // Comparison operator
name_op (.op_obj = ret->opcodes, .op_name = "IMPORT_NAME", .op_code = 108, .pop = 1, .push = 1); // Operand is in name list
name_op (.op_obj = ret->opcodes, .op_name = "IMPORT_FROM", .op_code = 109, .pop = 0, .push = 1); // Operand is in name list
jrel_op (.op_obj = ret->opcodes, .op_name = "JUMP_FORWARD", .op_code = 110, .pop = 0, .push = 0); // Number of bytes to skip
jabs_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_FALSE_OR_POP", .op_code = 111, .conditional = true); // Target byte offset from beginning of code
jabs_op (.op_obj = ret->opcodes, .op_name = "JUMP_IF_TRUE_OR_POP", .op_code = 112, .conditional = true); // ""
jabs_op (.op_obj = ret->opcodes, .op_name = "JUMP_ABSOLUTE", .op_code = 113, .pop = 0, .push = 0); // Target byte offset from beginning of code
jabs_op (.op_obj = ret->opcodes, .op_name = "POP_JUMP_IF_FALSE", .op_code = 114, .pop = 9, .push = 1, .conditional = true); // ""
jabs_op (.op_obj = ret->opcodes, .op_name = "POP_JUMP_IF_TRUE", .op_code = 115, .pop = 9, .push = 1, .conditional = true); // ""
name_op (.op_obj = ret->opcodes, .op_name = "LOAD_GLOBAL", .op_code = 116, .pop = 0, .push = 1); // Operand is in name list
jabs_op (.op_obj = ret->opcodes, .op_name = "CONTINUE_LOOP", .op_code = 119, .pop = 0, .push = 0); // Target address
jrel_op (.op_obj = ret->opcodes, .op_name = "SETUP_LOOP", .op_code = 120, .pop = 0, .push = 0, .conditional = true); // Distance to target address
jrel_op (.op_obj = ret->opcodes, .op_name = "SETUP_EXCEPT", .op_code = 121, .pop = 0, .push = 6, .conditional = true); // ""
jrel_op (.op_obj = ret->opcodes, .op_name = "SETUP_FINALLY", .op_code = 122, .pop = 0, .push = 6, .conditional = true); // ""
local_op (.op_obj = ret->opcodes, .op_name = "LOAD_FAST", .op_code = 124, .pop = 0, .push = 1); // Local variable number
store_op (.op_obj = ret->opcodes, .op_name = "STORE_FAST", .op_code = 125, .pop = 1, .push = 0, .func = LOCAL_OP); // Local variable number
local_op (.op_obj = ret->opcodes, .op_name = "DELETE_FAST", .op_code = 126, .pop = 0, .push = 0); // Local variable number
def_op (.op_obj = ret->opcodes, .op_name = "RAISE_VARARGS", .op_code = 130, .pop = 9, .push = 1, .fallthrough = false);
// Number of raise arguments (1, 2, or 3)
nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION", .op_code = 131, .pop = 9, .push = 1); // #args + (#kwargs << 8)
def_op (.op_obj = ret->opcodes, .op_name = "MAKE_FUNCTION", .op_code = 132, .pop = 9, .push = 1); // TOS is number of args if < 3.6
varargs_op (.op_obj = ret->opcodes, .op_name = "BUILD_SLICE", .op_code = 133, .pop = 9, .push = 1); // TOS is number of items to pop
def_op (.op_obj = ret->opcodes, .op_name = "MAKE_CLOSURE", .op_code = 134, .pop = 9, .push = 1); // TOS is number of items to pop
free_op (.op_obj = ret->opcodes, .op_name = "LOAD_CLOSURE", .op_code = 135, .pop = 0, .push = 1);
free_op (.op_obj = ret->opcodes, .op_name = "LOAD_DEREF", .op_code = 136, .pop = 0, .push = 1);
store_op (.op_obj = ret->opcodes, .op_name = "STORE_DEREF", .op_code = 137, .pop = 1, .push = 0, .func = FREE_OP);
free_op (.op_obj = ret->opcodes, .op_name = "DELETE_DEREF", .op_code = 138, .pop = 0, .push = 0);
nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION_VAR", .op_code = 140, .pop = 9, .push = 1); // #args + (#kwargs << 8)
nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION_KW", .op_code = 141, .pop = 9, .push = 1); // #args + (#kwargs << 8)
nargs_op (.op_obj = ret->opcodes, .op_name = "CALL_FUNCTION_VAR_KW", .op_code = 142, .pop = 9, .push = 1); // #args + (#kwargs << 8)
jrel_op (.op_obj = ret->opcodes, .op_name = "SETUP_WITH", .op_code = 143, .pop = 0, .push = 7);
def_op (.op_obj = ret->opcodes, .op_name = "LIST_APPEND", .op_code = 145, .pop = 2, .push = 1); // Calls list.append(TOS[-i], TOS).
// Used to implement list comprehensions.
def_op (.op_obj = ret->opcodes, .op_name = "SET_ADD", .op_code = 146, .pop = 1, .push = 0); // Calls set.add(TOS1[-i], TOS).
// Used to implement set comprehensions.
def_op (.op_obj = ret->opcodes, .op_name = "MAP_ADD", .op_code = 147, .pop = 2, .push = 1); // Calls dict.setitem(TOS1[-i], TOS, TOS1)
// Used to implement dict comprehensions.
def_op (.op_obj = ret->opcodes, .op_name = "EXTENDED_ARG", .op_code = 144);
ret->extended_arg = 144;
r_list_purge (ret->opcode_arg_fmt);
add_arg_fmt (ret, "EXTENDED_ARG", format_extended_arg);
return ret;
}
+856
View File
@@ -0,0 +1,856 @@
#include "opcode.h"
// The actual code of one opcode varies across the versions.
// That's why I specify one opcode by its name, not its code.
static inline void anal_push (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg, ut32 type, st32 push_cnt) {
op->type = type;
op->stackop = R_ANAL_STACK_INC;
op->stackptr = OBJECT_SIZE_ON_STACK * push_cnt;
}
static inline void anal_pop (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg, ut32 type, st32 push_cnt) {
op->type = type;
op->stackop = R_ANAL_STACK_INC;
op->stackptr = -(OBJECT_SIZE_ON_STACK * push_cnt);
}
static void anal_BEFORE_ASYNC_WITH (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_BEGIN_FINALLY (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_BINARY_ADD (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_ADD, 1);
}
static void anal_BINARY_AND (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_AND, 1);
}
static void anal_BINARY_CALL (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// https://github.com/python/cpython/blob/v1.4b3/Include/opcode.h
// I can not find this opcode even in v1.4 version source code.
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_BINARY_DIVIDE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_DIV, 1);
}
static void anal_BINARY_FLOOR_DIVIDE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_DIV, 1);
}
static void anal_BINARY_LSHIFT (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_SHL, 1);
}
static void anal_BINARY_MATRIX_MULTIPLY (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_BINARY_MODULO (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_MOD, 1);
}
static void anal_BINARY_MULTIPLY (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_MUL, 1);
}
static void anal_BINARY_OR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_OR, 1);
}
static void anal_BINARY_POWER (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_BINARY_RSHIFT (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_SHR, 1);
}
static void anal_BINARY_SUBSCR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_BINARY_SUBTRACT (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_SUB, 1);
}
static void anal_BINARY_TRUE_DIVIDE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_DIV, 1);
}
static void anal_BINARY_XOR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_XOR, 1);
}
static void anal_BREAK_LOOP (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_IJMP;
op->jump = -1;
op->fail = -1;
}
static void anal_BUILD_CLASS (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, 2);
}
static void anal_BUILD_CONST_KEY_MAP (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg);
}
static void anal_BUILD_FUNCTION (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_NEW;
}
static void anal_BUILD_LIST (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg);
}
static void anal_BUILD_LIST_UNPACK (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1);
}
static void anal_BUILD_MAP (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, 2 * oparg - 1);
}
static void anal_BUILD_MAP_UNPACK (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1);
}
static void anal_BUILD_MAP_UNPACK_WITH_CALL (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg);
}
static void anal_BUILD_SET (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1);
}
static void anal_BUILD_SET_UNPACK (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1);
}
static void anal_BUILD_SLICE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1);
}
static void anal_BUILD_STRING (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1);
}
static void anal_BUILD_TUPLE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1);
}
static void anal_BUILD_TUPLE_UNPACK (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg - 1);
}
static void anal_BUILD_TUPLE_UNPACK_WITH_CALL (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_NEW, oparg);
}
static void anal_CALL_FUNCTION (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// TODO
// Get callee function from stack
// Parse oparg by version info
op->type = R_ANAL_OP_TYPE_ICALL;
op->jump = -1;
}
static void anal_CALL_FUNCTION_EX (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_ICALL;
op->jump = -1;
}
static void anal_CALL_FUNCTION_KW (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_ICALL;
op->jump = -1;
}
static void anal_CALL_FUNCTION_VAR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_ICALL;
op->jump = -1;
}
static void anal_CALL_FUNCTION_VAR_KW (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_ICALL;
op->jump = -1;
}
static void anal_CALL_METHOD (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_ICALL;
op->jump = -1;
}
static void anal_DELETE_ATTR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_DELETE_DEREF (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_DELETE_FAST (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_DELETE_GLOBAL (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_DELETE_NAME (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_DELETE_SLICE_0 (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_DELETE_SLICE_1 (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_DELETE_SLICE_2 (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_DELETE_SLICE_3 (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_DELETE_SUBSCR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_DUP_TOP (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UPUSH, 1);
}
static void anal_DUP_TOPX (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UPUSH, 1);
}
static void anal_DUP_TOP_TWO (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UPUSH, 2);
}
static void anal_END_ASYNC_FOR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// If TOS is StopAsyncIteration pop 7 values from the stack and restore the exception state using the second three of them.
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_END_FINALLY (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_CJMP;
op->jump = -1;
op->fail = -1;
}
static void anal_EXEC_STMT (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_EXTENDED_ARG (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_FORMAT_VALUE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
if ((oparg & 0x04) == 0x04) {
op->stackop = R_ANAL_STACK_INC;
op->stackptr = -OBJECT_SIZE_ON_STACK;
}
}
static void anal_FOR_LOOP (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// https://github.com/python/cpython/blob/b2b1ed17819ecb24a78d07d3ff1e8e6bc6137721/Python/ceval.c#L1499
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_GET_AITER (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_GET_ANEXT (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_GET_AWAITABLE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_GET_ITER (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_GET_YIELD_FROM_ITER (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_IMPORT_FROM (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_IMPORT_NAME (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_IMPORT_STAR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_INPLACE_ADD (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_ADD;
}
static void anal_INPLACE_AND (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_AND;
}
static void anal_INPLACE_DIVIDE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_DIV;
}
static void anal_INPLACE_FLOOR_DIVIDE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_DIV;
}
static void anal_INPLACE_LSHIFT (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_SHL;
}
static void anal_INPLACE_MATRIX_MULTIPLY (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_INPLACE_MODULO (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_MOD;
}
static void anal_INPLACE_MULTIPLY (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_MUL;
}
static void anal_INPLACE_OR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_OR;
}
static void anal_INPLACE_POWER (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_INPLACE_RSHIFT (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_SHR;
}
static void anal_INPLACE_SUBTRACT (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_SUB;
}
static void anal_INPLACE_TRUE_DIVIDE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_DIV;
}
static void anal_INPLACE_XOR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_XOR;
}
static void anal_LIST_APPEND (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_LOAD_ASSERTION_ERROR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_LOAD_ATTR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_LOAD_BUILD_CLASS (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_LOAD_CLASSDEREF (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_LOAD_CLOSURE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_LOAD_CONST (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_LOAD_DEREF (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_LOAD_FAST (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_LOAD_GLOBAL (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_LOAD_GLOBALS (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// https://github.com/python/cpython/blob/24260ec91623c18569225229d5becb852010ae2c/Include/opcode.h#L80
// Can't find this opcode
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_LOAD_LOCAL (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_LOAD_LOCALS (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_LOAD_METHOD (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_LOAD_NAME (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_MAKE_CLOSURE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, oparg);
}
static void anal_MAKE_FUNCTION (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, oparg);
}
static void anal_MAP_ADD (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_NOP (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_NOP;
}
static void anal_POP_BLOCK (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_POP, 1);
}
static void anal_POP_EXCEPT (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_POP, 1);
}
static void anal_POP_FINALLY (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// FIXME
// POP_FINALLY will pop 6 elements if TOS is an exception type
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_POP, 1);
}
static void anal_POP_TOP (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_POP, 1);
}
static void anal_PRINT_EXPR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_PRINT_ITEM (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_PRINT_ITEM_TO (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 2);
}
static void anal_PRINT_NEWLINE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_PRINT_NEWLINE_TO (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_RAISE_EXCEPTION (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// https://github.com/python/cpython/blob/6c3a3aa17b028f6b93067083d32c7eaa4338757c/Include/opcode.h#L89
// Can't find this opcode
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_RAISE_VARARGS (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, oparg);
}
static void anal_RERAISE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 3);
}
static void anal_RESERVE_FAST (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// https://github.com/python/cpython/blob/6c3a3aa17b028f6b93067083d32c7eaa4338757c/Include/opcode.h#L134
// Can't find this opcode
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_RETURN_VALUE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_RET;
op->stackop = R_ANAL_STACK_INC;
op->stackptr = -OBJECT_SIZE_ON_STACK;
op->eob = true;
}
static void anal_ROT_FOUR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// Lifts second, third and forth stack items one position up, moves top down to position four.
op->type = R_ANAL_OP_TYPE_XCHG;
}
static void anal_ROT_THREE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// Lifts second and third stack item one position up, moves top down to position three.
op->type = R_ANAL_OP_TYPE_XCHG;
}
static void anal_ROT_TWO (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// Swaps the two top-most stack items.
op->type = R_ANAL_OP_TYPE_XCHG;
}
static void anal_SETUP_ANNOTATIONS (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_SET_ADD (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_SET_FUNC_ARGS (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// https://github.com/python/cpython/blob/v1.4/Python/ceval.c
// Can't find this opcode
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_SET_LINENO (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_SLICE_0 (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_SLICE_1 (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_SLICE_2 (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_SLICE_3 (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 2);
}
static void anal_STOP_CODE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_TRAP;
}
static void anal_STORE_ANNOTATION (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_STORE_ATTR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_STORE_DEREF (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_STORE_FAST (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_STORE_GLOBAL (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_STORE_LOCALS (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_STORE_MAP (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 2);
}
static void anal_STORE_NAME (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_STORE_SLICE_0 (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 2);
}
static void anal_STORE_SLICE_1 (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 3);
}
static void anal_STORE_SLICE_2 (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 3);
}
static void anal_STORE_SLICE_3 (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 4);
}
static void anal_STORE_SUBSCR (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 3);
}
static void anal_UNARY_CALL (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// https://github.com/python/cpython/blob/v1.4b3/Include/opcode.h
// I can not find this opcode even in v1.4 version source code.
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_UNARY_CONVERT (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_UNARY_INVERT (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_NOT;
}
static void anal_UNARY_NEGATIVE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_UNARY_NOT (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_NOT;
}
static void anal_UNARY_POSITIVE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_UNPACK_ARG (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, oparg - 1);
}
static void anal_UNPACK_EX (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, (oparg & 0xFF) + (oparg >> 8));
}
static void anal_UNPACK_LIST (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, oparg - 1);
}
static void anal_UNPACK_SEQUENCE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, oparg - 1);
}
static void anal_UNPACK_TUPLE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, oparg - 1);
}
static void anal_UNPACK_VARARG (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// https://github.com/python/cpython/blob/v1.4b3/Include/opcode.h
// I can not find this opcode even in v1.4 version source code.
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_WITH_CLEANUP (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// Need the value on stack
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_WITH_CLEANUP_FINISH (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 2);
}
static void anal_WITH_CLEANUP_START (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
// Need the value on stack
op->type = R_ANAL_OP_TYPE_UNK;
}
static void anal_WITH_EXCEPT_START (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_push (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_YIELD_FROM (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static void anal_YIELD_VALUE (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
anal_pop (op, op_obj, oparg, R_ANAL_OP_TYPE_UNK, 1);
}
static op_anal_func op_anal[] = {
{ "BEFORE_ASYNC_WITH", anal_BEFORE_ASYNC_WITH },
{ "BEGIN_FINALLY", anal_BEGIN_FINALLY },
{ "BINARY_ADD", anal_BINARY_ADD },
{ "BINARY_AND", anal_BINARY_AND },
{ "BINARY_CALL", anal_BINARY_CALL },
{ "BINARY_DIVIDE", anal_BINARY_DIVIDE },
{ "BINARY_FLOOR_DIVIDE", anal_BINARY_FLOOR_DIVIDE },
{ "BINARY_LSHIFT", anal_BINARY_LSHIFT },
{ "BINARY_MATRIX_MULTIPLY", anal_BINARY_MATRIX_MULTIPLY },
{ "BINARY_MODULO", anal_BINARY_MODULO },
{ "BINARY_MULTIPLY", anal_BINARY_MULTIPLY },
{ "BINARY_OR", anal_BINARY_OR },
{ "BINARY_POWER", anal_BINARY_POWER },
{ "BINARY_RSHIFT", anal_BINARY_RSHIFT },
{ "BINARY_SUBSCR", anal_BINARY_SUBSCR },
{ "BINARY_SUBTRACT", anal_BINARY_SUBTRACT },
{ "BINARY_TRUE_DIVIDE", anal_BINARY_TRUE_DIVIDE },
{ "BINARY_XOR", anal_BINARY_XOR },
{ "BREAK_LOOP", anal_BREAK_LOOP },
{ "BUILD_CLASS", anal_BUILD_CLASS },
{ "BUILD_CONST_KEY_MAP", anal_BUILD_CONST_KEY_MAP },
{ "BUILD_FUNCTION", anal_BUILD_FUNCTION },
{ "BUILD_LIST", anal_BUILD_LIST },
{ "BUILD_LIST_UNPACK", anal_BUILD_LIST_UNPACK },
{ "BUILD_MAP", anal_BUILD_MAP },
{ "BUILD_MAP_UNPACK", anal_BUILD_MAP_UNPACK },
{ "BUILD_MAP_UNPACK_WITH_CALL", anal_BUILD_MAP_UNPACK_WITH_CALL },
{ "BUILD_SET", anal_BUILD_SET },
{ "BUILD_SET_UNPACK", anal_BUILD_SET_UNPACK },
{ "BUILD_SLICE", anal_BUILD_SLICE },
{ "BUILD_STRING", anal_BUILD_STRING },
{ "BUILD_TUPLE", anal_BUILD_TUPLE },
{ "BUILD_TUPLE_UNPACK", anal_BUILD_TUPLE_UNPACK },
{ "BUILD_TUPLE_UNPACK_WITH_CALL", anal_BUILD_TUPLE_UNPACK_WITH_CALL },
{ "CALL_FUNCTION", anal_CALL_FUNCTION },
{ "CALL_FUNCTION_EX", anal_CALL_FUNCTION_EX },
{ "CALL_FUNCTION_KW", anal_CALL_FUNCTION_KW },
{ "CALL_FUNCTION_VAR", anal_CALL_FUNCTION_VAR },
{ "CALL_FUNCTION_VAR_KW", anal_CALL_FUNCTION_VAR_KW },
{ "CALL_METHOD", anal_CALL_METHOD },
{ "DELETE_ATTR", anal_DELETE_ATTR },
{ "DELETE_DEREF", anal_DELETE_DEREF },
{ "DELETE_FAST", anal_DELETE_FAST },
{ "DELETE_GLOBAL", anal_DELETE_GLOBAL },
{ "DELETE_NAME", anal_DELETE_NAME },
{ "DELETE_SLICE_0", anal_DELETE_SLICE_0 },
{ "DELETE_SLICE_1", anal_DELETE_SLICE_1 },
{ "DELETE_SLICE_2", anal_DELETE_SLICE_2 },
{ "DELETE_SLICE_3", anal_DELETE_SLICE_3 },
{ "DELETE_SUBSCR", anal_DELETE_SUBSCR },
{ "DUP_TOP", anal_DUP_TOP },
{ "DUP_TOPX", anal_DUP_TOPX },
{ "DUP_TOP_TWO", anal_DUP_TOP_TWO },
{ "END_ASYNC_FOR", anal_END_ASYNC_FOR },
{ "END_FINALLY", anal_END_FINALLY },
{ "EXEC_STMT", anal_EXEC_STMT },
{ "EXTENDED_ARG", anal_EXTENDED_ARG },
{ "FORMAT_VALUE", anal_FORMAT_VALUE },
{ "FOR_LOOP", anal_FOR_LOOP },
{ "GET_AITER", anal_GET_AITER },
{ "GET_ANEXT", anal_GET_ANEXT },
{ "GET_AWAITABLE", anal_GET_AWAITABLE },
{ "GET_ITER", anal_GET_ITER },
{ "GET_YIELD_FROM_ITER", anal_GET_YIELD_FROM_ITER },
{ "IMPORT_FROM", anal_IMPORT_FROM },
{ "IMPORT_NAME", anal_IMPORT_NAME },
{ "IMPORT_STAR", anal_IMPORT_STAR },
{ "INPLACE_ADD", anal_INPLACE_ADD },
{ "INPLACE_AND", anal_INPLACE_AND },
{ "INPLACE_DIVIDE", anal_INPLACE_DIVIDE },
{ "INPLACE_FLOOR_DIVIDE", anal_INPLACE_FLOOR_DIVIDE },
{ "INPLACE_LSHIFT", anal_INPLACE_LSHIFT },
{ "INPLACE_MATRIX_MULTIPLY", anal_INPLACE_MATRIX_MULTIPLY },
{ "INPLACE_MODULO", anal_INPLACE_MODULO },
{ "INPLACE_MULTIPLY", anal_INPLACE_MULTIPLY },
{ "INPLACE_OR", anal_INPLACE_OR },
{ "INPLACE_POWER", anal_INPLACE_POWER },
{ "INPLACE_RSHIFT", anal_INPLACE_RSHIFT },
{ "INPLACE_SUBTRACT", anal_INPLACE_SUBTRACT },
{ "INPLACE_TRUE_DIVIDE", anal_INPLACE_TRUE_DIVIDE },
{ "INPLACE_XOR", anal_INPLACE_XOR },
{ "LIST_APPEND", anal_LIST_APPEND },
{ "LOAD_ASSERTION_ERROR", anal_LOAD_ASSERTION_ERROR },
{ "LOAD_ATTR", anal_LOAD_ATTR },
{ "LOAD_BUILD_CLASS", anal_LOAD_BUILD_CLASS },
{ "LOAD_CLASSDEREF", anal_LOAD_CLASSDEREF },
{ "LOAD_CLOSURE", anal_LOAD_CLOSURE },
{ "LOAD_CONST", anal_LOAD_CONST },
{ "LOAD_DEREF", anal_LOAD_DEREF },
{ "LOAD_FAST", anal_LOAD_FAST },
{ "LOAD_GLOBAL", anal_LOAD_GLOBAL },
{ "LOAD_GLOBALS", anal_LOAD_GLOBALS },
{ "LOAD_LOCAL", anal_LOAD_LOCAL },
{ "LOAD_LOCALS", anal_LOAD_LOCALS },
{ "LOAD_METHOD", anal_LOAD_METHOD },
{ "LOAD_NAME", anal_LOAD_NAME },
{ "MAKE_CLOSURE", anal_MAKE_CLOSURE },
{ "MAKE_FUNCTION", anal_MAKE_FUNCTION },
{ "MAP_ADD", anal_MAP_ADD },
{ "NOP", anal_NOP },
{ "POP_BLOCK", anal_POP_BLOCK },
{ "POP_EXCEPT", anal_POP_EXCEPT },
{ "POP_FINALLY", anal_POP_FINALLY },
{ "POP_TOP", anal_POP_TOP },
{ "PRINT_EXPR", anal_PRINT_EXPR },
{ "PRINT_ITEM", anal_PRINT_ITEM },
{ "PRINT_ITEM_TO", anal_PRINT_ITEM_TO },
{ "PRINT_NEWLINE", anal_PRINT_NEWLINE },
{ "PRINT_NEWLINE_TO", anal_PRINT_NEWLINE_TO },
{ "RAISE_EXCEPTION", anal_RAISE_EXCEPTION },
{ "RAISE_VARARGS", anal_RAISE_VARARGS },
{ "RERAISE", anal_RERAISE },
{ "RESERVE_FAST", anal_RESERVE_FAST },
{ "RETURN_VALUE", anal_RETURN_VALUE },
{ "ROT_FOUR", anal_ROT_FOUR },
{ "ROT_THREE", anal_ROT_THREE },
{ "ROT_TWO", anal_ROT_TWO },
{ "SETUP_ANNOTATIONS", anal_SETUP_ANNOTATIONS },
{ "SET_ADD", anal_SET_ADD },
{ "SET_FUNC_ARGS", anal_SET_FUNC_ARGS },
{ "SET_LINENO", anal_SET_LINENO },
{ "SLICE_0", anal_SLICE_0 },
{ "SLICE_1", anal_SLICE_1 },
{ "SLICE_2", anal_SLICE_2 },
{ "SLICE_3", anal_SLICE_3 },
{ "STOP_CODE", anal_STOP_CODE },
{ "STORE_ANNOTATION", anal_STORE_ANNOTATION },
{ "STORE_ATTR", anal_STORE_ATTR },
{ "STORE_DEREF", anal_STORE_DEREF },
{ "STORE_FAST", anal_STORE_FAST },
{ "STORE_GLOBAL", anal_STORE_GLOBAL },
{ "STORE_LOCALS", anal_STORE_LOCALS },
{ "STORE_MAP", anal_STORE_MAP },
{ "STORE_NAME", anal_STORE_NAME },
{ "STORE_SLICE_0", anal_STORE_SLICE_0 },
{ "STORE_SLICE_1", anal_STORE_SLICE_1 },
{ "STORE_SLICE_2", anal_STORE_SLICE_2 },
{ "STORE_SLICE_3", anal_STORE_SLICE_3 },
{ "STORE_SUBSCR", anal_STORE_SUBSCR },
{ "UNARY_CALL", anal_UNARY_CALL },
{ "UNARY_CONVERT", anal_UNARY_CONVERT },
{ "UNARY_INVERT", anal_UNARY_INVERT },
{ "UNARY_NEGATIVE", anal_UNARY_NEGATIVE },
{ "UNARY_NOT", anal_UNARY_NOT },
{ "UNARY_POSITIVE", anal_UNARY_POSITIVE },
{ "UNPACK_ARG", anal_UNPACK_ARG },
{ "UNPACK_EX", anal_UNPACK_EX },
{ "UNPACK_LIST", anal_UNPACK_LIST },
{ "UNPACK_SEQUENCE", anal_UNPACK_SEQUENCE },
{ "UNPACK_TUPLE", anal_UNPACK_TUPLE },
{ "UNPACK_VARARG", anal_UNPACK_VARARG },
{ "WITH_CLEANUP", anal_WITH_CLEANUP },
{ "WITH_CLEANUP_FINISH", anal_WITH_CLEANUP_FINISH },
{ "WITH_CLEANUP_START", anal_WITH_CLEANUP_START },
{ "WITH_EXCEPT_START", anal_WITH_EXCEPT_START },
{ "YIELD_FROM", anal_YIELD_FROM },
{ "YIELD_VALUE", anal_YIELD_VALUE },
};
void anal_pyc_op (RAnalOp *op, pyc_opcode_object *op_obj, ut32 oparg) {
for (ut32 i = 0; i < (sizeof (op_anal) / sizeof (op_anal_func)); i++) {
if (!strcmp (op_anal[i].op_name, op_obj->op_name)) {
op_anal[i].func (op, op_obj, oparg);
break;
}
}
}
+69
View File
@@ -0,0 +1,69 @@
#include "opcode.h"
const char *format_extended_arg (ut32 oparg) {
return r_str_newf ("%llu", oparg * (1 << 16));
}
const char *format_CALL_FUNCTION_pos_name_encoded (ut32 oparg) {
ut32 pos_args = oparg & 0xFF;
ut32 name = (oparg >> 8) & 0xFF;
return r_str_newf ("%u positional, %u named", pos_args, name);
}
const char *format_MAKE_FUNCTION_arg_3x (ut32 oparg) {
ut32 pos_args = oparg & 0xFF;
ut32 name_default = (oparg >> 8) & 0xFF;
ut32 annotate_args = (oparg >> 16) & 0x7FFF;
return r_str_newf ("%u positional, %u name and default, %u annotations", pos_args, name_default, annotate_args);
}
const char *format_CALL_FUNCTION_KW_36 (ut32 oparg) {
return r_str_newf ("%u total positional and keyword args", oparg);
}
const char *format_CALL_FUNCTION_EX_36 (ut32 oparg) {
return (oparg & 0x01) ? "keyword args" : "";
}
static const char *MAKE_FUNCTION_FLAGS[] = { "default", "keyword-only", "annotation", "closure" };
const char *format_MAKE_FUNCTION_arg_36 (ut32 oparg) {
char *ret = r_str_new (" ");
for (unsigned i = 0; i < sizeof (MAKE_FUNCTION_FLAGS) / sizeof (char *); ++i) {
if (oparg & 0x1)
r_str_appendf (ret, ", %s", MAKE_FUNCTION_FLAGS[i]);
else {
free (ret);
ret = r_str_new (MAKE_FUNCTION_FLAGS[i]);
}
oparg >>= 1;
}
return ret;
}
const char *format_value_flags_36 (ut32 oparg) {
const char *ret = "";
switch (oparg & 0x3) {
case 0:
ret = "";
break;
case 1:
ret = "!s";
break;
case 2:
ret = "!r";
break;
case 3:
ret = "!a";
break;
}
if ((oparg & 0x4) == 0x4)
// pop fmt_spec from the stack and use it, else use an
// empty fmt_spec.
return "";
return ret;
}
const char *format_extended_arg_36 (ut32 oparg) {
return r_str_newf ("%llu", oparg * (1 << 8));
}
+217
View File
@@ -0,0 +1,217 @@
/* radare - LGPL3 - Copyright 2016-2020 - c0riolis, x0urc3 */
#include "pyc_dis.h"
static const char *cmp_op[] = {"<", "<=", "==", "!=", ">", ">=", "in", "not in", "is", "is not", "exception match", "BAD"};
int r_pyc_disasm (RAsmOp *opstruct, const ut8 *code, RList *cobjs, RList *interned_table, ut64 pc, pyc_opcodes *ops) {
pyc_code_object *cobj = NULL, *t = NULL;
ut32 extended_arg = 0, i = 0, oparg;
st64 start_offset, end_offset;
RListIter *iter = NULL;
char *name = NULL;
char *arg = NULL;
RList *varnames;
RList *consts;
RList *names;
RList *freevars;
RList *cellvars;
ut8 op;
r_list_foreach (cobjs, iter, t) {
start_offset = t->start_offset;
end_offset = t->end_offset;
if (start_offset <= pc && pc < end_offset) { // pc in [start_offset, end_offset)
cobj = t;
break;
}
}
if (cobj != NULL) {
/* TODO: adding line number and offset */
varnames = cobj->varnames->data;
consts = cobj->consts->data;
names = cobj->names->data;
freevars = cobj->freevars->data;
cellvars = cobj->cellvars->data;
op = code[i];
i += 1;
name = ops->opcodes[op].op_name;
r_strbuf_set (&opstruct->buf_asm, name);
if (name == NULL) {
return 0;
}
if (op >= ops->have_argument) {
if (ops->bits == 16) {
oparg = code[i] + code[i + 1] * 256 + extended_arg;
i += 2;
} else {
oparg = code[i] + extended_arg;
i += 1;
}
extended_arg = 0;
if (op == ops->extended_arg) {
if (ops->bits == 16) {
extended_arg = oparg * 65536;
} else {
extended_arg = oparg << 8;
}
}
arg = parse_arg (&ops->opcodes[op], oparg, names, consts, varnames, interned_table, freevars, cellvars, ops->opcode_arg_fmt);
if (arg != NULL) {
r_strbuf_appendf (&opstruct->buf_asm, "%20s", arg);
}
} else if (ops->bits == 8) {
i += 1;
}
return i;
}
return 0;
}
char *parse_arg (pyc_opcode_object *op, ut32 oparg, RList *names, RList *consts, RList *varnames, RList *interned_table, RList *freevars, RList *cellvars, RList *opcode_arg_fmt) {
pyc_object *t = NULL;
char *arg = NULL;
pyc_code_object *tmp_cobj;
pyc_arg_fmt *fmt;
RListIter *i = NULL;
// version-specific formatter for certain opcodes
r_list_foreach (opcode_arg_fmt, i, fmt)
if (!strcmp (fmt->op_name, op->op_name)) {
return fmt->formatter (oparg);
}
if (op->type & HASCONST) {
t = (pyc_object *)r_list_get_n (consts, oparg);
if (t == NULL) {
return NULL;
}
switch (t->type) {
case TYPE_CODE_v0:
case TYPE_CODE_v1:
tmp_cobj = t->data;
arg = r_str_newf ("CodeObject(%s) from %s", tmp_cobj->name->data, tmp_cobj->filename->data);
break;
case TYPE_TUPLE:
case TYPE_SET:
case TYPE_FROZENSET:
case TYPE_LIST:
case TYPE_SMALL_TUPLE:
arg = generic_array_obj_to_string (t->data);
break;
case TYPE_STRING:
case TYPE_INTERNED:
case TYPE_STRINGREF:
arg = r_str_newf ("'%s'", t->data);
default:
arg = t->data;
}
}
if (op->type & HASNAME) {
t = (pyc_object *)r_list_get_n (names, oparg);
if (t == NULL) {
return NULL;
}
arg = t->data;
}
if ((op->type & HASJREL) || (op->type & HASJABS)) {
arg = r_str_newf ("%u", oparg);
}
if (op->type & HASLOCAL) {
t = (pyc_object *)r_list_get_n (varnames, oparg);
if (t == NULL)
return NULL;
arg = t->data;
}
if (op->type & HASCOMPARE) {
arg = cmp_op[oparg];
}
if (op->type & HASFREE) {
if (!cellvars || !freevars) {
arg = r_str_newf ("%u", oparg);
}
if (oparg < r_list_length (cellvars)) {
t = (pyc_object*)r_list_get_n (cellvars, oparg);
} else if ((oparg - r_list_length (cellvars)) < r_list_length(freevars)) {
t = (pyc_object*)r_list_get_n (freevars, oparg);
} else
arg = r_str_newf ("%u", oparg);
if (t == NULL) {
return NULL;
}
arg = t->data;
}
if (op->type & HASNARGS) {
arg = r_str_newf ("%u", oparg);
}
if (op->type & HASVARGS) {
arg = r_str_newf ("%u", oparg);
}
return arg;
}
/* for debugging purpose */
void dump (RList *l) {
RListIter *it;
pyc_object *e = NULL;
r_list_foreach (l, it, e) {
if (e->type == TYPE_TUPLE) {
eprintf ("[TYPE_TUPLE] %s\n", generic_array_obj_to_string(e->data));
return;
}
eprintf("[DATA] %s\n", (char *)e->data);
}
}
char *generic_array_obj_to_string (RList *l) {
RListIter *iter = NULL;
pyc_object *e = NULL;
ut32 size = 256, used = 0;
char *r = NULL, *buf = NULL;
// add good enough space
buf = (char*)calloc (size+10, 1);
r_list_foreach (l, iter, e) {
while ( !(strlen (e->data) < size) ) {
size *= 2;
buf = realloc (buf, used + size);
if (!buf) {
eprintf ("generic_array_obj_to_string cannot request more memory");
return NULL;
}
}
strcat (buf, e->data);
strcat (buf, ",");
size -= strlen (e->data) + 1;
used += strlen (e->data) + 1;
}
/* remove last , */
buf[ strlen(buf)-1 ] = '\0';
r = r_str_newf ("(%s)", buf);
free(buf);
return r;
}
void dump_cobj (pyc_code_object *c) {
eprintf("[DUMP]\n");
eprintf("name: %s\n", (char *)c->name->data);
eprintf("const_start\n");
dump(c->consts->data);
eprintf("consts_end\n");
eprintf("names_start\n");
dump(c->names->data);
eprintf("names_end\n");
eprintf("varnames_start\n");
dump(c->varnames->data);
eprintf("varnames_end\n");
}
+83 -76
View File
@@ -1,76 +1,83 @@
#include <r_types.h>
#include <r_lib.h>
#include <r_util.h>
#include <r_asm.h>
#include "opcode.h"
typedef enum {
TYPE_ASCII = 'a',
TYPE_ASCII_INTERNED = 'A',
TYPE_BINARY_COMPLEX = 'y',
TYPE_BINARY_FLOAT = 'g',
TYPE_CODE_v0 = 'C',
TYPE_CODE_v1 = 'c',
TYPE_COMPLEX = 'x',
TYPE_DICT = '{',
TYPE_ELLIPSIS = '.',
TYPE_FALSE = 'F',
TYPE_FLOAT = 'f',
TYPE_FROZENSET = '>',
TYPE_INT64 = 'I',
TYPE_INTERNED = 't',
TYPE_INT = 'i',
TYPE_LIST = '[',
TYPE_LONG = 'l',
TYPE_NONE = 'N',
TYPE_NULL = '0',
TYPE_REF = 'r',
TYPE_SET = '<',
TYPE_SHORT_ASCII_INTERNED = 'Z',
TYPE_SHORT_ASCII = 'z',
TYPE_SMALL_TUPLE = ')',
TYPE_STOPITER = 'S',
TYPE_STRINGREF = 'R',
TYPE_STRING = 's',
TYPE_TRUE = 'T',
TYPE_TUPLE = '(',
TYPE_UNICODE = 'u',
TYPE_UNKNOWN = '?',
} pyc_marshal_type;
typedef enum {
FLAG_REF = '\x80',
} pyc_marshal_flag;
typedef struct {
pyc_marshal_type type;
void *data;
} pyc_object;
typedef struct {
ut32 argcount;
ut32 kwonlyargcount;
ut32 nlocals;
ut32 stacksize;
ut32 flags;
pyc_object *code;
pyc_object *consts;
pyc_object *names;
pyc_object *varnames;
pyc_object *freevars;
pyc_object *cellvars;
pyc_object *filename;
pyc_object *name;
ut32 firstlineno;
pyc_object *lnotab;
st64 start_offset;
st64 end_offset;
} pyc_code_object;
char *parse_arg (ut8 op, ut32 oparg, RList *names, RList *consts, RList *varnames, RList *interned_table);
int r_pyc_disasm (RAsmOp *op, const ut8 *buf, RList *cobjs, RList *interned_table, ut64 pc);
char *generic_array_obj_to_string (RList *l);
void dump_cobj (pyc_code_object *c);
void init_opname_table ();
void dump (RList *l);
/* radare - LGPL3 - Copyright 2016-2020 - c0riolis, x0urc3 */
#ifndef PYC_DIS_H
#define PYC_DIS_H
#include <r_types.h>
#include <r_lib.h>
#include <r_util.h>
#include <r_asm.h>
#include "opcode.h"
typedef enum {
TYPE_ASCII = 'a',
TYPE_ASCII_INTERNED = 'A',
TYPE_BINARY_COMPLEX = 'y',
TYPE_BINARY_FLOAT = 'g',
TYPE_CODE_v0 = 'C',
TYPE_CODE_v1 = 'c',
TYPE_COMPLEX = 'x',
TYPE_DICT = '{',
TYPE_ELLIPSIS = '.',
TYPE_FALSE = 'F',
TYPE_FLOAT = 'f',
TYPE_FROZENSET = '>',
TYPE_INT64 = 'I',
TYPE_INTERNED = 't',
TYPE_INT = 'i',
TYPE_LIST = '[',
TYPE_LONG = 'l',
TYPE_NONE = 'N',
TYPE_NULL = '0',
TYPE_REF = 'r',
TYPE_SET = '<',
TYPE_SHORT_ASCII_INTERNED = 'Z',
TYPE_SHORT_ASCII = 'z',
TYPE_SMALL_TUPLE = ')',
TYPE_STOPITER = 'S',
TYPE_STRINGREF = 'R',
TYPE_STRING = 's',
TYPE_TRUE = 'T',
TYPE_TUPLE = '(',
TYPE_UNICODE = 'u',
TYPE_UNKNOWN = '?',
} pyc_marshal_type;
typedef enum {
FLAG_REF = '\x80',
} pyc_marshal_flag;
typedef struct {
pyc_marshal_type type;
void *data;
} pyc_object;
typedef struct {
ut32 argcount;
ut32 posonlyargcount;
ut32 kwonlyargcount;
ut32 nlocals;
ut32 stacksize;
ut32 flags;
pyc_object *code;
pyc_object *consts;
pyc_object *names;
pyc_object *varnames;
pyc_object *freevars;
pyc_object *cellvars;
pyc_object *filename;
pyc_object *name;
ut32 firstlineno;
pyc_object *lnotab;
st64 start_offset;
st64 end_offset;
} pyc_code_object;
char *parse_arg (pyc_opcode_object *op, ut32 oparg, RList *names, RList *consts, RList *varnames, RList *interned_table, RList *freevars, RList *cellvars, RList *opcode_arg_fmt);
int r_pyc_disasm (RAsmOp *op, const ut8 *buf, RList *cobjs, RList *interned_table, ut64 pc, pyc_opcodes *opcodes);
char *generic_array_obj_to_string (RList *l);
void dump_cobj (pyc_code_object *c);
void dump (RList *l);
#endif
-307
View File
@@ -1,307 +0,0 @@
#include "pyc_dis.h"
void init_opname_table () {
int i;
for(i = 0; i < 0xff+1; i++)
op_name[i] = NULL;
op_name[STOP_CODE] = "STOP_CODE";
op_name[POP_TOP] = "POP_TOP";
op_name[ROT_TWO] = "ROT_TWO";
op_name[ROT_THREE] = "ROT_THREE";
op_name[DUP_TOP] = "DUP_TOP";
op_name[ROT_FOUR] = "ROT_FOUR";
op_name[NOP] = "NOP";
op_name[UNARY_POSITIVE] = "UNARY_POSITIVE";
op_name[UNARY_NEGATIVE] = "UNARY_NEGATIVE";
op_name[UNARY_NOT] = "UNARY_NOT";
op_name[UNARY_CONVERT] = "UNARY_CONVERT";
op_name[UNARY_INVERT] = "UNARY_INVERT";
op_name[BINARY_POWER] = "BINARY_POWER";
op_name[BINARY_MULTIPLY] = "BINARY_MULTIPLY";
op_name[BINARY_DIVIDE] = "BINARY_DIVIDE";
op_name[BINARY_MODULO] = "BINARY_MODULO";
op_name[BINARY_ADD] = "BINARY_ADD";
op_name[BINARY_SUBTRACT] = "BINARY_SUBTRACT";
op_name[BINARY_SUBSCR] = "BINARY_SUBSCR";
op_name[BINARY_FLOOR_DIVIDE] = "BINARY_FLOOR_DIVIDE";
op_name[BINARY_TRUE_DIVIDE] = "BINARY_TRUE_DIVIDE";
op_name[INPLACE_FLOOR_DIVIDE] = "INPLACE_FLOOR_DIVIDE";
op_name[INPLACE_TRUE_DIVIDE] = "INPLACE_TRUE_DIVIDE";
op_name[SLICE] = "SLICE";
op_name[SLICE_1] = "SLICE_1";
op_name[SLICE_2] = "SLICE_2";
op_name[SLICE_3] = "SLICE_3";
op_name[STORE_SLICE] = "STORE_SLICE";
op_name[STORE_SLICE_1] = "STORE_SLICE_1";
op_name[STORE_SLICE_2] = "STORE_SLICE_2";
op_name[STORE_SLICE_3] = "STORE_SLICE_3";
op_name[DELETE_SLICE] = "DELETE_SLICE";
op_name[DELETE_SLICE_1] = "DELETE_SLICE_1";
op_name[DELETE_SLICE_2] = "DELETE_SLICE_2";
op_name[DELETE_SLICE_3] = "DELETE_SLICE_3";
op_name[STORE_MAP] = "STORE_MAP";
op_name[INPLACE_ADD] = "INPLACE_ADD";
op_name[INPLACE_SUBTRACT] = "INPLACE_SUBTRACT";
op_name[INPLACE_MULTIPLY] = "INPLACE_MULTIPLY";
op_name[INPLACE_DIVIDE] = "INPLACE_DIVIDE";
op_name[INPLACE_MODULO] = "INPLACE_MODULO";
op_name[STORE_SUBSCR] = "STORE_SUBSCR";
op_name[DELETE_SUBSCR] = "DELETE_SUBSCR";
op_name[BINARY_LSHIFT] = "BINARY_LSHIFT";
op_name[BINARY_RSHIFT] = "BINARY_RSHIFT";
op_name[BINARY_AND] = "BINARY_AND";
op_name[BINARY_XOR] = "BINARY_XOR";
op_name[BINARY_OR] = "BINARY_OR";
op_name[INPLACE_POWER] = "INPLACE_POWER";
op_name[GET_ITER] = "GET_ITER";
op_name[PRINT_EXPR] = "PRINT_EXPR";
op_name[PRINT_ITEM] = "PRINT_ITEM";
op_name[PRINT_NEWLINE] = "PRINT_NEWLINE";
op_name[PRINT_ITEM_TO] = "PRINT_ITEM_TO";
op_name[PRINT_NEWLINE_TO] = "PRINT_NEWLINE_TO";
op_name[INPLACE_LSHIFT] = "INPLACE_LSHIFT";
op_name[INPLACE_RSHIFT] = "INPLACE_RSHIFT";
op_name[INPLACE_AND] = "INPLACE_AND";
op_name[INPLACE_XOR] = "INPLACE_XOR";
op_name[INPLACE_OR] = "INPLACE_OR";
op_name[BREAK_LOOP] = "BREAK_LOOP";
op_name[WITH_CLEANUP] = "WITH_CLEANUP";
op_name[LOAD_LOCALS] = "LOAD_LOCALS";
op_name[RETURN_VALUE] = "RETURN_VALUE";
op_name[IMPORT_STAR] = "IMPORT_STAR";
op_name[EXEC_STMT] = "EXEC_STMT";
op_name[YIELD_VALUE] = "YIELD_VALUE";
op_name[POP_BLOCK] = "POP_BLOCK";
op_name[END_FINALLY] = "END_FINALLY";
op_name[BUILD_CLASS] = "BUILD_CLASS";
op_name[HAVE_ARGUMENT] = "HAVE_ARGUMENT";
op_name[STORE_NAME] = "STORE_NAME";
op_name[DELETE_NAME] = "DELETE_NAME";
op_name[UNPACK_SEQUENCE] = "UNPACK_SEQUENCE";
op_name[FOR_ITER] = "FOR_ITER";
op_name[LIST_APPEND] = "LIST_APPEND";
op_name[STORE_ATTR] = "STORE_ATTR";
op_name[DELETE_ATTR] = "DELETE_ATTR";
op_name[STORE_GLOBAL] = "STORE_GLOBAL";
op_name[DELETE_GLOBAL] = "DELETE_GLOBAL";
op_name[DUP_TOPX] = "DUP_TOPX";
op_name[LOAD_CONST] = "LOAD_CONST";
op_name[LOAD_NAME] = "LOAD_NAME";
op_name[BUILD_TUPLE] = "BUILD_TUPLE";
op_name[BUILD_LIST] = "BUILD_LIST";
op_name[BUILD_SET] = "BUILD_SET";
op_name[BUILD_MAP] = "BUILD_MAP";
op_name[LOAD_ATTR] = "LOAD_ATTR";
op_name[COMPARE_OP] = "COMPARE_OP";
op_name[IMPORT_NAME] = "IMPORT_NAME";
op_name[IMPORT_FROM] = "IMPORT_FROM";
op_name[JUMP_FORWARD] = "JUMP_FORWARD";
op_name[JUMP_IF_FALSE_OR_POP] = "JUMP_IF_FALSE_OR_POP";
op_name[JUMP_IF_TRUE_OR_POP] = "JUMP_IF_TRUE_OR_POP";
op_name[JUMP_ABSOLUTE] = "JUMP_ABSOLUTE";
op_name[POP_JUMP_IF_FALSE] = "POP_JUMP_IF_FALSE";
op_name[POP_JUMP_IF_TRUE] = "POP_JUMP_IF_TRUE";
op_name[LOAD_GLOBAL] = "LOAD_GLOBAL";
op_name[CONTINUE_LOOP] = "CONTINUE_LOOP";
op_name[SETUP_LOOP] = "SETUP_LOOP";
op_name[SETUP_EXCEPT] = "SETUP_EXCEPT";
op_name[SETUP_FINALLY] = "SETUP_FINALLY";
op_name[LOAD_FAST] = "LOAD_FAST";
op_name[STORE_FAST] = "STORE_FAST";
op_name[DELETE_FAST] = "DELETE_FAST";
op_name[RAISE_VARARGS] = "RAISE_VARARGS";
op_name[CALL_FUNCTION] = "CALL_FUNCTION";
op_name[MAKE_FUNCTION] = "MAKE_FUNCTION";
op_name[BUILD_SLICE] = "BUILD_SLICE";
op_name[MAKE_CLOSURE] = "MAKE_CLOSURE";
op_name[LOAD_CLOSURE] = "LOAD_CLOSURE";
op_name[LOAD_DEREF] = "LOAD_DEREF";
op_name[STORE_DEREF] = "STORE_DEREF";
op_name[CALL_FUNCTION_VAR] = "CALL_FUNCTION_VAR";
op_name[CALL_FUNCTION_KW] = "CALL_FUNCTION_KW";
op_name[CALL_FUNCTION_VAR_KW] = "CALL_FUNCTION_VAR_KW";
op_name[SETUP_WITH] = "SETUP_WITH";
op_name[EXTENDED_ARG] = "EXTENDED_ARG";
op_name[SET_ADD] = "SET_ADD";
op_name[MAP_ADD] = "MAP_ADD";
}
int r_pyc_disasm (RAsmOp *opstruct, const ut8 *code, RList *cobjs, RList *interned_table, ut64 pc) {
pyc_code_object *cobj = NULL, *t = NULL;
ut32 extended_arg = 0, i = 0, oparg;
st64 start_offset, end_offset;
RListIter *iter = NULL;
char *name = NULL;
char *arg = NULL;
RList *varnames;
RList *consts;
RList *names;
ut8 op;
r_list_foreach (cobjs, iter, t) {
start_offset = t->start_offset;
end_offset = t->end_offset;
if (pc > start_offset && pc < end_offset) {
cobj = t;
break;
}
}
if (cobj != NULL) {
/* TODO: adding line number and offset */
varnames = cobj->varnames->data;
consts = cobj->consts->data;
names = cobj->names->data;
op = code[i];
i += 1;
name = op_name[op];
r_strbuf_set (&opstruct->buf_asm, name);
if (name == NULL) {
return 0;
}
if (op >= HAVE_ARGUMENT) {
oparg = code[i] + code[i+1]*256 + extended_arg;
extended_arg = 0;
i += 2;
if (op == EXTENDED_ARG)
extended_arg = oparg*65536;
arg = parse_arg (op, oparg, names, consts, varnames, interned_table);
if (arg != NULL) {
r_strbuf_appendf (&opstruct->buf_asm, "%20s", arg);
}
}
return i;
}
return 0;
}
char *parse_arg (ut8 op, ut32 oparg, RList *names, RList *consts, RList *varnames, RList *interned_table) {
pyc_object *t = NULL;
char *arg = NULL;
switch (op) {
case DUP_TOPX:
case UNPACK_SEQUENCE:
case BUILD_TUPLE:
case BUILD_LIST: //checked
case BUILD_SET:
case JUMP_FORWARD:
case CONTINUE_LOOP:
case SETUP_LOOP:
case BUILD_SLICE:
case CALL_FUNCTION:
case POP_JUMP_IF_FALSE:
case POP_JUMP_IF_TRUE:
case JUMP_ABSOLUTE:
case JUMP_IF_TRUE_OR_POP:
case JUMP_IF_FALSE_OR_POP:
case LOAD_CLOSURE:
case LOAD_DEREF:
case CALL_FUNCTION_KW:
arg = r_str_newf ("%u", oparg);
break;
case LOAD_FAST:
case STORE_FAST:
case DELETE_FAST:
t = (pyc_object*)r_list_get_n (varnames, oparg);
if (t == NULL)
return NULL;
arg = t->data;
break;
case LOAD_CONST:
t = (pyc_object*)r_list_get_n (consts, oparg);
if (t == NULL)
return NULL;
switch (t->type) {
case TYPE_CODE_v1:
arg = strdup("CodeObject");
break;
case TYPE_TUPLE:
arg = generic_array_obj_to_string (t->data);
break;
case TYPE_STRING:
case TYPE_INTERNED:
case TYPE_STRINGREF:
arg = r_str_newf ("'%s'", t->data);
break;
default:
arg = t->data;
}
break;
case STORE_NAME:
case STORE_ATTR:
case LOAD_NAME:
case LOAD_ATTR:
case IMPORT_NAME:
case IMPORT_FROM:
case LOAD_GLOBAL:
t = (pyc_object*)r_list_get_n (names, oparg);
if (t == NULL)
return NULL;
arg = t->data;
break;
}
return arg;
}
/* for debugging purpose */
void dump (RList *l) {
RListIter *it;
pyc_object *e = NULL;
r_list_foreach (l, it, e) {
if (e->type == TYPE_TUPLE) {
eprintf ("[TYPE_TUPLE] %s\n", generic_array_obj_to_string(e->data));
return;
}
eprintf("[DATA] %s\n", (char *)e->data);
}
}
char *generic_array_obj_to_string (RList *l) {
RListIter *iter = NULL;
pyc_object *e = NULL;
ut32 size = 256, used = 0;
char *r = NULL, *buf = NULL;
buf = (char*)calloc (1024, 0);
r_list_foreach (l, iter, e) {
while ( !(strlen (e->data) < size) ) {
size *= 2;
buf = realloc (buf, used + size);
if (!buf) {
eprintf ("generic_array_obj_to_string cannot request more memory");
return NULL;
}
}
strcat (buf, e->data);
strcat (buf, ",");
size -= strlen (e->data) + 1;
used += strlen (e->data) + 1;
}
/* remove last , */
buf[ strlen(buf)-1 ] = '\0';
r = r_str_newf ("(%s)", buf);
free(buf);
return r;
}
void dump_cobj (pyc_code_object *c) {
eprintf("[DUMP]\n");
eprintf("name: %s\n", (char *)c->name->data);
eprintf("const_start\n");
dump(c->consts->data);
eprintf("consts_end\n");
eprintf("names_start\n");
dump(c->names->data);
eprintf("names_end\n");
eprintf("varnames_start\n");
dump(c->varnames->data);
eprintf("varnames_end\n");
}
+95 -53
View File
@@ -1,53 +1,95 @@
#include <r_types.h>
#include <r_lib.h>
#include <r_util.h>
#include <r_asm.h>
#include "pyc_dis.h"
static int disassemble (RAsm *a, RAsmOp *opstruct, const ut8 *buf, int len) {
RList *interned_table = NULL;
RList *shared = NULL;
RList *cobjs = NULL;
RBin *bin = a->binb.bin;
ut64 pc = a->pc;
RBinPlugin *plugin = bin && bin->cur && bin->cur->o ?
bin->cur->o->plugin : NULL;
if (plugin) {
if (!strcmp (plugin->name, "pyc")) {
shared = bin->cur->o->bin_obj;
}
}
cobjs = r_list_get_n (shared, 0);
interned_table = r_list_get_n (shared, 1);
int r = r_pyc_disasm (opstruct, buf, cobjs, interned_table, pc);
opstruct->size = r;
return r;
}
static bool init (void *user) {
init_opname_table ();
return true;
}
RAsmPlugin r_asm_plugin_pyc = {
.name = "pyc",
.arch = "pyc",
.license = "LGPL3",
.bits = 32,
.desc = "PYC disassemble plugin",
.disassemble = &disassemble,
.init = &init,
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_pyc,
.version = R2_VERSION
};
#endif
/* radare - LGPL3 - Copyright 2016-2020 - c0riolis, x0urc3 */
#include <r_types.h>
#include <r_lib.h>
#include <r_util.h>
#include <r_asm.h>
#include "pyc_dis.h"
#include "opcode.h"
static pyc_opcodes *opcodes_cache = NULL;
static int disassemble(RAsm *a, RAsmOp *opstruct, const ut8 *buf, int len) {
RList *interned_table = NULL;
RList *shared = NULL;
RList *cobjs = NULL;
RBin *bin = a->binb.bin;
ut64 pc = a->pc;
RBinPlugin *plugin = bin && bin->cur && bin->cur->o? bin->cur->o->plugin: NULL;
if (plugin) {
if (!strcmp (plugin->name, "pyc")) {
shared = bin->cur->o->bin_obj;
}
}
cobjs = r_list_get_n (shared, 0);
interned_table = r_list_get_n (shared, 1);
if (!opcodes_cache || !pyc_opcodes_equal (opcodes_cache, a->cpu)) {
opcodes_cache = get_opcode_by_version (a->cpu);
opcodes_cache->bits = a->bits;
}
int r = r_pyc_disasm (opstruct, buf, cobjs, interned_table, pc, opcodes_cache);
opstruct->size = r;
return r;
}
void finish () {
if (opcodes_cache) {
free_opcode (opcodes_cache);
opcodes_cache = NULL;
}
}
/*
static int dis(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
const char *buf_asm = "invalid";
int size = -1;
if (op_name[buf[0]]) {
if (HAS_ARG(buf[0])) {
if (a->bits == 16) {
ut16 operand = (buf[2] << 8) | buf[1];
buf_asm = sdb_fmt ("%s %d",op_name[buf[0]], operand);
size = 3; // < 3.6
} else {
buf_asm = sdb_fmt ("%s %d",op_name[buf[0]], buf[1]);
size = 2; // >= 3.6
}
} else {
buf_asm = sdb_fmt (op_name[buf[0]]);
if (buf[1] == STOP_CODE) {
size = 2;
} else {
size = 1;
}
}
}
// eprintf("kmbs: f:%s\tbuf_asm:%s\n",__func__,buf_asm);
r_strbuf_set (&op->buf_asm, buf_asm);
op->size = size;
return size;
}
*/
RAsmPlugin r_asm_plugin_pyc = {
.name = "pyc",
.arch = "pyc",
.license = "LGPL3",
.bits = 16 | 8,
.desc = "PYC disassemble plugin",
.disassemble = &disassemble,
.fini = &finish,
};
#ifndef R2_PLUGIN_INCORE
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_pyc,
.version = R2_VERSION
};
#endif
+4 -1
View File
@@ -13,7 +13,10 @@ static int disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
obj = bin->cur->o;
int dlen = r_asm_swf_disass (obj, op->buf_asm, buf, len, a->pc);
char res[1024];
res[0] = 0;
int dlen = r_asm_swf_disass (obj, res, buf, len, a->pc);
r_strbuf_set (&op->buf_asm, res);
op->size = dlen;
return dlen;
}
+4 -1
View File
@@ -20,7 +20,10 @@ static int disassemble(RAsm *a, RAsmOp *aop, const ut8 *buf, int len) {
ZydisStatus st = ZydisDecoderDecodeInstruction (&decr, buf, len, a->pc, &info);
if (ZYDIS_SUCCESS (st)) {
ZydisFormatterInitInstructionFormatter (&fmtr, ZYDIS_FORMATTER_STYLE_INTEL);
ZydisFormatterFormatInstruction (&fmtr, &info, aop->buf_asm, R_ASM_BUFSIZE);
char str[128];
str[0] = 0;
ZydisFormatterFormatInstruction (&fmtr, &info, str, sizeof (str));
r_strbuf_set (&aop->buf_asm, str);
}
return aop->size = info.length;
+5 -3
View File
@@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2012-2013 - pancake */
/* radare - LGPL - Copyright 2012-2020 - pancake */
#include <r_types.h>
#include <r_util.h>
@@ -7,7 +7,9 @@
#include "../arch/z80_nc/disasm.c"
static int do_disassemble(RAsm *a, RAsmOp *op, const ut8 *buf, int len) {
int dlen = z80dis (0, buf, op->buf_asm, len);
char str[128];
int dlen = z80dis (0, buf, str, len);
r_strbuf_set (&op->buf_asm, str);
if (dlen<0) dlen = 0;
op->size = dlen;
return op->size;
@@ -24,7 +26,7 @@ RAsmPlugin r_asm_plugin_z80 = {
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
RLibStruct radare_plugin = {
.type = R_LIB_TYPE_ASM,
.data = &r_asm_plugin_z80,
.version = R2_VERSION
+31 -1
View File
@@ -1,5 +1,35 @@
OBJ_PYC=asm_pyc.o
OBJ_PYC+=../arch/pyc/pyc_disasm.o
OBJ_PYC+=../arch/pyc/opcode_10.o
OBJ_PYC+=../arch/pyc/opcode_11.o
OBJ_PYC+=../arch/pyc/opcode_12.o
OBJ_PYC+=../arch/pyc/opcode_13.o
OBJ_PYC+=../arch/pyc/opcode_14.o
OBJ_PYC+=../arch/pyc/opcode_15.o
OBJ_PYC+=../arch/pyc/opcode_16.o
OBJ_PYC+=../arch/pyc/opcode_20.o
OBJ_PYC+=../arch/pyc/opcode_21.o
OBJ_PYC+=../arch/pyc/opcode_22.o
OBJ_PYC+=../arch/pyc/opcode_23.o
OBJ_PYC+=../arch/pyc/opcode_24.o
OBJ_PYC+=../arch/pyc/opcode_25.o
OBJ_PYC+=../arch/pyc/opcode_26.o
OBJ_PYC+=../arch/pyc/opcode_27.o
OBJ_PYC+=../arch/pyc/opcode_2x.o
OBJ_PYC+=../arch/pyc/opcode_30.o
OBJ_PYC+=../arch/pyc/opcode_31.o
OBJ_PYC+=../arch/pyc/opcode_32.o
OBJ_PYC+=../arch/pyc/opcode_33.o
OBJ_PYC+=../arch/pyc/opcode_34.o
OBJ_PYC+=../arch/pyc/opcode_35.o
OBJ_PYC+=../arch/pyc/opcode_36.o
OBJ_PYC+=../arch/pyc/opcode_37.o
OBJ_PYC+=../arch/pyc/opcode_38.o
OBJ_PYC+=../arch/pyc/opcode_39.o
OBJ_PYC+=../arch/pyc/opcode_3x.o
OBJ_PYC+=../arch/pyc/opcode_arg_fmt.o
OBJ_PYC+=../arch/pyc/opcode_anal.o
OBJ_PYC+=../arch/pyc/opcode.o
OBJ_PYC+=../arch/pyc/pyc_dis.o
STATIC_OBJ+=${OBJ_PYC}
TARGET_PYC=asm_pyc.$(LIBEXT)
+1 -1
View File
@@ -14,4 +14,4 @@ ALL_TARGETS+=${TARGET_X86_ZYAN}
CFLAGS+=-I../arch/x86/zyan/include
${TARGET_X86_ZYAN}: ${OBJ_X86_ZYAN}
${CC} ${CFLAGS} -o ${TARGET_X86_ZYAN} ${OBJ_X86_ZYAN}
${CC} ${LDFLAGS} ${CFLAGS} -o ${TARGET_X86_ZYAN} ${OBJ_X86_ZYAN}
+559
View File
@@ -0,0 +1,559 @@
/*
Big number library - arithmetic on multiple-precision unsigned integers.
This library is an implementation of arithmetic on arbitrarily large integers.
The difference between this and other implementations, is that the data structure
has optimal memory utilization (i.e. a 1024 bit integer takes up 128 bytes RAM),
and all memory is allocated statically: no dynamic allocation for better or worse.
Primary goals are correctness, clarity of code and clean, portable implementation.
Secondary goal is a memory footprint small enough to make it suitable for use in
embedded applications.
The current state is correct functionality and adequate performance.
There may well be room for performance-optimizations and improvements.
*/
#include <stdio.h>
#include <stdbool.h>
#include <assert.h>
#include "bn.h"
/* Functions for shifting number in-place. */
static void _lshift_one_bit (struct bn *a);
static void _rshift_one_bit (struct bn *a);
static void _lshift_word (struct bn *a, int nwords);
static void _rshift_word (struct bn *a, int nwords);
/* Public / Exported functions. */
void bignum_init (struct bn *n) {
require (n, "n is null");
int i;
for (i = 0; i < BN_ARRAY_SIZE; ++i) {
n->array[i] = 0;
}
}
void bignum_from_int (struct bn *n, DTYPE_TMP i) {
require (n, "n is null");
bignum_init (n);
/* Endianness issue if machine is not little-endian? */
#ifdef WORD_SIZE
#if (WORD_SIZE == 1)
n->array[0] = (i & 0x000000ff);
n->array[1] = (i & 0x0000ff00) >> 8;
n->array[2] = (i & 0x00ff0000) >> 16;
n->array[3] = (i & 0xff000000) >> 24;
#elif (WORD_SIZE == 2)
n->array[0] = (i & 0x0000ffff);
n->array[1] = (i & 0xffff0000) >> 16;
#elif (WORD_SIZE == 4)
n->array[0] = i;
DTYPE_TMP num_32 = 32;
DTYPE_TMP tmp = i >> num_32; /* bit-shift with U64 operands to force 64-bit results */
n->array[1] = tmp;
#endif
#endif
}
int bignum_to_int (struct bn *n) {
require (n, "n is null");
int ret = 0;
/* Endianness issue if machine is not little-endian? */
#if (WORD_SIZE == 1)
ret += n->array[0];
ret += n->array[1] << 8;
ret += n->array[2] << 16;
ret += n->array[3] << 24;
#elif (WORD_SIZE == 2)
ret += n->array[0];
ret += n->array[1] << 16;
#elif (WORD_SIZE == 4)
ret += n->array[0];
#endif
return ret;
}
void bignum_from_string (struct bn *n, char *str, int nbytes) {
require (n, "n is null");
require (str, "str is null");
require (nbytes > 0, "nbytes must be positive");
require ((nbytes & 1) == 0, "string format must be in hex -> equal number of bytes");
require ((nbytes % (sizeof (DTYPE) * 2)) == 0, "string length must be a multiple of (sizeof(DTYPE) * 2) characters");
bignum_init (n);
DTYPE tmp; /* DTYPE is defined in bn.h - uint{8,16,32,64}_t */
int i = nbytes - (2 * WORD_SIZE); /* index into string */
int j = 0; /* index into array */
/* reading last hex-byte "MSB" from string first -> big endian */
/* MSB ~= most significant byte / block ? :) */
while (i >= 0) {
tmp = 0;
sscanf (&str[i], SSCANF_FORMAT_STR, &tmp);
n->array[j] = tmp;
i -= (2 * WORD_SIZE); /* step WORD_SIZE hex-byte(s) back in the string. */
j += 1; /* step one element forward in the array. */
}
}
void bignum_to_string (struct bn *n, char *str, int nbytes) {
require (n, "n is null");
require (str, "str is null");
require (nbytes > 0, "nbytes must be positive");
require ((nbytes & 1) == 0, "string format must be in hex -> equal number of bytes");
int j = BN_ARRAY_SIZE - 1; /* index into array - reading "MSB" first -> big-endian */
int i = 0; /* index into string representation. */
/* reading last array-element "MSB" first -> big endian */
while ((j >= 0) && (nbytes > (i + 1))) {
sprintf (&str[i], SPRINTF_FORMAT_STR, n->array[j]);
i += (2 * WORD_SIZE); /* step WORD_SIZE hex-byte(s) forward in the string. */
j -= 1; /* step one element back in the array. */
}
/* Count leading zeros: */
j = 0;
while (str[j] == '0') {
j += 1;
}
/* Move string j places ahead, effectively skipping leading zeros */
for (i = 0; i < (nbytes - j); ++i) {
str[i] = str[i + j];
}
/* Zero-terminate string */
str[i] = 0;
}
void bignum_dec (struct bn *n) {
require (n, "n is null");
DTYPE tmp; /* copy of n */
DTYPE res;
int i;
for (i = 0; i < BN_ARRAY_SIZE; ++i) {
tmp = n->array[i];
res = tmp - 1;
n->array[i] = res;
if (!(res > tmp)) {
break;
}
}
}
void bignum_inc (struct bn *n) {
require (n, "n is null");
DTYPE res;
DTYPE_TMP tmp; /* copy of n */
int i;
for (i = 0; i < BN_ARRAY_SIZE; ++i) {
tmp = n->array[i];
res = tmp + 1;
n->array[i] = res;
if (res > tmp) {
break;
}
}
}
void bignum_add (struct bn *a, struct bn *b, struct bn *c) {
require (a, "a is null");
require (b, "b is null");
require (c, "c is null");
DTYPE_TMP tmp;
int carry = 0;
int i;
for (i = 0; i < BN_ARRAY_SIZE; ++i) {
tmp = (DTYPE_TMP)a->array[i] + b->array[i] + carry;
carry = (tmp > MAX_VAL);
c->array[i] = (tmp & MAX_VAL);
}
}
void bignum_sub (struct bn *a, struct bn *b, struct bn *c) {
require (a, "a is null");
require (b, "b is null");
require (c, "c is null");
DTYPE_TMP res;
DTYPE_TMP tmp1;
DTYPE_TMP tmp2;
int borrow = 0;
int i;
for (i = 0; i < BN_ARRAY_SIZE; ++i) {
tmp1 = (DTYPE_TMP)a->array[i] + (MAX_VAL + 1); /* + number_base */
tmp2 = (DTYPE_TMP)b->array[i] + borrow;
;
res = (tmp1 - tmp2);
c->array[i] = (DTYPE) (res & MAX_VAL); /* "modulo number_base" == "% (number_base - 1)" if number_base is 2^N */
borrow = (res <= MAX_VAL);
}
}
void bignum_mul (struct bn *a, struct bn *b, struct bn *c) {
require (a, "a is null");
require (b, "b is null");
require (c, "c is null");
struct bn row;
struct bn tmp;
int i, j;
bignum_init (c);
for (i = 0; i < BN_ARRAY_SIZE; ++i) {
bignum_init (&row);
for (j = 0; j < BN_ARRAY_SIZE; ++j) {
if (i + j < BN_ARRAY_SIZE) {
bignum_init (&tmp);
DTYPE_TMP intermediate = ((DTYPE_TMP)a->array[i] * (DTYPE_TMP)b->array[j]);
bignum_from_int (&tmp, intermediate);
_lshift_word (&tmp, i + j);
bignum_add (&tmp, &row, &row);
}
}
bignum_add (c, &row, c);
}
}
void bignum_div (struct bn *a, struct bn *b, struct bn *c) {
require (a, "a is null");
require (b, "b is null");
require (c, "c is null");
struct bn current;
struct bn denom;
struct bn tmp;
bignum_from_int (&current, 1); // int current = 1;
bignum_assign (&denom, b); // denom = b
bignum_assign (&tmp, a); // tmp = a
const DTYPE_TMP half_max = 1 + (DTYPE_TMP) (MAX_VAL / 2);
bool overflow = false;
while (bignum_cmp (&denom, a) != LARGER) // while (denom <= a) {
{
if (denom.array[BN_ARRAY_SIZE - 1] >= half_max) {
overflow = true;
break;
}
_lshift_one_bit (&current); // current <<= 1;
_lshift_one_bit (&denom); // denom <<= 1;
}
if (!overflow) {
_rshift_one_bit (&denom); // denom >>= 1;
_rshift_one_bit (&current); // current >>= 1;
}
bignum_init (c); // int answer = 0;
while (!bignum_is_zero (&current)) // while (current != 0)
{
if (bignum_cmp (&tmp, &denom) != SMALLER) // if (dividend >= denom)
{
bignum_sub (&tmp, &denom, &tmp); // dividend -= denom;
bignum_or (c, &current, c); // answer |= current;
}
_rshift_one_bit (&current); // current >>= 1;
_rshift_one_bit (&denom); // denom >>= 1;
} // return answer;
}
void bignum_lshift (struct bn *a, struct bn *b, int nbits) {
require (a, "a is null");
require (b, "b is null");
require (nbits >= 0, "no negative shifts");
bignum_assign (b, a);
/* Handle shift in multiples of word-size */
const int nbits_pr_word = (WORD_SIZE * 8);
int nwords = nbits / nbits_pr_word;
if (nwords != 0) {
_lshift_word (b, nwords);
nbits -= (nwords * nbits_pr_word);
}
if (nbits != 0) {
int i;
for (i = (BN_ARRAY_SIZE - 1); i > 0; --i) {
b->array[i] = (b->array[i] << nbits) | (b->array[i - 1] >> ((8 * WORD_SIZE) - nbits));
}
b->array[i] <<= nbits;
}
}
void bignum_rshift (struct bn *a, struct bn *b, int nbits) {
require (a, "a is null");
require (b, "b is null");
require (nbits >= 0, "no negative shifts");
bignum_assign (b, a);
/* Handle shift in multiples of word-size */
const int nbits_pr_word = (WORD_SIZE * 8);
int nwords = nbits / nbits_pr_word;
if (nwords != 0) {
_rshift_word (b, nwords);
nbits -= (nwords * nbits_pr_word);
}
if (nbits != 0) {
int i;
for (i = 0; i < (BN_ARRAY_SIZE - 1); ++i) {
b->array[i] = (b->array[i] >> nbits) | (b->array[i + 1] << ((8 * WORD_SIZE) - nbits));
}
b->array[i] >>= nbits;
}
}
void bignum_mod (struct bn *a, struct bn *b, struct bn *c) {
/*
Take divmod and throw away div part
*/
require (a, "a is null");
require (b, "b is null");
require (c, "c is null");
struct bn tmp;
bignum_divmod (a, b, &tmp, c);
}
void bignum_divmod (struct bn *a, struct bn *b, struct bn *c, struct bn *d) {
/*
Puts a%b in d
and a/b in c
mod(a,b) = a - ((a / b) * b)
example:
mod(8, 3) = 8 - ((8 / 3) * 3) = 2
*/
require (a, "a is null");
require (b, "b is null");
require (c, "c is null");
struct bn tmp;
/* c = (a / b) */
bignum_div (a, b, c);
/* tmp = (c * b) */
bignum_mul (c, b, &tmp);
/* c = a - tmp */
bignum_sub (a, &tmp, d);
}
void bignum_and (struct bn *a, struct bn *b, struct bn *c) {
require (a, "a is null");
require (b, "b is null");
require (c, "c is null");
int i;
for (i = 0; i < BN_ARRAY_SIZE; ++i) {
c->array[i] = (a->array[i] & b->array[i]);
}
}
void bignum_or (struct bn *a, struct bn *b, struct bn *c) {
require (a, "a is null");
require (b, "b is null");
require (c, "c is null");
int i;
for (i = 0; i < BN_ARRAY_SIZE; ++i) {
c->array[i] = (a->array[i] | b->array[i]);
}
}
void bignum_xor (struct bn *a, struct bn *b, struct bn *c) {
require (a, "a is null");
require (b, "b is null");
require (c, "c is null");
int i;
for (i = 0; i < BN_ARRAY_SIZE; ++i) {
c->array[i] = (a->array[i] ^ b->array[i]);
}
}
int bignum_cmp (struct bn *a, struct bn *b) {
require (a, "a is null");
require (b, "b is null");
int i = BN_ARRAY_SIZE;
do {
i -= 1; /* Decrement first, to start with last array element */
if (a->array[i] > b->array[i]) {
return LARGER;
} else if (a->array[i] < b->array[i]) {
return SMALLER;
}
} while (i != 0);
return EQUAL;
}
int bignum_is_zero (struct bn *n) {
require (n, "n is null");
int i;
for (i = 0; i < BN_ARRAY_SIZE; ++i) {
if (n->array[i]) {
return 0;
}
}
return 1;
}
void bignum_pow (struct bn *a, struct bn *b, struct bn *c) {
require (a, "a is null");
require (b, "b is null");
require (c, "c is null");
struct bn tmp;
bignum_init (c);
if (bignum_cmp (b, c) == EQUAL) {
/* Return 1 when exponent is 0 -- n^0 = 1 */
bignum_inc (c);
} else {
struct bn bcopy;
bignum_assign (&bcopy, b);
/* Copy a -> tmp */
bignum_assign (&tmp, a);
bignum_dec (&bcopy);
/* Begin summing products: */
while (!bignum_is_zero (&bcopy)) {
/* c = tmp * tmp */
bignum_mul (&tmp, a, c);
/* Decrement b by one */
bignum_dec (&bcopy);
bignum_assign (&tmp, c);
}
/* c = tmp */
bignum_assign (c, &tmp);
}
}
void bignum_isqrt (struct bn *a, struct bn *b) {
require (a, "a is null");
require (b, "b is null");
struct bn low, high, mid, tmp;
bignum_init (&low);
bignum_assign (&high, a);
bignum_rshift (&high, &mid, 1);
bignum_inc (&mid);
while (bignum_cmp (&high, &low) > 0) {
bignum_mul (&mid, &mid, &tmp);
if (bignum_cmp (&tmp, a) > 0) {
bignum_assign (&high, &mid);
bignum_dec (&high);
} else {
bignum_assign (&low, &mid);
}
bignum_sub (&high, &low, &mid);
_rshift_one_bit (&mid);
bignum_add (&low, &mid, &mid);
bignum_inc (&mid);
}
bignum_assign (b, &low);
}
void bignum_assign (struct bn *dst, struct bn *src) {
require (dst, "dst is null");
require (src, "src is null");
int i;
for (i = 0; i < BN_ARRAY_SIZE; ++i) {
dst->array[i] = src->array[i];
}
}
/* Private / Static functions. */
static void _rshift_word (struct bn *a, int nwords) {
/* Naive method: */
require (a, "a is null");
require (nwords >= 0, "no negative shifts");
int i;
if (nwords >= BN_ARRAY_SIZE) {
for (i = 0; i < BN_ARRAY_SIZE; ++i) {
a->array[i] = 0;
}
return;
}
for (i = 0; i < BN_ARRAY_SIZE - nwords; ++i) {
a->array[i] = a->array[i + nwords];
}
for (; i < BN_ARRAY_SIZE; ++i) {
a->array[i] = 0;
}
}
static void _lshift_word (struct bn *a, int nwords) {
require (a, "a is null");
require (nwords >= 0, "no negative shifts");
int i;
/* Shift whole words */
for (i = (BN_ARRAY_SIZE - 1); i >= nwords; --i) {
a->array[i] = a->array[i - nwords];
}
/* Zero pad shifted words. */
for (; i >= 0; --i) {
a->array[i] = 0;
}
}
static void _lshift_one_bit (struct bn *a) {
require (a, "a is null");
int i;
for (i = (BN_ARRAY_SIZE - 1); i > 0; --i) {
a->array[i] = (a->array[i] << 1) | (a->array[i - 1] >> ((8 * WORD_SIZE) - 1));
}
a->array[0] <<= 1;
}
static void _rshift_one_bit (struct bn *a) {
require (a, "a is null");
int i;
for (i = 0; i < (BN_ARRAY_SIZE - 1); ++i) {
a->array[i] = (a->array[i] >> 1) | (a->array[i + 1] << ((8 * WORD_SIZE) - 1));
}
a->array[BN_ARRAY_SIZE - 1] >>= 1;
}
+113
View File
@@ -0,0 +1,113 @@
#ifndef __BIGNUM_H__
#define __BIGNUM_H__
/*
Big number library - arithmetic on multiple-precision unsigned integers.
This library is an implementation of arithmetic on arbitrarily large integers.
The difference between this and other implementations, is that the data structure
has optimal memory utilization (i.e. a 1024 bit integer takes up 128 bytes RAM),
and all memory is allocated statically: no dynamic allocation for better or worse.
Primary goals are correctness, clarity of code and clean, portable implementation.
Secondary goal is a memory footprint small enough to make it suitable for use in
embedded applications.
The current state is correct functionality and adequate performance.
There may well be room for performance-optimizations and improvements.
*/
#include <stdint.h>
#include <assert.h>
/* This macro defines the word size in bytes of the array that constitues the big-number data structure. */
#ifndef WORD_SIZE
#define WORD_SIZE 4
#endif
/* Size of big-numbers in bytes */
#define BN_ARRAY_SIZE (128 / WORD_SIZE)
/* Here comes the compile-time specialization for how large the underlying array size should be. */
/* The choices are 1, 2 and 4 bytes in size with uint32, uint64 for WORD_SIZE==4, as temporary. */
#ifndef WORD_SIZE
#error Must define WORD_SIZE to be 1, 2, 4
#elif (WORD_SIZE == 1)
/* Data type of array in structure */
#define DTYPE uint8_t
/* bitmask for getting MSB */
#define DTYPE_MSB ((DTYPE_TMP) (0x80))
/* Data-type larger than DTYPE, for holding intermediate results of calculations */
#define DTYPE_TMP uint32_t
/* sprintf format string */
#define SPRINTF_FORMAT_STR "%.02x"
#define SSCANF_FORMAT_STR "%2hhx"
/* Max value of integer type */
#define MAX_VAL ((DTYPE_TMP)0xFF)
#elif (WORD_SIZE == 2)
#define DTYPE uint16_t
#define DTYPE_TMP uint32_t
#define DTYPE_MSB ((DTYPE_TMP) (0x8000))
#define SPRINTF_FORMAT_STR "%.04x"
#define SSCANF_FORMAT_STR "%4hx"
#define MAX_VAL ((DTYPE_TMP)0xFFFF)
#elif (WORD_SIZE == 4)
#define DTYPE uint32_t
#define DTYPE_TMP uint64_t
#define DTYPE_MSB ((DTYPE_TMP) (0x80000000))
#define SPRINTF_FORMAT_STR "%.08x"
#define SSCANF_FORMAT_STR "%8x"
#define MAX_VAL ((DTYPE_TMP)0xFFFFFFFF)
#endif
#ifndef DTYPE
#error DTYPE must be defined to uint8_t, uint16_t uint32_t or whatever
#endif
/* Custom assert macro - easy to disable */
#define require(p, msg) assert (p &&msg)
/* Data-holding structure: array of DTYPEs */
struct bn {
DTYPE array[BN_ARRAY_SIZE];
};
/* Tokens returned by bignum_cmp() for value comparison */
enum { SMALLER = -1,
EQUAL = 0,
LARGER = 1 };
/* Initialization functions: */
void bignum_init (struct bn *n);
void bignum_from_int (struct bn *n, DTYPE_TMP i);
int bignum_to_int (struct bn *n);
void bignum_from_string (struct bn *n, char *str, int nbytes);
void bignum_to_string (struct bn *n, char *str, int maxsize);
/* Basic arithmetic operations: */
void bignum_add (struct bn *a, struct bn *b, struct bn *c); /* c = a + b */
void bignum_sub (struct bn *a, struct bn *b, struct bn *c); /* c = a - b */
void bignum_mul (struct bn *a, struct bn *b, struct bn *c); /* c = a * b */
void bignum_div (struct bn *a, struct bn *b, struct bn *c); /* c = a / b */
void bignum_mod (struct bn *a, struct bn *b, struct bn *c); /* c = a % b */
void bignum_divmod (struct bn *a, struct bn *b, struct bn *c, struct bn *d); /* c = a/b, d = a%b */
/* Bitwise operations: */
void bignum_and (struct bn *a, struct bn *b, struct bn *c); /* c = a & b */
void bignum_or (struct bn *a, struct bn *b, struct bn *c); /* c = a | b */
void bignum_xor (struct bn *a, struct bn *b, struct bn *c); /* c = a ^ b */
void bignum_lshift (struct bn *a, struct bn *b, int nbits); /* b = a << nbits */
void bignum_rshift (struct bn *a, struct bn *b, int nbits); /* b = a >> nbits */
/* Special operators and comparison */
int bignum_cmp (struct bn *a, struct bn *b); /* Compare: returns LARGER, EQUAL or SMALLER */
int bignum_is_zero (struct bn *n); /* For comparison with zero */
void bignum_inc (struct bn *n); /* Increment: add one to n */
void bignum_dec (struct bn *n); /* Decrement: subtract one from n */
void bignum_pow (struct bn *a, struct bn *b, struct bn *c); /* Calculate a^b -- e.g. 2^10 => 1024 */
void bignum_isqrt (struct bn *a, struct bn *b); /* Integer square root -- e.g. isqrt(5) => 2*/
void bignum_assign (struct bn *dst, struct bn *src); /* Copy src into dst -- dst := src */
#endif /* #ifndef __BIGNUM_H__ */
File diff suppressed because it is too large. Load diff
+3 -1
View File
@@ -51,6 +51,7 @@ typedef struct {
typedef struct {
ut32 argcount;
ut32 posonlyargcount;
ut32 kwonlyargcount;
ut32 nlocals;
ut32 stacksize;
@@ -69,6 +70,7 @@ typedef struct {
st64 end_offset;
} pyc_code_object;
bool get_sections_from_code_objects(RBuffer *buffer, RList *sections, RList *objs);
bool get_sections_symbols_from_code_objects(RBuffer *buffer, RList *sections, RList *symbols, RList *objs, ut32 magic);
ut64 get_code_object_addr (RBuffer *buffer, ut32 magic);
#endif
+20 -143
View File
@@ -1,150 +1,27 @@
/* radare - LGPL3 - Copyright 2016 - Matthieu (c0riolis) Tardy */
/* radare - LGPL3 - Copyright 2016-2020 - c0riolis, x0urc3 */
#include "pyc.h"
#include "marshal.h"
bool pyc_get_sections(RList *sections, RList *cobjs, RBuffer *buf, ut32 magic) {
return get_sections_from_code_objects (buf, sections, cobjs);
bool pyc_get_sections_symbols(RList *sections, RList *symbols, RList* cobjs, RBuffer *buf, ut32 magic) {
return get_sections_symbols_from_code_objects (buf, sections, symbols, cobjs, magic);
}
ut64 pyc_get_entrypoint(ut32 magic) {
switch (magic) {
case MAGIC_0_9_4_BETA:
case MAGIC_0_9_9_v0:
case MAGIC_0_9_9_v1:
case MAGIC_0_9_9_v2:
case MAGIC_1_0_1:
case MAGIC_1_1:
case MAGIC_1_2:
case MAGIC_1_3_B1:
case MAGIC_1_4_B1_v0:
case MAGIC_1_4_B1_v1:
case MAGIC_1_4:
case MAGIC_1_5_A1:
case MAGIC_1_6_A2:
case MAGIC_2_0_B1_v0:
case MAGIC_2_0_B1_v1_U:
case MAGIC_2_0_B1_v2:
case MAGIC_2_0_B1_v2_U:
case MAGIC_2_0_B1_v3:
case MAGIC_2_0_B1_v3_U:
case MAGIC_2_0_B1_v4:
case MAGIC_2_0_B1_v4_U:
case MAGIC_2_0_B1_v5_U:
case MAGIC_2_0_B1_v6_U:
case MAGIC_2_1_A1:
case MAGIC_2_1_A1_U:
case MAGIC_2_1_A2:
case MAGIC_2_1_A2_U:
case MAGIC_2_2_A0:
case MAGIC_2_2_A0_U:
case MAGIC_2_2_A1:
case MAGIC_2_2_A1_U:
case MAGIC_2_3_A0_v0:
case MAGIC_2_3_A0_v0_U:
case MAGIC_2_3_A0_v1:
case MAGIC_2_3_A0_v1_U:
case MAGIC_2_3_A0_v2:
case MAGIC_2_3_A0_v2_U:
case MAGIC_2_4_A0_v0:
case MAGIC_2_4_A0_v0_U:
case MAGIC_2_4_A0_v1:
case MAGIC_2_4_A0_v1_U:
case MAGIC_2_4_A2:
case MAGIC_2_4_A2_U:
case MAGIC_2_4_A3:
case MAGIC_2_4_A3_U:
case MAGIC_2_5_A0_v0:
case MAGIC_2_5_A0_v0_U:
case MAGIC_2_5_A0_v1:
case MAGIC_2_5_A0_v1_U:
case MAGIC_2_5_A0_v2:
case MAGIC_2_5_A0_v2_U:
case MAGIC_2_5_A0_v3_U:
case MAGIC_2_5_B2_v0:
case MAGIC_2_5_B2_v0_U:
case MAGIC_2_5_B2_v1:
case MAGIC_2_5_B2_v1_U:
case MAGIC_2_5_C3:
case MAGIC_2_5_C3_U:
case MAGIC_2_6_A0_v0:
case MAGIC_2_6_A0_v0_U:
case MAGIC_2_6_A0_v1:
case MAGIC_2_6_A0_v1_U:
case MAGIC_2_6_A0_v2:
case MAGIC_2_6_A0_v2_U:
case MAGIC_2_6_A1_PLUS_v0:
case MAGIC_2_6_A1_PLUS_v0_U:
case MAGIC_2_6_A1_PLUS_v1:
case MAGIC_2_6_A1_PLUS_v1_U:
case MAGIC_2_7_A0_v0:
case MAGIC_2_7_A0_v0_U:
case MAGIC_2_7_A0_v1:
case MAGIC_2_7_A0_v1_U:
case MAGIC_2_7_A0_v2:
case MAGIC_2_7_A0_v2_U:
case MAGIC_2_7_A2_PLUS_v0:
case MAGIC_2_7_A2_PLUS_v0_U:
case MAGIC_2_7_A2_PLUS_v1:
case MAGIC_2_7_A2_PLUS_v1_U:
case MAGIC_3_0X_v0:
case MAGIC_3_0X_v0_U:
case MAGIC_3_0X_v1:
case MAGIC_3_0X_v1_U:
case MAGIC_3_0X_v2:
case MAGIC_3_0X_v2_U:
case MAGIC_3_0X_v3:
case MAGIC_3_0X_v3_U:
case MAGIC_3_0X_v4:
case MAGIC_3_0X_v4_U:
case MAGIC_3_0X_v5:
case MAGIC_3_0X_v5_U:
case MAGIC_3_0X_v6:
case MAGIC_3_0X_v6_U:
case MAGIC_3_0_A1_v0:
case MAGIC_3_0_A1_v0_U:
case MAGIC_3_0_A1_v1:
case MAGIC_3_0_A1_v1_U:
case MAGIC_3_0_A1_PLUS:
case MAGIC_3_0_A1_PLUS_U:
case MAGIC_3_0_A2:
case MAGIC_3_0_A2_U:
case MAGIC_3_0_A2_PLUS:
case MAGIC_3_0_A2_PLUS_U:
case MAGIC_3_0_A3_PLUS:
case MAGIC_3_0_A3_PLUS_U:
case MAGIC_3_0_A5_PLUS:
case MAGIC_3_0_A5_PLUS_U:
case MAGIC_3_1_A0_v0:
case MAGIC_3_1_A0_v0_U:
case MAGIC_3_1_A0_v1:
case MAGIC_3_1_A0_v1_U:
case MAGIC_3_2_A0:
case MAGIC_3_2_A0_U:
case MAGIC_3_2_A1_PLUS_U:
case MAGIC_3_2_A2_PLUS_U:
case MAGIC_3_3_A0_U:
case MAGIC_3_3_0_A0_v0_U:
return 0x8;
case MAGIC_3_3_0_A0_v1_U:
case MAGIC_3_3_0_A1_PLUS_U:
case MAGIC_3_3_0_A3_PLUS_U:
case MAGIC_3_4_0_A0_v0_U:
case MAGIC_3_4_0_A0_v1_U:
case MAGIC_3_4_0_A0_v2_U:
case MAGIC_3_4_0_A0_v3_U:
case MAGIC_3_4_0_A0_v4_U:
case MAGIC_3_4_0_A3_PLUS_v0_U:
case MAGIC_3_4_0_A3_PLUS_v1_U:
case MAGIC_3_4_0_RC1_PLUS_U:
case MAGIC_3_5_0_A0_U:
case MAGIC_3_5_0_A4_PLUS_U:
case MAGIC_3_5_0_B1_PLUS_U:
case MAGIC_3_5_0_B2_PLUS_U:
case MAGIC_3_6_0_A0_v0_U:
case MAGIC_3_6_0_A0_v1_U:
return 0xc;
default:
return 0x0;
}
bool pyc_is_object(ut8 b, pyc_marshal_type type) {
bool ret = false;
if (b == type) {
ret = true;
}
return ret;
}
bool pyc_is_code(ut8 b, ut32 magic) {
if ((magic == 0x00949494 || magic == 0x0099be2a || magic == 0x0099be3a || magic == 0x00999901) && (pyc_is_object((b & ~FLAG_REF), TYPE_CODE_v0))) {
//TYPE_CODE_V0 for Python < 1.0
return true;
}
if (pyc_is_object((b & ~FLAG_REF), TYPE_CODE_v1)) {
return true;
}
return false;
}
+6 -3
View File
@@ -1,4 +1,4 @@
/* radare - LGPL3 - Copyright 2016 - Matthieu (c0riolis) Tardy */
/* radare - LGPL3 - Copyright 2016-2020 - c0riolis, x0urc3 */
#ifndef PYC_H
#define PYC_H
@@ -8,8 +8,11 @@
#include <r_lib.h>
#include <r_bin.h>
#include "pyc_magic.h"
bool pyc_get_sections(RList *sections, RList* mem, RBuffer *buf, ut32 magic);
#include "marshal.h"
bool pyc_get_sections_symbols(RList *sections, RList *symbols, RList* mem, RBuffer *buf, ut32 magic);
ut64 pyc_get_entrypoint(ut32 magic);
bool pyc_is_object(ut8 b, pyc_marshal_type type);
bool pyc_is_code(ut8 b, ut32 magic);
#endif
+259 -144
View File
@@ -1,156 +1,271 @@
/* radare - LGPL3 - Copyright 2016 - Matthieu (c0riolis) Tardy */
/* radare - LGPL3 - Copyright 2016-2020 - c0riolis, x0urc3 */
#include "pyc_magic.h"
#include <stdlib.h>
static struct pyc_version versions[] = {
{MAGIC_0_9_4_BETA, "0.9.4 beta", "77b80a91d357c1d95d8e7cd4cbbe799e5deb777e", false},
{MAGIC_0_9_9_v0, "0.9.9", "1cabc2b6c9701aea29bb506b593946e67bf7593a", false},
{MAGIC_0_9_9_v1, "0.9.9", "f820e6917f07e5012bdd103ef97389318d5a10f8", false},
{MAGIC_0_9_9_v2, "0.9.9", "9fed5726a36d7ce1355c30592838d93321d580ee", false},
{MAGIC_1_0_1, "1.0.1", "1808ca5d8883097c72c6a8a89143041c20ea13c1", false},
{MAGIC_1_1, "1.1", "d1e6c9a64a563841f60177ac907739f953f15630", false},
{MAGIC_1_2, "1.2", "fb3daf9b2456dc1a3d99f56f78c5e6270eeaf1e8", false},
{MAGIC_1_3_B1, "1.3b1", "0261bf5b3819b03d83f254562947244634604026", false},
{MAGIC_1_4_B1_v0, "1.4b1", "d1ae0ea9a585f912d7aa3d004ff817d0dea112f8", false},
{MAGIC_1_4_B1_v1, "1.4b1", "22e29b1747e139d9598eaa5126c59313af39949d", false},
{MAGIC_1_4, "1.4", "b82d847b3dcbccd63de075e3879a9369dfb34e0d", false},
{MAGIC_1_5_A1, "1.5a1", "104a646fc7a67f27df25d4e941b20035e5876f9f", false},
{MAGIC_1_6_A2, "1.6a2", "84cd52b560e571eba371d7136abcc9c42c27b002", false},
{MAGIC_2_0_B1_v0, "2.0b1", "f79434ee41fa86019216240ba32be660bcfc5419", false},
{MAGIC_2_0_B1_v1, "2.0b1", "4388249506d190a76a4dbbbc70294ef6ba0656d5", false},
{MAGIC_2_0_B1_v1_U, "2.0b1", "4388249506d190a76a4dbbbc70294ef6ba0656d5", true,},
{MAGIC_2_0_B1_v2, "2.0b1", "4eaa463c031a1bdb5e7791c370d04108e0682dd4", false},
{MAGIC_2_0_B1_v2_U, "2.0b1", "4eaa463c031a1bdb5e7791c370d04108e0682dd4", true },
{MAGIC_2_0_B1_v3, "2.0b1", "18385172fac0b7099bd2d2264df614ed4466f083", false},
{MAGIC_2_0_B1_v3_U, "2.0b1", "18385172fac0b7099bd2d2264df614ed4466f083", true },
{MAGIC_2_0_B1_v4, "2.0b1", "f657dc8ff25e93b877305bbcfc45e360191bb326", false},
{MAGIC_2_0_B1_v4_U, "2.0b1", "f657dc8ff25e93b877305bbcfc45e360191bb326", true },
{MAGIC_2_0_B1_v5, "2.0b1", "1b9fd0cbd914947cc421ba7e45aa093d7ba9af00", false},
{MAGIC_2_0_B1_v5_U, "2.0b1", "1b9fd0cbd914947cc421ba7e45aa093d7ba9af00", true },
{MAGIC_2_0_B1_v6, "2.0b1", "1f1a156ed5af8f7a50ce05fc85f85423a24f2aa4", false},
{MAGIC_2_0_B1_v6_U, "2.0b1", "1f1a156ed5af8f7a50ce05fc85f85423a24f2aa4", true },
{MAGIC_2_1_A1, "2.1a1", "fd8c7203251ff37dbb397f7d423ae41f16a03c68", false},
{MAGIC_2_1_A1_U, "2.1a1", "fd8c7203251ff37dbb397f7d423ae41f16a03c68", true },
{MAGIC_2_1_A2, "2.1a2", "0076e8d28f9eba9eff4508696dc33730af2b4001", false},
{MAGIC_2_1_A2_U, "2.1a2", "0076e8d28f9eba9eff4508696dc33730af2b4001", true },
{MAGIC_2_2_A0, "2.2a0", "32e7d0898eab85de8134f932680a85c6e7abcec0", false},
{MAGIC_2_2_A0_U, "2.2a0", "32e7d0898eab85de8134f932680a85c6e7abcec0", true },
{MAGIC_2_2_A1, "2.2a1", "09df3254b49d7c9306585302fe815ab0bdb53439", false},
{MAGIC_2_2_A1_U, "2.2a1", "09df3254b49d7c9306585302fe815ab0bdb53439", true },
{MAGIC_2_3_A0_v0, "2.3a0", "abedb2418f6231adf24205092a59996f1f1e4c02", false},
{MAGIC_2_3_A0_v0_U, "2.3a0", "abedb2418f6231adf24205092a59996f1f1e4c02", true },
{MAGIC_2_3_A0_v1, "2.3a0", "d6ae544acd24a1f72ce00534fed464fde91ee504", false},
{MAGIC_2_3_A0_v1_U, "2.3a0", "d6ae544acd24a1f72ce00534fed464fde91ee504", true },
{MAGIC_2_3_A0_v2, "2.3a0", "cf5928fab108de9fbe02632d07176c717c2b3aa7", false},
{MAGIC_2_3_A0_v2_U, "2.3a0", "cf5928fab108de9fbe02632d07176c717c2b3aa7", true },
{MAGIC_2_3_A0_v3, "2.3a0", "5fe4d93df429134ef8695c12e59ff962ff8b73d2", false},
{MAGIC_2_3_A0_v3_U, "2.3a0", "5fe4d93df429134ef8695c12e59ff962ff8b73d2", true },
{MAGIC_2_4_A0_v0, "2.4a0", "adb42a71169604d3609ac2fbdb64cf8cd1c7250b", false},
{MAGIC_2_4_A0_v0_U, "2.4a0", "adb42a71169604d3609ac2fbdb64cf8cd1c7250b", true },
{MAGIC_2_4_A0_v1, "2.4a0", "3df36e2e5ddc1149af8eb52e20bc225d806236d4", false},
{MAGIC_2_4_A0_v1_U, "2.4a0", "3df36e2e5ddc1149af8eb52e20bc225d806236d4", true },
{MAGIC_2_4_A2, "2.4a2", "1f9b9c226b43ed20cb61e6d21aea6cb966e8bcd3", false},
{MAGIC_2_4_A2_U, "2.4a2", "1f9b9c226b43ed20cb61e6d21aea6cb966e8bcd3", true },
{MAGIC_2_4_A3, "2.4a3", "2b49b4a85d9eb4a4cfa9f29c21d649c383945671", false},
{MAGIC_2_4_A3_U, "2.4a3", "2b49b4a85d9eb4a4cfa9f29c21d649c383945671", true },
{MAGIC_2_5_A0_v0, "2.5a0", "44e3f21f052590ddfabc12909af5188a4cd89d8c", false},
{MAGIC_2_5_A0_v0_U, "2.5a0", "44e3f21f052590ddfabc12909af5188a4cd89d8c", true },
{MAGIC_2_5_A0_v1, "2.5a0", "eb15cdd4a2f1001792074ca0789026989452ff82", false},
{MAGIC_2_5_A0_v1_U, "2.5a0", "eb15cdd4a2f1001792074ca0789026989452ff82", true },
{MAGIC_2_5_A0_v2, "2.5a0", "b6d2f6fd3e116b9b9fe95bc982ac763c359ff103", false},
{MAGIC_2_5_A0_v2_U, "2.5a0", "b6d2f6fd3e116b9b9fe95bc982ac763c359ff103", true },
{MAGIC_2_5_A0_v3, "2.5a0", "5c36c222e7ca5310e5cc8b8db283bd669d1e24d4", false},
{MAGIC_2_5_A0_v3_U, "2.5a0", "5c36c222e7ca5310e5cc8b8db283bd669d1e24d4", true },
{MAGIC_2_5_B2_v0, "2.5b2", "2c3ec720aa7beb0da4002b847cc5ed7dc782566c", false},
{MAGIC_2_5_B2_v0_U, "2.5b2", "2c3ec720aa7beb0da4002b847cc5ed7dc782566c", true },
{MAGIC_2_5_B2_v1, "2.5b2", "b745b3fd66a649a5fa540bdf47971c26af0a959e", false},
{MAGIC_2_5_B2_v1_U, "2.5b2", "b745b3fd66a649a5fa540bdf47971c26af0a959e", true },
{MAGIC_2_5_C3, "2.5c3", "b90a8b0395bd43fd193842451d0c49573b4d7166", false},
{MAGIC_2_5_C3_U, "2.5c3", "b90a8b0395bd43fd193842451d0c49573b4d7166", true },
{MAGIC_2_6_A0_v0, "2.6a0", "8dcb882ec3e1aac7d336a40aa64ec66561fc3dec", false},
{MAGIC_2_6_A0_v0_U, "2.6a0", "8dcb882ec3e1aac7d336a40aa64ec66561fc3dec", true },
{MAGIC_2_6_A0_v1, "2.6a0", "3985d7e2067db75f170e0891994b0fd70963e40b", false},
{MAGIC_2_6_A0_v1_U, "2.6a0", "3985d7e2067db75f170e0891994b0fd70963e40b", true },
{MAGIC_2_6_A0_v2, "2.6a0", "07aa19170a673da6b3e8c4c66bfd868b2f90c0e4", false},
{MAGIC_2_6_A0_v2_U, "2.6a0", "07aa19170a673da6b3e8c4c66bfd868b2f90c0e4", true },
{MAGIC_2_6_A1_PLUS_v0, "2.6a1+", "343597c7d682b3552580352deddd0cdb36978a04", false},
{MAGIC_2_6_A1_PLUS_v0_U, "2.6a1+", "343597c7d682b3552580352deddd0cdb36978a04", true },
{MAGIC_2_6_A1_PLUS_v1, "2.6a1+", "eac41f90296c69c6d07d29f1feb453a4c0e400d1", false},
{MAGIC_2_6_A1_PLUS_v1_U, "2.6a1+", "eac41f90296c69c6d07d29f1feb453a4c0e400d1", true },
{MAGIC_2_6_A1_PLUS_v2, "2.6a1+", "a0ea3a0efc710934ad66e3907211230ff227d6a1", false},
{MAGIC_2_6_A1_PLUS_v2_U, "2.6a1+", "a0ea3a0efc710934ad66e3907211230ff227d6a1", true },
{MAGIC_2_7_A0_v0, "2.7a0", "94e79d78dff0dfb5c53f49842c7df65ad5b79e66", false},
{MAGIC_2_7_A0_v0_U, "2.7a0", "94e79d78dff0dfb5c53f49842c7df65ad5b79e66", true },
{MAGIC_2_7_A0_v1, "2.7a0", "ef8fe90886968b1eb468cb91ebae103f773fa17f", false},
{MAGIC_2_7_A0_v1_U, "2.7a0", "ef8fe90886968b1eb468cb91ebae103f773fa17f", true },
{MAGIC_2_7_A0_v2, "2.7a0", "145376df3ad728f7052fdd8b6eba600a8317fece", false},
{MAGIC_2_7_A0_v2_U, "2.7a0", "145376df3ad728f7052fdd8b6eba600a8317fece", true },
{MAGIC_2_7_A2_PLUS_v0, "2.7a2+", "c2fdf25329ff30cf8d68c0c0e7cf479d7b203745", false},
{MAGIC_2_7_A2_PLUS_v0_U, "2.7a2+", "c2fdf25329ff30cf8d68c0c0e7cf479d7b203745", true },
{MAGIC_2_7_A2_PLUS_v1, "2.7a2+", "edfed0e32cedf3b84c6e999052486a750a3f5bee", false},
{MAGIC_2_7_A2_PLUS_v1_U, "2.7a2+", "edfed0e32cedf3b84c6e999052486a750a3f5bee", true },
{MAGIC_3_0X_v0, "3.0x", "49c6eb688906b1dddabf578f08129e6729d6151f", false},
{MAGIC_3_0X_v0_U, "3.0x", "49c6eb688906b1dddabf578f08129e6729d6151f", true },
{MAGIC_3_0X_v1, "3.0x", "f87a3e61853d72b1d133992f991e397b31aac8e8", false},
{MAGIC_3_0X_v1_U, "3.0x", "f87a3e61853d72b1d133992f991e397b31aac8e8", true },
{MAGIC_3_0X_v2, "3.0x", "d0b83c4630c0924df661063543f3c5478c8c35ac", false},
{MAGIC_3_0X_v2_U, "3.0x", "d0b83c4630c0924df661063543f3c5478c8c35ac", true },
{MAGIC_3_0X_v3, "3.0x", "1cce0526d9b0a53f4ff95713dde153dc70dae2dc", false},
{MAGIC_3_0X_v3_U, "3.0x", "1cce0526d9b0a53f4ff95713dde153dc70dae2dc", true },
{MAGIC_3_0X_v4, "3.0x", "7a35d3d1ac5a301ef3dc52f9140844f0422011a5", false},
{MAGIC_3_0X_v4_U, "3.0x", "7a35d3d1ac5a301ef3dc52f9140844f0422011a5", true },
{MAGIC_3_0X_v5, "3.0x", "793e0323d4d65bfc89b40d78162cd771c575a18e", false},
{MAGIC_3_0X_v5_U, "3.0x", "793e0323d4d65bfc89b40d78162cd771c575a18e", true },
{MAGIC_3_0X_v6, "3.0x", "19f7ff443718f7a9da1aea9edbf00a135f860883", false},
{MAGIC_3_0X_v6_U, "3.0x", "19f7ff443718f7a9da1aea9edbf00a135f860883", true },
{MAGIC_3_0_A1_v0, "3.0a1", "a89d469e1ff77716914ce1a4244fa529a71ce68a", false},
{MAGIC_3_0_A1_v0_U, "3.0a1", "a89d469e1ff77716914ce1a4244fa529a71ce68a", true },
{MAGIC_3_0_A1_v1, "3.0a1", "19319e70fc3edbb45b2d007161c1b3a1de094181", false},
{MAGIC_3_0_A1_v1_U, "3.0a1", "19319e70fc3edbb45b2d007161c1b3a1de094181", true },
{MAGIC_3_0_A1_PLUS, "3.0a1+", "0d462d789b18ec6a59ebe2116688d5b6985c215d", false},
{MAGIC_3_0_A1_PLUS_U, "3.0a1+", "0d462d789b18ec6a59ebe2116688d5b6985c215d", true },
{MAGIC_3_0_A2, "3.0a2", "4dc01402d78afe2c9b4a4bd8004eb08e2647335d", false},
{MAGIC_3_0_A2_U, "3.0a2", "4dc01402d78afe2c9b4a4bd8004eb08e2647335d", true },
{MAGIC_3_0_A2_PLUS, "3.0a2+", "73e1bf179a01ad7824ff5aa2b29ce068a457cd67", false},
{MAGIC_3_0_A2_PLUS_U, "3.0a2+", "73e1bf179a01ad7824ff5aa2b29ce068a457cd67", true },
{MAGIC_3_0_A3_PLUS, "3.0a3+", "832c820e9d144cb76c8778ad6fcffe232b1f5c46", false},
{MAGIC_3_0_A3_PLUS_U, "3.0a3+", "832c820e9d144cb76c8778ad6fcffe232b1f5c46", true },
{MAGIC_3_0_A5_PLUS, "3.0a5+", "212a1fee6bf93f8b74f81dd3567bf964e627ea20", false},
{MAGIC_3_0_A5_PLUS_U, "3.0a5+", "212a1fee6bf93f8b74f81dd3567bf964e627ea20", true },
{MAGIC_3_1_A0_v0, "3.1a0", "2ee4653927f72f9bb3ff14b3083d4a203d684dfc", false},
{MAGIC_3_1_A0_v0_U, "3.1a0", "2ee4653927f72f9bb3ff14b3083d4a203d684dfc", true },
{MAGIC_3_1_A0_v1, "3.1a0", "643d8d4fc8ebcc69155d3416357aadca9c053388", false},
{MAGIC_3_1_A0_v1_U, "3.1a0", "643d8d4fc8ebcc69155d3416357aadca9c053388", true },
{MAGIC_3_2_A0, "3.2a0", "3aaf2e065db05401803705ed4bfa3fd2f9030df8", false},
{MAGIC_3_2_A0_U, "3.2a0", "3aaf2e065db05401803705ed4bfa3fd2f9030df8", true },
{MAGIC_3_2_A1_PLUS_U, "3.2a1+", "72523121127327c022096d30e7b28a4a5a89495d", true },
{MAGIC_3_2_A2_PLUS_U, "3.2a2+", "252895d491570d5a27452809b582717be409b24d", true },
{MAGIC_3_3_A0_U, "3.3a0", "9a6d9ac6fb2e1bb15bbb4e8c2a6c939d07088477", true },
{MAGIC_3_3_0_A0_v0_U, "3.3.0a0", "e1dbc72bd97f36c1aed7e3ba2a58278f4da807be", true },
{MAGIC_3_3_0_A0_v1_U, "3.3.0a0", "87331661042b89022f6f49506ae9c1ae459a95be", true },
{MAGIC_3_3_0_A1_PLUS_U, "3.3.0a1+", "c0a6569fdad624cc89cdd24b68331dc2a9b64827", true },
{MAGIC_3_3_0_A3_PLUS_U, "3.3.0a3+", "96ab78ef82a775da11a538fc47aebe70d9c34f04", true },
{MAGIC_3_4_0_A0_v0_U, "3.4.0a0", "d296cf1600a8c2c7098737944b5ee793b67a6883", true },
{MAGIC_3_4_0_A0_v1_U, "3.4.0a0", "2528e4aea33801b40ec902a77b5451ebc925a331", true },
{MAGIC_3_4_0_A0_v2_U, "3.4.0a0", "cf65c7a75f558e6cd68903f4c2800f6b9574a35f", true },
{MAGIC_3_4_0_A0_v3_U, "3.4.0a0", "3d858f1eef546e6adb2c073be9384065cfc2537e", true },
{MAGIC_3_4_0_A0_v4_U, "3.4.0a0", "6db3741e59be2b6427032a0f51d8a06625d64c28", true },
{MAGIC_3_4_0_A3_PLUS_v0_U, "3.4.0a3+", "35b384ed594b4618a7ea345dad7d2149eabcf3e7", true },
{MAGIC_3_4_0_A3_PLUS_v1_U, "3.4.0a3+", "bb2affc1e317a85c4edfe450c119bdec851a08ee", true },
{MAGIC_3_4_0_RC1_PLUS_U, "3.4.0rc1+", "e301a515f8f4c5cdde3b9726ec298bd4de1af963", true },
{MAGIC_3_5_0_A0_U, "3.5.0a0", "c553d8f72d659b3bc14fe326662ba53ca97bf38a", true },
{MAGIC_3_5_0_A4_PLUS_U, "3.5.0a4+", "a65f685ba8c011bf117cadf26c13ab7a0cbb122c", true },
{MAGIC_3_5_0_B1_PLUS_U, "3.5.0b1+", "6f05f83c7010764aff53793fbff162c42018f57e", true },
{MAGIC_3_5_0_B2_PLUS_U, "3.5.0b2+", "7a0a1a4ac63942f4ea3c7804e323adf668d40a21", true },
{MAGIC_3_6_0_A0_v0_U, "3.6.0a0", "1ddeb2e175df5009571b3632a709c6b74995cb29", true },
{MAGIC_3_6_0_A0_v1_U, "3.6.0a0", "775b74e0e103f816382a0fc009b6ac51ea956750", true },
{ 0x00949494, "0.9.4 beta", "77b80a91d357c1d95d8e7cd4cbbe799e5deb777e" },
{ 0x0099be2a, "0.9.9", "1cabc2b6c9701aea29bb506b593946e67bf7593a" },
{ 0x0099be3a, "0.9.9", "f820e6917f07e5012bdd103ef97389318d5a10f8" },
{ 0x00999901, "0.9.9", "9fed5726a36d7ce1355c30592838d93321d580ee" },
{ 0x00999902, "1.0.1", "1808ca5d8883097c72c6a8a89143041c20ea13c1" },
{ 0x00999903, "1.1", "d1e6c9a64a563841f60177ac907739f953f15630" },
{ 0x0a0d4127, "1.2", "fb3daf9b2456dc1a3d99f56f78c5e6270eeaf1e8" },
{ 0x0a0d2e89, "1.3b1", "0261bf5b3819b03d83f254562947244634604026" },
{ 0x0a0d0767, "1.4b1", "d1ae0ea9a585f912d7aa3d004ff817d0dea112f8" },
{ 0x0a0d1704, "1.4b1", "22e29b1747e139d9598eaa5126c59313af39949d" },
{ 0x0a0d4e95, "1.4", "b82d847b3dcbccd63de075e3879a9369dfb34e0d" },
{ 0x0a0d4e99, "1.5a1", "104a646fc7a67f27df25d4e941b20035e5876f9f" },
{ 0x0a0dc4fc, "1.6a2", "84cd52b560e571eba371d7136abcc9c42c27b002" },
{ 0x0a0dc61b, "2.0b1", "f79434ee41fa86019216240ba32be660bcfc5419" },
{ 0x0a0dc67b, "2.0b1", "4eaa463c031a1bdb5e7791c370d04108e0682dd4" },
{ 0x0a0dc67c, "2.0b1", "4eaa463c031a1bdb5e7791c370d04108e0682dd4" },
{ 0x0a0dc67f, "2.0b1", "18385172fac0b7099bd2d2264df614ed4466f083" },
{ 0x0a0dc680, "2.0b1", "18385172fac0b7099bd2d2264df614ed4466f083" },
{ 0x0a0dc685, "2.0b1", "f657dc8ff25e93b877305bbcfc45e360191bb326" },
{ 0x0a0dc686, "2.0b1", "f657dc8ff25e93b877305bbcfc45e360191bb326" },
{ 0x0a0dc686, "2.0b1", "1b9fd0cbd914947cc421ba7e45aa093d7ba9af00" },
{ 0x0a0dc687, "2.0b1", "1b9fd0cbd914947cc421ba7e45aa093d7ba9af00" },
{ 0x0a0dc687, "2.0b1", "1f1a156ed5af8f7a50ce05fc85f85423a24f2aa4" },
{ 0x0a0dc688, "2.0b1", "1f1a156ed5af8f7a50ce05fc85f85423a24f2aa4" },
{ 0x0a0deadc, "2.1a1", "fd8c7203251ff37dbb397f7d423ae41f16a03c68" },
{ 0x0a0deadd, "2.1a1", "fd8c7203251ff37dbb397f7d423ae41f16a03c68" },
{ 0x0a0deb2a, "2.1a2", "0076e8d28f9eba9eff4508696dc33730af2b4001" },
{ 0x0a0deb2b, "2.1a2", "0076e8d28f9eba9eff4508696dc33730af2b4001" },
{ 0x0a0dec04, "2.2a0", "32e7d0898eab85de8134f932680a85c6e7abcec0" },
{ 0x0a0dec05, "2.2a0", "32e7d0898eab85de8134f932680a85c6e7abcec0" },
{ 0x0a0ded2d, "2.2a1", "09df3254b49d7c9306585302fe815ab0bdb53439" },
{ 0x0a0ded2e, "2.2a1", "09df3254b49d7c9306585302fe815ab0bdb53439" },
{ 0x0a0df231, "2.3a0", "abedb2418f6231adf24205092a59996f1f1e4c02" },
{ 0x0a0df232, "2.3a0", "abedb2418f6231adf24205092a59996f1f1e4c02" },
{ 0x0a0df23b, "2.3a0", "d6ae544acd24a1f72ce00534fed464fde91ee504" },
{ 0x0a0df23c, "2.3a0", "d6ae544acd24a1f72ce00534fed464fde91ee504" },
{ 0x0a0df245, "2.3a0", "cf5928fab108de9fbe02632d07176c717c2b3aa7" },
{ 0x0a0df246, "2.3a0", "cf5928fab108de9fbe02632d07176c717c2b3aa7" },
{ 0x0a0df24f, "2.4a0", "adb42a71169604d3609ac2fbdb64cf8cd1c7250b" },
{ 0x0a0df250, "2.4a0", "adb42a71169604d3609ac2fbdb64cf8cd1c7250b" },
{ 0x0a0df259, "2.4a0", "3df36e2e5ddc1149af8eb52e20bc225d806236d4" },
{ 0x0a0df25a, "2.4a0", "3df36e2e5ddc1149af8eb52e20bc225d806236d4" },
{ 0x0a0df263, "2.4a2", "1f9b9c226b43ed20cb61e6d21aea6cb966e8bcd3" },
{ 0x0a0df264, "2.4a2", "1f9b9c226b43ed20cb61e6d21aea6cb966e8bcd3" },
{ 0x0a0df26d, "2.4a3", "2b49b4a85d9eb4a4cfa9f29c21d649c383945671" },
{ 0x0a0df26e, "2.4a3", "2b49b4a85d9eb4a4cfa9f29c21d649c383945671" },
{ 0x0a0df277, "2.5a0", "44e3f21f052590ddfabc12909af5188a4cd89d8c" },
{ 0x0a0df278, "2.5a0", "44e3f21f052590ddfabc12909af5188a4cd89d8c" },
{ 0x0a0df281, "2.5a0", "eb15cdd4a2f1001792074ca0789026989452ff82" },
{ 0x0a0df282, "2.5a0", "eb15cdd4a2f1001792074ca0789026989452ff82" },
{ 0x0a0df28b, "2.5a0", "b6d2f6fd3e116b9b9fe95bc982ac763c359ff103" },
{ 0x0a0df28c, "2.5a0", "b6d2f6fd3e116b9b9fe95bc982ac763c359ff103" },
{ 0x0a0df28c, "2.5a0", "5c36c222e7ca5310e5cc8b8db283bd669d1e24d4" },
{ 0x0a0df28d, "2.5a0", "5c36c222e7ca5310e5cc8b8db283bd669d1e24d4" },
{ 0x0a0df295, "2.5b2", "2c3ec720aa7beb0da4002b847cc5ed7dc782566c" },
{ 0x0a0df296, "2.5b2", "2c3ec720aa7beb0da4002b847cc5ed7dc782566c" },
{ 0x0a0df29f, "2.5b2", "b745b3fd66a649a5fa540bdf47971c26af0a959e" },
{ 0x0a0df2a0, "2.5b2", "b745b3fd66a649a5fa540bdf47971c26af0a959e" },
{ 0x0a0df2a9, "2.5c3", "b90a8b0395bd43fd193842451d0c49573b4d7166" },
{ 0x0a0df2aa, "2.5c3", "b90a8b0395bd43fd193842451d0c49573b4d7166" },
{ 0x0a0df2b3, "2.6a0", "8dcb882ec3e1aac7d336a40aa64ec66561fc3dec" },
{ 0x0a0df2b4, "2.6a0", "8dcb882ec3e1aac7d336a40aa64ec66561fc3dec" },
{ 0x0a0df2bd, "2.6a0", "3985d7e2067db75f170e0891994b0fd70963e40b" },
{ 0x0a0df2be, "2.6a0", "3985d7e2067db75f170e0891994b0fd70963e40b" },
{ 0x0a0df2c7, "2.6a0", "07aa19170a673da6b3e8c4c66bfd868b2f90c0e4" },
{ 0x0a0df2c8, "2.6a0", "07aa19170a673da6b3e8c4c66bfd868b2f90c0e4" },
{ 0x0a0df2d1, "2.6a1+", "343597c7d682b3552580352deddd0cdb36978a04" },
{ 0x0a0df2d2, "2.6a1+", "343597c7d682b3552580352deddd0cdb36978a04" },
{ 0x0a0df2d3, "2.6a1+", "eac41f90296c69c6d07d29f1feb453a4c0e400d1" },
{ 0x0a0df2d4, "2.6a1+", "eac41f90296c69c6d07d29f1feb453a4c0e400d1" },
{ 0x0a0df2db, "2.7a0", "94e79d78dff0dfb5c53f49842c7df65ad5b79e66" },
{ 0x0a0df2dc, "2.7a0", "94e79d78dff0dfb5c53f49842c7df65ad5b79e66" },
{ 0x0a0df2e5, "2.7a0", "ef8fe90886968b1eb468cb91ebae103f773fa17f" },
{ 0x0a0df2e6, "2.7a0", "ef8fe90886968b1eb468cb91ebae103f773fa17f" },
{ 0x0a0df2ef, "2.7a0", "145376df3ad728f7052fdd8b6eba600a8317fece" },
{ 0x0a0df2f0, "2.7a0", "145376df3ad728f7052fdd8b6eba600a8317fece" },
{ 0x0a0df2f9, "2.7a2+", "c2fdf25329ff30cf8d68c0c0e7cf479d7b203745" },
{ 0x0a0df2fa, "2.7a2+", "c2fdf25329ff30cf8d68c0c0e7cf479d7b203745" },
{ 0x0a0df303, "2.7a2+", "edfed0e32cedf3b84c6e999052486a750a3f5bee" },
{ 0x0a0df304, "2.7a2+", "edfed0e32cedf3b84c6e999052486a750a3f5bee" },
{ 0x0a0d0bb8, "3.0x", "49c6eb688906b1dddabf578f08129e6729d6151f" },
{ 0x0a0d0bb9, "3.0x", "49c6eb688906b1dddabf578f08129e6729d6151f" },
{ 0x0a0d0bc2, "3.0x", "f87a3e61853d72b1d133992f991e397b31aac8e8" },
{ 0x0a0d0bc3, "3.0x", "f87a3e61853d72b1d133992f991e397b31aac8e8" },
{ 0x0a0d0bcc, "3.0x", "d0b83c4630c0924df661063543f3c5478c8c35ac" },
{ 0x0a0d0bcd, "3.0x", "d0b83c4630c0924df661063543f3c5478c8c35ac" },
{ 0x0a0d0bd6, "3.0x", "1cce0526d9b0a53f4ff95713dde153dc70dae2dc" },
{ 0x0a0d0bd7, "3.0x", "1cce0526d9b0a53f4ff95713dde153dc70dae2dc" },
{ 0x0a0d0be0, "3.0x", "7a35d3d1ac5a301ef3dc52f9140844f0422011a5" },
{ 0x0a0d0be1, "3.0x", "7a35d3d1ac5a301ef3dc52f9140844f0422011a5" },
{ 0x0a0d0bea, "3.0x", "793e0323d4d65bfc89b40d78162cd771c575a18e" },
{ 0x0a0d0beb, "3.0x", "793e0323d4d65bfc89b40d78162cd771c575a18e" },
{ 0x0a0d0bf4, "3.0x", "19f7ff443718f7a9da1aea9edbf00a135f860883" },
{ 0x0a0d0bf5, "3.0x", "19f7ff443718f7a9da1aea9edbf00a135f860883" },
{ 0x0a0d0bfe, "3.0a1", "a89d469e1ff77716914ce1a4244fa529a71ce68a" },
{ 0x0a0d0bff, "3.0a1", "a89d469e1ff77716914ce1a4244fa529a71ce68a" },
{ 0x0a0d0c08, "3.0a1", "19319e70fc3edbb45b2d007161c1b3a1de094181" },
{ 0x0a0d0c09, "3.0a1", "19319e70fc3edbb45b2d007161c1b3a1de094181" },
{ 0x0a0d0c12, "3.0a1+", "0d462d789b18ec6a59ebe2116688d5b6985c215d" },
{ 0x0a0d0c13, "3.0a1+", "0d462d789b18ec6a59ebe2116688d5b6985c215d" },
{ 0x0a0d0c1c, "3.0a2", "4dc01402d78afe2c9b4a4bd8004eb08e2647335d" },
{ 0x0a0d0c1d, "3.0a2", "4dc01402d78afe2c9b4a4bd8004eb08e2647335d" },
{ 0x0a0d0c1e, "3.0a2+", "73e1bf179a01ad7824ff5aa2b29ce068a457cd67" },
{ 0x0a0d0c1f, "3.0a2+", "73e1bf179a01ad7824ff5aa2b29ce068a457cd67" },
{ 0x0a0d0c26, "3.0a3+", "832c820e9d144cb76c8778ad6fcffe232b1f5c46" },
{ 0x0a0d0c27, "3.0a3+", "832c820e9d144cb76c8778ad6fcffe232b1f5c46" },
{ 0x0a0d0c3a, "3.0a5+", "212a1fee6bf93f8b74f81dd3567bf964e627ea20" },
{ 0x0a0d0c3b, "3.0a5+", "212a1fee6bf93f8b74f81dd3567bf964e627ea20" },
{ 0x0a0d0c44, "3.1a0", "2ee4653927f72f9bb3ff14b3083d4a203d684dfc" },
{ 0x0a0d0c45, "3.1a0", "2ee4653927f72f9bb3ff14b3083d4a203d684dfc" },
{ 0x0a0d0c4e, "3.1a0", "643d8d4fc8ebcc69155d3416357aadca9c053388" },
{ 0x0a0d0c4f, "3.1a0", "643d8d4fc8ebcc69155d3416357aadca9c053388" },
{ 0x0a0d0c58, "3.2a0", "3aaf2e065db05401803705ed4bfa3fd2f9030df8" },
{ 0x0a0d0c59, "3.2a0", "3aaf2e065db05401803705ed4bfa3fd2f9030df8" },
{ 0x0a0d0c62, "3.2a1+", "72523121127327c022096d30e7b28a4a5a89495d" },
{ 0x0a0d0c6c, "3.2a2+", "252895d491570d5a27452809b582717be409b24d" },
{ 0x0a0d0c76, "3.3a0", "9a6d9ac6fb2e1bb15bbb4e8c2a6c939d07088477" },
{ 0x0a0d0c80, "3.3.0a0", "e1dbc72bd97f36c1aed7e3ba2a58278f4da807be" },
{ 0x0a0d0c8a, "3.3.0a0", "87331661042b89022f6f49506ae9c1ae459a95be" },
{ 0x0a0d0c94, "3.3.0a1+", "c0a6569fdad624cc89cdd24b68331dc2a9b64827" },
{ 0x0a0d0c9e, "3.3.0a3+", "96ab78ef82a775da11a538fc47aebe70d9c34f04" },
{ 0x0a0d0ca8, "3.4.0a0", "d296cf1600a8c2c7098737944b5ee793b67a6883" },
{ 0x0a0d0cb2, "3.4.0a0", "2528e4aea33801b40ec902a77b5451ebc925a331" },
{ 0x0a0d0cbc, "3.4.0a0", "cf65c7a75f558e6cd68903f4c2800f6b9574a35f" },
{ 0x0a0d0cc6, "3.4.0a0", "3d858f1eef546e6adb2c073be9384065cfc2537e" },
{ 0x0a0d0cd0, "3.4.0a0", "6db3741e59be2b6427032a0f51d8a06625d64c28" },
{ 0x0a0d0cda, "3.4.0a3+", "35b384ed594b4618a7ea345dad7d2149eabcf3e7" },
{ 0x0a0d0ce4, "3.4.0a3+", "bb2affc1e317a85c4edfe450c119bdec851a08ee" },
{ 0x0a0d0cee, "3.4.0rc1+", "e301a515f8f4c5cdde3b9726ec298bd4de1af963" },
{ 0x0a0d0cf8, "3.5.0a0", "c553d8f72d659b3bc14fe326662ba53ca97bf38a" },
{ 0x0a0d0d02, "3.5.0a4+", "a65f685ba8c011bf117cadf26c13ab7a0cbb122c" },
{ 0x0a0d0d0c, "3.5.0b1+", "6f05f83c7010764aff53793fbff162c42018f57e" },
{ 0x0a0d0d16, "3.5.0b2+", "7a0a1a4ac63942f4ea3c7804e323adf668d40a21" },
{ 0x0a0d0d20, "3.6.0a0", "1ddeb2e175df5009571b3632a709c6b74995cb29" },
{ 0x0a0d0d21, "3.6.0a0", "775b74e0e103f816382a0fc009b6ac51ea956750" },
{ 0x0a0d0d33, "v3.6.0", "5c4568a05a0a62b5947c55f68f9f2ecfb90a4f12" },
{ 0x0a0d0d2c, "v3.6.0a2", "fa42893546010a0c649ba0d85d41a8bb980086f0" },
{ 0x0a0d0d2c, "v3.6.0a3", "a731a68cf6611b0b23da758d735f056ff661757e" },
{ 0x0a0d0d2c, "v3.6.0a4", "b87d6000f38e6158bbe1d9df5c6136f27aeace12" },
{ 0x0a0d0d31, "v3.6.0b1", "beb798cad6a6013d5a606ea0cd19640b35b468ea" },
{ 0x0a0d0d32, "v3.6.0b2", "7e16af499b92def6fc4ab1bbcecd2c055a38de29" },
{ 0x0a0d0d32, "v3.6.0b3", "0ef256c2b09cca0990d8d3767de943096dd61a07" },
{ 0x0a0d0d32, "v3.6.0b4", "38c508a00c32a6ce45a10b705adf8c818fa49dcd" },
{ 0x0a0d0d33, "v3.6.0rc1", "ad2c2d380e7ebbd31712ceb59e87e84b8a7c131d" },
{ 0x0a0d0d33, "v3.6.0rc2", "f7b280956df077b90c5983eeabc8accdbb0aeb8d" },
{ 0x0a0d0d33, "v3.6.1", "208f61cc7a5dbc9879ae6e5c2f95891e270f09ef" },
{ 0x0a0d0d33, "v3.6.10", "ff1e26c1da1d89c5ddb3bfdfdbe5bcdf68b14990" },
{ 0x0a0d0d33, "v3.6.10rc", "6e40b45ef295e91febc75b9597033c18425cc36f" },
{ 0x0a0d0d33, "v3.6.1rc1", "ef16e250bd9864c4dd07e9d128ea871a7604c0f6" },
{ 0x0a0d0d33, "v3.6.2", "84d6b204565614fc9ae672fb5b8c6f2fd13afd34" },
{ 0x0a0d0d33, "v3.6.2rc1", "c34b7ba8183311504042966c658116083c0fd1ec" },
{ 0x0a0d0d33, "v3.6.2rc2", "62922b8b6550c0e80580e9a79dcce9d792358300" },
{ 0x0a0d0d33, "v3.6.3", "7a8e13423f3cc8cbacece5b8d40c9a78ed2ce468" },
{ 0x0a0d0d33, "v3.6.3rc1", "5dea35ed4d74f4a660e0cb848c76cb91a80ef284" },
{ 0x0a0d0d33, "v3.6.4", "f40976d661609cba85458040512ac2bbceeb3756" },
{ 0x0a0d0d33, "v3.6.4rc1", "73f3fb83724c0d3cc7361e57988196d657e21933" },
{ 0x0a0d0d33, "v3.6.5", "0a295395451a7f0366995f7c645da35255d640d7" },
{ 0x0a0d0d33, "v3.6.5rc1", "87c4b938b9d22bc17113d9548a11c24b6bf44490" },
{ 0x0a0d0d33, "v3.6.6", "5a62cf854bec500e3ee252624e39dbdaf66362a0" },
{ 0x0a0d0d33, "v3.6.6rc1", "9d7889210ba48b6fde9fac464fff1725d2dbdc1d" },
{ 0x0a0d0d33, "v3.6.7", "5ebb4a6fe4fc0981d427c9d417d12b6d92cb9fea" },
{ 0x0a0d0d33, "v3.6.7rc1", "9883b7245756a44f5c51870abb32d711dfc46df7" },
{ 0x0a0d0d33, "v3.6.7rc2", "923364c5da68e958d69383a56036ca3bb4def006" },
{ 0x0a0d0d33, "v3.6.8", "50dca05a9c8574e293a5486bb36f0e41f3786628" },
{ 0x0a0d0d33, "v3.6.8rc1", "036b0b3833a10aef6e326d8369524fd61f49ffc7" },
{ 0x0a0d0d33, "v3.6.9", "3406378668cca081c0747e765cfe9dc80bdefa89" },
{ 0x0a0d0d33, "v3.6.9rc1", "734d1d9fbb7cc685b13a11f081e6afa35df3b27f" },
{ 0x0a0d0d3e, "v3.7.0a1", "c9a8ad52ed621cd429361c12bf96d019e79eac84" },
{ 0x0a0d0d3f, "v3.7.0a2", "02ffd31e928bfb492ec4f23635590df36ddda134" },
{ 0x0a0d0d3f, "v3.7.0a3", "4ccd273feeb9692d7171d2923969359e58c96498" },
{ 0x0a0d0d40, "v3.7.0a4", "682d0dbdd1e7436f54a9a8f57e22cbfc5147c4c3" },
{ 0x0a0d0d41, "v3.7.0b1", "1401315d067812555e5f45d2111cdf4a2564fcef" },
{ 0x0a0d0d41, "v3.7.0b2", "511db7b8ecceb74fb2e738ce41e5394516b871f8" },
{ 0x0a0d0d41, "v3.7.0b3", "aa8b7b7c6c1dbe44789745108396b20b85dbec39" },
{ 0x0a0d0d41, "v3.7.0b4", "58bb10ac350a934a2cd75506d6cc70cdb2e0ee3b" },
{ 0x0a0d0d42, "v3.7.0", "ae1f6af15f3e4110616801e235873e47fd7d1977" },
{ 0x0a0d0d42, "v3.7.0b5", "6f05d12b03c4681d6488645e027b5bc5c19ce406" },
{ 0x0a0d0d42, "v3.7.0rc1", "2cbc466248a1a5b6b2639d6cf63945e71446b857" },
{ 0x0a0d0d42, "v3.7.1", "520d6b8e38c078e5560597592c790ce160c8d75c" },
{ 0x0a0d0d42, "v3.7.1rc1", "c05eb2f1bba48c803d54ce12fc00de87b69d5e06" },
{ 0x0a0d0d42, "v3.7.1rc2", "a2644156afbb499582326df7c7e2ec95d6a3373e" },
{ 0x0a0d0d42, "v3.7.2", "e15c3ed43c574400443edc785b5b44b812df0407" },
{ 0x0a0d0d42, "v3.7.2rc1", "fc9123bd8b773d25ba03f04a85139caf53a91715" },
{ 0x0a0d0d42, "v3.7.3", "0b8794d19c9f51451155b1f7ad235aa046632c8c" },
{ 0x0a0d0d42, "v3.7.3rc1", "cb702f0f6b05d1e6d1e1e4449a1e61cd535617d8" },
{ 0x0a0d0d42, "v3.7.4", "e4539bae82b5dc645fd99cbc869d2fba3067a4ee" },
{ 0x0a0d0d42, "v3.7.4rc1", "da3644267b7c7614e55b7e33228ce31ce2749f2a" },
{ 0x0a0d0d42, "v3.7.4rc2", "50745cbf2d7ca594e256fa96ea00a93a53f2ac96" },
{ 0x0a0d0d42, "v3.7.5", "dc8ada53cff5e8e8f9c20587ab6afc2152b2888f" },
{ 0x0a0d0d42, "v3.7.5rc1", "4d4c87da17c34d9eb169801d6bc01158c00171dc" },
{ 0x0a0d0d42, "v3.7.6", "ef8e77cea43fb83c1398d058b8f639fede8fba76" },
{ 0x0a0d0d42, "v3.7.6rc1", "73ffb22c7f371ff4ea04fdee86a8e71ce1ba56f9" },
{ 0x0a0d0d49, "v3.8.0a1", "8cb4789728241d25bca2c15568317c6655389f1b" },
{ 0x0a0d0d49, "v3.8.0a2", "c31af9d3dd4560d12dfe943347379f0fc6f47a50" },
{ 0x0a0d0d49, "v3.8.0a3", "d53bead39cd475e581c13307b7838160e603a6fd" },
{ 0x0a0d0d52, "v3.8.0a4", "1b3497f679823b0368fabc95ccd1a1c24b8d429e" },
{ 0x0a0d0d52, "v3.8.0b1", "5191895b326e520473c501736239271685a2a077" },
{ 0x0a0d0d53, "v3.8.0b2", "0bb25c6b3dc78355870758bdf88d1d543cdf4203" },
{ 0x0a0d0d54, "v3.8.0b3", "108336b63a31356dc9c1f35f91843d6893e26e00" },
{ 0x0a0d0d55, "v3.8.0", "5d714034866ce1e9f89dc141fe4cc0b50cf20a8e" },
{ 0x0a0d0d55, "v3.8.0b4", "122a9b489cfe94b04801d057e5b510d51710fab3" },
{ 0x0a0d0d55, "v3.8.0rc1", "41f60748364a6afda7360e6cc6e846af569b7ab9" },
{ 0x0a0d0d55, "v3.8.1", "d2529ef779ce819a5ea833b264e47440efcbac29" },
{ 0x0a0d0d55, "v3.8.1rc1", "827f6399a61be9d14f8ccfa5be73a6030ec45f1d" },
{ 0x0a0d0d5c, "v3.9.0a1", "fd757083df79c21eee862e8d89aeefefe45f64a0" },
{ 0x0a0d0d5e, "v3.9.0a2", "bf0a31c8fb782e03e9530c2488ab2d0e29fc0495" },
{ 0x0a0d0d60, "v3.9.0a3", "a36ea266c6470f6c65416f24de4497637e59af23" },
};
struct pyc_version get_pyc_version(ut32 magic) {
struct pyc_version fail = {-1, 0, 0, false};
struct pyc_version fail = {-1, 0, 0};
ut32 i;
for (i = 0; i < sizeof (versions) / sizeof (*versions); ++i)
if (versions[i].magic == magic)
if (versions[i].magic == magic) {
return versions[i];
}
return fail;
}
bool magic_int_within(ut32 target_magic, ut32 lower, ut32 upper, bool *error) {
if (*error) {
return false;
}
ut64 ti = 0, li = 0, ui = 0;
ut64 size = sizeof(versions) / sizeof(struct pyc_version);
for (; ti < size && versions[ti].magic != target_magic; ++ti) {}
if (ti == size) {
*error = true;
eprintf("target_magic not found in versions[]");
return false;
}
for (; li < size && (versions[li].magic & 0xffff) != lower; ++li) {}
if (li == size) {
*error = true;
eprintf("lower magic_int not found in versions[]");
return false;
}
for (; ui < size && (versions[ui].magic & 0xffff) != upper; ++ui) {}
if (ui == size) {
*error = true;
eprintf("upper magic_int not found in versions[]");
return false;
}
return (li <= ti) && (ti <= ui);
}
double version2double(const char *version) {
unsigned idx = 0, buf_idx = 0;
char buf[20];
double result;
while (!('0' <= version[idx] && version[idx] <= '9'))
++idx;
for (; version[idx] != '.'; ++idx)
buf[buf_idx++] = version[idx];
buf[buf_idx++] = version[idx++];
for (; '0' <= version[idx] && version[idx] <= '9'; ++idx)
buf[buf_idx++] = version[idx];
buf[buf_idx] = '\x00';
sscanf (buf, "%lf", &result);
return result;
}
+5 -144
View File
@@ -1,159 +1,20 @@
/* radare - LGPL3 - Copyright 2016 - Matthieu (c0riolis) Tardy */
/* radare - LGPL3 - Copyright 2016-2020 - c0riolis, x0urc3 */
#ifndef PYC_MAGIC_H
#define PYC_MAGIC_H
#include <r_types.h>
#define MAGIC_0_9_4_BETA 0x00949494
#define MAGIC_0_9_9_v0 0x0099be2a
#define MAGIC_0_9_9_v1 0x0099be3a
#define MAGIC_0_9_9_v2 0x00999901
#define MAGIC_1_0_1 0x00999902
#define MAGIC_1_1 0x00999903
#define MAGIC_1_2 0x0a0d4127
#define MAGIC_1_3_B1 0x0a0d2e89
#define MAGIC_1_4_B1_v0 0x0a0d0767
#define MAGIC_1_4_B1_v1 0x0a0d1704
#define MAGIC_1_4 0x0a0d4e95
#define MAGIC_1_5_A1 0x0a0d4e99
#define MAGIC_1_6_A2 0x0a0dc4fc
#define MAGIC_2_0_B1_v0 0x0a0dc61b
#define MAGIC_2_0_B1_v1 0x0a0dc4fc
#define MAGIC_2_0_B1_v1_U 0x0a0dc4fd
#define MAGIC_2_0_B1_v2 0x0a0dc67b
#define MAGIC_2_0_B1_v2_U 0x0a0dc67c
#define MAGIC_2_0_B1_v3 0x0a0dc67f
#define MAGIC_2_0_B1_v3_U 0x0a0dc680
#define MAGIC_2_0_B1_v4 0x0a0dc685
#define MAGIC_2_0_B1_v4_U 0x0a0dc686
#define MAGIC_2_0_B1_v5 0x0a0dc686
#define MAGIC_2_0_B1_v5_U 0x0a0dc687
#define MAGIC_2_0_B1_v6 0x0a0dc687
#define MAGIC_2_0_B1_v6_U 0x0a0dc688
#define MAGIC_2_1_A1 0x0a0deadc
#define MAGIC_2_1_A1_U 0x0a0deadd
#define MAGIC_2_1_A2 0x0a0deb2a
#define MAGIC_2_1_A2_U 0x0a0deb2b
#define MAGIC_2_2_A0 0x0a0dec04
#define MAGIC_2_2_A0_U 0x0a0dec05
#define MAGIC_2_2_A1 0x0a0ded2d
#define MAGIC_2_2_A1_U 0x0a0ded2e
#define MAGIC_2_3_A0_v0 0x0a0df231
#define MAGIC_2_3_A0_v0_U 0x0a0df232
#define MAGIC_2_3_A0_v1 0x0a0df23b
#define MAGIC_2_3_A0_v1_U 0x0a0df23c
#define MAGIC_2_3_A0_v2 0x0a0df245
#define MAGIC_2_3_A0_v2_U 0x0a0df246
#define MAGIC_2_3_A0_v3 0x0a0df23b
#define MAGIC_2_3_A0_v3_U 0x0a0df23c
#define MAGIC_2_4_A0_v0 0x0a0df24f
#define MAGIC_2_4_A0_v0_U 0x0a0df250
#define MAGIC_2_4_A0_v1 0x0a0df259
#define MAGIC_2_4_A0_v1_U 0x0a0df25a
#define MAGIC_2_4_A2 0x0a0df263
#define MAGIC_2_4_A2_U 0x0a0df264
#define MAGIC_2_4_A3 0x0a0df26d
#define MAGIC_2_4_A3_U 0x0a0df26e
#define MAGIC_2_5_A0_v0 0x0a0df277
#define MAGIC_2_5_A0_v0_U 0x0a0df278
#define MAGIC_2_5_A0_v1 0x0a0df281
#define MAGIC_2_5_A0_v1_U 0x0a0df282
#define MAGIC_2_5_A0_v2 0x0a0df28b
#define MAGIC_2_5_A0_v2_U 0x0a0df28c
#define MAGIC_2_5_A0_v3 0x0a0df28c
#define MAGIC_2_5_A0_v3_U 0x0a0df28d
#define MAGIC_2_5_B2_v0 0x0a0df295
#define MAGIC_2_5_B2_v0_U 0x0a0df296
#define MAGIC_2_5_B2_v1 0x0a0df29f
#define MAGIC_2_5_B2_v1_U 0x0a0df2a0
#define MAGIC_2_5_C3 0x0a0df2a9
#define MAGIC_2_5_C3_U 0x0a0df2aa
#define MAGIC_2_6_A0_v0 0x0a0df2b3
#define MAGIC_2_6_A0_v0_U 0x0a0df2b4
#define MAGIC_2_6_A0_v1 0x0a0df2bd
#define MAGIC_2_6_A0_v1_U 0x0a0df2be
#define MAGIC_2_6_A0_v2 0x0a0df2c7
#define MAGIC_2_6_A0_v2_U 0x0a0df2c8
#define MAGIC_2_6_A1_PLUS_v0 0x0a0df2d1
#define MAGIC_2_6_A1_PLUS_v0_U 0x0a0df2d2
#define MAGIC_2_6_A1_PLUS_v1 0x0a0df2d3
#define MAGIC_2_6_A1_PLUS_v1_U 0x0a0df2d4
#define MAGIC_2_6_A1_PLUS_v2 0x0a0df2d1
#define MAGIC_2_6_A1_PLUS_v2_U 0x0a0df2d2
#define MAGIC_2_7_A0_v0 0x0a0df2db
#define MAGIC_2_7_A0_v0_U 0x0a0df2dc
#define MAGIC_2_7_A0_v1 0x0a0df2e5
#define MAGIC_2_7_A0_v1_U 0x0a0df2e6
#define MAGIC_2_7_A0_v2 0x0a0df2ef
#define MAGIC_2_7_A0_v2_U 0x0a0df2f0
#define MAGIC_2_7_A2_PLUS_v0 0x0a0df2f9
#define MAGIC_2_7_A2_PLUS_v0_U 0x0a0df2fa
#define MAGIC_2_7_A2_PLUS_v1 0x0a0df303
#define MAGIC_2_7_A2_PLUS_v1_U 0x0a0df304
#define MAGIC_3_0X_v0 0x0a0d0bb8
#define MAGIC_3_0X_v0_U 0x0a0d0bb9
#define MAGIC_3_0X_v1 0x0a0d0bc2
#define MAGIC_3_0X_v1_U 0x0a0d0bc3
#define MAGIC_3_0X_v2 0x0a0d0bcc
#define MAGIC_3_0X_v2_U 0x0a0d0bcd
#define MAGIC_3_0X_v3 0x0a0d0bd6
#define MAGIC_3_0X_v3_U 0x0a0d0bd7
#define MAGIC_3_0X_v4 0x0a0d0be0
#define MAGIC_3_0X_v4_U 0x0a0d0be1
#define MAGIC_3_0X_v5 0x0a0d0bea
#define MAGIC_3_0X_v5_U 0x0a0d0beb
#define MAGIC_3_0X_v6 0x0a0d0bf4
#define MAGIC_3_0X_v6_U 0x0a0d0bf5
#define MAGIC_3_0_A1_v0 0x0a0d0bfe
#define MAGIC_3_0_A1_v0_U 0x0a0d0bff
#define MAGIC_3_0_A1_v1 0x0a0d0c08
#define MAGIC_3_0_A1_v1_U 0x0a0d0c09
#define MAGIC_3_0_A1_PLUS 0x0a0d0c12
#define MAGIC_3_0_A1_PLUS_U 0x0a0d0c13
#define MAGIC_3_0_A2 0x0a0d0c1c
#define MAGIC_3_0_A2_U 0x0a0d0c1d
#define MAGIC_3_0_A2_PLUS 0x0a0d0c1e
#define MAGIC_3_0_A2_PLUS_U 0x0a0d0c1f
#define MAGIC_3_0_A3_PLUS 0x0a0d0c26
#define MAGIC_3_0_A3_PLUS_U 0x0a0d0c27
#define MAGIC_3_0_A5_PLUS 0x0a0d0c3a
#define MAGIC_3_0_A5_PLUS_U 0x0a0d0c3b
#define MAGIC_3_1_A0_v0 0x0a0d0c44
#define MAGIC_3_1_A0_v0_U 0x0a0d0c45
#define MAGIC_3_1_A0_v1 0x0a0d0c4e
#define MAGIC_3_1_A0_v1_U 0x0a0d0c4f
#define MAGIC_3_2_A0 0x0a0d0c58
#define MAGIC_3_2_A0_U 0x0a0d0c59
#define MAGIC_3_2_A1_PLUS_U 0x0a0d0c62
#define MAGIC_3_2_A2_PLUS_U 0x0a0d0c6c
#define MAGIC_3_3_A0_U 0x0a0d0c76
#define MAGIC_3_3_0_A0_v0_U 0x0a0d0c80
#define MAGIC_3_3_0_A0_v1_U 0x0a0d0c8a
#define MAGIC_3_3_0_A1_PLUS_U 0x0a0d0c94
#define MAGIC_3_3_0_A3_PLUS_U 0x0a0d0c9e
#define MAGIC_3_4_0_A0_v0_U 0x0a0d0ca8
#define MAGIC_3_4_0_A0_v1_U 0x0a0d0cb2
#define MAGIC_3_4_0_A0_v2_U 0x0a0d0cbc
#define MAGIC_3_4_0_A0_v3_U 0x0a0d0cc6
#define MAGIC_3_4_0_A0_v4_U 0x0a0d0cd0
#define MAGIC_3_4_0_A3_PLUS_v0_U 0x0a0d0cda
#define MAGIC_3_4_0_A3_PLUS_v1_U 0x0a0d0ce4
#define MAGIC_3_4_0_RC1_PLUS_U 0x0a0d0cee
#define MAGIC_3_5_0_A0_U 0x0a0d0cf8
#define MAGIC_3_5_0_A4_PLUS_U 0x0a0d0d02
#define MAGIC_3_5_0_B1_PLUS_U 0x0a0d0d0c
#define MAGIC_3_5_0_B2_PLUS_U 0x0a0d0d16
#define MAGIC_3_6_0_A0_v0_U 0x0a0d0d20
#define MAGIC_3_6_0_A0_v1_U 0x0a0d0d21
struct pyc_version {
ut32 magic;
char *version;
char *revision;
bool unicode;
};
struct pyc_version get_pyc_version(ut32 magic);
double version2double(const char *version);
bool magic_int_within(ut32 target_magic, ut32 lower, ut32 uppper, bool *error);
#endif
+13 -14
View File
@@ -74,13 +74,13 @@ int r_bin_swf_get_sections(RList *list, RBinFile *arch) {
if (!(head_sect = R_NEW0 (RBinSection))) {
return false;
}
strcpy (head_sect->name, "Header");
head_sect->name = strdup ("Header");
head_sect->paddr = 0;
head_sect->vaddr = 0;
ut8 start = 0x8; // signature + version + size
head_sect->size = start;
head_sect->vsize = start;
head_sect->srwx = R_BIN_SCN_READABLE;
head_sect->perm = R_PERM_R;
r_list_append (list, head_sect);
/* ZlibData section */
@@ -89,12 +89,12 @@ int r_bin_swf_get_sections(RList *list, RBinFile *arch) {
if (!(data = R_NEW0 (RBinSection)))
return false;
snprintf(data->name, R_BIN_SIZEOF_STRINGS, "ZlibData");
data->name = strdup ("ZlibData");
data->paddr = start;
data->vaddr = start;
data->size = r_buf_size(arch->buf) - start;
data->vsize = r_buf_size(arch->buf) - start;
data->srwx = R_BIN_SCN_READABLE;
data->perm = R_PERM_R;
r_list_append (list, data);
} else if (header.signature[0] == ISWF_MAGIC_0_2) {
@@ -107,13 +107,13 @@ int r_bin_swf_get_sections(RList *list, RBinFile *arch) {
if (!(head_sect = R_NEW0 (RBinSection))) {
return false;
}
strcpy (head_sect->name, "Header");
head_sect->name = strdup ("Header");
head_sect->paddr = 0;
head_sect->vaddr = 0;
ut8 start = 0x8; // signature + version + size
head_sect->size = start;
head_sect->vsize = start;
head_sect->srwx = R_BIN_SCN_READABLE;
head_sect->perm = R_PERM_R;
r_list_append (list, head_sect);
/* LzmaData section */
@@ -121,12 +121,12 @@ int r_bin_swf_get_sections(RList *list, RBinFile *arch) {
if (!data) {
return false;
}
snprintf(data->name, R_BIN_SIZEOF_STRINGS, "LzmaData");
data->name = strdup ("LzmaData");
data->paddr = start;
data->vaddr = start;
data->size = r_buf_size(arch->buf) - start;
data->vsize = r_buf_size(arch->buf) - start;
data->srwx = R_BIN_SCN_READABLE;
data->perm = R_PERM_R;
r_list_append (list, data);
} else {
@@ -135,13 +135,13 @@ int r_bin_swf_get_sections(RList *list, RBinFile *arch) {
if (!(head_sect = R_NEW0 (RBinSection))) {
return false;
}
strcpy(head_sect->name, "Header");
head_sect->name = strdup ("Header");
head_sect->paddr = 0;
head_sect->vaddr = 0;
ut32 start = header.rect_size + SWF_HDR_MIN_SIZE; // rect + min_size
head_sect->size = start;
head_sect->vsize = start;
head_sect->srwx = R_BIN_SCN_READABLE;
head_sect->perm = R_PERM_R;
r_list_append (list, head_sect);
/* Other sections */
@@ -173,7 +173,7 @@ int r_bin_swf_get_sections(RList *list, RBinFile *arch) {
return false;
}
swf_tag_t tag = r_asm_swf_gettag (tagCode);
strcpy (new->name, tag.name);
new->name = strdup (tag.name);
new->paddr = start;
new->vaddr = start;
@@ -183,11 +183,11 @@ int r_bin_swf_get_sections(RList *list, RBinFile *arch) {
switch (tagCode) {
case TAG_DOACTION:
case TAG_DOINITACTION:
new->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE;
new->perm = R_PERM_RX;
new->has_strings = true;
break;
default:
new->srwx = R_BIN_SCN_READABLE;
new->perm = R_PERM_R;
break;
}
r_list_append (list, new);
@@ -196,7 +196,6 @@ int r_bin_swf_get_sections(RList *list, RBinFile *arch) {
r_buf_read_at (arch->buf, end, (ut8*)&tagCodeAndLength, 2);
section++;
}
}
return true;
+22 -12
View File
@@ -52,6 +52,12 @@ static bool check_bytes(const ut8 *buf, ut64 length) {
return false;
}
static bool check_buffer(RBuffer *b) {
ut8 buf[1024];
r_buf_read_at (b, 0, buf, sizeof (buf));
return check_bytes (buf, sizeof (buf));
}
static void *load_bytes(RBinFile *arch, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb) {
if (!buf || !sz || sz < sizeof (pcap_file_hdr_t) || sz == UT64_MAX) {
return NULL;
@@ -117,9 +123,9 @@ static void _read_ipv4_sym(RList *list, const ut8 *buf, ut64 off, ut64 sz, int e
ptr->name = r_str_newf ("0x%"PFMT64x": IPV%d, Src: %d.%d.%d.%d, Dst: %d.%d.%d.%d",
off, (ipv4.ver_len >> 4) & 0x0F, (ipv4.src >> 24) & 0xFF,
(ipv4.src >> 16) & 0xFF, (ipv4.src >> 8) & 0xFF,
ipv4.src && 0xFF, (ipv4.dst >> 24) & 0xFF,
ipv4.src & 0xFF, (ipv4.dst >> 24) & 0xFF,
(ipv4.dst >> 16) & 0xFF, (ipv4.dst >> 8) & 0xFF,
ipv4.dst && 0xFF);
ipv4.dst & 0xFF);
ptr->paddr = ptr->vaddr = off;
r_list_append (list, ptr);
if (off + ipv4.tot_len > sz) {
@@ -249,15 +255,15 @@ static RList *symbols(RBinFile *arch) {
RBinSymbol *ptr = NULL;
RList *ret = NULL;
pcap_obj_t *obj = NULL;
const ut8 *buf = NULL;
ut64 sz = 0;
ut64 off;
ut64 pkt_num = 0;
if (!arch || !arch->o || !arch->o->bin_obj || !arch->buf || !arch->buf->buf) {
if (!arch || !arch->o || !arch->o->bin_obj || !arch->buf) {
return NULL;
}
obj = arch->o->bin_obj;
buf = r_buf_buffer (arch->buf);
ut8 buf[1024]; // sizeof(pcap_file-hdr
r_buf_read_at (arch->buf, 0, buf, sizeof (buf));
sz = r_buf_size (arch->buf);
if (sz == 0 || sz == UT64_MAX) {
return NULL;
@@ -315,15 +321,15 @@ static RList *strings(RBinFile *arch) {
RBinString *ptr = NULL;
RList *ret = NULL;
pcap_obj_t *obj = NULL;
const ut8 *buf = NULL;
char *tmp = NULL;
ut64 sz = 0;
ut64 off;
if (!arch || !arch->o || !arch->o->bin_obj || !arch->buf || !arch->buf->buf) {
if (!arch || !arch->o || !arch->o->bin_obj || !arch->buf) {
return NULL;
}
obj = arch->o->bin_obj;
buf = r_buf_buffer (arch->buf);
ut8 buf[1024];
r_buf_read_at (arch->buf, 0, buf, sizeof (buf));
sz = r_buf_size (arch->buf);
if (sz == 0 || sz == UT64_MAX) {
return NULL;
@@ -412,25 +418,29 @@ static bool load(RBinFile *arch) {
if (!arch || !arch->o) {
return false;
}
const ut8 *bytes = r_buf_buffer (arch->buf);
ut64 size = r_buf_size (arch->buf);
ut8 *bytes = malloc (size);
if (!bytes || size == 0 || size == UT64_MAX) {
return false;
}
r_buf_read_at (arch->buf, 0, bytes, size);
arch->o->bin_obj = load_bytes (arch, bytes, size, arch->o->loadaddr, arch->sdb);
return arch->o->bin_obj != NULL;
}
static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) {
return load(bf);
}
RBinPlugin r_bin_plugin_pcap = {
.name = "pcap",
.desc = "libpcap .pcap format r2 plugin",
.license = "LGPL3",
.info = info,
.load = load,
.strings = strings,
.symbols = symbols,
.load_bytes = load_bytes,
.check_bytes = check_bytes,
.load_buffer= load_buffer,
.check_buffer = check_buffer,
};
#ifndef CORELIB
+73 -34
View File
@@ -1,26 +1,47 @@
/* radare - LGPL3 - Copyright 2016-2017 - Matthieu (c0riolis) Tardy */
/* radare - LGPL3 - Copyright 2016-2020 - c0riolis, x0urc3 */
#include <r_bin.h>
#include "pyc_magic.h"
#include "pyc.h"
#include "marshal.h"
// XXX: to not use globals
static ut64 code_start_offset = 0;
static struct pyc_version version;
/* used from marshall.c */
RList *interned_table = NULL;
static RList *sections_cache = NULL;
static bool check_bytes(const ut8 *buf, ut64 length) {
if (!buf || length < 8) {
// magic + timestamp
return false;
static bool check_buffer(RBuffer *b) {
if (r_buf_size (b) > 4) {
ut32 buf;
r_buf_read_at (b, 0, (ut8 *)&buf, sizeof (buf));
version = get_pyc_version (buf);
return version.magic != -1;
}
version = get_pyc_version (*(ut32*)buf);
return version.magic != -1;
return false;
}
static bool load_bytes(RBinFile *bf, void **bin_obj, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb) {
return check_bytes (buf, sz);
static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) {
return check_buffer (buf);
}
static ut64 get_entrypoint(RBuffer *buf) {
ut8 b;
ut64 result;
for (int addr = 0x8; addr <= 0x10; addr += 0x4) {
r_buf_read_at (buf, addr, &b, sizeof (b));
if (pyc_is_code (b, version.magic)) {
code_start_offset = addr;
r_buf_seek (buf, addr + 1, R_BUF_SET);
if ((result = get_code_object_addr (buf, version.magic)) == 0) {
return addr;
} else {
return result;
}
}
}
return 0;
}
static RBinInfo *info(RBinFile *arch) {
@@ -28,18 +49,43 @@ static RBinInfo *info(RBinFile *arch) {
if (!ret)
return NULL;
ret->file = strdup (arch->file);
ret->type = r_str_newf ("Python %s%s byte-compiled file", version.version,
version.unicode ? " Unicode" : "");
ret->type = r_str_newf ("Python %s byte-compiled file", version.version);
ret->bclass = strdup ("Python byte-compiled file");
ret->rclass = strdup ("pyc");
ret->machine = r_str_newf ("Python %s VM (rev %s)", version.version,
version.revision);
ret->os = strdup ("any");
ret->bits = 32;
ret->bits = version2double(version.version) < 3.6? 16: 8;
ret->cpu = strdup (version.version); // pass version info in cpu, Asm plugin will get it
return ret;
}
static RList *sections(RBinFile *arch) {
return sections_cache;
}
static RList *entries(RBinFile *arch) {
RList *entries = r_list_new ();
if (!entries) {
return NULL;
}
RBinAddr *addr = R_NEW0 (RBinAddr);
if (!addr) {
return NULL;
}
ut64 entrypoint = get_entrypoint (arch->buf);
addr->paddr = entrypoint;
addr->vaddr = entrypoint;
r_buf_seek (arch->buf, entrypoint, R_IO_SEEK_SET);
r_list_append (entries, addr);
return entries;
}
static ut64 baddr(RBinFile *bf) {
return 0;
}
static RList *symbols(RBinFile *arch) {
RList *shared = r_list_new ();
if (!shared) {
return NULL;
@@ -59,25 +105,16 @@ static RList *sections(RBinFile *arch) {
if (!sections) {
return NULL;
}
pyc_get_sections (sections, cobjs, arch->buf, version.magic);
return sections;
}
static RList *entries(RBinFile *arch) {
RList *entries = r_list_new ();
if (!entries) {
RList *symbols = r_list_new ();
if (!symbols) {
r_list_free (sections);
return NULL;
}
RBinAddr *addr = R_NEW0 (RBinAddr);
if (!addr) {
return NULL;
}
ut64 entrypoint = pyc_get_entrypoint (version.magic);
addr->paddr = entrypoint;
addr->vaddr = entrypoint;
r_buf_seek (arch->buf, entrypoint, R_IO_SEEK_CUR);
r_list_append (entries, addr);
return entries;
RBuffer *buffer = arch->buf;
r_buf_seek (buffer, code_start_offset, R_BUF_SET);
pyc_get_sections_symbols (sections, symbols, cobjs, buffer, version.magic);
sections_cache = sections;
return symbols;
}
RBinPlugin r_bin_plugin_pyc = {
@@ -85,14 +122,16 @@ RBinPlugin r_bin_plugin_pyc = {
.desc = "Python byte-compiled file plugin",
.license = "LGPL3",
.info = &info,
.load_bytes = &load_bytes,
.check_bytes = &check_bytes,
.load_buffer = &load_buffer,
.check_buffer = &check_buffer,
.entries = &entries,
.sections = &sections,
.baddr = &baddr,
.symbols = &symbols,
};
#ifndef CORELIB
RLibStruct radare_plugin = {
#ifndef R2_PLUGIN_INCORE
R_API RLibStruct radare_plugin = {
.type = R_LIB_TYPE_BIN,
.data = &r_bin_plugin_pyc,
.version = R2_VERSION,
+23 -13
View File
@@ -1,4 +1,4 @@
/* radare - LGPL3 - 2016 - xarkes */
/* radare - LGPL3 - 2016-2020 - xarkes */
#include <r_types.h>
#include <r_util.h>
@@ -7,14 +7,15 @@
#include "../format/swf/swf_specs.h"
#include "../format/swf/swf.h"
static int check(RBinFile *arch);
static int check_bytes(const ut8 *buf, ut64 length);
static bool check_buffer(RBuffer *b);
static char compression;
static char flashVersion;
static bool load_bytes(RBinFile *bf, void **bin_obj, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){
if (check_bytes (buf, sz)) {
static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *b, ut64 loadaddr, Sdb *sdb){
if (check_buffer (b)) {
ut8 buf[4];
r_buf_read_at (b, 0, buf, 4);
compression = buf[0];
flashVersion = buf[3];
return true;
@@ -22,12 +23,21 @@ static bool load_bytes(RBinFile *bf, void **bin_obj, const ut8 *buf, ut64 sz, ut
return false;
}
static int check_bytes(const ut8 *buf, ut64 length) {
if (!buf || length < 4) return false;
if ((*buf == ISWF_MAGIC_0_0 || *buf == ISWF_MAGIC_0_1 ||
*buf == ISWF_MAGIC_0_2) && (!memcmp (buf+1, ISWF_MAGIC, 2)))
return true;
static bool check_buffer(RBuffer *b) {
ut8 buf[4];
if (r_buf_size (b) < 4) {
return false;
}
r_buf_read_at (b, 0, buf, 4);
switch (buf[0]) {
case ISWF_MAGIC_0_0:
case ISWF_MAGIC_0_1:
case ISWF_MAGIC_0_2:
if (!memcmp (buf + 1, ISWF_MAGIC, 2)) {
return true;
}
break;
}
return false;
}
@@ -92,8 +102,8 @@ RBinPlugin r_bin_plugin_swf = {
.name = "swf",
.desc = "SWF",
.license = "LGPL3",
.load_bytes = &load_bytes,
.check_bytes = &check_bytes,
.load_buffer = &load_buffer,
.check_buffer = &check_buffer,
.entries = &entries,
.sections = &sections,
.info = &info,
+2 -1
View File
@@ -2,6 +2,7 @@ OBJ_PYC=bin_pyc.o
OBJ_PYC+=../format/pyc/marshal.o
OBJ_PYC+=../format/pyc/pyc_magic.o
OBJ_PYC+=../format/pyc/pyc.o
OBJ_PYC+=../format/pyc/bn.o
STATIC_OBJ+=${OBJ_PYC}
TARGET_PYC=bin_pyc.${LIBEXT}
@@ -10,5 +11,5 @@ CFLAGS+=-I../format/pyc/
ALL_TARGETS+=${TARGET_PYC}
${TARGET_PYC}: ${OBJ_PYC}
${CC} ${CFLAGS} -o ${TARGET_PYC} ${OBJ_PYC} $(R2_CFLAGS) $(R2_LDFLAGS) -lr_util -lgmp
${CC} ${CFLAGS} -o ${TARGET_PYC} ${OBJ_PYC} $(R2_CFLAGS) $(R2_LDFLAGS) -lr_util
+11 -10
View File
@@ -204,12 +204,11 @@ static RList *r_debug_unicorn_pids(RDebug *dbg, int pid) {
static RList *r_debug_unicorn_map_get(RDebug *dbg) {
RDebugMap *m;
RList *list;
SdbListIter *iter;
RIOMap *map;
int i = 0;
list = r_list_new ();
//list->free = r_debug_map_free;
ls_foreach (dbg->iob.io->maps, iter, map) {
r_vector_foreach (&dbg->iob.io->maps.v, map) {
m = r_debug_map_new (map->name,
map->itv.addr,
map->itv.addr + map->itv.size,
@@ -237,7 +236,7 @@ static RDebugInfo* r_debug_unicorn_info(RDebug *dbg, const char *arg) {
return rdi;
}
static RDebugMap * r_debug_unicorn_map_alloc(RDebug *dbg, ut64 addr, int size) {
static RDebugMap * r_debug_unicorn_map_alloc(RDebug *dbg, ut64 addr, int size, bool thp) {
RDebugMap *map;
uc_err err = uc_mem_map (uh, addr, size, UC_PROT_WRITE | UC_PROT_READ);
if (err) {
@@ -263,7 +262,7 @@ static int r_debug_unicorn_map_dealloc(RDebug *dbg, ut64 addr, int size) {
return 0;
}
static int r_debug_unicorn_detach(int pid) {
static int r_debug_unicorn_detach(RDebug *dbg, int pid) {
if (uh) {
/* unicorn lib doesnt checks for null. it just crashes -_-U */
uc_close (uh);
@@ -275,7 +274,7 @@ static int r_debug_unicorn_detach(int pid) {
static bool r_debug_unicorn_kill(RDebug *dbg, int pid, int tid, int sig) {
// TODO: implement thread support signaling here
message ("TODO: r_debug_unicorn_kill\n");
(void)r_debug_unicorn_detach(pid);
(void)r_debug_unicorn_detach(dbg, pid);
return false;
}
@@ -390,7 +389,10 @@ static void _insn_out(uc_engine *handle, uint32_t port, int size, uint32_t value
static bool _mem_invalid(uc_engine *handle, uc_mem_type type,
uint64_t address, int size, int64_t value, void *user_data) {
const char *typestr = "";
switch(type) {
switch (type) {
case UC_MEM_READ_AFTER:
typestr = "read-after";
break;
case UC_MEM_READ:
typestr = "read";
break;
@@ -485,7 +487,7 @@ static int r_debug_unicorn_attach(RDebug *dbg, int pid) {
return ret;
#endif
//if (!uh) {
r_debug_unicorn_detach (pid);
r_debug_unicorn_detach (dbg, pid);
r_debug_unicorn_init (dbg);
//}
return 'U' + 'N' + 'I' + 'C' + 'O' + 'R' + 'N';
@@ -508,7 +510,6 @@ static int r_debug_unicorn_wait(RDebug *dbg, int pid) {
}
static int r_debug_unicorn_init(RDebug *dbg) {
SdbListIter *iter;
int code_is_mapped;
RIOMap *map;
int bits = (dbg->bits & R_SYS_BITS_64) ? 64: 32;
@@ -532,7 +533,7 @@ static int r_debug_unicorn_init(RDebug *dbg) {
return false;
}
ut64 lastvaddr = 0LL;
int n_sect = ls_length (dbg->iob.io->maps);
size_t n_sect = dbg->iob.io->maps.v.len;
if (n_sect == 0) {
message (logo);
message ("[UNICORN] dpa # reatach to initialize the unicorn\n");
@@ -540,7 +541,7 @@ static int r_debug_unicorn_init(RDebug *dbg) {
}
code_is_mapped = 0;
ls_foreach (dbg->iob.io->maps, iter, map) {
r_vector_foreach (&dbg->iob.io->maps.v, map) {
int perms = 0;
if (map->perm & R_PERM_R) perms |= UC_PROT_READ;
if (map->perm & R_PERM_W) perms |= UC_PROT_WRITE;
+166 -68
View File
@@ -164,6 +164,13 @@ static char *get_field_imm15 (long instr)
return (tmpstr);
}
static char *get_field_imm5 (long instr)
{
char *tmpstr;
tmpstr = r_str_newf ("%u", (short)((instr & IMM5_MASK) >> IMM_LOW));
return (tmpstr);
}
static char *
get_field_special (long instr, struct op_code_struct * op)
{
@@ -244,7 +251,6 @@ static void analyse_arithmetic_inst_imm(struct mb_anal_ctx *ctx, unsigned long i
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);
@@ -254,40 +260,38 @@ static void analyse_arithmetic_inst_imm(struct mb_anal_ctx *ctx, unsigned long i
switch (mb_op->instr) {
case addi:
r_strbuf_appendf (&op->esil, "_imm,%s,+,%s,=", ra, rd);
r_strbuf_appendf (&op->esil, ",31,$c,c,=");
op->type = R_ANAL_OP_TYPE_ADD;
break;
case rsubi:
r_strbuf_appendf (&op->esil, "_imm,%s,-,%s,=", ra, rd);
r_strbuf_appendf (&op->esil, "%s,_imm,-,%s,=", ra, rd);
r_strbuf_appendf (&op->esil, ",1,$b,!,c,=");
op->type = R_ANAL_OP_TYPE_SUB;
break;
case addic:
/* should use carry */
r_strbuf_appendf (&op->esil, "_imm,%s,+,%s,=", ra, rd);
r_strbuf_appendf (&op->esil, "_imm,%s,+,c,+,%s,=", ra, rd);
r_strbuf_appendf (&op->esil, ",31,$c,c,=");
op->type = R_ANAL_OP_TYPE_ADD;
break;
case rsubic:
/* should use carry */
r_strbuf_appendf (&op->esil, "_imm,%s,-,%s,=", ra, rd);
r_strbuf_appendf (&op->esil, "%s,_imm,-,c,+,%s,=", ra, rd);
r_strbuf_appendf (&op->esil, ",1,$b,!,c,=");
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);
r_strbuf_appendf (&op->esil, "%s,_imm,-,%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);
r_strbuf_appendf (&op->esil, "_imm,%s,+,c,+,%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);
r_strbuf_appendf (&op->esil, "%s,_imm,-,c,+,%s,=", ra, rd);
op->type = R_ANAL_OP_TYPE_SUB;
break;
}
@@ -306,27 +310,29 @@ static void analyse_arithmetic_inst(struct mb_anal_ctx *ctx, unsigned long insn,
switch (mb_op->instr) {
case add:
r_strbuf_setf (&op->esil, "%s,%s,+,%s,=", ra, rb, rd);
r_strbuf_appendf (&op->esil, ",31,$c,c,=");
op->type = R_ANAL_OP_TYPE_ADD;
break;
case rsub:
r_strbuf_setf (&op->esil, "%s,%s,-,%s,=", ra, rb, rd);
r_strbuf_appendf (&op->esil, ",1,$b,!,c,=");
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);
r_strbuf_appendf (&op->esil, ",31,$c,c,=");
op->type = R_ANAL_OP_TYPE_ADD;
break;
case rsubc:
r_strbuf_setf (&op->esil, "%s,%s,-,c,+,%s,=", ra, rb, rd);
r_strbuf_appendf (&op->esil, ",1,$b,!,c,=");
op->type = R_ANAL_OP_TYPE_SUB;
break;
case addk:
/* should keep carry */
r_strbuf_setf (&op->esil, "%s,%s,+,%s,=", ra, rb, rd);
op->type = R_ANAL_OP_TYPE_ADD;
break;
case rsubk:
/* should keep carry */
r_strbuf_setf (&op->esil, "%s,%s,-,%s,=", ra, rb, rd);
op->type = R_ANAL_OP_TYPE_SUB;
break;
@@ -341,10 +347,11 @@ static void analyse_arithmetic_inst(struct mb_anal_ctx *ctx, unsigned long insn,
op->type = R_ANAL_OP_TYPE_CMP;
break;
case addkc:
r_strbuf_setf (&op->esil, "%s,%s,c,+,+,%s,=", ra, rb, rd);
r_strbuf_setf (&op->esil, "%s,%s,+,c,+,%s,=", ra, rb, rd);
op->type = R_ANAL_OP_TYPE_ADD;
break;
case rsubkc:
r_strbuf_setf (&op->esil, "%s,%s,-,c,+,%s,=", ra, rb, rd);
op->type = R_ANAL_OP_TYPE_SUB;
break;
case swapb:
@@ -359,13 +366,48 @@ static void analyse_arithmetic_inst(struct mb_anal_ctx *ctx, unsigned long insn,
r_strbuf_appendf (&op->esil, ",0,_imm,=");
}
static void analyse_logical_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 *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 ori:
r_strbuf_appendf (&op->esil, "_imm,%s,|,%s,=", ra, rd);
op->type = R_ANAL_OP_TYPE_OR;
break;
case andi:
r_strbuf_appendf (&op->esil, "_imm,%s,&,%s,=", ra, rd);
op->type = R_ANAL_OP_TYPE_AND;
break;
case xori:
r_strbuf_appendf (&op->esil, "_imm,%s,^,%s,=", ra, rd);
op->type = R_ANAL_OP_TYPE_XOR;
break;
case andni:
r_strbuf_appendf (&op->esil, "_imm,!,%s,&,%s,=", ra, rd);
op->type = R_ANAL_OP_TYPE_NOT;
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_logical_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 or:
r_strbuf_setf (&op->esil, "%s,%s,|,%s,=", ra, rb, rd);
@@ -393,32 +435,27 @@ 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);
r_strbuf_setf (&op->esil, "%s,1,&,c,=,", ra);
r_strbuf_appendf (&op->esil, "1,%s,>>>>,%s,=", ra, rd);
op->type = R_ANAL_OP_TYPE_SAR;
break;
case src:
r_strbuf_setf (&op->esil, "1,%s,>>,%s,=,", ra, rd);
r_strbuf_appendf (&op->esil, "31,c,<<,%s,|=", rd);
op->type = R_ANAL_OP_TYPE_SHR;
break;
case srl:
r_strbuf_setf (&op->esil, "%s,1,&,c,=,", ra);
r_strbuf_appendf (&op->esil, "1,%s,>>,%s,=", ra, rd);
op->type = R_ANAL_OP_TYPE_SHR;
break;
case sext8:
r_strbuf_setf (&op->esil, "%s,%s,=,7,%s,>>,?{,0xffffff00,%s,|=,}", ra, rd, ra, rd);
op->type = R_ANAL_OP_TYPE_CAST;
break;
case sext16:
break;
case ori:
r_strbuf_setf (&op->esil, "%s,_imm,|,%s,|,%s,=", ra, imm, rd);
op->type = R_ANAL_OP_TYPE_OR;
break;
case andi:
r_strbuf_setf (&op->esil, "%s,_imm,|,%s,&,%s,=", ra, imm, rd);
op->type = R_ANAL_OP_TYPE_AND;
break;
case xori:
r_strbuf_setf (&op->esil, "%s,_imm,|,%s,^,%s,=", ra, imm, rd);
op->type = R_ANAL_OP_TYPE_XOR;
break;
case andni:
r_strbuf_setf (&op->esil, "%s,!,%s,&,%s,=", ra, imm, rd);
op->type = R_ANAL_OP_TYPE_NOT;
r_strbuf_setf (&op->esil, "%s,%s,=,15,%s,>>,?{,0xffff0000,%s,|=,}", ra, rd, ra, rd);
op->type = R_ANAL_OP_TYPE_CAST;
break;
default:
break;
@@ -537,12 +574,12 @@ static void analyse_branch_inst_imm(struct mb_anal_ctx *ctx, unsigned long insn,
op->jump = jump_addr;
break;
case brai:
r_strbuf_setf (&op->esil, "_imm,pc,=");
r_strbuf_appendf (&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,=");
r_strbuf_appendf (&op->esil, "_imm,pc,=");
op->type = R_ANAL_OP_TYPE_JMP;
op->delay = 1;
op->jump = jump_addr;
@@ -559,13 +596,13 @@ static void analyse_branch_inst_imm(struct mb_anal_ctx *ctx, unsigned long insn,
op->jump = jump_addr;
break;
case beqi:
r_strbuf_appendf (&op->esil, "0,%s,==,?{,_imm,$$,+,pc,=,}", ra);
r_strbuf_appendf (&op->esil, "0,%s,==,$z,?{,_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);
r_strbuf_appendf (&op->esil, "0,%s,==,$z,?{,_imm,$$,+,pc,=,}", ra);
op->type = R_ANAL_OP_TYPE_CJMP;
op->delay = 1;
op->jump = jump_addr;
@@ -784,6 +821,7 @@ static void analyse_return_inst(struct mb_anal_ctx *ctx, unsigned long insn,
}
// 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_special_inst(struct mb_anal_ctx *ctx, unsigned long insn, struct op_code_struct *mb_op) {
@@ -858,12 +896,43 @@ static void analyse_anyware_inst(struct mb_anal_ctx *ctx, unsigned long insn, st
r_strbuf_appendf (&op->esil, ",0,_imm,=");
}
static void analyse_memory_load_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 *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 lbui:
r_strbuf_appendf (&op->esil, "%s,_imm,+,[1],%s,=", ra, rd);
op->type = R_ANAL_OP_TYPE_LOAD;
break;
case lhui:
r_strbuf_appendf (&op->esil, "%s,_imm,+,[4],%s,=", ra, rd);
r_strbuf_appendf (&op->esil, ",16,%s,>>=",rd);
op->type = R_ANAL_OP_TYPE_LOAD;
break;
case lwi:
r_strbuf_appendf (&op->esil, "%s,_imm,+,[4],%s,=", ra, rd);
op->type = R_ANAL_OP_TYPE_LOAD;
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_memory_load_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 lbu:
r_strbuf_setf (&op->esil, "%s,%s,[],+,%s,=", ra, rb, rd);
@@ -893,18 +962,37 @@ static void analyse_memory_load_inst(struct mb_anal_ctx *ctx, unsigned long insn
r_strbuf_setf (&op->esil, "%s,%s,[],+,%s,=", ra, rb, rd);
op->type = R_ANAL_OP_TYPE_LOAD;
break;
case lbui:
r_strbuf_setf (&op->esil, "%s,%s,_imm,|,+,[1],%s,=", ra, imm, rd);
op->type = R_ANAL_OP_TYPE_LOAD;
default:
break;
case lhui:
r_strbuf_setf (&op->esil, "%s,%s,_imm,|,+,[4],%s,=", ra, imm, rd);
r_strbuf_appendf (&op->esil, ",16,%s,>>=",rd);
op->type = R_ANAL_OP_TYPE_LOAD;
}
// 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_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 *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 sbi:
/* Only store least significant byte */
r_strbuf_appendf (&op->esil, "%s,%s,_imm,+,=[1]", rd, ra);
op->type = R_ANAL_OP_TYPE_STORE;
break;
case lwi:
r_strbuf_setf (&op->esil, "%s,%s,_imm,|,+,[4],%s,=", ra, imm, rd);
op->type = R_ANAL_OP_TYPE_LOAD;
case shi:
/* Only store least significant halword */
r_strbuf_appendf (&op->esil, "%s,%s,_imm,+,=[2]", rd, ra);
op->type = R_ANAL_OP_TYPE_STORE;
break;
case swi:
r_strbuf_appendf (&op->esil, "%s,%s,_imm,+,=[]", rd, ra);
op->type = R_ANAL_OP_TYPE_STORE;
break;
default:
break;
@@ -919,7 +1007,7 @@ static void analyse_memory_store_inst(struct mb_anal_ctx *ctx, unsigned long ins
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 sb:
r_strbuf_setf (&op->esil, "%s,%s,%s,+,=[1]", rd, ra, rb);
@@ -951,20 +1039,6 @@ static void analyse_memory_store_inst(struct mb_anal_ctx *ctx, unsigned long ins
r_strbuf_setf (&op->esil, "%s,%s,+,%s,=[]", rd, ra, rb);
op->type = R_ANAL_OP_TYPE_STORE;
break;
case sbi:
/* Only store least significant byte */
r_strbuf_setf (&op->esil, ",%s,%s,%s,_imm,|,+,=[1]", rd, ra, imm);
op->type = R_ANAL_OP_TYPE_STORE;
break;
case shi:
/* Only store least significant halword */
r_strbuf_setf (&op->esil, ",%s,%s,%s,_imm,|,+,=[2]", rd, ra, imm);
op->type = R_ANAL_OP_TYPE_STORE;
break;
case swi:
r_strbuf_setf (&op->esil, "%s,%s,%s,_imm,|,+,=[]", rd, ra, imm);
op->type = R_ANAL_OP_TYPE_STORE;
break;
default:
break;
}
@@ -975,23 +1049,34 @@ static void analyse_memory_store_inst(struct mb_anal_ctx *ctx, unsigned long ins
static void analyse_barrel_shift_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 *imm5 = get_field_imm5 (insn);
switch (mb_op->instr) {
case bsll:
r_strbuf_setf (&op->esil, ",%s,%s,<<,%s,=", rb, ra, rd);
op->type = R_ANAL_OP_TYPE_SHL;
break;
case bsra:
r_strbuf_setf (&op->esil, ",%s,%s,>>>>,%s,=", rb, ra, rd);
op->type = R_ANAL_OP_TYPE_SAR;
break;
case bsrl:
r_strbuf_setf (&op->esil, ",%s,%s,>>,%s,=", rb, ra, rd);
op->type = R_ANAL_OP_TYPE_SHR;
break;
case bslli:
r_strbuf_setf (&op->esil, ",%s,%s,<<,%s,=", imm5, ra, rd);
op->type = R_ANAL_OP_TYPE_SHL;
break;
case bsrai:
r_strbuf_setf (&op->esil, ",%s,%s,>>>>,%s,=", imm5, ra, rd);
op->type = R_ANAL_OP_TYPE_SAR;
break;
case bsrli:
r_strbuf_setf (&op->esil, ",%s,%s,>>,%s,=", imm5, ra, rd);
op->type = R_ANAL_OP_TYPE_SHR;
break;
default:
@@ -999,10 +1084,11 @@ static void analyse_barrel_shift_inst(struct mb_anal_ctx *ctx, unsigned long ins
}
// Reset _immf to zero even if not used.
r_strbuf_appendf (&op->esil, ",0,_immf,=");
r_strbuf_appendf (&op->esil, ",0,_imm,=");
}
static int microblaze_op(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len) {
static int microblaze_op(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int len, RAnalOpMask mask) {
int oplen = 4;
static struct mb_anal_ctx ctx;
static bool first_time = true;
@@ -1055,6 +1141,9 @@ static int microblaze_op(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l
op->type = R_ANAL_OP_TYPE_ILL;
return oplen;
}
if (mask & R_ANAL_OP_MASK_DISASM) {
op->mnemonic = strdup (mb_op->name);
}
r_strbuf_setf (&op->esil, "");
handle_immediate_inst (&ctx, insn, mb_op);
@@ -1072,6 +1161,9 @@ static int microblaze_op(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l
case logical_inst:
analyse_logical_inst (&ctx, insn, mb_op);
break;
case logical_inst_imm:
analyse_logical_inst_imm (&ctx, insn, mb_op);
break;
case mult_inst:
analyse_mult_inst (&ctx, insn, mb_op);
break;
@@ -1093,9 +1185,15 @@ static int microblaze_op(RAnal *a, RAnalOp *op, ut64 addr, const ut8 *buf, int l
case memory_load_inst:
analyse_memory_load_inst (&ctx, insn, mb_op);
break;
case memory_load_inst_imm:
analyse_memory_load_inst_imm (&ctx, insn, mb_op);
break;
case memory_store_inst:
analyse_memory_store_inst (&ctx, insn, mb_op);
break;
case memory_store_inst_imm:
analyse_memory_store_inst_imm (&ctx, insn, mb_op);
break;
case barrel_shift_inst:
analyse_barrel_shift_inst (&ctx, insn, mb_op);
break;
@@ -1125,7 +1223,7 @@ static int microblaze_set_reg_profile(RAnal* anal) {
"=A6 r10\n"
"=R0 r3\n"
"=R1 r4\n"
"gpr r0 .32 0 0\n"
"gpr r0 .32 ? 0\n"
"gpr r1 .32 4 0\n"
"gpr r2 .32 8 0\n"
"gpr r3 .32 12 0\n"
@@ -1159,7 +1257,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 c .1 132.2 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 */
+10 -10
View File
@@ -199,10 +199,10 @@ static struct op_code_struct
{"bgtd", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9E800000, OPCODE_MASK_H14, bgtd, branch_inst },
{"bge", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9CA00000, OPCODE_MASK_H14, bge, branch_inst },
{"bged", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9EA00000, OPCODE_MASK_H14, bged, branch_inst },
{"ori", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA0000000, OPCODE_MASK_H, ori, logical_inst },
{"andi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA4000000, OPCODE_MASK_H, andi, logical_inst },
{"xori", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA8000000, OPCODE_MASK_H, xori, logical_inst },
{"andni", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xAC000000, OPCODE_MASK_H, andni, logical_inst },
{"ori", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA0000000, OPCODE_MASK_H, ori, logical_inst_imm },
{"andi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA4000000, OPCODE_MASK_H, andi, logical_inst_imm },
{"xori", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA8000000, OPCODE_MASK_H, xori, logical_inst_imm },
{"andni", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xAC000000, OPCODE_MASK_H, andni, logical_inst_imm },
{"imm", INST_TYPE_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB0000000, OPCODE_MASK_H12, imm, immediate_inst },
{"rtsd", INST_TYPE_R1_IMM, INST_NO_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB6000000, OPCODE_MASK_H1, rtsd, return_inst },
{"rtid", INST_TYPE_R1_IMM, INST_NO_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB6200000, OPCODE_MASK_H1, rtid, return_inst },
@@ -241,12 +241,12 @@ static struct op_code_struct
{"sw", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000000, OPCODE_MASK_H4, sw, memory_store_inst },
{"swr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000200, OPCODE_MASK_H4, swr, memory_store_inst },
{"swx", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000400, OPCODE_MASK_H4, swx, memory_store_inst },
{"lbui", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE0000000, OPCODE_MASK_H, lbui, memory_load_inst },
{"lhui", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE4000000, OPCODE_MASK_H, lhui, memory_load_inst },
{"lwi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE8000000, OPCODE_MASK_H, lwi, memory_load_inst },
{"sbi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xF0000000, OPCODE_MASK_H, sbi, memory_store_inst },
{"shi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xF4000000, OPCODE_MASK_H, shi, memory_store_inst },
{"swi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xF8000000, OPCODE_MASK_H, swi, memory_store_inst },
{"lbui", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE0000000, OPCODE_MASK_H, lbui, memory_load_inst_imm },
{"lhui", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE4000000, OPCODE_MASK_H, lhui, memory_load_inst_imm },
{"lwi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE8000000, OPCODE_MASK_H, lwi, memory_load_inst_imm },
{"sbi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xF0000000, OPCODE_MASK_H, sbi, memory_store_inst_imm },
{"shi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xF4000000, OPCODE_MASK_H, shi, memory_store_inst_imm },
{"swi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xF8000000, OPCODE_MASK_H, swi, memory_store_inst_imm },
{"nop", INST_TYPE_NONE, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x80000000, OPCODE_MASK_H1234, invalid_inst, logical_inst }, /* translates to or r0, r0, r0. */
{"la", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x30000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* la translates to addik. */
{"tuqula",INST_TYPE_RD, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x3000002A, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* tuqula rd translates to addik rd, r0, 42. */
@@ -61,9 +61,10 @@ enum microblaze_instr
enum microblaze_instr_type
{
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
arithmetic_inst, arithmetic_inst_imm, logical_inst, logical_inst_imm,
mult_inst, div_inst, branch_inst, branch_inst_imm, return_inst,
immediate_inst, special_inst, memory_load_inst, memory_load_inst_imm,
memory_store_inst, memory_store_inst_imm, barrel_shift_inst, anyware_inst
};
#define INST_WORD_SIZE 4
+3 -11
View File
@@ -5,9 +5,9 @@
"requires": true,
"dependencies": {
"acorn": {
"version": "6.2.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.2.0.tgz",
"integrity": "sha512-8oe72N3WPMjA+2zVG71Ia0nXZ8DpQH+QyyHO+p06jT8eg8FGG3FbcUIi8KziHlAfheJQZeoqbvq1mQSQHXKYLw=="
"version": "6.4.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.4.1.tgz",
"integrity": "sha512-ZVA9k326Nwrj3Cj9jlh3wGFutC2ZornPNARZwsNYqQYgN0EsV2d53w5RN/co65Ohn4sUAUtb1rSUAOD6XN9idA=="
},
"acorn-jsx": {
"version": "5.0.1",
@@ -615,14 +615,6 @@
"acorn": "^6.0.2",
"acorn-jsx": "^5.0.0",
"eslint-visitor-keys": "^1.0.0"
},
"dependencies": {
"acorn": {
"version": "6.1.1",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-6.1.1.tgz",
"integrity": "sha512-jPTiwtOxaHNaAPg/dmrJ/beuzLRnXtB0kQPQ8JpotKJgTB6rX6c8mlf315941pyjBSaPg8NHXS9fhP4u17DpGA==",
"dev": true
}
}
},
"esprima": {
+13
View File
@@ -0,0 +1,13 @@
BINDIR=$(shell r2pm -H R2PM_BINDIR)
all: cmsis-svd
cmsis-svd:
git clone https://github.com/posborne/cmsis-svd
install:
cp -f r2svd.py $(BINDIR)/r2svd
chmod +x $(BINDIR)/r2svd
uninstall:
rm -f $(BINDIR)/r2svd.py
+44
View File
@@ -0,0 +1,44 @@
SVD loader for r2
=================
https://github.com/radareorg/radare2/issues/15484
https://raw.githubusercontent.com/posborne/cmsis-svd/master/data/Atmel/AT91SAM9CN11.svd
Installation:
-------------
```
$ r2pm -i r2svd
```
or just `make install` in this directory
Usage:
------
```
$ r2 -m 0x400000 firmware.fw
> !r2svd
TexasInstruments
Nordic
NXP
Cypress
Fujitsu
Toshiba
Spansion
ARM_SAMPLE
Nuvoton
Freescale
Holtek
SiliconLabs
SiFive-Community
STMicro
Atmel
> !r2svd Holtek
ht32f125x.svd
ht32f175x.svd
ht32f275x.svd
> .!r2svd Holtek ht32f125x.svd
```
+49
View File
@@ -0,0 +1,49 @@
#!/usr/bin/env python3
# use cmsis-svd python api to load the SVD peripheral and memory layout into r2
# --pancake @ 2020
import json
import sys
import math
import pkg_resources
from cmsis_svd.parser import SVDParser
argc = len(sys.argv)
if argc != 3:
try:
if argc == 1:
vendors = pkg_resources.resource_listdir("cmsis_svd", "data")
print('\n'.join(vendors))
elif argc == 2:
svds = pkg_resources.resource_listdir("cmsis_svd", "data/%s"%(sys.argv[1]))
print('\n'.join(svds))
else:
raise Exception('')
except:
print('Usage: .!r2svd [mcu] [svd]')
sys.exit(1)
sys.exit(0)
mcu = sys.argv[1] # Freescale
svd = sys.argv[2] # MK20D7.svd
parser = SVDParser.for_packaged_svd(mcu, svd)
svd_dict = parser.get_device().to_dict()
for p in svd_dict['peripherals']:
addr = p['base_address']
size = p['address_block']['size'] / 8
print("CC %s @ 0x%x"%(p['description'], addr))
print("f %s %d 0x%x"%(p['name'], size, addr))
s = ""
for r in p['registers']:
offs = int(r['address_offset'])
at = int(addr) + math.floor(offs / 8)
bt = (offs % 8)
s += " " + r['name']
if at != addr:
print("f %s.%s %d 0x%x"%(p['name'], r['name'], size, at))
# print(" 0x%x %d %s"%(at, bt, r['name']))
print("CC (%s) @ 0x%x"%(s, addr))
# print(json.dumps(svd_dict, sort_keys=True, indent=4, separators=(',', ': ')))
+4 -4
View File
@@ -1,5 +1,5 @@
#!/bin/sh
# This script was automatically generated by ACR v1.7.2
# This script was automatically generated by ACR v1.8.1
# @author: pancake <nopcode.org>
# @url: http://www.nopcode.org
# @repo: git clone https://github.com/radare/acr
@@ -103,7 +103,7 @@ done
: ${INSTALL_PROGRAM_STRIP:=${INSTALL} -m 755 -s}
: ${INSTALL_MAN:=${INSTALL} -m 444}
: ${INSTALL_LIB:=${INSTALL} -m 755 -c}
PKGNAME='radare2-extras-ssdeep' ; VERSION='1.0' ;
PKGNAME='radare2-extras-ssdeep' ; VERSION='1.0' ; VERSION_MAJOR=1; VERSION_MINOR=0; VERSION_PATCH=0; VERSION_NUMBER=10000;
}
show_usage() {
@@ -171,7 +171,7 @@ take_environ() {
}
show_version() {
echo "radare2-extras-ssdeep-1.0 configuration script done with acr v1.7.2.
echo "radare2-extras-ssdeep-1.0 configuration script done with acr v1.8.1.
The 'Free Software Foundation' message is only for autodetection.
Originally written by pancake <nopcode.org>."
exit 0
@@ -261,7 +261,7 @@ parse_options "$1"
shift
done
ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU PKGNAME VPATH VERSION CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C HAVE_LIB_FUZZY SD_CFLAGS SD_LDFLAGS HAVE_PKGCFG_SSDEEP R2_CFLAGS R2_LDFLAGS HAVE_PKGCFG_R_CORE"
ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU VERSION VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION_NUMBER PKGNAME VPATH CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C HAVE_LIB_FUZZY SD_CFLAGS SD_LDFLAGS HAVE_PKGCFG_SSDEEP R2_CFLAGS R2_LDFLAGS HAVE_PKGCFG_R_CORE"
create_environ
+4 -4
View File
@@ -1,5 +1,5 @@
#!/bin/sh
# This script was automatically generated by ACR v1.7.2
# This script was automatically generated by ACR v1.8.1
# @author: pancake <nopcode.org>
# @url: http://www.nopcode.org
# @repo: git clone https://github.com/radare/acr
@@ -103,7 +103,7 @@ done
: ${INSTALL_PROGRAM_STRIP:=${INSTALL} -m 755 -s}
: ${INSTALL_MAN:=${INSTALL} -m 444}
: ${INSTALL_LIB:=${INSTALL} -m 755 -c}
PKGNAME='radare2-extras-yara' ; VERSION='1.0' ; CONTACT_MAIL="[email protected]" ; CONTACT_NAME="jfrankowski" ; CONTACT="jfrankowski <[email protected]>" ;
PKGNAME='radare2-extras-yara' ; VERSION='1.0' ; VERSION_MAJOR=1; VERSION_MINOR=0; VERSION_PATCH=0; VERSION_NUMBER=10000; CONTACT_MAIL="[email protected]" ; CONTACT_NAME="jfrankowski" ; CONTACT="jfrankowski <[email protected]>" ;
}
show_usage() {
@@ -173,7 +173,7 @@ take_environ() {
}
show_version() {
echo "radare2-extras-yara-1.0 configuration script done with acr v1.7.2.
echo "radare2-extras-yara-1.0 configuration script done with acr v1.8.1.
The 'Free Software Foundation' message is only for autodetection.
Originally written by pancake <nopcode.org>."
exit 0
@@ -263,7 +263,7 @@ parse_options "$1"
shift
done
ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU PKGNAME VPATH VERSION CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C HAVE_LIB_YARA YR_CFLAGS YR_LDFLAGS HAVE_PKGCFG_YARA R2_CFLAGS R2_LDFLAGS HAVE_PKGCFG_R_CORE"
ENVWORDS="MANDIR INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU VERSION VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION_NUMBER PKGNAME VPATH CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C HAVE_LIB_YARA YR_CFLAGS YR_LDFLAGS HAVE_PKGCFG_YARA R2_CFLAGS R2_LDFLAGS HAVE_PKGCFG_R_CORE"
create_environ
+42 -10
View File
@@ -13,7 +13,9 @@
// true if the plugin has been initialized.
static int initialized = false;
static int callback(int message, void* rule, void* data);
static bool print_strings = 0;
static int callback(YR_SCAN_CONTEXT* context, int message, void* rule, void* data);
static int r_cmd_yara_add (const RCore* core, const char* input);
static int r_cmd_yara_add_file (const char* rules_path);
static int r_cmd_yara_call(void *user, const char *input);
@@ -21,7 +23,7 @@ static int r_cmd_yara_clear();
static int r_cmd_yara_init(void *user, const char *cmd);
static int r_cmd_yara_help(const RCore* core);
static int r_cmd_yara_process(const RCore* core, const char* input);
static int r_cmd_yara_scan(const RCore* core);
static int r_cmd_yara_scan(const RCore* core, const char* option);
static int r_cmd_yara_load_default_rules (const RCore* core);
static const char* yara_rule_template = "rule RULE_NAME {\n\tstrings:\n\n\tcondition:\n}";
@@ -32,20 +34,38 @@ static const char* yara_rule_template = "rule RULE_NAME {\n\tstrings:\n\n\tcondi
*/
static RList* rules_list;
static int callback (int message, void *msg_data, void *user_data) {
static int callback (YR_SCAN_CONTEXT* context, int message, void *msg_data, void *user_data) {
RPrint *print = (RPrint *)user_data;
YR_RULE* rule = msg_data;
if (message == CALLBACK_MSG_RULE_MATCHING)
r_cons_printf ("%s\n", rule->identifier);
{
YR_STRING* string;
r_cons_printf("%s\n", rule->identifier);
if (print_strings) {
yr_rule_strings_foreach(rule, string)
{
YR_MATCH* match;
yr_string_matches_foreach(context, string, match)
{
r_cons_printf("0x%08" PRIx64 ": %s : ", match->base + match->offset, string->identifier);
r_print_bytes(print, match->data, match->data_length, "%02x ");
}
}
}
}
return CALLBACK_CONTINUE;
}
static void compiler_callback(int error_level, const char* file_name,
int line_number, const char* message, void* user_data) {
int line_number, const struct YR_RULE *rule, const char* message, void* user_data) {
eprintf ("file: %s line_number: %d.\n%s", file_name, line_number, message);
return;
}
static int r_cmd_yara_scan(const RCore* core) {
static int r_cmd_yara_scan(const RCore* core, const char* option) {
RListIter* rules_it;
YR_RULES* rules;
void* to_scan;
@@ -57,6 +77,18 @@ static int r_cmd_yara_scan(const RCore* core) {
return false;
}
if( *option == '\0') {
print_strings = 0;
}
else if (*option == 'S') {
print_strings = 1;
}
else {
print_strings = 0;
eprintf ("Invalid option\n");
return false;
}
to_scan = malloc (to_scan_size);
if (!to_scan) {
eprintf ("Something went wrong during memory allocation\n");
@@ -71,7 +103,7 @@ static int r_cmd_yara_scan(const RCore* core) {
}
r_list_foreach (rules_list, rules_it, rules) {
yr_rules_scan_mem (rules, to_scan, to_scan_size, 0, callback, NULL, 0);
yr_rules_scan_mem (rules, to_scan, to_scan_size, 0, callback, core->print, 0);
}
free (to_scan);
@@ -136,7 +168,7 @@ static int r_cmd_yara_tag (const char * search_tag) {
r_list_foreach (rules_list, rules_it, rules) {
yr_rules_foreach (rules, rule) {
yr_rule_tags_foreach(rule, tag_name) {
yr_rule_tags_foreach(rule, tag_name) {eprintf ("Invalid option\n");
if (r_str_casestr (tag_name, search_tag)) {
r_cons_printf("%s\n", rule->identifier);
break;
@@ -296,7 +328,7 @@ static int r_cmd_yara_help(const RCore* core) {
"clear", "", "Clear all rules",
"help", "", "Show this help",
"list", "", "List all rules",
"scan", "", "Scan the current file",
"scan", "[S]", "Scan the current file, if S option is given it prints matching strings.",
"show", " name", "Show rules containing name",
"tag", " name", "List rules with tag 'name'",
"tags", "", "List tags from the loaded rules",
@@ -316,7 +348,7 @@ static int r_cmd_yara_process(const RCore* core, const char* input) {
else if (!strncmp (input, "list", 4))
return r_cmd_yara_list ();
else if (!strncmp (input, "scan", 4))
return r_cmd_yara_scan (core);
return r_cmd_yara_scan (core, input + 4);
else if (!strncmp (input, "show", 4))
return r_cmd_yara_show (input + 5);
else if (!strncmp (input, "tags", 4))