Skip to content

Commit

Permalink
pfo files must be .h or .r2 ##print
Browse files Browse the repository at this point in the history
  • Loading branch information
trufae authored Dec 21, 2024
1 parent 790eed9 commit 552d65a
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 37 deletions.
12 changes: 5 additions & 7 deletions libr/bin/d/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ clean:

.PHONY: all clean install install-symlink symstall uninstall

FORMATS=dex macho elf32 elf64 elf_enums pe32 trx mz zip symclass.sdb

install: $(F_SDB)
@echo "[i] Installing bin format files"
rm -rf "$P"
mkdir -p "$P"
-cp -f $(FORMATS) "$P" || true
-cp -f *.r2 *.h "$P" || true
-cp -f symclass.sdb "$P" || true
mkdir -p "$P/dll"
cp -f dll/*.sdb "$P/dll"

Expand All @@ -53,10 +52,9 @@ symclass.sdb:
CWD=$(shell pwd)
symstall install-symlink: symclass.sdb
mkdir -p "$P"
for FILE in * ; do \
if [ "$$FILE" != Makefile ]; then \
[ ! -d "$P/$$FILE" ] && ln -fs "${CWD}/$$FILE" "$P/$$FILE" ; \
fi ; \
rm -rf "$P/dll"
for FILE in *.r2 *.h dll symclass.sdb ; do \
[ ! -d "$P/$$FILE" ] && ln -fs "${CWD}/$$FILE" "$P/$$FILE" ; \
done

$(DLL_SDB):
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion libr/bin/d/elf32 → libr/bin/d/elf32.r2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pfo elf_enums
pfo elf_enums.r2
pf.elf_ident [4]z[1]E[1]E[1]E.:: magic (elf_class)class (elf_data)data (elf_hdr_version)version
pf.elf_header ?[2]E[2]E[4]ExxxxN2N2N2N2N2N2 (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx
pf.elf_phdr [4]Exxxxx[4]Ex (elf_p_type)type offset vaddr paddr filesz memsz (elf_p_flags)flags align
Expand Down
2 changes: 1 addition & 1 deletion libr/bin/d/elf64 → libr/bin/d/elf64.r2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pfo elf_enums
pfo elf_enums.r2
pf.elf_ident [4]z[1]E[1]E[1]E.:: magic (elf_class)class (elf_data)data (elf_hdr_version)version
pf.elf_header ?[2]E[2]E[4]EqqqxN2N2N2N2N2N2 (elf_ident)ident (elf_type)type (elf_machine)machine (elf_obj_version)version entry phoff shoff flags ehsize phentsize phnum shentsize shnum shstrndx
pf.elf_phdr [4]E[4]Eqqqqqq (elf_p_type)type (elf_p_flags)flags offset vaddr paddr filesz memsz align
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 15 additions & 9 deletions libr/bin/d/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,21 @@ foreach file : sdb_files
endforeach

format_files = [
'dex',
'macho',
'elf32',
'elf64',
'elf_enums',
'pe32',
'trx',
'mz',
'zip'
'cdex.h',
'dex.h',
'jni.h',
'bios.r2',
'dex.r2',
'elf32.r2',
'elf64.r2',
'elf_enums.r2',
'fatmacho.r2',
'macho.r2',
'mz.r2',
'ntfs.r2',
'pe32.r2',
'trx.r2',
'zip.r2',
]

install_data(format_files,
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion libr/bin/d/pe32 → libr/bin/d/pe32.r2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pfo mz
pfo mz.r2
pf.pe_nt_image_headers32 [4]z?? signature (pe_image_file_header)fileHeader (pe_image_optional_header32)optionalHeader
pf.pe_image_optional_header32 [2]Ebbxxxxxxxxxwwwwwwxxxx[2]E[2]Bxxxxxx[16]? (pe_magic)magic majorLinkerVersion minorLinkerVersion sizeOfCode sizeOfInitializedData sizeOfUninitializedData addressOfEntryPoint baseOfCode baseOfData imageBase sectionAlignment fileAlignment majorOperatingSystemVersion minorOperatingSystemVersion majorImageVersion minorImageVersion majorSubsystemVersion minorSubsystemVersion win32VersionValue sizeOfImage sizeOfHeaders checkSum (pe_subsystem)subsystem (pe_dllcharacteristics)dllCharacteristics sizeOfStackReserve sizeOfStackCommit sizeOfHeapReserve sizeOfHeapCommit loaderFlags numberOfRvaAndSizes (pe_image_data_directory)dataDirectory
pf.pe_image_file_header [2]Ewtxxw[2]B (pe_machine)machine numberOfSections timeDateStamp pointerToSymbolTable numberOfSymbols sizeOfOptionalHeader (pe_characteristics)characteristics
Expand Down
File renamed without changes.
File renamed without changes.
33 changes: 25 additions & 8 deletions libr/core/cmd_print.inc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,17 @@ static void cmd_pfb(RCore *core, const char *_input) {
}
}

static bool is_pfo_file(const char *fn) {
if (*fn != '.') {
if (r_str_endswith (fn, ".r2")) {
return true;
}
if (r_str_endswith (fn, ".h")) {
return true;
}
}
return false;
}
static void cmd_print_format(RCore *core, const char *_input, const ut8* block, int len) {
char *input = NULL;
bool v2 = false;
Expand Down Expand Up @@ -2234,23 +2245,29 @@ static void cmd_print_format(RCore *core, const char *_input, const ut8* block,
char *home = r_xdg_datadir ("format");
if (home) {
files = r_sys_dir (home);
r_list_foreach (files, iter, fn) {
if (*fn != '.') {
r_cons_println (fn);
if (files) {
r_list_sort (files, (RListComparator)strcmp);
r_list_foreach (files, iter, fn) {
if (is_pfo_file (fn)) {
r_cons_println (fn);
}
}
r_list_free (files);
}
r_list_free (files);
free (home);
}
char *path = r_str_r2_prefix (R2_SDB_FORMAT R_SYS_DIR);
if (path) {
files = r_sys_dir (path);
r_list_foreach (files, iter, fn) {
if (*fn != '.') {
r_cons_println (fn);
if (files) {
r_list_sort (files, (RListComparator)strcmp);
r_list_foreach (files, iter, fn) {
if (is_pfo_file (fn)) {
r_cons_println (fn);
}
}
r_list_free (files);
}
r_list_free (files);
free (path);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/db/cmd/cmd_pf2
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ RUN
NAME=pf?
FILE=-
CMDS=<<EOF
pfo elf32
pfo elf32.r2
pf?elf_header
pf? elf_header
EOF
Expand Down
18 changes: 9 additions & 9 deletions test/db/cmd/cmd_pf_elf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
NAME=32: Elf header size
FILE=malloc://1024
CMDS=<<EOF
pfo elf32
pfo elf32.r2
pfs.elf_header
EOF
EXPECT=<<EOF
Expand All @@ -12,7 +12,7 @@ RUN
NAME=64: Elf header size
FILE=malloc://1024
CMDS=<<EOF
pfo elf64
pfo elf64.r2
pfs.elf_header
EOF
EXPECT=<<EOF
Expand All @@ -23,7 +23,7 @@ RUN
NAME=32: Elf program header size
FILE=malloc://1024
CMDS=<<EOF
pfo elf32
pfo elf32.r2
pfs.elf_phdr
EOF
EXPECT=<<EOF
Expand All @@ -34,7 +34,7 @@ RUN
NAME=64: Elf program header size
FILE=malloc://1024
CMDS=<<EOF
pfo elf64
pfo elf64.r2
pfs.elf_phdr
EOF
EXPECT=<<EOF
Expand All @@ -45,7 +45,7 @@ RUN
NAME=32: Elf section header size
FILE=malloc://1024
CMDS=<<EOF
pfo elf32
pfo elf32.r2
pfs.elf_shdr
EOF
EXPECT=<<EOF
Expand All @@ -56,7 +56,7 @@ RUN
NAME=64: Elf section header size
FILE=malloc://1024
CMDS=<<EOF
pfo elf64
pfo elf64.r2
pfs.elf_shdr
EOF
EXPECT=<<EOF
Expand All @@ -67,7 +67,7 @@ RUN
NAME=32: Multiple section headers
FILE=malloc://1024
CMDS=<<EOF
pfo elf32
pfo elf32.r2
pf [2]? (elf_shdr)sections
EOF
EXPECT=<<EOF
Expand Down Expand Up @@ -103,7 +103,7 @@ RUN
NAME=64: Multiple section headers
FILE=malloc://1024
CMDS=<<EOF
pfo elf64
pfo elf64.r2
pf [2]? (elf_shdr)sections
EOF
EXPECT=<<EOF
Expand Down Expand Up @@ -392,7 +392,7 @@ RUN
NAME=pf elf_header times fix
FILE=-
CMDS=<<EOF
pfo elf32
pfo elf32.r2
pf? elf_header
pfs.elf_header
?e
Expand Down

0 comments on commit 552d65a

Please sign in to comment.