@sie-js/apoxi-tool 1.0.6 → 1.0.9
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/dist/src/cli/misc.js +2 -2
- package/dist/src/cli/unlock.js +2 -2
- package/dist/src/cli.js +5 -6
- package/dist/src/data/unlocker.elf.js +89 -89
- package/dist/src/lib/dwd.js +48 -37
- package/dist/src/utils/serial.js +2 -2
- package/dist/src/utils/string.js +1 -1
- package/dist/src/utils/version.d.ts +1 -0
- package/dist/src/utils/version.js +20 -0
- package/package.json +1 -2
package/dist/src/cli/misc.js
CHANGED
@@ -21,7 +21,7 @@ export const cliBruteforceDWDKeys = async (options) => {
|
|
21
21
|
const pb = new cliProgress.SingleBar({
|
22
22
|
format: ' [{bar}] {percentage}% | ETA: {eta}s | {speed} keys/s'
|
23
23
|
}, cliProgress.Presets.legacy);
|
24
|
-
console.log("
|
24
|
+
console.log("Brute-force key2...");
|
25
25
|
pb.start(0xFFFF, 0);
|
26
26
|
const possibleKeys = await dwd.bruteforceKey2({
|
27
27
|
onProgress: (e) => {
|
@@ -35,7 +35,7 @@ export const cliBruteforceDWDKeys = async (options) => {
|
|
35
35
|
console.log();
|
36
36
|
const foundKeys = [];
|
37
37
|
for (const key2 of possibleKeys) {
|
38
|
-
console.log(sprintf("
|
38
|
+
console.log(sprintf("Brute-force key1 for key2=%04X", key2));
|
39
39
|
const keys = await dwd.bruteforceKey1(key2);
|
40
40
|
if (keys != null)
|
41
41
|
foundKeys.push(keys);
|
package/dist/src/cli/unlock.js
CHANGED
@@ -7,7 +7,7 @@ export const cliUnlockBoot = async (options) => {
|
|
7
7
|
const dwd = await connectDWD(options.port, +options.baudrate, options.key);
|
8
8
|
onCleanup(() => disconnectDWD(dwd));
|
9
9
|
if (await isApoxiBootUnlocked(dwd)) {
|
10
|
-
console.log("Boot already open
|
10
|
+
console.log("Boot is already open. Unlock is not needed.");
|
11
11
|
return;
|
12
12
|
}
|
13
13
|
const { confirm } = await inquirer.prompt([
|
@@ -15,7 +15,7 @@ export const cliUnlockBoot = async (options) => {
|
|
15
15
|
type: 'confirm',
|
16
16
|
name: 'confirm',
|
17
17
|
message: chalk.red([
|
18
|
-
`WARNING: Unlocking the APOXI bootloader
|
18
|
+
`WARNING: Unlocking the APOXI bootloader MAY BREAK THE DEVICE and it may never work again.`,
|
19
19
|
'MAKE A FULL BACKUP BEFORE THE OPERATION.',
|
20
20
|
'Continue?'
|
21
21
|
].join('\n')),
|
package/dist/src/cli.js
CHANGED
@@ -6,12 +6,11 @@ import debug from "debug";
|
|
6
6
|
import { getDefaultPort } from "#src/utils/serial.js";
|
7
7
|
import { cliBruteforceDWDKeys, cliListSerialPorts } from "#src/cli/misc.js";
|
8
8
|
import { cliUnlockBoot } from "#src/cli/unlock.js";
|
9
|
-
import {
|
10
|
-
const pkg = await readPackage();
|
9
|
+
import { getVersion } from "#src/utils/version.js";
|
11
10
|
const DEFAULT_PORT = await getDefaultPort();
|
12
11
|
program
|
13
12
|
.name("apoxi-tool")
|
14
|
-
.version(
|
13
|
+
.version(getVersion(), '-v, --version')
|
15
14
|
.description('CLI tool for APOXI phones.')
|
16
15
|
.option('-p, --port <port>', 'serial port name', DEFAULT_PORT)
|
17
16
|
.option('-b, --baudrate <baudrate>', 'limit maximum baudrate (0 - use maximum)', '0')
|
@@ -31,7 +30,7 @@ program
|
|
31
30
|
});
|
32
31
|
program
|
33
32
|
.command('unlock-bootloader')
|
34
|
-
.description('Unlock APOXI bootloader (
|
33
|
+
.description('Unlock APOXI bootloader (allows using V-Klay)')
|
35
34
|
.action(createAppCommand(cliUnlockBoot));
|
36
35
|
program
|
37
36
|
.command('read-memory')
|
@@ -43,7 +42,7 @@ program
|
|
43
42
|
.action(createAppCommand(cliReadMemory));
|
44
43
|
program
|
45
44
|
.command('read-all-memory')
|
46
|
-
.description('Read and save phone memory
|
45
|
+
.description('Read and save all available phone memory blocks')
|
47
46
|
.option('-i, --include <blocks>', 'Include blocks (comma separated)', (v) => v.split(','), [])
|
48
47
|
.option('-e, --exclude <blocks>', 'Exclude blocks (comma separated)', (v) => v.split(','), [])
|
49
48
|
.option('-o, --output [dir]', 'Write output to directory')
|
@@ -56,7 +55,7 @@ program.command('list-ports')
|
|
56
55
|
.description('List available serial ports.')
|
57
56
|
.action(createAppCommand(cliListSerialPorts));
|
58
57
|
program.command('bruteforce-dwd-keys')
|
59
|
-
.description('
|
58
|
+
.description('Brute-force DWD keys')
|
60
59
|
.action(createAppCommand(cliBruteforceDWDKeys));
|
61
60
|
program.showSuggestionAfterError(true);
|
62
61
|
program.showHelpAfterError();
|
@@ -1,93 +1,93 @@
|
|
1
1
|
// DO NOT EDIT! AUTO-GENERATED BY tools/importApoxiUnlockerElf.ts
|
2
|
-
export default Buffer.from("
|
2
|
+
export default Buffer.from("7f454c4601010100000000000000000003002800010000008808000034000000fc13000000020005340020000700280013001200060000003400000034000000" +
|
3
3
|
"34000000e0000000e000000004000000040000000300000014010000140100001401000011000000110000000400000001000000010000000000000000000000" +
|
4
4
|
"00000000250100002501000004000000010000000100000028010000280100002801000049000000490000000400000004000000010000007401000074010000" +
|
5
|
-
"
|
6
|
-
"
|
7
|
-
"
|
8
|
-
"
|
9
|
-
"
|
10
|
-
"
|
5
|
+
"740100009408000094080000050000000400000001000000080a0000080a0000080a00009400000038010200060000000400000002000000080a0000080a0000" +
|
6
|
+
"080a0000880000008800000006000000040000002f7573722f6c69622f6c642e736f2e3100000000010000000300000000000000000000000000000000000000" +
|
7
|
+
"0000000000000000000000000000000000000000140200000000000003000600000000009c0a00000000000003000a00000000004c0600001700000050060000" +
|
8
|
+
"1700000054060000170000005806000017000000640600001700000068060000170000006c06000017000000740600001700000088060000170000008c060000" +
|
9
|
+
"1700000090060000170000009406000017000000f806000017000000fc060000170000007c070000170000008007000017000000000800001700000004080000" +
|
10
|
+
"170000000808000017000000840800001700000004e04ee2ff5f2de928649fe518d04de2a00100eb042096e50f3ae0e3c72f03e50000e0e30c30e0e30f22a0e3" +
|
11
11
|
"083086e50c0086e5c03092e5000053e3020000aa803092e5010013e30300001a0230e0e3083086e518d08de2ff9ffde8101f12ee103f13ee14308de514c09de5" +
|
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
|
-
"
|
62
|
-
"
|
63
|
-
"
|
64
|
-
"
|
65
|
-
"
|
66
|
-
"
|
67
|
-
"
|
68
|
-
"
|
69
|
-
"
|
70
|
-
"
|
71
|
-
"
|
72
|
-
"
|
73
|
-
"
|
74
|
-
"
|
75
|
-
"
|
76
|
-
"
|
77
|
-
"
|
78
|
-
"
|
79
|
-
"
|
80
|
-
"
|
81
|
-
"
|
82
|
-
"
|
83
|
-
"
|
84
|
-
"
|
85
|
-
"
|
86
|
-
"
|
87
|
-
"
|
88
|
-
"
|
89
|
-
"
|
90
|
-
"
|
91
|
-
"
|
92
|
-
"
|
93
|
-
"
|
12
|
+
"c8339fe5021a81e200c083e500c891e5bc339fe5bc539fe500c083e5380100ebb4339fe5b4439fe5003881e5b0339fe5c01092e5ac939fe5001083e5c03092e5" +
|
13
|
+
"a4a39fe50231c3e3c03082e59c339fe59c739fe5003085e598339fe5004089e500408ae5003087e5470100eb000050e31200000a0120a0e30010a0e39000a0e3" +
|
14
|
+
"e40000eb0120a0e30210a0e10080a0e100008ae59000a0e3de0000eb890058e3200058130110a0130010a0030040a0e1000089e54100000a0a50e0e3080000ea" +
|
15
|
+
"34339fe5003085e530339fe5003087e52d0100eb000050e30480a0010b50e003e3ffff1a084884e1000055e30c4086e5085086152f00001a0a42a0e300339fe5" +
|
16
|
+
"0c2094e5030052e10030e0132800001ada0000eb008050e2a900000a0c1098e50400a0e18e0100eb007051e27800001a003098e5cc929fe5f020a0e3b020c3e1" +
|
17
|
+
"ff20a0e3b020c3e10930a0e10c2098e5020055e16900003a0a42a0e36030a0e3b030c4e12020a0e3d030a0e3b030c4e1b020c4e1b030c4e1b030d4e1800013e3" +
|
18
|
+
"fcffff0a0130a0e36050a0e3b050c4e1b030c4e1003098e5f020a0e3b020c3e1ff20a0e3b020c3e1043098e5000053e3590000aa083086e5e40000eb89ffffea" +
|
19
|
+
"002095e598e0a0e30a52a0e30a2282e2b0e0c2e1be74d5e12c329fe50190a0e3ff00a0e3f0c0a0e31977a0e1001083e5b0c0c5e1b000c5e1b0e0c2e1b825d5e1" +
|
20
|
+
"08708de5b0c0c5e1b000c5e1fc019fe5080052e30950e083002080e5b0ffff8aecb19fe50221a0e12d2082e22da0a0e30c208de504108de50c209de502005ae1" +
|
21
|
+
"0900001a0c009de9020053e10850e013a3ffff1ab0319fe5003093e5020853e30750e0830050a0939dffffea0a10a0e10020a0e39800a0e3660000eb01108ae2" +
|
22
|
+
"0020a0e30090a0e19800a0e3610000eb02108ae20020a0e3009489e19800a0e35c0000eb0020a0e303108ae2019089e204a08ae20070a0e19800a0e3550000eb" +
|
23
|
+
"04309de500508be5007487e10774a0e1970902e00c708be5023083e004308de524319fe504028be9025085e0002093e510b08be2020057e100708385cdffffea" +
|
24
|
+
"0a2285e20020d2e5015085e20120c3e48dffffea0530e0e3a5ffffea0030e0e30c30c9e50d30c9e50e30c9e50f30c9e5520000eb000050e32100000a0c2090e5" +
|
25
|
+
"d030a0e30120c2e34010a0e370c0a0e3b050c4e1b030c4e1070052e10e00001a0a32a0e36020a0e3b020c3e10120a0e3b020c3e1003090e5f020a0e3b020c3e1" +
|
26
|
+
"ff20a0e3b020c3e10030a0e3083086e56e0000eba40000eb12ffffea0a3287e2b010c3e1b9e097e1b0e0c3e1b0c0c3e1b0e0d3e180001ee3fcffff0a027087e2" +
|
27
|
+
"e4ffffea0630e0e379ffffea880800002c0b0200280b0200340b0200120c00a0ffff0000240b0200380b02003c0b0200aa0a0000300b020054050000aaaa0000" +
|
28
|
+
"545500000200ffff9c0a0000200b02001c0b02009c0a020058309fe5000052e3003093e50a3283e20600000aaa20a0e3b020c3e140209fe555c0a0e3002092e5" +
|
29
|
+
"0a2282e2b0c0c2e10008a0e12008a0e18110a0e1b000c3e10a1281e20a32a0e3f020a0e3b000d1e1b020c3e1ff20a0e3b020c3e11eff2fe1340b0200300b0200" +
|
30
|
+
"74209fe574309fe500c092e50300a0e10020a0e30c0052e11000001a0000a0e31eff2fe1001093e5160271e30500009a04e093e50e1081e00a0251e30100009a" +
|
31
|
+
"020280e004f09de4012082e20c0052e1103083e2f2ffff1a0000a0e304f09de4001093e5160271e30120829210308392e7ffff9a04e02de5ecffffea1c0b0200" +
|
32
|
+
"9c0a020010d04de204008de5103f13ee0c308de504309de5103f03ee0000a0e10000a0e10000a0e10000a0e10000a0e10000a0e10000a0e10000a0e10000a0e1" +
|
33
|
+
"0000a0e10c309de510d08de21eff2fe1103f12ee24209fe5023a83e2002092e5002883e518309fe5002093e50f32a0e3c02083e50c309fe5000093e5e0ffffea" +
|
34
|
+
"280b0200240b02002c0b020070209fe50a32a0e3002092e510402de9f0c0a0e3ff10a0e3032082e098e0a0e3b0c0c3e1b010c3e1b0e0c2e1b002d3e1b0c0c3e1" +
|
35
|
+
"b010c3e1b0e0c2e1b242d3e1b0c0c3e1b010c3e1b0e0c2e1b422d3e1510050e3520054030100a0030000a013b0c0c3e1590052e30000a01301000002b010c3e1" +
|
36
|
+
"1080bde8340b020061feffea00000000000000000000000000000000000000000000000000000000000000007aff17ee0000a0e10000a0e10000a0e1faffff1a" +
|
37
|
+
"0000a0e39a0f07ee0000a0e10000a0e10000a0e10000a0e10000a0e10000a0e1150f07ee0000a0e10000a0e11eff2fe1012051e21eff2f013600003a010050e1" +
|
38
|
+
"2200009a020011e12300000a0e0211e38111a0010830a0030130a013010251e3000051310112a0310332a031faffff3a020151e3000051318110a0318330a031" +
|
39
|
+
"faffff3a0020a0e3010050e10100402003208221a10050e1a1004020a3208221210150e12101402023218221a10150e1a1014020a3218221000050e32332b011" +
|
40
|
+
"2112a011efffff1a0200a0e11eff2fe10100a0030000a0131eff2fe1010851e32118a0211020a0230020a033010c51e32114a02108208222100051e32112a021" +
|
41
|
+
"04208222040051e303208282a12082903002a0e11eff2fe1000050e30000e013070000ea000051e3faffff0a03402de9beffffeb0640bde8920003e0031041e0" +
|
42
|
+
"1eff2fe11eff2fe10400000028010000050000007001000006000000400100000a000000010000000b0000001000000015000000000000001100000074010000" +
|
43
|
+
"12000000a000000013000000080000001600000000000000fbffff6f00000008faffff6f14000000000000000000000000000000000000000000000000000000" +
|
44
|
+
"00000000000000000000000000000000080a000000000000000000004743433a202841726d20474e5520546f6f6c636861696e2031342e322e52656c31202842" +
|
45
|
+
"75696c642061726d2d31342e353229292031342e322e31203230323431313139000000000c000000ffffffff0100017c0e0c0d000c00000000000000f0080000" +
|
46
|
+
"f40000002f646174612f6a656e6b696e732f776f726b73706163652f474e552d746f6f6c636861696e2f61726d2d31342f6275696c642d61726d2d6e6f6e652d" +
|
47
|
+
"656162692f6f626a2f676363322f61726d2d6e6f6e652d656162692f6c6962676363002f646174612f6a656e6b696e732f776f726b73706163652f474e552d74" +
|
48
|
+
"6f6f6c636861696e2f61726d2d31342f7372632f6763632f6c69626763632f636f6e6669672f61726d006c69623166756e63732e530041290000006165616269" +
|
49
|
+
"00011f000000053554454a00060508010901120414011501170318011a011e040000000000000000000000000000000000000000140100000000000003000100" +
|
50
|
+
"00000000280100000000000003000200000000004001000000000000030003000000000070010000000000000300040000000000740100000000000003000500" +
|
51
|
+
"0000000014020000000000000300060000000000080a0000000000000300070000000000900a00000000000003000800000000009c0a00000000000003000900" +
|
52
|
+
"000000009c0a00000000000003000a0000000000400b02000000000003000b0000000000000000000000000003000c0000000000000000000000000003000d00" +
|
53
|
+
"00000000000000000000000003000e0000000000000000000000000003000f000100000000000000000000000400f1ff08000000980600000000000000000600" +
|
54
|
+
"0b00000098060000680000000200060020000000f8060000000000000000060023000000340b02000400000001000a0036000000300b02000400000001000a00" +
|
55
|
+
"0800000000070000000000000000060049000000000700008400000002000600200000007c0700000000000000000600670000001c0b02000400000001000a00" +
|
56
|
+
"790000009c0a02008000000001000a000800000084070000000000000000060087000000840700004c0000000200060008000000d00700000000000000000600" +
|
57
|
+
"a0000000d00700003c0000000200060020000000000800000000000000000600b2000000280b02000400000001000a00c0000000240b02000400000001000a00" +
|
58
|
+
"cb0000002c0b02000400000001000a00080000000c0800000000000000000600dd0000000c0800007c0000000200060020000000840800000000000000000600" +
|
59
|
+
"08000000140200000000000000000600200000004c0600000000000000000600f3000000380b02000400000001000a00fd0000003c0b02000400000001000a00" +
|
60
|
+
"070100009c0a00000000020001000a0014010000200b02000400000001000a00200000009c0a00000000000000000a00200000009c0a02000000000000000a00" +
|
61
|
+
"200000001c0b02000000000000000a0020000000200b02000000000000000a0020000000240b02000000000000000a0020000000280b02000000000000000a00" +
|
62
|
+
"200000002c0b02000000000000000a0020000000300b02000000000000000a0020000000340b02000000000000000a0020000000380b02000000000000000a00" +
|
63
|
+
"200000003c0b02000000000000000a002301000000000000000000000400f1ff08000000880800000000000000000600200000008c0800000000000000000600" +
|
64
|
+
"08000000ac08000000000000000006002e01000000000000000000000400f1ff08000000f0080000000000000000060039010000f00800000000000000000600" +
|
65
|
+
"20000000100000000000000000000d005101000000000000000000000400f1ff08000000040a000000000000000006000000000000000000000000000400f1ff" +
|
66
|
+
"5d010000080a0000000000000100f1ff66010000e4090000200000000200060077010000900a0000000000000100f1ff8d010000040a00000400000002000600" +
|
67
|
+
"b4010000400b02000000000010000a009b010000f0080000f400000012020600a50100009c0a00000000000010000a00b3010000400b02000000000010000a00" +
|
68
|
+
"1e020000880800000000000012000600bf010000040a00000400000022020600cd0100009c0a00000000000010000a00d9010000140200008404000012000600" +
|
69
|
+
"de010000f00800000000000012020600ec010000400b02000000000010000a00f4010000ac0800000000000012000600050200009c0a00000000000010000800" +
|
70
|
+
"0c020000400b02000000000010000a0011020000000008000000000010000b00180200009c0a00000000000010000800006d61696e2e6300246100726561645f" +
|
71
|
+
"7265672e636f6e737470726f702e3000246400666c6173685f756e6c6f636b5f616464723100666c6173685f756e6c6f636b5f61646472320066696e645f666c" +
|
72
|
+
"6173685f726567696f6e2e636f6e737470726f702e300065726173655f726567696f6e735f636e740065726173655f726567696f6e73007365745f646f6d6169" +
|
73
|
+
"6e5f6163636573732e697372612e30006c6f636b5f666c6173685f616363657373006f6c645f666c6173685f6d6d75006f6c645f627573636f6e006f6c645f64" +
|
74
|
+
"6f6d61696e5f61636365737300636865636b5f7172792e636f6e737470726f702e3000666c6173685f70696400666c6173685f7669640077726974655f627566" +
|
75
|
+
"666572006d61785f65726173655f73697a6500696e69742e532e6f626a005f756469767369332e6f002e756469767369335f736b69705f646976305f74657374" +
|
76
|
+
"005f64766d645f746c732e6f005f44594e414d4943005f5f61656162695f75696469766d6f64005f474c4f42414c5f4f46465345545f5441424c455f005f5f61" +
|
77
|
+
"656162695f6964697630005f5f75646976736933005f5f6273735f73746172745f5f005f5f6273735f656e645f5f005f5f61656162695f6c64697630005f5f62" +
|
78
|
+
"73735f7374617274006d61696e005f5f61656162695f7569646976005f5f656e645f5f00636c65616e5f616c6c5f636163686573005f6564617461005f656e64" +
|
79
|
+
"005f737461636b005f5f646174615f737461727400002e73796d746162002e737472746162002e7368737472746162002e696e74657270002e68617368002e64" +
|
80
|
+
"796e73796d002e64796e737472002e72656c2e64796e002e74657874002e64796e616d6963002e676f74002e70657273697374656e74002e627373002e6e6f69" +
|
81
|
+
"6e6974002e636f6d6d656e74002e64656275675f6672616d65002e64656275675f6c696e655f737472002e41524d2e6174747269627574657300000000000000" +
|
82
|
+
"0000000000000000000000000000000000000000000000000000000000000000000000001b000000010000000200000014010000140100001100000000000000" +
|
83
|
+
"00000000010000000000000023000000050000000200000028010000280100001800000003000000000000000400000004000000290000000b00000002000000" +
|
84
|
+
"40010000400100003000000004000000030000000400000010000000310000000300000002000000700100007001000001000000000000000000000001000000" +
|
85
|
+
"000000003900000009000000020000007401000074010000a0000000030000000000000004000000080000004200000001000000060000001402000014020000" +
|
86
|
+
"f407000000000000000000000400000000000000480000000600000003000000080a0000080a0000880000000400000000000000040000000800000051000000" +
|
87
|
+
"0100000003000000900a0000900a00000c000000000000000000000004000000040000005600000001000000030000009c0a00009c0a00000000000000000000" +
|
88
|
+
"0000000004000000000000006200000008000000030000009c0a00009c0a0000a400020000000000000000000400000000000000670000000800000003000000" +
|
89
|
+
"400b02000000000000000000000000000000000004000000000000006f0000000100000030000000000000009c0a000045000000000000000000000001000000" +
|
90
|
+
"0100000078000000010000000000000000000000e40a0000200000000000000000000000040000000000000085000000010000003000000000000000040b0000" +
|
91
|
+
"b20000000000000000000000010000000100000095000000030000700000000000000000b60b00002a0000000000000000000000010000000000000001000000" +
|
92
|
+
"020000000000000000000000e00b0000500500001100000046000000040000001000000009000000030000000000000000000000301100002502000000000000" +
|
93
|
+
"0000000001000000000000001100000003000000000000000000000055130000a500000000000000000000000100000000000000", "hex");
|
package/dist/src/lib/dwd.js
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import { sprintf } from "sprintf-js";
|
2
2
|
import unlockerElf from "#src/data/unlocker.elf.js";
|
3
|
-
import { retryAsyncOnError } from "#src/utils/retry.js";
|
4
3
|
const TCM_START = 0xFFFF0000;
|
5
4
|
const PRAM_IRQ_HANDLER = TCM_START + 0x38;
|
6
5
|
const BOOT_MODE = 0xA000000C;
|
@@ -39,18 +38,18 @@ export async function unlockApoxiBootloader(dwd, options) {
|
|
39
38
|
const ramSize = (1 << (27 - ((addrsel & 0xF0) >> 4)));
|
40
39
|
const ramAddr = Number((BigInt(addrsel) & 0xffff0000n));
|
41
40
|
if (await isApoxiBootUnlocked(dwd)) {
|
42
|
-
options.debug("Boot already open
|
41
|
+
options.debug("Boot is already open. Unlock is not needed.");
|
43
42
|
return;
|
44
43
|
}
|
45
44
|
const { loadELF } = await import("@sie-js/creampie");
|
46
45
|
const bootMode = (await dwd.readMemory(BOOT_MODE, 4)).buffer.readUInt32LE(0);
|
47
46
|
options.debug(sprintf("Boot mode: %08X", bootMode));
|
48
|
-
options.debug(sprintf("
|
49
|
-
options.debug("Searching empty
|
47
|
+
options.debug(sprintf("RAM: %08X, %d MB", ramAddr, ramSize / 1024 / 1024));
|
48
|
+
options.debug("Searching for an empty RAM block... (this may take a while)");
|
50
49
|
let emptyRamBlock = 0;
|
51
50
|
for (let i = ramAddr; i < ramAddr + ramSize; i += 256 * 1024) {
|
52
51
|
if ((i % (1024 * 1024)) == 0)
|
53
|
-
options.debug(sprintf("RAM scan progress: %d
|
52
|
+
options.debug(sprintf("RAM scan progress: %d MB / %d MB", (i - ramAddr) / 1024 / 1024, ramSize / 1024 / 1024));
|
54
53
|
const blockStart = await dwd.readMemory(i, 230);
|
55
54
|
if (blockStart.buffer.every((v) => v == 0)) {
|
56
55
|
const fullBlock = await dwd.readMemory(i, 256 * 1024);
|
@@ -62,46 +61,58 @@ export async function unlockApoxiBootloader(dwd, options) {
|
|
62
61
|
}
|
63
62
|
if (!emptyRamBlock)
|
64
63
|
throw new Error("Empty RAM block not found!");
|
65
|
-
options.debug(sprintf("Found empty
|
66
|
-
const oldIrqHandler = (await dwd.readMemory(PRAM_IRQ_HANDLER, 4)).buffer.readUInt32LE(0);
|
67
|
-
options.debug(sprintf("Old SWI handler: %08X", oldIrqHandler));
|
64
|
+
options.debug(sprintf("Found empty RAM block: %08X", emptyRamBlock));
|
68
65
|
const elf = loadELF(emptyRamBlock, unlockerElf);
|
69
|
-
await dwd.writeMemory(emptyRamBlock, elf.image);
|
70
|
-
const check = await dwd.readMemory(emptyRamBlock, elf.image.length);
|
71
|
-
if (check.buffer.toString("hex") != elf.image.toString("hex")) {
|
72
|
-
options.debug(check.buffer.toString("hex"));
|
73
|
-
options.debug(elf.image.toString("hex"));
|
74
|
-
throw new Error("Payload corrupted!!!");
|
75
|
-
}
|
76
|
-
options.debug(sprintf("Patcher entry: %08X", elf.entry));
|
77
|
-
const PATCHER_ADDR = elf.entry;
|
78
|
-
const PARAM_OLD_IRQ_HANDLER = PATCHER_ADDR + 4;
|
79
|
-
const PARAM_RESPONSE_CODE = PATCHER_ADDR + 8;
|
80
|
-
const PARAM_RESPONSE_FLASH_ID = PATCHER_ADDR + 12;
|
81
66
|
for (let i = 0; i < 30; i++) {
|
82
|
-
|
67
|
+
await dwd.writeMemory(emptyRamBlock, elf.image);
|
68
|
+
const check = await dwd.readMemory(emptyRamBlock, elf.image.length);
|
69
|
+
if (check.buffer.toString("hex") != elf.image.toString("hex")) {
|
70
|
+
options.debug(check.buffer.toString("hex"));
|
71
|
+
options.debug(elf.image.toString("hex"));
|
72
|
+
throw new Error("Payload is corrupted.");
|
73
|
+
}
|
74
|
+
options.debug(sprintf("Patcher entry: %08X", elf.entry));
|
75
|
+
const PATCHER_ADDR = elf.entry;
|
76
|
+
const PARAM_OLD_IRQ_HANDLER = PATCHER_ADDR + 4;
|
77
|
+
const PARAM_RESPONSE_CODE = PATCHER_ADDR + 8;
|
78
|
+
const PARAM_RESPONSE_FLASH_ID = PATCHER_ADDR + 12;
|
79
|
+
const oldIrqHandler = (await dwd.readMemory(PRAM_IRQ_HANDLER, 4)).buffer.readUInt32LE(0);
|
80
|
+
options.debug(sprintf("Old SWI handler: %08X", oldIrqHandler));
|
83
81
|
await dwd.writeMemory(PARAM_OLD_IRQ_HANDLER, uint32(oldIrqHandler));
|
84
|
-
|
85
|
-
let responseCode = PatchResponseCode.UNKNOWN;
|
86
|
-
let responseFlashId = 0;
|
82
|
+
options.debug("Running patcher...");
|
87
83
|
try {
|
88
|
-
await
|
89
|
-
options.debug("Waiting for done...");
|
90
|
-
responseCode = (await dwd.readMemory(PARAM_RESPONSE_CODE, 4)).buffer.readInt32LE(0);
|
91
|
-
responseFlashId = (await dwd.readMemory(PARAM_RESPONSE_FLASH_ID, 4)).buffer.readUInt32LE(0);
|
92
|
-
options.debug(sprintf("Code: %d (%s)", responseCode, PatchResponseCode[responseCode]));
|
93
|
-
options.debug(sprintf("FlashID: %08X", responseFlashId));
|
94
|
-
if (responseCode == PatchResponseCode.SUCCESS) {
|
95
|
-
options.debug("Success!!! Boot mode patched, now reboot phone.");
|
96
|
-
}
|
97
|
-
}, { max: 10, delay: 1000 });
|
84
|
+
await dwd.writeMemory(PRAM_IRQ_HANDLER, uint32(PATCHER_ADDR));
|
98
85
|
}
|
99
86
|
catch (e) {
|
100
|
-
|
101
|
-
|
87
|
+
// fail is ok
|
88
|
+
}
|
89
|
+
options.debug("Waiting 5 seconds to complete...");
|
90
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
91
|
+
// Flush
|
92
|
+
await dwd.getSerialPort()?.read(1024, 100);
|
93
|
+
try {
|
94
|
+
const responseCode = (await dwd.readMemory(PARAM_RESPONSE_CODE, 4)).buffer.readInt32LE(0);
|
95
|
+
const responseFlashId = (await dwd.readMemory(PARAM_RESPONSE_FLASH_ID, 4)).buffer.readUInt32LE(0);
|
96
|
+
options.debug(sprintf("Code: %d (%s)", responseCode, PatchResponseCode[responseCode]));
|
97
|
+
options.debug(sprintf("Flash ID: %08X", responseFlashId));
|
98
|
+
if (responseCode == PatchResponseCode.SUCCESS) {
|
99
|
+
options.debug("Success. Boot mode patched. Please reboot the phone.");
|
100
|
+
}
|
101
|
+
else if (responseCode == PatchResponseCode.BOOT_ALREADY_OPEN) {
|
102
|
+
options.debug("Boot is already open. Unlock is not needed.");
|
103
|
+
}
|
104
|
+
else {
|
105
|
+
options.debug("Unlocking failed!");
|
106
|
+
}
|
107
|
+
if (!(responseCode == PatchResponseCode.FLASH_NOT_FOUND || responseCode == PatchResponseCode.FLASH_BUSY))
|
108
|
+
break;
|
109
|
+
options.debug("Retrying...");
|
102
110
|
}
|
103
|
-
|
111
|
+
catch (e) {
|
112
|
+
options.debug(String(e));
|
113
|
+
options.debug("An error occurred while waiting for a response from the unlocker. Please remove and reinstall the battery, then try again.");
|
104
114
|
break;
|
115
|
+
}
|
105
116
|
}
|
106
117
|
}
|
107
118
|
function uint32(value) {
|
package/dist/src/utils/serial.js
CHANGED
@@ -9,7 +9,7 @@ const USB_DEVICES = [
|
|
9
9
|
"04DA:*", // Panasonic/Softbank
|
10
10
|
];
|
11
11
|
export async function connectDWD(path, limitBaudrate, key) {
|
12
|
-
console.info(`Connecting to phone using port ${path}...`);
|
12
|
+
console.info(`Connecting to the phone using port ${path}...`);
|
13
13
|
const port = new AsyncSerialPort(new SerialPort({
|
14
14
|
path,
|
15
15
|
baudRate: 112500,
|
@@ -34,7 +34,7 @@ export async function connectDWD(path, limitBaudrate, key) {
|
|
34
34
|
await dwd.connect();
|
35
35
|
}
|
36
36
|
catch (e) {
|
37
|
-
console.error(`Error while connecting to phone!`);
|
37
|
+
console.error(`Error while connecting to the phone!`);
|
38
38
|
await port.close();
|
39
39
|
throw e;
|
40
40
|
}
|
package/dist/src/utils/string.js
CHANGED
@@ -28,7 +28,7 @@ export function parseSize(value) {
|
|
28
28
|
}
|
29
29
|
export function formatSize(size) {
|
30
30
|
if (size > 1024 * 1024) {
|
31
|
-
return +(size / 1024 / 1024).toFixed(2) + "
|
31
|
+
return +(size / 1024 / 1024).toFixed(2) + " MB";
|
32
32
|
}
|
33
33
|
else {
|
34
34
|
return +(size / 1024).toFixed(2) + " kB";
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function getVersion(): string;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import fs from "node:fs";
|
2
|
+
import path from "node:path";
|
3
|
+
export function getVersion() {
|
4
|
+
let currentDir = import.meta.dirname;
|
5
|
+
while (true) {
|
6
|
+
const pkgPath = path.join(currentDir, "package.json");
|
7
|
+
if (fs.existsSync(pkgPath)) {
|
8
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath).toString());
|
9
|
+
if (pkg.version) {
|
10
|
+
return pkg.version;
|
11
|
+
}
|
12
|
+
}
|
13
|
+
const parentDir = path.dirname(currentDir);
|
14
|
+
if (parentDir === currentDir) {
|
15
|
+
break;
|
16
|
+
}
|
17
|
+
currentDir = parentDir;
|
18
|
+
}
|
19
|
+
return "1.0.0";
|
20
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sie-js/apoxi-tool",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.9",
|
4
4
|
"description": "CLI tools for APOXI phones.",
|
5
5
|
"bin": {
|
6
6
|
"apoxi-tool": "./dist/src/cli.js"
|
@@ -38,7 +38,6 @@
|
|
38
38
|
"commander": "^14.0.0",
|
39
39
|
"debug": "^4.4.1",
|
40
40
|
"inquirer": "^12.9.1",
|
41
|
-
"read-pkg": "^9.0.1",
|
42
41
|
"serialport": "^13.0.0",
|
43
42
|
"sprintf-js": "^1.1.3",
|
44
43
|
"table": "^6.9.0"
|