rizin/test/db/cmd/project
Anton Kochkov 3c59df7e98
Refactor RzTypes to use structs instead of SDB + New Tree-Sitter based C Parser (#1047)
- Removed oldshell version of `t` (types) commands
- Removed `tk` command because types storage switched to the hashtable
- Added `tfc` command to show the calling convention of the function or set it
- Added `tsl` (RZ_OUTPUT_MODE_LONG) to show structure members' sizes and offsets
- Added `tul` (RZ_OUTPUT_MODE_LONG) to show union members' sizes
- Switched the types storage to the hashtable instead of SDB
- Added load and export from/to SDB for standard type libraries and serialization for Projects
- Changed all `char *type` occurences to the proper `RzType`
- Added `RzCallable` type for the function/class method types
- Changed all function types API to use the `RzCallable` API
- Switched the function types (`RzCallable`) storage to the hashtable instead of SDB
- Added a connection between `RzAnalysisFunction` and `RzCallable` - `rz_analysis_function_derive_type()` API function to derive new `RzCallable` type from the `RzAnalysisFunction` even if it doesn't exist in the RzTypeDB.
- Moved type links to the RzAnalysis where they belong
- Removed TCC and MPC-based parsers
- Added Tree-Sitter-based parser for C grammar (see `librz/type/parser/*`)
- Reworked type databases in `librz/analysis/d/` to be consistent with C standard, libc, platform-specific definitions
- Switched the type links from `char *` to `RzType`
- Switched the type links from SDB to the hashtable
- Added concept of the "type paths", e.g. `a.b[20].c` where `b` is a member of `a` (`a` is either structure or a union) and `c` is a member of `b`, and `b` is an array where we take 20-th element.
- Added concept of the typeclasses (a bit similar to Haskell) for numerical types: `None` (the most generic one), `Num` (includes `Integral` and `Floating`), `Integral` (includes `Signed Integral` and `Unsigned Integral`), `Floating`.
- Added concept of type equality (`rz_types_equal(a, b)` API function)
- Added Doxygen documentation to every API function in the `librz/type/*`.
- Updated the project format from **V2** to **V3**, added migration.
2021-07-20 01:46:45 +08:00

379 lines
7.6 KiB
Text

NAME=load with file without moving anything
FILE=bins/elf/crackme0x05
CMDS=<<EOF
e asm.bytes=true
e cfg.oldshell=false
f i_do_hope_that_no_entity_knocks_over_my_beverage @ 0x080483d8
Ps .tmp_load_no_move.rzdb
o--
Po .tmp_load_no_move.rzdb
rm .tmp_load_no_move.rzdb
pdi 3 @ 0x080483d8
EOF
EXPECT=<<EOF
0x080483d8 i_do_hope_that_no_entity_knocks_over_my_beverage:
0x080483d8 50 push eax
0x080483d9 54 push esp
0x080483da 52 push edx
EOF
RUN
NAME=load with file using saved absolute file path after project file was moved
FILE=bins/elf/crackme0x05
CMDS=<<EOF
e cfg.oldshell=false
e asm.bytes=true
f i_do_hope_that_no_entity_knocks_over_my_beverage @ 0x080483d8
Ps .tmp_load_move_project.rzdb
o--
mkdir -p .tmp_load_move_project
mv .tmp_load_move_project.rzdb .tmp_load_move_project/
cd .tmp_load_move_project
Po .tmp_load_move_project.rzdb
rm .tmp_load_move_project.rzdb
cd ..
rm .tmp_load_move_project
pdi 3 @ 0x080483d8
EOF
EXPECT=<<EOF
0x080483d8 i_do_hope_that_no_entity_knocks_over_my_beverage:
0x080483d8 50 push eax
0x080483d9 54 push esp
0x080483da 52 push edx
EOF
RUN
NAME=load with file using saved relative file path after project file and binary were moved together
FILE=--
CMDS=<<EOF
e asm.bytes=true
e cfg.oldshell=false
cp bins/elf/crackme0x05 .tmp_load_move_both.bin
o .tmp_load_move_both.bin
f i_do_hope_that_no_entity_knocks_over_my_beverage @ 0x080483d8
Ps .tmp_load_move_both.rzdb
o--
mkdir -p .tmp_load_move_both
mv .tmp_load_move_both.rzdb .tmp_load_move_both/
mv .tmp_load_move_both.bin .tmp_load_move_both/
Po .tmp_load_move_both/.tmp_load_move_both.rzdb
pdi 3 @ 0x080483d8
o--
rm .tmp_load_move_both/.tmp_load_move_both.rzdb
rm .tmp_load_move_both/.tmp_load_move_both.bin
rm .tmp_load_move_both
EOF
EXPECT=<<EOF
0x080483d8 i_do_hope_that_no_entity_knocks_over_my_beverage:
0x080483d8 50 push eax
0x080483d9 54 push esp
0x080483da 52 push edx
EOF
RUN
NAME=load with file using saved relative file path after project file and binary were moved together with different relation
FILE=--
CMDS=<<EOF
e cfg.oldshell=false
e asm.bytes=true
mkdir -p .tmp_load_move_both2/.tmp_load_move_both2
cp bins/elf/crackme0x05 .tmp_load_move_both2/somebin
o .tmp_load_move_both2/somebin
f i_do_hope_that_no_entity_knocks_over_my_beverage @ 0x080483d8
Ps .tmp_load_move_both2.rzdb
o--
mv .tmp_load_move_both2.rzdb .tmp_load_move_both2/
mv .tmp_load_move_both2/somebin .tmp_load_move_both2/.tmp_load_move_both2/somebin
Po .tmp_load_move_both2/.tmp_load_move_both2.rzdb
pdi 3 @ 0x080483d8
o--
rm .tmp_load_move_both2/.tmp_load_move_both2.rzdb
rm .tmp_load_move_both2/.tmp_load_move_both2/somebin
rm .tmp_load_move_both2/.tmp_load_move_both2
rm .tmp_load_move_both2
EOF
EXPECT=<<EOF
0x080483d8 i_do_hope_that_no_entity_knocks_over_my_beverage:
0x080483d8 50 push eax
0x080483d9 54 push esp
0x080483da 52 push edx
EOF
RUN
NAME=load with file using saved raw file path after everything has been messed up, but binary is in cwd
FILE=--
CMDS=<<EOF
e asm.bytes=true
e cfg.oldshell=false
mkdir -p .tmp_load_move_bin
cp bins/elf/crackme0x05 .tmp_load_move_bin.bin
o .tmp_load_move_bin.bin
f i_do_hope_that_no_entity_knocks_over_my_beverage @ 0x080483d8
Ps .tmp_load_move_bin.rzdb
o--
mv .tmp_load_move_bin.bin .tmp_load_move_bin/.tmp_load_move_bin.bin
cd .tmp_load_move_bin
Po ../.tmp_load_move_bin.rzdb
pdi 3 @ 0x080483d8
o--
cd ..
rm .tmp_load_move_bin/.tmp_load_move_bin.bin
rm .tmp_load_move_bin
rm .tmp_load_move_bin.rzdb
EOF
EXPECT=<<EOF
0x080483d8 i_do_hope_that_no_entity_knocks_over_my_beverage:
0x080483d8 50 push eax
0x080483d9 54 push esp
0x080483da 52 push edx
EOF
RUN
NAME=load without file
FILE=bins/elf/crackme0x05
CMDS=<<EOF
e asm.bytes=true
e cfg.oldshell=false
f a_nice_refreshing_un-moisten @ 0x080483d8
Ps .tmp_load_without_file.rzdb
o
?e --
o--
o
pdi 3 @ 0x080483d8
?e --
Poo .tmp_load_without_file.rzdb
rm .tmp_load_without_file.rzdb
o
?e --
pdi 3 @ 0x080483d8
EOF
EXPECT=<<EOF
3 * r-x 0x00001de8 bins/elf/crackme0x05
4 - rw- 0x00000004 null://4
5 - r-x 0x0000001c vfile://0/reloc-targets
--
0x080483d8 ff invalid
0x080483d9 ff invalid
0x080483da ff invalid
--
--
0x080483d8 a_nice_refreshing_un_moisten:
0x080483d8 ff invalid
0x080483d9 ff invalid
0x080483da ff invalid
EOF
RUN
NAME=load on top of file
FILE=bins/elf/crackme0x05
CMDS=<<EOF
e cfg.oldshell=false
e asm.bytes=true
f a_nice_refreshing_un-moisten @ 0x080483d8
Ps .tmp_load_on_top_of_file.rzdb
o
?e --
o--
o
pdi 3 @ 0x080483d8
?e --
o bins/elf/crackme0x00b
Poo .tmp_load_on_top_of_file.rzdb
rm .tmp_load_on_top_of_file.rzdb
?e --
pdi 3 @ 0x080483d8
EOF
EXPECT=<<EOF
3 * r-x 0x00001de8 bins/elf/crackme0x05
4 - rw- 0x00000004 null://4
5 - r-x 0x0000001c vfile://0/reloc-targets
--
0x080483d8 ff invalid
0x080483d9 ff invalid
0x080483da ff invalid
--
--
0x080483d8 a_nice_refreshing_un_moisten:
0x080483d8 0000 add byte [eax], al
0x080483da 00e9 add cl, ch
0x080483dc 90 nop
EOF
RUN
NAME=flags
FILE=bins/elf/crackme0x05
CMDS=<<EOF
e cfg.oldshell=false
fr sym.main sym.renamedmain
f~?
f~main
Ps .tmp_flags.rzdb
?e --
o--
f
?e --
Poo .tmp_flags.rzdb
rm .tmp_flags.rzdb
f~?
f~main
EOF
EXPECT=<<EOF
117
0x08048364 16 sym.imp.__libc_start_main
0x08048540 256 main
0x08048540 92 sym.renamedmain
0x0804a000 4 reloc.__libc_start_main
--
--
117
0x08048364 16 sym.imp.__libc_start_main
0x08048540 92 sym.renamedmain
0x08048540 256 main
0x0804a000 4 reloc.__libc_start_main
EOF
RUN
NAME=config
FILE==
CMDS=<<EOF
e cfg.oldshell=false
e asm.describe=1
e asm.describe
e asm.indentspace=8
e asm.indentspace
e analysis.fcnprefix=myfunctions
e analysis.fcnprefix
Ps .tmp_config.rzdb
?e --
e asm.describe=0
e asm.describe
e asm.indentspace=0
e asm.indentspace
e analysis.fcnprefix=fcn
e analysis.fcnprefix
?e --
Poo .tmp_config.rzdb
rm .tmp_config.rzdb
e asm.describe
e asm.indentspace
e analysis.fcnprefix
EOF
EXPECT=<<EOF
true
8
myfunctions
--
false
0
fcn
--
true
8
myfunctions
EOF
RUN
NAME=seek
FILE==
CMDS=<<EOF
e cfg.oldshell=false
s 0x1337
s
Ps .tmp_seek.rzdb
o--
s 0
Poo .tmp_seek.rzdb
rm .tmp_seek.rzdb
s
EOF
EXPECT=<<EOF
0x1337
0x1337
EOF
RUN
NAME=analysis
FILE==
CMDS=<<EOF
e cfg.oldshell=false
af+ 0x100 windowpane
afb+ windowpane 0x100 0x30
afl
Ps .tmp_analysis.rzdb
?e --
o--
afl
?e --
Poo .tmp_analysis.rzdb
rm .tmp_analysis.rzdb
afl
EOF
EXPECT=<<EOF
0x00000100 1 48 windowpane
--
--
0x00000100 1 48 windowpane
EOF
RUN
NAME=remember saved project file during session
FILE=bins/elf/crackme0x05
CMDS=<<EOF
e asm.bytes=true
e cfg.oldshell=false
Ps .tmp_remember.rzdb
e prj.file
f cashews @ 0x080483d8
Ps
o--
e prj.file=
e prj.file
Po .tmp_remember.rzdb
e prj.file
rm .tmp_remember.rzdb
pdi 1 @ 0x080483d8
EOF
EXPECT=<<EOF
.tmp_remember.rzdb
.tmp_remember.rzdb
0x080483d8 cashews:
0x080483d8 50 push eax
EOF
RUN
NAME=raw file permissions after reload
FILE=bins/other/0x3
CMDS=<<EOF
e cfg.oldshell=false
om
Ps .tmp_perms.rzdb
o--
?e --
om
?e --
Po .tmp_perms.rzdb
om
rm .tmp_perms.rzdb
EOF
EXPECT=<<EOF
1 fd: 3 +0x00000000 0x00000000 - 0x00000002 r-x
--
--
1 fd: 3 +0x00000000 0x00000000 - 0x00000002 r-x
EOF
RUN
NAME=migrate info
FILE=--
CMDS=<<EOF
Po prj/v1-noreturn.rzdb
EOF
EXPECT=
EXPECT_ERR=<<EOF
Detailed project load info:
project migrated from version 1 to 2.
project migrated from version 2 to 3.
EOF
RUN