1 /* radare - LGPL - Copyright 2009-2019 - pancake, nibble */
2 
3 #include <r_types.h>
4 #include <r_util.h>
5 #include <r_lib.h>
6 #include <r_bin.h>
7 #include <r_magic.h>
8 
get_filetype(RBuffer * b)9 static char *get_filetype(RBuffer *b) {
10 	ut8 buf[4096] = { 0 };
11 	char *res = NULL;
12 	RMagic *ck = r_magic_new (0);
13 	if (!ck) {
14 		return NULL;
15 	}
16 	const char *tmp = NULL;
17 	// TODO: dir.magic not honored here
18 	r_magic_load (ck, R2_SDB_MAGIC);
19 	r_buf_read_at (b, 0, buf, sizeof (buf));
20 	tmp = r_magic_buffer (ck, buf, sizeof (buf));
21 	if (tmp) {
22 		res = strdup (tmp);
23 	}
24 	r_magic_free (ck);
25 	return res;
26 }
27 
info(RBinFile * bf)28 static RBinInfo *info(RBinFile *bf) {
29 	RBinInfo *ret = R_NEW0 (RBinInfo);
30 	if (!ret) {
31 		return NULL;
32 	}
33 	ret->lang = "";
34 	ret->file = bf->file? strdup (bf->file): NULL;
35 	ret->type = get_filetype (bf->buf);
36 	ret->has_pi = 0;
37 	ret->has_canary = 0;
38 	ret->has_retguard = -1;
39 	ret->big_endian = 0;
40 	ret->has_va = 0;
41 	ret->has_nx = 0;
42 	ret->dbg_info = 0;
43 	ret->dbg_info = 0;
44 	ret->dbg_info = 0;
45 	return ret;
46 }
47 
load_buffer(RBinFile * bf,void ** bin_obj,RBuffer * buf,ut64 loadaddr,Sdb * sdb)48 static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) {
49 	return true;
50 }
51 
destroy(RBinFile * bf)52 static void destroy(RBinFile *bf) {
53 	r_buf_free (bf->o->bin_obj);
54 }
55 
baddr(RBinFile * bf)56 static ut64 baddr(RBinFile *bf) {
57 	return 0LL;
58 }
59 
60 RBinPlugin r_bin_plugin_any = {
61 	.name = "any",
62 	.desc = "Dummy format r_bin plugin",
63 	.license = "LGPL3",
64 	.load_buffer = &load_buffer,
65 	.destroy = &destroy,
66 	.baddr = &baddr,
67 	.info = info,
68 	.minstrlen = 0,
69 };
70 
71 #ifndef R2_PLUGIN_INCORE
72 R_API RLibStruct radare_plugin = {
73 	.type = R_LIB_TYPE_BIN,
74 	.data = &r_bin_plugin_any,
75 	.version = R2_VERSION
76 };
77 #endif
78