roxify 1.2.6 → 1.2.8
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/CHANGELOG.md +36 -0
- package/LICENSE +21 -21
- package/README.md +370 -117
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +606 -606
- package/dist/index.d.ts +13 -13
- package/dist/index.js +13 -13
- package/dist/minpng.d.ts +8 -8
- package/dist/minpng.js +238 -238
- package/dist/pack.d.ts +31 -27
- package/dist/pack.js +188 -184
- package/dist/utils/constants.d.ts +38 -38
- package/dist/utils/constants.js +22 -22
- package/dist/utils/crc.d.ts +4 -4
- package/dist/utils/crc.js +29 -29
- package/dist/utils/decoder.d.ts +4 -4
- package/dist/utils/decoder.js +665 -626
- package/dist/utils/encoder.d.ts +4 -4
- package/dist/utils/encoder.js +422 -348
- package/dist/utils/errors.d.ts +9 -9
- package/dist/utils/errors.js +18 -18
- package/dist/utils/helpers.d.ts +11 -11
- package/dist/utils/helpers.js +112 -76
- package/dist/utils/inspection.d.ts +19 -19
- package/dist/utils/inspection.js +518 -518
- package/dist/utils/optimization.d.ts +3 -3
- package/dist/utils/optimization.js +640 -636
- package/dist/utils/reconstitution.d.ts +3 -3
- package/dist/utils/reconstitution.js +266 -266
- package/dist/utils/types.d.ts +44 -44
- package/dist/utils/types.js +1 -1
- package/dist/utils/zstd.d.ts +17 -17
- package/dist/utils/zstd.js +153 -118
- package/libroxify_native.node +0 -0
- package/package.json +47 -65
package/dist/utils/errors.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export declare class PassphraseRequiredError extends Error {
|
|
2
|
-
constructor(message?: string);
|
|
3
|
-
}
|
|
4
|
-
export declare class IncorrectPassphraseError extends Error {
|
|
5
|
-
constructor(message?: string);
|
|
6
|
-
}
|
|
7
|
-
export declare class DataFormatError extends Error {
|
|
8
|
-
constructor(message?: string);
|
|
9
|
-
}
|
|
1
|
+
export declare class PassphraseRequiredError extends Error {
|
|
2
|
+
constructor(message?: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class IncorrectPassphraseError extends Error {
|
|
5
|
+
constructor(message?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class DataFormatError extends Error {
|
|
8
|
+
constructor(message?: string);
|
|
9
|
+
}
|
package/dist/utils/errors.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export class PassphraseRequiredError extends Error {
|
|
2
|
-
constructor(message = 'Passphrase required') {
|
|
3
|
-
super(message);
|
|
4
|
-
this.name = 'PassphraseRequiredError';
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
export class IncorrectPassphraseError extends Error {
|
|
8
|
-
constructor(message = 'Incorrect passphrase') {
|
|
9
|
-
super(message);
|
|
10
|
-
this.name = 'IncorrectPassphraseError';
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export class DataFormatError extends Error {
|
|
14
|
-
constructor(message = 'Data format error') {
|
|
15
|
-
super(message);
|
|
16
|
-
this.name = 'DataFormatError';
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
export class PassphraseRequiredError extends Error {
|
|
2
|
+
constructor(message = 'Passphrase required') {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = 'PassphraseRequiredError';
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export class IncorrectPassphraseError extends Error {
|
|
8
|
+
constructor(message = 'Incorrect passphrase') {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'IncorrectPassphraseError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class DataFormatError extends Error {
|
|
14
|
+
constructor(message = 'Data format error') {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = 'DataFormatError';
|
|
17
|
+
}
|
|
18
|
+
}
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
export declare function colorsToBytes(colors: Array<{
|
|
4
|
-
r: number;
|
|
5
|
-
g: number;
|
|
6
|
-
b: number;
|
|
7
|
-
}>): Buffer;
|
|
8
|
-
export declare function deltaEncode(data: Buffer): Buffer;
|
|
9
|
-
export declare function deltaDecode(data: Buffer): Buffer;
|
|
10
|
-
export declare function applyXor(buf: Buffer, passphrase: string): Buffer;
|
|
11
|
-
export declare function tryDecryptIfNeeded(buf: Buffer, passphrase?: string): Buffer;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
export declare function colorsToBytes(colors: Array<{
|
|
4
|
+
r: number;
|
|
5
|
+
g: number;
|
|
6
|
+
b: number;
|
|
7
|
+
}>): Buffer;
|
|
8
|
+
export declare function deltaEncode(data: Buffer): Buffer;
|
|
9
|
+
export declare function deltaDecode(data: Buffer): Buffer;
|
|
10
|
+
export declare function applyXor(buf: Buffer, passphrase: string): Buffer;
|
|
11
|
+
export declare function tryDecryptIfNeeded(buf: Buffer, passphrase?: string): Buffer;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -1,76 +1,112 @@
|
|
|
1
|
-
import { createDecipheriv, pbkdf2Sync } from 'crypto';
|
|
2
|
-
import { ENC_AES, ENC_NONE, ENC_XOR } from './constants.js';
|
|
3
|
-
import { IncorrectPassphraseError, PassphraseRequiredError } from './errors.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
catch (e) {
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
return
|
|
76
|
-
}
|
|
1
|
+
import { createDecipheriv, pbkdf2Sync } from 'crypto';
|
|
2
|
+
import { ENC_AES, ENC_NONE, ENC_XOR } from './constants.js';
|
|
3
|
+
import { IncorrectPassphraseError, PassphraseRequiredError } from './errors.js';
|
|
4
|
+
let nativeDeltaEncode = null;
|
|
5
|
+
let nativeDeltaDecode = null;
|
|
6
|
+
let hasNative = false;
|
|
7
|
+
try {
|
|
8
|
+
const native = require('../../libroxify_native.node');
|
|
9
|
+
if (native?.nativeDeltaEncode && native?.nativeDeltaDecode) {
|
|
10
|
+
nativeDeltaEncode = native.nativeDeltaEncode;
|
|
11
|
+
nativeDeltaDecode = native.nativeDeltaDecode;
|
|
12
|
+
hasNative = true;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
// Native module not available, will use TS fallback
|
|
17
|
+
}
|
|
18
|
+
export function colorsToBytes(colors) {
|
|
19
|
+
const buf = Buffer.alloc(colors.length * 3);
|
|
20
|
+
for (let i = 0; i < colors.length; i++) {
|
|
21
|
+
buf[i * 3] = colors[i].r;
|
|
22
|
+
buf[i * 3 + 1] = colors[i].g;
|
|
23
|
+
buf[i * 3 + 2] = colors[i].b;
|
|
24
|
+
}
|
|
25
|
+
return buf;
|
|
26
|
+
}
|
|
27
|
+
function deltaEncodeTS(data) {
|
|
28
|
+
if (data.length === 0)
|
|
29
|
+
return data;
|
|
30
|
+
const out = Buffer.alloc(data.length);
|
|
31
|
+
out[0] = data[0];
|
|
32
|
+
for (let i = 1; i < data.length; i++) {
|
|
33
|
+
out[i] = (data[i] - data[i - 1] + 256) & 0xff;
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
function deltaDecodeTS(data) {
|
|
38
|
+
if (data.length === 0)
|
|
39
|
+
return data;
|
|
40
|
+
const out = Buffer.alloc(data.length);
|
|
41
|
+
out[0] = data[0];
|
|
42
|
+
for (let i = 1; i < data.length; i++) {
|
|
43
|
+
out[i] = (out[i - 1] + data[i]) & 0xff;
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
export function deltaEncode(data) {
|
|
48
|
+
if (hasNative && nativeDeltaEncode) {
|
|
49
|
+
try {
|
|
50
|
+
return Buffer.from(nativeDeltaEncode(data));
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
console.warn('Native deltaEncode failed, falling back to TS:', e);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return deltaEncodeTS(data);
|
|
57
|
+
}
|
|
58
|
+
export function deltaDecode(data) {
|
|
59
|
+
if (hasNative && nativeDeltaDecode) {
|
|
60
|
+
try {
|
|
61
|
+
return Buffer.from(nativeDeltaDecode(data));
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
console.warn('Native deltaDecode failed, falling back to TS:', e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return deltaDecodeTS(data);
|
|
68
|
+
}
|
|
69
|
+
export function applyXor(buf, passphrase) {
|
|
70
|
+
const key = Buffer.from(passphrase, 'utf8');
|
|
71
|
+
const out = Buffer.alloc(buf.length);
|
|
72
|
+
for (let i = 0; i < buf.length; i++) {
|
|
73
|
+
out[i] = buf[i] ^ key[i % key.length];
|
|
74
|
+
}
|
|
75
|
+
return out;
|
|
76
|
+
}
|
|
77
|
+
export function tryDecryptIfNeeded(buf, passphrase) {
|
|
78
|
+
if (!buf || buf.length === 0)
|
|
79
|
+
return buf;
|
|
80
|
+
const flag = buf[0];
|
|
81
|
+
if (flag === ENC_AES) {
|
|
82
|
+
const MIN_AES_LEN = 1 + 16 + 12 + 16 + 1;
|
|
83
|
+
if (buf.length < MIN_AES_LEN)
|
|
84
|
+
throw new IncorrectPassphraseError();
|
|
85
|
+
if (!passphrase)
|
|
86
|
+
throw new PassphraseRequiredError();
|
|
87
|
+
const salt = buf.slice(1, 17);
|
|
88
|
+
const iv = buf.slice(17, 29);
|
|
89
|
+
const tag = buf.slice(29, 45);
|
|
90
|
+
const enc = buf.slice(45);
|
|
91
|
+
const PBKDF2_ITERS = 1000000;
|
|
92
|
+
const key = pbkdf2Sync(passphrase, salt, PBKDF2_ITERS, 32, 'sha256');
|
|
93
|
+
const dec = createDecipheriv('aes-256-gcm', key, iv);
|
|
94
|
+
dec.setAuthTag(tag);
|
|
95
|
+
try {
|
|
96
|
+
const decrypted = Buffer.concat([dec.update(enc), dec.final()]);
|
|
97
|
+
return decrypted;
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
throw new IncorrectPassphraseError();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (flag === ENC_XOR) {
|
|
104
|
+
if (!passphrase)
|
|
105
|
+
throw new PassphraseRequiredError();
|
|
106
|
+
return applyXor(buf.slice(1), passphrase);
|
|
107
|
+
}
|
|
108
|
+
if (flag === ENC_NONE) {
|
|
109
|
+
return buf.slice(1);
|
|
110
|
+
}
|
|
111
|
+
return buf;
|
|
112
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/**
|
|
4
|
-
* List files in a Rox PNG archive without decoding the full payload.
|
|
5
|
-
* Returns the file list if available, otherwise null.
|
|
6
|
-
* @param pngBuf - PNG data
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export declare function listFilesInPng(pngBuf: Buffer, opts?: {
|
|
10
|
-
includeSizes?: boolean;
|
|
11
|
-
}): Promise<string[] | {
|
|
12
|
-
name: string;
|
|
13
|
-
size: number;
|
|
14
|
-
}[] | null>;
|
|
15
|
-
/**
|
|
16
|
-
* Detect if a PNG/ROX buffer contains an encrypted payload (requires passphrase)
|
|
17
|
-
* Returns true if encryption flag indicates AES or XOR.
|
|
18
|
-
*/
|
|
19
|
-
export declare function hasPassphraseInPng(pngBuf: Buffer): Promise<boolean>;
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
/**
|
|
4
|
+
* List files in a Rox PNG archive without decoding the full payload.
|
|
5
|
+
* Returns the file list if available, otherwise null.
|
|
6
|
+
* @param pngBuf - PNG data
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare function listFilesInPng(pngBuf: Buffer, opts?: {
|
|
10
|
+
includeSizes?: boolean;
|
|
11
|
+
}): Promise<string[] | {
|
|
12
|
+
name: string;
|
|
13
|
+
size: number;
|
|
14
|
+
}[] | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Detect if a PNG/ROX buffer contains an encrypted payload (requires passphrase)
|
|
17
|
+
* Returns true if encryption flag indicates AES or XOR.
|
|
18
|
+
*/
|
|
19
|
+
export declare function hasPassphraseInPng(pngBuf: Buffer): Promise<boolean>;
|