build: support LIEF 0.17.x and 1.x · nodejs/node@6ee32f8 · GitHub
Skip to content

Commit 6ee32f8

Browse files
inoway46aduh95
authored andcommitted
build: support LIEF 0.17.x and 1.x
Keep bundled LIEF at 0.17.0 while selecting the Mach-O section API from the headers in use and the bundled build settings by version. Prepare the updater for Mbed TLS 4 and TF-PSA-Crypto so the vendor update can land separately. Assisted-by: Codex Signed-off-by: inoway46 <inoueyuya416@gmail.com> PR-URL: #66240 Fixes: #66238 Refs: #66242 Refs: #63530 Refs: nodejs/nodejs-dependency-vuln-assessments#360 Refs: nodejs/nodejs-dependency-vuln-assessments#342 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent 702c744 commit 6ee32f8

3 files changed

Lines changed: 192 additions & 2 deletions

File tree

‎deps/LIEF/lief.gyp‎

Lines changed: 164 additions & 2 deletions

‎src/node_sea_bin.cc‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#else // defined(DEBUG)
1212
#include "LIEF/LIEF.hpp"
1313
#endif // defined(DEBUG)
14+
#include "LIEF/version.h"
1415
#endif // HAVE_LIEF
1516

1617
#include "debug_utils-inl.h"
@@ -175,8 +176,13 @@ InjectOutput InjectIntoMachO(const std::vector<uint8_t>& executable,
175176
LIEF::MachO::SegmentCommand::VM_PROTECTIONS::READ));
176177
new_segment.init_protection(static_cast<uint32_t>(
177178
LIEF::MachO::SegmentCommand::VM_PROTECTIONS::READ));
179+
#if LIEF_VERSION_MAJOR >= 1
180+
auto section = LIEF::MachO::Section::create(section_name, data);
181+
new_segment.add_section(*section);
182+
#else
178183
LIEF::MachO::Section section(section_name, data);
179184
new_segment.add_section(section);
185+
#endif
180186
binary.add(new_segment);
181187
} else {
182188
// Check if the section exists
@@ -191,8 +197,13 @@ InjectOutput InjectIntoMachO(const std::vector<uint8_t>& executable,
191197
segment_name,
192198
section_name)};
193199
}
200+
#if LIEF_VERSION_MAJOR >= 1
201+
auto section = LIEF::MachO::Section::create(section_name, data);
202+
binary.add_section(*segment, *section);
203+
#else
194204
LIEF::MachO::Section section(section_name, data);
195205
binary.add_section(*segment, section);
206+
#endif
196207
}
197208

198209
// It will need to be signed again anyway, so remove the signature
@@ -295,7 +306,15 @@ InjectOutput InjectIntoPE(const std::vector<uint8_t>& executable,
295306
cfg.resources = true;
296307
cfg.rsrc_section = ".rsrc"; // ensure section name
297308
LIEF::PE::Builder builder(*binary, cfg);
309+
#if LIEF_VERSION_MAJOR >= 1
310+
// LIEF 1.0.0 does not export the result's bool conversion in shared builds.
311+
// TODO(inoway46): Remove this workaround once the upstream issue is fixed.
312+
// https://github.com/lief-project/LIEF/issues/1387
313+
builder.build();
314+
if (builder.get_build().empty()) {
315+
#else
298316
if (!builder.build()) {
317+
#endif
299318
return {InjectResult::kError, {}, "Failed to build modified PE binary"};
300319
}
301320

‎tools/prepare_lief.py‎

Lines changed: 9 additions & 0 deletions

0 commit comments

Comments
 (0)