Fix searching for strings in rz-bin when the file format is invalid (#3245)

* Fix searching for strings in `rz-bin` when the file format is invalid

  * Always try with "any" bin plugin before giving up searching a file
  * Add a test in `db/tools/rz_bin` for this

* Remove `EXPECT_ERR` from `rz-bin broken MZ` test
This commit is contained in:
Dhruv Maroo 2022-12-15 20:38:48 +05:30 committed by GitHub
parent adf8b0717e
commit f8f042f818
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View file

@ -209,7 +209,6 @@ RZ_API RzBinFile *rz_bin_open(RzBin *bin, const char *file, RzBinOptions *opt) {
return NULL;
}
opt->sz = 0;
opt->pluginname = NULL;
return rz_bin_open_io(bin, opt);
}

View file

@ -1159,9 +1159,16 @@ RZ_API int rz_main_rz_bin(int argc, const char **argv) {
RzBinFile *bf = rz_bin_open(bin, file, &bo);
if (!bf) {
eprintf("rz-bin: Cannot open file\n");
result = 1;
goto err;
/* Try opening as a binary file */
bo.pluginname = "any";
RZ_LOG_INFO("Treating input file as a binary file...\n");
bf = rz_bin_open(bin, file, &bo);
if (!bf) {
RZ_LOG_ERROR("rz-bin: Cannot open file\n");
result = 1;
goto err;
}
}
/* required to automatically select a sub-bin when not specified */
(void)rz_core_bin_update_arch_bits(&core);

View file

@ -1213,3 +1213,12 @@ EOF
EXPECT=<<EOF
EOF
RUN
NAME=rz-bin broken MZ file
FILE=bins/mz/broken.exe
CMDS=!rz-bin -zzj ${RZ_FILE} ; echo ""
EXPECT=<<EOF
{}
[{"vaddr":77,"paddr":77,"ordinal":0,"size":45,"length":44,"section":"","type":"ascii","string":"!This program cannot be run in DOS mode.\r\r\n$"},{"vaddr":155,"paddr":155,"ordinal":1,"size":6,"length":5,"section":"","type":"ascii","string":"Q\fb.Q"},{"vaddr":189,"paddr":189,"ordinal":2,"size":5,"length":4,"section":"","type":"ascii","string":"b.Q{"},{"vaddr":205,"paddr":205,"ordinal":3,"size":8,"length":7,"section":"","type":"ascii","string":"b.Q4<*P"},{"vaddr":213,"paddr":213,"ordinal":4,"size":6,"length":5,"section":"","type":"ascii","string":"b.Q4<"},{"vaddr":221,"paddr":221,"ordinal":5,"size":8,"length":7,"section":"","type":"ascii","string":"b.Q4<,P"},{"vaddr":229,"paddr":229,"ordinal":6,"size":8,"length":7,"section":"","type":"ascii","string":"b.QRich"},{"vaddr":241,"paddr":241,"ordinal":7,"size":30,"length":29,"section":"","type":"ascii","string":"https://malwarec2.com/drd.exe"}]
EOF
RUN