Remove GRUB and librz_fs plugins (#9)
This commit is contained in:
parent
45ca181de2
commit
881058693d
234 changed files with 89 additions and 34239 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
|
@ -55,9 +55,9 @@ build_sdb
|
|||
config-user.mk
|
||||
librz/bin/d/dll/dll
|
||||
librz/config.h
|
||||
librz/include/r_userconf.h
|
||||
librz/include/r_version.h
|
||||
librz/include/r_version.h.tmp
|
||||
librz/include/rz_userconf.h
|
||||
librz/include/rz_version.h
|
||||
librz/include/rz_version.h.tmp
|
||||
shlr/capstone/
|
||||
shlr/java/out
|
||||
shlr/java/out.exe
|
||||
|
|
|
|||
1
Makefile
1
Makefile
|
|
@ -437,7 +437,6 @@ meson-symstall: symstall-sdb
|
|||
ln -fs $(PWD)/build/librz/asm/librz_asm.$(EXT_SO) ${L}/librz_asm.$(EXT_SO)
|
||||
ln -fs $(PWD)/build/librz/anal/librz_anal.$(EXT_SO) ${L}/librz_anal.$(EXT_SO)
|
||||
ln -fs $(PWD)/build/librz/egg/librz_egg.$(EXT_SO) ${L}/librz_egg.$(EXT_SO)
|
||||
ln -fs $(PWD)/build/librz/fs/librz_fs.$(EXT_SO) ${L}/librz_fs.$(EXT_SO)
|
||||
ln -fs $(PWD)/build/librz/debug/librz_debug.$(EXT_SO) ${L}/librz_debug.$(EXT_SO)
|
||||
ln -fs $(PWD)/build/librz/core/librz_core.$(EXT_SO) ${L}/librz_core.$(EXT_SO)
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ LDFLAGS+=-L../../librz/anal -lrz_anal
|
|||
LDFLAGS+=-L../../librz/crypto -lrz_crypto
|
||||
LDFLAGS+=-L../../librz/flag -lrz_flag
|
||||
LDFLAGS+=-L../../librz/parse -lrz_parse
|
||||
LDFLAGS+=-L../../librz/fs -lrz_fs
|
||||
LDFLAGS+=-L../../librz/magic -lrz_magic
|
||||
LDFLAGS+=-L../../librz/syscall -lrz_syscall
|
||||
LDFLAGS+=-L../../librz/util -lrz_util
|
||||
|
|
@ -60,7 +59,6 @@ include ../../shlr/zip/deps.mk
|
|||
include ../../shlr/gdb/deps.mk
|
||||
include ../../shlr/java/deps.mk
|
||||
include ../../shlr/bochs/deps.mk
|
||||
include ../../shlr/grub/deps.mk
|
||||
include ../../shlr/qnx/deps.mk
|
||||
include ../../shlr/ar/deps.mk
|
||||
include ../../shlr/sdb.mk
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ ISLIB=1
|
|||
BINDEPS=rz_core rz_parse rz_search rz_cons rz_config
|
||||
BINDEPS+=rz_bin rz_debug rz_anal rz_reg rz_bp rz_io
|
||||
BINDEPS+=rz_lang rz_asm rz_syscall rz_hash rz_crypto
|
||||
BINDEPS+=rz_magic rz_socket rz_flag rz_util rz_egg rz_fs
|
||||
BINDEPS+=rz_magic rz_socket rz_flag rz_util rz_egg
|
||||
|
||||
include ../rules.mk
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
BIN=rizin
|
||||
BINDEPS=rz_core rz_parse rz_search rz_cons rz_config
|
||||
BINDEPS+=rz_bin rz_debug rz_anal rz_reg rz_bp rz_io rz_fs
|
||||
BINDEPS+=rz_bin rz_debug rz_anal rz_reg rz_bp rz_io
|
||||
BINDEPS+=rz_lang rz_asm rz_syscall rz_hash rz_main
|
||||
BINDEPS+=rz_magic rz_socket rz_flag rz_egg rz_crypto rz_util
|
||||
|
||||
|
|
@ -93,7 +93,6 @@ include ../../shlr/zip/deps.mk
|
|||
include ../../shlr/gdb/deps.mk
|
||||
include ../../shlr/java/deps.mk
|
||||
include ../../shlr/bochs/deps.mk
|
||||
include ../../shlr/grub/deps.mk
|
||||
include ../../shlr/qnx/deps.mk
|
||||
include ../../shlr/ar/deps.mk
|
||||
include ../../shlr/yxml/deps.mk
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ executable('rizin', 'rizin.c',
|
|||
rz_socket_dep,
|
||||
rz_core_dep,
|
||||
rz_io_dep,
|
||||
rz_fs_dep,
|
||||
rz_bin_dep,
|
||||
rz_flag_dep,
|
||||
rz_cons_dep,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ BIN=rz-bin
|
|||
BINDEPS=rz_magic rz_core rz_bin rz_egg rz_cons rz_main
|
||||
BINDEPS+=rz_config rz_io rz_flag rz_asm
|
||||
BINDEPS+=rz_debug rz_hash rz_lang rz_anal rz_parse rz_bp rz_reg
|
||||
BINDEPS+=rz_search rz_syscall rz_socket rz_fs rz_magic rz_crypto rz_util
|
||||
BINDEPS+=rz_search rz_syscall rz_socket rz_magic rz_crypto rz_util
|
||||
|
||||
include ../rules.mk
|
||||
|
||||
|
|
@ -11,7 +11,6 @@ include ../../librz/main/deps.mk
|
|||
include ../../shlr/zip/deps.mk
|
||||
include ../../shlr/gdb/deps.mk
|
||||
include ../../shlr/java/deps.mk
|
||||
include ../../shlr/grub/deps.mk
|
||||
include ../../shlr/bochs/deps.mk
|
||||
include ../../shlr/qnx/deps.mk
|
||||
include ../../shlr/ar/deps.mk
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
BIN=rz-diff
|
||||
|
||||
BINDEPS=rz_core rz_config rz_cons rz_search rz_anal
|
||||
BINDEPS+=rz_bin rz_debug rz_io rz_asm rz_hash rz_fs rz_crypto
|
||||
BINDEPS+=rz_bin rz_debug rz_io rz_asm rz_hash rz_crypto
|
||||
BINDEPS+=rz_socket rz_flag rz_lang rz_reg rz_bp rz_parse
|
||||
BINDEPS+=rz_syscall rz_magic rz_util rz_parse rz_egg rz_main
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
BIN=rz-gg
|
||||
BINDEPS=rz_egg rz_syscall rz_asm
|
||||
BINDEPS+=rz_core rz_hash rz_debug rz_fs rz_config rz_bp rz_crypto rz_cons
|
||||
BINDEPS+=rz_core rz_hash rz_debug rz_config rz_bp rz_crypto rz_cons
|
||||
BINDEPS+=rz_lang rz_parse rz_anal rz_reg rz_flag rz_crypto
|
||||
BINDEPS+=rz_bin rz_search rz_io rz_socket
|
||||
BINDEPS+=rz_magic rz_util rz_main
|
||||
|
|
@ -11,7 +11,6 @@ include ../../shlr/ar/deps.mk
|
|||
include ../../librz/socket/deps.mk
|
||||
include ../../shlr/bochs/deps.mk
|
||||
include ../../shlr/gdb/deps.mk
|
||||
include ../../shlr/grub/deps.mk
|
||||
include ../../shlr/java/deps.mk
|
||||
include ../../shlr/capstone.mk
|
||||
include ../../shlr/qnx/deps.mk
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ executable('rz-gg', 'rz-gg.c',
|
|||
rz_core_dep,
|
||||
rz_hash_dep,
|
||||
rz_debug_dep,
|
||||
rz_fs_dep,
|
||||
rz_config_dep,
|
||||
rz_bp_dep,
|
||||
rz_crypto_dep
|
||||
|
|
|
|||
4
configure
vendored
4
configure
vendored
|
|
@ -181,7 +181,7 @@ printf "\nOptional Features:
|
|||
--with-syscapstone force to use system-wide capstone
|
||||
--with-syszip force to use system's libzip and zlib
|
||||
--with-sysxxhash force to use system's xxhash
|
||||
--without-gpl do not build GPL code (grub, cxx, ... )
|
||||
--without-gpl do not build GPL code (cxx, ... )
|
||||
--with-openssl build with openssl if possible
|
||||
--without-libuv disable libuv dependency
|
||||
--with-rpath use rpath to build
|
||||
|
|
@ -704,7 +704,7 @@ for A in ${ENVWORDS} ; do
|
|||
SEDFLAGS="${SEDFLAGS}s,@${A}@,${VAR},g;"
|
||||
done
|
||||
SEDFLAGS="${SEDFLAGS}'"
|
||||
for A in ./config-user.mk librz/include/rz_userconf.h pkgcfg/rz_io.pc pkgcfg/rz_magic.pc pkgcfg/rz_asm.pc pkgcfg/rz_bin.pc pkgcfg/rz_anal.pc pkgcfg/rz_hash.pc pkgcfg/rz_cons.pc pkgcfg/rz_core.pc pkgcfg/rz_lang.pc pkgcfg/rz_socket.pc pkgcfg/rz_debug.pc pkgcfg/rz_reg.pc pkgcfg/rz_config.pc pkgcfg/rz_flag.pc pkgcfg/rz_syscall.pc pkgcfg/rz_util.pc pkgcfg/rz_search.pc pkgcfg/rz_bp.pc pkgcfg/rz_parse.pc pkgcfg/rz_fs.pc pkgcfg/rz_egg.pc pkgcfg/rz_crypto.pc ; do # SUBDIRS
|
||||
for A in ./config-user.mk librz/include/rz_userconf.h pkgcfg/rz_io.pc pkgcfg/rz_magic.pc pkgcfg/rz_asm.pc pkgcfg/rz_bin.pc pkgcfg/rz_anal.pc pkgcfg/rz_hash.pc pkgcfg/rz_cons.pc pkgcfg/rz_core.pc pkgcfg/rz_lang.pc pkgcfg/rz_socket.pc pkgcfg/rz_debug.pc pkgcfg/rz_reg.pc pkgcfg/rz_config.pc pkgcfg/rz_flag.pc pkgcfg/rz_syscall.pc pkgcfg/rz_util.pc pkgcfg/rz_search.pc pkgcfg/rz_bp.pc pkgcfg/rz_parse.pc pkgcfg/rz_egg.pc pkgcfg/rz_crypto.pc ; do # SUBDIRS
|
||||
if [ -f "${VPATH}/${A}.acr" ]; then
|
||||
SD_TARGET=${A}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ IFAND HAVE_LIB_XXHASH USE_XXHASH {
|
|||
LIBXXHASH = '' ;
|
||||
}
|
||||
|
||||
ARG_WITHOUT WITH_GPL gpl do not build GPL code (grub, cxx, ... ) ;
|
||||
ARG_WITHOUT WITH_GPL gpl do not build GPL code (cxx, ... ) ;
|
||||
|
||||
CHKDECL sys/personality.h ADDR_NO_RANDOMIZE
|
||||
CHKDECL features.h __GLIBC__
|
||||
|
|
@ -268,7 +268,6 @@ SUBDIRS ./config-user.mk
|
|||
pkgcfg/rz_search.pc
|
||||
pkgcfg/rz_bp.pc
|
||||
pkgcfg/rz_parse.pc
|
||||
pkgcfg/rz_fs.pc
|
||||
pkgcfg/rz_egg.pc
|
||||
pkgcfg/rz_crypto.pc
|
||||
;
|
||||
|
|
|
|||
|
|
@ -30,6 +30,6 @@ emcc -O2 rz_ax.o ../../librz/util/librz_util.a -o rz_ax.js
|
|||
|
||||
binrz/rz_asm/rz_asm.js:
|
||||
|
||||
emcc -O2 -L.. -o rz_asm.js ../../shlr/sdb/src/libsdb.a ../../librz/fs/p/grub/libgrubfs.a -lm $A/util/librz_util.a $A/asm/librz_asm.a rz_asm.o ../../librz/util/librz_util.a ../../librz/parse/librz_parse.a ../../librz/db/libr_db.a ../../librz/syscall/librz_syscall.a ../../librz/asm/librz_asm.a ../../librz/lib/libr_lib.a ../../librz/db/libr_db.a ../../shlr/sdb/src/libsdb.a ../../librz/util/librz_util.a
|
||||
emcc -O2 -L.. -o rz_asm.js ../../shlr/sdb/src/libsdb.a -lm $A/util/librz_util.a $A/asm/librz_asm.a rz_asm.o ../../librz/util/librz_util.a ../../librz/parse/librz_parse.a ../../librz/db/libr_db.a ../../librz/syscall/librz_syscall.a ../../librz/asm/librz_asm.a ../../librz/lib/libr_lib.a ../../librz/db/libr_db.a ../../shlr/sdb/src/libsdb.a ../../librz/util/librz_util.a
|
||||
|
||||
-->
|
||||
|
|
|
|||
|
|
@ -108,9 +108,6 @@ _libr.${EXT_AR}: .librz
|
|||
librz.${EXT_AR}: .librz
|
||||
-${AR} -rs $@ .librz/*/*.o
|
||||
|
||||
ifeq (1,$(WITH_GPL))
|
||||
E+=../shlr/grub/libgrubfs.${EXT_AR}
|
||||
endif
|
||||
E+=../shlr/yxml/libyxml.${EXT_AR}
|
||||
E+=../shlr/ar/librz_ar.${EXT_AR}
|
||||
E+=../shlr/winkd/librz_winkd.${EXT_AR}
|
||||
|
|
@ -235,7 +232,7 @@ install: install-includes install-pkgconfig
|
|||
${INSTALL_LIB} "$$lib" "${DESTDIR}${LIBDIR}/$$lib"; \
|
||||
fi
|
||||
# object archives
|
||||
@for FILE in `find * -type f -iname "*.${EXT_AR}" | grep -v fs/p` ; do \
|
||||
@for FILE in `find * -type f -iname "*.${EXT_AR}"` ; do \
|
||||
echo " ${DESTDIR}${LIBDIR}/$$FILE"; ${INSTALL_DATA} $$FILE "${DESTDIR}${LIBDIR}" ; done || true
|
||||
# plugins
|
||||
@${INSTALL_DIR} "${DESTDIR}${LIBDIR}/rizin/${VERSION}"
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ rz_bin_sources = [
|
|||
'p/bin_dyldcache.c',
|
||||
'p/bin_elf.c',
|
||||
'p/bin_elf64.c',
|
||||
'p/bin_fs.c',
|
||||
'p/bin_java.c',
|
||||
'p/bin_ldr_linux.c',
|
||||
'p/bin_le.c',
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ all: ${ALL_TARGETS}
|
|||
ALL_TARGETS=
|
||||
FORMATS=any.mk elf.mk elf64.mk pe.mk pe64.mk te.mk mach0.mk
|
||||
FORMATS+=bios.mk mach064.mk dyldcache.mk xnu_kernelcache.mk java.mk
|
||||
FORMATS+=dex.mk fs.mk ningb.mk coff.mk ningba.mk xbe.mk zimg.mk
|
||||
FORMATS+=dex.mk ningb.mk coff.mk ningba.mk xbe.mk zimg.mk
|
||||
FORMATS+=omf.mk cgc.mk dol.mk nes.mk mbn.mk psxexe.mk spc700.mk
|
||||
FORMATS+=vsf.mk nin3ds.mk bflt.mk wasm.mk sfc.mk
|
||||
FORMATS+=mdmp.mk z64.mk qnx.mk prg.mk dmp64.mk
|
||||
|
|
|
|||
|
|
@ -1,110 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011-2019 - pancake */
|
||||
|
||||
#include <rz_types.h>
|
||||
#include <rz_util.h>
|
||||
#include <rz_lib.h>
|
||||
#include <rz_bin.h>
|
||||
#include "../../fs/types.h"
|
||||
|
||||
static char *fsname(RBuffer *b) {
|
||||
ut8 buf[1024];
|
||||
int i, j;
|
||||
|
||||
for (i = 0; fstypes[i].name; i++) {
|
||||
RzFSType *f = &fstypes[i];
|
||||
|
||||
if (rz_buf_read_at (b, f->bufoff, buf, sizeof (buf)) != sizeof (buf)) {
|
||||
break;
|
||||
}
|
||||
if (f->buflen > 0) {
|
||||
size_t min = R_MIN (f->buflen, sizeof (buf));
|
||||
if (!memcmp (buf, f->buf, min)) {
|
||||
bool ret = true;
|
||||
min = R_MIN (f->bytelen, sizeof (buf));
|
||||
if (rz_buf_read_at (b, f->byteoff, buf, min) != min) {
|
||||
break;
|
||||
}
|
||||
for (j = 0; j < min; j++) {
|
||||
if (buf[j] != f->byte) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret) {
|
||||
return strdup (f->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool check_buffer(RBuffer *b) {
|
||||
rz_return_val_if_fail (b, false);
|
||||
char *p = fsname (b);
|
||||
bool hasFs = p != NULL;
|
||||
free (p);
|
||||
return hasFs;
|
||||
}
|
||||
|
||||
static bool load_buffer(RBinFile *bf, void **bin_obj, RBuffer *buf, ut64 loadaddr, Sdb *sdb) {
|
||||
return check_buffer (buf);
|
||||
}
|
||||
|
||||
static void destroy(RBinFile *bf) {
|
||||
//rz_bin_fs_free ((struct rz_bin_fs_obj_t*)bf->o->bin_obj);
|
||||
}
|
||||
|
||||
static ut64 baddr(RBinFile *bf) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* accelerate binary load */
|
||||
static RzList *strings(RBinFile *bf) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static RBinInfo* info(RBinFile *bf) {
|
||||
RBinInfo *ret = NULL;
|
||||
if (!bf) {
|
||||
return NULL;
|
||||
}
|
||||
if (!(ret = R_NEW0 (RBinInfo))) {
|
||||
return NULL;
|
||||
}
|
||||
ret->file = bf->file? strdup (bf->file): NULL;
|
||||
ret->type = strdup ("fs");
|
||||
ret->bclass = fsname (bf->buf);
|
||||
ret->rclass = strdup ("fs");
|
||||
ret->os = strdup ("any");
|
||||
ret->subsystem = strdup ("unknown");
|
||||
ret->machine = strdup ("any");
|
||||
// ret->arch = strdup ("any");
|
||||
ret->has_va = 0;
|
||||
ret->bits = 32;
|
||||
ret->big_endian = 0;
|
||||
ret->dbg_info = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
RBinPlugin rz_bin_plugin_fs = {
|
||||
.name = "fs",
|
||||
.desc = "filesystem bin plugin",
|
||||
.author = "pancake",
|
||||
.version = "1.0",
|
||||
.license = "LGPL3",
|
||||
.load_buffer = &load_buffer,
|
||||
.destroy = &destroy,
|
||||
.check_buffer = &check_buffer,
|
||||
.baddr = &baddr,
|
||||
.strings = &strings,
|
||||
.info = &info,
|
||||
};
|
||||
|
||||
#ifndef R2_PLUGIN_INCORE
|
||||
RZ_API RzLibStruct radare_plugin = {
|
||||
.type = R_LIB_TYPE_BIN,
|
||||
.data = &rz_bin_plugin_fs,
|
||||
.version = R2_VERSION
|
||||
};
|
||||
#endif
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
OBJ_FS=bin_fs.o
|
||||
|
||||
STATIC_OBJ+=${OBJ_FS}
|
||||
TARGET_FS=bin_fs.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_FS}
|
||||
|
||||
${TARGET_FS}: ${OBJ_FS}
|
||||
${CC} $(call libname,bin_fs) -shared ${CFLAGS} \
|
||||
-o ${TARGET_FS} ${OBJ_FS} $(LINK) $(LDFLAGS)
|
||||
|
|
@ -4,7 +4,7 @@ NAME=rz_core
|
|||
|
||||
R2DEPS=rz_config rz_cons rz_io rz_util rz_flag rz_asm
|
||||
R2DEPS+=rz_debug rz_hash rz_bin rz_lang rz_io rz_anal rz_parse rz_bp rz_egg
|
||||
R2DEPS+=rz_reg rz_search rz_syscall rz_socket rz_fs rz_magic rz_crypto
|
||||
R2DEPS+=rz_reg rz_search rz_syscall rz_socket rz_magic rz_crypto
|
||||
|
||||
OBJS=core.o cmd.o cmd_helps.o cfile.o cconfig.o visual.o cio.o yank.o libs.o agraph.o
|
||||
OBJS+=fortune.o hack.o vasm.o patch.o cbin.o corelog.o rtr.o cmd_api.o
|
||||
|
|
@ -44,7 +44,7 @@ include $(TOP)/shlr/rizin-shell-parser-deps.mk
|
|||
include $(LTOP)/rules.mk
|
||||
|
||||
cmd.o: cmd_hash.c cmd_debug.c cmd_zign.c cmd_project.c \
|
||||
cmd_open.c cmd_meta.c cmd_macro.c cmd_magic.c cmd_mount.c cmd_eval.c \
|
||||
cmd_open.c cmd_meta.c cmd_macro.c cmd_magic.c cmd_eval.c \
|
||||
cmd_seek.c cmd_print.c cmd_help.c cmd_anal.c cmd_search.c cmd_log.c \
|
||||
cmd_cmp.c cmd_write.c cmd_egg.c cmd_info.c cmd_type.c cmd_flag.c \
|
||||
cmd_search_rop.c
|
||||
|
|
|
|||
|
|
@ -1859,27 +1859,6 @@ static bool cb_cmd_esil_trap(void *user, void *data) {
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool cb_fsview(void *user, void *data) {
|
||||
int type = R_FS_VIEW_NORMAL;
|
||||
RzCore *core = (RzCore *) user;
|
||||
RConfigNode *node = (RConfigNode *) data;
|
||||
if (*node->value == '?') {
|
||||
print_node_options (node);
|
||||
return false;
|
||||
}
|
||||
if (!strcmp (node->value, "all")) {
|
||||
type = R_FS_VIEW_ALL;
|
||||
}
|
||||
if (!strstr (node->value, "del")) {
|
||||
type |= R_FS_VIEW_DELETED;
|
||||
}
|
||||
if (!strstr (node->value, "spe")) {
|
||||
type |= R_FS_VIEW_SPECIAL;
|
||||
}
|
||||
rz_fs_view (core->fs, type);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool cb_cmddepth(void *user, void *data) {
|
||||
RzCore *core = (RzCore *)user;
|
||||
int c = R_MAX (((RConfigNode*)data)->i_value, 0);
|
||||
|
|
@ -3413,11 +3392,6 @@ RZ_API int rz_core_config_init(RzCore *core) {
|
|||
SETCB ("cmd.esil.todo", "", &cb_cmd_esil_todo, "Command to run when the esil instruction contains TODO");
|
||||
SETCB ("cmd.esil.ioer", "", &cb_cmd_esil_ioer, "Command to run when esil fails to IO (invalid read/write)");
|
||||
|
||||
/* filesystem */
|
||||
n = NODECB ("fs.view", "normal", &cb_fsview);
|
||||
SETDESC (n, "Set visibility options for filesystems");
|
||||
SETOPTIONS (n, "all", "deleted", "special", NULL);
|
||||
|
||||
/* hexdump */
|
||||
SETCB ("hex.header", "true", &cb_hex_header, "Show header in hexdump");
|
||||
SETCB ("hex.bytes", "true", &cb_hex_bytes, "Show bytes column in hexdump");
|
||||
|
|
|
|||
|
|
@ -116,7 +116,6 @@ static void cmd_debug_reg(RzCore *core, const char *str);
|
|||
#include "cmd_info.c"
|
||||
#include "cmd_macro.c"
|
||||
#include "cmd_magic.c"
|
||||
#include "cmd_mount.c"
|
||||
#include "cmd_seek.c"
|
||||
#include "cmd_search.c" // defines incDigitBuffer... used by cmd_print
|
||||
#include "cmd_print.c"
|
||||
|
|
@ -478,14 +477,10 @@ static int cmd_uniq(void *data, const char *input) { // "uniq"
|
|||
if (!arg) {
|
||||
arg = "";
|
||||
}
|
||||
if (rz_fs_check (core->fs, arg)) {
|
||||
rz_core_cmdf (core, "md %s", arg);
|
||||
} else {
|
||||
char *res = rz_syscmd_uniq (arg);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
char *res = rz_syscmd_uniq (arg);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -516,14 +511,10 @@ static int cmd_head (void *data, const char *_input) { // "head"
|
|||
if (!arg) {
|
||||
arg = "";
|
||||
}
|
||||
if (rz_fs_check (core->fs, arg)) {
|
||||
rz_core_cmdf (core, "md %s", arg);
|
||||
} else {
|
||||
char *res = rz_syscmd_head (arg, lines);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
char *res = rz_syscmd_head (arg, lines);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -1175,6 +1166,26 @@ RZ_API bool rz_core_run_script(RzCore *core, const char *file) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int cmd_m(void *data, const char *input) {
|
||||
switch (*input) {
|
||||
case '?': // "m?"
|
||||
eprintf ("Usage: m[kv] # mkdir to create directory, mv to move a file\n");
|
||||
break;
|
||||
case 'k': { // "mkdir"
|
||||
char *res = rz_syscmd_mkdir (input);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'v': // "mv"
|
||||
return rz_syscmd_mv (input) ? 1: 0;
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_ls(void *data, const char *input) { // "ls"
|
||||
RzCore *core = (RzCore *)data;
|
||||
const char *arg = strchr (input, ' ');
|
||||
|
|
@ -1196,14 +1207,10 @@ static int cmd_ls(void *data, const char *input) { // "ls"
|
|||
if (!arg) {
|
||||
arg = "";
|
||||
}
|
||||
if (rz_fs_check (core->fs, arg)) {
|
||||
rz_core_cmdf (core, "md %s", arg);
|
||||
} else {
|
||||
char *res = rz_syscmd_ls (arg);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
char *res = rz_syscmd_ls (arg);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -1241,12 +1248,10 @@ static int cmd_join(void *data, const char *input) { // "join"
|
|||
if (!arg2) {
|
||||
arg2 = "";
|
||||
}
|
||||
if (!rz_fs_check (core->fs, arg1) && !rz_fs_check (core->fs, arg2)) {
|
||||
char *res = rz_syscmd_join (arg1, arg2);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
char *res = rz_syscmd_join (arg1, arg2);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -2091,7 +2096,6 @@ static struct autocomplete_flag_map_t {
|
|||
{ "$file", "hints file paths", R_CORE_AUTOCMPLT_FILE },
|
||||
{ "$thme", "shows known themes hints", R_CORE_AUTOCMPLT_THME },
|
||||
{ "$optn", "allows the selection for multiple options", R_CORE_AUTOCMPLT_OPTN },
|
||||
{ "$ms", "shows mount hints", R_CORE_AUTOCMPLT_MS},
|
||||
{ "$sdb", "shows sdb hints", R_CORE_AUTOCMPLT_SDB},
|
||||
{ NULL, NULL, 0 }
|
||||
};
|
||||
|
|
@ -7135,9 +7139,9 @@ RZ_API void rz_core_cmd_init(RzCore *core) {
|
|||
{"k", "perform sdb query", cmd_kuery, NULL, &k_help},
|
||||
{"l", "list files and directories", cmd_ls, NULL, &l_help},
|
||||
{"j", "join the contents of the two files", cmd_join, NULL, &j_help},
|
||||
{"m", "make directory and move files", cmd_m, NULL, &m_help},
|
||||
{"h", "show the top n number of line in file", cmd_head, NULL, &h_help},
|
||||
{"L", "manage dynamically loaded plugins", cmd_plugins, NULL, &L_help},
|
||||
{"m", "mount filesystem", cmd_mount, cmd_mount_init, &m_help},
|
||||
{"o", "open or map file", cmd_open, cmd_open_init, &o_help},
|
||||
{"p", "print current block", cmd_print, cmd_print_init, &p_help},
|
||||
{"P", "project", cmd_project, cmd_project_init, &P_help},
|
||||
|
|
|
|||
|
|
@ -567,14 +567,10 @@ static int cmd_cmp(void *data, const char *input) {
|
|||
rz_cons_printf ("%s\n", oldText + 1);
|
||||
}
|
||||
} else {
|
||||
if (rz_fs_check (core->fs, path)) {
|
||||
rz_core_cmdf (core, "mg %s", path);
|
||||
} else {
|
||||
char *res = rz_syscmd_cat (path);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
char *res = rz_syscmd_cat (path);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,6 +105,10 @@ const RzCmdDescHelp l_help = {
|
|||
.summary = "list files and directories",
|
||||
};
|
||||
|
||||
const RzCmdDescHelp m_help = {
|
||||
.summary = "make directories and move files",
|
||||
};
|
||||
|
||||
const RzCmdDescHelp j_help = {
|
||||
.summary = "join the contents of the two files",
|
||||
};
|
||||
|
|
@ -117,10 +121,6 @@ const RzCmdDescHelp L_help = {
|
|||
.summary = "list, unload, load r2 plugins",
|
||||
};
|
||||
|
||||
const RzCmdDescHelp m_help = {
|
||||
.summary = "mountpoints commands",
|
||||
};
|
||||
|
||||
const RzCmdDescHelp o_help = {
|
||||
.summary = "open file at optional address",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,424 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2009-2019 // pancake */
|
||||
|
||||
static const char *help_msg_m[] = {
|
||||
"Usage:", "m[-?*dgy] [...] ", "Mountpoints management",
|
||||
"m", " /mnt ext2 0", "Mount ext2 fs at /mnt with delta 0 on IO",
|
||||
"m", " /mnt", "Mount fs at /mnt with autodetect fs and current offset",
|
||||
"m", "", "List all mountpoints in human readable format",
|
||||
"m*", "", "Same as above, but in r2 commands",
|
||||
"m-/", "", "Umount given path (/)",
|
||||
"mL", "", "List filesystem plugins (Same as Lm)",
|
||||
"mc", " [file]", "Cat: Show the contents of the given file",
|
||||
"md", " /", "List directory contents for path",
|
||||
"mf", "[?] [o|n]", "Search files for given filename or for offset",
|
||||
"mg", " /foo", "Get fs file/dir and dump it to disk",
|
||||
"mi", " /foo/bar", "Get offset and size of given file",
|
||||
"mj", "", "List mounted filesystems in JSON",
|
||||
"mo", " /foo/bar", "Open given file into a malloc://",
|
||||
"mp", " msdos 0", "Show partitions in msdos format at offset 0",
|
||||
"mp", "", "List all supported partition types",
|
||||
"ms", " /mnt", "Open filesystem prompt at /mnt",
|
||||
"mw", " [file] [data]", "Write data into file", // TODO: add mwf
|
||||
"my", "", "Yank contents of file into clipboard",
|
||||
//"TODO: support multiple mountpoints and RFile IO's (need io+core refactorn",
|
||||
NULL
|
||||
};
|
||||
|
||||
static void cmd_mount_init(RzCore *core, RzCmdDesc *parent) {
|
||||
DEFINE_CMD_DESCRIPTOR (core, m);
|
||||
}
|
||||
|
||||
static int cmd_mkdir(void *data, const char *input) {
|
||||
char *res = rz_syscmd_mkdir (input);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_mv(void *data, const char *input) {
|
||||
return rz_syscmd_mv (input)? 1: 0;
|
||||
}
|
||||
|
||||
static char *cwd = NULL;
|
||||
#define av_max 1024
|
||||
|
||||
static const char *t2s(const char ch) {
|
||||
switch (ch) {
|
||||
case 'f': return "file";
|
||||
case 'd': return "directory";
|
||||
case 'm': return "mountpoint";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static void cmd_mount_ls (RzCore *core, const char *input) {
|
||||
bool isJSON = *input == 'j';
|
||||
RzListIter *iter;
|
||||
RzFSFile *file;
|
||||
RzFSRoot *root;
|
||||
input = rz_str_trim_head_ro (input + isJSON);
|
||||
RzList *list = rz_fs_dir (core->fs, input);
|
||||
PJ *pj = NULL;
|
||||
if (isJSON) {
|
||||
pj = pj_new ();
|
||||
pj_a (pj);
|
||||
}
|
||||
if (list) {
|
||||
rz_list_foreach (list, iter, file) {
|
||||
if (isJSON) {
|
||||
pj_o (pj);
|
||||
pj_ks (pj, "type", t2s(file->type));
|
||||
pj_ks (pj, "name", file->name);
|
||||
pj_end (pj);
|
||||
} else {
|
||||
rz_cons_printf ("%c %s\n", file->type, file->name);
|
||||
}
|
||||
}
|
||||
rz_list_free (list);
|
||||
}
|
||||
const char *path = *input? input: "/";
|
||||
rz_list_foreach (core->fs->roots, iter, root) {
|
||||
// TODO: adjust contents between //
|
||||
if (!strncmp (path, root->path, strlen (path))) {
|
||||
char *base = strdup (root->path);
|
||||
char *ls = (char *)rz_str_lchr (base, '/');
|
||||
if (ls) {
|
||||
ls++;
|
||||
*ls = 0;
|
||||
}
|
||||
// TODO: adjust contents between //
|
||||
if (!strcmp (path, base)) {
|
||||
if (isJSON) {
|
||||
pj_o (pj);
|
||||
pj_ks (pj, "path", root->path);
|
||||
pj_ks (pj, "type", "mountpoint");
|
||||
pj_end (pj);
|
||||
} else {
|
||||
rz_cons_printf ("m %s\n", root->path); // (root->path && root->path[0]) ? root->path + 1: "");
|
||||
}
|
||||
}
|
||||
free (base);
|
||||
}
|
||||
}
|
||||
if (isJSON) {
|
||||
pj_end (pj);
|
||||
rz_cons_printf ("%s\n", pj_string (pj));
|
||||
pj_free (pj);
|
||||
}
|
||||
}
|
||||
|
||||
static int cmd_mount(void *data, const char *_input) {
|
||||
ut64 off = 0;
|
||||
char *input, *oinput, *ptr, *ptr2;
|
||||
RzList *list;
|
||||
RzListIter *iter;
|
||||
RzFSFile *file;
|
||||
RzFSRoot *root;
|
||||
RzFSPlugin *plug;
|
||||
RzFSPartition *part;
|
||||
RzCore *core = (RzCore *)data;
|
||||
|
||||
if (!strncmp ("kdir", _input, 4)) {
|
||||
return cmd_mkdir (data, _input);
|
||||
}
|
||||
if (!strncmp ("v", _input, 1)) {
|
||||
return cmd_mv (data, _input);
|
||||
}
|
||||
input = oinput = strdup (_input);
|
||||
|
||||
switch (*input) {
|
||||
case ' ':
|
||||
input = (char *)rz_str_trim_head_ro (input + 1);
|
||||
ptr = strchr (input, ' ');
|
||||
if (ptr) {
|
||||
*ptr = 0;
|
||||
ptr = (char *)rz_str_trim_head_ro (ptr + 1);
|
||||
ptr2 = strchr (ptr, ' ');
|
||||
if (ptr2) {
|
||||
*ptr2 = 0;
|
||||
off = rz_num_math (core->num, ptr2+1);
|
||||
}
|
||||
input = (char *)rz_str_trim_head_ro (input);
|
||||
ptr = (char*)rz_str_trim_head_ro (ptr);
|
||||
|
||||
const char *mountp = input;
|
||||
const char *fstype = ptr;
|
||||
if (*mountp != '/') {
|
||||
if (*fstype != '/') {
|
||||
eprintf ("Invalid mountpoint\n");
|
||||
return 0;
|
||||
}
|
||||
mountp = ptr;
|
||||
fstype = input;
|
||||
}
|
||||
|
||||
if (!rz_fs_mount (core->fs, fstype, mountp, off)) {
|
||||
eprintf ("Cannot mount %s\n", input);
|
||||
}
|
||||
} else {
|
||||
if (!(ptr = rz_fs_name (core->fs, core->offset))) {
|
||||
eprintf ("Unknown filesystem type\n");
|
||||
}
|
||||
if (!rz_fs_mount (core->fs, ptr, input, core->offset)) {
|
||||
eprintf ("Cannot mount %s\n", input);
|
||||
}
|
||||
free (ptr);
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
rz_fs_umount (core->fs, input+1);
|
||||
break;
|
||||
case 'j':
|
||||
{
|
||||
PJ *pj = pj_new ();
|
||||
pj_o (pj);
|
||||
pj_k (pj, "mountpoints");
|
||||
pj_a (pj);
|
||||
rz_list_foreach (core->fs->roots, iter, root) {
|
||||
pj_o (pj);
|
||||
pj_ks (pj, "path", root->path);
|
||||
pj_ks (pj, "plugin", root->p->name);
|
||||
pj_kn (pj, "offset", root->delta);
|
||||
pj_end (pj);
|
||||
}
|
||||
pj_end (pj);
|
||||
pj_k (pj, "plugins");
|
||||
pj_a (pj);
|
||||
rz_list_foreach (core->fs->plugins, iter, plug) {
|
||||
pj_o (pj);
|
||||
pj_ks (pj, "name", plug->name);
|
||||
pj_ks (pj, "description", plug->desc);
|
||||
pj_end (pj);
|
||||
}
|
||||
|
||||
pj_end (pj);
|
||||
pj_end (pj);
|
||||
rz_cons_printf ("%s\n", pj_string (pj));
|
||||
pj_free (pj);
|
||||
}
|
||||
break;
|
||||
case '*':
|
||||
rz_list_foreach (core->fs->roots, iter, root) {
|
||||
rz_cons_printf ("m %s %s 0x%"PFMT64x"\n",
|
||||
root-> path, root->p->name, root->delta);
|
||||
}
|
||||
break;
|
||||
case '\0':
|
||||
rz_list_foreach (core->fs->roots, iter, root) {
|
||||
rz_cons_printf ("%s\t0x%"PFMT64x"\t%s\n",
|
||||
root->p->name, root->delta, root->path);
|
||||
}
|
||||
break;
|
||||
case 'L': // "mL" list of plugins
|
||||
rz_list_foreach (core->fs->plugins, iter, plug) {
|
||||
rz_cons_printf ("%10s %s\n", plug->name, plug->desc);
|
||||
}
|
||||
break;
|
||||
case 'l': // "ml"
|
||||
case 'd': // "md"
|
||||
cmd_mount_ls (core, input + 1);
|
||||
break;
|
||||
case 'p':
|
||||
input++;
|
||||
if (*input == ' ') {
|
||||
input++;
|
||||
}
|
||||
ptr = strchr (input, ' ');
|
||||
if (ptr) {
|
||||
*ptr = 0;
|
||||
off = rz_num_math (core->num, ptr+1);
|
||||
}
|
||||
list = rz_fs_partitions (core->fs, input, off);
|
||||
if (list) {
|
||||
rz_list_foreach (list, iter, part) {
|
||||
rz_cons_printf ("%d %02x 0x%010"PFMT64x" 0x%010"PFMT64x"\n",
|
||||
part->number, part->type,
|
||||
part->start, part->start+part->length);
|
||||
}
|
||||
rz_list_free (list);
|
||||
} else {
|
||||
eprintf ("Cannot read partition\n");
|
||||
}
|
||||
break;
|
||||
case 'o': //"mo"
|
||||
input++;
|
||||
if (input[0]==' ') {
|
||||
input++;
|
||||
}
|
||||
file = rz_fs_open (core->fs, input, false);
|
||||
if (file) {
|
||||
rz_fs_read (core->fs, file, 0, file->size);
|
||||
char *uri = rz_str_newf ("malloc://%d", file->size);
|
||||
RzIODesc *fd = rz_io_open (core->io, uri, R_PERM_RW, 0);
|
||||
if (fd) {
|
||||
rz_io_desc_write (fd, file->data, file->size);
|
||||
}
|
||||
} else {
|
||||
eprintf ("Cannot open file\n");
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
input++;
|
||||
if (input[0]==' ') {
|
||||
input++;
|
||||
}
|
||||
file = rz_fs_open (core->fs, input, false);
|
||||
if (file) {
|
||||
// XXX: dump to file or just pipe?
|
||||
rz_fs_read (core->fs, file, 0, file->size);
|
||||
rz_cons_printf ("f file %d 0x%08"PFMT64x"\n", file->size, file->off);
|
||||
rz_fs_close (core->fs, file);
|
||||
} else {
|
||||
eprintf ("Cannot open file\n");
|
||||
}
|
||||
break;
|
||||
case 'c': // "mc"
|
||||
input++;
|
||||
if (*input == ' ') {
|
||||
input++;
|
||||
}
|
||||
ptr = strchr (input, ' ');
|
||||
if (ptr) {
|
||||
*ptr++ = 0;
|
||||
} else {
|
||||
ptr = "./";
|
||||
}
|
||||
file = rz_fs_open (core->fs, input, false);
|
||||
if (file) {
|
||||
rz_fs_read (core->fs, file, 0, file->size);
|
||||
rz_cons_memcat ((const char *)file->data, file->size);
|
||||
rz_fs_close (core->fs, file);
|
||||
rz_cons_memcat ("\n", 1);
|
||||
} else if (!rz_fs_dir_dump (core->fs, input, ptr)) {
|
||||
eprintf ("Cannot open file\n");
|
||||
}
|
||||
break;
|
||||
case 'g': // "mg"
|
||||
input++;
|
||||
if (*input == ' ') {
|
||||
input++;
|
||||
}
|
||||
ptr = strchr (input, ' ');
|
||||
if (ptr) {
|
||||
*ptr++ = 0;
|
||||
} else {
|
||||
ptr = "./";
|
||||
}
|
||||
file = rz_fs_open (core->fs, input, false);
|
||||
if (file) {
|
||||
char *localFile = strdup (input);
|
||||
char *slash = (char *)rz_str_rchr (localFile, NULL, '/');
|
||||
if (slash) {
|
||||
memmove (localFile, slash + 1, strlen (slash));
|
||||
}
|
||||
rz_fs_read (core->fs, file, 0, file->size);
|
||||
rz_file_dump (localFile, file->data, file->size, false);
|
||||
rz_fs_close (core->fs, file);
|
||||
eprintf ("File '%s' created.\n", localFile);
|
||||
free (localFile);
|
||||
} else if (!rz_fs_dir_dump (core->fs, input, ptr)) {
|
||||
eprintf ("Cannot open file\n");
|
||||
}
|
||||
break;
|
||||
case 'f':
|
||||
input++;
|
||||
switch (*input) {
|
||||
case '?':
|
||||
rz_cons_printf (
|
||||
"Usage: mf[no] [...]\n"
|
||||
" mfn /foo *.c ; search files by name in /foo path\n"
|
||||
" mfo /foo 0x5e91 ; search files by offset in /foo path\n"
|
||||
);
|
||||
break;
|
||||
case 'n':
|
||||
input++;
|
||||
if (*input == ' ')
|
||||
input++;
|
||||
ptr = strchr (input, ' ');
|
||||
if (ptr) {
|
||||
*ptr++ = 0;
|
||||
list = rz_fs_find_name (core->fs, input, ptr);
|
||||
rz_list_foreach (list, iter, ptr) {
|
||||
rz_str_trim_path (ptr);
|
||||
printf ("%s\n", ptr);
|
||||
}
|
||||
//XXX: rz_list_purge (list);
|
||||
} else eprintf ("Unknown store path\n");
|
||||
break;
|
||||
case 'o':
|
||||
input++;
|
||||
if (*input == ' ')
|
||||
input++;
|
||||
ptr = strchr (input, ' ');
|
||||
if (ptr) {
|
||||
*ptr++ = 0;
|
||||
ut64 off = rz_num_math (core->num, ptr);
|
||||
list = rz_fs_find_off (core->fs, input, off);
|
||||
rz_list_foreach (list, iter, ptr) {
|
||||
rz_str_trim_path (ptr);
|
||||
printf ("%s\n", ptr);
|
||||
}
|
||||
//XXX: rz_list_purge (list);
|
||||
} else eprintf ("Unknown store path\n");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 's': // "ms"
|
||||
if (core->http_up) {
|
||||
free (oinput);
|
||||
return false;
|
||||
}
|
||||
input++;
|
||||
if (input[0] == ' ') {
|
||||
input++;
|
||||
}
|
||||
rz_cons_set_raw (false);
|
||||
{
|
||||
RzFSShell shell = {
|
||||
.cwd = &cwd,
|
||||
.set_prompt = rz_line_set_prompt,
|
||||
.readline = rz_line_readline,
|
||||
.hist_add = rz_line_hist_add
|
||||
};
|
||||
core->rfs = &shell;
|
||||
core->autocomplete_type = AUTOCOMPLETE_MS;
|
||||
rz_core_autocomplete_reload (core);
|
||||
rz_fs_shell_prompt (&shell, core->fs, input);
|
||||
core->autocomplete_type = AUTOCOMPLETE_DEFAULT;
|
||||
rz_core_autocomplete_reload (core);
|
||||
R_FREE (cwd);
|
||||
}
|
||||
break;
|
||||
case 'w':
|
||||
if (input[1] == ' ') {
|
||||
char *args = rz_str_trim_dup (input + 1);
|
||||
char *arg = strchr (args, ' ');
|
||||
if (arg) {
|
||||
data = arg + 1;
|
||||
} else {
|
||||
data = "";
|
||||
// touch and truncate
|
||||
}
|
||||
RzFSFile *f = rz_fs_open (core->fs, args, true);
|
||||
if (f) {
|
||||
rz_fs_write (core->fs, f, 0, (const ut8 *)data, strlen (data));
|
||||
rz_fs_close (core->fs, f);
|
||||
rz_fs_file_free (f);
|
||||
}
|
||||
free (args);
|
||||
} else {
|
||||
eprintf ("Usage: mw [file] ([data])\n");
|
||||
}
|
||||
break;
|
||||
case 'y':
|
||||
eprintf ("TODO\n");
|
||||
break;
|
||||
case '?':
|
||||
rz_core_cmd_help (core, help_msg_m);
|
||||
break;
|
||||
}
|
||||
free (oinput);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -27,7 +27,6 @@ static const char *help_msg_slash_m[] = {
|
|||
"/m", "", "search for known magic patterns",
|
||||
"/m", " [file]", "same as above but using the given magic file",
|
||||
"/me", " ", "like ?e similar to IRC's /me",
|
||||
"/mm", " ", "search for known filesystems and mount them automatically",
|
||||
"/mb", "", "search recognized RBin headers",
|
||||
NULL
|
||||
};
|
||||
|
|
@ -3376,35 +3375,6 @@ reread:
|
|||
// TODO : iter maps?
|
||||
cmd_search_bin (core, search_itv);
|
||||
rz_config_set_i (core->config, "bin.verbose", bin_verbose);
|
||||
} else if (input[1] == 'm') { // "/mm"
|
||||
ut64 addr = search_itv.addr;
|
||||
RzListIter *iter;
|
||||
RzIOMap *map;
|
||||
int count = 0;
|
||||
const int align = core->search->align;
|
||||
rz_list_foreach (param.boundaries, iter, map) {
|
||||
// eprintf ("-- %llx %llx\n", map->itv.addr, rz_itv_end (map->itv));
|
||||
rz_cons_break_push (NULL, NULL);
|
||||
for (addr = map->itv.addr; addr < rz_itv_end (map->itv); addr++) {
|
||||
if (rz_cons_is_breaked ()) {
|
||||
break;
|
||||
}
|
||||
if (align && (0 != (addr % align))) {
|
||||
addr += (addr % align) - 1;
|
||||
continue;
|
||||
}
|
||||
char *mp = rz_str_newf ("/mnt%d", count);
|
||||
eprintf ("[*] Trying to mount at 0x%08"PFMT64x"\r[", addr);
|
||||
if (rz_fs_mount (core->fs, NULL, mp, addr)) {
|
||||
count ++;
|
||||
eprintf ("Mounted %s at 0x%08"PFMT64x"\n", mp, addr);
|
||||
}
|
||||
free (mp);
|
||||
}
|
||||
rz_cons_clear_line (1);
|
||||
rz_cons_break_pop ();
|
||||
}
|
||||
eprintf ("\n");
|
||||
} else if (input[1] == 'e') { // "/me"
|
||||
rz_cons_printf ("* r2 thinks%s\n", input + 2);
|
||||
} else if (input[1] == ' ' || input[1] == '\0' || param.outmode == R_MODE_JSON) {
|
||||
|
|
|
|||
|
|
@ -234,14 +234,10 @@ static int cmd_sort(void *data, const char *input) { // "sort"
|
|||
if (!arg) {
|
||||
arg = "";
|
||||
}
|
||||
if (rz_fs_check (core->fs, arg)) {
|
||||
rz_core_cmdf (core, "md %s", arg);
|
||||
} else {
|
||||
char *res = rz_syscmd_sort (arg);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
char *res = rz_syscmd_sort (arg);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -339,14 +339,10 @@ static int cmd_tail(void *data, const char *_input) { // "tail"
|
|||
if (!arg) {
|
||||
arg = "";
|
||||
}
|
||||
if (rz_fs_check (core->fs, arg)) {
|
||||
rz_core_cmdf (core, "md %s", arg);
|
||||
} else {
|
||||
char *res = rz_syscmd_tail (arg, lines);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
char *res = rz_syscmd_tail (arg, lines);
|
||||
if (res) {
|
||||
rz_cons_print (res);
|
||||
free (res);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -830,13 +830,9 @@ RZ_API RzCore *rz_core_new(void) {
|
|||
}
|
||||
|
||||
/*-----------------------------------*/
|
||||
#define radare_argc (sizeof (radare_argv) / sizeof(const char*) - 1)
|
||||
#define ms_argc (sizeof (ms_argv) / sizeof (const char*) - 1)
|
||||
static const char *ms_argv[] = {
|
||||
"?", "!", "ls", "cd", "cat", "get", "mount", "help", "q", "exit", NULL
|
||||
};
|
||||
#define rizin_argc (sizeof (rizin_argv) / sizeof(const char*) - 1)
|
||||
|
||||
static const char *radare_argv[] = {
|
||||
static const char *rizin_argv[] = {
|
||||
"whereis", "which", "ls", "rm", "mkdir", "pwd", "cat", "sort", "uniq", "join", "less", "exit", "quit",
|
||||
"#?", "#!", "#sha1", "#crc32", "#pcprint", "#sha256", "#sha512", "#md4", "#md5",
|
||||
"#!python", "#!vala", "#!pipe",
|
||||
|
|
@ -951,7 +947,6 @@ static const char *radare_argv[] = {
|
|||
"k?", "k", "ko", "kd", "ks", "kj",
|
||||
"l",
|
||||
"L?", "L", "L-", "Ll", "LL", "La", "Lc", "Ld", "Lh", "Li", "Lo",
|
||||
"m?", "m", "m*", "ml", "m-", "md", "mf?", "mf", "mg", "mo", "mi", "mp", "ms", "my",
|
||||
"o?", "o", "o-", "o--", "o+", "oa", "oa-", "oq", "o*", "o.", "o=",
|
||||
"ob?", "ob", "ob*", "obo", "oba", "obf", "obj", "obr", "ob-", "ob-*",
|
||||
"oc", "of", "oi", "oj", "oL", "om", "on",
|
||||
|
|
@ -1028,91 +1023,6 @@ static const char *radare_argv[] = {
|
|||
NULL
|
||||
};
|
||||
|
||||
static void autocomplete_mount_point (RLineCompletion *completion, RzCore *core, const char *path) {
|
||||
RzFSRoot *r;
|
||||
RzListIter *iter;
|
||||
rz_list_foreach (core->fs->roots, iter, r) {
|
||||
char *base = strdup (r->path);
|
||||
char *ls = (char *) rz_str_lchr (base, '/');
|
||||
if (ls) {
|
||||
ls++;
|
||||
*ls = 0;
|
||||
}
|
||||
if (!strcmp (path, base)) {
|
||||
rz_line_completion_push (completion, r->path);
|
||||
}
|
||||
free (base);
|
||||
}
|
||||
}
|
||||
|
||||
static void autocomplete_ms_path(RLineCompletion *completion, RzCore *core, const char *str, const char *path) {
|
||||
char *lpath = NULL, *dirname = NULL , *basename = NULL;
|
||||
char *p = NULL;
|
||||
char *pwd = (core->rfs && *(core->rfs->cwd)) ? *(core->rfs->cwd): ".";
|
||||
int n = 0;
|
||||
RzList *list;
|
||||
RzListIter *iter;
|
||||
RzFSFile *file;
|
||||
rz_return_if_fail (path);
|
||||
lpath = rz_str_new (path);
|
||||
p = (char *)rz_str_last (lpath, R_SYS_DIR);
|
||||
if (p) {
|
||||
*p = 0;
|
||||
if (p == lpath) { // /xxx
|
||||
dirname = rz_str_new ("/");
|
||||
} else if (lpath[0] == '.') { // ./xxx/yyy
|
||||
dirname = rz_str_newf ("%s%s", pwd, R_SYS_DIR);
|
||||
} else if (lpath[0] == '/') { // /xxx/yyy
|
||||
dirname = rz_str_newf ("%s%s", lpath, R_SYS_DIR);
|
||||
} else { // xxx/yyy
|
||||
if (strlen (pwd) == 1) { // if pwd is root
|
||||
dirname = rz_str_newf ("%s%s%s", R_SYS_DIR, lpath, R_SYS_DIR);
|
||||
} else {
|
||||
dirname = rz_str_newf ("%s%s%s%s", pwd, R_SYS_DIR, lpath, R_SYS_DIR);
|
||||
}
|
||||
}
|
||||
basename = rz_str_new (p + 1);
|
||||
} else { // xxx
|
||||
if (strlen (pwd) == 1) {
|
||||
dirname = rz_str_newf ("%s", R_SYS_DIR);
|
||||
} else {
|
||||
dirname = rz_str_newf ("%s%s", pwd, R_SYS_DIR);
|
||||
}
|
||||
basename = rz_str_new (lpath);
|
||||
}
|
||||
|
||||
if (!dirname || !basename) {
|
||||
goto out;
|
||||
}
|
||||
list= rz_fs_dir (core->fs, dirname);
|
||||
n = strlen (basename);
|
||||
bool chgdir = !strncmp (str, "cd ", 3);
|
||||
if (list) {
|
||||
rz_list_foreach (list, iter, file) {
|
||||
if (!file) {
|
||||
continue;
|
||||
}
|
||||
if (!basename[0] || !strncmp (file->name, basename, n)) {
|
||||
char *tmpstring = rz_str_newf ("%s%s", dirname, file->name);
|
||||
if (rz_file_is_directory (tmpstring)) {
|
||||
char *s = rz_str_newf ("%s/", tmpstring);
|
||||
rz_line_completion_push (completion, s);
|
||||
free (s);
|
||||
} else if (!chgdir) {
|
||||
rz_line_completion_push (completion, tmpstring);
|
||||
}
|
||||
free (tmpstring);
|
||||
}
|
||||
}
|
||||
rz_list_free (list);
|
||||
}
|
||||
autocomplete_mount_point (completion, core, path);
|
||||
out:
|
||||
free (lpath);
|
||||
free (dirname);
|
||||
free (basename);
|
||||
}
|
||||
|
||||
static void autocomplete_process_path(RLineCompletion *completion, const char *str, const char *path) {
|
||||
char *lpath = NULL, *dirname = NULL , *basename = NULL;
|
||||
char *home = NULL, *filename = NULL, *p = NULL;
|
||||
|
|
@ -1278,10 +1188,10 @@ static void autocomplete_default(R_NULLABLE RzCore *core, RLineCompletion *compl
|
|||
}
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < radare_argc && radare_argv[i]; i++) {
|
||||
int length = strlen (radare_argv[i]);
|
||||
if (!strncmp (radare_argv[i], buf->data, length)) {
|
||||
rz_line_completion_push (completion, radare_argv[i]);
|
||||
for (i = 0; i < rizin_argc && rizin_argv[i]; i++) {
|
||||
int length = strlen (rizin_argv[i]);
|
||||
if (!strncmp (rizin_argv[i], buf->data, length)) {
|
||||
rz_line_completion_push (completion, rizin_argv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1522,20 +1432,6 @@ static void autocomplete_file(RLineCompletion *completion, const char *str) {
|
|||
|
||||
}
|
||||
|
||||
static void autocomplete_ms_file(RzCore* core, RLineCompletion *completion, const char *str) {
|
||||
rz_return_if_fail (str);
|
||||
char *pipe = strchr (str, '>');
|
||||
char *path = (core->rfs && *(core->rfs->cwd)) ? *(core->rfs->cwd): "/";
|
||||
if (pipe) {
|
||||
str = rz_str_trim_head_ro (pipe + 1);
|
||||
}
|
||||
if (str && !*str) {
|
||||
autocomplete_ms_path (completion, core, str, path);
|
||||
} else {
|
||||
autocomplete_ms_path (completion, core, str, str);
|
||||
}
|
||||
}
|
||||
|
||||
static void autocomplete_theme(RzCore *core, RLineCompletion *completion, const char *str) {
|
||||
rz_return_if_fail (str);
|
||||
int len = strlen (str);
|
||||
|
|
@ -1663,9 +1559,6 @@ static bool find_autocomplete(RzCore *core, RLineCompletion *completion, RLineBu
|
|||
case R_CORE_AUTOCMPLT_MACR:
|
||||
autocomplete_macro (core, completion, p);
|
||||
break;
|
||||
case R_CORE_AUTOCMPLT_MS:
|
||||
autocomplete_ms_file(core, completion, p);
|
||||
break;
|
||||
case R_CORE_AUTOCMPLT_FILE:
|
||||
autocomplete_file (completion, p);
|
||||
break;
|
||||
|
|
@ -1947,7 +1840,7 @@ RZ_API int rz_core_fgets(char *buf, int len) {
|
|||
const char *ptr;
|
||||
RLine *rli = rz_line_singleton ();
|
||||
buf[0] = '\0';
|
||||
rz_line_completion_set (&rli->completion, radare_argc, radare_argv);
|
||||
rz_line_completion_set (&rli->completion, rizin_argc, rizin_argv);
|
||||
rli->completion.run = autocomplete;
|
||||
rli->completion.run_user = rli->user;
|
||||
ptr = rz_line_readline ();
|
||||
|
|
@ -2333,6 +2226,7 @@ static void __foreach(RzCore *core, const char **cmds, int type) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static void __init_autocomplete_default (RzCore* core) {
|
||||
const char *fcns[] = {
|
||||
"afi", "afcf", "afn", NULL
|
||||
|
|
@ -2354,17 +2248,14 @@ static void __init_autocomplete_default (RzCore* core) {
|
|||
const char *files[] = {
|
||||
".", "..", ".*", "/F", "/m", "!", "!!", "#!c", "#!v", "#!cpipe", "#!vala",
|
||||
"#!rust", "#!zig", "#!pipe", "#!python", "aeli", "arp", "arpg", "dmd", "drp", "drpg", "o",
|
||||
"idp", "idpi", "L", "obf", "o+", "oc", "r2", "rz_bin", "rz_asm", "rz_hash", "rz_ax",
|
||||
"rz_find", "cd", "on", "op", "wf", "rm", "wF", "wp", "Sd", "Sl", "to", "pm",
|
||||
"idp", "idpi", "L", "obf", "o+", "oc", "r2", "rabin2", "rasm2", "rahash2", "rax2",
|
||||
"rafind2", "cd", "on", "op", "wf", "rm", "wF", "wp", "Sd", "Sl", "to", "pm",
|
||||
"/m", "zos", "zfd", "zfs", "zfz", "cat", "wta", "wtf", "wxf", "dml", "vi",
|
||||
"less", "head", "tail", NULL
|
||||
};
|
||||
const char *projs[] = {
|
||||
"Pc", "Pd", "Pi", "Po", "Ps", "P-", NULL
|
||||
};
|
||||
const char *mounts[] = {
|
||||
"md", "mg", "mo", "ms", "mc", "mi", "mw", NULL
|
||||
};
|
||||
__foreach (core, flags, R_CORE_AUTOCMPLT_FLAG);
|
||||
__foreach (core, seeks, R_CORE_AUTOCMPLT_SEEK);
|
||||
__foreach (core, fcns, R_CORE_AUTOCMPLT_FCN);
|
||||
|
|
@ -2372,7 +2263,6 @@ static void __init_autocomplete_default (RzCore* core) {
|
|||
__foreach (core, breaks, R_CORE_AUTOCMPLT_BRKP);
|
||||
__foreach (core, files, R_CORE_AUTOCMPLT_FILE);
|
||||
__foreach (core, projs, R_CORE_AUTOCMPLT_PRJT);
|
||||
__foreach (core, mounts, R_CORE_AUTOCMPLT_MS);
|
||||
|
||||
rz_core_autocomplete_add (core->autocomplete, "-", R_CORE_AUTOCMPLT_MINS, true);
|
||||
rz_core_autocomplete_add (core->autocomplete, "zs", R_CORE_AUTOCMPLT_ZIGN, true);
|
||||
|
|
@ -2387,9 +2277,9 @@ static void __init_autocomplete_default (RzCore* core) {
|
|||
rz_core_autocomplete_add (core->autocomplete, "(-", R_CORE_AUTOCMPLT_MACR, true);
|
||||
/* just for hints */
|
||||
int i;
|
||||
for (i = 0; i < radare_argc && radare_argv[i]; i++) {
|
||||
if (!rz_core_autocomplete_find (core->autocomplete, radare_argv[i], true)) {
|
||||
rz_core_autocomplete_add (core->autocomplete, radare_argv[i], R_CORE_AUTOCMPLT_DFLT, true);
|
||||
for (i = 0; i < rizin_argc && rizin_argv[i]; i++) {
|
||||
if (!rz_core_autocomplete_find (core->autocomplete, rizin_argv[i], true)) {
|
||||
rz_core_autocomplete_add (core->autocomplete, rizin_argv[i], R_CORE_AUTOCMPLT_DFLT, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2399,17 +2289,6 @@ static void __init_autocomplete (RzCore* core) {
|
|||
core->autocomplete = R_NEW0 (RzCoreAutocomplete);
|
||||
if (core->autocomplete_type == AUTOCOMPLETE_DEFAULT) {
|
||||
__init_autocomplete_default (core);
|
||||
} else if (core->autocomplete_type == AUTOCOMPLETE_MS) {
|
||||
rz_core_autocomplete_add (core->autocomplete, "ls", R_CORE_AUTOCMPLT_MS, true);
|
||||
rz_core_autocomplete_add (core->autocomplete, "cd", R_CORE_AUTOCMPLT_MS, true);
|
||||
rz_core_autocomplete_add (core->autocomplete, "cat", R_CORE_AUTOCMPLT_MS, true);
|
||||
rz_core_autocomplete_add (core->autocomplete, "get", R_CORE_AUTOCMPLT_MS, true);
|
||||
rz_core_autocomplete_add (core->autocomplete, "mount", R_CORE_AUTOCMPLT_MS, true);
|
||||
for (i = 0; i < ms_argc && ms_argv[i]; i++) {
|
||||
if (!rz_core_autocomplete_find (core->autocomplete, ms_argv[i], true)) {
|
||||
rz_core_autocomplete_add (core->autocomplete, ms_argv[i], R_CORE_AUTOCMPLT_MS, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2653,7 +2532,6 @@ RZ_API bool rz_core_init(RzCore *core) {
|
|||
core->io->ff = 1;
|
||||
core->search = rz_search_new (R_SEARCH_KEYWORD);
|
||||
rz_io_undo_enable (core->io, 1, 0); // TODO: configurable via eval
|
||||
core->fs = rz_fs_new ();
|
||||
core->flags = rz_flag_new ();
|
||||
core->flags->cb_printf = rz_cons_printf;
|
||||
core->graph = rz_agraph_new (rz_cons_canvas_new (1, 1));
|
||||
|
|
@ -2673,9 +2551,6 @@ RZ_API bool rz_core_init(RzCore *core) {
|
|||
rz_io_bind (core->io, &(core->search->iob));
|
||||
rz_io_bind (core->io, &(core->print->iob));
|
||||
rz_io_bind (core->io, &(core->anal->iob));
|
||||
rz_io_bind (core->io, &(core->fs->iob));
|
||||
rz_cons_bind (&(core->fs->csb));
|
||||
rz_core_bind (core, &(core->fs->cob));
|
||||
rz_io_bind (core->io, &(core->bin->iob));
|
||||
rz_flag_bind (core->flags, &(core->anal->flb));
|
||||
core->anal->flg_class_set = core_flg_class_set;
|
||||
|
|
@ -2815,7 +2690,6 @@ RZ_API void rz_core_fini(RzCore *c) {
|
|||
rz_cons_singleton ()->teefile = NULL; // HACK
|
||||
rz_search_free (c->search);
|
||||
rz_flag_free (c->flags);
|
||||
rz_fs_free (c->fs);
|
||||
rz_egg_free (c->egg);
|
||||
rz_lib_free (c->lib);
|
||||
rz_buf_free (c->yank_buf);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ CB (asm, rasm)
|
|||
CB (parse, parser)
|
||||
CB (bin, bin)
|
||||
CB (egg, egg)
|
||||
CB (fs, fs)
|
||||
|
||||
static void __openPluginsAt(RzCore *core, const char *arg, const char *user_path) {
|
||||
if (arg && *arg) {
|
||||
|
|
@ -105,7 +104,6 @@ RZ_API void rz_core_loadlibs_init(RzCore *core) {
|
|||
DF (PARSE, "parsing plugins", parse);
|
||||
DF (BIN, "bin plugins", bin);
|
||||
DF (EGG, "egg plugins", egg);
|
||||
DF (FS, "fs plugins", fs);
|
||||
core->times->loadlibs_init_time = rz_time_now_mono () - prev;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ rz_core_sources = [
|
|||
#'cmd_macro.c',
|
||||
#'cmd_magic.c',
|
||||
#'cmd_meta.c',
|
||||
#'cmd_mount.c',
|
||||
#'cmd_open.c',
|
||||
#'cmd_print.c',
|
||||
#'cmd_project.c',
|
||||
|
|
@ -87,7 +86,6 @@ rz_core_deps = [
|
|||
rz_anal_dep,
|
||||
rz_socket_dep,
|
||||
rz_io_dep,
|
||||
rz_fs_dep,
|
||||
rz_lang_dep,
|
||||
rz_magic_dep,
|
||||
rz_hash_dep,
|
||||
|
|
@ -140,7 +138,6 @@ pkgconfig_mod.generate(
|
|||
'rz_anal',
|
||||
'rz_socket',
|
||||
'rz_io',
|
||||
'rz_fs',
|
||||
'rz_lang',
|
||||
'rz_hash',
|
||||
'rz_flag',
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ CFLAGS+=-I../../include -Wall -shared
|
|||
CFLAGS+=${PIC_CFLAGS} ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}..
|
||||
CFLAGS+=-L../../util -lrz_util -L../../reg -lrz_reg -L.. -lrz_core
|
||||
CFLAGS+=-L../../cons -lrz_cons -L../../bin -lrz_bin
|
||||
CFLAGS+=-L../../parse -lrz_parse -L../../io -lrz_io -L../../fs -lrz_fs
|
||||
CFLAGS+=-L../../parse -lrz_parse -L../../io -lrz_io
|
||||
CFLAGS+=-L../../magic -lrz_magic -L../../hash -lrz_hash
|
||||
CFLAGS+=-L../../config -lrz_config
|
||||
CFLAGS+=-L../../anal -lrz_anal -L../../egg -lrz_egg -L../../flag -lrz_flag
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ static int rz_core_rtr_http_run(RzCore *core, int launch, int browse, const char
|
|||
}
|
||||
eprintf ("Starting http server...\n");
|
||||
eprintf ("open http://%s:%d/\n", host, atoi (port));
|
||||
eprintf ("r2 -C http://%s:%d/cmd/\n", host, atoi (port));
|
||||
eprintf ("rizin -C http://%s:%d/cmd/\n", host, atoi (port));
|
||||
core->http_up = true;
|
||||
|
||||
ut64 newoff, origoff = core->offset;
|
||||
|
|
|
|||
|
|
@ -2151,11 +2151,6 @@ RZ_API void rz_core_visual_browse(RzCore *core, const char *input) {
|
|||
case '1':
|
||||
rz_core_visual_bit_editor (core);
|
||||
break;
|
||||
case 'M':
|
||||
if (!rz_list_empty (core->fs->roots)) {
|
||||
rz_core_visual_mounts (core);
|
||||
}
|
||||
break;
|
||||
case 'z': // "vbz"
|
||||
if (rz_core_visual_view_zigns (core)) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -2481,328 +2481,6 @@ RZ_API void rz_core_visual_config(RzCore *core) {
|
|||
}
|
||||
}
|
||||
|
||||
RZ_API void rz_core_visual_mounts(RzCore *core) {
|
||||
RzList *list = NULL;
|
||||
RzFSRoot *fsroot = NULL;
|
||||
RzListIter *iter;
|
||||
RzFSFile *file;
|
||||
RzFSPartition *part;
|
||||
int i, ch, option, mode, partition, dir, delta = 7;
|
||||
char *str, path[4096], buf[1024], *root = NULL;
|
||||
const char *n, *p;
|
||||
|
||||
dir = partition = option = mode = 0;
|
||||
for (;;) {
|
||||
/* Clear */
|
||||
rz_cons_clear00 ();
|
||||
|
||||
/* Show */
|
||||
if (mode == 0) {
|
||||
if (list) {
|
||||
rz_list_free (list);
|
||||
list = NULL;
|
||||
}
|
||||
rz_cons_printf ("Press '/' to navigate the root filesystem.\nPartitions:\n\n");
|
||||
n = rz_fs_partition_type_get (partition);
|
||||
list = rz_fs_partitions (core->fs, n, 0);
|
||||
i = 0;
|
||||
if (list) {
|
||||
rz_list_foreach (list, iter, part) {
|
||||
if ((option-delta <= i) && (i <= option+delta)) {
|
||||
if (option == i) {
|
||||
rz_cons_printf (" > ");
|
||||
} else {
|
||||
rz_cons_printf (" ");
|
||||
}
|
||||
rz_cons_printf ("%d %02x 0x%010"PFMT64x" 0x%010"PFMT64x"\n",
|
||||
part->number, part->type,
|
||||
part->start, part->start+part->length);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
rz_list_free (list);
|
||||
list = NULL;
|
||||
} else {
|
||||
rz_cons_printf ("Cannot read partition\n");
|
||||
}
|
||||
} else if (mode == 1) {
|
||||
rz_cons_printf ("Types:\n\n");
|
||||
for (i=0;;i++) {
|
||||
n = rz_fs_partition_type_get (i);
|
||||
if (!n) {
|
||||
break;
|
||||
}
|
||||
rz_cons_printf ("%s%s\n", (i==partition)?" > ":" ", n);
|
||||
}
|
||||
} else if (mode == 3) {
|
||||
i = 0;
|
||||
rz_cons_printf ("Mountpoints:\n\n");
|
||||
rz_list_foreach (core->fs->roots, iter, fsroot) {
|
||||
if (fsroot && (option-delta <= i) && (i <= option+delta)) {
|
||||
rz_cons_printf ("%s %s\n", (option == i)?" > ":" ",
|
||||
fsroot->path);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
if (root) {
|
||||
list = rz_fs_dir (core->fs, path);
|
||||
if (list) {
|
||||
rz_cons_printf ("%s:\n\n", path);
|
||||
i = 0;
|
||||
rz_list_foreach (list, iter, file) {
|
||||
if ((dir-delta <= i) && (i <= dir+delta)) {
|
||||
rz_cons_printf ("%s%c %s\n", (dir == i)?" > ":" ",
|
||||
file->type, file->name);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
rz_cons_printf ("\n");
|
||||
rz_list_free (list);
|
||||
list = NULL;
|
||||
} else {
|
||||
rz_cons_printf ("Cannot open '%s' directory\n", root);
|
||||
}
|
||||
} else {
|
||||
rz_cons_printf ("Root undefined\n");
|
||||
}
|
||||
}
|
||||
if (mode==2) {
|
||||
rz_str_trim_path (path);
|
||||
str = path + strlen (path);
|
||||
strncat (path, "/", sizeof (path)-strlen (path)-1);
|
||||
list = rz_fs_dir (core->fs, path);
|
||||
file = rz_list_get_n (list, dir);
|
||||
if (file && file->type != 'd') {
|
||||
rz_core_cmdf (core, "px @ 0x%" PFMT64x "!64", file->off);
|
||||
}
|
||||
rz_list_free (list);
|
||||
list = NULL;
|
||||
*str='\0';
|
||||
}
|
||||
rz_cons_flush ();
|
||||
|
||||
/* Ask for option */
|
||||
ch = rz_cons_readchar ();
|
||||
if (ch==-1||ch==4){
|
||||
free (root);
|
||||
return;
|
||||
}
|
||||
ch = rz_cons_arrow_to_hjkl (ch);
|
||||
switch (ch) {
|
||||
case '/':
|
||||
R_FREE (root);
|
||||
root = strdup ("/");
|
||||
strncpy (path, root, sizeof (path)-1);
|
||||
mode = 2;
|
||||
break;
|
||||
case 'l':
|
||||
case '\r':
|
||||
case '\n':
|
||||
if (mode == 0) {
|
||||
n = rz_fs_partition_type_get (partition);
|
||||
list = rz_fs_partitions (core->fs, n, 0);
|
||||
if (!list) {
|
||||
rz_cons_printf ("Unknown partition\n");
|
||||
rz_cons_any_key (NULL);
|
||||
rz_cons_flush ();
|
||||
break;
|
||||
}
|
||||
part = rz_list_get_n (list, option);
|
||||
if (!part) {
|
||||
rz_cons_printf ("Unknown partition\n");
|
||||
rz_cons_any_key (NULL);
|
||||
rz_cons_flush ();
|
||||
break;
|
||||
}
|
||||
p = rz_fs_partition_type (n, part->type);
|
||||
if (p) {
|
||||
if (rz_fs_mount (core->fs, p, "/root", part->start)) {
|
||||
free (root);
|
||||
root = strdup ("/root");
|
||||
strncpy (path, root, sizeof (path)-1);
|
||||
mode = 2;
|
||||
} else {
|
||||
rz_cons_printf ("Cannot mount partition\n");
|
||||
rz_cons_flush ();
|
||||
rz_cons_any_key (NULL);
|
||||
}
|
||||
} else {
|
||||
rz_cons_printf ("Unknown partition type\n");
|
||||
rz_cons_flush ();
|
||||
rz_cons_any_key (NULL);
|
||||
}
|
||||
rz_list_free (list);
|
||||
list = NULL;
|
||||
} else if (mode == 2){
|
||||
rz_str_trim_path (path);
|
||||
strncat (path, "/", sizeof (path)-strlen (path)-1);
|
||||
list = rz_fs_dir (core->fs, path);
|
||||
file = rz_list_get_n (list, dir);
|
||||
if (file) {
|
||||
if (file->type == 'd') {
|
||||
strncat (path, file->name, sizeof (path)-strlen (path)-1);
|
||||
rz_str_trim_path (path);
|
||||
if (root && strncmp (root, path, strlen (root) - 1)) {
|
||||
strncpy (path, root, sizeof (path) - 1);
|
||||
}
|
||||
} else {
|
||||
rz_core_cmdf (core, "s 0x%"PFMT64x, file->off);
|
||||
rz_fs_umount (core->fs, root);
|
||||
free (root);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
rz_cons_printf ("Unknown file\n");
|
||||
rz_cons_flush ();
|
||||
rz_cons_any_key (NULL);
|
||||
}
|
||||
|
||||
} else if (mode == 3) {
|
||||
fsroot = rz_list_get_n (core->fs->roots, option);
|
||||
if (fsroot) {
|
||||
root = strdup (fsroot->path);
|
||||
strncpy (path, root, sizeof (path)-1);
|
||||
}
|
||||
mode = 2;
|
||||
}
|
||||
dir = partition = option = 0;
|
||||
break;
|
||||
case 'k':
|
||||
if (mode == 0 || mode == 3) {
|
||||
if (option > 0) {
|
||||
option--;
|
||||
}
|
||||
} else if (mode == 1) {
|
||||
if (partition > 0) {
|
||||
partition--;
|
||||
}
|
||||
} else {
|
||||
if (dir > 0) {
|
||||
dir--;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'j':
|
||||
if (mode == 0) {
|
||||
n = rz_fs_partition_type_get (partition);
|
||||
list = rz_fs_partitions (core->fs, n, 0);
|
||||
if (option < rz_list_length (list) - 1) {
|
||||
option++;
|
||||
}
|
||||
} else if (mode == 1) {
|
||||
if (partition < rz_fs_partition_get_size () - 1) {
|
||||
partition++;
|
||||
}
|
||||
} else if (mode == 3) {
|
||||
if (option < rz_list_length (core->fs->roots) - 1) {
|
||||
option++;
|
||||
}
|
||||
} else {
|
||||
list = rz_fs_dir (core->fs, path);
|
||||
if (dir < rz_list_length (list) - 1) {
|
||||
dir++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
mode = 1;
|
||||
break;
|
||||
case 'h':
|
||||
if (mode == 2) {
|
||||
if (!root) {
|
||||
mode = 0;
|
||||
} else
|
||||
if (strcmp (path, root)) {
|
||||
strcat (path, "/..");
|
||||
rz_str_trim_path (path);
|
||||
} else {
|
||||
rz_fs_umount (core->fs, root);
|
||||
mode = 0;
|
||||
}
|
||||
} else if (mode == 1) {
|
||||
mode = 0;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 'Q':
|
||||
case 'q':
|
||||
if (mode == 2 && root) {
|
||||
rz_fs_umount (core->fs, root);
|
||||
mode = 0;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case 'g':
|
||||
if (mode == 2) {
|
||||
rz_str_trim_path (path);
|
||||
str = path + strlen (path);
|
||||
strncat (path, "/", sizeof (path)-strlen (path)-1);
|
||||
list = rz_fs_dir (core->fs, path);
|
||||
file = rz_list_get_n (list, dir);
|
||||
if (file && root) {
|
||||
strncat (path, file->name, sizeof (path)-strlen (path)-1);
|
||||
rz_str_trim_path (path);
|
||||
if (strncmp (root, path, strlen (root) - 1)) {
|
||||
strncpy (path, root, sizeof (path) - 1);
|
||||
}
|
||||
file = rz_fs_open (core->fs, path, false);
|
||||
if (file) {
|
||||
rz_fs_read (core->fs, file, 0, file->size);
|
||||
rz_cons_show_cursor (true);
|
||||
rz_cons_set_raw (0);
|
||||
rz_line_set_prompt ("Dump path (ej: /tmp/file): ");
|
||||
rz_cons_fgets (buf, sizeof (buf), 0, 0);
|
||||
rz_cons_set_raw (1);
|
||||
rz_cons_show_cursor (false);
|
||||
rz_file_dump (buf, file->data, file->size, 0);
|
||||
rz_fs_close (core->fs, file);
|
||||
rz_cons_printf ("Done\n");
|
||||
} else {
|
||||
rz_cons_printf ("Cannot dump file\n");
|
||||
}
|
||||
} else {
|
||||
rz_cons_printf ("Cannot dump file\n");
|
||||
}
|
||||
rz_cons_flush ();
|
||||
rz_cons_any_key (NULL);
|
||||
*str='\0';
|
||||
}
|
||||
break;
|
||||
case 'm':
|
||||
mode = 3;
|
||||
option = 0;
|
||||
break;
|
||||
case '?':
|
||||
rz_cons_clear00 ();
|
||||
rz_cons_printf ("\nVM: Visual Mount points help:\n\n");
|
||||
rz_cons_printf (" q - go back or quit menu\n");
|
||||
rz_cons_printf (" j/k - down/up keys\n");
|
||||
rz_cons_printf (" h/l - forward/go keys\n");
|
||||
rz_cons_printf (" t - choose partition type\n");
|
||||
rz_cons_printf (" g - dump file\n");
|
||||
rz_cons_printf (" m - show mountpoints\n");
|
||||
rz_cons_printf (" : - enter command\n");
|
||||
rz_cons_printf (" ? - show this help\n");
|
||||
rz_cons_flush ();
|
||||
rz_cons_any_key (NULL);
|
||||
break;
|
||||
case ':':
|
||||
rz_cons_show_cursor (true);
|
||||
rz_cons_set_raw (0);
|
||||
rz_line_set_prompt (":> ");
|
||||
rz_cons_fgets (buf, sizeof (buf), 0, 0);
|
||||
rz_cons_set_raw (1);
|
||||
rz_cons_show_cursor (false);
|
||||
rz_core_cmd (core, buf, 1);
|
||||
rz_cons_any_key (NULL);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// helper
|
||||
static void function_rename(RzCore *core, ut64 addr, const char *name) {
|
||||
RzListIter *iter;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
LIBS="librz/cons/librz_cons.a librz/util/librz_util.a librz/bin/librz_bin.a librz/anal/librz_anal.a librz/bp/librz_bp.a librz/hash/librz_hash.a librz/debug/librz_debug.a shlr/sdb/src/libsdb.a librz/core/librz_core.a librz/main/librz_main.a librz/fs/librz_fs.a librz/syscall/librz_syscall.a shlr/java/librz_java.a shlr/zip/librz.a librz/socket/librz_socket.a librz/anal/librz_anal.a librz/flag/librz_flag.a librz/search/librz_search.a librz/reg/librz_reg.a librz/config/librz_config.a librz/io/librz_io.a librz/parse/librz_parse.a librz/bp/librz_bp.a librz/asm/librz_asm.a librz/bp/librz_bp.a librz/egg/librz_egg.a librz/anal/librz_anal.a librz/magic/librz_magic.a librz/lang/librz_lang.a librz/fs/librz_fs.a shlr/grub/libgrubfs.a shlr/capstone/libcapstone.a shlr/gdb/lib/libgdbr.a shlr/tree-sitter/libtree-sitter.a shlr/rizin-shell-parser/libshell-parser.a"
|
||||
LIBS="librz/cons/librz_cons.a librz/util/librz_util.a librz/bin/librz_bin.a librz/anal/librz_anal.a librz/bp/librz_bp.a librz/hash/librz_hash.a librz/debug/librz_debug.a shlr/sdb/src/libsdb.a librz/core/librz_core.a librz/main/librz_main.a librz/syscall/librz_syscall.a shlr/java/librz_java.a shlr/zip/librz.a librz/socket/librz_socket.a librz/anal/librz_anal.a librz/flag/librz_flag.a librz/search/librz_search.a librz/reg/librz_reg.a librz/config/librz_config.a librz/io/librz_io.a librz/parse/librz_parse.a librz/bp/librz_bp.a librz/asm/librz_asm.a librz/bp/librz_bp.a librz/egg/librz_egg.a librz/anal/librz_anal.a librz/magic/librz_magic.a librz/lang/librz_lang.a shlr/capstone/libcapstone.a shlr/gdb/lib/libgdbr.a shlr/tree-sitter/libtree-sitter.a shlr/rizin-shell-parser/libshell-parser.a"
|
||||
cd ..
|
||||
|
||||
LIB=librz.a
|
||||
|
|
|
|||
|
|
@ -1,44 +0,0 @@
|
|||
NAME=rz_fs
|
||||
R2DEPS=rz_util rz_io rz_socket
|
||||
CFLAGS+=-DR2_PLUGIN_INCORE -Iarch/include -Iarch
|
||||
|
||||
SHLR=../../shlr/
|
||||
|
||||
include ../config.mk
|
||||
CFLAGS+=-I$(SHLR)/grub/include
|
||||
ifeq ($(WITH_GPL),1)
|
||||
LDFLAGS+=$(SHLR)/grub/libgrubfs.a
|
||||
endif
|
||||
|
||||
EXTRA_TARGETS=plugins
|
||||
foo:
|
||||
for TARGET in pre plugins ${LIBSO} ${LIBAR} ; do ${MAKE} $$TARGET ; done
|
||||
|
||||
include ${STATIC_FS_PLUGINS}
|
||||
STATIC_OBJS=$(subst ..,p/..,$(subst fs_,p/fs_,$(STATIC_OBJ)))
|
||||
OBJS=${STATIC_OBJS} fs.o fs_file.o shell.o
|
||||
#p/grub/main.o
|
||||
|
||||
#p/grub/libgrubfs.a:
|
||||
# cd p/grub && ${MAKE} libgrubfs.a CC="${CC}"
|
||||
|
||||
pre:
|
||||
cd d && ${MAKE}
|
||||
# @if [ ! -e librz_fs.${EXT_SO} ]; then if [ ! -e librz_fs.${EXT_AR} ]; then rm -f ${STATIC_OBJS} ; fi ; fi
|
||||
|
||||
re:
|
||||
rm -f fs.o librz_fs.so
|
||||
${MAKE}
|
||||
rm -f t/fastcall.o
|
||||
sudo ${MAKE} install
|
||||
cd t && ${MAKE}
|
||||
|
||||
test:
|
||||
#valgrind r2 -i test.rsc /tmp/test.fs.img
|
||||
gdb --args r2 -i test.rsc /tmp/test.fs.img
|
||||
|
||||
plugins:
|
||||
#cd p/grub && ${MAKE} libgrubfs.a CC="${CC}"
|
||||
cd p && ${MAKE} all
|
||||
|
||||
include ../rules.mk
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
include ../../../global.mk
|
||||
|
||||
# this bin should be created by make -C shlr/Makefile sdb/sdb
|
||||
SDB=$(STOP)/sdb/sdb
|
||||
DBS=dospart.sdb
|
||||
|
||||
all: $(DBS)
|
||||
|
||||
%.sdb:% ${SDB}
|
||||
@echo " SDB $<"
|
||||
@-${SDB} $<.sdb = < $<
|
||||
@test -f $<.sdb
|
||||
|
||||
clean:
|
||||
rm -f *.sdb
|
||||
|
||||
$(SDB):
|
||||
@echo "Cannot find sdb/sdb"
|
||||
@false
|
||||
|
||||
# cp -rf $(STOP)/sdb/src $(STOP)/sdb/src-native
|
||||
# cd $(STOP)/sdb/src-native && ${MAKE} -j 1 ARCH=xxx CC=gcc clean sdb
|
||||
# cp -f $(STOP)/sdb/src-native/sdb $(SDB)
|
||||
# rm -rf $(STOP)/sdb/src-native
|
||||
|
||||
.PHONY: all clean
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
# http://www.win.tue.nl/~aeb/partitions/partition_types-1.html
|
||||
0=empty
|
||||
1.fs=fat
|
||||
1=DOS 12-bit FAT
|
||||
2=XENIX root
|
||||
3=XENIX /usr
|
||||
4.fs=fat
|
||||
4=DOS 3.0+ 16-bit FAT (up to 32M)
|
||||
5.fs=fat
|
||||
5=DOS 3.0+ extended partition
|
||||
6.fs=fat
|
||||
6=DOS 3.0+ 16-bit FAT (over 32M)
|
||||
7.fs=ntfs
|
||||
7=Window NTFS / exFAT / QNX
|
||||
11.fs=fat
|
||||
11=WIN95 OSR2 FAT32
|
||||
12.fs=fat
|
||||
12=WIN95 OSR2 FAT32, LBA
|
||||
...
|
||||
130=Linux swap
|
||||
131.fs=ext2
|
||||
131=Linux native partition
|
||||
...
|
||||
166=OpenBSD
|
||||
167=NeXTStep
|
||||
168=Mac OS-X
|
||||
169=NetBSD
|
||||
171=Mac OS-X Boot partition
|
||||
175=Mac OS-X HFS
|
||||
716
librz/fs/fs.c
716
librz/fs/fs.c
|
|
@ -1,716 +0,0 @@
|
|||
/* rizin - LGPL - Copyright 2011-2019 - pancake */
|
||||
|
||||
#include <rz_fs.h>
|
||||
#include "config.h"
|
||||
#include "types.h"
|
||||
#include <errno.h>
|
||||
#include "../../shlr/grub/include/grub/msdos_partition.h"
|
||||
|
||||
#if WITH_GPL
|
||||
# ifndef USE_GRUB
|
||||
# define USE_GRUB 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
R_LIB_VERSION (rz_fs);
|
||||
|
||||
static RzFSPlugin* fs_static_plugins[] = {
|
||||
R_FS_STATIC_PLUGINS
|
||||
};
|
||||
|
||||
RZ_API RzFS* rz_fs_new(void) {
|
||||
int i;
|
||||
RzFSPlugin* static_plugin;
|
||||
RzFS* fs = R_NEW0 (RzFS);
|
||||
if (fs) {
|
||||
fs->view = R_FS_VIEW_NORMAL;
|
||||
fs->roots = rz_list_new ();
|
||||
if (!fs->roots) {
|
||||
rz_fs_free (fs);
|
||||
return NULL;
|
||||
}
|
||||
fs->roots->free = (RzListFree) rz_fs_root_free;
|
||||
fs->plugins = rz_list_new ();
|
||||
if (!fs->plugins) {
|
||||
rz_fs_free (fs);
|
||||
return NULL;
|
||||
}
|
||||
fs->plugins->free = free;
|
||||
// XXX fs->roots->free = rz_fs_plugin_free;
|
||||
for (i = 0; fs_static_plugins[i]; i++) {
|
||||
static_plugin = R_NEW (RzFSPlugin);
|
||||
if (!static_plugin) {
|
||||
continue;
|
||||
}
|
||||
memcpy (static_plugin, fs_static_plugins[i], sizeof (RzFSPlugin));
|
||||
rz_fs_add (fs, static_plugin);
|
||||
free (static_plugin);
|
||||
}
|
||||
}
|
||||
return fs;
|
||||
}
|
||||
|
||||
RZ_API RzFSPlugin* rz_fs_plugin_get(RzFS* fs, const char* name) {
|
||||
RzListIter* iter;
|
||||
RzFSPlugin* p;
|
||||
if (!fs || !name) {
|
||||
return NULL;
|
||||
}
|
||||
rz_list_foreach (fs->plugins, iter, p) {
|
||||
if (!strcmp (p->name, name)) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RZ_API void rz_fs_free(RzFS* fs) {
|
||||
if (!fs) {
|
||||
return;
|
||||
}
|
||||
//rz_io_free (fs->iob.io);
|
||||
//root makes use of plugin so revert to avoid UaF
|
||||
rz_list_free (fs->roots);
|
||||
rz_list_free (fs->plugins);
|
||||
free (fs);
|
||||
}
|
||||
|
||||
/* plugins */
|
||||
RZ_API void rz_fs_add(RzFS* fs, RzFSPlugin* p) {
|
||||
// TODO: find coliding plugin name
|
||||
if (p && p->init) {
|
||||
p->init ();
|
||||
}
|
||||
RzFSPlugin* sp = R_NEW0 (RzFSPlugin);
|
||||
if (sp) {
|
||||
if (p) {
|
||||
memcpy (sp, p, sizeof (RzFSPlugin));
|
||||
}
|
||||
rz_list_append (fs->plugins, sp);
|
||||
}
|
||||
}
|
||||
|
||||
RZ_API void rz_fs_del(RzFS* fs, RzFSPlugin* p) {
|
||||
// TODO: implement rz_fs_del
|
||||
}
|
||||
|
||||
/* mountpoint */
|
||||
RZ_API RzFSRoot* rz_fs_mount(RzFS* fs, const char* fstype, const char* path, ut64 delta) {
|
||||
RzFSPlugin* p;
|
||||
RzFSRoot* root;
|
||||
RzListIter* iter;
|
||||
char* str;
|
||||
int len, lenstr;
|
||||
char *heapFsType = NULL;
|
||||
|
||||
if (path[0] != '/') {
|
||||
eprintf ("rz_fs_mount: invalid mountpoint %s\n", path);
|
||||
return NULL;
|
||||
}
|
||||
if (!fstype || !*fstype) {
|
||||
heapFsType = rz_fs_name (fs, delta);
|
||||
fstype = (const char *)heapFsType;
|
||||
}
|
||||
if (!(p = rz_fs_plugin_get (fs, fstype))) {
|
||||
// eprintf ("rz_fs_mount: Invalid filesystem type\n");
|
||||
free (heapFsType);
|
||||
return NULL;
|
||||
}
|
||||
str = strdup (path);
|
||||
if (!str) {
|
||||
free (heapFsType);
|
||||
return NULL;
|
||||
}
|
||||
rz_str_trim_path (str);
|
||||
if (*str && strchr (str + 1, '/')) {
|
||||
eprintf ("rz_fs_mount: mountpoint must have no subdirectories\n");
|
||||
free (heapFsType);
|
||||
return NULL;
|
||||
}
|
||||
/* Check if path exists */
|
||||
rz_list_foreach (fs->roots, iter, root) {
|
||||
len = strlen (root->path);
|
||||
lenstr = strlen (str);
|
||||
if (!strncmp (str, root->path, len)) {
|
||||
if (len < lenstr && str[len] != '/') {
|
||||
continue;
|
||||
}
|
||||
if (len > lenstr && root->path[lenstr] == '/') {
|
||||
continue;
|
||||
}
|
||||
eprintf ("rz_fs_mount: Invalid mount point\n");
|
||||
free (str);
|
||||
free (heapFsType);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
RzFSFile* file = rz_fs_open (fs, str, false);
|
||||
if (file) {
|
||||
rz_fs_close (fs, file);
|
||||
eprintf ("rz_fs_mount: Invalid mount point\n");
|
||||
free (heapFsType);
|
||||
free (str);
|
||||
return NULL;
|
||||
}
|
||||
RzList *list = rz_fs_dir (fs, str);
|
||||
if (!rz_list_empty (list)) {
|
||||
//XXX: list need free ??
|
||||
eprintf ("rz_fs_mount: Invalid mount point\n");
|
||||
free (str);
|
||||
free (heapFsType);
|
||||
return NULL;
|
||||
}
|
||||
// TODO: we should just construct the root with the rfs instance
|
||||
root = rz_fs_root_new (str, delta);
|
||||
root->p = p;
|
||||
root->iob = fs->iob;
|
||||
root->cob = fs->cob;
|
||||
if (!p->mount (root)) {
|
||||
free (str);
|
||||
free (heapFsType);
|
||||
rz_fs_root_free (root);
|
||||
return NULL;
|
||||
}
|
||||
rz_list_append (fs->roots, root);
|
||||
eprintf ("Mounted %s on %s at 0x%" PFMT64x "\n", fstype, str, delta);
|
||||
free (str);
|
||||
free (heapFsType);
|
||||
return root;
|
||||
}
|
||||
|
||||
static inline bool rz_fs_match(const char* root, const char* path, int len) {
|
||||
return (!strncmp (path, root, len));
|
||||
}
|
||||
|
||||
RZ_API bool rz_fs_umount(RzFS* fs, const char* path) {
|
||||
int len;
|
||||
RzFSRoot* root;
|
||||
RzListIter* iter, * riter = NULL;
|
||||
|
||||
if (!path) {
|
||||
return false;
|
||||
}
|
||||
|
||||
rz_list_foreach (fs->roots, iter, root) {
|
||||
len = strlen (root->path);
|
||||
if (rz_fs_match (path, root->path, len)) {
|
||||
riter = iter;
|
||||
}
|
||||
}
|
||||
if (riter) {
|
||||
rz_list_delete (fs->roots, riter);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RZ_API RzList* rz_fs_root(RzFS* fs, const char* p) {
|
||||
RzList* roots;
|
||||
RzFSRoot* root;
|
||||
RzListIter* iter;
|
||||
int len, olen;
|
||||
char* path = strdup (p);
|
||||
if (!path) {
|
||||
return NULL;
|
||||
}
|
||||
roots = rz_list_new ();
|
||||
rz_str_trim_path (path);
|
||||
rz_list_foreach (fs->roots, iter, root) {
|
||||
len = strlen (root->path);
|
||||
if (rz_fs_match (path, root->path, len)) {
|
||||
olen = strlen (path);
|
||||
if (len == 1 || olen == len) {
|
||||
rz_list_append (roots, root);
|
||||
} else if (olen > len && path[len] == '/') {
|
||||
rz_list_append (roots, root);
|
||||
}
|
||||
}
|
||||
}
|
||||
free (path);
|
||||
return roots;
|
||||
}
|
||||
|
||||
/* filez */
|
||||
RZ_API RzFSFile* rz_fs_open(RzFS* fs, const char* p, bool create) {
|
||||
RzFSRoot* root;
|
||||
RzListIter* iter;
|
||||
RzFSFile* f = NULL;
|
||||
const char* dir;
|
||||
char* path = rz_str_trim_dup (p);
|
||||
RzList *roots = rz_fs_root (fs, path);
|
||||
if (!rz_list_empty (roots)) {
|
||||
rz_list_foreach (roots, iter, root) {
|
||||
if (create) {
|
||||
if (root && root->p && root->p->write) {
|
||||
f = rz_fs_file_new (root, path + strlen (root->path));
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (root && root->p && root->p->open) {
|
||||
if (strlen (root->path) == 1) {
|
||||
dir = path;
|
||||
} else {
|
||||
dir = path + strlen (root->path);
|
||||
}
|
||||
f = root->p->open (root, dir, false);
|
||||
if (f) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
free (roots);
|
||||
free (path);
|
||||
return f;
|
||||
}
|
||||
|
||||
// NOTE: close doesnt free
|
||||
RZ_API void rz_fs_close(RzFS* fs, RzFSFile* file) {
|
||||
if (fs && file) {
|
||||
R_FREE (file->data);
|
||||
if (file->p && file->p->close) {
|
||||
file->p->close (file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RZ_API int rz_fs_write(RzFS* fs, RzFSFile* file, ut64 addr, const ut8 *data, int len) {
|
||||
if (len < 1) {
|
||||
return false;
|
||||
}
|
||||
if (fs && file) {
|
||||
// TODO: fill file->data ? looks like dupe of rbuffer
|
||||
if (file->p && file->p->write) {
|
||||
file->p->write (file, addr, data, len);
|
||||
return true;
|
||||
}
|
||||
eprintf ("rz_fs_write: file->p->write is null\n");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RZ_API int rz_fs_read(RzFS* fs, RzFSFile* file, ut64 addr, int len) {
|
||||
if (len < 1) {
|
||||
eprintf ("rz_fs_read: too short read\n");
|
||||
return false;
|
||||
}
|
||||
if (fs && file) {
|
||||
if (file->p && file->p->read) {
|
||||
if (!file->data) {
|
||||
free (file->data);
|
||||
file->data = calloc (1, len + 1);
|
||||
}
|
||||
file->p->read (file, addr, len);
|
||||
return true;
|
||||
} else {
|
||||
eprintf ("rz_fs_read: file->p->read is null\n");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RZ_API RzList* rz_fs_dir(RzFS* fs, const char* p) {
|
||||
RzList *ret = NULL;
|
||||
RzFSRoot* root;
|
||||
RzListIter* iter;
|
||||
const char* dir;
|
||||
char* path = strdup (p);
|
||||
rz_str_trim_path (path);
|
||||
RzList *roots = rz_fs_root (fs, path);
|
||||
rz_list_foreach (roots, iter, root) {
|
||||
if (root) {
|
||||
if (strlen (root->path) == 1) {
|
||||
dir = path;
|
||||
} else {
|
||||
dir = path + strlen (root->path);
|
||||
}
|
||||
if (!*dir) {
|
||||
dir = "/";
|
||||
}
|
||||
ret = root->p->dir (root, dir, fs->view);
|
||||
if (ret) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
free (roots);
|
||||
free (path);
|
||||
return ret;
|
||||
}
|
||||
|
||||
RZ_API int rz_fs_dir_dump(RzFS* fs, const char* path, const char* name) {
|
||||
RzList* list;
|
||||
RzListIter* iter;
|
||||
RzFSFile* file, * item;
|
||||
char* str, * npath;
|
||||
|
||||
list = rz_fs_dir (fs, path);
|
||||
if (!list) {
|
||||
return false;
|
||||
}
|
||||
if (!rz_sys_mkdir (name)) {
|
||||
if (rz_sys_mkdir_failed ()) {
|
||||
eprintf ("Cannot create \"%s\"\n", name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
rz_list_foreach (list, iter, file) {
|
||||
if (!strcmp (file->name, ".") || !strcmp (file->name, "..")) {
|
||||
continue;
|
||||
}
|
||||
str = (char*) malloc (strlen (name) + strlen (file->name) + 2);
|
||||
if (!str) {
|
||||
return false;
|
||||
}
|
||||
strcpy (str, name);
|
||||
strcat (str, "/");
|
||||
strcat (str, file->name);
|
||||
npath = malloc (strlen (path) + strlen (file->name) + 2);
|
||||
if (!npath) {
|
||||
free (str);
|
||||
return false;
|
||||
}
|
||||
strcpy (npath, path);
|
||||
strcat (npath, "/");
|
||||
strcat (npath, file->name);
|
||||
switch (file->type) {
|
||||
// DON'T FOLLOW MOUNTPOINTS
|
||||
case R_FS_FILE_TYPE_DIRECTORY:
|
||||
if (!rz_fs_dir_dump (fs, npath, str)) {
|
||||
free (npath);
|
||||
free (str);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case R_FS_FILE_TYPE_REGULAR:
|
||||
item = rz_fs_open (fs, npath, false);
|
||||
if (item) {
|
||||
rz_fs_read (fs, item, 0, item->size);
|
||||
if (!rz_file_dump (str, item->data, item->size, 0)) {
|
||||
free (npath);
|
||||
free (str);
|
||||
return false;
|
||||
}
|
||||
rz_fs_close (fs, item);
|
||||
}
|
||||
break;
|
||||
}
|
||||
free (npath);
|
||||
free (str);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void rz_fs_find_off_aux(RzFS* fs, const char* name, ut64 offset, RzList* list) {
|
||||
RzList* dirs;
|
||||
RzListIter* iter;
|
||||
RzFSFile* item, * file;
|
||||
char* found = NULL;
|
||||
|
||||
dirs = rz_fs_dir (fs, name);
|
||||
rz_list_foreach (dirs, iter, item) {
|
||||
if (!strcmp (item->name, ".") || !strcmp (item->name, "..")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
found = (char*) malloc (strlen (name) + strlen (item->name) + 2);
|
||||
if (!found) {
|
||||
break;
|
||||
}
|
||||
strcpy (found, name);
|
||||
strcat (found, "/");
|
||||
strcat (found, item->name);
|
||||
|
||||
if (item->type == R_FS_FILE_TYPE_DIRECTORY) {
|
||||
rz_fs_find_off_aux (fs, found, offset, list);
|
||||
} else {
|
||||
file = rz_fs_open (fs, found, false);
|
||||
if (file) {
|
||||
rz_fs_read (fs, file, 0, file->size);
|
||||
if (file->off == offset) {
|
||||
rz_list_append (list, found);
|
||||
}
|
||||
rz_fs_close (fs, file);
|
||||
}
|
||||
}
|
||||
free (found);
|
||||
}
|
||||
}
|
||||
|
||||
RZ_API RzList* rz_fs_find_off(RzFS* fs, const char* name, ut64 off) {
|
||||
RzList* list = rz_list_new ();
|
||||
if (!list) {
|
||||
return NULL;
|
||||
}
|
||||
list->free = free;
|
||||
rz_fs_find_off_aux (fs, name, off, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
static void rz_fs_find_name_aux(RzFS* fs, const char* name, const char* glob, RzList* list) {
|
||||
RzList* dirs;
|
||||
RzListIter* iter;
|
||||
RzFSFile* item;
|
||||
char* found;
|
||||
|
||||
dirs = rz_fs_dir (fs, name);
|
||||
rz_list_foreach (dirs, iter, item) {
|
||||
if (rz_str_glob (item->name, glob)) {
|
||||
found = (char*) malloc (strlen (name) + strlen (item->name) + 2);
|
||||
if (!found) {
|
||||
break;
|
||||
}
|
||||
strcpy (found, name);
|
||||
strcat (found, "/");
|
||||
strcat (found, item->name);
|
||||
rz_list_append (list, found);
|
||||
}
|
||||
if (!strcmp (item->name, ".") || !strcmp (item->name, "..")) {
|
||||
continue;
|
||||
}
|
||||
if (item->type == R_FS_FILE_TYPE_DIRECTORY) {
|
||||
found = (char*) malloc (strlen (name) + strlen (item->name) + 2);
|
||||
if (!found) {
|
||||
break;
|
||||
}
|
||||
strcpy (found, name);
|
||||
strcat (found, "/");
|
||||
strcat (found, item->name);
|
||||
rz_fs_find_name_aux (fs, found, glob, list);
|
||||
free (found);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RZ_API RzList* rz_fs_find_name(RzFS* fs, const char* name, const char* glob) {
|
||||
RzList* list = rz_list_newf (free);
|
||||
if (list) {
|
||||
rz_fs_find_name_aux (fs, name, glob, list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
RZ_API RzFSFile* rz_fs_slurp(RzFS* fs, const char* path) {
|
||||
RzFSFile* file = NULL;
|
||||
RzFSRoot* root;
|
||||
RzList* roots = rz_fs_root (fs, path);
|
||||
RzListIter* iter;
|
||||
rz_list_foreach (roots, iter, root) {
|
||||
if (!root || !root->p) {
|
||||
continue;
|
||||
}
|
||||
if (root->p->open && root->p->read && root->p->close) {
|
||||
file = root->p->open (root, path, false);
|
||||
if (file) {
|
||||
root->p->read (file, 0, file->size); //file->data
|
||||
}else {
|
||||
eprintf ("rz_fs_slurp: cannot open file\n");
|
||||
}
|
||||
} else {
|
||||
if (root->p->slurp) {
|
||||
free (roots);
|
||||
return root->p->slurp (root, path);
|
||||
}
|
||||
eprintf ("rz_fs_slurp: null root->p->slurp\n");
|
||||
}
|
||||
}
|
||||
free (roots);
|
||||
return file;
|
||||
}
|
||||
|
||||
// TODO: move into grubfs
|
||||
#include "../../shlr/grub/include/grubfs.h"
|
||||
|
||||
#if USE_GRUB
|
||||
static int grub_parhook(void* disk, void* ptr, void* closure) {
|
||||
struct grub_partition* par = ptr;
|
||||
RzList* list = (RzList*) closure;
|
||||
RzFSPartition* p = rz_fs_partition_new (
|
||||
rz_list_length (list),
|
||||
par->start * 512, 512 * par->len);
|
||||
p->type = par->msdostype;
|
||||
rz_list_append (list, p);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int fs_parhook(void* disk, void* ptr, void* closure) {
|
||||
RzFSPartition* par = ptr;
|
||||
RzList* list = (RzList*) closure;
|
||||
rz_list_append (list, par);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include "p/part_dos.c"
|
||||
|
||||
static RzFSPartitionType partitions[] = {
|
||||
/* LGPL code */
|
||||
{"dos", &fs_part_dos, fs_parhook},
|
||||
#if USE_GRUB
|
||||
/* WARNING GPL code */
|
||||
#if !__EMSCRIPTEN__
|
||||
// wtf for some reason is not available on emscripten
|
||||
{"msdos", &grub_msdos_partition_map, grub_parhook},
|
||||
#endif
|
||||
{"apple", &grub_apple_partition_map, grub_parhook},
|
||||
{"sun", &grub_sun_partition_map, grub_parhook},
|
||||
{"sunpc", &grub_sun_pc_partition_map, grub_parhook},
|
||||
{"amiga", &grub_amiga_partition_map, grub_parhook},
|
||||
{"bsdlabel", &grub_bsdlabel_partition_map, grub_parhook},
|
||||
{"gpt", &grub_gpt_partition_map, grub_parhook},
|
||||
#endif
|
||||
// XXX: In BURG all bsd partition map are in bsdlabel
|
||||
//{ "openbsdlabel", &grub_openbsd_partition_map },
|
||||
//{ "netbsdlabel", &grub_netbsd_partition_map },
|
||||
//{ "acorn", &grub_acorn_partition_map },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
RZ_API const char* rz_fs_partition_type_get(int n) {
|
||||
if (n < 0 || n >= R_FS_PARTITIONS_LENGTH) {
|
||||
return NULL;
|
||||
}
|
||||
return partitions[n].name;
|
||||
}
|
||||
|
||||
RZ_API int rz_fs_partition_get_size(void) {
|
||||
return R_FS_PARTITIONS_LENGTH;
|
||||
}
|
||||
|
||||
RZ_API RzList* rz_fs_partitions(RzFS* fs, const char* ptype, ut64 delta) {
|
||||
int i, cur = -1;
|
||||
for (i = 0; partitions[i].name; i++) {
|
||||
if (!strcmp (ptype, partitions[i].name)) {
|
||||
cur = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cur != -1) {
|
||||
RzList* list = rz_list_newf ((RzListFree) rz_fs_partition_free);
|
||||
#if USE_GRUB
|
||||
void* disk = NULL;
|
||||
if (partitions[i].iterate == grub_parhook) {
|
||||
struct grub_partition_map* gpt = partitions[i].ptr;
|
||||
grubfs_bind_io (NULL, 0);
|
||||
disk = (void*) grubfs_disk (&fs->iob);
|
||||
if (gpt) {
|
||||
gpt->iterate (disk,
|
||||
(void*) partitions[i].iterate, list);
|
||||
}
|
||||
grubfs_free (disk);
|
||||
} else {
|
||||
#else
|
||||
{
|
||||
#endif
|
||||
RzFSPartitionIterator iterate = partitions[i].ptr;
|
||||
iterate (fs, partitions[i].iterate, list); //grub_parhook, list);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
if (ptype && *ptype) {
|
||||
eprintf ("Unknown partition type '%s'.\n", ptype);
|
||||
}
|
||||
eprintf ("Supported types:\n");
|
||||
for (i = 0; partitions[i].name; i++) {
|
||||
eprintf (" %s", partitions[i].name);
|
||||
}
|
||||
eprintf ("\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RZ_API int rz_fs_partition_type_str(const char* type) {
|
||||
// TODO: implement
|
||||
return 0;
|
||||
}
|
||||
|
||||
RZ_API const char* rz_fs_partition_type(const char* part, int type) {
|
||||
// XXX: part is ignored O_o
|
||||
switch (type) {
|
||||
case GRUB_PC_PARTITION_TYPE_FAT12:
|
||||
case GRUB_PC_PARTITION_TYPE_FAT16_GT32M:
|
||||
case GRUB_PC_PARTITION_TYPE_FAT16_LT32M:
|
||||
case GRUB_PC_PARTITION_TYPE_FAT32:
|
||||
case GRUB_PC_PARTITION_TYPE_FAT32_LBA:
|
||||
case GRUB_PC_PARTITION_TYPE_FAT16_LBA:
|
||||
return strdup ("fat");
|
||||
|
||||
case GRUB_PC_PARTITION_TYPE_EXT2FS:
|
||||
return strdup ("ext2");
|
||||
|
||||
case GRUB_PC_PARTITION_TYPE_MINIX:
|
||||
case GRUB_PC_PARTITION_TYPE_LINUX_MINIX:
|
||||
return strdup ("minix");
|
||||
|
||||
case GRUB_PC_PARTITION_TYPE_NTFS:
|
||||
return strdup ("ntfs");
|
||||
|
||||
case GRUB_PC_PARTITION_TYPE_EXTENDED:
|
||||
case GRUB_PC_PARTITION_TYPE_LINUX_EXTENDED:
|
||||
return strdup ("ext3");
|
||||
|
||||
case GRUB_PC_PARTITION_TYPE_HFS:
|
||||
return strdup ("hfs");
|
||||
|
||||
case GRUB_PC_PARTITION_TYPE_WIN95_EXTENDED: // fat?
|
||||
case GRUB_PC_PARTITION_TYPE_EZD:
|
||||
case GRUB_PC_PARTITION_TYPE_VSTAFS:
|
||||
case GRUB_PC_PARTITION_TYPE_FREEBSD: // ufs
|
||||
case GRUB_PC_PARTITION_TYPE_OPENBSD: // ufs
|
||||
case GRUB_PC_PARTITION_TYPE_NETBSD: // ufs
|
||||
case GRUB_PC_PARTITION_TYPE_GPT_DISK:
|
||||
case GRUB_PC_PARTITION_TYPE_LINUX_RAID:
|
||||
case GRUB_PC_PARTITION_TYPE_NONE:
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
RZ_API char* rz_fs_name(RzFS* fs, ut64 offset) {
|
||||
ut8 buf[1024];
|
||||
int i, j, len, ret = false;
|
||||
|
||||
for (i = 0; fstypes[i].name; i++) {
|
||||
RzFSType* f = &fstypes[i];
|
||||
len = R_MIN (f->buflen, sizeof (buf) - 1);
|
||||
fs->iob.read_at (fs->iob.io, offset + f->bufoff, buf, len);
|
||||
if (f->buflen > 0 && !memcmp (buf, f->buf, f->buflen)) {
|
||||
ret = true;
|
||||
len = R_MIN (f->bytelen, sizeof (buf));
|
||||
fs->iob.read_at (fs->iob.io, offset + f->byteoff, buf, len);
|
||||
// for (j = 0; j < f->bytelen; j++) {
|
||||
for (j = 0; j < len; j++) {
|
||||
if (buf[j] != f->byte) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ret) {
|
||||
return strdup (f->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RZ_API void rz_fs_view(RzFS* fs, int view) {
|
||||
fs->view = view;
|
||||
}
|
||||
|
||||
RZ_API bool rz_fs_check(RzFS *fs, const char *p) {
|
||||
RzFSRoot *root;
|
||||
RzListIter *iter;
|
||||
char* path = strdup (p);
|
||||
if (!path) {
|
||||
return false;
|
||||
}
|
||||
rz_str_trim_path (path);
|
||||
rz_list_foreach (fs->roots, iter, root) {
|
||||
if (rz_fs_match (path, root->path, strlen (root->path))) {
|
||||
free (path);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
free (path);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011-2019 - pancake */
|
||||
|
||||
#include <rz_fs.h>
|
||||
|
||||
RZ_API RzFSFile* rz_fs_file_new(RzFSRoot* root, const char* path) {
|
||||
RzFSFile* file = R_NEW0 (RzFSFile);
|
||||
if (!file) {
|
||||
return NULL;
|
||||
}
|
||||
file->root = root;
|
||||
if (root) {
|
||||
file->p = file->root->p; // XXX dupe
|
||||
}
|
||||
file->path = strdup (path);
|
||||
char *last = (char *)rz_str_rchr (file->path, NULL, '/');
|
||||
if (last) {
|
||||
*last++ = 0;
|
||||
file->name = strdup (last);
|
||||
} else {
|
||||
file->name = strdup (path);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
RZ_API void rz_fs_file_free(RzFSFile* file) {
|
||||
if (file) {
|
||||
free (file->path);
|
||||
free (file->name);
|
||||
free (file->data);
|
||||
free (file);
|
||||
}
|
||||
}
|
||||
|
||||
RZ_API char* rz_fs_file_copy_abs_path(RzFSFile* file) {
|
||||
if (!file) {
|
||||
return NULL;
|
||||
}
|
||||
if (!strcmp (file->path, file->name)) {
|
||||
return strdup (file->path);
|
||||
}
|
||||
return rz_str_newf ("%s/%s", file->path, file->name);
|
||||
}
|
||||
|
||||
// TODO: Use RzFSRoot and pass it in the stack instead of heap? problematic with bindings
|
||||
RZ_API RzFSRoot* rz_fs_root_new(const char* path, ut64 delta) {
|
||||
char* p;
|
||||
RzFSRoot* root = R_NEW0 (RzFSRoot);
|
||||
if (!root) {
|
||||
return NULL;
|
||||
}
|
||||
root->path = strdup (path);
|
||||
if (!root->path) {
|
||||
R_FREE (root);
|
||||
return NULL;
|
||||
}
|
||||
p = root->path + strlen (path);
|
||||
if (*p == '/') {
|
||||
*p = 0; // chop tailing slash
|
||||
}
|
||||
root->delta = delta;
|
||||
return root;
|
||||
}
|
||||
|
||||
RZ_API void rz_fs_root_free(RzFSRoot* root) {
|
||||
if (root) {
|
||||
if (root->p && root->p->umount) {
|
||||
root->p->umount (root);
|
||||
}
|
||||
free (root->path);
|
||||
free (root);
|
||||
}
|
||||
}
|
||||
|
||||
RZ_API RzFSPartition* rz_fs_partition_new(int num, ut64 start, ut64 length) {
|
||||
RzFSPartition* p = R_NEW0 (RzFSPartition);
|
||||
if (!p) {
|
||||
return NULL;
|
||||
}
|
||||
p->number = num;
|
||||
p->type = 0; // TODO we need an enum with all the partition types
|
||||
p->start = start;
|
||||
p->length = length;
|
||||
return p;
|
||||
}
|
||||
|
||||
RZ_API void rz_fs_partition_free(RzFSPartition* p) {
|
||||
free (p);
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
rz_fs_sources = [
|
||||
'fs_file.c',
|
||||
'fs.c',
|
||||
'shell.c',
|
||||
'p/fs_cpio.c',
|
||||
'p/fs_ext2.c',
|
||||
'p/fs_fat.c',
|
||||
'p/fs_fb.c',
|
||||
#'p/fs_grub_base.c',
|
||||
'p/fs_hfs.c',
|
||||
'p/fs_hfsplus.c',
|
||||
'p/fs_io.c',
|
||||
'p/fs_iso9660.c',
|
||||
'p/fs_jfs.c',
|
||||
'p/fs_minix.c',
|
||||
'p/fs_ntfs.c',
|
||||
'p/fs_posix.c',
|
||||
'p/fs_rz.c',
|
||||
'p/fs_reiserfs.c',
|
||||
'p/fs_sfs.c',
|
||||
'p/fs_tar.c',
|
||||
'p/fs_udf.c',
|
||||
'p/fs_ufs.c',
|
||||
'p/fs_ufs2.c',
|
||||
'p/fs_xfs.c',
|
||||
#'p/part_dos.c'
|
||||
]
|
||||
|
||||
rz_fs = library('rz_fs', rz_fs_sources,
|
||||
include_directories: platform_inc,
|
||||
c_args: library_cflags,
|
||||
dependencies: [
|
||||
rz_util_dep,
|
||||
grub_dep
|
||||
],
|
||||
install: true,
|
||||
implicit_include_directories: false,
|
||||
install_rpath: rpath_lib,
|
||||
soversion: r2_libversion
|
||||
)
|
||||
|
||||
rz_fs_dep = declare_dependency(link_with: rz_fs,
|
||||
include_directories: platform_inc)
|
||||
|
||||
pkgconfig_mod.generate(rz_fs,
|
||||
subdirs: 'librz',
|
||||
version: r2_version,
|
||||
name: 'rz_fs',
|
||||
filebase: 'rz_fs',
|
||||
libraries: pkgcfg_sanitize_libs,
|
||||
requires: [
|
||||
'rz_util'
|
||||
],
|
||||
description: 'radare foundation libraries'
|
||||
)
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
include ../../config.mk
|
||||
include ../../../mk/platform.mk
|
||||
|
||||
CFLAGS+=-I$(LIBR)/include -Wall -shared ${PIC_CFLAGS} ${LDFLAGS_LIB} ${LDFLAGS_LINKPATH}..
|
||||
GRUB=$(LIBR)../shlr/grub/libgrub.a
|
||||
#CFLAGS+=-I../../include
|
||||
LDFLAGS+=${LINK}
|
||||
|
||||
ifeq ($(WITHPIC),1)
|
||||
all:
|
||||
|
||||
#FILESYSTEMS=hfs.mk iso9660.mk jfs.mk
|
||||
#FILESYSTEMS=hfsplus.mk
|
||||
FILESYSTEMS=ext2.mk fat.mk ntfs.mk reiserfs.mk tar.mk udf.mk ufs2.mk ufs.mk xfs.mk hfs.mk
|
||||
include $(FILESYSTEMS)
|
||||
|
||||
clean:
|
||||
-rm -f *.${EXT_SO} *.o ${STATIC_OBJ}
|
||||
|
||||
mrproper: clean
|
||||
-rm -f *.d ../arch/*/*/*.d
|
||||
|
||||
.PHONY: all clean mrproper
|
||||
else
|
||||
all clean mrproper:
|
||||
|
||||
.PHONY: all clean mrproper
|
||||
endif
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_CPIO=fs_cpio.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-I$(SHLR)/grub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_CPIO}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_CPIO=fs_cpio.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_CPIO}
|
||||
|
||||
${TARGET_CPIO}: ${OBJ_CPIO}
|
||||
${CC} $(call libname,fs_cpio) ${LDFLAGS} ${CFLAGS} -o ${TARGET_CPIO} ${OBJ_CPIO} ${EXTRA}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_EXT2=fs_ext2.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_EXT2}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_EXT2=fs_ext2.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_EXT2}
|
||||
|
||||
${TARGET_EXT2}: ${OBJ_EXT2}
|
||||
${CC} $(call libname,fs_ext2) ${LDFLAGS} ${CFLAGS} -o ${TARGET_EXT2} ${OBJ_EXT2} ${EXTRA}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_FAT=fs_fat.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_FAT}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_FAT=fs_fat.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_FAT}
|
||||
|
||||
${TARGET_FAT}: ${OBJ_FAT}
|
||||
${CC} $(call libname,fs_fat) ${LDFLAGS} ${CFLAGS} -o ${TARGET_FAT} ${OBJ_FAT} ${EXTRA}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_FB=fs_fb.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_FB}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_FB=fs_fb.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_FB}
|
||||
|
||||
${TARGET_FB}: ${OBJ_FB}
|
||||
${CC} $(call libname,fs_fb) ${LDFLAGS} ${CFLAGS} -o ${TARGET_FB} ${OBJ_FB} ${EXTRA}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) cpio_##x
|
||||
#define FSS(x) x##_cpio
|
||||
#define FSNAME "cpio"
|
||||
#define FSDESC "CPIO filesystem"
|
||||
#define FSPRFX cpio
|
||||
#define FSIPTR grub_cpio_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) ext2_##x
|
||||
#define FSS(x) x##_ext2
|
||||
#define FSNAME "ext2"
|
||||
#define FSDESC "ext2 filesystem"
|
||||
#define FSPRFX ext2
|
||||
#define FSIPTR grub_ext2_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) fat_##x
|
||||
#define FSS(x) x##_fat
|
||||
#define FSNAME "fat"
|
||||
#define FSDESC "FAT filesystem"
|
||||
#define FSPRFX fat
|
||||
#define FSIPTR grub_fat_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) fb_##x
|
||||
#define FSS(x) x##_fb
|
||||
#define FSNAME "fb"
|
||||
#define FSDESC "FB filesystem"
|
||||
#define FSPRFX fb
|
||||
#define FSIPTR grub_fb_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011-2020 - pancake */
|
||||
|
||||
#include <rz_fs.h>
|
||||
#include "grubfs.h"
|
||||
|
||||
#if WITH_GPL
|
||||
|
||||
static RzFSFile* FSP(_open)(RzFSRoot *root, const char *path, bool create) {
|
||||
RzFSFile *file = rz_fs_file_new (root, path);
|
||||
GrubFS *gfs = grubfs_new (&FSIPTR, &root->iob);
|
||||
file->ptr = gfs;
|
||||
file->p = root->p;
|
||||
grubfs_bind_io (NULL, file->root->delta);
|
||||
if (gfs->file->fs->open (gfs->file, path)) {
|
||||
rz_fs_file_free (file);
|
||||
grubfs_free (gfs);
|
||||
file = NULL;
|
||||
} else {
|
||||
file->size = gfs->file->size;
|
||||
file->off = gfs->file->offset;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
static bool FSP(_read)(RzFSFile *file, ut64 addr, int len) {
|
||||
GrubFS *gfs = file->ptr;
|
||||
grubfs_bind_io (NULL, file->root->delta);
|
||||
gfs->file->fs->read (gfs->file, (char*)file->data, len);
|
||||
file->off = grub_hack_lastoff; //gfs->file->offset;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void FSP(_close)(RzFSFile *file) {
|
||||
GrubFS *gfs = file->ptr;
|
||||
gfs->file->fs->close (gfs->file);
|
||||
}
|
||||
|
||||
static RzList *list = NULL;
|
||||
|
||||
static int dirhook (const char *filename, const struct grub_dirhook_info *info, void *closure) {
|
||||
RzFSFile *fsf = rz_fs_file_new (NULL, filename);
|
||||
fsf->type = info->dir? 'd':'f';
|
||||
fsf->time = info->mtime;
|
||||
rz_list_append (list, fsf);
|
||||
//info->mtimeset
|
||||
//info->case_insensitive
|
||||
//printf ("DIRFILE: %c (%d) %s\n", info->dir?'d':'f', info->mtime, filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static RzList *FSP(_dir)(RzFSRoot *root, const char *path, int view) {
|
||||
GrubFS *gfs;
|
||||
|
||||
if (!root)
|
||||
return NULL;
|
||||
|
||||
gfs = root->ptr;
|
||||
list = rz_list_new ();
|
||||
// eprintf ("rz_fs_???_dir: %s\n", path);
|
||||
//gfs->file->device->data = &root->iob;
|
||||
grubfs_bind_io (&root->iob, root->delta);
|
||||
gfs->file->fs->dir (gfs->file->device, path, dirhook, 0);
|
||||
grubfs_bind_io (NULL, root->delta);
|
||||
return list;
|
||||
}
|
||||
|
||||
static int do_nothing (const char *a, const struct grub_dirhook_info *b, void *c) { return 0; }
|
||||
|
||||
static int FSP(_mount)(RzFSRoot *root) {
|
||||
int ret;
|
||||
GrubFS *gfs = grubfs_new (&FSIPTR, &root->iob);
|
||||
root->ptr = gfs;
|
||||
grubfs_bind_io (&root->iob, root->delta);
|
||||
// XXX: null hook seems to be problematic on some filesystems
|
||||
//return gfs->file->fs->dir (gfs->file->device, "/", NULL, 0)? false:true;
|
||||
ret = gfs->file->fs->dir (gfs->file->device, "/", do_nothing, 0)? false:true;
|
||||
grubfs_bind_io (NULL, root->delta);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void FSP(_umount)(RzFSRoot *root) {
|
||||
grubfs_free (root->ptr);
|
||||
root->ptr = NULL;
|
||||
}
|
||||
|
||||
RzFSPlugin FSS(rz_fs_plugin) = {
|
||||
.name = FSNAME,
|
||||
.desc = FSDESC,
|
||||
.license = "GPL2",
|
||||
.open = FSP(_open),
|
||||
.read = FSP(_read),
|
||||
.close = FSP(_close),
|
||||
.dir = FSP(_dir),
|
||||
.mount = FSP(_mount),
|
||||
.umount = FSP(_umount),
|
||||
};
|
||||
#else
|
||||
RzFSPlugin FSS(rz_fs_plugin) = {
|
||||
.name = FSNAME,
|
||||
.desc = FSDESC,
|
||||
};
|
||||
#endif
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) grub_hfs##x
|
||||
#define FSS(x) x##_hfs
|
||||
#define FSNAME "hfs"
|
||||
#define FSDESC "HFS filesystem"
|
||||
#define FSPRFX hfs
|
||||
#define FSIPTR grub_hfs_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) hfsplus_##x
|
||||
#define FSS(x) x##_hfsplus
|
||||
#define FSNAME "hfsplus"
|
||||
#define FSDESC "HFSPLUS filesystem"
|
||||
#define FSPRFX hfsplus
|
||||
#define FSIPTR grub_hfsplus_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,140 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2017-2019 - pancake */
|
||||
|
||||
#include <rz_fs.h>
|
||||
#include <rz_lib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
static RzFSFile *fs_io_open(RzFSRoot *root, const char *path, bool create) {
|
||||
char *cmd = rz_str_newf ("m %s", path);
|
||||
char *res = root->iob.system (root->iob.io, cmd);
|
||||
R_FREE (cmd);
|
||||
if (res) {
|
||||
ut32 size = 0;
|
||||
if (sscanf (res, "%u", &size) != 1) {
|
||||
size = 0;
|
||||
}
|
||||
R_FREE (res);
|
||||
if (size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
RzFSFile *file = rz_fs_file_new (root, path);
|
||||
if (!file) {
|
||||
return NULL;
|
||||
}
|
||||
file->ptr = NULL;
|
||||
file->p = root->p;
|
||||
file->size = size;
|
||||
return file;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool fs_io_read(RzFSFile *file, ut64 addr, int len) {
|
||||
RzFSRoot *root = file->root;
|
||||
char *abs_path = rz_fs_file_copy_abs_path (file);
|
||||
if (!abs_path) {
|
||||
return false;
|
||||
}
|
||||
char *cmd = rz_str_newf ("mg %s", abs_path);
|
||||
R_FREE (abs_path);
|
||||
if (!cmd) {
|
||||
return false;
|
||||
}
|
||||
char *res = root->iob.system (root->iob.io, cmd);
|
||||
R_FREE (cmd);
|
||||
if (res) {
|
||||
int encoded_size = strlen (res);
|
||||
if (encoded_size != len * 2) {
|
||||
eprintf ("Unexpected size (%d vs %d)\n", encoded_size, len*2);
|
||||
R_FREE (res);
|
||||
return false;
|
||||
}
|
||||
file->data = (ut8 *) calloc (1, len);
|
||||
if (!file->data) {
|
||||
R_FREE (res);
|
||||
return false;
|
||||
}
|
||||
int ret = rz_hex_str2bin (res, file->data);
|
||||
if (ret != len) {
|
||||
eprintf ("Inconsistent read\n");
|
||||
R_FREE (file->data);
|
||||
}
|
||||
R_FREE (res);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void fs_io_close(RzFSFile *file) {
|
||||
// fclose (file->ptr);
|
||||
}
|
||||
|
||||
static void append_file(RzList *list, const char *name, int type, int time, ut64 size) {
|
||||
RzFSFile *fsf = rz_fs_file_new (NULL, name);
|
||||
if (!fsf) {
|
||||
return;
|
||||
}
|
||||
fsf->type = type;
|
||||
fsf->time = time;
|
||||
fsf->size = size;
|
||||
rz_list_append (list, fsf);
|
||||
}
|
||||
|
||||
static RzList *fs_io_dir(RzFSRoot *root, const char *path, int view /*ignored*/) {
|
||||
RzList *list = rz_list_new ();
|
||||
if (!list) {
|
||||
return NULL;
|
||||
}
|
||||
char *cmd = rz_str_newf ("md %s", path);
|
||||
char *res = root->iob.system (root->iob.io, cmd);
|
||||
if (res) {
|
||||
size_t i, count = 0;
|
||||
size_t *lines = rz_str_split_lines (res, &count);
|
||||
if (lines) {
|
||||
for (i = 0; i < count; i++) {
|
||||
const char *line = res + lines[i];
|
||||
if (!*line) {
|
||||
continue;
|
||||
}
|
||||
char type = 'f';
|
||||
if (line[1] == ' ' && line[0] != ' ') {
|
||||
type = line[0];
|
||||
line += 2;
|
||||
}
|
||||
append_file (list, line, type, 0, 0);
|
||||
}
|
||||
R_FREE (res);
|
||||
R_FREE (lines);
|
||||
}
|
||||
}
|
||||
R_FREE (cmd);
|
||||
return list;
|
||||
}
|
||||
|
||||
static int fs_io_mount(RzFSRoot *root) {
|
||||
root->ptr = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void fs_io_umount(RzFSRoot *root) {
|
||||
root->ptr = NULL;
|
||||
}
|
||||
|
||||
RzFSPlugin rz_fs_plugin_io = {
|
||||
.name = "io",
|
||||
.desc = "rz_io based filesystem",
|
||||
.license = "MIT",
|
||||
.open = fs_io_open,
|
||||
.read = fs_io_read,
|
||||
.close = fs_io_close,
|
||||
.dir = &fs_io_dir,
|
||||
.mount = fs_io_mount,
|
||||
.umount = fs_io_umount,
|
||||
};
|
||||
|
||||
#ifndef R2_PLUGIN_INCORE
|
||||
RZ_API RzLibStruct radare_plugin = {
|
||||
.type = R_LIB_TYPE_FS,
|
||||
.data = &rz_fs_plugin_io,
|
||||
.version = R2_VERSION
|
||||
};
|
||||
#endif
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) iso9660_##x
|
||||
#define FSS(x) x##_iso9660
|
||||
#define FSNAME "iso9660"
|
||||
#define FSDESC "ISO9660 filesystem"
|
||||
#define FSPRFX iso9660
|
||||
#define FSIPTR grub_iso9660_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) jfs_##x
|
||||
#define FSS(x) x##_jfs
|
||||
#define FSNAME "jfs"
|
||||
#define FSDESC "JFS filesystem"
|
||||
#define FSPRFX jfs
|
||||
#define FSIPTR grub_jfs_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) minix_##x
|
||||
#define FSS(x) x##_minix
|
||||
#define FSNAME "minix"
|
||||
#define FSDESC "MINIX filesystem"
|
||||
#define FSPRFX minix
|
||||
#define FSIPTR grub_minix_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) ntfs_##x
|
||||
#define FSS(x) x##_ntfs
|
||||
#define FSNAME "ntfs"
|
||||
#define FSDESC "NTFS filesystem"
|
||||
#define FSPRFX ntfs
|
||||
#define FSIPTR grub_ntfs_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,149 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011-2017 - pancake */
|
||||
|
||||
#include <rz_fs.h>
|
||||
#include <rz_lib.h>
|
||||
#include <sys/stat.h>
|
||||
#ifdef _MSC_VER
|
||||
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
#define MAXPATHLEN 255
|
||||
#endif
|
||||
static RzFSFile* fs_posix_open(RzFSRoot *root, const char *path, bool create) {
|
||||
FILE *fd;
|
||||
RzFSFile *file = rz_fs_file_new (root, path);
|
||||
if (!file) {
|
||||
return NULL;
|
||||
}
|
||||
file->ptr = NULL;
|
||||
file->p = root->p;
|
||||
fd = rz_sandbox_fopen (path, create? "wb": "rb");
|
||||
if (fd) {
|
||||
fseek (fd, 0, SEEK_END);
|
||||
file->size = ftell (fd);
|
||||
fclose (fd);
|
||||
} else {
|
||||
rz_fs_file_free (file);
|
||||
file = NULL;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
static bool fs_posix_read(RzFSFile *file, ut64 addr, int len) {
|
||||
free (file->data);
|
||||
file->data = (void*)rz_file_slurp_range (file->name, 0, len, NULL);
|
||||
return false;
|
||||
}
|
||||
|
||||
static void fs_posix_close(RzFSFile *file) {
|
||||
//fclose (file->ptr);
|
||||
}
|
||||
|
||||
static RzList *fs_posix_dir(RzFSRoot *root, const char *path, int view /*ignored*/) {
|
||||
RzList *list;
|
||||
char fullpath[4096];
|
||||
struct stat st;
|
||||
#if __WINDOWS__
|
||||
WIN32_FIND_DATAW entry;
|
||||
HANDLE fh;
|
||||
wchar_t *wcpath;
|
||||
char *wctocbuff;
|
||||
wchar_t directory[MAX_PATH];
|
||||
#else
|
||||
struct dirent *de;
|
||||
DIR *dir;
|
||||
#endif
|
||||
list = rz_list_new ();
|
||||
if (!list) {
|
||||
return NULL;
|
||||
}
|
||||
#if __WINDOWS__
|
||||
wcpath = rz_utf8_to_utf16 (path);
|
||||
if (!wcpath) {
|
||||
return NULL;
|
||||
}
|
||||
swprintf (directory, _countof (directory), L"%ls\\*.*", wcpath);
|
||||
fh = FindFirstFileW (directory, &entry);
|
||||
if (fh == INVALID_HANDLE_VALUE) {
|
||||
free (wcpath);
|
||||
return NULL;
|
||||
}
|
||||
do {
|
||||
if ((wctocbuff = rz_utf16_to_utf8 (entry.cFileName))) {
|
||||
RzFSFile *fsf = rz_fs_file_new (NULL, wctocbuff);
|
||||
if (!fsf) {
|
||||
rz_list_free (list);
|
||||
FindClose (fh);
|
||||
return NULL;
|
||||
}
|
||||
fsf->type = 'f';
|
||||
snprintf (fullpath, sizeof (fullpath)-1, "%s/%s", path, wctocbuff);
|
||||
if (!stat (fullpath, &st)) {
|
||||
fsf->type = S_ISDIR (st.st_mode)?'d':'f';
|
||||
fsf->time = st.st_atime;
|
||||
} else {
|
||||
fsf->type = 'f';
|
||||
fsf->time = 0;
|
||||
}
|
||||
rz_list_append (list, fsf);
|
||||
free (wctocbuff);
|
||||
}
|
||||
|
||||
} while (FindNextFileW (fh, &entry));
|
||||
FindClose (fh);
|
||||
#else
|
||||
dir = opendir (path);
|
||||
if (!dir) {
|
||||
rz_list_free (list);
|
||||
return NULL;
|
||||
}
|
||||
while ((de = readdir (dir))) {
|
||||
RzFSFile *fsf = rz_fs_file_new (NULL, de->d_name);
|
||||
if (!fsf) {
|
||||
rz_list_free (list);
|
||||
closedir (dir);
|
||||
return NULL;
|
||||
}
|
||||
fsf->type = 'f';
|
||||
snprintf (fullpath, sizeof (fullpath)-1, "%s/%s", path, de->d_name);
|
||||
if (!stat (fullpath, &st)) {
|
||||
fsf->type = S_ISDIR (st.st_mode)?'d':'f';
|
||||
fsf->time = st.st_atime;
|
||||
} else {
|
||||
fsf->type = 'f';
|
||||
fsf->time = 0;
|
||||
}
|
||||
rz_list_append (list, fsf);
|
||||
}
|
||||
closedir (dir);
|
||||
#endif
|
||||
return list;
|
||||
}
|
||||
|
||||
static int fs_posix_mount(RzFSRoot *root) {
|
||||
root->ptr = NULL; // XXX: TODO
|
||||
return true;
|
||||
}
|
||||
|
||||
static void fs_posix_umount(RzFSRoot *root) {
|
||||
root->ptr = NULL;
|
||||
}
|
||||
|
||||
RzFSPlugin rz_fs_plugin_posix = {
|
||||
.name = "posix",
|
||||
.desc = "POSIX filesystem",
|
||||
.license = "MIT",
|
||||
.open = fs_posix_open,
|
||||
.read = fs_posix_read,
|
||||
.close = fs_posix_close,
|
||||
.dir = &fs_posix_dir,
|
||||
.mount = fs_posix_mount,
|
||||
.umount = fs_posix_umount,
|
||||
};
|
||||
|
||||
#ifndef R2_PLUGIN_INCORE
|
||||
RZ_API RzLibStruct radare_plugin = {
|
||||
.type = R_LIB_TYPE_FS,
|
||||
.data = &rz_fs_plugin_posix,
|
||||
.version = R2_VERSION
|
||||
};
|
||||
#endif
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) reiserfs_##x
|
||||
#define FSS(x) x##_reiserfs
|
||||
#define FSNAME "reiserfs"
|
||||
#define FSDESC "REISERzFS filesystem"
|
||||
#define FSPRFX reiserfs
|
||||
#define FSIPTR grub_reiserfs_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,321 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2017-2019 - pancake */
|
||||
|
||||
#include <rz_fs.h>
|
||||
#include <rz_lib.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
typedef RzList *(*DirHandler)(RzFSRoot *root, const char *path);
|
||||
typedef RzFSFile *(*CatHandler)(RzFSRoot *root, RzFSFile *file, const char *path);
|
||||
typedef bool (*WriteHandler)(RzFSFile *file, ut64 addr, const ut8 *data, int len);
|
||||
|
||||
typedef struct {
|
||||
const char *path;
|
||||
DirHandler dir;
|
||||
CatHandler cat;
|
||||
WriteHandler write;
|
||||
} Routes;
|
||||
|
||||
static RzFSFile *__flags_cat(RzFSRoot *root, RzFSFile *file, const char *path);
|
||||
static RzFSFile *__cfg_cat(RzFSRoot *root, RzFSFile *file, const char *path);
|
||||
static RzFSFile *__seek_cat(RzFSRoot *root, RzFSFile *file, const char *path);
|
||||
static RzFSFile *__bsize_cat(RzFSRoot *root, RzFSFile *file, const char *path);
|
||||
static bool __cfg_write(RzFSFile *file, ut64 addr, const ut8 *data, int len);
|
||||
static bool __seek_write(RzFSFile *file, ut64 addr, const ut8 *data, int len);
|
||||
static bool __bsize_write(RzFSFile *file, ut64 addr, const ut8 *data, int len);
|
||||
static RzFSFile *__version(RzFSRoot *root, RzFSFile *file, const char *path);
|
||||
static RzList *__root(RzFSRoot *root, const char *path);
|
||||
static RzList *__cfg(RzFSRoot *root, const char *path);
|
||||
static RzList *__flags(RzFSRoot *root, const char *path);
|
||||
|
||||
static Routes routes[] = {
|
||||
{"/cfg", &__cfg, &__cfg_cat, &__cfg_write },
|
||||
{"/flags", &__flags, &__flags_cat, NULL},
|
||||
{"/version", NULL, &__version, NULL},
|
||||
{"/seek", NULL, &__seek_cat, &__seek_write },
|
||||
{"/bsize", NULL, &__bsize_cat, &__bsize_write },
|
||||
{"/", &__root},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
static void append_file(RzList *list, const char *name, int type, int time, ut64 size) {
|
||||
if (!list || !name || !*name) {
|
||||
return;
|
||||
}
|
||||
RzFSFile *fsf = rz_fs_file_new (NULL, name);
|
||||
if (!fsf) {
|
||||
return;
|
||||
}
|
||||
fsf->type = type;
|
||||
fsf->time = time;
|
||||
fsf->size = size;
|
||||
rz_list_append (list, fsf);
|
||||
}
|
||||
|
||||
static RzList *fscmd(RzFSRoot *root, const char *cmd, int type) {
|
||||
char *res = root->cob.cmdstr (root->cob.core, cmd);
|
||||
if (res) {
|
||||
RzList *list = rz_list_newf (free);
|
||||
if (!list) {
|
||||
free (res);
|
||||
return NULL;
|
||||
}
|
||||
size_t i, count = 0;
|
||||
size_t *lines = rz_str_split_lines (res, &count);
|
||||
if (lines) {
|
||||
for (i = 0; i < count; i++) {
|
||||
append_file (list, res + lines[i], type, 0, 0);
|
||||
}
|
||||
free (lines);
|
||||
}
|
||||
free (res);
|
||||
return list;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static RzFSFile* fs_rz_open(RzFSRoot *root, const char *path, bool create) {
|
||||
int i;
|
||||
for (i = 0; routes[i].path; i++) {
|
||||
const char *cwd = routes[i].path;
|
||||
if (routes[i].cat && !strncmp (path, cwd, strlen (cwd))) {
|
||||
return routes[i].cat (root, NULL, path);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool fs_rz_write(RzFSFile *file, ut64 addr, const ut8 *data, int len) {
|
||||
int i;
|
||||
const char *path = file->path;
|
||||
const char *name = file->name;
|
||||
for (i = 0; routes[i].path; i++) {
|
||||
if (routes[i].write) {
|
||||
if (!strncmp (name, routes[i].path + 1, strlen (routes[i].path) - 1)) {
|
||||
return routes[i].write (file, addr, data, len);
|
||||
}
|
||||
if (!strncmp (path, routes[i].path, strlen (routes[i].path))) {
|
||||
return routes[i].write (file, addr, data, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool fs_rz_read(RzFSFile *file, ut64 addr, int len) {
|
||||
int i;
|
||||
const char *path = file->name;
|
||||
for (i = 0; routes[i].path; i++) {
|
||||
if (routes[i].cat && !strncmp (path, routes[i].path, strlen (routes[i].path))) {
|
||||
return routes[i].cat (file->root, file, path);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static void fs_rz_close(RzFSFile *file) {
|
||||
// eprintf ("TODO: fs.r2.close\n");
|
||||
//fclose (file->ptr);
|
||||
}
|
||||
|
||||
static RzFSFile *__version(RzFSRoot *root, RzFSFile *file, const char *path) {
|
||||
char *res = root->cob.cmdstrf (root->cob.core, "?V");
|
||||
/// root->iob.io->cb_printf ("%s\n", res);
|
||||
if (!file) {
|
||||
file = rz_fs_file_new (root, path);
|
||||
}
|
||||
file->ptr = NULL;
|
||||
free (file->data);
|
||||
file->data = (ut8*)res;
|
||||
file->p = root->p;
|
||||
file->size = strlen (res);
|
||||
return file;
|
||||
}
|
||||
|
||||
static RzFSFile *__flags_cat(RzFSRoot *root, RzFSFile *file, const char *path) {
|
||||
rz_return_val_if_fail (root && path, NULL);
|
||||
const char *last = rz_str_rchr (path, NULL, '/');
|
||||
if (last) {
|
||||
last++;
|
||||
} else {
|
||||
last = path;
|
||||
}
|
||||
char *res = root->cob.cmdstrf (root->cob.core, "?v %s", last);
|
||||
if (file) {
|
||||
file->ptr = NULL;
|
||||
file->data = (ut8*)res;
|
||||
file->p = root->p;
|
||||
file->size = strlen (res);
|
||||
} else {
|
||||
file = rz_fs_file_new (root, path);
|
||||
file->ptr = NULL;
|
||||
file->data = (ut8*)res;
|
||||
file->p = root->p;
|
||||
file->size = strlen (res);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
static bool __bsize_write(RzFSFile *file, ut64 addr, const ut8 *data, int len) {
|
||||
void *core = file->root->cob.core;
|
||||
char *res = file->root->cob.cmdstrf (core, "b %s", data);
|
||||
free (res);
|
||||
return true;
|
||||
}
|
||||
|
||||
static RzFSFile *__bsize_cat(RzFSRoot *root, RzFSFile *file, const char *path) {
|
||||
char *res = root->cob.cmdstrf (root->cob.core, "b");
|
||||
if (!file) {
|
||||
file = rz_fs_file_new (root, path);
|
||||
}
|
||||
file->ptr = NULL;
|
||||
file->data = (ut8*)res;
|
||||
file->p = root->p;
|
||||
file->size = strlen (res);
|
||||
return file;
|
||||
}
|
||||
|
||||
static bool __seek_write(RzFSFile *file, ut64 addr, const ut8 *data, int len) {
|
||||
void *core = file->root->cob.core;
|
||||
char *res = file->root->cob.cmdstrf (core, "s %s", data);
|
||||
free (res);
|
||||
return true;
|
||||
}
|
||||
|
||||
static RzFSFile *__seek_cat(RzFSRoot *root, RzFSFile *file, const char *path) {
|
||||
char *res = root->cob.cmdstrf (root->cob.core, "s");
|
||||
if (!file) {
|
||||
file = rz_fs_file_new (root, path);
|
||||
}
|
||||
file->ptr = NULL;
|
||||
file->data = (ut8*)res;
|
||||
file->p = root->p;
|
||||
file->size = strlen (res);
|
||||
return file;
|
||||
}
|
||||
|
||||
static bool __cfg_write(RzFSFile *file, ut64 addr, const ut8 *data, int len) {
|
||||
const char *a = file->name;
|
||||
void *core = file->root->cob.core;
|
||||
char *prefix = strdup (file->path + strlen ("/cfg/"));
|
||||
char *res = file->root->cob.cmdstrf (core, "e %s.%s=%s", prefix, a, data);
|
||||
free (prefix);
|
||||
free (res);
|
||||
return true;
|
||||
}
|
||||
|
||||
static RzFSFile *__cfg_cat(RzFSRoot *root, RzFSFile *file, const char *path) {
|
||||
if (strlen (path) < 6) {
|
||||
return NULL;
|
||||
}
|
||||
char *a = strdup (path + 5);
|
||||
rz_str_replace_char (a, '/', '.');
|
||||
char *res = root->cob.cmdstrf (root->cob.core, "e %s", a);
|
||||
// root->iob.io->cb_printf ("%s\n", res);
|
||||
// eprintf ("%s", res);
|
||||
if (!file) {
|
||||
file = rz_fs_file_new (root, path);
|
||||
}
|
||||
file->ptr = NULL;
|
||||
file->data = (ut8*)res;
|
||||
file->p = root->p;
|
||||
file->size = strlen (res);
|
||||
return file;
|
||||
}
|
||||
|
||||
static RzList *__flags(RzFSRoot *root, const char *path) {
|
||||
const char *prefix = NULL;
|
||||
if (!strncmp (path, "/flags/", 7)) {
|
||||
prefix = path + 7;
|
||||
}
|
||||
char *cmd = prefix
|
||||
? rz_str_newf ("fq@F:%s", prefix)
|
||||
: strdup ("fsq");
|
||||
RzList *res = fscmd (root, cmd, prefix? 'f': 'd');
|
||||
free (cmd);
|
||||
return res;
|
||||
}
|
||||
|
||||
static RzList *__cfg(RzFSRoot *root, const char *path) {
|
||||
const char *prefix = NULL;
|
||||
if (!strncmp (path, "/cfg/", 5)) {
|
||||
prefix = path + 5;
|
||||
}
|
||||
char *cmd = prefix
|
||||
? rz_str_newf ("es %s", prefix)
|
||||
: strdup ("es");
|
||||
char *res = root->cob.cmdstr (root->cob.core, cmd);
|
||||
free (cmd);
|
||||
if (res) {
|
||||
RzList *list = rz_list_new ();
|
||||
if (!list) {
|
||||
free (res);
|
||||
return NULL;
|
||||
}
|
||||
size_t i, count = 0;
|
||||
size_t *lines = rz_str_split_lines (res, &count);
|
||||
if (lines) {
|
||||
for (i = 0; i < count; i++) {
|
||||
char *line = res + lines[i];
|
||||
append_file (list, line, prefix? 'f': 'd', 0, 0);
|
||||
}
|
||||
free (res);
|
||||
free (lines);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static RzList *__root(RzFSRoot *root, const char *path) {
|
||||
RzList *list = rz_list_newf (NULL);
|
||||
if (!list) {
|
||||
return NULL;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; routes[i].path; i++) {
|
||||
char type = routes[i].dir? 'd': 'f';
|
||||
append_file (list, routes[i].path + 1, type, 0, 0);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static RzList *fs_rz_dir(RzFSRoot *root, const char *path, int view /*ignored*/) {
|
||||
int i;
|
||||
for (i = 0; routes[i].path; i++) {
|
||||
if (routes[i].dir && !strncmp (path, routes[i].path, strlen (routes[i].path))) {
|
||||
return routes[i].dir (root, path);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int fs_rz_mount(RzFSRoot *root) {
|
||||
root->ptr = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void fs_rz_umount(RzFSRoot *root) {
|
||||
root->ptr = NULL;
|
||||
}
|
||||
|
||||
RzFSPlugin rz_fs_plugin_rz = {
|
||||
.name = "r2",
|
||||
.desc = "r2-based filesystem",
|
||||
.license = "MIT",
|
||||
.open = fs_rz_open, // open == read
|
||||
.read = fs_rz_read, // read == open
|
||||
.write = fs_rz_write,
|
||||
.close = fs_rz_close,
|
||||
.dir = &fs_rz_dir,
|
||||
.mount = fs_rz_mount,
|
||||
.umount = fs_rz_umount,
|
||||
};
|
||||
|
||||
#ifndef R2_PLUGIN_INCORE
|
||||
RZ_API RzLibStruct radare_plugin = {
|
||||
.type = R_LIB_TYPE_FS,
|
||||
.data = &rz_fs_plugin_rz,
|
||||
.versr2n = R2_VERSION
|
||||
};
|
||||
#endif
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) sfs_##x
|
||||
#define FSS(x) x##_sfs
|
||||
#define FSNAME "sfs"
|
||||
#define FSDESC "Amiga Smart FileSystem"
|
||||
#define FSPRFX sfs
|
||||
#define FSIPTR grub_sfs_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) tar_##x
|
||||
#define FSS(x) x##_tar
|
||||
#define FSNAME "tar"
|
||||
#define FSDESC "TAR filesystem"
|
||||
#define FSPRFX tar
|
||||
#define FSIPTR grub_tar_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) udf_##x
|
||||
#define FSS(x) x##_udf
|
||||
#define FSNAME "udf"
|
||||
#define FSDESC "UDF filesystem"
|
||||
#define FSPRFX udf
|
||||
#define FSIPTR grub_udf_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) ufs_##x
|
||||
#define FSS(x) x##_ufs
|
||||
#define FSNAME "ufs"
|
||||
#define FSDESC "UFS filesystem"
|
||||
#define FSPRFX ufs
|
||||
#define FSIPTR grub_ufs_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) ufs2_##x
|
||||
#define FSS(x) x##_ufs2
|
||||
#define FSNAME "ufs2"
|
||||
#define FSDESC "UFS2 filesystem"
|
||||
#define FSPRFX ufs2
|
||||
#define FSIPTR grub_ufs2_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
/* radare - LGPL - Copyright 2011 pancake<nopcode.org> */
|
||||
|
||||
#define FSP(x) xfs_##x
|
||||
#define FSS(x) x##_xfs
|
||||
#define FSNAME "xfs"
|
||||
#define FSDESC "XFS filesystem"
|
||||
#define FSPRFX xfs
|
||||
#define FSIPTR grub_xfs_fs
|
||||
|
||||
#include "fs_grub_base.c"
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_HFS=fs_hfs.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_HFS}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_HFS=fs_hfs.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_HFS}
|
||||
|
||||
${TARGET_HFS}: ${OBJ_HFS}
|
||||
${CC} $(call libname,fs_hfs) ${LDFLAGS} ${CFLAGS} -o ${TARGET_HFS} ${OBJ_HFS} ${EXTRA}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_HFSPLUS=fs_hfsplus.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_HFSPLUS}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_HFSPLUS=fs_hfsplus.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_HFSPLUS}
|
||||
|
||||
${TARGET_HFSPLUS}: ${OBJ_HFSPLUS}
|
||||
${CC} $(call libname,fs_hfsplus) ${LDFLAGS} ${CFLAGS} -o ${TARGET_HFSPLUS} ${OBJ_HFSPLUS} ${EXTRA}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
OBJ_IO=fs_io.o
|
||||
|
||||
STATIC_OBJ+=${OBJ_IO}
|
||||
TARGET_IO=fs_io.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_IO}
|
||||
|
||||
${TARGET_IO}: ${OBJ_IO}
|
||||
${CC} $(call libname,fs_io) ${LDFLAGS} ${CFLAGS} -o ${TARGET_IO} ${OBJ_IO} ${EXTRA}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_ISO9660=fs_iso9660.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_ISO9660}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_ISO9660=fs_iso9660.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_ISO9660}
|
||||
|
||||
${TARGET_ISO9660}: ${OBJ_ISO9660}
|
||||
${CC} $(call libname,fs_iso9660) ${LDFLAGS} ${CFLAGS} -o ${TARGET_ISO9660} ${OBJ_ISO9660} ${EXTRA}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_JFS=fs_jfs.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_JFS}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_JFS=fs_jfs.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_JFS}
|
||||
|
||||
${TARGET_JFS}: ${OBJ_JFS}
|
||||
${CC} $(call libname,fs_jfs) ${LDFLAGS} ${CFLAGS} -o ${TARGET_JFS} ${OBJ_JFS} ${EXTRA}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
#!/bin/sh
|
||||
# TODO: btrfs does not have READ hook
|
||||
# TODO: cpio | tarfs
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "Use: makeplugin.sh [newplugname]"
|
||||
exit 1
|
||||
fi
|
||||
U=$(echo $1 | tr '[a-z]' '[A-Z]')
|
||||
sed -e s,fat,$1,g -e s,FAT,$U,g fat.mk > $1.mk
|
||||
sed -e s,fat,$1,g -e s,FAT,$U,g fs_fat.c > fs_$1.c
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_MINIX=fs_minix.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_MINIX}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_MINIX=fs_minix.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_MINIX}
|
||||
|
||||
${TARGET_MINIX}: ${OBJ_MINIX}
|
||||
${CC} $(call libname,fs_minix) ${LDFLAGS} ${CFLAGS} -o ${TARGET_MINIX} ${OBJ_MINIX} ${EXTRA}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_NTFS=fs_ntfs.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_NTFS}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_NTFS=fs_ntfs.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_NTFS}
|
||||
|
||||
${TARGET_NTFS}: ${OBJ_NTFS}
|
||||
${CC} $(call libname,fs_ntfs) ${LDFLAGS} ${CFLAGS} -o ${TARGET_NTFS} ${OBJ_NTFS} ${EXTRA}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
/* rizin - LGPL - Copyright 2015-2017 - pancake */
|
||||
|
||||
/* XXX: maybe this should be implemented in RBin */
|
||||
/* we need to extract the code section and get offset flags */
|
||||
|
||||
#include <rz_fs.h>
|
||||
#include <rz_types.h>
|
||||
R_PACKED (
|
||||
typedef struct {
|
||||
ut8 flag; // 0x80 if active
|
||||
ut8 start_head;
|
||||
ut8 start_sector;
|
||||
ut8 start_cylinder;
|
||||
ut8 type;
|
||||
ut8 end_head;
|
||||
ut8 end_sector;
|
||||
ut8 end_cylinder;
|
||||
ut32 start; // sector count (starting from 0)
|
||||
ut32 length; // in sector
|
||||
}) DOS_ENTRY;
|
||||
R_PACKED (
|
||||
typedef struct {
|
||||
ut8 code[446]; // code
|
||||
DOS_ENTRY entries[4];
|
||||
ut16 aa55; // the signature
|
||||
}) MBR;
|
||||
|
||||
static int fs_part_dos(void *disk, void *ptr, void *closure) {
|
||||
int i;
|
||||
MBR mbr;
|
||||
RzFS *fs = (RzFS*)disk;
|
||||
RzFSPartition *par = NULL;
|
||||
RzFSPartitionIterator iterate = (RzFSPartitionIterator)ptr;
|
||||
RzList *list = (RzList*)closure;
|
||||
|
||||
memset (&mbr, 0, sizeof (mbr));
|
||||
fs->iob.read_at (fs->iob.io, 0, (ut8*)&mbr, sizeof (mbr));
|
||||
if (mbr.aa55 != 0xaa55) {
|
||||
eprintf ("Invalid DOS signature at 0x%x\n",
|
||||
(int)rz_offsetof (MBR, aa55));
|
||||
return 0;
|
||||
}
|
||||
for (i=0; i<4; i++) {
|
||||
ut64 addr, aend;
|
||||
DOS_ENTRY *e = &mbr.entries[i];
|
||||
if (e->type != 0) {
|
||||
//int is_active = (e->flag == 0x80);
|
||||
addr = e->start;
|
||||
addr *= 512;
|
||||
|
||||
aend = 0; //e->start;
|
||||
aend += e->length;
|
||||
aend *= 512;
|
||||
par = rz_fs_partition_new (i, addr, aend);
|
||||
par->index = 0;
|
||||
par->type = e->type;
|
||||
iterate (disk, par, list);
|
||||
} else {
|
||||
// TODO: make deleted entries accessible?
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
OBJ_POSIX=fs_posix.o
|
||||
|
||||
STATIC_OBJ+=${OBJ_POSIX}
|
||||
TARGET_POSIX=fs_posix.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_POSIX}
|
||||
|
||||
${TARGET_POSIX}: ${OBJ_POSIX}
|
||||
${CC} $(call libname,fs_posix) ${LDFLAGS} ${CFLAGS} -o ${TARGET_POSIX} ${OBJ_POSIX} ${EXTRA}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_REISERzFS=fs_reiserfs.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_REISERzFS}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_REISERzFS=fs_reiserfs.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_REISERzFS}
|
||||
|
||||
${TARGET_REISERzFS}: ${OBJ_REISERzFS}
|
||||
${CC} $(call libname,fs_reiserfs) ${LDFLAGS} ${CFLAGS} -o ${TARGET_REISERzFS} ${OBJ_REISERzFS} ${EXTRA}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
OBJ_R2=fs_rz.o
|
||||
|
||||
STATIC_OBJ+=${OBJ_R2}
|
||||
TARGET_R2=fs_rz.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_R2}
|
||||
|
||||
${TARGET_R2}: ${OBJ_R2}
|
||||
${CC} $(call libname,fs_rz) ${LDFLAGS} ${CFLAGS} -o ${TARGET_R2} ${OBJ_R2} ${EXTRA}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_SFS=fs_sfs.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_SFS}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_SFS=fs_sfs.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_SFS}
|
||||
|
||||
${TARGET_SFS}: ${OBJ_SFS}
|
||||
${CC} $(call libname,fs_sfs) ${LDFLAGS} ${CFLAGS} -o ${TARGET_SFS} ${OBJ_SFS} ${EXTRA}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_TAR=fs_tar.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_TAR}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_TAR=fs_tar.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_TAR}
|
||||
|
||||
${TARGET_TAR}: ${OBJ_TAR}
|
||||
${CC} $(call libname,fs_tar) ${LDFLAGS} ${CFLAGS} -o ${TARGET_TAR} ${OBJ_TAR} ${EXTRA}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_UDF=fs_udf.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_UDF}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_UDF=fs_udf.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_UDF}
|
||||
|
||||
${TARGET_UDF}: ${OBJ_UDF}
|
||||
${CC} $(call libname,fs_udf) ${LDFLAGS} ${CFLAGS} -o ${TARGET_UDF} ${OBJ_UDF} ${EXTRA}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_UFS=fs_ufs.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_UFS}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_UFS=fs_ufs.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_UFS}
|
||||
|
||||
${TARGET_UFS}: ${OBJ_UFS}
|
||||
${CC} $(call libname,fs_ufs) ${LDFLAGS} ${CFLAGS} -o ${TARGET_UFS} ${OBJ_UFS} ${EXTRA}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_UFS2=fs_ufs2.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_UFS2}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_UFS2=fs_ufs2.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_UFS2}
|
||||
|
||||
${TARGET_UFS2}: ${OBJ_UFS2}
|
||||
${CC} $(call libname,fs_ufs2) ${LDFLAGS} ${CFLAGS} -o ${TARGET_UFS2} ${OBJ_UFS2} ${EXTRA}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
OBJ_XFS=fs_xfs.o
|
||||
EXTRA=$(GRUB)
|
||||
CFLAGS+=-Igrub/include
|
||||
|
||||
STATIC_OBJ+=${OBJ_XFS}
|
||||
#STATIC_OBJ+=${EXTRA}
|
||||
TARGET_XFS=fs_xfs.${EXT_SO}
|
||||
|
||||
ALL_TARGETS+=${TARGET_XFS}
|
||||
|
||||
${TARGET_XFS}: ${OBJ_XFS}
|
||||
${CC} $(call libname,fs_xfs) ${LDFLAGS} ${CFLAGS} -o ${TARGET_XFS} ${OBJ_XFS} ${EXTRA}
|
||||
312
librz/fs/shell.c
312
librz/fs/shell.c
|
|
@ -1,312 +0,0 @@
|
|||
/* rizin - LGPL - Copyright 2018-2020 - pancake */
|
||||
|
||||
#include <rz_fs.h>
|
||||
|
||||
#define PROMPT_PATH_BUFSIZE 1024
|
||||
|
||||
static bool handlePipes(RzFS *fs, char *msg, const ut8 *data, const char *cwd) {
|
||||
char *red = strchr (msg, '>');
|
||||
if (!red) {
|
||||
return false;
|
||||
}
|
||||
*red++ = 0;
|
||||
rz_str_trim (msg);
|
||||
red = rz_str_trim_dup (red);
|
||||
if (*red != '/') {
|
||||
char *blu = rz_str_newf ("%s/%s", cwd, red);
|
||||
free (red);
|
||||
red = blu;
|
||||
}
|
||||
RzFSFile *f = rz_fs_open (fs, red, true);
|
||||
if (!f) {
|
||||
eprintf ("Cannot open %s for writing\n", red);
|
||||
free (red);
|
||||
return true;
|
||||
}
|
||||
rz_fs_write (fs, f, 0, data ? data : (ut8*)msg, strlen (data ? (char*)data : msg));
|
||||
free (red);
|
||||
rz_fs_close (fs, f);
|
||||
rz_fs_file_free (f);
|
||||
return true;
|
||||
}
|
||||
|
||||
RZ_API int rz_fs_shell_prompt(RzFSShell* shell, RzFS* fs, const char* root) {
|
||||
char buf[PROMPT_PATH_BUFSIZE];
|
||||
char path[PROMPT_PATH_BUFSIZE];
|
||||
char prompt[PROMPT_PATH_BUFSIZE];
|
||||
char str[2048];
|
||||
char* input;
|
||||
const char* ptr;
|
||||
RzList* list = NULL;
|
||||
RzListIter* iter;
|
||||
RzFSFile* file = NULL;
|
||||
|
||||
if (root && *root) {
|
||||
strncpy (buf, root, sizeof (buf) - 1);
|
||||
rz_str_trim_path (buf);
|
||||
list = rz_fs_root (fs, buf);
|
||||
if (rz_list_empty (list)) {
|
||||
printf ("Unknown root\n");
|
||||
rz_list_free (list);
|
||||
return false;
|
||||
}
|
||||
rz_str_ncpy (path, buf, sizeof (path) - 1);
|
||||
} else {
|
||||
strcpy (path, "/");
|
||||
}
|
||||
|
||||
PrintfCallback cb_printf = fs->csb.cb_printf;
|
||||
for (;;) {
|
||||
snprintf (prompt, sizeof (prompt), "[%.*s]> ", (int)sizeof (prompt) - 5, path);
|
||||
if (shell) {
|
||||
*shell->cwd = strdup (path);
|
||||
if (shell->set_prompt) {
|
||||
shell->set_prompt (prompt);
|
||||
}
|
||||
if (shell->readline) {
|
||||
ptr = shell->readline ();
|
||||
} else {
|
||||
if (!fgets (buf, sizeof (buf), stdin)) {
|
||||
break;
|
||||
}
|
||||
if (feof (stdin)) {
|
||||
break;
|
||||
}
|
||||
rz_str_trim_tail (buf);
|
||||
ptr = buf;
|
||||
}
|
||||
if (!ptr) {
|
||||
break;
|
||||
}
|
||||
rz_str_trim ((char *)ptr); // XXX abadidea
|
||||
if (shell->hist_add) {
|
||||
shell->hist_add (ptr);
|
||||
}
|
||||
if (ptr != buf) {
|
||||
rz_str_ncpy (buf, ptr, sizeof (buf) - 1);
|
||||
}
|
||||
} else {
|
||||
printf ("%s", prompt);
|
||||
if (!fgets (buf, sizeof (buf), stdin)) {
|
||||
break;
|
||||
}
|
||||
if (feof (stdin)) {
|
||||
break;
|
||||
}
|
||||
rz_str_trim_tail (buf);
|
||||
}
|
||||
char *wave = strchr (buf, '~');
|
||||
if (wave) {
|
||||
*wave++ = 0;
|
||||
}
|
||||
|
||||
if (!strcmp (buf, "q") || !strcmp (buf, "exit")) {
|
||||
rz_list_free (list);
|
||||
return true;
|
||||
}
|
||||
if (buf[0] == '#') {
|
||||
// comment
|
||||
continue;
|
||||
} else if (buf[0] == ':') {
|
||||
char *msg = fs->cob.cmdstr (fs->cob.core, buf + 1);
|
||||
printf ("%s\n", msg);
|
||||
free (msg);
|
||||
} else if (buf[0] == '!') {
|
||||
rz_sandbox_system (buf + 1, 1);
|
||||
} else if (!strncmp (buf, "echo", 4)) {
|
||||
char *msg = rz_str_trim_dup (buf + 4);
|
||||
if (!handlePipes (fs, msg, NULL, path)) {
|
||||
cb_printf ("%s\n", msg);
|
||||
}
|
||||
free (msg);
|
||||
} else if (!strncmp (buf, "ls", 2)) {
|
||||
char *ptr = str;
|
||||
rz_list_free (list);
|
||||
if (buf[2] == ' ') {
|
||||
if (buf[3] != '/') {
|
||||
strncpy (str, path, sizeof (str) - 1);
|
||||
strcat (str, "/");
|
||||
strncat (str, buf + 3, sizeof (buf) - 1);
|
||||
list = rz_fs_dir (fs, str);
|
||||
} else {
|
||||
list = rz_fs_dir (fs, buf + 3);
|
||||
ptr = buf + 3;
|
||||
}
|
||||
} else {
|
||||
ptr = path;
|
||||
list = rz_fs_dir (fs, path);
|
||||
}
|
||||
if (list) {
|
||||
rz_list_foreach (list, iter, file) {
|
||||
cb_printf ("%c %s\n", file->type, file->name);
|
||||
}
|
||||
}
|
||||
// mountpoints if any
|
||||
RzFSRoot *r;
|
||||
char *me = strdup (ptr);
|
||||
rz_list_foreach (fs->roots, iter, r) {
|
||||
char *base = strdup (r->path);
|
||||
char *ls = (char *)rz_str_lchr (base, '/');
|
||||
if (ls) {
|
||||
ls++;
|
||||
*ls = 0;
|
||||
}
|
||||
// TODO: adjust contents between //
|
||||
if (!strcmp (me, base)) {
|
||||
cb_printf ("m %s\n", (r->path && r->path[0]) ? r->path + 1: "");
|
||||
}
|
||||
free (base);
|
||||
}
|
||||
free (me);
|
||||
} else if (!strncmp (buf, "pwd", 3)) {
|
||||
eprintf ("%s\n", path);
|
||||
} else if (!memcmp (buf, "cd ", 3)) {
|
||||
char opath[PROMPT_PATH_BUFSIZE];
|
||||
rz_str_ncpy (opath, path, sizeof (opath));
|
||||
input = buf + 3;
|
||||
while (*input == ' ') {
|
||||
input++;
|
||||
}
|
||||
if (!strcmp (input, "..")) {
|
||||
char* p = (char*) rz_str_lchr (path, '/');
|
||||
if (p) {
|
||||
p[(p == path)? 1: 0] = 0;
|
||||
}
|
||||
} else {
|
||||
strcat (path, "/");
|
||||
if (*input == '/') {
|
||||
strncpy (path, input, sizeof (opath) - 1);
|
||||
} else {
|
||||
if ((strlen (path) + strlen (input)) >= sizeof (path)) {
|
||||
// overflow
|
||||
path[0] = 0;
|
||||
} else {
|
||||
strcat (path, input);
|
||||
}
|
||||
}
|
||||
path[sizeof (path) - 1] = 0;
|
||||
}
|
||||
rz_str_trim_path (path);
|
||||
rz_list_free (list);
|
||||
list = rz_fs_dir (fs, path);
|
||||
if (rz_list_empty (list)) {
|
||||
RzFSRoot *r;
|
||||
RzListIter *iter;
|
||||
rz_list_foreach (fs->roots, iter, r) {
|
||||
if (!strcmp (path, r->path)) {
|
||||
rz_list_append (list, r->path);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!memcmp (buf, "cat ", 4)) {
|
||||
input = buf + 3;
|
||||
while (input[0] == ' ') {
|
||||
input++;
|
||||
}
|
||||
if (input[0] == '/') {
|
||||
if (root) {
|
||||
strncpy (str, root, sizeof (str) - 1);
|
||||
} else {
|
||||
str[0] = 0;
|
||||
}
|
||||
} else {
|
||||
strncpy (str, path, sizeof (str) - 1);
|
||||
}
|
||||
strncat (str, "/", sizeof (str) - strlen (str) - 1);
|
||||
strncat (str, input, sizeof (str) - strlen (str) - 1);
|
||||
char *p = strchr (str, '>');
|
||||
if (p) {
|
||||
*p = 0;
|
||||
}
|
||||
file = rz_fs_open (fs, str, false);
|
||||
if (file) {
|
||||
if (p) {
|
||||
*p = '>';
|
||||
}
|
||||
rz_fs_read (fs, file, 0, file->size);
|
||||
if (!handlePipes (fs, str, file->data, path)) {
|
||||
char *s = rz_str_ndup ((const char *)file->data, file->size);
|
||||
cb_printf ("%s\n", s);
|
||||
free (s);
|
||||
}
|
||||
cb_printf ("\n");
|
||||
rz_fs_close (fs, file);
|
||||
} else {
|
||||
eprintf ("Cannot open file\n");
|
||||
}
|
||||
} else if (!memcmp (buf, "mount", 5)) {
|
||||
RzFSRoot* r;
|
||||
rz_list_foreach (fs->roots, iter, r) {
|
||||
cb_printf ("%s %s\n", r->path, r->p->name);
|
||||
}
|
||||
} else if (!memcmp (buf, "get ", 4)) {
|
||||
char* s = 0;
|
||||
input = buf + 3;
|
||||
while (input[0] == ' ') {
|
||||
input++;
|
||||
}
|
||||
if (input[0] == '/') {
|
||||
if (root) {
|
||||
s = malloc (strlen (root) + strlen (input) + 2);
|
||||
if (!s) {
|
||||
goto beach;
|
||||
}
|
||||
strcpy (s, root);
|
||||
}
|
||||
} else {
|
||||
s = malloc (strlen (path) + strlen (input) + 2);
|
||||
if (!s) {
|
||||
goto beach;
|
||||
}
|
||||
strcpy (s, path);
|
||||
}
|
||||
if (!s) {
|
||||
s = calloc (strlen (input) + 32, 1);
|
||||
if (!s) {
|
||||
goto beach;
|
||||
}
|
||||
}
|
||||
strcat (s, "/");
|
||||
strcat (s, input);
|
||||
file = rz_fs_open (fs, s, false);
|
||||
if (file) {
|
||||
rz_fs_read (fs, file, 0, file->size);
|
||||
rz_file_dump (input, file->data, file->size, 0);
|
||||
rz_fs_close (fs, file);
|
||||
} else {
|
||||
input -= 2; //OMFG!!!! O_O
|
||||
memcpy (input, "./", 2);
|
||||
if (!rz_fs_dir_dump (fs, s, input)) {
|
||||
eprintf ("Cannot open file\n");
|
||||
}
|
||||
}
|
||||
free (s);
|
||||
} else if (!memcmp (buf, "help", 4) || !strcmp (buf, "?")) {
|
||||
cb_printf (
|
||||
"Usage: [command (arguments)]([~grep-expression])\n"
|
||||
" !cmd ; escape to system\n"
|
||||
" :cmd ; escape to the r2 repl\n"
|
||||
" ls [path] ; list current directory\n"
|
||||
" cd path ; change current directory\n"
|
||||
" cat file ; print contents of file\n"
|
||||
" get file ; dump file to disk\n"
|
||||
" mount ; list mount points\n"
|
||||
" q/exit ; leave prompt mode\n"
|
||||
" ?/help ; show this help\n");
|
||||
} else {
|
||||
if (*buf) {
|
||||
eprintf ("Unknown command %s\n", buf);
|
||||
}
|
||||
}
|
||||
if (wave) {
|
||||
fs->csb.cb_grep (wave);
|
||||
}
|
||||
fs->csb.cb_flush ();
|
||||
}
|
||||
beach:
|
||||
clearerr (stdin);
|
||||
printf ("\n");
|
||||
rz_list_free (list);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
ml
|
||||
m ext2 /foo
|
||||
md /foo
|
||||
mg /foo/test
|
||||
m-/foo
|
||||
m
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
#ifndef FS_TYPES_H
|
||||
#define FS_TYPES_H
|
||||
|
||||
typedef struct rz_fs_type_t {
|
||||
const char *name;
|
||||
int bufoff;
|
||||
const char *buf;
|
||||
int buflen;
|
||||
int byteoff;
|
||||
ut8 byte;
|
||||
int bytelen;
|
||||
} RzFSType;
|
||||
|
||||
static RzFSType fstypes[] = {
|
||||
{ "hfs", 0x400, "BD", 2, 0, 0, 0x400 },
|
||||
{ "hfsplus", 0x400, "H+", 2, 0, 0, 0x400 },
|
||||
{ "fat", 0x36, "FAT12", 5, 0, 0, 0 },
|
||||
{ "fat", 0x52, "FAT32", 5, 0, 0, 0 },
|
||||
{ "ext2", 0x438, "\x53\xef", 2, 0, 0, 0 },
|
||||
{ "btrfs", 0x10040, "_BHRfS_M", 8, 0, 0, 0x0 },
|
||||
{ "iso9660", 0x8000, "\x01" "CD0", 4, 0, 0, 0x8000 },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -9,7 +9,6 @@
|
|||
#include "rz_magic.h"
|
||||
#include "rz_agraph.h"
|
||||
#include "rz_io.h"
|
||||
#include "rz_fs.h"
|
||||
#include "rz_lib.h"
|
||||
#include "rz_diff.h"
|
||||
#include "rz_egg.h"
|
||||
|
|
@ -272,8 +271,6 @@ struct rz_core_t {
|
|||
RzDebug *dbg;
|
||||
RzFlag *flags;
|
||||
RzSearch *search;
|
||||
RzFS *fs;
|
||||
RzFSShell *rfs;
|
||||
RzEgg *egg;
|
||||
RzCoreLog *log;
|
||||
RzAGraph *graph;
|
||||
|
|
|
|||
|
|
@ -1,181 +0,0 @@
|
|||
#ifndef R2_FS_H
|
||||
#define R2_FS_H
|
||||
|
||||
#include <rz_types.h>
|
||||
#include <rz_list.h>
|
||||
#include <rz_bind.h> // RzCoreBind
|
||||
#include <rz_io.h> // RzIOBind
|
||||
#include <rz_util.h>
|
||||
#include <rz_cons.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
R_LIB_VERSION_HEADER (rz_fs);
|
||||
|
||||
struct rz_fs_plugin_t;
|
||||
struct rz_fs_root_t;
|
||||
struct rz_fs_t;
|
||||
|
||||
typedef struct rz_fs_t {
|
||||
RzIOBind iob;
|
||||
RzCoreBind cob;
|
||||
RzConsBind csb;
|
||||
RzList /*<RzFSPlugin>*/ *plugins;
|
||||
RzList /*<RzFSRoot>*/ *roots;
|
||||
int view;
|
||||
void *ptr;
|
||||
} RzFS;
|
||||
|
||||
typedef struct rz_fs_partition_plugin_t {
|
||||
const char *name;
|
||||
} RzFSPartitionPlugin;
|
||||
|
||||
typedef struct rz_fs_file_t {
|
||||
char *name;
|
||||
char *path;
|
||||
ut64 off;
|
||||
ut32 size;
|
||||
ut8 *data;
|
||||
void *ctx;
|
||||
char type;
|
||||
ut64 time;
|
||||
struct rz_fs_plugin_t *p;
|
||||
struct rz_fs_root_t *root;
|
||||
void *ptr; // internal pointer
|
||||
} RzFSFile;
|
||||
|
||||
typedef struct rz_fs_root_t {
|
||||
char *path;
|
||||
ut64 delta;
|
||||
struct rz_fs_plugin_t *p;
|
||||
void *ptr;
|
||||
// TODO: deprecate
|
||||
RzIOBind iob;
|
||||
RzCoreBind cob;
|
||||
} RzFSRoot;
|
||||
|
||||
typedef struct rz_fs_plugin_t {
|
||||
const char *name;
|
||||
const char *desc;
|
||||
const char *license;
|
||||
RzFSFile* (*slurp)(RzFSRoot *root, const char *path);
|
||||
RzFSFile* (*open)(RzFSRoot *root, const char *path, bool create);
|
||||
bool (*unlink)(RzFSRoot *root, const char *path);
|
||||
bool (*write)(RzFSFile *fs, ut64 addr, const ut8 *data, int len);
|
||||
bool (*read)(RzFSFile *fs, ut64 addr, int len);
|
||||
void (*close)(RzFSFile *fs);
|
||||
RzList *(*dir)(RzFSRoot *root, const char *path, int view);
|
||||
void (*init)(void);
|
||||
void (*fini)(void);
|
||||
int (*mount)(RzFSRoot *root);
|
||||
void (*umount)(RzFSRoot *root);
|
||||
} RzFSPlugin;
|
||||
|
||||
typedef struct rz_fs_partition_t {
|
||||
int number;
|
||||
ut64 start;
|
||||
ut64 length;
|
||||
int index;
|
||||
int type;
|
||||
} RzFSPartition;
|
||||
|
||||
typedef struct rz_fs_shell_t {
|
||||
char **cwd;
|
||||
void (*set_prompt)(const char *prompt);
|
||||
const char* (*readline)(void);
|
||||
int (*hist_add)(const char *line);
|
||||
} RzFSShell;
|
||||
|
||||
#define R_FS_FILE_TYPE_MOUNTPOINT 'm'
|
||||
#define R_FS_FILE_TYPE_DIRECTORY 'd'
|
||||
#define R_FS_FILE_TYPE_REGULAR 'r'
|
||||
#define R_FS_FILE_TYPE_DELETED 'x'
|
||||
#define R_FS_FILE_TYPE_SPECIAL 's'
|
||||
#define R_FS_FILE_TYPE_MOUNT 'm'
|
||||
|
||||
typedef int (*RzFSPartitionIterator)(void *disk, void *ptr, void *user);
|
||||
typedef struct rz_fs_partition_type_t {
|
||||
const char *name;
|
||||
void *ptr; // grub_msdos_partition_map
|
||||
RzFSPartitionIterator iterate;
|
||||
//RzFSPartitionIterator parhook;
|
||||
} RzFSPartitionType;
|
||||
#define R_FS_PARTITIONS_LENGTH (int)(sizeof (partitions)/sizeof(RzFSPartitionType)-1)
|
||||
|
||||
enum {
|
||||
R_FS_VIEW_NORMAL = 0,
|
||||
R_FS_VIEW_DELETED = 1,
|
||||
R_FS_VIEW_SPECIAL = 2,
|
||||
R_FS_VIEW_ALL = 0xff,
|
||||
};
|
||||
|
||||
#ifdef RZ_API
|
||||
RZ_API RzFS *rz_fs_new(void);
|
||||
RZ_API void rz_fs_view(RzFS* fs, int view);
|
||||
RZ_API void rz_fs_free(RzFS* fs);
|
||||
RZ_API void rz_fs_add(RzFS *fs, RzFSPlugin *p);
|
||||
RZ_API void rz_fs_del(RzFS *fs, RzFSPlugin *p);
|
||||
RZ_API RzFSRoot *rz_fs_mount(RzFS* fs, const char *fstype, const char *path, ut64 delta);
|
||||
RZ_API bool rz_fs_umount(RzFS* fs, const char *path);
|
||||
RZ_API RzList *rz_fs_root(RzFS *fs, const char *path);
|
||||
RZ_API RzFSFile *rz_fs_open(RzFS* fs, const char *path, bool create);
|
||||
RZ_API void rz_fs_close(RzFS* fs, RzFSFile *file);
|
||||
RZ_API int rz_fs_read(RzFS* fs, RzFSFile *file, ut64 addr, int len);
|
||||
RZ_API int rz_fs_write(RzFS* fs, RzFSFile* file, ut64 addr, const ut8 *data, int len);
|
||||
RZ_API RzFSFile *rz_fs_slurp(RzFS* fs, const char *path);
|
||||
RZ_API RzList *rz_fs_dir(RzFS* fs, const char *path);
|
||||
RZ_API int rz_fs_dir_dump(RzFS* fs, const char *path, const char *name);
|
||||
RZ_API RzList *rz_fs_find_name(RzFS* fs, const char *name, const char *glob);
|
||||
RZ_API RzList *rz_fs_find_off(RzFS* fs, const char *name, ut64 off);
|
||||
RZ_API RzList *rz_fs_partitions(RzFS* fs, const char *ptype, ut64 delta);
|
||||
RZ_API char *rz_fs_name(RzFS *fs, ut64 offset);
|
||||
RZ_API int rz_fs_prompt(RzFS *fs, const char *root);
|
||||
RZ_API bool rz_fs_check(RzFS *fs, const char *p);
|
||||
RZ_API int rz_fs_shell_prompt(RzFSShell *shell, RzFS *fs, const char *root);
|
||||
|
||||
/* file.c */
|
||||
RZ_API RzFSFile *rz_fs_file_new(RzFSRoot *root, const char *path);
|
||||
RZ_API void rz_fs_file_free(RzFSFile *file);
|
||||
RZ_API char* rz_fs_file_copy_abs_path(RzFSFile* file);
|
||||
RZ_API RzFSRoot *rz_fs_root_new(const char *path, ut64 delta);
|
||||
RZ_API void rz_fs_root_free(RzFSRoot *root);
|
||||
RZ_API RzFSPartition *rz_fs_partition_new(int num, ut64 start, ut64 length);
|
||||
RZ_API void rz_fs_partition_free(RzFSPartition *p);
|
||||
RZ_API const char *rz_fs_partition_type(const char *part, int type);
|
||||
RZ_API const char *rz_fs_partition_type_get(int n);
|
||||
RZ_API int rz_fs_partition_get_size(void); // WTF. wrong function name
|
||||
|
||||
/* plugins */
|
||||
extern RzFSPlugin rz_fs_plugin_io;
|
||||
extern RzFSPlugin rz_fs_plugin_rz;
|
||||
extern RzFSPlugin rz_fs_plugin_ext2;
|
||||
extern RzFSPlugin rz_fs_plugin_fat;
|
||||
extern RzFSPlugin rz_fs_plugin_ntfs;
|
||||
extern RzFSPlugin rz_fs_plugin_hfs;
|
||||
extern RzFSPlugin rz_fs_plugin_hfsplus;
|
||||
extern RzFSPlugin rz_fs_plugin_reiserfs;
|
||||
extern RzFSPlugin rz_fs_plugin_tar;
|
||||
extern RzFSPlugin rz_fs_plugin_iso9660;
|
||||
extern RzFSPlugin rz_fs_plugin_udf;
|
||||
extern RzFSPlugin rz_fs_plugin_ufs;
|
||||
extern RzFSPlugin rz_fs_plugin_ufs2;
|
||||
extern RzFSPlugin rz_fs_plugin_sfs;
|
||||
extern RzFSPlugin rz_fs_plugin_tar;
|
||||
extern RzFSPlugin rz_fs_plugin_btrfs;
|
||||
extern RzFSPlugin rz_fs_plugin_jfs;
|
||||
extern RzFSPlugin rz_fs_plugin_afs;
|
||||
extern RzFSPlugin rz_fs_plugin_affs;
|
||||
extern RzFSPlugin rz_fs_plugin_cpio;
|
||||
extern RzFSPlugin rz_fs_plugin_xfs;
|
||||
extern RzFSPlugin rz_fs_plugin_fb;
|
||||
extern RzFSPlugin rz_fs_plugin_minix;
|
||||
extern RzFSPlugin rz_fs_plugin_posix;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -81,7 +81,6 @@ enum {
|
|||
R_LIB_TYPE_CRYPTO, /* cryptography */
|
||||
R_LIB_TYPE_CORE, /* RzCore commands */
|
||||
R_LIB_TYPE_EGG, /* rz_egg plugin */
|
||||
R_LIB_TYPE_FS, /* rz_fs plugin */
|
||||
R_LIB_TYPE_LAST
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ ifeq ($(LIBS0),)
|
|||
LIBS0=util
|
||||
LIBS1=socket hash reg cons magic bp search config
|
||||
LIBS2=syscall lang crypto io flag
|
||||
LIBS3=fs parse bin
|
||||
LIBS3=parse bin
|
||||
LIBS4=asm
|
||||
LIBS5=anal egg
|
||||
LIBS6=debug
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ MAIN_LINK_ALL=1
|
|||
ifeq ($(MAIN_LINK_ALL),1)
|
||||
R2DEPS=rz_config rz_cons rz_io rz_util rz_flag rz_asm rz_core
|
||||
R2DEPS+=rz_debug rz_hash rz_bin rz_lang rz_io rz_anal rz_parse rz_bp rz_egg
|
||||
R2DEPS+=rz_reg rz_search rz_syscall rz_socket rz_fs rz_magic rz_crypto
|
||||
R2DEPS+=rz_reg rz_search rz_syscall rz_socket rz_magic rz_crypto
|
||||
else
|
||||
# only works
|
||||
WITH_LIBS=0
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ rz_main_deps = [
|
|||
rz_search_dep,
|
||||
rz_syscall_dep,
|
||||
rz_socket_dep,
|
||||
rz_fs_dep,
|
||||
rz_magic_dep,
|
||||
rz_crypto_dep
|
||||
]
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ static int rz_main_version_verify(int show) {
|
|||
{ "rz_debug", rz_debug_version },
|
||||
{ "rz_main", rz_main_version },
|
||||
{ "rz_hash", rz_hash_version },
|
||||
{ "rz_fs", rz_fs_version },
|
||||
{ "rz_io", rz_io_version },
|
||||
#if !USE_LIB_MAGIC
|
||||
{ "rz_magic", rz_magic_version },
|
||||
|
|
|
|||
|
|
@ -138,7 +138,6 @@ bin_plugins = [
|
|||
'dyldcache',
|
||||
'elf',
|
||||
'elf64',
|
||||
'fs',
|
||||
'java',
|
||||
'le',
|
||||
'mach0',
|
||||
|
|
@ -239,29 +238,6 @@ egg_plugins = [
|
|||
'xor'
|
||||
]
|
||||
|
||||
fs_plugins = [
|
||||
'cpio',
|
||||
'ext2',
|
||||
'fat',
|
||||
'fb',
|
||||
'hfs',
|
||||
'hfsplus',
|
||||
'io',
|
||||
'iso9660',
|
||||
'jfs',
|
||||
'minix',
|
||||
'ntfs',
|
||||
'posix',
|
||||
'rz',
|
||||
'reiserfs',
|
||||
'sfs',
|
||||
'tar',
|
||||
'udf',
|
||||
'ufs',
|
||||
'ufs2',
|
||||
'xfs'
|
||||
]
|
||||
|
||||
io_plugins = [
|
||||
'ar',
|
||||
'fd',
|
||||
|
|
@ -359,7 +335,6 @@ include_files =[
|
|||
'include/rz_endian.h',
|
||||
'include/rz_flag.h',
|
||||
'include/rz_flist.h',
|
||||
'include/rz_fs.h',
|
||||
'include/rz_hash.h',
|
||||
'include/rz_heap_glibc.h',
|
||||
'include/rz_heap_jemalloc.h',
|
||||
|
|
|
|||
|
|
@ -226,7 +226,6 @@ conf_data.set('plugins_bin_ldr', '&rz_bin_ldr_plugin_' + ', &rz_bin_ldr_plugin_'
|
|||
conf_data.set('plugins_bin_xtr', '&rz_bin_xtr_plugin_' + ', &rz_bin_xtr_plugin_'.join(bin_xtr_plugins) + ', 0')
|
||||
conf_data.set('plugins_crypto', '&rz_crypto_plugin_' + ', &rz_crypto_plugin_'.join(crypto_plugins) + ', 0')
|
||||
conf_data.set('plugins_io', '&rz_io_plugin_' + ', &rz_io_plugin_'.join(io_plugins) + ', 0')
|
||||
conf_data.set('plugins_fs', '&rz_fs_plugin_' + ', &rz_fs_plugin_'.join(fs_plugins) + ', 0')
|
||||
conf_data.set('plugins_debug', '&rz_debug_plugin_' + ', &rz_debug_plugin_'.join(debug_plugins) + ', 0')
|
||||
conf_data.set('plugins_egg', '&rz_egg_plugin_' + ', &rz_egg_plugin_'.join(egg_plugins) + ', 0')
|
||||
conf_data.set('plugins_lang', '&rz_lang_plugin_' + ', &rz_lang_plugin_'.join(lang_plugins) + ', 0')
|
||||
|
|
@ -585,7 +584,6 @@ subdir('librz/lang')
|
|||
subdir('librz/asm')
|
||||
subdir('librz/anal')
|
||||
subdir('librz/egg')
|
||||
subdir('librz/fs')
|
||||
subdir('librz/debug')
|
||||
subdir('librz/core')
|
||||
|
||||
|
|
@ -639,7 +637,6 @@ if meson.is_subproject()
|
|||
rz_debug_dep,
|
||||
rz_egg_dep,
|
||||
rz_flag_dep,
|
||||
rz_fs_dep,
|
||||
rz_hash_dep,
|
||||
rz_io_dep,
|
||||
rz_lang_dep,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,6 @@ includedir=${prefix}/include
|
|||
Name: rz_core
|
||||
Description: radare foundation libraries
|
||||
Version: @VERSION@
|
||||
Requires: rz_config rz_cons rz_io rz_util rz_flag rz_asm rz_debug rz_hash rz_bin rz_lang rz_io rz_anal rz_parse rz_bp rz_egg rz_reg rz_search rz_syscall rz_socket rz_fs rz_magic rz_crypto
|
||||
Requires: rz_config rz_cons rz_io rz_util rz_flag rz_asm rz_debug rz_hash rz_bin rz_lang rz_io rz_anal rz_parse rz_bp rz_egg rz_reg rz_search rz_syscall rz_socket rz_magic rz_crypto
|
||||
Libs: -L${libdir} -lrz_core @SSL_LDFLAGS@ @CAPSTONE_LDFLAGS@
|
||||
Cflags: -I${includedir}/librz @SSL_CFLAGS@ @CAPSTONE_CFLAGS@
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
prefix=@PREFIX@
|
||||
exec_prefix=${prefix}
|
||||
libdir=@LIBDIR@
|
||||
includedir=${prefix}/include
|
||||
|
||||
Name: rz_fs
|
||||
Description: radare foundation libraries
|
||||
Version: @VERSION@
|
||||
Requires: rz_util rz_io
|
||||
Libs: -L${libdir} -lrz_fs
|
||||
Cflags: -I${includedir}/librz
|
||||
|
|
@ -58,14 +58,6 @@ debug.bf
|
|||
debug.io
|
||||
egg.exec
|
||||
egg.xor
|
||||
fs.io
|
||||
fs.fat
|
||||
fs.ntfs
|
||||
fs.ext2
|
||||
fs.hfs
|
||||
fs.hfsplus
|
||||
fs.reiserfs
|
||||
fs.posix
|
||||
io.debug
|
||||
io.rap
|
||||
io.gzip
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue