-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbin_ggpack.c
99 lines (81 loc) · 1.9 KB
/
bin_ggpack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* MIT - Copyright 2017 - mrmacete */
#include <r_core.h>
#include <r_bin.h>
#include <r_lib.h>
#include <r_io.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "r_ggpack.h"
static bool __check_bytes(const ut8 *b, ut64 length) {
ut32 index_offset = r_read_le32 (b);
if (index_offset >= length) {
return false;
}
ut32 index_magic = r_read_be32 (b + index_offset);
if (index_magic != 0x01020304) {
return false;
}
ut32 plo = r_read_le32 (b + index_offset + 8);
if (b[index_offset + plo] != 7) {
return false;
}
return true;
}
static void *__load_bytes(RBinFile *arch, const ut8 *buf, ut64 sz, ut64 loadaddr, Sdb *sdb){
return R_NOTNULL;
}
static RBinInfo *__info(RBinFile *arch) {
RBinInfo *ret = R_NEW0 (RBinInfo);
if (!ret || !arch || !arch->buf) {
free (ret);
return NULL;
}
ret->file = strdup (arch->file);
ret->type = strdup ("ggpack");
ret->has_va = 0;
return ret;
}
static RList *__symbols(RBinFile *arch) {
RList *result = r_list_newf ((RListFree)free);
if (!result) {
return NULL;
}
int i;
RIO * io = arch->rbin->iob.io;
RIOGGPack *rg = io->desc->data;
for (i = 0; i < rg->index->length; i++) {
RGGPackIndexEntry * entry = rg->index->entries[i];
RBinSymbol *sym = R_NEW0 (RBinSymbol);
if (!sym) {
r_list_free (result);
return NULL;
}
sym->name = strdup (entry->file_name);
sym->paddr = sym->vaddr = entry->offset;
sym->size = entry->size;
sym->ordinal = 0;
r_list_append (result, sym);
}
return result;
}
static RList *__strings(RBinFile *arch) {
return NULL;
}
RBinPlugin r_bin_plugin_ggpack = {
.name = "ggpack",
.desc = "ggpack bin goodies",
.license = "MIT",
.load_bytes = &__load_bytes,
.symbols = &__symbols,
.strings = &__strings,
.check_bytes = &__check_bytes,
.info = &__info,
};
#ifndef CORELIB
RLibStruct radare_plugin = {
.type = R_LIB_TYPE_BIN,
.data = &r_bin_plugin_ggpack,
.version = R2_VERSION
};
#endif