Initial TE format support

This commit is contained in:
Anton Kochkov 2013-03-02 01:08:31 +04:00
parent 13bbde408a
commit d580e72a70
6 changed files with 785 additions and 1 deletions

385
libr/bin/format/te/te.c Normal file
View File

@ -0,0 +1,385 @@
/* radare - LGPL - Copyright 2008-2013 nibble, pancake, xvilka */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <r_types.h>
#include <r_util.h>
#include "te_specs.h"
#include "te.h"
/* TODO:
* 1. Implement import/export
* 2. Implement symbols support
* 3. Implement debugging info support
* 4. More sections parse
*/
ut64 r_bin_te_get_main_offset(struct r_bin_te_obj_t *bin) {
struct r_bin_te_addr_t *entry = r_bin_te_get_entrypoint (bin);
ut64 addr = 0LL;
ut8 buf[512];
if (r_buf_read_at (bin->b, entry->offset, buf, sizeof (buf)) == -1) {
eprintf ("Error: read (entry)\n");
} else {
if (buf[367] == 0xe8) {
int delta = (buf[368] | buf[369]<<8 | buf[370]<<16 | buf[371]<<24);
addr = entry->rva + 367 + 5 + delta;
}
}
free (entry);
return addr;
}
static TE_DWord r_bin_te_rva_to_offset(struct r_bin_te_obj_t* bin, TE_DWord rva) {
TE_DWord section_base;
int i, section_size;
for (i = 0; i < bin->header->NumberOfSections; i++) {
section_base = bin->section_header[i].VirtualAddress;
section_size = bin->section_header[i].VirtualSize;
if (rva >= section_base && rva < section_base + section_size)
return bin->section_header[i].PointerToRawData + (rva - section_base);
}
return 0;
}
static int r_bin_te_init_hdr(struct r_bin_te_obj_t* bin) {
if (!(bin->header = malloc(sizeof(TE_image_file_header)))) {
perror ("malloc (header)");
return R_FALSE;
}
if (r_buf_read_at (bin->b, 0, (ut8*)bin->header, sizeof(TE_image_file_header)) == -1) {
eprintf("Error: read (header)\n");
return R_FALSE;
}
if (strncmp ((char*)&bin->header->Signature, "VZ", 2))
return R_FALSE;
return R_TRUE;
}
static int r_bin_te_init_sections(struct r_bin_te_obj_t* bin) {
int sections_size = sizeof(TE_image_file_header) * bin->header->NumberOfSections;
if (sections_size > bin->size) {
eprintf ("Invalid NumberOfSections value\n");
return R_FALSE;
}
if (!(bin->section_header = malloc (sections_size))) {
perror ("malloc (sections headers)");
return R_FALSE;
}
if (r_buf_read_at (bin->b, bin->header + sizeof(TE_image_file_header),
(ut8*)bin->section_header, sections_size) == -1) {
eprintf ("Error: read (sections headers)\n");
return R_FALSE;
}
return R_TRUE;
}
static int r_bin_te_init(struct r_bin_te_obj_t* bin) {
bin->header = NULL;
bin->section_header = NULL;
//bin->export_directory = NULL;
//bin->import_directory = NULL;
bin->endian = 0;
if (!r_bin_te_init_hdr(bin)) {
eprintf("Warning: File is not TE\n");
return R_FALSE;
}
if (!r_bin_te_init_sections(bin)) {
eprintf("Warning: Cannot initialize sections\n");
return R_FALSE;
}
// FIXME: Not yet implemented!
//r_bin_te_init_imports(bin);
//r_bin_te_init_exports(bin);
return R_TRUE;
}
char* r_bin_te_get_arch(struct r_bin_te_obj_t* bin) {
char *arch;
switch (bin->header->Machine) {
case TE_IMAGE_FILE_MACHINE_ALPHA:
case TE_IMAGE_FILE_MACHINE_ALPHA64:
arch = strdup("alpha");
break;
case TE_IMAGE_FILE_MACHINE_ARM:
case TE_IMAGE_FILE_MACHINE_THUMB:
arch = strdup("arm");
break;
case TE_IMAGE_FILE_MACHINE_M68K:
arch = strdup("m68k");
break;
case TE_IMAGE_FILE_MACHINE_MIPS16:
case TE_IMAGE_FILE_MACHINE_MIPSFPU:
case TE_IMAGE_FILE_MACHINE_MIPSFPU16:
case TE_IMAGE_FILE_MACHINE_WCEMIPSV2:
arch = strdup("mips");
break;
case TE_IMAGE_FILE_MACHINE_POWERPC:
case TE_IMAGE_FILE_MACHINE_POWERPCFP:
arch = strdup("ppc");
break;
default:
arch = strdup("x86");
}
return arch;
}
struct r_bin_te_addr_t* r_bin_te_get_entrypoint(struct r_bin_te_obj_t* bin) {
struct r_bin_te_addr_t *entry = NULL;
if ((entry = malloc(sizeof(struct r_bin_te_addr_t))) == NULL) {
perror("malloc (entrypoint)");
return NULL;
}
entry->rva = bin->header->AddressOfEntryPoint;
if (entry->rva == 0) // in TE if EP = 0 then EP = baddr
entry->rva = bin->header->ImageBase;
entry->offset = r_bin_te_rva_to_offset(bin, entry->rva);
return entry;
}
ut64 r_bin_te_get_image_base(struct r_bin_te_obj_t* bin)
{
return (ut64)bin->header->ImageBase;
}
int r_bin_te_get_image_size(struct r_bin_te_obj_t* bin) {
return bin->header->StrippedSize;
}
char* r_bin_te_get_machine(struct r_bin_te_obj_t* bin) {
char *machine;
switch (bin->header->Machine) {
case TE_IMAGE_FILE_MACHINE_ALPHA:
machine = strdup("Alpha");
break;
case TE_IMAGE_FILE_MACHINE_ALPHA64:
machine = strdup("Alpha 64");
break;
case TE_IMAGE_FILE_MACHINE_AM33:
machine = strdup("AM33");
break;
case TE_IMAGE_FILE_MACHINE_AMD64:
machine = strdup("AMD 64");
break;
case TE_IMAGE_FILE_MACHINE_ARM:
machine = strdup("ARM");
break;
case TE_IMAGE_FILE_MACHINE_CEE:
machine = strdup("CEE");
break;
case TE_IMAGE_FILE_MACHINE_CEF:
machine = strdup("CEF");
break;
case TE_IMAGE_FILE_MACHINE_EBC:
machine = strdup("EBC");
break;
case TE_IMAGE_FILE_MACHINE_I386:
machine = strdup("i386");
break;
case TE_IMAGE_FILE_MACHINE_IA64:
machine = strdup("ia64");
break;
case TE_IMAGE_FILE_MACHINE_M32R:
machine = strdup("M32R");
break;
case TE_IMAGE_FILE_MACHINE_M68K:
machine = strdup("M68K");
break;
case TE_IMAGE_FILE_MACHINE_MIPS16:
machine = strdup("Mips 16");
break;
case TE_IMAGE_FILE_MACHINE_MIPSFPU:
machine = strdup("Mips FPU");
break;
case TE_IMAGE_FILE_MACHINE_MIPSFPU16:
machine = strdup("Mips FPU 16");
break;
case TE_IMAGE_FILE_MACHINE_POWERPC:
machine = strdup("PowerPC");
break;
case TE_IMAGE_FILE_MACHINE_POWERPCFP:
machine = strdup("PowerPC FP");
break;
case TE_IMAGE_FILE_MACHINE_R10000:
machine = strdup("R10000");
break;
case TE_IMAGE_FILE_MACHINE_R3000:
machine = strdup("R3000");
break;
case TE_IMAGE_FILE_MACHINE_R4000:
machine = strdup("R4000");
break;
case TE_IMAGE_FILE_MACHINE_SH3:
machine = strdup("SH3");
break;
case TE_IMAGE_FILE_MACHINE_SH3DSP:
machine = strdup("SH3DSP");
break;
case TE_IMAGE_FILE_MACHINE_SH3E:
machine = strdup("SH3E");
break;
case TE_IMAGE_FILE_MACHINE_SH4:
machine = strdup("SH4");
break;
case TE_IMAGE_FILE_MACHINE_SH5:
machine = strdup("SH5");
break;
case TE_IMAGE_FILE_MACHINE_THUMB:
machine = strdup("Thumb");
break;
case TE_IMAGE_FILE_MACHINE_TRICORE:
machine = strdup("Tricore");
break;
case TE_IMAGE_FILE_MACHINE_WCEMIPSV2:
machine = strdup("WCE Mips V2");
break;
default:
machine = strdup("unknown");
}
return machine;
}
char* r_bin_te_get_os(struct r_bin_te_obj_t* bin) {
char *os;
switch (bin->header->Subsystem) {
case TE_IMAGE_SUBSYSTEM_NATIVE:
os = strdup("native");
break;
case TE_IMAGE_SUBSYSTEM_WINDOWS_GUI:
case TE_IMAGE_SUBSYSTEM_WINDOWS_CUI:
case TE_IMAGE_SUBSYSTEM_WINDOWS_CE_GUI:
os = strdup ("windows");
break;
case TE_IMAGE_SUBSYSTEM_POSIX_CUI:
os = strdup ("posix");
break;
case TE_IMAGE_SUBSYSTEM_EFI_APPLICATION:
case TE_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
case TE_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
case TE_IMAGE_SUBSYSTEM_EFI_ROM:
os = strdup ("efi");
break;
case TE_IMAGE_SUBSYSTEM_XBOX:
os = strdup ("xbox");
break;
default:
// XXX: this is unknown
os = strdup ("windows");
}
return os;
}
struct r_bin_te_section_t* r_bin_te_get_sections(struct r_bin_te_obj_t* bin) {
struct r_bin_te_section_t *sections = NULL;
TE_image_section_header *shdr = bin->section_header;
int i, sections_count = bin->header->NumberOfSections;
if ((sections = malloc((sections_count + 1) * sizeof(struct r_bin_te_section_t))) == NULL) {
perror ("malloc (sections)");
return NULL;
}
for (i = 0; i < sections_count; i++) {
memcpy (sections[i].name, shdr[i].Name, TE_IMAGE_SIZEOF_NAME);
sections[i].name[TE_IMAGE_SIZEOF_NAME-1] = '\0';
sections[i].rva = shdr[i].VirtualAddress;
sections[i].size = shdr[i].SizeOfRawData;
sections[i].vsize = shdr[i].VirtualSize;
sections[i].offset = shdr[i].PointerToRawData;
sections[i].flags = shdr[i].Characteristics;
sections[i].last = 0;
}
sections[i].last = 1;
return sections;
}
char* r_bin_te_get_subsystem(struct r_bin_te_obj_t* bin) {
char *subsystem;
switch (bin->header->Subsystem) {
case TE_IMAGE_SUBSYSTEM_NATIVE:
subsystem = strdup("Native");
break;
case TE_IMAGE_SUBSYSTEM_WINDOWS_GUI:
subsystem = strdup("Windows GUI");
break;
case TE_IMAGE_SUBSYSTEM_WINDOWS_CUI:
subsystem = strdup("Windows CUI");
break;
case TE_IMAGE_SUBSYSTEM_POSIX_CUI:
subsystem = strdup("POSIX CUI");
break;
case TE_IMAGE_SUBSYSTEM_WINDOWS_CE_GUI:
subsystem = strdup("Windows CE GUI");
break;
case TE_IMAGE_SUBSYSTEM_EFI_APPLICATION:
subsystem = strdup("EFI Application");
break;
case TE_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
subsystem = strdup("EFI Boot Service Driver");
break;
case TE_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
subsystem = strdup("EFI Runtime Driver");
break;
case TE_IMAGE_SUBSYSTEM_EFI_ROM:
subsystem = strdup("EFI ROM");
break;
case TE_IMAGE_SUBSYSTEM_XBOX:
subsystem = strdup("XBOX");
break;
default:
subsystem = strdup("Unknown");
}
return subsystem;
}
struct r_bin_te_export_t* r_bin_te_get_exports(struct r_bin_te_obj_t* bin) {
return NULL;
}
struct r_bin_te_import_t* r_bin_pe_get_imports(struct r_bin_te_obj_t *bin) {
return NULL;
}
void* r_bin_te_free(struct r_bin_te_obj_t* bin) {
if (!bin) return NULL;
free (bin->header);
free (bin->section_header);
//free (bin->export_directory);
//free (bin->import_directory);
r_buf_free (bin->b);
free (bin);
return NULL;
}
struct r_bin_te_obj_t* r_bin_te_new(const char* file) {
ut8 *buf;
struct r_bin_te_obj_t *bin = R_NEW0 (struct r_bin_te_obj_t);
if (!bin) return NULL;
bin->file = file;
if (!(buf = (ut8*)r_file_slurp(file, &bin->size)))
return r_bin_te_free(bin);
bin->b = r_buf_new ();
if (!r_buf_set_bytes (bin->b, buf, bin->size))
return r_bin_te_free(bin);
free (buf);
if (!r_bin_te_init(bin))
return r_bin_te_free(bin);
return bin;
}
struct r_bin_te_obj_t* r_bin_pe_new_buf(struct r_buf_t *buf) {
struct r_bin_te_obj_t *bin = R_NEW0 (struct r_bin_te_obj_t);
if (!bin) return NULL;
bin->b = buf;
bin->size = buf->length;
if (!r_bin_te_init(bin))
return r_bin_te_free(bin);
return bin;
}

