Skip to content

Commit

Permalink
build exe
Browse files Browse the repository at this point in the history
  • Loading branch information
Azq2 committed Jun 15, 2024
1 parent 72a64a2 commit 628691c
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 59 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ jobs:
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- run: scripts/build.exe

- uses: softprops/action-gh-release@v1
with:
token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: true
files: siemens-memory-dumper.exe.zip
84 changes: 43 additions & 41 deletions bin/siemens-memory-dumper.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,56 @@ const USB_DEVICES = [
"11F5:1004", // DCA-540
];

const DEFAULT_PORT = await getDefaultPort();
(async () => {
const DEFAULT_PORT = await getDefaultPort();

program
.description('CLI memory dumper for Siemens phones.')
.option('-p, --port <port>', 'serial port name', DEFAULT_PORT)
.option('-b, --baudrate <baudrate>', 'limit maximum baudrate (0 - use maximum)', '0');
program
.description('CLI memory dumper for Siemens phones.')
.option('-p, --port <port>', 'serial port name', DEFAULT_PORT)
.option('-b, --baudrate <baudrate>', 'limit maximum baudrate (0 - use maximum)', '0');

program.command('read')
.description('Read memory region by address and size and save to file.')
.argument('<addr>', 'memory address (0xHEX)')
.argument('<size>', 'memory size (0xHEX or 1M, 128k, 256...)')
.argument('[file|dir]', 'write memory to this file or dir')
.action(async function (addr, size, output) {
await readMemoryToFile({addr, size, output, ...this.optsWithGlobals()});
});
program.command('read')
.description('Read memory region by address and size and save to file.')
.argument('<addr>', 'memory address (0xHEX)')
.argument('<size>', 'memory size (0xHEX or 1M, 128k, 256...)')
.argument('[file|dir]', 'write memory to this file or dir')
.action(async function (addr, size, output) {
await readMemoryToFile({addr, size, output, ...this.optsWithGlobals()});
});

program.command('read-region')
.description('Read memory region by name and save to file.')
.argument('<name>', 'memory region name (SRAM, RAM, ...)')
.argument('[file|dir]', 'write memory to this file or dir')
.action(async function (name, output) {
await readMemoryToFile({name, output, ...this.optsWithGlobals()});
});
program.command('read-region')
.description('Read memory region by name and save to file.')
.argument('<name>', 'memory region name (SRAM, RAM, ...)')
.argument('[file|dir]', 'write memory to this file or dir')
.action(async function (name, output) {
await readMemoryToFile({name, output, ...this.optsWithGlobals()});
});

program.command('read-all')
.description('Read all available memory regions from phone and save to dir.')
.argument('[dir]', 'write memory regions to this dir')
.action(async function (output) {
await readAllMemory({output, ...this.optsWithGlobals()});
});
program.command('read-all')
.description('Read all available memory regions from phone and save to dir.')
.argument('[dir]', 'write memory regions to this dir')
.action(async function (output) {
await readAllMemory({output, ...this.optsWithGlobals()});
});

program.command('list')
.description('List available memory regions for dump.')
.action(async function () {
await listAvailableMemory(this.optsWithGlobals());
});
program.command('list')
.description('List available memory regions for dump.')
.action(async function () {
await listAvailableMemory(this.optsWithGlobals());
});

program.command('list-ports')
.description('List available serial ports.')
.action(async function () {
for (let p of await SerialPort.list()) {
if (p.productId != null)
console.log(p.path, `${p.vendorId}:${p.productId}`, p.manufacturer);
}
});
program.command('list-ports')
.description('List available serial ports.')
.action(async function () {
for (let p of await SerialPort.list()) {
if (p.productId != null)
console.log(p.path, `${p.vendorId}:${p.productId}`, p.manufacturer);
}
});

program.showHelpAfterError();
program.parse();
program.showHelpAfterError();
program.parse();
})();

