@afterpack/protection-map 0.1.0-rc.20260925T1347
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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +55 -0
- package/codec.mjs +292 -0
- package/index.d.ts +53 -0
- package/index.mjs +1 -0
- package/package.json +63 -0
- package/render-core.mjs +83 -0
- package/render.mjs +66 -0
- package/template.html +4302 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 AfterPack
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @afterpack/protection-map
|
|
2
|
+
|
|
3
|
+
The viewer for the [AfterPack](https://www.afterpack.dev) Protection Map: a single HTML file that
|
|
4
|
+
shows your original source, shaded by how strongly each part was protected, with the weak spots a
|
|
5
|
+
build left readable.
|
|
6
|
+
|
|
7
|
+
You usually do not need to install this package. The AfterPack CLI and every AfterPack plugin
|
|
8
|
+
already use it to write `.afterpack/protectionMap.html` when your build has source maps. Open that
|
|
9
|
+
file in a browser. It works offline, straight from disk. Two options control it:
|
|
10
|
+
[`protectionMap.enabled`](https://www.afterpack.dev/docs/config#protectionMap-enabled) turns it on
|
|
11
|
+
or off, and [`protectionMap.detailed`](https://www.afterpack.dev/docs/config#protectionMap-detailed)
|
|
12
|
+
set to `false` leaves out the per-region list of transformations for a smaller file.
|
|
13
|
+
|
|
14
|
+
The Protection Map contains your original source. Keep it local: never deploy, publish or commit
|
|
15
|
+
it. The AfterPack tools add `.afterpack/` to your `.gitignore` for you.
|
|
16
|
+
|
|
17
|
+
## Render one yourself
|
|
18
|
+
|
|
19
|
+
If you have Protection Map data as JSON, render it with the bundled command. The template ships
|
|
20
|
+
with the package:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
npx afterpack-protection-map report.json protection-map.html
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Add `--no-lineage` for a smaller file without the per-region transform history.
|
|
27
|
+
|
|
28
|
+
Or from Node:
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import { writeFileSync } from "node:fs";
|
|
32
|
+
import { renderProtectionMapHtml } from "@afterpack/protection-map";
|
|
33
|
+
|
|
34
|
+
const { html } = renderProtectionMapHtml(data);
|
|
35
|
+
writeFileSync("protection-map.html", html);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`renderProtectionMapHtml(data, { template, includeLineage })` uses the bundled template unless you
|
|
39
|
+
pass one, and includes lineage unless `includeLineage` is `false`.
|
|
40
|
+
|
|
41
|
+
## Links
|
|
42
|
+
|
|
43
|
+
- [How to read the Protection Map](https://www.afterpack.dev/docs/protection-map)
|
|
44
|
+
- [Presets and protection levels](https://www.afterpack.dev/docs/presets)
|
|
45
|
+
- [Complexity](https://www.afterpack.dev/docs/complexity)
|
|
46
|
+
- [Directives for protecting specific code](https://www.afterpack.dev/docs/directives)
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
Apache-2.0.
|
|
51
|
+
|
|
52
|
+
## Feedback
|
|
53
|
+
|
|
54
|
+
Questions, suggestions and bug reports: [afterpack.dev/contact](https://www.afterpack.dev/contact).
|
|
55
|
+
You can also file a bug on [GitHub Issues](https://github.com/afterpack-dev/afterpack/issues).
|
package/codec.mjs
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
export const COMPACT_SCHEMA_VERSION = 5;
|
|
2
|
+
|
|
3
|
+
const DICT_FIELDS = [
|
|
4
|
+
"nodeKind",
|
|
5
|
+
"preservedReason",
|
|
6
|
+
"reversalClass",
|
|
7
|
+
"band",
|
|
8
|
+
"costClass",
|
|
9
|
+
"transform",
|
|
10
|
+
"category",
|
|
11
|
+
"phase",
|
|
12
|
+
"severity",
|
|
13
|
+
"mechanism",
|
|
14
|
+
"disposition",
|
|
15
|
+
"reason",
|
|
16
|
+
"proHint",
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const REGION_COLUMNS = [
|
|
20
|
+
"span",
|
|
21
|
+
"nodeKind",
|
|
22
|
+
"preservedReason",
|
|
23
|
+
"reversalClass",
|
|
24
|
+
"score",
|
|
25
|
+
"entropyRaw",
|
|
26
|
+
"transformCount",
|
|
27
|
+
"sizeDeltaEst",
|
|
28
|
+
"costClass",
|
|
29
|
+
"decodeOps",
|
|
30
|
+
"callFrames",
|
|
31
|
+
"band",
|
|
32
|
+
];
|
|
33
|
+
const SPOTLIGHT_COLUMNS = [
|
|
34
|
+
"span",
|
|
35
|
+
"severity",
|
|
36
|
+
"mechanism",
|
|
37
|
+
"disposition",
|
|
38
|
+
"sample",
|
|
39
|
+
"bytes",
|
|
40
|
+
"reason",
|
|
41
|
+
"proHint",
|
|
42
|
+
"reversalClass",
|
|
43
|
+
];
|
|
44
|
+
const LINEAGE_COLUMNS = ["transform", "category", "phase", "entropyGain", "sizeDeltaEst", "label"];
|
|
45
|
+
|
|
46
|
+
function regionScalar(r, col) {
|
|
47
|
+
switch (col) {
|
|
48
|
+
case "span":
|
|
49
|
+
return r.span;
|
|
50
|
+
case "nodeKind":
|
|
51
|
+
return r.nodeKind;
|
|
52
|
+
case "preservedReason":
|
|
53
|
+
return r.preservedReason;
|
|
54
|
+
case "reversalClass":
|
|
55
|
+
return r.reversalClass;
|
|
56
|
+
case "score":
|
|
57
|
+
return r.score;
|
|
58
|
+
case "entropyRaw":
|
|
59
|
+
return r.entropyRaw;
|
|
60
|
+
case "transformCount":
|
|
61
|
+
return r.transformCount;
|
|
62
|
+
case "sizeDeltaEst":
|
|
63
|
+
return r.sizeDeltaEst;
|
|
64
|
+
case "costClass":
|
|
65
|
+
return r.perf ? r.perf.costClass : undefined;
|
|
66
|
+
case "decodeOps":
|
|
67
|
+
return r.perf ? r.perf.decodeOps : undefined;
|
|
68
|
+
case "callFrames":
|
|
69
|
+
return r.perf ? r.perf.callFrames : undefined;
|
|
70
|
+
case "band":
|
|
71
|
+
return r.band;
|
|
72
|
+
default:
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function spotScalar(s, col) {
|
|
78
|
+
switch (col) {
|
|
79
|
+
case "span":
|
|
80
|
+
return s.span;
|
|
81
|
+
case "severity":
|
|
82
|
+
return s.severity;
|
|
83
|
+
case "mechanism":
|
|
84
|
+
return s.mechanism;
|
|
85
|
+
case "disposition":
|
|
86
|
+
return s.disposition;
|
|
87
|
+
case "sample":
|
|
88
|
+
return s.sample;
|
|
89
|
+
case "bytes":
|
|
90
|
+
return s.bytes;
|
|
91
|
+
case "reason":
|
|
92
|
+
return s.reason;
|
|
93
|
+
case "proHint":
|
|
94
|
+
return s.proHint;
|
|
95
|
+
case "reversalClass":
|
|
96
|
+
return s.reversalClass;
|
|
97
|
+
default:
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function encodeCompact(data, { includeLineage = true } = {}) {
|
|
103
|
+
const files = data && Array.isArray(data.files) ? data.files : [];
|
|
104
|
+
|
|
105
|
+
const dictMaps = new Map();
|
|
106
|
+
const dict = {};
|
|
107
|
+
for (const f of DICT_FIELDS) {
|
|
108
|
+
dictMaps.set(f, new Map());
|
|
109
|
+
dict[f] = [];
|
|
110
|
+
}
|
|
111
|
+
const isNullHole = (value) => value == null;
|
|
112
|
+
const intern = (field, value) => {
|
|
113
|
+
if (isNullHole(value)) return value;
|
|
114
|
+
const m = dictMaps.get(field);
|
|
115
|
+
let idx = m.get(value);
|
|
116
|
+
if (idx === undefined) {
|
|
117
|
+
idx = dict[field].length;
|
|
118
|
+
dict[field].push(value);
|
|
119
|
+
m.set(value, idx);
|
|
120
|
+
}
|
|
121
|
+
return idx;
|
|
122
|
+
};
|
|
123
|
+
const isDict = (col) => dictMaps.has(col);
|
|
124
|
+
|
|
125
|
+
const legend = {};
|
|
126
|
+
|
|
127
|
+
const encFiles = files.map((fdoc) => {
|
|
128
|
+
const regions = fdoc && Array.isArray(fdoc.regions) ? fdoc.regions : [];
|
|
129
|
+
const spotlights = fdoc && Array.isArray(fdoc.spotlights) ? fdoc.spotlights : [];
|
|
130
|
+
|
|
131
|
+
for (const r of regions) {
|
|
132
|
+
const cls = r?.reversalClass;
|
|
133
|
+
if (cls != null && !(cls in legend)) {
|
|
134
|
+
legend[cls] = {
|
|
135
|
+
why: r.why == null ? null : r.why,
|
|
136
|
+
tier: r.tier == null ? null : r.tier,
|
|
137
|
+
ceiling: r.ceiling == null ? null : r.ceiling,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const rcols = {};
|
|
143
|
+
for (const col of REGION_COLUMNS) {
|
|
144
|
+
const dictted = isDict(col);
|
|
145
|
+
const arr = new Array(regions.length);
|
|
146
|
+
for (let i = 0; i < regions.length; i++) {
|
|
147
|
+
const v = regionScalar(regions[i], col);
|
|
148
|
+
arr[i] = dictted ? intern(col, v) : v;
|
|
149
|
+
}
|
|
150
|
+
rcols[col] = arr;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (includeLineage) {
|
|
154
|
+
const lin = new Array(regions.length);
|
|
155
|
+
const capped = {};
|
|
156
|
+
let hasLineage = false;
|
|
157
|
+
let hasCapped = false;
|
|
158
|
+
for (let i = 0; i < regions.length; i++) {
|
|
159
|
+
const steps = regions[i] && Array.isArray(regions[i].lineage) ? regions[i].lineage : [];
|
|
160
|
+
if (steps.length) hasLineage = true;
|
|
161
|
+
lin[i] = steps.map((st) => [
|
|
162
|
+
intern("transform", st.transform),
|
|
163
|
+
intern("category", st.category),
|
|
164
|
+
intern("phase", st.phase),
|
|
165
|
+
st.entropyGain,
|
|
166
|
+
st.sizeDeltaEst,
|
|
167
|
+
st.label == null ? null : st.label,
|
|
168
|
+
]);
|
|
169
|
+
const lc = regions[i]?.lineageCapped;
|
|
170
|
+
if (lc != null) {
|
|
171
|
+
capped[i] = lc;
|
|
172
|
+
hasCapped = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (hasLineage) rcols.lineage = lin;
|
|
176
|
+
if (hasCapped) rcols.lineageCapped = capped;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const scols = {};
|
|
180
|
+
for (const col of SPOTLIGHT_COLUMNS) {
|
|
181
|
+
const dictted = isDict(col);
|
|
182
|
+
const arr = new Array(spotlights.length);
|
|
183
|
+
for (let j = 0; j < spotlights.length; j++) {
|
|
184
|
+
const v = spotScalar(spotlights[j], col);
|
|
185
|
+
arr[j] = dictted ? intern(col, v) : v;
|
|
186
|
+
}
|
|
187
|
+
scols[col] = arr;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
file: fdoc.file,
|
|
192
|
+
regions: { n: regions.length, cols: rcols },
|
|
193
|
+
spotlights: { n: spotlights.length, cols: scols },
|
|
194
|
+
aggregate: fdoc.aggregate,
|
|
195
|
+
...(fdoc.renamedSpans?.length ? { renamedSpans: fdoc.renamedSpans } : {}),
|
|
196
|
+
...(fdoc.extractedSpans?.length ? { extractedSpans: fdoc.extractedSpans } : {}),
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const prunedDict = {};
|
|
201
|
+
for (const f of DICT_FIELDS) {
|
|
202
|
+
if (dict[f].length) prunedDict[f] = dict[f];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
schemaVersion: COMPACT_SCHEMA_VERSION,
|
|
207
|
+
...(data && data.spanUnits !== undefined ? { spanUnits: data.spanUnits } : {}),
|
|
208
|
+
generatedAt: data && data.generatedAt !== undefined ? data.generatedAt : null,
|
|
209
|
+
engine: data && data.engine !== undefined ? data.engine : null,
|
|
210
|
+
legend,
|
|
211
|
+
dict: prunedDict,
|
|
212
|
+
columns: { region: REGION_COLUMNS, spotlight: SPOTLIGHT_COLUMNS, lineage: LINEAGE_COLUMNS },
|
|
213
|
+
files: encFiles,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function afterpackDecodeDocument(c) {
|
|
218
|
+
const dict = c.dict || {};
|
|
219
|
+
const cols = c.columns || {};
|
|
220
|
+
const regionCols = cols.region || [];
|
|
221
|
+
const spotCols = cols.spotlight || [];
|
|
222
|
+
const lineageCols = cols.lineage || [];
|
|
223
|
+
const legend = c.legend || {};
|
|
224
|
+
|
|
225
|
+
const decodeTable = (table, colNames) => {
|
|
226
|
+
const n = table?.n || 0;
|
|
227
|
+
const src = table?.cols || {};
|
|
228
|
+
const rows = new Array(n);
|
|
229
|
+
for (let i = 0; i < n; i++) rows[i] = {};
|
|
230
|
+
for (const col of colNames) {
|
|
231
|
+
const arr = src[col];
|
|
232
|
+
const d = dict[col];
|
|
233
|
+
for (let i = 0; i < n; i++) {
|
|
234
|
+
const v = arr ? arr[i] : undefined;
|
|
235
|
+
rows[i][col] = d ? d[v] : v;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return { rows, src };
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const files = (c.files || []).map((fc) => {
|
|
242
|
+
const rdec = decodeTable(fc.regions, regionCols);
|
|
243
|
+
const regions = rdec.rows;
|
|
244
|
+
const rsrc = rdec.src;
|
|
245
|
+
for (let i = 0; i < regions.length; i++) {
|
|
246
|
+
const region = regions[i];
|
|
247
|
+
const decodeOps = region.decodeOps;
|
|
248
|
+
region.perf = { costClass: region.costClass, decodeOps, callFrames: region.callFrames };
|
|
249
|
+
delete region.costClass;
|
|
250
|
+
delete region.decodeOps;
|
|
251
|
+
delete region.callFrames;
|
|
252
|
+
region.lineage = rsrc.lineage
|
|
253
|
+
? (rsrc.lineage[i] || []).map((t) => {
|
|
254
|
+
const step = {};
|
|
255
|
+
for (let k = 0; k < lineageCols.length; k++) {
|
|
256
|
+
const lc = lineageCols[k];
|
|
257
|
+
step[lc] = dict[lc] ? dict[lc][t[k]] : t[k];
|
|
258
|
+
}
|
|
259
|
+
return step;
|
|
260
|
+
})
|
|
261
|
+
: [];
|
|
262
|
+
if (rsrc.lineageCapped && rsrc.lineageCapped[i] != null) {
|
|
263
|
+
region.lineageCapped = rsrc.lineageCapped[i];
|
|
264
|
+
}
|
|
265
|
+
const lg = legend[region.reversalClass] || {};
|
|
266
|
+
region.why = lg.why == null ? undefined : lg.why;
|
|
267
|
+
region.tier = lg.tier == null ? null : lg.tier;
|
|
268
|
+
region.ceiling = lg.ceiling == null ? null : lg.ceiling;
|
|
269
|
+
region.annotations = decodeOps > 0 ? ["materializationSite"] : [];
|
|
270
|
+
region.outputSpan = null;
|
|
271
|
+
}
|
|
272
|
+
const sdec = decodeTable(fc.spotlights, spotCols);
|
|
273
|
+
return {
|
|
274
|
+
file: fc.file,
|
|
275
|
+
regions,
|
|
276
|
+
spotlights: sdec.rows,
|
|
277
|
+
aggregate: fc.aggregate,
|
|
278
|
+
renamedSpans: fc.renamedSpans || [],
|
|
279
|
+
extractedSpans: fc.extractedSpans || [],
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
return {
|
|
284
|
+
schemaVersion: c.schemaVersion,
|
|
285
|
+
...(c.spanUnits !== undefined ? { spanUnits: c.spanUnits } : {}),
|
|
286
|
+
generatedAt: c.generatedAt !== undefined ? c.generatedAt : null,
|
|
287
|
+
engine: c.engine !== undefined ? c.engine : null,
|
|
288
|
+
files,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export { afterpackDecodeDocument, afterpackDecodeDocument as decodeCompact };
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** What AfterPack applied to a build, file by file. It contains your original source, so keep it private. */
|
|
2
|
+
export interface ProtectionMap {
|
|
3
|
+
schemaVersion: number;
|
|
4
|
+
spanUnits?: "utf16";
|
|
5
|
+
generatedAt: string | null;
|
|
6
|
+
engine: {
|
|
7
|
+
version: string;
|
|
8
|
+
backend: string;
|
|
9
|
+
seed: number;
|
|
10
|
+
preset: "minify" | "light" | "medium" | "hard" | "extreme" | null;
|
|
11
|
+
complexity: number;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
files: ProtectionMapFile[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** One file of a {@link ProtectionMap}. */
|
|
18
|
+
export interface ProtectionMapFile {
|
|
19
|
+
file: {
|
|
20
|
+
path: string | null;
|
|
21
|
+
originalSource: string;
|
|
22
|
+
inputSize: number;
|
|
23
|
+
outputSize: number;
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
};
|
|
26
|
+
regions: Record<string, unknown>[];
|
|
27
|
+
spotlights: Record<string, unknown>[];
|
|
28
|
+
aggregate: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface RenderProtectionMapOptions {
|
|
32
|
+
/** An HTML template to render into. Defaults to the one bundled with this package. */
|
|
33
|
+
template?: string;
|
|
34
|
+
/** Keep the per-region transform history. Defaults to `true`. */
|
|
35
|
+
includeLineage?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface RenderedProtectionMap {
|
|
39
|
+
/** The self-contained HTML report. */
|
|
40
|
+
html: string;
|
|
41
|
+
/** The number of files in the report. */
|
|
42
|
+
files: number;
|
|
43
|
+
/** The number of regions whose transform history was shortened. */
|
|
44
|
+
cappedRegions: number;
|
|
45
|
+
/** The number of transform history steps removed. */
|
|
46
|
+
totalLineageStepsRemoved: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Render Protection Map data into one self-contained HTML file. */
|
|
50
|
+
export declare function renderProtectionMapHtml(
|
|
51
|
+
data: ProtectionMap | { files: ProtectionMapFile[] },
|
|
52
|
+
options?: RenderProtectionMapOptions,
|
|
53
|
+
): RenderedProtectionMap;
|
package/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { renderProtectionMapHtml } from "./render-core.mjs";
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@afterpack/protection-map",
|
|
3
|
+
"version": "0.1.0-rc.20260925T1347",
|
|
4
|
+
"description": "AfterPack Protection Map viewer: render protection data into a self-contained HTML report",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.mjs",
|
|
7
|
+
"types": "./index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"default": "./index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"./template.html": "./template.html"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"afterpack-protection-map": "./render.mjs"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"NOTICE",
|
|
21
|
+
"README.md",
|
|
22
|
+
"codec.mjs",
|
|
23
|
+
"index.d.ts",
|
|
24
|
+
"index.mjs",
|
|
25
|
+
"render-core.mjs",
|
|
26
|
+
"render.mjs",
|
|
27
|
+
"template.html"
|
|
28
|
+
],
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/afterpack-dev/afterpack.git",
|
|
35
|
+
"directory": "packages/protection-map"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"obfuscation",
|
|
39
|
+
"obfuscator",
|
|
40
|
+
"javascript-obfuscator",
|
|
41
|
+
"code-protection",
|
|
42
|
+
"source-code-protection",
|
|
43
|
+
"javascript-security",
|
|
44
|
+
"protection-map",
|
|
45
|
+
"heatmap",
|
|
46
|
+
"report",
|
|
47
|
+
"afterpack"
|
|
48
|
+
],
|
|
49
|
+
"author": "AfterPack (https://www.afterpack.dev)",
|
|
50
|
+
"license": "Apache-2.0",
|
|
51
|
+
"homepage": "https://www.afterpack.dev/docs/protection-map",
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/afterpack-dev/afterpack/issues"
|
|
54
|
+
},
|
|
55
|
+
"engines": {
|
|
56
|
+
"node": ">=18"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"lint": "biome check .",
|
|
60
|
+
"lint:fix": "biome check --write .",
|
|
61
|
+
"test": "node --test"
|
|
62
|
+
}
|
|
63
|
+
}
|