77
libr/bin/format/te/te.h Normal file
View File

@ -0,0 +1,77 @@
/* radare - LGPL - Copyright 2013 xvilka */
#include "r_types.h"
#ifndef _INCLUDE_R_BIN_TE_H_
#define _INCLUDE_R_BIN_TE_H_
#define R_BIN_TE_SCN_IS_SHAREABLE(x) x & TE_IMAGE_SCN_MEM_SHARED
#define R_BIN_TE_SCN_IS_EXECUTABLE(x) x & TE_IMAGE_SCN_MEM_EXECUTE
#define R_BIN_TE_SCN_IS_READABLE(x) x & TE_IMAGE_SCN_MEM_READ
#define R_BIN_TE_SCN_IS_WRITABLE(x) x & TE_IMAGE_SCN_MEM_WRITE
struct r_bin_te_addr_t {
ut64 rva;
ut64 offset;
};
struct r_bin_te_section_t {
ut8 name[TE_IMAGE_SIZEOF_NAME];
ut64 size;
ut64 vsize;
ut64 rva;
ut64 offset;
ut64 flags;
int last;
};
struct r_bin_te_import_t {
ut8 name[TE_NAME_LENGTH];
ut64 rva;
ut64 offset;
ut64 hint;
ut64 ordinal;
int last;
};
struct r_bin_te_export_t {
ut8 name[TE_NAME_LENGTH];
ut8 forwarder[TE_NAME_LENGTH];
ut64 rva;
ut64 offset;
ut64 ordinal;
int last;
};
struct r_bin_te_string_t {
char string[TE_STRING_LENGTH];
ut64 rva;
ut64 offset;
ut64 size;
char type;
int last;
};
#endif
struct r_bin_te_obj_t {
TE_image_file_header *header;
TE_image_section_header *section_header;
int size;
int endian;
const char* file;
struct r_buf_t* b;
};
char* r_bin_te_get_arch(struct r_bin_te_obj_t* bin);
struct r_bin_te_addr_t* r_bin_te_get_entrypoint(struct r_bin_te_obj_t* bin);
ut64 r_bin_te_get_main_offset(struct r_bin_te_obj_t *bin);
ut64 r_bin_te_get_image_base(struct r_bin_te_obj_t* bin);
int r_bin_te_get_image_size(struct r_bin_te_obj_t* bin);
char* r_bin_te_get_machine(struct r_bin_te_obj_t* bin);
char* r_bin_te_get_os(struct r_bin_te_obj_t* bin);
struct r_bin_te_section_t* r_bin_te_get_sections(struct r_bin_te_obj_t* bin);
char* r_bin_te_get_subsystem(struct r_bin_te_obj_t* bin);
void* r_bin_te_free(struct r_bin_te_obj_t* bin);
struct r_bin_te_obj_t* r_bin_te_new(const char* file);
struct r_bin_te_obj_t* r_bin_te_new_buf(struct r_buf_t *buf);

