@tsvm/bytecode 0.1.0 → 0.1.2
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 +21 -0
- package/dist/index.js +11 -11
- package/package.json +34 -34
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BlackVault Malware Lab
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.js
CHANGED
|
@@ -4,12 +4,9 @@ function generateRemappedOpcodes(seed) {
|
|
|
4
4
|
const forward = /* @__PURE__ */ new Map();
|
|
5
5
|
const reverse = /* @__PURE__ */ new Map();
|
|
6
6
|
const rng = new SeededRandom(seed);
|
|
7
|
-
const opcodes =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
opcodes.push(Number(key));
|
|
11
|
-
}
|
|
12
|
-
}
|
|
7
|
+
const opcodes = Object.values(OpCode).filter(
|
|
8
|
+
(v) => typeof v === "number"
|
|
9
|
+
);
|
|
13
10
|
const availableSlots = [];
|
|
14
11
|
for (let i = 0; i < 256; i++) {
|
|
15
12
|
availableSlots.push(i);
|
|
@@ -53,7 +50,7 @@ function encodeBytecode(instructions, mapping, config, rng) {
|
|
|
53
50
|
if (Array.isArray(forward)) {
|
|
54
51
|
if (!rng) throw new Error("SeededRandom required when opcodeMap is provided");
|
|
55
52
|
mappedOp = forward[Math.floor(rng.next() * forward.length)];
|
|
56
|
-
} else if (forward
|
|
53
|
+
} else if (typeof forward === "number") {
|
|
57
54
|
mappedOp = forward;
|
|
58
55
|
}
|
|
59
56
|
}
|
|
@@ -499,11 +496,11 @@ function compileToBytecode(irModule, config) {
|
|
|
499
496
|
changed = true;
|
|
500
497
|
}
|
|
501
498
|
const inst = flatInsts[i];
|
|
502
|
-
let mappedOp = inst.mappedOp
|
|
503
|
-
const forward = mapping.forward.get(inst.opcode);
|
|
499
|
+
let mappedOp = inst.mappedOp ?? inst.opcode;
|
|
504
500
|
if (inst.mappedOp === void 0) {
|
|
501
|
+
const forward = mapping.forward.get(inst.opcode);
|
|
505
502
|
if (Array.isArray(forward)) mappedOp = forward[0];
|
|
506
|
-
else if (forward
|
|
503
|
+
else if (typeof forward === "number") mappedOp = forward;
|
|
507
504
|
}
|
|
508
505
|
let size = 1;
|
|
509
506
|
if (config.junkInsertion) {
|
|
@@ -605,6 +602,9 @@ function compileToBytecode(irModule, config) {
|
|
|
605
602
|
|
|
606
603
|
// src/decoder.ts
|
|
607
604
|
import { ImmediateEncodingScheme as ImmediateEncodingScheme2, ConstantEncodingScheme as ConstantEncodingScheme2, OperandKind as OperandKind3, OpCode as OpCode4, ConstantKind } from "@tsvm/shared";
|
|
605
|
+
function assertOpCode(value) {
|
|
606
|
+
return value;
|
|
607
|
+
}
|
|
608
608
|
function numToOperandKind(kind) {
|
|
609
609
|
switch (kind) {
|
|
610
610
|
case 0:
|
|
@@ -747,7 +747,7 @@ function decodeBytecode(bytes, mapping, config) {
|
|
|
747
747
|
mappedOp = raw[offset.pos++];
|
|
748
748
|
}
|
|
749
749
|
const canonicalOp = mapping.reverse.get(mappedOp);
|
|
750
|
-
const opcode = canonicalOp ?? mappedOp;
|
|
750
|
+
const opcode = canonicalOp ?? assertOpCode(mappedOp);
|
|
751
751
|
const numJunk = config.junkInsertion ? (opcode * 7 + config.seed) % 4 : 0;
|
|
752
752
|
offset.pos += numJunk;
|
|
753
753
|
const layout = opcodeLayout[opcode] ?? OPCODE_DEFAULT_LAYOUT;
|
package/package.json
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@tsvm/bytecode",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"files": [
|
|
5
|
-
"dist",
|
|
6
|
-
"LICENSE"
|
|
7
|
-
],
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"publishConfig": {
|
|
10
|
-
"access": "public"
|
|
11
|
-
},
|
|
12
|
-
"type": "module",
|
|
13
|
-
"main": "./dist/index.js",
|
|
14
|
-
"types": "./dist/index.d.ts",
|
|
15
|
-
"exports": {
|
|
16
|
-
".": {
|
|
17
|
-
"types": "./dist/index.d.ts",
|
|
18
|
-
"import": "./dist/index.js"
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@tsvm/bytecode",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"files": [
|
|
5
|
+
"dist",
|
|
6
|
+
"LICENSE"
|
|
7
|
+
],
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@tsvm/shared": "0.1.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"tsup": "^8.4.0",
|
|
26
|
+
"typescript": "^5.8.0"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsup ./src/index.ts --format esm --dts --clean",
|
|
30
|
+
"test": "pnpm --dir ../.. exec vitest run packages/bytecode/tests/**/*.test.ts --config vitest.config.mjs",
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"clean": "rm -rf dist"
|
|
33
|
+
}
|
|
34
|
+
}
|