Skip to content

Commit cbccd56

Browse files
author
Your Name
committed
Changes to add commit hash to version info
1 parent ba12d43 commit cbccd56

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
frida-cshell.js
33
frida-cshell
4+
src/version.ts

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "frida-cshell",
3-
"version": "1.7.7",
3+
"version": "1.7.8",
44
"description": "Frida's CShell",
55
"scripts": {
6-
"prepare": "npm run build && npm run version && npm run package && npm run copy",
6+
"prepare": "npm run version && npm run build && npm run package && npm run copy",
77
"build": "frida-compile src/entrypoint.ts -o frida-cshell.js -c",
88
"lint": "eslint src",
99
"pretty": "npx prettier --write src",
10-
"version": "replace --silent '@VER@' $npm_package_version frida-cshell.js",
10+
"version": "node version.js",
1111
"package": "./package",
1212
"copy": "cp .cshellrc ~/.cshellrc"
1313
},

src/io/output.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import { CharCode } from './char.js';
22
import { Vars } from '../vars/vars.js';
33
import { DEFAULT_SRC_PATH } from '../entrypoint.js';
44
import { Format } from '../misc/format.js';
5+
import { APP_VERSION, GIT_COMMIT_HASH } from '../version.js';
56

67
export class Output {
7-
private static readonly VERSION = '@VER@';
8-
98
private static readonly shell: string[] = [
109
' _.---._ ',
1110
' .\'"".\'/|\\\'.""\'.',
@@ -42,7 +41,12 @@ export class Output {
4241
this.writeln();
4342
this.writeln(
4443
this.bold(
45-
`CSHELL v${this.VERSION}, running in FRIDA ${Frida.version} using ${Script.runtime}`,
44+
[
45+
`CSHELL: v${APP_VERSION}`,
46+
`COMMIT: ${GIT_COMMIT_HASH}`,
47+
`FRIDA: ${Frida.version}`,
48+
`RUNTIME: ${Script.runtime}`,
49+
].join('\n'),
4650
),
4751
);
4852
this.writeln(`init script: ${Output.bold(DEFAULT_SRC_PATH)}`);

version.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { execSync } = require('child_process');
2+
const fs = require('fs');
3+
const path = require('path');
4+
5+
const packageJsonPath = path.resolve(__dirname, 'package.json');
6+
const { version } = require(packageJsonPath);
7+
8+
let commitHash = 'unknown';
9+
try {
10+
commitHash = execSync('git rev-parse HEAD').toString().trim();
11+
} catch (err) {
12+
console.error('Failed to get Git commit hash:', err.message);
13+
}
14+
15+
// Write the commit hash to a file
16+
const outputPath = path.resolve('.', 'src', 'version.ts');
17+
const content = `
18+
export const GIT_COMMIT_HASH = '${commitHash}';
19+
export const APP_VERSION = '${version}';
20+
`;
21+
22+
fs.writeFileSync(outputPath, content, { encoding: 'utf8' });
23+
24+
console.log(`Git commit hash written to ${outputPath}`);

0 commit comments

Comments
 (0)