From 2fe7788327a57071f42c8ace312c796db819cc47 Mon Sep 17 00:00:00 2001 From: Slava Bacherikov Date: Fri, 22 Jul 2016 23:47:59 +0300 Subject: [PATCH] Add FSI20Hex code --- scripts/decrypt_bios.ts | 52 ++++++++++++++++++++++++++++++++++++++++- spec/bios.spec.js | 7 +++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/scripts/decrypt_bios.ts b/scripts/decrypt_bios.ts index 661e4da..bf3e4d6 100644 --- a/scripts/decrypt_bios.ts +++ b/scripts/decrypt_bios.ts @@ -256,6 +256,48 @@ function FSI20DecNewSolver(serial: string): string { }).join(""); } +/* For Fujinsu-Siemens. 8 or 5x4 hexadecimal digits. */ +function FSI20HexSolver(serial: string): string { + + function generateCRC16Table(): number[] { + let table: number[] = []; + for (let i = 0, crc = 0; i < 256; i++) { + crc = (i << 8); + for (let j = 0; j < 8; j++) { + crc = (crc << 1); + if (crc & 0x10000) + crc = crc ^ 0x1021; + } + table.push(crc & 0xFFFF); + } + return table; + } + + function hashToString(hash: number) { + const zero = "0".charCodeAt(0); + return [12, 8, 4, 0].reduce((acc, num) => { + let temp = String.fromCharCode(zero + ((hash >> num) % 16) % 10); + return acc + temp; + }, ""); + } + + function calculateHash(word: string, table: number[]) { + let hash = 0; + for (let i = 0, d = 0; i < word.length; i++) { + d = table[(word.charCodeAt(i) ^ (hash >> 8)) % 256]; + hash = ((hash << 8) ^ d) & 0xFFFF ; + } + return hash; + } + + if (serial.length === 20) + serial = serial.slice(12, 20); + + const table = generateCRC16Table(); + return hashToString(calculateHash(serial.slice(0, 4), table)) + + hashToString(calculateHash(serial.slice(4, 8), table)); +} + export let CleanSerial = (serial: string) => serial.trim().replace(/-/gi, ""); export let Sony: BIOSDecoder = { @@ -297,12 +339,20 @@ export let Insyde: BIOSDecoder = { export let FSI20DecOld: BIOSDecoder = { model: BIOSModels.FSIPhoenix, - name: "Fujitsu-Siemens old", + name: "Fujitsu-Siemens decimal", examples: ["1234-4321-1234-4321-1234"], check: (s) => /^\d{20}$/i.test(s), solve: (serial) => [FSI20DecNewSolver(serial), FSI20DecOldSolver(serial)] }; +export let FSI20Hex: BIOSDecoder = { + model: BIOSModels.FSILPhoenix, + name: "Fujitsu-Siemens hexdigits", + examples: ["AAAA-BBBB-CCCC-DEAD-BEEF"], + check: (s) => /^[0-9ABCDEF]{20}$/i.test(s), + solve: (serial) => [FSI20HexSolver(serial)] +}; + export let Decoders: BIOSDecoder[] = [ Sony, Samsung, HPMini, Insyde, FSI20DecOld ]; diff --git a/spec/bios.spec.js b/spec/bios.spec.js index dd99438..ec9311f 100644 --- a/spec/bios.spec.js +++ b/spec/bios.spec.js @@ -49,11 +49,16 @@ describe("Decryp BIOS", function() { expect(bios.Insyde.check("12345678d")).toBe(false); }); - it("FSI 20 dec old key for 1234-4321-1234-4321-1234 is 7122790 or 10cphf0b", function() { + it("FSI 20 dec key for 1234-4321-1234-4321-1234 is 7122790 or 10cphf0b", function() { expect(bios.FSI20DecOld.solve(bios.CleanSerial("1234-4321-1234-4321-1234"))) .toEqual(["7122790", "10cphf0b"]); expect(bios.FSI20DecOld.solve(bios.CleanSerial("1234-4321-1234-4321-1236"))) .toEqual(["7122790", "100phf0b"]); }) + + it("FSI 20 hex key for AAAA-BBBB-CCCC-DEAD-BEEF is 64830592", function() { + expect(bios.FSI20Hex.solve(bios.CleanSerial("AAAA-BBBB-CCCC-DEAD-BEEF"))) + .toEqual(["64830592"]); + }); });