async function getDefaultPort() {
let availablePorts = (await SerialPort.list()).filter((d) => {
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@sie-js/siemens-memory-dumper",
"version": "1.0.3",
"type": "module",
"main": "./bin/siemens-memory-dumper.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"link-local-deps": "npm link -S ../node-sie-serial/",
Expand Down
10 changes: 10 additions & 0 deletions pkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"pkg": {
"targets": [
"latest-win-x64"
],
"assets": [
"./node_modules/@serialport/bindings-cpp/prebuilds"
]
}
}
8 changes: 8 additions & 0 deletions scripts/build-exe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e
set -x
cd "$(dirname $0)/../"
rm -f *.exe *.exe.zip
npx -y esbuild bin/siemens-memory-dumper.js --bundle --outfile=./siemens-memory-dumper.js --format=cjs --platform=node --loader:.node=file --external:@serialport/bindings-cpp
npx -y pkg -c ./pkg.json ./siemens-memory-dumper.js
zip siemens-memory-dumper.exe.zip siemens-memory-dumper.exe
24 changes: 14 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs';
import "chalk";
import chalk from "chalk";
import { table as asciiTable } from 'table';
import { CGSN, serialWaitForOpen } from "@sie-js/serial";
import cliProgress from "cli-progress";
Expand All @@ -19,15 +19,15 @@ export async function readMemoryToFile(argv) {

let info = await getPhoneInfo(cgsn);
if (!info) {
console.error(`Can't get phone information!`);
showError(`Can't get phone information!`);
await cgsnClose(cgsn, port);
return;
}

if (argv.name) {
let region = getMemoryRegionByName(info.memoryRegions, argv.name);
if (!region) {
console.error(`Memory region ${argv.name} not found.`);
showError(`Memory region ${argv.name} not found.`);
await cgsnClose(cgsn, port);
return;
}
Expand Down Expand Up @@ -84,8 +84,8 @@ export async function readAllMemory(argv) {
try {
fs.mkdirSync(argv.output, true);
} catch (e) {
console.error(e.message);
console.error(`Output dir not found: ${argv.output}`);
showError(e.message);
showError(`Output dir not found: ${argv.output}`);
return;
}
}
Expand All @@ -96,7 +96,7 @@ export async function readAllMemory(argv) {

let info = await getPhoneInfo(cgsn);
if (!info) {
console.error(`Can't get phone information!`);
showError(`Can't get phone information!`);
await cgsnClose(cgsn, port);
return;
}
Expand Down Expand Up @@ -135,7 +135,7 @@ export async function readAllMemory(argv) {
i++;

if (!result.success) {
console.error(`Error: ${result.error}`);
showError(`Error: ${result.error}`);
break;
}

Expand All @@ -158,7 +158,7 @@ export async function listAvailableMemory(argv) {

let info = await getPhoneInfo(cgsn);
if (!info) {
console.error(`Can't get phone information!`);
showError(`Can't get phone information!`);
await cgsnClose(cgsn, port);
return;
}
Expand Down Expand Up @@ -293,7 +293,7 @@ async function getPhoneInfo(cgsn) {
descr: 'External RAM.',
});
} else {
console.error(`Detected unknown phone! Memory regions maybe incorret.`);
showError(`Detected unknown phone! Memory regions maybe incorret.`);
memoryRegions.push({
name: "RAM",
addr: 0xA8000000,
Expand All @@ -316,7 +316,7 @@ async function cgsnConnect(portName, limitBaudrate) {
console.info(`Connected using ${port.baudRate} baudrate.`);
return [cgsn, port];
} else {
console.error('Phone not found or CGSN patch is not installed.');
showError('Phone not found or CGSN patch is not installed.');
await cgsnClose(cgsn, port);
return [null, null];
}
Expand Down Expand Up @@ -359,3 +359,7 @@ function formatSize(size) {
return +(size / 1024).toFixed(2) + " kB";
}
}

function showError(message) {
console.error(chalk.red(message))
}

0 comments on commit 628691c

Please sign in to comment.