Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 957292e

Browse filesBrowse files
joyeecheungaduh95
authored andcommitted
sea: split sea binary manipulation code
Split the sea binary manipulation code to a seperate file so that adding more low-level binary manipulation code doesn't clobber the higher-level code. PR-URL: #61167 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent fbe4da5 commit 957292e
Copy full SHA for 957292e

4 files changed

+68-39Lines changed: 68 additions & 39 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎node.gyp‎

Copy file name to clipboardExpand all lines: node.gyp
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
'src/node_report_module.cc',
143143
'src/node_report_utils.cc',
144144
'src/node_sea.cc',
145+
'src/node_sea_bin.cc',
145146
'src/node_serdes.cc',
146147
'src/node_shadow_realm.cc',
147148
'src/node_snapshotable.cc',
Collapse file

‎src/node_sea.cc‎

Copy file name to clipboardExpand all lines: src/node_sea.cc
-39Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@
1414
#include "simdjson.h"
1515
#include "util-inl.h"
1616

17-
// The POSTJECT_SENTINEL_FUSE macro is a string of random characters selected by
18-
// the Node.js project that is present only once in the entire binary. It is
19-
// used by the postject_has_resource() function to efficiently detect if a
20-
// resource has been injected. See
21-
// https://github.com/nodejs/postject/blob/35343439cac8c488f2596d7c4c1dddfec1fddcae/postject-api.h#L42-L45.
22-
#define POSTJECT_SENTINEL_FUSE "NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2"
23-
#include "postject-api.h"
24-
#undef POSTJECT_SENTINEL_FUSE
25-
2617
#include <memory>
2718
#include <string_view>
2819
#include <tuple>
@@ -233,33 +224,6 @@ SeaResource SeaDeserializer::Read() {
233224
exec_argv};
234225
}
235226

236-
std::string_view FindSingleExecutableBlob() {
237-
#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
238-
CHECK(IsSingleExecutable());
239-
static const std::string_view result = []() -> std::string_view {
240-
size_t size;
241-
#ifdef __APPLE__
242-
postject_options options;
243-
postject_options_init(&options);
244-
options.macho_segment_name = "NODE_SEA";
245-
const char* blob = static_cast<const char*>(
246-
postject_find_resource("NODE_SEA_BLOB", &size, &options));
247-
#else
248-
const char* blob = static_cast<const char*>(
249-
postject_find_resource("NODE_SEA_BLOB", &size, nullptr));
250-
#endif
251-
return {blob, size};
252-
}();
253-
per_process::Debug(DebugCategory::SEA,
254-
"Found SEA blob %p, size=%zu\n",
255-
result.data(),
256-
result.size());
257-
return result;
258-
#else
259-
UNREACHABLE();
260-
#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
261-
}
262-
263227
} // anonymous namespace
264228

265229
bool SeaResource::use_snapshot() const {
@@ -283,9 +247,6 @@ SeaResource FindSingleExecutableResource() {
283247
return sea_resource;
284248
}
285249

286-
bool IsSingleExecutable() {
287-
return postject_has_resource();
288-
}
289250

290251
void IsSea(const FunctionCallbackInfo<Value>& args) {
291252
args.GetReturnValue().Set(IsSingleExecutable());
Collapse file

‎src/node_sea.h‎

Copy file name to clipboardExpand all lines: src/node_sea.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct SeaResource {
5454
};
5555

5656
bool IsSingleExecutable();
57+
std::string_view FindSingleExecutableBlob();
5758
SeaResource FindSingleExecutableResource();
5859
std::tuple<int, char**> FixupArgsForSEA(int argc, char** argv);
5960
node::ExitCode BuildSingleExecutableBlob(
Collapse file

‎src/node_sea_bin.cc‎

Copy file name to clipboard
+66Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include "node_sea.h"
2+
3+
#ifdef HAVE_LIEF
4+
#include "LIEF/LIEF.hpp"
5+
#endif // HAVE_LIEF
6+
7+
#include "debug_utils-inl.h"
8+
#include "env-inl.h"
9+
#include "util-inl.h"
10+
11+
#include <algorithm>
12+
#include <codecvt>
13+
#include <locale>
14+
#include <memory>
15+
#include <vector>
16+
#include <string>
17+
#include <iostream>
18+
#include <fstream>
19+
#include <sstream>
20+
#include <string_view>
21+
22+
// The POSTJECT_SENTINEL_FUSE macro is a string of random characters selected by
23+
// the Node.js project that is present only once in the entire binary. It is
24+
// used by the postject_has_resource() function to efficiently detect if a
25+
// resource has been injected. See
26+
// https://github.com/nodejs/postject/blob/35343439cac8c488f2596d7c4c1dddfec1fddcae/postject-api.h#L42-L45.
27+
#define POSTJECT_SENTINEL_FUSE "NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2"
28+
#include "postject-api.h"
29+
#undef POSTJECT_SENTINEL_FUSE
30+
31+
namespace node {
32+
namespace sea {
33+
34+
std::string_view FindSingleExecutableBlob() {
35+
#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
36+
CHECK(IsSingleExecutable());
37+
static const std::string_view result = []() -> std::string_view {
38+
size_t size;
39+
#ifdef __APPLE__
40+
postject_options options;
41+
postject_options_init(&options);
42+
options.macho_segment_name = "NODE_SEA";
43+
const char* blob = static_cast<const char*>(
44+
postject_find_resource("NODE_SEA_BLOB", &size, &options));
45+
#else
46+
const char* blob = static_cast<const char*>(
47+
postject_find_resource("NODE_SEA_BLOB", &size, nullptr));
48+
#endif
49+
return {blob, size};
50+
}();
51+
per_process::Debug(DebugCategory::SEA,
52+
"Found SEA blob %p, size=%zu\n",
53+
result.data(),
54+
result.size());
55+
return result;
56+
#else
57+
UNREACHABLE();
58+
#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
59+
}
60+
61+
bool IsSingleExecutable() {
62+
return postject_has_resource();
63+
}
64+
65+
} // namespace sea
66+
} // namespace node

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.