View File

@ -0,0 +1,101 @@
/* radare - LGPL - Copyright 2008 nibble, xvilka */
#undef TE_
#undef TE_Word
#undef TE_DWord
#undef TE_VWord
#define TE_Word ut16
#define TE_DWord ut64
#define TE_VWord ut32
#ifndef _INCLUDE_R_BIN_TE_SPECS_H_
#define _INCLUDE_R_BIN_TE_SPECS_H_
#define TE_NAME_LENGTH 256
#define TE_STRING_LENGTH 256
#define TE_IMAGE_FILE_MACHINE_UNKNOWN 0x0000
#define TE_IMAGE_FILE_MACHINE_ALPHA 0x0184
#define TE_IMAGE_FILE_MACHINE_ALPHA64 0x0284
#define TE_IMAGE_FILE_MACHINE_AM33 0x01d3
#define TE_IMAGE_FILE_MACHINE_AMD64 0x8664
#define TE_IMAGE_FILE_MACHINE_ARM 0x01c0
#define TE_IMAGE_FILE_MACHINE_AXP64 TE_IMAGE_FILE_MACHINE_ALPHA64
#define TE_IMAGE_FILE_MACHINE_CEE 0xc0ee
#define TE_IMAGE_FILE_MACHINE_CEF 0x0cef
#define TE_IMAGE_FILE_MACHINE_EBC 0x0ebc
#define TE_IMAGE_FILE_MACHINE_I386 0x014c
#define TE_IMAGE_FILE_MACHINE_IA64 0x0200
#define TE_IMAGE_FILE_MACHINE_M32R 0x9041
#define TE_IMAGE_FILE_MACHINE_M68K 0x0268
#define TE_IMAGE_FILE_MACHINE_MIPS16 0x0266
#define TE_IMAGE_FILE_MACHINE_MIPSFPU 0x0366
#define TE_IMAGE_FILE_MACHINE_MIPSFPU16 0x0466
#define TE_IMAGE_FILE_MACHINE_POWERPC 0x01f0
#define TE_IMAGE_FILE_MACHINE_POWERPCFP 0x01f1
#define TE_IMAGE_FILE_MACHINE_R10000 0x0168
#define TE_IMAGE_FILE_MACHINE_R3000 0x0162
#define TE_IMAGE_FILE_MACHINE_R4000 0x0166
#define TE_IMAGE_FILE_MACHINE_SH3 0x01a2
#define TE_IMAGE_FILE_MACHINE_SH3DSP 0x01a3
#define TE_IMAGE_FILE_MACHINE_SH3E 0x01a4
#define TE_IMAGE_FILE_MACHINE_SH4 0x01a6
#define TE_IMAGE_FILE_MACHINE_SH5 0x01a8
#define TE_IMAGE_FILE_MACHINE_THUMB 0x01c2
#define TE_IMAGE_FILE_MACHINE_TRICORE 0x0520
#define TE_IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169
#define TE_IMAGE_DIRECTORY_ENTRIES 2
#define TE_IMAGE_SUBSYSTEM_UNKNOWN 0
#define TE_IMAGE_SUBSYSTEM_NATIVE 1
#define TE_IMAGE_SUBSYSTEM_WINDOWS_GUI 2
#define TE_IMAGE_SUBSYSTEM_WINDOWS_CUI 3
#define TE_IMAGE_SUBSYSTEM_POSIX_CUI 7
#define TE_IMAGE_SUBSYSTEM_WINDOWS_CE_GUI 9
#define TE_IMAGE_SUBSYSTEM_EFI_APPLICATION 10
#define TE_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
#define TE_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12
#define TE_IMAGE_SUBSYSTEM_EFI_ROM 13
#define TE_IMAGE_SUBSYSTEM_XBOX 14
typedef struct {
ut32 VirtualAddress;
ut32 Size;
} efi_image_data_directory;
typedef struct {
ut16 Signature;
ut16 Machine;
ut8 NumberOfSections;
ut8 Subsystem;
ut16 StrippedSize;
ut32 AddressOfEntryPoint;
ut32 BaseOfCode;
ut64 ImageBase;
efi_image_data_directory DataDirectory[2];
} TE_image_file_header;
#define TE_IMAGE_SIZEOF_NAME 8
#define TE_IMAGE_SCN_MEM_SHARED 0x10000000
#define TE_IMAGE_SCN_MEM_EXECUTE 0x20000000
#define TE_IMAGE_SCN_MEM_READ 0x40000000
#define TE_IMAGE_SCN_MEM_WRITE 0x80000000
typedef struct {
ut8 Name[TE_IMAGE_SIZEOF_NAME];
ut32 VirtualSize;
ut32 VirtualAddress;
ut32 SizeOfRawData;
ut32 PointerToRawData;
ut32 PointerToRelocations;
ut32 PointerToLineNumbers;
ut16 NumberOfRelocations;
ut16 NumberOfLinenumbers;
ut32 Characteristics;
} TE_image_section_header;
#endif

