afterpresets 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -6
- package/native-runtime/CMakeLists.txt +82 -0
- package/native-runtime/README.md +40 -0
- package/native-runtime/THIRD_PARTY_NOTICES.md +14 -0
- package/native-runtime/include/ap_native.h +223 -0
- package/native-runtime/src/apply.cpp +199 -0
- package/native-runtime/src/crypto.cpp +225 -0
- package/native-runtime/src/crypto.hpp +51 -0
- package/native-runtime/src/dialog.cpp +62 -0
- package/native-runtime/src/dialog.hpp +35 -0
- package/native-runtime/src/engine.cpp +909 -0
- package/native-runtime/src/engine.hpp +232 -0
- package/native-runtime/src/fsutil.cpp +291 -0
- package/native-runtime/src/fsutil.hpp +57 -0
- package/native-runtime/src/json.cpp +326 -0
- package/native-runtime/src/json.hpp +70 -0
- package/native-runtime/src/platform.hpp +83 -0
- package/native-runtime/src/platform_common.cpp +60 -0
- package/native-runtime/src/platform_mac.mm +314 -0
- package/native-runtime/src/platform_win.cpp +277 -0
- package/native-runtime/src/runtime.cpp +473 -0
- package/native-runtime/src/util.cpp +169 -0
- package/native-runtime/src/util.hpp +32 -0
- package/native-runtime/src/zip.cpp +243 -0
- package/native-runtime/src/zip.hpp +58 -0
- package/native-runtime/third_party/monocypher/LICENCE.md +167 -0
- package/native-runtime/third_party/monocypher/monocypher-ed25519.c +500 -0
- package/native-runtime/third_party/monocypher/monocypher-ed25519.h +140 -0
- package/native-runtime/third_party/monocypher/monocypher.c +2956 -0
- package/native-runtime/third_party/monocypher/monocypher.h +321 -0
- package/native-runtime/third_party/tinf/LICENSE +22 -0
- package/native-runtime/third_party/tinf/crc32.c +57 -0
- package/native-runtime/third_party/tinf/tinf.h +140 -0
- package/native-runtime/third_party/tinf/tinflate.c +636 -0
- package/native-runtime/vendor-files.json +39 -0
- package/package.json +7 -4
- package/runtime/docs/cep/host-after-effects.md +3 -3
- package/runtime/docs/cep/host-premiere.md +4 -4
- package/runtime/docs/cep/host.md +10 -2
- package/runtime/docs/common/README.md +1 -1
- package/runtime/docs/native/README.md +44 -0
- package/runtime/docs/native/debugging.md +140 -0
- package/runtime/docs/native/rules.md +402 -0
- package/runtime/docs/native/testing.md +154 -0
- package/runtime/package.json +1 -1
- package/runtime/scripts/ae-sdk-docs/config.js +102 -0
- package/runtime/scripts/ae-sdk-docs/convert.js +430 -0
- package/runtime/scripts/ae-sdk-docs/index.js +314 -0
- package/runtime/scripts/ae-sdk-docs/source.js +205 -0
- package/runtime/scripts/ae-sdk-docs/split.js +170 -0
- package/runtime/scripts/ae-sdk-docs.js +72 -0
- package/runtime/src/host.js +1 -1
- package/src/agent/cli-group.js +9 -0
- package/src/agent/extendscript.js +10 -0
- package/src/agent/host-target.js +1 -0
- package/src/agent/panels.js +1 -0
- package/src/agent/png.js +1 -0
- package/src/agent/run-tool.js +3 -0
- package/src/{mcp → agent}/snapshot.js +2 -2
- package/src/agent/tool-error.js +1 -0
- package/src/agent/tools/capture.js +3 -0
- package/src/agent/tools/host.js +1 -0
- package/src/agent/tools/native.js +1 -0
- package/src/agent/tools/panel.js +7 -0
- package/src/agent/tools.js +2 -0
- package/src/api/error-messages.js +1 -1
- package/src/build/build.js +9 -8
- package/src/check/check.js +3 -3
- package/src/check/native.js +14 -0
- package/src/check/pricing.js +1 -1
- package/src/cli.js +3 -3
- package/src/commands/build.js +8 -2
- package/src/commands/check.js +10 -2
- package/src/commands/comp.js +6 -0
- package/src/commands/dev.js +29 -2
- package/src/commands/docs.js +5 -1
- package/src/commands/host.js +1 -0
- package/src/commands/init.js +12 -7
- package/src/commands/panel.js +1 -0
- package/src/commands/push.js +9 -2
- package/src/commands/releases.js +8 -3
- package/src/commands/sdk.js +14 -0
- package/src/commands/testers.js +1 -1
- package/src/commands/upgrade.js +2 -2
- package/src/commands/whoami.js +1 -1
- package/src/dev/bridge.js +8 -0
- package/src/dev/native.js +3 -0
- package/src/dev/session.js +5 -4
- package/src/native/build.js +27 -0
- package/src/native/cmake/CMakeLists.txt +88 -0
- package/src/native/cmake/zig-windows.cmake +19 -0
- package/src/native/effect.js +3 -0
- package/src/native/install.js +8 -0
- package/src/native/installers.js +4 -0
- package/src/native/pipl.js +20 -0
- package/src/native/restart.js +2 -0
- package/src/native/sdk.js +8 -0
- package/src/project/docs.js +3 -3
- package/src/project/project.js +2 -2
- package/src/project/template.js +5 -4
- package/src/prompt.js +1 -1
- package/src/release/confirm.js +5 -0
- package/src/release/native.js +3 -0
- package/src/release/publish.js +1 -1
- package/src/system/run-command.js +1 -1
- package/src/targets.js +1 -1
- package/template/cep/AGENTS.md +102 -164
- package/template/cep/README.md +7 -3
- package/template/cep/docs/code_guide.md +67 -0
- package/template/cep/docs/initial_setup.md +63 -42
- package/template/cep/docs/release_checklist.md +25 -0
- package/template/cep/gitignore +2 -1
- package/template/cep/src/features/update-screen/update-screen.js +1 -1
- package/template/hosts/AGENTS.two-apps.md +12 -0
- package/template/native/AGENTS.md +106 -0
- package/template/native/README.md +71 -0
- package/template/native/docs/code_guide.md +72 -0
- package/template/native/docs/initial_setup.md +154 -0
- package/template/native/docs/release_checklist.md +25 -0
- package/template/native/effect.json +16 -0
- package/template/native/gitignore +9 -0
- package/template/native/package.json +14 -0
- package/template/native/src/Effect.cpp +224 -0
- package/template/native/src/License.cpp +95 -0
- package/template/native/src/License.h +29 -0
- package/template/native/src/Render.h +68 -0
- package/src/commands/mcp.js +0 -7
- package/src/mcp/extendscript.js +0 -9
- package/src/mcp/panels.js +0 -1
- package/src/mcp/protocol.js +0 -4
- package/src/mcp/server.js +0 -2
- package/src/mcp/tools/account.js +0 -3
- package/src/mcp/tools/host.js +0 -1
- package/src/mcp/tools/panel.js +0 -7
- package/src/mcp/tools/project.js +0 -40
- package/src/mcp/tools/releases.js +0 -29
- package/template/cep/.mcp.json +0 -8
- /package/src/{mcp → agent}/capture.js +0 -0
- /package/src/{mcp → agent}/redact.js +0 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
#include "zip.hpp"
|
|
2
|
+
|
|
3
|
+
#include <cctype>
|
|
4
|
+
#include <cstring>
|
|
5
|
+
#include <set>
|
|
6
|
+
|
|
7
|
+
#include "fsutil.hpp"
|
|
8
|
+
|
|
9
|
+
extern "C" {
|
|
10
|
+
#include "tinf.h"
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
namespace apn {
|
|
14
|
+
|
|
15
|
+
namespace {
|
|
16
|
+
|
|
17
|
+
constexpr uint32_t SIG_EOCD = 0x06054b50;
|
|
18
|
+
constexpr uint32_t SIG_CENTRAL = 0x02014b50;
|
|
19
|
+
constexpr uint32_t SIG_LOCAL = 0x04034b50;
|
|
20
|
+
|
|
21
|
+
uint16_t u16(const std::string &b, size_t p) { return (uint16_t)((uint8_t)b[p] | (uint8_t)b[p + 1] << 8); }
|
|
22
|
+
uint32_t u32(const std::string &b, size_t p) {
|
|
23
|
+
return (uint32_t)(uint8_t)b[p] | (uint32_t)(uint8_t)b[p + 1] << 8 | (uint32_t)(uint8_t)b[p + 2] << 16 |
|
|
24
|
+
(uint32_t)(uint8_t)b[p + 3] << 24;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
bool fail(ZipError &err, const std::string &message) {
|
|
28
|
+
err.message = "Invalid update archive: " + message;
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
std::string quoted(const std::string &s) { return "\"" + s + "\""; }
|
|
33
|
+
|
|
34
|
+
// The local header must agree with the central directory (name, method, sizes,
|
|
35
|
+
// CRC, no data descriptor), so no data is hidden from one extractor and visible
|
|
36
|
+
// to another. The server checks the same.
|
|
37
|
+
bool local_header_ok(const std::string &buf, const ZipEntry &e) {
|
|
38
|
+
size_t o = e.local_offset;
|
|
39
|
+
if ((uint64_t)o + 30 > buf.size() || u32(buf, o) != SIG_LOCAL) return false;
|
|
40
|
+
uint16_t name_len = u16(buf, o + 26);
|
|
41
|
+
if ((uint64_t)o + 30 + name_len + u16(buf, o + 28) + e.comp_size > buf.size()) return false;
|
|
42
|
+
return u16(buf, o + 8) == e.method && !(u16(buf, o + 6) & 0x0008) && u32(buf, o + 14) == e.crc &&
|
|
43
|
+
u32(buf, o + 18) == e.comp_size && u32(buf, o + 22) == e.size && buf.compare(o + 30, name_len, e.name) == 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
bool ends_with(const std::string &s, const std::string &suffix) {
|
|
47
|
+
return s.size() >= suffix.size() && s.compare(s.size() - suffix.size(), suffix.size(), suffix) == 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
} // namespace
|
|
52
|
+
|
|
53
|
+
bool zip_list(const std::string &buf, std::vector<ZipEntry> &out, ZipError &err) {
|
|
54
|
+
out.clear();
|
|
55
|
+
if (buf.size() < 22) return fail(err, "file is too small.");
|
|
56
|
+
size_t min = buf.size() > 22 + 65535 ? buf.size() - 22 - 65535 : 0;
|
|
57
|
+
size_t eocd = std::string::npos;
|
|
58
|
+
for (size_t i = buf.size() - 22 + 1; i-- > min;) {
|
|
59
|
+
if (u32(buf, i) == SIG_EOCD) { eocd = i; break; }
|
|
60
|
+
}
|
|
61
|
+
if (eocd == std::string::npos) return fail(err, "end of central directory not found.");
|
|
62
|
+
uint16_t count = u16(buf, eocd + 10);
|
|
63
|
+
uint32_t cd_size = u32(buf, eocd + 12);
|
|
64
|
+
uint32_t cd_offset = u32(buf, eocd + 16);
|
|
65
|
+
if (count == 0xFFFF || cd_size == 0xFFFFFFFF || cd_offset == 0xFFFFFFFF) return fail(err, "ZIP64 is not supported.");
|
|
66
|
+
if ((uint64_t)cd_offset + cd_size > eocd) return fail(err, "central directory out of range.");
|
|
67
|
+
if (count > ZipLimits::MAX_ENTRIES) return fail(err, "more than " + std::to_string(ZipLimits::MAX_ENTRIES) + " entries.");
|
|
68
|
+
uint64_t total = 0;
|
|
69
|
+
size_t p = cd_offset;
|
|
70
|
+
for (uint16_t i = 0; i < count; i++) {
|
|
71
|
+
if (p + 46 > buf.size() || u32(buf, p) != SIG_CENTRAL) return fail(err, "bad central directory entry.");
|
|
72
|
+
uint16_t made_by = u16(buf, p + 4);
|
|
73
|
+
uint16_t flags = u16(buf, p + 8);
|
|
74
|
+
ZipEntry e;
|
|
75
|
+
e.method = u16(buf, p + 10);
|
|
76
|
+
e.crc = u32(buf, p + 16);
|
|
77
|
+
e.comp_size = u32(buf, p + 20);
|
|
78
|
+
e.size = u32(buf, p + 24);
|
|
79
|
+
uint16_t name_len = u16(buf, p + 28);
|
|
80
|
+
uint16_t extra_len = u16(buf, p + 30);
|
|
81
|
+
uint16_t comment_len = u16(buf, p + 32);
|
|
82
|
+
uint32_t ext_attr = u32(buf, p + 38);
|
|
83
|
+
e.local_offset = u32(buf, p + 42);
|
|
84
|
+
if (p + 46 + name_len > buf.size()) return fail(err, "entry name out of range.");
|
|
85
|
+
e.name = buf.substr(p + 46, name_len);
|
|
86
|
+
p += 46 + (size_t)name_len + extra_len + comment_len;
|
|
87
|
+
if (flags & (0x0001 | 0x0040)) return fail(err, "encrypted entries are not supported (" + e.name + ").");
|
|
88
|
+
if (flags & 0x0008) return fail(err, "data descriptors are not supported (" + e.name + ").");
|
|
89
|
+
if (e.comp_size == 0xFFFFFFFF || e.size == 0xFFFFFFFF || e.local_offset == 0xFFFFFFFF) {
|
|
90
|
+
return fail(err, "ZIP64 is not supported.");
|
|
91
|
+
}
|
|
92
|
+
uint32_t unix_mode = (ext_attr >> 16) & 0xF000;
|
|
93
|
+
bool unix_host = (made_by >> 8) == 3;
|
|
94
|
+
if (unix_host && unix_mode == 0xA000) return fail(err, "symbolic links are not allowed (" + e.name + ").");
|
|
95
|
+
// Only regular files and folders (a mode of 0 means "not recorded").
|
|
96
|
+
if (unix_host && unix_mode != 0 && unix_mode != 0x8000 && unix_mode != 0x4000) {
|
|
97
|
+
return fail(err, "special files are not allowed (" + e.name + ").");
|
|
98
|
+
}
|
|
99
|
+
if (e.method != 0 && e.method != 8) {
|
|
100
|
+
return fail(err, "unsupported compression method " + std::to_string(e.method) + " (" + e.name + ").");
|
|
101
|
+
}
|
|
102
|
+
e.is_directory = !e.name.empty() && e.name.back() == '/';
|
|
103
|
+
e.executable = unix_host && ((ext_attr >> 16) & 0111) != 0;
|
|
104
|
+
if (e.method == 0 && e.comp_size != e.size) return fail(err, "stored size does not match (" + e.name + ").");
|
|
105
|
+
if (e.size > ZipLimits::MAX_ENTRY_BYTES) return fail(err, e.name + " is too large.");
|
|
106
|
+
if (e.is_directory && e.size != 0) return fail(err, "folder entry with data (" + e.name + ").");
|
|
107
|
+
total += e.size;
|
|
108
|
+
if (total > ZipLimits::MAX_TOTAL_BYTES) return fail(err, "the archive unpacks to more than 400 MB.");
|
|
109
|
+
if (!local_header_ok(buf, e)) return fail(err, "local header does not match the central directory (" + e.name + ").");
|
|
110
|
+
out.push_back(std::move(e));
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
bool zip_read(const std::string &buf, const ZipEntry &e, std::string &out, ZipError &err) {
|
|
116
|
+
size_t o = e.local_offset;
|
|
117
|
+
if ((uint64_t)o + 30 > buf.size() || u32(buf, o) != SIG_LOCAL) return fail(err, "bad local header (" + e.name + ").");
|
|
118
|
+
if (!local_header_ok(buf, e)) return fail(err, "local header does not match the central directory (" + e.name + ").");
|
|
119
|
+
uint16_t local_name_len = u16(buf, o + 26);
|
|
120
|
+
uint64_t start = (uint64_t)o + 30 + local_name_len + u16(buf, o + 28);
|
|
121
|
+
uint64_t end = start + e.comp_size;
|
|
122
|
+
if (end > buf.size()) return fail(err, "entry data out of range (" + e.name + ").");
|
|
123
|
+
if (e.method == 0) {
|
|
124
|
+
out.assign(buf, (size_t)start, e.comp_size);
|
|
125
|
+
} else {
|
|
126
|
+
out.assign(e.size, '\0');
|
|
127
|
+
unsigned int dest_len = e.size;
|
|
128
|
+
// tinf never writes past dest_len; a stream that wants more is a data error.
|
|
129
|
+
int res = tinf_uncompress(e.size ? &out[0] : nullptr, &dest_len, buf.data() + start, e.comp_size);
|
|
130
|
+
if (res != TINF_OK) return fail(err, "corrupt data (" + e.name + ").");
|
|
131
|
+
out.resize(dest_len);
|
|
132
|
+
}
|
|
133
|
+
if (out.size() != e.size) return fail(err, "size mismatch (" + e.name + ").");
|
|
134
|
+
if (tinf_crc32(out.data(), (unsigned int)out.size()) != e.crc && !(out.empty() && e.crc == 0)) {
|
|
135
|
+
return fail(err, "CRC mismatch (" + e.name + ").");
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
std::optional<std::vector<std::string>> zip_entry_parts(const std::string &name, ZipError &err) {
|
|
141
|
+
if (name.empty() || name.size() > ZipLimits::MAX_NAME_BYTES) { fail(err, "empty or overlong entry name."); return std::nullopt; }
|
|
142
|
+
for (unsigned char c : name) {
|
|
143
|
+
if (c < 0x20 || c > 0x7e) { fail(err, "non-ASCII or control characters in an entry name."); return std::nullopt; }
|
|
144
|
+
}
|
|
145
|
+
if (name.find('\\') != std::string::npos || name.find('\0') != std::string::npos) {
|
|
146
|
+
fail(err, "illegal characters in " + quoted(name) + ".");
|
|
147
|
+
return std::nullopt;
|
|
148
|
+
}
|
|
149
|
+
if (name[0] == '/' || (name.size() >= 2 && std::isalpha((unsigned char)name[0]) && name[1] == ':')) {
|
|
150
|
+
fail(err, "absolute path " + quoted(name) + ".");
|
|
151
|
+
return std::nullopt;
|
|
152
|
+
}
|
|
153
|
+
std::string trimmed = name.back() == '/' ? name.substr(0, name.size() - 1) : name;
|
|
154
|
+
std::vector<std::string> parts;
|
|
155
|
+
size_t start = 0;
|
|
156
|
+
for (;;) {
|
|
157
|
+
size_t slash = trimmed.find('/', start);
|
|
158
|
+
parts.push_back(trimmed.substr(start, slash == std::string::npos ? std::string::npos : slash - start));
|
|
159
|
+
if (slash == std::string::npos) break;
|
|
160
|
+
start = slash + 1;
|
|
161
|
+
}
|
|
162
|
+
for (const auto &part : parts) {
|
|
163
|
+
if (part.empty() || part == "." || part == ".." || part.find_first_of("<>:\"|?*") != std::string::npos ||
|
|
164
|
+
part.back() == '.' || part.back() == ' ') {
|
|
165
|
+
fail(err, "unsafe path " + quoted(name) + ".");
|
|
166
|
+
return std::nullopt;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return parts;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
bool zip_extract_plugin(const std::string &archive, const std::string &os, const std::string &dest_dir,
|
|
173
|
+
std::string &plugin_name, ZipError &err, uint64_t max_total) {
|
|
174
|
+
std::vector<ZipEntry> entries;
|
|
175
|
+
if (!zip_list(archive, entries, err)) return false;
|
|
176
|
+
bool mac = os == "macos";
|
|
177
|
+
std::set<std::string> candidates; // root plugin names for this OS
|
|
178
|
+
std::vector<std::vector<std::string>> parts(entries.size());
|
|
179
|
+
for (size_t i = 0; i < entries.size(); i++) {
|
|
180
|
+
auto p = zip_entry_parts(entries[i].name, err);
|
|
181
|
+
if (!p) return false; // one unsafe name refuses the whole archive
|
|
182
|
+
parts[i] = *p;
|
|
183
|
+
const std::string &top = parts[i][0];
|
|
184
|
+
std::string lower_top = top;
|
|
185
|
+
for (auto &c : lower_top) c = (char)std::tolower((unsigned char)c);
|
|
186
|
+
if (mac && ends_with(lower_top, ".plugin") && top.size() > 7 && parts[i].size() >= 4 &&
|
|
187
|
+
parts[i][1] == "Contents" && parts[i][2] == "MacOS" && !entries[i].is_directory) {
|
|
188
|
+
candidates.insert(top);
|
|
189
|
+
}
|
|
190
|
+
if (!mac && parts[i].size() == 1 && !entries[i].is_directory && ends_with(lower_top, ".aex") && top.size() > 4) {
|
|
191
|
+
candidates.insert(top);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (candidates.size() != 1) {
|
|
195
|
+
std::string what = mac ? "<Name>.plugin/Contents/MacOS/<binary>" : "<Name>.aex";
|
|
196
|
+
return fail(err, candidates.empty() ? "no " + what + " at the top level."
|
|
197
|
+
: "more than one " + what + " at the top level.");
|
|
198
|
+
}
|
|
199
|
+
plugin_name = *candidates.begin();
|
|
200
|
+
struct Item {
|
|
201
|
+
size_t index;
|
|
202
|
+
std::string rel; // path below dest_dir, '/'-separated
|
|
203
|
+
};
|
|
204
|
+
std::vector<Item> plan;
|
|
205
|
+
std::set<std::string> seen;
|
|
206
|
+
uint64_t total = 0;
|
|
207
|
+
for (size_t i = 0; i < entries.size(); i++) {
|
|
208
|
+
if (parts[i][0] != plugin_name) continue; // installers, readme, the other OS's plugin
|
|
209
|
+
std::string rel;
|
|
210
|
+
for (size_t k = 0; k < parts[i].size(); k++) rel += (k ? "/" : "") + parts[i][k];
|
|
211
|
+
std::string folded = rel;
|
|
212
|
+
for (auto &c : folded) c = (char)std::tolower((unsigned char)c);
|
|
213
|
+
// Case-insensitive duplicates would overwrite each other on APFS/NTFS.
|
|
214
|
+
if (!entries[i].is_directory && !seen.insert(folded).second) return fail(err, "duplicate entry " + quoted(entries[i].name) + ".");
|
|
215
|
+
total += entries[i].size;
|
|
216
|
+
if (total > max_total) return fail(err, "too large.");
|
|
217
|
+
plan.push_back({i, rel});
|
|
218
|
+
}
|
|
219
|
+
// Decompress and verify everything before writing anything.
|
|
220
|
+
std::vector<std::string> data(plan.size());
|
|
221
|
+
for (size_t k = 0; k < plan.size(); k++) {
|
|
222
|
+
if (entries[plan[k].index].is_directory) continue;
|
|
223
|
+
if (!zip_read(archive, entries[plan[k].index], data[k], err)) return false;
|
|
224
|
+
}
|
|
225
|
+
if (!fsu::mkdirs(dest_dir)) return fail(err, "cannot create the staging folder.");
|
|
226
|
+
for (size_t k = 0; k < plan.size(); k++) {
|
|
227
|
+
std::string target = dest_dir;
|
|
228
|
+
for (const auto &part : parts[plan[k].index]) target = fsu::join(target, part);
|
|
229
|
+
const ZipEntry &e = entries[plan[k].index];
|
|
230
|
+
if (e.is_directory) {
|
|
231
|
+
if (!fsu::mkdirs(target)) return fail(err, "cannot create " + plan[k].rel + ".");
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
// The plugin's own executable keeps its x bit; on macOS everything in
|
|
235
|
+
// Contents/MacOS is executable even if the archiver dropped the mode.
|
|
236
|
+
const auto &p = parts[plan[k].index];
|
|
237
|
+
bool exec = e.executable || (mac && p.size() >= 4 && p[1] == "Contents" && p[2] == "MacOS");
|
|
238
|
+
if (!fsu::write_file(target, data[k], exec)) return fail(err, "cannot write " + plan[k].rel + ".");
|
|
239
|
+
}
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
} // namespace apn
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Minimal ZIP reader for signed update archives (port of packages/runtime/src/zip.js).
|
|
2
|
+
// Stored and deflate entries; refuses ZIP64, encryption, symlinks, CRC/size
|
|
3
|
+
// mismatches and unsafe paths.
|
|
4
|
+
#pragma once
|
|
5
|
+
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
#include <optional>
|
|
8
|
+
#include <string>
|
|
9
|
+
#include <vector>
|
|
10
|
+
|
|
11
|
+
namespace apn {
|
|
12
|
+
|
|
13
|
+
struct ZipEntry {
|
|
14
|
+
std::string name;
|
|
15
|
+
bool is_directory = false;
|
|
16
|
+
bool executable = false; // POSIX x bit in the external attributes
|
|
17
|
+
uint16_t method = 0;
|
|
18
|
+
uint32_t crc = 0;
|
|
19
|
+
uint32_t comp_size = 0;
|
|
20
|
+
uint32_t size = 0;
|
|
21
|
+
uint32_t local_offset = 0;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Limits and rules mirror the server's release check
|
|
25
|
+
// (apps/api/src/lib/developer-platform/native-release.ts), as defence in depth.
|
|
26
|
+
struct ZipLimits {
|
|
27
|
+
static constexpr size_t MAX_ENTRIES = 1000;
|
|
28
|
+
static constexpr uint64_t MAX_ENTRY_BYTES = 128ULL * 1024 * 1024;
|
|
29
|
+
static constexpr uint64_t MAX_TOTAL_BYTES = 400ULL * 1024 * 1024;
|
|
30
|
+
static constexpr size_t MAX_NAME_BYTES = 255;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
struct ZipError {
|
|
34
|
+
std::string message;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Parses the central directory. On failure returns false and fills err.
|
|
38
|
+
bool zip_list(const std::string &archive, std::vector<ZipEntry> &out, ZipError &err);
|
|
39
|
+
// Decompresses one entry and checks its size and CRC.
|
|
40
|
+
bool zip_read(const std::string &archive, const ZipEntry &entry, std::string &out, ZipError &err);
|
|
41
|
+
|
|
42
|
+
// Splits and validates an entry name like the server: printable ASCII only,
|
|
43
|
+
// at most 255 bytes, no absolute paths, "..", ".", empty parts, backslashes,
|
|
44
|
+
// and no segment Windows cannot store (<>:"|?* or a trailing dot/space).
|
|
45
|
+
std::optional<std::vector<std::string>> zip_entry_parts(const std::string &name, ZipError &err);
|
|
46
|
+
|
|
47
|
+
// The release ZIP contract (docs/native-runtime-design.md, "Release ZIP"): at
|
|
48
|
+
// its root <Name>.plugin/ (macOS), <Name>.aex (Windows), mac-install.command,
|
|
49
|
+
// windows-install.bat, readme.txt. Extracts ONLY this OS's plugin into
|
|
50
|
+
// dest_dir (dest_dir/<Name>.plugin or dest_dir/<Name>.aex) after validating
|
|
51
|
+
// every entry of the archive and decompressing the chosen entries in memory
|
|
52
|
+
// first, so a corrupt or unsafe archive writes nothing. Exactly one plugin for
|
|
53
|
+
// the OS must be present. os: "macos" | "windows". plugin_name receives
|
|
54
|
+
// "<Name>.plugin" / "<Name>.aex".
|
|
55
|
+
bool zip_extract_plugin(const std::string &archive, const std::string &os, const std::string &dest_dir,
|
|
56
|
+
std::string &plugin_name, ZipError &err, uint64_t max_total = ZipLimits::MAX_TOTAL_BYTES);
|
|
57
|
+
|
|
58
|
+
} // namespace apn
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Monocypher as a whole is dual-licensed. Choose whichever licence you
|
|
2
|
+
want from the two licences listed below.
|
|
3
|
+
|
|
4
|
+
The first licence is a regular 2-clause BSD licence. The second licence
|
|
5
|
+
is the CC-0 from Creative Commons. It is intended to release Monocypher
|
|
6
|
+
to the public domain. The BSD licence serves as a fallback option.
|
|
7
|
+
|
|
8
|
+
See the individual files for specific information about who contributed
|
|
9
|
+
to what file during which years. See below for special notes.
|
|
10
|
+
|
|
11
|
+
Licence 1 (2-clause BSD)
|
|
12
|
+
------------------------
|
|
13
|
+
|
|
14
|
+
Copyright (c) 2017-2023, Loup Vaillant
|
|
15
|
+
Copyright (c) 2017-2019, Michael Savage
|
|
16
|
+
Copyright (c) 2017-2023, Fabio Scotoni
|
|
17
|
+
All rights reserved.
|
|
18
|
+
|
|
19
|
+
Redistribution and use in source and binary forms, with or without
|
|
20
|
+
modification, are permitted provided that the following conditions are
|
|
21
|
+
met:
|
|
22
|
+
|
|
23
|
+
1. Redistributions of source code must retain the above copyright
|
|
24
|
+
notice, this list of conditions and the following disclaimer.
|
|
25
|
+
|
|
26
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
27
|
+
notice, this list of conditions and the following disclaimer in the
|
|
28
|
+
documentation and/or other materials provided with the
|
|
29
|
+
distribution.
|
|
30
|
+
|
|
31
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
32
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
33
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
34
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
35
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
36
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
37
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
38
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
39
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
40
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
41
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
Licence 2 (CC-0)
|
|
45
|
+
----------------
|
|
46
|
+
|
|
47
|
+
> CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
48
|
+
> LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
49
|
+
> ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
50
|
+
> INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
51
|
+
> REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
52
|
+
> PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
53
|
+
> THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
54
|
+
> HEREUNDER.
|
|
55
|
+
|
|
56
|
+
### Statement of Purpose
|
|
57
|
+
|
|
58
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
59
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
60
|
+
and subsequent owner(s) (each and all, an "owner") of an original work
|
|
61
|
+
of authorship and/or a database (each, a "Work").
|
|
62
|
+
|
|
63
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
64
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
65
|
+
scientific works ("Commons") that the public can reliably and without
|
|
66
|
+
fear of later claims of infringement build upon, modify, incorporate in
|
|
67
|
+
other works, reuse and redistribute as freely as possible in any form
|
|
68
|
+
whatsoever and for any purposes, including without limitation commercial
|
|
69
|
+
purposes. These owners may contribute to the Commons to promote the
|
|
70
|
+
ideal of a free culture and the further production of creative, cultural
|
|
71
|
+
and scientific works, or to gain reputation or greater distribution for
|
|
72
|
+
their Work in part through the use and efforts of others.
|
|
73
|
+
|
|
74
|
+
For these and/or other purposes and motivations, and without any
|
|
75
|
+
expectation of additional consideration or compensation, the person
|
|
76
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or
|
|
77
|
+
she is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
78
|
+
elects to apply CC0 to the Work and publicly distribute the Work under
|
|
79
|
+
its terms, with knowledge of his or her Copyright and Related Rights in
|
|
80
|
+
the Work and the meaning and intended legal effect of CC0 on those
|
|
81
|
+
rights.
|
|
82
|
+
|
|
83
|
+
1. **Copyright and Related Rights.** A Work made available under CC0 may
|
|
84
|
+
be protected by copyright and related or neighboring rights
|
|
85
|
+
("Copyright and Related Rights"). Copyright and Related Rights
|
|
86
|
+
include, but are not limited to, the following:
|
|
87
|
+
|
|
88
|
+
- the right to reproduce, adapt, distribute, perform, display,
|
|
89
|
+
communicate, and translate a Work;
|
|
90
|
+
- moral rights retained by the original author(s) and/or
|
|
91
|
+
performer(s); publicity and privacy rights pertaining to a person's
|
|
92
|
+
image or likeness depicted in a Work;
|
|
93
|
+
- rights protecting against unfair competition in regards to a Work,
|
|
94
|
+
subject to the limitations in paragraph 4(a), below;
|
|
95
|
+
- rights protecting the extraction, dissemination, use and reuse of
|
|
96
|
+
data in a Work;
|
|
97
|
+
- database rights (such as those arising under Directive 96/9/EC of
|
|
98
|
+
the European Parliament and of the Council of 11 March 1996 on the
|
|
99
|
+
legal protection of databases, and under any national
|
|
100
|
+
implementation thereof, including any amended or successor version
|
|
101
|
+
of such directive); and
|
|
102
|
+
- other similar, equivalent or corresponding rights throughout the
|
|
103
|
+
world based on applicable law or treaty, and any national
|
|
104
|
+
implementations thereof.
|
|
105
|
+
|
|
106
|
+
2. **Waiver.** To the greatest extent permitted by, but not in
|
|
107
|
+
contravention of, applicable law, Affirmer hereby overtly, fully,
|
|
108
|
+
permanently, irrevocably and unconditionally waives, abandons, and
|
|
109
|
+
surrenders all of Affirmer's Copyright and Related Rights and
|
|
110
|
+
associated claims and causes of action, whether now known or unknown
|
|
111
|
+
(including existing as well as future claims and causes of action),
|
|
112
|
+
in the Work (i) in all territories worldwide, (ii) for the maximum
|
|
113
|
+
duration provided by applicable law or treaty (including future time
|
|
114
|
+
extensions), (iii) in any current or future medium and for any number
|
|
115
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
116
|
+
limitation commercial, advertising or promotional purposes (the
|
|
117
|
+
"Waiver"). Affirmer makes the Waiver for the benefit of each member
|
|
118
|
+
of the public at large and to the detriment of Affirmer's heirs and
|
|
119
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
120
|
+
revocation, rescission, cancellation, termination, or any other legal
|
|
121
|
+
or equitable action to disrupt the quiet enjoyment of the Work by the
|
|
122
|
+
public as contemplated by Affirmer's express Statement of Purpose.
|
|
123
|
+
|
|
124
|
+
3. **Public License Fallback.** Should any part of the Waiver for any
|
|
125
|
+
reason be judged legally invalid or ineffective under applicable law,
|
|
126
|
+
then the Waiver shall be preserved to the maximum extent permitted
|
|
127
|
+
taking into account Affirmer's express Statement of Purpose. In
|
|
128
|
+
addition, to the extent the Waiver is so judged Affirmer hereby
|
|
129
|
+
grants to each affected person a royalty-free, non transferable, non
|
|
130
|
+
sublicensable, non exclusive, irrevocable and unconditional license
|
|
131
|
+
to exercise Affirmer's Copyright and Related Rights in the Work (i)
|
|
132
|
+
in all territories worldwide, (ii) for the maximum duration provided
|
|
133
|
+
by applicable law or treaty (including future time extensions), (iii)
|
|
134
|
+
in any current or future medium and for any number of copies, and
|
|
135
|
+
(iv) for any purpose whatsoever, including without limitation
|
|
136
|
+
commercial, advertising or promotional purposes (the "License"). The
|
|
137
|
+
License shall be deemed effective as of the date CC0 was applied by
|
|
138
|
+
Affirmer to the Work. Should any part of the License for any reason
|
|
139
|
+
be judged legally invalid or ineffective under applicable law, such
|
|
140
|
+
partial invalidity or ineffectiveness shall not invalidate the
|
|
141
|
+
remainder of the License, and in such case Affirmer hereby affirms
|
|
142
|
+
that he or she will not (i) exercise any of his or her remaining
|
|
143
|
+
Copyright and Related Rights in the Work or (ii) assert any
|
|
144
|
+
associated claims and causes of action with respect to the Work, in
|
|
145
|
+
either case contrary to Affirmer's express Statement of Purpose.
|
|
146
|
+
|
|
147
|
+
4. **Limitations and Disclaimers.**
|
|
148
|
+
|
|
149
|
+
- No trademark or patent rights held by Affirmer are waived,
|
|
150
|
+
abandoned, surrendered, licensed or otherwise affected by this
|
|
151
|
+
document.
|
|
152
|
+
- Affirmer offers the Work as-is and makes no representations or
|
|
153
|
+
warranties of any kind concerning the Work, express, implied,
|
|
154
|
+
statutory or otherwise, including without limitation warranties of
|
|
155
|
+
title, merchantability, fitness for a particular purpose, non
|
|
156
|
+
infringement, or the absence of latent or other defects, accuracy,
|
|
157
|
+
or the present or absence of errors, whether or not discoverable,
|
|
158
|
+
all to the greatest extent permissible under applicable law.
|
|
159
|
+
- Affirmer disclaims responsibility for clearing rights of other
|
|
160
|
+
persons that may apply to the Work or any use thereof, including
|
|
161
|
+
without limitation any person's Copyright and Related Rights in the
|
|
162
|
+
Work. Further, Affirmer disclaims responsibility for obtaining any
|
|
163
|
+
necessary consents, permissions or other rights required for any
|
|
164
|
+
use of the Work.
|
|
165
|
+
- Affirmer understands and acknowledges that Creative Commons is not
|
|
166
|
+
a party to this document and has no duty or obligation with respect
|
|
167
|
+
to this CC0 or use of the Work.
|