Skip to content

Commit

Permalink
new methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Azq2 committed Aug 28, 2024
1 parent 9fa9319 commit 90533a5
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 6 deletions.
19 changes: 19 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"description": "Tools for Siemens Mobile firmware files.",
"dependencies": {
"debug": "^4.3.4",
"iconv-lite": "^0.6.3",
"sprintf-js": "^1.1.3"
},
"repository": {
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './exe.js';
export * from './xbi.js';
export * from './swupik.js';
export * from './xfs.js';
21 changes: 15 additions & 6 deletions src/xbi.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const XBI_FILEDS = {
0x23: ['flashSize', 'uint32be'],
0x28: ['model', 'str'],
0x29: ['vendor', 'str'],
0x2A: ['baseline0', 'str'],
0x2A: ['baseline', 'str'],
0x30: ['eraseRegions[]', 'region'],
0x37: ['swCode', 'swCode'],
0x34: ['projectType', 'uint8'],
Expand All @@ -44,9 +44,9 @@ const XBI_FILEDS = {
0x56: ['hashAreaSize', 'uint16le'],

0x60: ['t9', 'uint8'],
0x61: ['baseline1', 'str'],
0x62: ['baseline2', 'str'],
0x63: ['baseline3', 'str'],
0x61: ['databaseName', 'str'],
0x62: ['baselineVersion', 'str'],
0x63: ['baselineRelease', 'str'],

0x64: ['mobileName', 'str2'],
0x70: ['dll', 'str2'],
Expand Down Expand Up @@ -157,8 +157,17 @@ export function parseXbi(buffer) {
return info;
}

export function convertXbiToFlash(buffer) {
let xbi = parseXbi(buffer);
export function getXbiExtension(xbi) {
if (xbi.updateType == 'ExtendedNewSplit') {
return 'xfs';
} else if (xbiInfo.databaseName == 'klf_bootcore') {
return 'xbb';
}
return xbi.compressionType == 0 ? 'xbi' : 'xbz';
}

export function convertXbiToFlash(buffer, xbi = null) {
xbi = xbi || parseXbi(buffer);

let flash = Buffer.alloc(xbi.flashSize);
flash.fill(0xFF, 0);
Expand Down
64 changes: 64 additions & 0 deletions src/xfs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import iconv from 'iconv-lite';

export function getVersionFromFFS(buffer) {
return _getVersionFromFFS_SG(buffer) || _getVersionFromFFS_NSG(buffer);
}

function _getVersionFromFFS_NSG(buffer) {
let fileNamePtr = iconv.encode("info.txt", "utf16-be");
let lastIndex = 0;
while (true) {
let index = buffer.indexOf(fileNamePtr, lastIndex);
if (index < 0)
break;

index += fileNamePtr.length;

let possibleString = buffer.subarray(index, index + 256).filter((byte) => byte != 0xFF).toString();
let matches = possibleString.match(/([\w\d]+_\d+_[\w\d-]+_\d+_\d+)\n/i);

if (matches && matches[1])
return matches[1];

lastIndex = index + 1;
}

return null;
}

function _getVersionFromFFS_SG(buffer) {
let patterns = [
iconv.encode("ccq_vinfo.txt", "utf16-be"),
Buffer.concat([ Buffer.from("ccq_vinfo.txt", "utf-8"), Buffer.from([0]) ])
];

for (let fileNamePtr of patterns) {
let lastIndex = 0;
while (true) {
let index = buffer.indexOf(fileNamePtr, lastIndex);
if (index < 0)
break;

index += fileNamePtr.length;

let chars = [];
while (index < buffer.length && buffer[index] != 0x0A) {
if (buffer[index] > 0x7F || buffer[index] < 0x20) {
if (buffer[index] != 0x0A)
chars = [];
break;
}
chars.push(buffer[index]);
index++;
}

let possibleString = Buffer.from(chars).toString();
if (possibleString.match(/^[\w\d]+_\d+_[\w\d-]+_\d+_\d+$/i))
return possibleString;

lastIndex = index + 1;
}
}

return null;
}

0 comments on commit 90533a5

Please sign in to comment.