View File

@ -6,7 +6,7 @@ LDFLAGS+=-L$(LTOP)/util -lr_util
foo: all
ALL_TARGETS=
FORMATS=any.mk elf.mk elf64.mk pe.mk pe64.mk mach0.mk mach064.mk fatmach0.mk dyldcache.mk java.mk dex.mk fs.mk
FORMATS=any.mk elf.mk elf64.mk pe.mk pe64.mk te.mk mach0.mk mach064.mk fatmach0.mk dyldcache.mk java.mk dex.mk fs.mk
include $(FORMATS)
all: ${ALL_TARGETS}

212
libr/bin/p/bin_te.c Normal file
View File

@ -0,0 +1,212 @@
/* radare - LGPL - Copyright 2009-2013 - nibble, pancake, xvilka */
#include <r_types.h>
#include <r_util.h>
#include <r_lib.h>
#include <r_bin.h>
#include "te/te_specs.h"
#include "te/te.h"
static int load(RBinArch *arch) {
if(!(arch->bin_obj = r_bin_te_new_buf (arch->buf)))
return R_FALSE;
return R_TRUE;
}
static int destroy(RBinArch *arch) {
r_bin_te_free ((struct r_bin_te_obj_t*)arch->bin_obj);
return R_TRUE;
}
static ut64 baddr(RBinArch *arch) {
return r_bin_te_get_image_base (arch->bin_obj);
}
static RBinAddr* binsym(RBinArch *arch, int type) {
RBinAddr *ret = NULL;
switch (type) {
case R_BIN_SYM_MAIN:
if (!(ret = R_NEW (RBinAddr)))
return NULL;
memset (ret, '\0', sizeof (RBinAddr));
ret->offset = ret->rva = r_bin_te_get_main_offset (arch->bin_obj);
break;
}
return ret;
}
static RList* entries(RBinArch *arch) {
RList* ret;
RBinAddr *ptr = NULL;
struct r_bin_te_addr_t *entry = NULL;
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(entry = r_bin_te_get_entrypoint (arch->bin_obj)))
return ret;
if ((ptr = R_NEW (RBinAddr))) {
ptr->offset = entry->offset;
ptr->rva = entry->rva;
r_list_append (ret, ptr);
}
free (entry);
return ret;
}
static RList* sections(RBinArch *arch) {
RList *ret = NULL;
RBinSection *ptr = NULL;
struct r_bin_te_section_t *sections = NULL;
int i;
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(sections = r_bin_te_get_sections(arch->bin_obj)))
return NULL;
for (i = 0; !sections[i].last; i++) {
if (!(ptr = R_NEW (RBinSection)))
break;
strncpy (ptr->name, (char*)sections[i].name, R_BIN_SIZEOF_STRINGS);
ptr->size = sections[i].size;
ptr->vsize = sections[i].vsize;
ptr->offset = sections[i].offset;
ptr->rva = sections[i].rva;
ptr->srwx = 0;
if (R_BIN_TE_SCN_IS_EXECUTABLE (sections[i].flags))
ptr->srwx |= 0x1;
if (R_BIN_TE_SCN_IS_WRITABLE (sections[i].flags))
ptr->srwx |= 0x2;
if (R_BIN_TE_SCN_IS_READABLE (sections[i].flags))
ptr->srwx |= 0x4;
if (R_BIN_TE_SCN_IS_SHAREABLE (sections[i].flags))
ptr->srwx |= 0x8;
r_list_append (ret, ptr);
}
free (sections);
return ret;
}
static RList* symbols(RBinArch *arch) {
RList *ret = NULL;
RBinSymbol *ptr = NULL;
struct r_bin_te_export_t *symbols = NULL;
int i;
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(symbols = r_bin_te_get_exports(arch->bin_obj)))
return ret;
for (i = 0; !symbols[i].last; i++) {
if (!(ptr = R_NEW (RBinSymbol)))
break;
strncpy (ptr->name, (char*)symbols[i].name, R_BIN_SIZEOF_STRINGS);
strncpy (ptr->forwarder, (char*)symbols[i].forwarder, R_BIN_SIZEOF_STRINGS);
strncpy (ptr->bind, "NONE", R_BIN_SIZEOF_STRINGS);
strncpy (ptr->type, "FUNC", R_BIN_SIZEOF_STRINGS); //XXX Get the right type
ptr->size = 0;
ptr->rva = symbols[i].rva;
ptr->offset = symbols[i].offset;
ptr->ordinal = symbols[i].ordinal;
r_list_append (ret, ptr);
}
free (symbols);
return ret;
}
static RList* imports(RBinArch *arch) {
RList *ret = NULL;
RBinImport *ptr = NULL;
struct r_bin_te_import_t *imports = NULL;
int i;
if (!(ret = r_list_new ()))
return NULL;
ret->free = free;
if (!(imports = r_bin_te_get_imports(arch->bin_obj)))
return ret;
for (i = 0; !imports[i].last; i++) {
if (!(ptr = R_NEW (RBinImport)))
break;
strncpy (ptr->name, (char*)imports[i].name, R_BIN_SIZEOF_STRINGS);
strncpy (ptr->bind, "NONE", R_BIN_SIZEOF_STRINGS);
strncpy (ptr->type, "FUNC", R_BIN_SIZEOF_STRINGS);
ptr->rva = imports[i].rva;
ptr->offset = imports[i].offset;
ptr->size = 0;
ptr->ordinal = imports[i].ordinal;
ptr->hint = imports[i].hint;
r_list_append (ret, ptr);
}
free (imports);
return ret;
}
static RBinInfo* info(RBinArch *arch) {
char *str;
RBinInfo *ret = R_NEW0 (RBinInfo);
if (!ret) return NULL;
strncpy (ret->file, arch->file, R_BIN_SIZEOF_STRINGS);
strncpy (ret->rpath, "NONE", R_BIN_SIZEOF_STRINGS);
if ((str = r_bin_te_get_class (arch->bin_obj))) {
strncpy (ret->bclass, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
strncpy (ret->rclass, "te", R_BIN_SIZEOF_STRINGS);
if ((str = r_bin_te_get_os (arch->bin_obj))) {
strncpy (ret->os, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = r_bin_te_get_arch (arch->bin_obj))) {
strncpy (ret->arch, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = r_bin_te_get_machine (arch->bin_obj))) {
strncpy (ret->machine, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
if ((str = r_bin_te_get_subsystem (arch->bin_obj))) {
strncpy (ret->subsystem, str, R_BIN_SIZEOF_STRINGS);
free (str);
}
strncpy (ret->type, "EXEC (Executable file)", R_BIN_SIZEOF_STRINGS);
ret->bits = 0;
ret->big_endian = 1;
ret->dbg_info = 0;
ret->has_va = R_TRUE;
return ret;
}
struct r_bin_plugin_t r_bin_plugin_te = {
.name = "te",
.desc = "TE bin plugin",
.init = NULL,
.fini = NULL,
.load = &load,
.destroy = &destroy,
.check = NULL,
.baddr = &baddr,
.binsym = &binsym,
.entries = &entries,
.sections = &sections,
.symbols = &symbols,
.imports = &imports,
.strings = NULL,
.info = &info,
.fields = NULL,
.libs = NULL,
.relocs = NULL,
.meta = NULL,
.write = NULL,
.minstrlen = 4,
.create = NULL,
};
#ifndef CORELIB
struct r_lib_struct_t radare_plugin = {
.type = R_LIB_TYPE_BIN,
.data = &r_bin_plugin_te
};
#endif

9
libr/bin/p/te.mk Normal file
View File

@ -0,0 +1,9 @@
OBJ_TE=bin_te.o ../format/te/te.o
STATIC_OBJ+=${OBJ_TE}
TARGET_TE=bin_te.${EXT_SO}
ALL_TARGETS+=${TARGET_TE}
${TARGET_TE}: ${OBJ_TE}
${CC} $(call libname,bin_te) ${CFLAGS} $(LDFLAGS) ${OBJ_TE}