Skip to content

Commit 2bf67e6

Browse files
wxsBSDplusvic
authored andcommitted
Fix regression in export parsing.
UPX packed files will cause export parsing to stop parsing because the function address is not a valid RVA, and I was refusing to parse that export in that case. This is a regression from how we used to do parsing (we were never checking the export RVA so it was never considered in prior releases). This is causing rules which used to work to no longer work on packed samples. Specifically, checking for a DLL which is UPX packed using pe.exports("foo") is likely to not work in 4.0.0 when it used to work in 3.11.0. Apologies for missing this, but to make sure it doesn't happen again in the future I've added a test case for this (just packed an existing DLL that is in the repo).
1 parent 1d90197 commit 2bf67e6

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

libyara/modules/pe/pe.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1218,13 +1218,13 @@ static void pe_parse_exports(
12181218

12191219
for (i = 0; i < number_of_exports; i++)
12201220
{
1221-
offset = pe_rva_to_offset(pe, yr_le32toh(function_addrs[i]));
1222-
if (offset <= 0)
1223-
continue;
1224-
12251221
set_integer(
12261222
ordinal_base + i, pe->object, "export_details[%i].ordinal", exp_sz);
12271223

1224+
// Don't check for a failure here since some packers make this an invalid
1225+
// value.
1226+
offset = pe_rva_to_offset(pe, yr_le32toh(function_addrs[i]));
1227+
12281228
if (offset > export_start && offset < export_start + export_size)
12291229
{
12301230
remaining = pe->data_size - (size_t) offset;
Binary file not shown.

tests/test-pe.c

+9
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,15 @@ int main(int argc, char** argv)
279279
}",
280280
"tests/data/mtxex.dll");
281281

282+
assert_true_rule_file(
283+
"import \"pe\" \
284+
rule test { \
285+
condition: \
286+
pe.export_details[0].name == \"CP_PutItem\" \
287+
}",
288+
"tests/data/079a472d22290a94ebb212aa8015cdc8dd28a968c6b4d3b88acdd58ce2d3b885.upx");
289+
290+
282291
assert_true_rule_file(
283292
"import \"pe\" \
284293
rule test { \

0 commit comments

Comments
 (0)