Skip to content

Commit

Permalink
Resolve #1168
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Feb 8, 2025
1 parent 646af9f commit 930310d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/PE/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,9 @@ ok_error_t Parser::parse_exports() {
entry.set_forward_info(std::move(library), std::move(function));

if (is_valid_fwd) {
if (auto name_offset = name_table_value(*stream_, name_table_offset, i)) {
if (auto name = stream_->peek_string_at(*name_offset)) {
if (auto name_rva = name_table_value(*stream_, name_table_offset, i)) {
uint32_t name_offset = binary_->rva_to_offset(*name_rva);
if (auto name = stream_->peek_string_at(name_offset)) {
const bool is_valid = !name->empty() &&
name->size() <= MAX_EXPORT_NAME_SIZE && is_printable(*name);
if (is_valid) {
Expand Down
13 changes: 9 additions & 4 deletions tests/pe/test_forward_information.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import lief
import json
from utils import get_sample

def test_basic():
path = get_sample('PE/PE32_x86_library_kernel32.dll')
sample = lief.parse(path)
sample = lief.PE.parse(path)
exports = sample.get_export()
forwarded_exports: list[lief.PE.ExportEntry] = [exp for exp in exports.entries if exp.is_forwarded]
assert len(forwarded_exports) == 82
Expand All @@ -26,3 +23,11 @@ def test_basic():
assert "forward_information" in json_serialized
assert json_serialized["forward_information"]["library"] == "NTDLL"
assert json_serialized["forward_information"]["function"] == "RtlInterlockedPushListSList"

def test_issue_1168():
input_path = get_sample('PE/user32.dll')
pe = lief.PE.parse(input_path)
fwd = [e for e in pe.get_export().entries if e.is_forwarded]
assert len(fwd) == 4
assert fwd[0].name == "DefDlgProcA"
assert fwd[3].name == "DefWindowProcW"

0 comments on commit 930310d

Please sign in to comment.