mirror of
https://github.com/radareorg/radare2.git
synced 2024-10-07 18:43:45 +00:00
* Use valaswig-cc -x for generating bindings (iterator support and so)
* Remove deprecated r_bin.i.experimental * Define r_array functions in r_array.h as inline static (list.h like) * Minor fixups in some vapis and headers * Update python examples * Exclude problematic libs from swig/rules.mk (temporary)
This commit is contained in:
parent
4bbe54c148
commit
d1aceaaa80
@ -224,7 +224,7 @@ R_API int r_asm_disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf
|
||||
return ret;
|
||||
}
|
||||
|
||||
R_API int r_asm_assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf)
|
||||
R_API int r_asm_assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, const char *buf)
|
||||
{
|
||||
int ret = 0;
|
||||
struct list_head *pos;
|
||||
|
@ -1,6 +1,11 @@
|
||||
/* radare - LGPL - Copyright 2010 nibble <.ds@gmail.com> */
|
||||
|
||||
#ifndef _INCLUDE_R_ARRAY_H_
|
||||
#define _INCLUDE_R_ARRAY_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define r_array_t void**
|
||||
#define RArray void**
|
||||
#define r_array_rewind(it) for (; it!=*it; it--); it++
|
||||
@ -9,15 +14,45 @@
|
||||
#define r_array_iterator(x) x
|
||||
#define r_array_unref(x) x
|
||||
|
||||
R_API void **r_array_init(void **it, int n);
|
||||
R_API void **r_array_new(int n);
|
||||
R_API void **r_array_prev(void **it);
|
||||
R_API void r_array_set(void **it, int idx, void *data);
|
||||
R_API void r_array_delete(void **it, int idx);
|
||||
R_API void r_array_free(void **it);
|
||||
static inline void **r_array_init(void **it, int n) {
|
||||
*it = it;
|
||||
memset (++it, 0, (n+1) * sizeof (void*));
|
||||
return it;
|
||||
}
|
||||
|
||||
static inline void **r_array_new(int n) {
|
||||
void **it;
|
||||
if (!(it = (void **)malloc ((n+2) * sizeof (void*))))
|
||||
return NULL;
|
||||
return r_array_init (it, n);
|
||||
}
|
||||
|
||||
static inline void **r_array_prev(void **it) {
|
||||
void **p = it;
|
||||
return (--it==*it)?p:it;
|
||||
}
|
||||
|
||||
static inline void r_array_set(void **it, int idx, void *data) {
|
||||
r_array_rewind (it);
|
||||
it[idx] = data;
|
||||
}
|
||||
|
||||
static inline void r_array_delete(void **it, int idx) {
|
||||
r_array_rewind (it);
|
||||
free (it[idx]);
|
||||
for(it += idx; *it; it++) *it = *(it+1);
|
||||
}
|
||||
|
||||
#define r_array_foreach(it, pos) \
|
||||
r_array_rewind(it); \
|
||||
while (r_array_next (it) && (pos = r_array_get (it)))
|
||||
|
||||
static inline void r_array_free(void **it) {
|
||||
void *pos;
|
||||
r_array_foreach (it, pos)
|
||||
free (pos);
|
||||
r_array_rewind (it);
|
||||
free (--it);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -94,7 +94,7 @@ R_API int r_asm_set_big_endian(struct r_asm_t *a, int boolean);
|
||||
R_API int r_asm_set_syntax(struct r_asm_t *a, int syntax);
|
||||
R_API int r_asm_set_pc(struct r_asm_t *a, ut64 pc);
|
||||
R_API int r_asm_disassemble(struct r_asm_t *a, struct r_asm_aop_t *aop, ut8 *buf, ut64 len);
|
||||
R_API int r_asm_assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, char *buf);
|
||||
R_API int r_asm_assemble(struct r_asm_t *a, struct r_asm_aop_t *aop, const char *buf);
|
||||
R_API struct r_asm_code_t* r_asm_mdisassemble(struct r_asm_t *a, ut8 *buf, ut64 len);
|
||||
R_API struct r_asm_code_t* r_asm_massemble(struct r_asm_t *a, const char *buf);
|
||||
|
||||
|
@ -71,6 +71,7 @@ typedef struct r_core_t {
|
||||
#ifdef R_API
|
||||
R_API int r_core_init(struct r_core_t *core);
|
||||
R_API struct r_core_t *r_core_new();
|
||||
R_API struct r_core_t *r_core_free(struct r_core_t *c);
|
||||
R_API int r_core_config_init(struct r_core_t *core);
|
||||
R_API int r_core_prompt(struct r_core_t *r);
|
||||
R_API int r_core_cmd(struct r_core_t *r, const char *cmd, int log);
|
||||
|
@ -51,7 +51,7 @@ R_API int r_flag_name_check(const char *name);
|
||||
R_API int r_flag_name_filter(char *name);
|
||||
|
||||
/* spaces */
|
||||
R_API const const char *r_flag_space_get(struct r_flag_t *f, int idx);
|
||||
R_API const char *r_flag_space_get(struct r_flag_t *f, int idx);
|
||||
R_API void r_flag_space_set(struct r_flag_t *f, const char *name);
|
||||
R_API void r_flag_space_list(struct r_flag_t *f);
|
||||
#endif
|
||||
|
@ -1,6 +1,6 @@
|
||||
NAME=r_util
|
||||
include ../config.mk
|
||||
OBJ=mem.o pool.o num.o str.o re.o hex.o file.o alloca.o
|
||||
OBJ+=float.o prof.o cache.o sys.o btree.o array.o buf.o list.o
|
||||
OBJ+=float.o prof.o cache.o sys.o btree.o buf.o list.o
|
||||
|
||||
include ../rules.mk
|
||||
|
@ -1,42 +0,0 @@
|
||||
/* radare - LGPL - Copyright 2010 nibble <.ds@gmail.com> */
|
||||
|
||||
#include <r_util.h>
|
||||
|
||||
R_API void **r_array_init(void **it, int n) {
|
||||
*it = it;
|
||||
memset (++it, 0, (n+1) * sizeof (void*));
|
||||
return it;
|
||||
}
|
||||
|
||||
R_API void **r_array_new(int n) {
|
||||
void **it;
|
||||
if (!(it = (void **)malloc ((n+2) * sizeof (void*))))
|
||||
return NULL;
|
||||
return r_array_init (it, n);
|
||||
}
|
||||
|
||||
R_API void **r_array_prev(void **it) {
|
||||
void **p = it;
|
||||
return (--it==*it)?p:it;
|
||||
}
|
||||
|
||||
R_API void r_array_set(void **it, int idx, void *data) {
|
||||
r_array_rewind (it);
|
||||
it[idx] = data;
|
||||
}
|
||||
|
||||
R_API void r_array_delete(void **it, int idx) {
|
||||
r_array_rewind (it);
|
||||
free (it[idx]);
|
||||
for(it += idx; *it; it++) *it = *(it+1);
|
||||
}
|
||||
|
||||
R_API void r_array_free(void **it) {
|
||||
void *pos;
|
||||
r_array_foreach (it, pos)
|
||||
free (pos);
|
||||
r_array_rewind (it);
|
||||
free (--it);
|
||||
}
|
||||
|
||||
/* TODO: r_array_iterator */
|
@ -1,6 +1,6 @@
|
||||
/* radare - LGPL - Copyright 2009 nibble<.ds@gmail.com> */
|
||||
|
||||
[CCode (cheader_filename="r_bin.h", cprefix="r_bin_", lower_case_cprefix="r_bin_")]
|
||||
[CCode (cheader_filename="r_bin.h,r_array.h,r_types.h", cprefix="r_bin_", lower_case_cprefix="r_bin_")]
|
||||
namespace Radare {
|
||||
[Compact]
|
||||
[CCode (cname="RBin", free_function="r_bin_free", cprefix="r_bin_")]
|
||||
@ -14,13 +14,13 @@ namespace Radare {
|
||||
public int load(string file, string? plugin_name = null);
|
||||
public int list();
|
||||
public uint64 get_baddr();
|
||||
public RArray<RBin.Entry*> get_entries();
|
||||
public RArray<RBin.Field*> get_fields();
|
||||
public RArray<RBin.Import*> get_imports();
|
||||
public RArray<RBin.Section*> get_sections();
|
||||
public RArray<RBin.String*> get_strings();
|
||||
public RArray<RBin.Symbol*> get_symbols();
|
||||
public RBin.Info* get_info();
|
||||
public RArray<RBin.Entry> get_entries();
|
||||
public RArray<RBin.Field> get_fields();
|
||||
public RArray<RBin.Import> get_imports();
|
||||
public RArray<RBin.Section> get_sections();
|
||||
public RArray<RBin.String> get_strings();
|
||||
public RArray<RBin.Symbol> get_symbols();
|
||||
public RBin.Info get_info();
|
||||
|
||||
[CCode (cname="RBinEntry", free_function="", ref_function="", unref_function="")]
|
||||
public class Entry {
|
||||
|
@ -7,7 +7,7 @@ namespace Radare {
|
||||
public RDiff (uint64 off_a = 0LL, uint64 off_b = 0LL);
|
||||
public int buffers (uint8* a, int la, uint8* b, int lb);
|
||||
//public int set_callback(...);
|
||||
public int buffers_distance (uint8 *a, int la, uint8 *b, int lb, out int distance, out double similarity);
|
||||
public int buffers_distance (uint8 *a, int la, uint8 *b, int lb, out uint32 distance, out double similarity);
|
||||
public static int lines (string file, string sa, int la, string file2, string sb, int lb);
|
||||
|
||||
[Compact]
|
||||
|
@ -15,5 +15,5 @@ cd ${LNG}
|
||||
echo LIBS = `pkg-config --libs ${MOD}`
|
||||
|
||||
valaswig-cc ${LNG} ${MOD} \
|
||||
--vapidir=../../libr/vapi -I../../libr/include \
|
||||
-x --vapidir=../../libr/vapi -I../../libr/include \
|
||||
../../libr/vapi/${MOD} `pkg-config --libs ${MOD}`
|
||||
|
@ -1,54 +0,0 @@
|
||||
%module r_bin
|
||||
%{
|
||||
extern "C" {
|
||||
#include <r_bin.h>
|
||||
#include <r_util.h>
|
||||
}
|
||||
#include <vector>
|
||||
%}
|
||||
%include <r_bin.h>
|
||||
%include "std_vector.i"
|
||||
|
||||
typedef void** RArray;
|
||||
typedef unsigned long long ut64;
|
||||
typedef long long st64;
|
||||
typedef unsigned int ut32;
|
||||
typedef unsigned short ut16;
|
||||
typedef unsigned char ut8;
|
||||
|
||||
namespace std {
|
||||
%template(SectionVector) std::vector<RBinSection>;
|
||||
%template(SymbolVector) std::vector<RBinSymbol>;
|
||||
%template(ImportVector) std::vector<RBinImport>;
|
||||
%template(StringVector) std::vector<RBinString>;
|
||||
%template(FieldVector) std::vector<RBinField>;
|
||||
%template(EntryVector) std::vector<RBinEntry>;
|
||||
};
|
||||
|
||||
%extend RBin {
|
||||
RBin() {
|
||||
return r_bin_new();
|
||||
}
|
||||
~RBin() {
|
||||
r_bin_free(self);
|
||||
}
|
||||
int load(const char *file, const char* plugin_name) {
|
||||
return r_bin_load(self, file, plugin_name);
|
||||
}
|
||||
ut64 get_baddr() {
|
||||
return r_bin_get_baddr(self);
|
||||
}
|
||||
std::vector<RBinSection> get_sections() {
|
||||
std::vector<RBinSection> ret;
|
||||
RArray sections;
|
||||
RBinSection *section;
|
||||
sections = r_bin_get_sections(self);
|
||||
r_array_rewind(sections);
|
||||
while (*sections != 0 && (section = (RBinSection*)(*sections++)))
|
||||
ret.push_back(*section);
|
||||
return ret;
|
||||
}
|
||||
RBinInfo* get_info() {
|
||||
return r_bin_get_info(self);
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
LIBS=r_util.so r_bp.so r_asm.so r_diff.so r_debug.so r_hash.so r_cons.so
|
||||
LIBS+=r_core.so r_search.so r_db.so r_lib.so r_io.so libr.so
|
||||
LIBS=r_util.so r_bp.so r_asm.so r_diff.so r_core.so r_bin.so
|
||||
|
||||
.SUFFIXES: .so
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
from r_bin import *
|
||||
from r2.r_bin import *
|
||||
|
||||
b = RBin ()
|
||||
b.load("/bin/ls", None)
|
||||
baddr= b.get_baddr()
|
||||
print '-> Sections'
|
||||
for i in b.get_sections ():
|
||||
for i in b.get_symbols ():
|
||||
print 'offset=0x%08x va=0x%08x size=%05i %s' % (
|
||||
i.offset, baddr+i.rva, i.size, i.name)
|
||||
|
@ -1,4 +1,4 @@
|
||||
from r_bp import *
|
||||
from r2.r_bp import *
|
||||
|
||||
a = rBreakpoint ()
|
||||
a = RBreakpoint ()
|
||||
print dir(a)
|
||||
|
@ -1,6 +1,6 @@
|
||||
from r_util import *
|
||||
from r2.r_util import *
|
||||
|
||||
a = rNum ()
|
||||
a = RNum ()
|
||||
|
||||
print "The value is: %d"%(a.get("33"))
|
||||
print "The math is: %d"%(a.math("33+(4*2)"))
|
||||
|
Loading…
Reference in New Issue
Block a user