MCPcopy Create free account
hub / github.com/lief-project/LIEF / parse_string

Function parse_string

src/PE/resources/ResourceStringTable.cpp:30–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28namespace PE {
29
30result<ResourceStringTable::entry_t> parse_string(BinaryStream& stream) {
31 // typedef struct {
32 // WORD wLength;
33 // WORD wValueLength;
34 // WORD wType;
35 // WCHAR szKey;
36 // WORD Padding;
37 // WORD Value;
38 // } String;
39 auto wLength = stream.read<uint16_t>();
40 if (!wLength) { return make_error_code(wLength.error()); }
41
42 if (*wLength == 0) {
43 return make_error_code(lief_errors::read_error);
44 }
45
46 const uint32_t end_offset = stream.pos() - sizeof(uint16_t) + *wLength;
47
48 auto wValueLength = stream.read<uint16_t>();
49 if (!wValueLength) { return make_error_code(wValueLength.error()); }
50
51 auto wType = stream.read<uint16_t>();
52 if (!wType) { return make_error_code(wType.error()); }
53
54 if (*wType != 0 && wType != 1) {
55 return make_error_code(lief_errors::corrupted);
56 }
57
58 ResourceStringTable::entry_t entry;
59
60 auto szKey = stream.read_u16string();
61 if (!szKey) { return make_error_code(szKey.error()); }
62
63 entry.key = std::move(*szKey);
64
65 if (stream.pos() >= end_offset) {
66 return entry;
67 }
68
69 stream.align(sizeof(uint32_t));
70
71 if (stream.pos() >= end_offset) {
72 return entry;
73 }
74
75 auto Value = stream.read_u16string();
76 if (!Value) { return entry; }
77
78 entry.value = std::move(*Value);
79
80 stream.setpos(end_offset);
81 return entry;
82}
83
84result<ResourceStringTable> ResourceStringTable::parse(BinaryStream& stream) {
85 // typedef struct {

Callers 1

parseMethod · 0.85

Calls 4

make_error_codeFunction · 0.85
read_u16stringMethod · 0.80
alignMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected