Renamed the "Format" class to "AsmFormat" to avoid potential future conflicts

This commit is contained in:
Pierre Pronchery 2012-05-19 12:43:52 +00:00
parent 07bc3364b4
commit 9d251ebd89
10 changed files with 283 additions and 281 deletions

View File

@ -24,58 +24,58 @@
/* AsmFormat */ /* AsmFormat */
/* types */ /* types */
typedef struct _Format Format; typedef struct _AsmFormat AsmFormat;
typedef struct _FormatPlugin FormatPlugin; typedef struct _AsmFormatPlugin AsmFormatPlugin;
typedef struct _FormatPluginHelper typedef struct _AsmFormatPluginHelper
{ {
Format * format; AsmFormat * format;
/* callbacks */ /* callbacks */
/* accessors */ /* accessors */
char const * (*get_filename)(Format * format); char const * (*get_filename)(AsmFormat * format);
void (*get_functions)(Format * format, AsmFunction ** functions, void (*get_functions)(AsmFormat * format, AsmFunction ** functions,
size_t * functions_cnt); size_t * functions_cnt);
/* useful */ /* useful */
ssize_t (*read)(Format * format, void * buf, size_t size); ssize_t (*read)(AsmFormat * format, void * buf, size_t size);
off_t (*seek)(Format * format, off_t offset, int whence); off_t (*seek)(AsmFormat * format, off_t offset, int whence);
/* assembly */ /* assembly */
ssize_t (*write)(Format * format, void const * buf, size_t size); ssize_t (*write)(AsmFormat * format, void const * buf, size_t size);
/* disassembly */ /* disassembly */
/* FIXME let a different architecture be specified in the callback? */ /* FIXME let a different architecture be specified in the callback? */
AsmSection * (*get_section_by_id)(Format * format, AsmSectionId id); AsmSection * (*get_section_by_id)(AsmFormat * format, AsmSectionId id);
AsmString * (*get_string_by_id)(Format * format, AsmStringId id); AsmString * (*get_string_by_id)(AsmFormat * format, AsmStringId id);
int (*set_function)(Format * format, int id, char const * name, int (*set_function)(AsmFormat * format, int id, char const * name,
off_t offset, ssize_t size); off_t offset, ssize_t size);
int (*set_section)(Format * format, int id, char const * name, int (*set_section)(AsmFormat * format, int id, char const * name,
off_t offset, ssize_t size, off_t base); off_t offset, ssize_t size, off_t base);
int (*set_string)(Format * format, int id, char const * name, int (*set_string)(AsmFormat * format, int id, char const * name,
off_t offset, ssize_t size); off_t offset, ssize_t size);
int (*decode)(Format * format, off_t offset, size_t size, off_t base, int (*decode)(AsmFormat * format, off_t offset, size_t size, off_t base,
AsmArchInstructionCall ** calls, size_t * calls_cnt); AsmArchInstructionCall ** calls, size_t * calls_cnt);
} FormatPluginHelper; } AsmFormatPluginHelper;
struct _FormatPlugin struct _AsmFormatPlugin
{ {
FormatPluginHelper * helper; AsmFormatPluginHelper * helper;
char const * name; char const * name;
char const * signature; char const * signature;
size_t signature_len; size_t signature_len;
int (*init)(FormatPlugin * format, char const * arch); int (*init)(AsmFormatPlugin * format, char const * arch);
int (*exit)(FormatPlugin * format); int (*exit)(AsmFormatPlugin * format);
int (*function)(FormatPlugin * format, char const * function); int (*function)(AsmFormatPlugin * format, char const * function);
int (*section)(FormatPlugin * format, char const * section); int (*section)(AsmFormatPlugin * format, char const * section);
char const * (*detect)(FormatPlugin * format); char const * (*detect)(AsmFormatPlugin * format);
int (*decode)(FormatPlugin * format, int raw); int (*decode)(AsmFormatPlugin * format, int raw);
int (*decode_section)(FormatPlugin * format, AsmSection * section, int (*decode_section)(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt); AsmArchInstructionCall ** calls, size_t * calls_cnt);
void * priv; void * priv;

View File

@ -303,7 +303,7 @@ int asm_plugin_list(AsmPluginType type, int decode)
size_t len; size_t len;
char const * sep = ""; char const * sep = "";
AsmArch * arch; AsmArch * arch;
Format * format; AsmFormat * format;
aspd = &_asm_plugin_description[type]; aspd = &_asm_plugin_description[type];
fprintf(stderr, "%s%s%s", "Available ", aspd->description, fprintf(stderr, "%s%s%s", "Available ", aspd->description,

View File

@ -40,7 +40,7 @@ struct _AsmCode
{ {
AsmArch * arch; AsmArch * arch;
AsmArchDescription * description; AsmArchDescription * description;
Format * format; AsmFormat * format;
char * filename; char * filename;
FILE * fp; FILE * fp;
@ -112,7 +112,7 @@ AsmCode * asmcode_new(char const * arch, char const * format)
/* asmcode_new_file */ /* asmcode_new_file */
static Format * _new_file_format(char const * filename, FILE * fp); static AsmFormat * _new_file_format(char const * filename, FILE * fp);
AsmCode * asmcode_new_file(char const * arch, char const * format, AsmCode * asmcode_new_file(char const * arch, char const * format,
char const * filename) char const * filename)
@ -160,7 +160,7 @@ AsmCode * asmcode_new_file(char const * arch, char const * format,
return code; return code;
} }
static Format * _new_file_format(char const * filename, FILE * fp) static AsmFormat * _new_file_format(char const * filename, FILE * fp)
{ {
char const path[] = LIBDIR "/" PACKAGE "/format"; char const path[] = LIBDIR "/" PACKAGE "/format";
DIR * dir; DIR * dir;
@ -168,7 +168,7 @@ static Format * _new_file_format(char const * filename, FILE * fp)
size_t len; size_t len;
char const ext[] = ".so"; char const ext[] = ".so";
int hasflat = 0; int hasflat = 0;
Format * format = NULL; AsmFormat * format = NULL;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, filename); fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, filename);

View File

@ -25,14 +25,14 @@
#include "../config.h" #include "../config.h"
/* Format */ /* AsmFormat */
/* private */ /* private */
/* types */ /* types */
struct _Format struct _AsmFormat
{ {
FormatPluginHelper helper; AsmFormatPluginHelper helper;
Plugin * handle; Plugin * handle;
FormatPlugin * plugin; AsmFormatPlugin * plugin;
/* internal */ /* internal */
/* file */ /* file */
@ -46,36 +46,36 @@ struct _Format
/* prototypes */ /* prototypes */
/* helpers */ /* helpers */
static char const * _format_helper_get_filename(Format * format); static char const * _format_helper_get_filename(AsmFormat * format);
static void _format_helper_get_functions(Format * format, static void _format_helper_get_functions(AsmFormat * format,
AsmFunction ** functions, size_t * functions_cnt); AsmFunction ** functions, size_t * functions_cnt);
static AsmSection * _format_helper_get_section_by_id(Format * format, static AsmSection * _format_helper_get_section_by_id(AsmFormat * format,
AsmSectionId id); AsmSectionId id);
static AsmString * _format_helper_get_string_by_id(Format * format, static AsmString * _format_helper_get_string_by_id(AsmFormat * format,
AsmStringId id); AsmStringId id);
static int _format_helper_set_function(Format * format, AsmFunctionId id, static int _format_helper_set_function(AsmFormat * format, AsmFunctionId id,
char const * name, off_t offset, ssize_t size); char const * name, off_t offset, ssize_t size);
static int _format_helper_set_section(Format * format, AsmSectionId id, static int _format_helper_set_section(AsmFormat * format, AsmSectionId id,
char const * name, off_t offset, ssize_t size, off_t base); char const * name, off_t offset, ssize_t size, off_t base);
static int _format_helper_set_string(Format * format, AsmStringId id, static int _format_helper_set_string(AsmFormat * format, AsmStringId id,
char const * name, off_t offset, ssize_t size); char const * name, off_t offset, ssize_t size);
static int _format_helper_decode(Format * format, off_t offset, size_t size, static int _format_helper_decode(AsmFormat * format, off_t offset, size_t size,
off_t base, AsmArchInstructionCall ** calls, size_t * calls_cnt); off_t base, AsmArchInstructionCall ** calls, size_t * calls_cnt);
static ssize_t _format_helper_read(Format * format, void * buf, size_t size); static ssize_t _format_helper_read(AsmFormat * format, void * buf, size_t size);
static off_t _format_helper_seek(Format * format, off_t offset, int whence); static off_t _format_helper_seek(AsmFormat * format, off_t offset, int whence);
static ssize_t _format_helper_write(Format * format, void const * buf, static ssize_t _format_helper_write(AsmFormat * format, void const * buf,
size_t size); size_t size);
/* public */ /* public */
/* functions */ /* functions */
/* format_new */ /* format_new */
Format * format_new(char const * format) AsmFormat * format_new(char const * format)
{ {
Format * f; AsmFormat * f;
Plugin * handle; Plugin * handle;
FormatPlugin * plugin; AsmFormatPlugin * plugin;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, format); fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, format);
@ -113,7 +113,7 @@ Format * format_new(char const * format)
/* format_delete */ /* format_delete */
void format_delete(Format * format) void format_delete(AsmFormat * format)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s()\n", __func__); fprintf(stderr, "DEBUG: %s()\n", __func__);
@ -126,7 +126,7 @@ void format_delete(Format * format)
/* accessors */ /* accessors */
/* format_can_decode */ /* format_can_decode */
int format_can_decode(Format * format) int format_can_decode(AsmFormat * format)
{ {
return format->plugin->decode != NULL return format->plugin->decode != NULL
/* && format->plugin->decode_section != NULL */; /* && format->plugin->decode_section != NULL */;
@ -134,7 +134,7 @@ int format_can_decode(Format * format)
/* format_get_arch */ /* format_get_arch */
char const * format_get_arch(Format * format) char const * format_get_arch(AsmFormat * format)
{ {
if(format->plugin->detect == NULL) if(format->plugin->detect == NULL)
return NULL; return NULL;
@ -143,7 +143,7 @@ char const * format_get_arch(Format * format)
/* format_get_name */ /* format_get_name */
char const * format_get_name(Format * format) char const * format_get_name(AsmFormat * format)
{ {
return format->plugin->name; return format->plugin->name;
} }
@ -151,7 +151,7 @@ char const * format_get_name(Format * format)
/* useful */ /* useful */
/* format_decode */ /* format_decode */
int format_decode(Format * format, AsmCode * code, int raw) int format_decode(AsmFormat * format, AsmCode * code, int raw)
{ {
int ret; int ret;
@ -166,7 +166,7 @@ int format_decode(Format * format, AsmCode * code, int raw)
/* format_decode_section */ /* format_decode_section */
int format_decode_section(Format * format, AsmCode * code, AsmSection * section, int format_decode_section(AsmFormat * format, AsmCode * code, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt) AsmArchInstructionCall ** calls, size_t * calls_cnt)
{ {
int ret; int ret;
@ -186,7 +186,7 @@ int format_decode_section(Format * format, AsmCode * code, AsmSection * section,
/* format_detect_arch */ /* format_detect_arch */
char const * format_detect_arch(Format * format) char const * format_detect_arch(AsmFormat * format)
{ {
if(format->plugin->detect == NULL) if(format->plugin->detect == NULL)
{ {
@ -199,7 +199,7 @@ char const * format_detect_arch(Format * format)
/* format_exit */ /* format_exit */
int format_exit(Format * format) int format_exit(AsmFormat * format)
{ {
int ret = 0; int ret = 0;
@ -216,7 +216,7 @@ int format_exit(Format * format)
/* format_function */ /* format_function */
int format_function(Format * format, char const * function) int format_function(AsmFormat * format, char const * function)
{ {
if(format->plugin->function == NULL) if(format->plugin->function == NULL)
return 0; return 0;
@ -225,7 +225,7 @@ int format_function(Format * format, char const * function)
/* format_init */ /* format_init */
int format_init(Format * format, char const * arch, char const * filename, int format_init(AsmFormat * format, char const * arch, char const * filename,
FILE * fp) FILE * fp)
{ {
int ret = 0; int ret = 0;
@ -247,7 +247,7 @@ int format_init(Format * format, char const * arch, char const * filename,
/* format_match */ /* format_match */
int format_match(Format * format) int format_match(AsmFormat * format)
{ {
int ret = 0; int ret = 0;
char const * s = format->plugin->signature; char const * s = format->plugin->signature;
@ -275,7 +275,7 @@ int format_match(Format * format)
/* format_section */ /* format_section */
int format_section(Format * format, char const * section) int format_section(AsmFormat * format, char const * section)
{ {
if(format->plugin->section == NULL) if(format->plugin->section == NULL)
return 0; return 0;
@ -287,14 +287,14 @@ int format_section(Format * format, char const * section)
/* functions */ /* functions */
/* helpers */ /* helpers */
/* format_helper_get_filename */ /* format_helper_get_filename */
static char const * _format_helper_get_filename(Format * format) static char const * _format_helper_get_filename(AsmFormat * format)
{ {
return format->filename; return format->filename;
} }
/* format_helper_get_functions */ /* format_helper_get_functions */
static void _format_helper_get_functions(Format * format, static void _format_helper_get_functions(AsmFormat * format,
AsmFunction ** functions, size_t * functions_cnt) AsmFunction ** functions, size_t * functions_cnt)
{ {
asmcode_get_functions(format->code, functions, functions_cnt); asmcode_get_functions(format->code, functions, functions_cnt);
@ -302,7 +302,7 @@ static void _format_helper_get_functions(Format * format,
/* format_helper_get_section_by_id */ /* format_helper_get_section_by_id */
static AsmSection * _format_helper_get_section_by_id(Format * format, static AsmSection * _format_helper_get_section_by_id(AsmFormat * format,
AsmSectionId id) AsmSectionId id)
{ {
return asmcode_get_section_by_id(format->code, id); return asmcode_get_section_by_id(format->code, id);
@ -310,7 +310,7 @@ static AsmSection * _format_helper_get_section_by_id(Format * format,
/* format_helper_get_string_by_id */ /* format_helper_get_string_by_id */
static AsmString * _format_helper_get_string_by_id(Format * format, static AsmString * _format_helper_get_string_by_id(AsmFormat * format,
AsmStringId id) AsmStringId id)
{ {
return asmcode_get_string_by_id(format->code, id); return asmcode_get_string_by_id(format->code, id);
@ -318,7 +318,7 @@ static AsmString * _format_helper_get_string_by_id(Format * format,
/* format_helper_set_function */ /* format_helper_set_function */
static int _format_helper_set_function(Format * format, AsmFunctionId id, static int _format_helper_set_function(AsmFormat * format, AsmFunctionId id,
char const * name, off_t offset, ssize_t size) char const * name, off_t offset, ssize_t size)
{ {
return asmcode_set_function(format->code, id, name, offset, size); return asmcode_set_function(format->code, id, name, offset, size);
@ -326,7 +326,7 @@ static int _format_helper_set_function(Format * format, AsmFunctionId id,
/* format_helper_set_section */ /* format_helper_set_section */
static int _format_helper_set_section(Format * format, AsmSectionId id, static int _format_helper_set_section(AsmFormat * format, AsmSectionId id,
char const * name, off_t offset, ssize_t size, off_t base) char const * name, off_t offset, ssize_t size, off_t base)
{ {
return asmcode_set_section(format->code, id, name, offset, size, base); return asmcode_set_section(format->code, id, name, offset, size, base);
@ -334,7 +334,7 @@ static int _format_helper_set_section(Format * format, AsmSectionId id,
/* format_helper_set_string */ /* format_helper_set_string */
static int _format_helper_set_string(Format * format, AsmStringId id, static int _format_helper_set_string(AsmFormat * format, AsmStringId id,
char const * name, off_t offset, ssize_t size) char const * name, off_t offset, ssize_t size)
{ {
return asmcode_set_string(format->code, id, name, offset, size); return asmcode_set_string(format->code, id, name, offset, size);
@ -342,7 +342,7 @@ static int _format_helper_set_string(Format * format, AsmStringId id,
/* format_helper_decode */ /* format_helper_decode */
static int _format_helper_decode(Format * format, off_t offset, size_t size, static int _format_helper_decode(AsmFormat * format, off_t offset, size_t size,
off_t base, AsmArchInstructionCall ** calls, size_t * calls_cnt) off_t base, AsmArchInstructionCall ** calls, size_t * calls_cnt)
{ {
int ret; int ret;
@ -359,7 +359,7 @@ static int _format_helper_decode(Format * format, off_t offset, size_t size,
/* format_helper_read */ /* format_helper_read */
static ssize_t _format_helper_read(Format * format, void * buf, size_t size) static ssize_t _format_helper_read(AsmFormat * format, void * buf, size_t size)
{ {
if(fread(buf, size, 1, format->fp) == 1) if(fread(buf, size, 1, format->fp) == 1)
return size; return size;
@ -374,7 +374,7 @@ static ssize_t _format_helper_read(Format * format, void * buf, size_t size)
/* format_helper_seek */ /* format_helper_seek */
static off_t _format_helper_seek(Format * format, off_t offset, int whence) static off_t _format_helper_seek(AsmFormat * format, off_t offset, int whence)
{ {
if(whence == SEEK_SET) if(whence == SEEK_SET)
{ {
@ -394,7 +394,7 @@ static off_t _format_helper_seek(Format * format, off_t offset, int whence)
/* format_helper_write */ /* format_helper_write */
static ssize_t _format_helper_write(Format * format, void const * buf, static ssize_t _format_helper_write(AsmFormat * format, void const * buf,
size_t size) size_t size)
{ {
if(fwrite(buf, size, 1, format->fp) == 1) if(fwrite(buf, size, 1, format->fp) == 1)

View File

@ -23,40 +23,42 @@
# include "code.h" # include "code.h"
/* Format */ /* AsmFormat */
/* public */ /* public */
/* types */ /* types */
typedef int (*FormatDecodeCallback)(void * priv, char const * section, typedef int (*AsmFormatDecodeCallback)(void * priv, char const * section,
off_t offset, size_t size, off_t base); off_t offset, size_t size, off_t base);
typedef AsmString * (*FormatGetStringByIdCallback)(void * priv, AsmStringId id); typedef AsmString * (*AsmFormatGetStringByIdCallback)(void * priv,
typedef int (*FormatSetFunctionCallback)(void * priv, AsmFunctionId id, AsmStringId id);
typedef int (*AsmFormatSetFunctionCallback)(void * priv, AsmFunctionId id,
char const * name, off_t offset, ssize_t length); char const * name, off_t offset, ssize_t length);
typedef int (*FormatSetStringCallback)(void * priv, AsmStringId id, typedef int (*AsmFormatSetStringCallback)(void * priv, AsmStringId id,
char const * name, off_t offset, ssize_t length); char const * name, off_t offset, ssize_t length);
/* functions */ /* functions */
Format * format_new(char const * format); AsmFormat * format_new(char const * format);
void format_delete(Format * format); void format_delete(AsmFormat * format);
/* accessors */ /* accessors */
int format_can_decode(Format * format); int format_can_decode(AsmFormat * format);
char const * format_get_name(Format * format); char const * format_get_name(AsmFormat * format);
/* useful */ /* useful */
/* assembly */ /* assembly */
int format_init(Format * format, char const * arch, char const * filename, int format_init(AsmFormat * format, char const * arch, char const * filename,
FILE * fp); FILE * fp);
int format_exit(Format * format); int format_exit(AsmFormat * format);
int format_function(Format * format, char const * function); int format_function(AsmFormat * format, char const * function);
int format_section(Format * format, char const * section); int format_section(AsmFormat * format, char const * section);
/* disassembly */ /* disassembly */
int format_decode(Format * format, AsmCode * code, int raw); int format_decode(AsmFormat * format, AsmCode * code, int raw);
int format_decode_section(Format * format, AsmCode * code, AsmSection * section, int format_decode_section(AsmFormat * format, AsmCode * code,
AsmArchInstructionCall ** calls, size_t * calls_cnt); AsmSection * section, AsmArchInstructionCall ** calls,
char const * format_detect_arch(Format * format); size_t * calls_cnt);
int format_match(Format * format); char const * format_detect_arch(AsmFormat * format);
int format_match(AsmFormat * format);
#endif /* !ASM_FORMAT_H */ #endif /* !ASM_FORMAT_H */

View File

@ -122,17 +122,17 @@ static char _dex_signature[4] = "dex\n";
/* prototypes */ /* prototypes */
/* plug-in */ /* plug-in */
static int _dex_init(FormatPlugin * format, char const * arch); static int _dex_init(AsmFormatPlugin * format, char const * arch);
static int _dex_exit(FormatPlugin * format); static int _dex_exit(AsmFormatPlugin * format);
static char const * _dex_detect(FormatPlugin * format); static char const * _dex_detect(AsmFormatPlugin * format);
static int _dex_decode(FormatPlugin * format, int raw); static int _dex_decode(AsmFormatPlugin * format, int raw);
static int _dex_decode_section(FormatPlugin * format, AsmSection * section, static int _dex_decode_section(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt); AsmArchInstructionCall ** calls, size_t * calls_cnt);
/* public */ /* public */
/* variables */ /* variables */
FormatPlugin format_plugin = AsmFormatPlugin format_plugin =
{ {
NULL, NULL,
"dex", "dex",
@ -153,7 +153,7 @@ FormatPlugin format_plugin =
/* functions */ /* functions */
/* plug-in */ /* plug-in */
/* dex_init */ /* dex_init */
static int _dex_init(FormatPlugin * format, char const * arch) static int _dex_init(AsmFormatPlugin * format, char const * arch)
{ {
Dex * dex; Dex * dex;
@ -173,7 +173,7 @@ static int _dex_init(FormatPlugin * format, char const * arch)
/* dex_exit */ /* dex_exit */
static int _dex_exit(FormatPlugin * format) static int _dex_exit(AsmFormatPlugin * format)
{ {
Dex * dex = format->priv; Dex * dex = format->priv;
@ -184,7 +184,7 @@ static int _dex_exit(FormatPlugin * format)
/* dex_detect */ /* dex_detect */
static char const * _dex_detect(FormatPlugin * format) static char const * _dex_detect(AsmFormatPlugin * format)
{ {
/* XXX some sections might contain native code */ /* XXX some sections might contain native code */
return "dalvik"; return "dalvik";
@ -192,17 +192,17 @@ static char const * _dex_detect(FormatPlugin * format)
/* dex_decode */ /* dex_decode */
static int _decode_map(FormatPlugin * format, DexHeader * dh, int raw); static int _decode_map(AsmFormatPlugin * format, DexHeader * dh, int raw);
static int _decode_map_code(FormatPlugin * format, size_t id, off_t offset, static int _decode_map_code(AsmFormatPlugin * format, size_t id, off_t offset,
size_t size); size_t size);
static int _decode_map_method_id(FormatPlugin * format, off_t offset, static int _decode_map_method_id(AsmFormatPlugin * format, off_t offset,
size_t size); size_t size);
static int _decode_map_string_id(FormatPlugin * format, off_t offset, static int _decode_map_string_id(AsmFormatPlugin * format, off_t offset,
size_t size); size_t size);
static int _dex_decode(FormatPlugin * format, int raw) static int _dex_decode(AsmFormatPlugin * format, int raw)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
DexHeader dh; DexHeader dh;
#ifdef DEBUG #ifdef DEBUG
@ -218,10 +218,10 @@ static int _dex_decode(FormatPlugin * format, int raw)
return 0; return 0;
} }
static int _decode_map(FormatPlugin * format, DexHeader * dh, int raw) static int _decode_map(AsmFormatPlugin * format, DexHeader * dh, int raw)
{ {
int ret = 0; int ret = 0;
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
uint32_t size; uint32_t size;
uint32_t i; uint32_t i;
off_t offset; off_t offset;
@ -274,10 +274,10 @@ static int _decode_map(FormatPlugin * format, DexHeader * dh, int raw)
return ret; return ret;
} }
static int _decode_map_code(FormatPlugin * format, size_t id, off_t offset, static int _decode_map_code(AsmFormatPlugin * format, size_t id, off_t offset,
size_t size) size_t size)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%lu, %ld, %lu)\n", __func__, id, offset, fprintf(stderr, "DEBUG: %s(%lu, %ld, %lu)\n", __func__, id, offset,
@ -287,10 +287,10 @@ static int _decode_map_code(FormatPlugin * format, size_t id, off_t offset,
0) == id) ? 0 : -1; 0) == id) ? 0 : -1;
} }
static int _decode_map_method_id(FormatPlugin * format, off_t offset, static int _decode_map_method_id(AsmFormatPlugin * format, off_t offset,
size_t size) size_t size)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
Dex * dex = format->priv; Dex * dex = format->priv;
ssize_t s; ssize_t s;
size_t i; size_t i;
@ -326,10 +326,10 @@ static int _decode_map_method_id(FormatPlugin * format, off_t offset,
return 0; return 0;
} }
static int _decode_map_string_id(FormatPlugin * format, off_t offset, static int _decode_map_string_id(AsmFormatPlugin * format, off_t offset,
size_t size) size_t size)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
DexStringIdItem * dsii; DexStringIdItem * dsii;
ssize_t s; ssize_t s;
size_t i; size_t i;
@ -365,10 +365,10 @@ static int _decode_map_string_id(FormatPlugin * format, off_t offset,
/* dex_decode_section */ /* dex_decode_section */
static int _dex_decode_section(FormatPlugin * format, AsmSection * section, static int _dex_decode_section(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt) AsmArchInstructionCall ** calls, size_t * calls_cnt)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
DexMapCodeItem dmci; DexMapCodeItem dmci;
size_t i; size_t i;
off_t seek; off_t seek;

View File

@ -73,36 +73,36 @@ typedef struct _Elf
/* prototypes */ /* prototypes */
static int _elf_error(FormatPlugin * format); static int _elf_error(AsmFormatPlugin * format);
/* plug-in */ /* plug-in */
static int _elf_init(FormatPlugin * format, char const * arch); static int _elf_init(AsmFormatPlugin * format, char const * arch);
static int _elf_exit(FormatPlugin * format); static int _elf_exit(AsmFormatPlugin * format);
static char const * _elf_detect(FormatPlugin * format); static char const * _elf_detect(AsmFormatPlugin * format);
static int _elf_decode(FormatPlugin * format, int raw); static int _elf_decode(AsmFormatPlugin * format, int raw);
static int _elf_decode32(FormatPlugin * format, int raw); static int _elf_decode32(AsmFormatPlugin * format, int raw);
static int _elf_decode64(FormatPlugin * format, int raw); static int _elf_decode64(AsmFormatPlugin * format, int raw);
static int _elf_decode_section(FormatPlugin * format, AsmSection * section, static int _elf_decode_section(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt); AsmArchInstructionCall ** calls, size_t * calls_cnt);
/* ELF32 */ /* ELF32 */
static int _init_32(FormatPlugin * format); static int _init_32(AsmFormatPlugin * format);
static int _exit_32(FormatPlugin * format); static int _exit_32(AsmFormatPlugin * format);
static int _section_32(FormatPlugin * format, char const * name); static int _section_32(AsmFormatPlugin * format, char const * name);
static void _swap_32_ehdr(Elf32_Ehdr * ehdr); static void _swap_32_ehdr(Elf32_Ehdr * ehdr);
static void _swap_32_phdr(Elf32_Phdr * phdr); static void _swap_32_phdr(Elf32_Phdr * phdr);
static void _swap_32_shdr(Elf32_Shdr * shdr); static void _swap_32_shdr(Elf32_Shdr * shdr);
/* ELF64 */ /* ELF64 */
static int _init_64(FormatPlugin * format); static int _init_64(AsmFormatPlugin * format);
static int _exit_64(FormatPlugin * format); static int _exit_64(AsmFormatPlugin * format);
static int _section_64(FormatPlugin * format, char const * name); static int _section_64(AsmFormatPlugin * format, char const * name);
static void _swap_64_ehdr(Elf64_Ehdr * ehdr); static void _swap_64_ehdr(Elf64_Ehdr * ehdr);
static void _swap_64_phdr(Elf64_Phdr * phdr); static void _swap_64_phdr(Elf64_Phdr * phdr);
static void _swap_64_shdr(Elf64_Shdr * shdr); static void _swap_64_shdr(Elf64_Shdr * shdr);
/* ElfStrtab */ /* ElfStrtab */
static int _elfstrtab_set(FormatPlugin * format, ElfStrtab * strtab, static int _elfstrtab_set(AsmFormatPlugin * format, ElfStrtab * strtab,
char const * name); char const * name);
@ -171,7 +171,7 @@ static ElfStrtab shstrtab = { NULL, 0 }; /* section string table */
/* public */ /* public */
/* variables */ /* variables */
/* format_plugin */ /* format_plugin */
FormatPlugin format_plugin = AsmFormatPlugin format_plugin =
{ {
NULL, NULL,
"elf", "elf",
@ -191,7 +191,7 @@ FormatPlugin format_plugin =
/* private */ /* private */
/* functions */ /* functions */
/* elf_error */ /* elf_error */
static int _elf_error(FormatPlugin * format) static int _elf_error(AsmFormatPlugin * format)
{ {
return -error_set_code(1, "%s: %s", format->helper->get_filename( return -error_set_code(1, "%s: %s", format->helper->get_filename(
format->helper->format), strerror(errno)); format->helper->format), strerror(errno));
@ -201,7 +201,7 @@ static int _elf_error(FormatPlugin * format)
/* elf_init */ /* elf_init */
static ElfArch * _init_arch(char const * arch); static ElfArch * _init_arch(char const * arch);
static int _elf_init(FormatPlugin * format, char const * arch) static int _elf_init(AsmFormatPlugin * format, char const * arch)
{ {
Elf * elf; Elf * elf;
@ -257,7 +257,7 @@ static ElfArch * _init_arch(char const * arch)
/* elf_exit */ /* elf_exit */
static int _elf_exit(FormatPlugin * format) static int _elf_exit(AsmFormatPlugin * format)
{ {
Elf * elf = format->priv; Elf * elf = format->priv;
@ -272,12 +272,12 @@ static int _elf_exit(FormatPlugin * format)
/* elf_detect */ /* elf_detect */
static char const * _detect_32(FormatPlugin * format, Elf32_Ehdr * ehdr); static char const * _detect_32(AsmFormatPlugin * format, Elf32_Ehdr * ehdr);
static char const * _detect_64(FormatPlugin * format, Elf64_Ehdr * ehdr); static char const * _detect_64(AsmFormatPlugin * format, Elf64_Ehdr * ehdr);
static char const * _elf_detect(FormatPlugin * format) static char const * _elf_detect(AsmFormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
union union
{ {
Elf32_Ehdr ehdr32; Elf32_Ehdr ehdr32;
@ -300,7 +300,7 @@ static char const * _elf_detect(FormatPlugin * format)
return NULL; return NULL;
} }
static char const * _detect_32(FormatPlugin * format, Elf32_Ehdr * ehdr) static char const * _detect_32(AsmFormatPlugin * format, Elf32_Ehdr * ehdr)
{ {
format->decode = _elf_decode32; format->decode = _elf_decode32;
if(ehdr->e_ident[EI_DATA] != elf_arch_native->endian) if(ehdr->e_ident[EI_DATA] != elf_arch_native->endian)
@ -325,7 +325,7 @@ static char const * _detect_32(FormatPlugin * format, Elf32_Ehdr * ehdr)
return NULL; return NULL;
} }
static char const * _detect_64(FormatPlugin * format, Elf64_Ehdr * ehdr) static char const * _detect_64(AsmFormatPlugin * format, Elf64_Ehdr * ehdr)
{ {
format->decode = _elf_decode64; format->decode = _elf_decode64;
if(ehdr->e_ident[EI_DATA] != elf_arch_native->endian) if(ehdr->e_ident[EI_DATA] != elf_arch_native->endian)
@ -346,7 +346,7 @@ static char const * _detect_64(FormatPlugin * format, Elf64_Ehdr * ehdr)
/* elf_decode */ /* elf_decode */
static int _elf_decode(FormatPlugin * format, int raw) static int _elf_decode(AsmFormatPlugin * format, int raw)
{ {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%d)\n", __func__, raw); fprintf(stderr, "DEBUG: %s(%d)\n", __func__, raw);
@ -358,19 +358,19 @@ static int _elf_decode(FormatPlugin * format, int raw)
/* elf_decode32 */ /* elf_decode32 */
static int _decode32_shdr(FormatPlugin * format, Elf32_Ehdr * ehdr, static int _decode32_shdr(AsmFormatPlugin * format, Elf32_Ehdr * ehdr,
Elf32_Shdr ** shdr); Elf32_Shdr ** shdr);
static int _decode32_addr(FormatPlugin * format, Elf32_Ehdr * ehdr, static int _decode32_addr(AsmFormatPlugin * format, Elf32_Ehdr * ehdr,
Elf32_Addr * addr); Elf32_Addr * addr);
static int _decode32_strtab(FormatPlugin * format, Elf32_Shdr * shdr, static int _decode32_strtab(AsmFormatPlugin * format, Elf32_Shdr * shdr,
size_t shdr_cnt, uint16_t ndx, char ** strtab, size_t shdr_cnt, uint16_t ndx, char ** strtab,
size_t * strtab_cnt); size_t * strtab_cnt);
static int _decode32_symtab(FormatPlugin * format, Elf32_Ehdr * ehdr, static int _decode32_symtab(AsmFormatPlugin * format, Elf32_Ehdr * ehdr,
Elf32_Shdr * shdr, size_t shdr_cnt, uint16_t ndx); Elf32_Shdr * shdr, size_t shdr_cnt, uint16_t ndx);
static int _elf_decode32(FormatPlugin * format, int raw) static int _elf_decode32(AsmFormatPlugin * format, int raw)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
Elf32_Ehdr ehdr; Elf32_Ehdr ehdr;
Elf32_Shdr * shdr = NULL; Elf32_Shdr * shdr = NULL;
Elf32_Addr base = 0x0; Elf32_Addr base = 0x0;
@ -422,10 +422,10 @@ static int _elf_decode32(FormatPlugin * format, int raw)
return (i == ehdr.e_shnum) ? 0 : -1; return (i == ehdr.e_shnum) ? 0 : -1;
} }
static int _decode32_shdr(FormatPlugin * format, Elf32_Ehdr * ehdr, static int _decode32_shdr(AsmFormatPlugin * format, Elf32_Ehdr * ehdr,
Elf32_Shdr ** shdr) Elf32_Shdr ** shdr)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
ssize_t size; ssize_t size;
size_t i; size_t i;
@ -454,10 +454,10 @@ static int _decode32_shdr(FormatPlugin * format, Elf32_Ehdr * ehdr,
return 0; return 0;
} }
static int _decode32_addr(FormatPlugin * format, Elf32_Ehdr * ehdr, static int _decode32_addr(AsmFormatPlugin * format, Elf32_Ehdr * ehdr,
Elf32_Addr * addr) Elf32_Addr * addr)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
Elf32_Half i; Elf32_Half i;
Elf32_Phdr phdr; Elf32_Phdr phdr;
@ -480,11 +480,11 @@ static int _decode32_addr(FormatPlugin * format, Elf32_Ehdr * ehdr,
return 0; return 0;
} }
static int _decode32_strtab(FormatPlugin * format, Elf32_Shdr * shdr, static int _decode32_strtab(AsmFormatPlugin * format, Elf32_Shdr * shdr,
size_t shdr_cnt, uint16_t ndx, char ** strtab, size_t shdr_cnt, uint16_t ndx, char ** strtab,
size_t * strtab_cnt) size_t * strtab_cnt)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
if(ndx >= shdr_cnt) if(ndx >= shdr_cnt)
return -error_set_code(1, "%s: %s", return -error_set_code(1, "%s: %s",
@ -505,10 +505,10 @@ static int _decode32_strtab(FormatPlugin * format, Elf32_Shdr * shdr,
return 0; return 0;
} }
static int _decode32_symtab(FormatPlugin * format, Elf32_Ehdr * ehdr, static int _decode32_symtab(AsmFormatPlugin * format, Elf32_Ehdr * ehdr,
Elf32_Shdr * shdr, size_t shdr_cnt, uint16_t ndx) Elf32_Shdr * shdr, size_t shdr_cnt, uint16_t ndx)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
char * strtab = NULL; char * strtab = NULL;
size_t strtab_cnt = 0; size_t strtab_cnt = 0;
Elf32_Sym sym; Elf32_Sym sym;
@ -558,19 +558,19 @@ static int _decode32_symtab(FormatPlugin * format, Elf32_Ehdr * ehdr,
/* elf_decode64 */ /* elf_decode64 */
static int _decode64_shdr(FormatPlugin * format, Elf64_Ehdr * ehdr, static int _decode64_shdr(AsmFormatPlugin * format, Elf64_Ehdr * ehdr,
Elf64_Shdr ** shdr); Elf64_Shdr ** shdr);
static int _decode64_addr(FormatPlugin * format, Elf64_Ehdr * ehdr, static int _decode64_addr(AsmFormatPlugin * format, Elf64_Ehdr * ehdr,
Elf64_Addr * addr); Elf64_Addr * addr);
static int _decode64_strtab(FormatPlugin * format, Elf64_Shdr * shdr, static int _decode64_strtab(AsmFormatPlugin * format, Elf64_Shdr * shdr,
size_t shdr_cnt, uint16_t ndx, char ** strtab, size_t shdr_cnt, uint16_t ndx, char ** strtab,
size_t * strtab_cnt); size_t * strtab_cnt);
static int _decode64_symtab(FormatPlugin * format, Elf64_Ehdr * ehdr, static int _decode64_symtab(AsmFormatPlugin * format, Elf64_Ehdr * ehdr,
Elf64_Shdr * shdr, size_t shdr_cnt, uint16_t ndx); Elf64_Shdr * shdr, size_t shdr_cnt, uint16_t ndx);
static int _elf_decode64(FormatPlugin * format, int raw) static int _elf_decode64(AsmFormatPlugin * format, int raw)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
Elf64_Ehdr ehdr; Elf64_Ehdr ehdr;
Elf64_Shdr * shdr = NULL; Elf64_Shdr * shdr = NULL;
Elf64_Addr base = 0x0; Elf64_Addr base = 0x0;
@ -621,10 +621,10 @@ static int _elf_decode64(FormatPlugin * format, int raw)
return (i == ehdr.e_shnum) ? 0 : -1; return (i == ehdr.e_shnum) ? 0 : -1;
} }
static int _decode64_shdr(FormatPlugin * format, Elf64_Ehdr * ehdr, static int _decode64_shdr(AsmFormatPlugin * format, Elf64_Ehdr * ehdr,
Elf64_Shdr ** shdr) Elf64_Shdr ** shdr)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
ssize_t size; ssize_t size;
size_t i; size_t i;
@ -653,10 +653,10 @@ static int _decode64_shdr(FormatPlugin * format, Elf64_Ehdr * ehdr,
return 0; return 0;
} }
static int _decode64_addr(FormatPlugin * format, Elf64_Ehdr * ehdr, static int _decode64_addr(AsmFormatPlugin * format, Elf64_Ehdr * ehdr,
Elf64_Addr * addr) Elf64_Addr * addr)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
Elf64_Quarter i; Elf64_Quarter i;
Elf64_Phdr phdr; Elf64_Phdr phdr;
@ -679,11 +679,11 @@ static int _decode64_addr(FormatPlugin * format, Elf64_Ehdr * ehdr,
return 0; return 0;
} }
static int _decode64_strtab(FormatPlugin * format, Elf64_Shdr * shdr, static int _decode64_strtab(AsmFormatPlugin * format, Elf64_Shdr * shdr,
size_t shdr_cnt, uint16_t ndx, char ** strtab, size_t shdr_cnt, uint16_t ndx, char ** strtab,
size_t * strtab_cnt) size_t * strtab_cnt)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
ssize_t size; ssize_t size;
if(ndx >= shdr_cnt) if(ndx >= shdr_cnt)
@ -705,10 +705,10 @@ static int _decode64_strtab(FormatPlugin * format, Elf64_Shdr * shdr,
return 0; return 0;
} }
static int _decode64_symtab(FormatPlugin * format, Elf64_Ehdr * ehdr, static int _decode64_symtab(AsmFormatPlugin * format, Elf64_Ehdr * ehdr,
Elf64_Shdr * shdr, size_t shdr_cnt, uint16_t ndx) Elf64_Shdr * shdr, size_t shdr_cnt, uint16_t ndx)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
char * strtab = NULL; char * strtab = NULL;
size_t strtab_cnt = 0; size_t strtab_cnt = 0;
Elf64_Sym sym; Elf64_Sym sym;
@ -758,10 +758,10 @@ static int _decode64_symtab(FormatPlugin * format, Elf64_Ehdr * ehdr,
/* elf_decode_section */ /* elf_decode_section */
static int _elf_decode_section(FormatPlugin * format, AsmSection * section, static int _elf_decode_section(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt) AsmArchInstructionCall ** calls, size_t * calls_cnt)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
return helper->decode(helper->format, section->offset, section->size, return helper->decode(helper->format, section->offset, section->size,
section->base, calls, calls_cnt); section->base, calls, calls_cnt);
@ -789,9 +789,9 @@ static ElfSectionValues * _section_values(char const * name)
/* ELF32 */ /* ELF32 */
/* init_32 */ /* init_32 */
static int _init_32(FormatPlugin * format) static int _init_32(AsmFormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
Elf * elf = format->priv; Elf * elf = format->priv;
ElfArch * ea = elf->arch; ElfArch * ea = elf->arch;
Elf32_Ehdr hdr; Elf32_Ehdr hdr;
@ -829,13 +829,13 @@ static int _init_32(FormatPlugin * format)
/* exit_32 */ /* exit_32 */
static int _exit_32_phdr(FormatPlugin * format, Elf32_Off offset); static int _exit_32_phdr(AsmFormatPlugin * format, Elf32_Off offset);
static int _exit_32_shdr(FormatPlugin * format, Elf32_Off offset); static int _exit_32_shdr(AsmFormatPlugin * format, Elf32_Off offset);
static int _exit_32(FormatPlugin * format) static int _exit_32(AsmFormatPlugin * format)
{ {
int ret = 0; int ret = 0;
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
long offset; long offset;
#ifdef DEBUG #ifdef DEBUG
@ -858,9 +858,9 @@ static int _exit_32(FormatPlugin * format)
return ret; return ret;
} }
static int _exit_32_phdr(FormatPlugin * format, Elf32_Off offset) static int _exit_32_phdr(AsmFormatPlugin * format, Elf32_Off offset)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
Elf * elf = format->priv; Elf * elf = format->priv;
ElfArch * ea = elf->arch; ElfArch * ea = elf->arch;
Elf32_Ehdr hdr; Elf32_Ehdr hdr;
@ -893,9 +893,9 @@ static int _exit_32_phdr(FormatPlugin * format, Elf32_Off offset)
return 0; return 0;
} }
static int _exit_32_shdr(FormatPlugin * format, Elf32_Off offset) static int _exit_32_shdr(AsmFormatPlugin * format, Elf32_Off offset)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
Elf * elf = format->priv; Elf * elf = format->priv;
ElfArch * ea = elf->arch; ElfArch * ea = elf->arch;
Elf32_Word addralign = ea->addralign; Elf32_Word addralign = ea->addralign;
@ -947,9 +947,9 @@ static int _exit_32_shdr(FormatPlugin * format, Elf32_Off offset)
/* section_32 */ /* section_32 */
static int _section_32(FormatPlugin * format, char const * name) static int _section_32(AsmFormatPlugin * format, char const * name)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
Elf * elf = format->priv; Elf * elf = format->priv;
int ss; int ss;
Elf32_Shdr * p; Elf32_Shdr * p;
@ -1035,9 +1035,9 @@ static void _swap_32_shdr(Elf32_Shdr * shdr)
/* ELF64 */ /* ELF64 */
/* init_64 */ /* init_64 */
static int _init_64(FormatPlugin * format) static int _init_64(AsmFormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
Elf * elf = format->priv; Elf * elf = format->priv;
ElfArch * ea = elf->arch; ElfArch * ea = elf->arch;
Elf64_Ehdr hdr; Elf64_Ehdr hdr;
@ -1074,13 +1074,13 @@ static int _init_64(FormatPlugin * format)
/* exit_64 */ /* exit_64 */
static int _exit_64_phdr(FormatPlugin * format, Elf64_Off offset); static int _exit_64_phdr(AsmFormatPlugin * format, Elf64_Off offset);
static int _exit_64_shdr(FormatPlugin * format, Elf64_Off offset); static int _exit_64_shdr(AsmFormatPlugin * format, Elf64_Off offset);
static int _exit_64(FormatPlugin * format) static int _exit_64(AsmFormatPlugin * format)
{ {
int ret = 0; int ret = 0;
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
long offset; long offset;
if(_section_64(format, ".shstrtab") != 0) if(_section_64(format, ".shstrtab") != 0)
@ -1100,9 +1100,9 @@ static int _exit_64(FormatPlugin * format)
return ret; return ret;
} }
static int _exit_64_phdr(FormatPlugin * format, Elf64_Off offset) static int _exit_64_phdr(AsmFormatPlugin * format, Elf64_Off offset)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
Elf * elf = format->priv; Elf * elf = format->priv;
ElfArch * ea = elf->arch; ElfArch * ea = elf->arch;
Elf64_Ehdr hdr; Elf64_Ehdr hdr;
@ -1132,9 +1132,9 @@ static int _exit_64_phdr(FormatPlugin * format, Elf64_Off offset)
return 0; return 0;
} }
static int _exit_64_shdr(FormatPlugin * format, Elf64_Off offset) static int _exit_64_shdr(AsmFormatPlugin * format, Elf64_Off offset)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
Elf * elf = format->priv; Elf * elf = format->priv;
ElfArch * ea = elf->arch; ElfArch * ea = elf->arch;
Elf64_Xword addralign = ea->addralign; Elf64_Xword addralign = ea->addralign;
@ -1180,9 +1180,9 @@ static int _exit_64_shdr(FormatPlugin * format, Elf64_Off offset)
/* section_64 */ /* section_64 */
static int _section_64(FormatPlugin * format, char const * name) static int _section_64(AsmFormatPlugin * format, char const * name)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
Elf * elf = format->priv; Elf * elf = format->priv;
int ss; int ss;
Elf64_Shdr * p; Elf64_Shdr * p;
@ -1267,7 +1267,7 @@ static void _swap_64_shdr(Elf64_Shdr * shdr)
/* private */ /* private */
/* functions */ /* functions */
/* elfstrtab_get */ /* elfstrtab_get */
static int _elfstrtab_set(FormatPlugin * format, ElfStrtab * strtab, static int _elfstrtab_set(AsmFormatPlugin * format, ElfStrtab * strtab,
char const * name) char const * name)
{ {
size_t len; size_t len;

View File

@ -24,14 +24,14 @@
/* private */ /* private */
/* prototypes */ /* prototypes */
/* plug-in */ /* plug-in */
static int _flat_decode(FormatPlugin * format, int raw); static int _flat_decode(AsmFormatPlugin * format, int raw);
static int _flat_decode_section(FormatPlugin * format, AsmSection * section, static int _flat_decode_section(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt); AsmArchInstructionCall ** calls, size_t * calls_cnt);
/* public */ /* public */
/* variables */ /* variables */
FormatPlugin format_plugin = AsmFormatPlugin format_plugin =
{ {
NULL, NULL,
"flat", "flat",
@ -52,9 +52,9 @@ FormatPlugin format_plugin =
/* functions */ /* functions */
/* plug-in */ /* plug-in */
/* flat_decode */ /* flat_decode */
static int _flat_decode(FormatPlugin * format, int raw) static int _flat_decode(AsmFormatPlugin * format, int raw)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
off_t offset; off_t offset;
if((offset = helper->seek(helper->format, 0, SEEK_END)) >= 0) if((offset = helper->seek(helper->format, 0, SEEK_END)) >= 0)
@ -65,10 +65,10 @@ static int _flat_decode(FormatPlugin * format, int raw)
/* flat_decode_section */ /* flat_decode_section */
static int _flat_decode_section(FormatPlugin * format, AsmSection * section, static int _flat_decode_section(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt) AsmArchInstructionCall ** calls, size_t * calls_cnt)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
if(section->id != 0) if(section->id != 0)
return -1; return -1;

View File

@ -142,18 +142,18 @@ static char _java_signature[4] = "\xca\xfe\xba\xbe";
/* prototypes */ /* prototypes */
/* plug-in */ /* plug-in */
static int _java_init(FormatPlugin * format, char const * arch); static int _java_init(AsmFormatPlugin * format, char const * arch);
static int _java_exit(FormatPlugin * format); static int _java_exit(AsmFormatPlugin * format);
static char const * _java_detect(FormatPlugin * format); static char const * _java_detect(AsmFormatPlugin * format);
static int _java_decode(FormatPlugin * format, int raw); static int _java_decode(AsmFormatPlugin * format, int raw);
static int _java_decode_section(FormatPlugin * format, AsmSection * section, static int _java_decode_section(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt); AsmArchInstructionCall ** calls, size_t * calls_cnt);
/* public */ /* public */
/* variables */ /* variables */
/* format_plugin */ /* format_plugin */
FormatPlugin format_plugin = AsmFormatPlugin format_plugin =
{ {
NULL, NULL,
"java", "java",
@ -173,7 +173,7 @@ FormatPlugin format_plugin =
/* private */ /* private */
/* functions */ /* functions */
/* java_init */ /* java_init */
static int _java_init(FormatPlugin * format, char const * arch) static int _java_init(AsmFormatPlugin * format, char const * arch)
{ {
JavaPlugin * java; JavaPlugin * java;
@ -197,16 +197,16 @@ static int _java_init(FormatPlugin * format, char const * arch)
/* java_exit */ /* java_exit */
static int _exit_constant_pool(FormatPlugin * format); static int _exit_constant_pool(AsmFormatPlugin * format);
static int _exit_access_flags(FormatPlugin * format); static int _exit_access_flags(AsmFormatPlugin * format);
static int _exit_class_name(FormatPlugin * format); static int _exit_class_name(AsmFormatPlugin * format);
static int _exit_super_name(FormatPlugin * format); static int _exit_super_name(AsmFormatPlugin * format);
static int _exit_interface_table(FormatPlugin * format); static int _exit_interface_table(AsmFormatPlugin * format);
static int _exit_field_table(FormatPlugin * format); static int _exit_field_table(AsmFormatPlugin * format);
static int _exit_method_table(FormatPlugin * format); static int _exit_method_table(AsmFormatPlugin * format);
static int _exit_attribute_table(FormatPlugin * format); static int _exit_attribute_table(AsmFormatPlugin * format);
static int _java_exit(FormatPlugin * format) static int _java_exit(AsmFormatPlugin * format)
{ {
int ret = 0; int ret = 0;
JavaPlugin * java = format->priv; JavaPlugin * java = format->priv;
@ -225,9 +225,9 @@ static int _java_exit(FormatPlugin * format)
return ret; return ret;
} }
static int _exit_constant_pool(FormatPlugin * format) static int _exit_constant_pool(AsmFormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
JavaPlugin * java = format->priv; JavaPlugin * java = format->priv;
uint16_t cnt = _htob16(java->constants_cnt + 1); uint16_t cnt = _htob16(java->constants_cnt + 1);
@ -237,9 +237,9 @@ static int _exit_constant_pool(FormatPlugin * format)
return 0; return 0;
} }
static int _exit_access_flags(FormatPlugin * format) static int _exit_access_flags(AsmFormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
JavaPlugin * java = format->priv; JavaPlugin * java = format->priv;
uint16_t flags = _htob16(java->access_flags); uint16_t flags = _htob16(java->access_flags);
@ -249,9 +249,9 @@ static int _exit_access_flags(FormatPlugin * format)
return 0; return 0;
} }
static int _exit_class_name(FormatPlugin * format) static int _exit_class_name(AsmFormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
uint16_t index = _htob16(0); uint16_t index = _htob16(0);
/* FIXME really implement */ /* FIXME really implement */
@ -261,9 +261,9 @@ static int _exit_class_name(FormatPlugin * format)
return 0; return 0;
} }
static int _exit_super_name(FormatPlugin * format) static int _exit_super_name(AsmFormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
uint16_t index = _htob16(0); uint16_t index = _htob16(0);
/* FIXME really implement */ /* FIXME really implement */
@ -273,9 +273,9 @@ static int _exit_super_name(FormatPlugin * format)
return 0; return 0;
} }
static int _exit_interface_table(FormatPlugin * format) static int _exit_interface_table(AsmFormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
JavaPlugin * java = format->priv; JavaPlugin * java = format->priv;
uint16_t cnt = _htob16(java->interfaces_cnt); uint16_t cnt = _htob16(java->interfaces_cnt);
@ -285,9 +285,9 @@ static int _exit_interface_table(FormatPlugin * format)
return 0; return 0;
} }
static int _exit_field_table(FormatPlugin * format) static int _exit_field_table(AsmFormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
JavaPlugin * java = format->priv; JavaPlugin * java = format->priv;
uint16_t cnt = _htob16(java->fields_cnt); uint16_t cnt = _htob16(java->fields_cnt);
@ -297,9 +297,9 @@ static int _exit_field_table(FormatPlugin * format)
return 0; return 0;
} }
static int _exit_method_table(FormatPlugin * format) static int _exit_method_table(AsmFormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
JavaPlugin * java = format->priv; JavaPlugin * java = format->priv;
uint16_t cnt = _htob16(java->methods_cnt); uint16_t cnt = _htob16(java->methods_cnt);
@ -309,9 +309,9 @@ static int _exit_method_table(FormatPlugin * format)
return 0; return 0;
} }
static int _exit_attribute_table(FormatPlugin * format) static int _exit_attribute_table(AsmFormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
JavaPlugin * java = format->priv; JavaPlugin * java = format->priv;
uint16_t cnt = _htob16(java->attributes_cnt); uint16_t cnt = _htob16(java->attributes_cnt);
@ -323,9 +323,9 @@ static int _exit_attribute_table(FormatPlugin * format)
/* java_detect */ /* java_detect */
static char const * _java_detect(FormatPlugin * format) static char const * _java_detect(AsmFormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
JavaHeader jh; JavaHeader jh;
if(helper->seek(helper->format, 0, SEEK_SET) != 0) if(helper->seek(helper->format, 0, SEEK_SET) != 0)
@ -344,9 +344,9 @@ static char const * _java_detect(FormatPlugin * format)
/* java_decode */ /* java_decode */
static int _java_decode(FormatPlugin * format, int raw) static int _java_decode(AsmFormatPlugin * format, int raw)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
off_t end; off_t end;
/* XXX consider the whole file as a section */ /* XXX consider the whole file as a section */
@ -357,20 +357,20 @@ static int _java_decode(FormatPlugin * format, int raw)
/* java_decode_section */ /* java_decode_section */
static int _decode_attributes(FormatPlugin * format, uint16_t cnt, static int _decode_attributes(AsmFormatPlugin * format, uint16_t cnt,
AsmArchInstructionCall ** calls, size_t * calls_cnt); AsmArchInstructionCall ** calls, size_t * calls_cnt);
static int _decode_constants(FormatPlugin * format, uint16_t cnt); static int _decode_constants(AsmFormatPlugin * format, uint16_t cnt);
static int _decode_fields(FormatPlugin * format, uint16_t cnt); static int _decode_fields(AsmFormatPlugin * format, uint16_t cnt);
static int _decode_interfaces(FormatPlugin * format, uint16_t cnt); static int _decode_interfaces(AsmFormatPlugin * format, uint16_t cnt);
static int _decode_methods(FormatPlugin * format, uint16_t cnt, static int _decode_methods(AsmFormatPlugin * format, uint16_t cnt,
AsmArchInstructionCall ** calls, size_t * calls_cnt); AsmArchInstructionCall ** calls, size_t * calls_cnt);
static int _methods_add(FormatPlugin * format, uint16_t id, uint16_t name, static int _methods_add(AsmFormatPlugin * format, uint16_t id, uint16_t name,
off_t offset, size_t size); off_t offset, size_t size);
static int _java_decode_section(FormatPlugin * format, AsmSection * section, static int _java_decode_section(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt) AsmArchInstructionCall ** calls, size_t * calls_cnt)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
JavaPlugin * java = format->priv; JavaPlugin * java = format->priv;
JavaHeader jh; JavaHeader jh;
JavaHeader2 jh2; JavaHeader2 jh2;
@ -411,10 +411,10 @@ static int _java_decode_section(FormatPlugin * format, AsmSection * section,
return 0; return 0;
} }
static int _decode_attributes(FormatPlugin * format, uint16_t cnt, static int _decode_attributes(AsmFormatPlugin * format, uint16_t cnt,
AsmArchInstructionCall ** calls, size_t * calls_cnt) AsmArchInstructionCall ** calls, size_t * calls_cnt)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
size_t i; size_t i;
JavaAttributeInfo jai; JavaAttributeInfo jai;
off_t offset; off_t offset;
@ -446,9 +446,9 @@ static int _decode_attributes(FormatPlugin * format, uint16_t cnt,
return 0; return 0;
} }
static int _decode_constants(FormatPlugin * format, uint16_t cnt) static int _decode_constants(AsmFormatPlugin * format, uint16_t cnt)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
JavaPlugin * java = format->priv; JavaPlugin * java = format->priv;
size_t i; size_t i;
JavaCpInfo * jci; JavaCpInfo * jci;
@ -598,9 +598,9 @@ static int _decode_constants(FormatPlugin * format, uint16_t cnt)
return 0; return 0;
} }
static int _decode_fields(FormatPlugin * format, uint16_t cnt) static int _decode_fields(AsmFormatPlugin * format, uint16_t cnt)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
size_t i; size_t i;
JavaFieldInfo jfi; JavaFieldInfo jfi;
@ -618,9 +618,9 @@ static int _decode_fields(FormatPlugin * format, uint16_t cnt)
return 0; return 0;
} }
static int _decode_interfaces(FormatPlugin * format, uint16_t cnt) static int _decode_interfaces(AsmFormatPlugin * format, uint16_t cnt)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
size_t i; size_t i;
uint16_t u16; uint16_t u16;
@ -634,10 +634,10 @@ static int _decode_interfaces(FormatPlugin * format, uint16_t cnt)
return 0; return 0;
} }
static int _decode_methods(FormatPlugin * format, uint16_t cnt, static int _decode_methods(AsmFormatPlugin * format, uint16_t cnt,
AsmArchInstructionCall ** calls, size_t * calls_cnt) AsmArchInstructionCall ** calls, size_t * calls_cnt)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
size_t i; size_t i;
JavaMethodInfo jmi; JavaMethodInfo jmi;
off_t begin; off_t begin;
@ -670,10 +670,10 @@ static int _decode_methods(FormatPlugin * format, uint16_t cnt,
return 0; return 0;
} }
static int _methods_add(FormatPlugin * format, uint16_t id, uint16_t name, static int _methods_add(AsmFormatPlugin * format, uint16_t id, uint16_t name,
off_t offset, size_t size) off_t offset, size_t size)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
JavaPlugin * java = format->priv; JavaPlugin * java = format->priv;
JavaCpInfo * jci; JavaCpInfo * jci;
AsmString * as; AsmString * as;

View File

@ -210,10 +210,10 @@ static char const _pe_header_signature[4] = "PE\0\0";
/* prototypes */ /* prototypes */
/* plug-in */ /* plug-in */
static int _pe_init(FormatPlugin * format, char const * arch); static int _pe_init(AsmFormatPlugin * format, char const * arch);
static char const * _pe_detect(FormatPlugin * format); static char const * _pe_detect(AsmFormatPlugin * format);
static int _pe_decode(FormatPlugin * format, int raw); static int _pe_decode(AsmFormatPlugin * format, int raw);
static int _pe_decode_section(FormatPlugin * format, AsmSection * section, static int _pe_decode_section(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt); AsmArchInstructionCall ** calls, size_t * calls_cnt);
/* useful */ /* useful */
@ -223,7 +223,7 @@ static int _pe_get_machine(char const * arch);
/* public */ /* public */
/* variables */ /* variables */
FormatPlugin format_plugin = AsmFormatPlugin format_plugin =
{ {
NULL, NULL,
"pe", "pe",
@ -243,9 +243,9 @@ FormatPlugin format_plugin =
/* private */ /* private */
/* functions */ /* functions */
/* pe_init */ /* pe_init */
static int _pe_init(FormatPlugin * format, char const * arch) static int _pe_init(AsmFormatPlugin * format, char const * arch)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
int machine; int machine;
struct pe_msdos pm; struct pe_msdos pm;
struct pe_header ph; struct pe_header ph;
@ -277,9 +277,9 @@ static int _pe_init(FormatPlugin * format, char const * arch)
/* pe_detect */ /* pe_detect */
static char const * _pe_detect(FormatPlugin * format) static char const * _pe_detect(AsmFormatPlugin * format)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
struct pe_msdos pm; struct pe_msdos pm;
struct pe_header ph; struct pe_header ph;
@ -298,16 +298,16 @@ static char const * _pe_detect(FormatPlugin * format)
/* pe_decode */ /* pe_decode */
static int _decode_data(FormatPlugin * format, uint32_t vaddr, uint32_t base, static int _decode_data(AsmFormatPlugin * format, uint32_t vaddr, uint32_t base,
struct pe_image_header_data * pid, size_t i); struct pe_image_header_data * pid, size_t i);
static int _decode_data_export_directory(FormatPlugin * format, uint32_t vaddr, static int _decode_data_export_directory(AsmFormatPlugin * format, uint32_t vaddr,
uint32_t base, struct pe_image_header_data * pid); uint32_t base, struct pe_image_header_data * pid);
static int _decode_error(FormatPlugin * format); static int _decode_error(AsmFormatPlugin * format);
static char * _decode_string(FormatPlugin * format, off_t offset); static char * _decode_string(AsmFormatPlugin * format, off_t offset);
static int _pe_decode(FormatPlugin * format, int raw) static int _pe_decode(AsmFormatPlugin * format, int raw)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
struct pe_msdos pm; struct pe_msdos pm;
char buf[sizeof(_pe_header_signature)]; char buf[sizeof(_pe_header_signature)];
struct pe_header ph; struct pe_header ph;
@ -440,7 +440,7 @@ static int _pe_decode(FormatPlugin * format, int raw)
return 0; return 0;
} }
static int _decode_data(FormatPlugin * format, uint32_t vaddr, uint32_t base, static int _decode_data(AsmFormatPlugin * format, uint32_t vaddr, uint32_t base,
struct pe_image_header_data * pid, size_t i) struct pe_image_header_data * pid, size_t i)
{ {
pid->vaddr = _htol32(pid->vaddr); pid->vaddr = _htol32(pid->vaddr);
@ -461,10 +461,10 @@ static int _decode_data(FormatPlugin * format, uint32_t vaddr, uint32_t base,
return 0; return 0;
} }
static int _decode_data_export_directory(FormatPlugin * format, uint32_t vaddr, static int _decode_data_export_directory(AsmFormatPlugin * format, uint32_t vaddr,
uint32_t base, struct pe_image_header_data * pid) uint32_t base, struct pe_image_header_data * pid)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
struct pe_export_directory ped; struct pe_export_directory ped;
size_t j; size_t j;
uint32_t f; uint32_t f;
@ -518,15 +518,15 @@ static int _decode_data_export_directory(FormatPlugin * format, uint32_t vaddr,
return 0; return 0;
} }
static int _decode_error(FormatPlugin * format) static int _decode_error(AsmFormatPlugin * format)
{ {
return -error_set_code(1, "%s: %s", format->helper->get_filename( return -error_set_code(1, "%s: %s", format->helper->get_filename(
format->helper->format), strerror(errno)); format->helper->format), strerror(errno));
} }
static char * _decode_string(FormatPlugin * format, off_t offset) static char * _decode_string(AsmFormatPlugin * format, off_t offset)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
char * ret = NULL; char * ret = NULL;
char * p; char * p;
size_t len = 0; size_t len = 0;
@ -559,10 +559,10 @@ static char * _decode_string(FormatPlugin * format, off_t offset)
/* pe_decode_section */ /* pe_decode_section */
static int _pe_decode_section(FormatPlugin * format, AsmSection * section, static int _pe_decode_section(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt) AsmArchInstructionCall ** calls, size_t * calls_cnt)
{ {
FormatPluginHelper * helper = format->helper; AsmFormatPluginHelper * helper = format->helper;
return helper->decode(helper->format, section->offset, section->size, return helper->decode(helper->format, section->offset, section->size,
section->base, calls, calls_cnt); section->base, calls, calls_cnt);