Skip to content

Commit

Permalink
Improve sigdb file format detection ##anal
Browse files Browse the repository at this point in the history
  • Loading branch information
micronn authored Dec 17, 2023
1 parent 4e9a6e0 commit e18876d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 21 deletions.
31 changes: 10 additions & 21 deletions libr/anal/sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -2990,38 +2990,27 @@ static int signdb_type(const char *file) {
sz = R_MIN (sz, 0x200);
int is_sdb = 16;
int is_kv = 4;
int is_r2 = 4;
int is_r2 = 2;
int t = SIGNDB_TYPE_INVALID;
if (r_str_startswith (data, "[{\"name\":")) {
t = SIGNDB_TYPE_JSON;
} else {
for (i = 0; i < sz; i++) {
if (!strncmp (data + i, "\nza ", sz - i)) {
if (!strncmp (data + i, "\nza ", 4)) {
is_r2--;
i++;
i += 3;
continue;
}
switch (i) {
case 3:
case 7:
case 0xb:
case 0xf:
if (data[i] == 0) {
is_sdb--;
}
break;
case '=':
case '\n':
if ((i & 3) == 3 && data[i] == 0) {
is_sdb--;
continue;
}
if (data[i] == '=' || data[i] == '\n') {
is_kv--;
break;
default:
if (data[i] != 0) {
is_sdb--;
}
break;
continue;
}
}
if (is_sdb == 0) {
if (is_sdb < 0) {
t = SIGNDB_TYPE_SDB;
} else if (is_r2 < 0) {
t = SIGNDB_TYPE_R2;
Expand Down
50 changes: 50 additions & 0 deletions test/db/cmd/cmd_zignature
Original file line number Diff line number Diff line change
Expand Up @@ -1767,3 +1767,53 @@ za main N sym.imp.atoi
za sym.foo_int_ N sym.foo_int__int_
EOF
RUN

NAME=Saves and loads sdb zignatures without sdb extension
FILE=-
CMDS=<<EOF
rm .tmp_file
za s1 x xref1
za s2 r ref1
za s3 n sym1
za s4 n sym2
zos .tmp_file
z-*
zo .tmp_file
z~s1
z~s2
z~s3
z~s4
rm .tmp_file
EOF
EXPECT=<<EOF
s1:
s2:
s3:
s4:
EOF
RUN

NAME=Saves and loads r2 zignatures without r2 extension
FILE=-
CMDS=<<EOF
rm .tmp_file
za s1 x xref1
za s2 r ref1
za s3 n sym1
za s4 n sym2
z* > .tmp_file
z-*
zo .tmp_file
z~s1
z~s2
z~s3
z~s4
rm .tmp_file
EOF
EXPECT=<<EOF
s1:
s2:
s3:
s4:
EOF
RUN

0 comments on commit e18876d

Please sign in to comment.