Update modules and dependencies, change to jsbi

* Drop gulp support
* Migrate long.js to JSBI library (for long math)
* Update karma targets
This commit is contained in:
Slava Bacherikov 2020-05-29 20:12:51 +03:00
parent 0fef378a11
commit b99bdd7c81
16 changed files with 3781 additions and 4884 deletions

2
.gitignore vendored
View file

@ -1,10 +1,10 @@
.*.sw[po]
*.py[co]
*.bak
.nyc_output/
upload/
build/
temp/
typings/
typings.json
node_modules/
dist/

View file

@ -2,7 +2,7 @@ sudo: false
dist: trusty
language: node_js
node_js:
- '8'
- '14'
env:
matrix:
- SAUCE=true
@ -18,7 +18,7 @@ script:
- npm run browser-test
- npm run lint
after_sucess:
- ci/coveralls.sh
- npm run send-coverage
git:
depth: 1
submodules: false

View file

@ -1,2 +0,0 @@
#!/bin/sh
cat ./coverage/lcov.info | $(npm bin)/coveralls || true

View file

@ -1,2 +0,0 @@
var dataLayer;

View file

@ -1,17 +0,0 @@
/**
* @return {number}
* @nosideeffects
*/
Performance.prototype.mozNow = function() {};
/**
* @return {number}
* @nosideeffects
*/
Performance.prototype.oNow = function() {};
/**
* @return {number}
* @nosideeffects
*/
Performance.prototype.msNow = function() {};

View file

@ -1,159 +0,0 @@
/*
* Copyright 2017 The Closure Compiler Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Definitions for WebAssembly JS API
*
* @see http://webassembly.org/docs/js/
*
* @externs
* @author loorongjie@gmail.com (Loo Rong Jie)
*/
/**
* @const
*/
var WebAssembly = {};
/**
* @constructor
* @param {!BufferSource} bytes
*/
WebAssembly.Module = function(bytes) {};
/**
* @constructor
* @param {!WebAssembly.Module} moduleObject
* @param {Object=} importObject
*/
WebAssembly.Instance = function(moduleObject, importObject) {};
/**
* @typedef {{initial:number, maximum:(number|undefined)}}
*/
var MemoryDescriptor;
/**
* @constructor
* @param {MemoryDescriptor} memoryDescriptor
*/
WebAssembly.Memory = function(memoryDescriptor) {};
/**
* @typedef {{element:string, initial:number, maximum:(number|undefined)}}
*/
var TableDescriptor;
/**
* @constructor
* @param {TableDescriptor} tableDescriptor
*/
WebAssembly.Table = function(tableDescriptor) {};
/**
* @constructor
* @extends {Error}
*/
WebAssembly.CompileError = function() {};
/**
* @constructor
* @extends {Error}
*/
WebAssembly.LinkError = function() {};
/**
* @constructor
* @extends {Error}
*/
WebAssembly.RuntimeError = function() {};
// Note: Closure compiler does not support function overloading, omit this overload for now.
// {function(!WebAssembly.Module, Object=):!Promise<!WebAssembly.Instance>}
/**
* @param {!BufferSource} moduleObject
* @param {Object=} importObject
* @return {!Promise<{module:WebAssembly.Module, instance:WebAssembly.Instance}>}
*/
WebAssembly.instantiate = function(moduleObject, importObject) {};
/**
* @param {!BufferSource} bytes
* @return {!Promise<!WebAssembly.Module>}
*/
WebAssembly.compile = function(bytes) {};
/**
* @param {!BufferSource} bytes
* @return {boolean}
* @nosideeffects
*/
WebAssembly.validate = function(bytes) {};
/**
* @param {!WebAssembly.Module} moduleObject
* @return {!Array<{name:string, kind:string}>}
*/
WebAssembly.Module.exports = function(moduleObject) {};
/**
* @param {!WebAssembly.Module} moduleObject
* @return {!Array<{module:string, name:string, kind:string}>}
*/
WebAssembly.Module.imports = function(moduleObject) {};
/**
* @param {!WebAssembly.Module} moduleObject
* @param {string} sectionName
* @return {!Array<!ArrayBuffer>}
*/
WebAssembly.Module.customSections = function(moduleObject, sectionName) {};
WebAssembly.Instance.prototype.exports;
/**
* @param {number} delta
* @return {number}
*/
WebAssembly.Memory.prototype.grow = function(delta) {};
/**
* @type {!ArrayBuffer}
*/
WebAssembly.Memory.prototype.buffer;
/**
* @param {number} delta
* @return {number}
*/
WebAssembly.Table.prototype.grow = function(delta) {};
/**
* @type {number}
*/
WebAssembly.Table.prototype.length;
/**
* @param {number} index
* @return {function(...)}
*/
WebAssembly.Table.prototype.get = function(index) {};
/**
* @param {number} index
* @param {?function(...)} value
*/
WebAssembly.Table.prototype.set = function(index, value) {};

View file

@ -1,92 +0,0 @@
const gulp = require("gulp");
const ts = require("gulp-typescript");
const tslint = require("gulp-tslint");
const jasmine = require("gulp-jasmine");
const sourcemaps = require('gulp-sourcemaps');
const istanbul = require("gulp-istanbul");
const remapIstanbul = require("remap-istanbul/lib/gulpRemapIstanbul");
const tsProject = ts.createProject("tsconfig.json");
const del = require('del');
const { getWebpackConfig } = require('./webpack.base');
const webpack = require('webpack');
function coverage_build() {
return tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.js.pipe(sourcemaps.write('.', {includeContent: false}))
.pipe(gulp.dest("coverage-dist"));
};
const pre_coverage = gulp.series(coverage_build, function() {
return gulp.src(["coverage-dist/**/*.js"])
.pipe(istanbul())
.pipe(istanbul.hookRequire());
});
const coverage = gulp.series(coverage_build, pre_coverage, function() {
return gulp.src("coverage-dist/**/*.spec.js")
.pipe(jasmine())
.pipe(istanbul.writeReports({
dir: './coverage',
reporters: ['json'],
reportOpts: {
json: {dir: './coverage', file: 'coverage-js.json'}
}
})).on("end", function () {
return gulp.src('coverage/coverage-js.json')
.pipe(remapIstanbul({
basePath: 'src/',
reports: {
'json': './coverage/coverage.json',
'html': './coverage/html-report',
'lcovonly': './coverage/lcov.info',
'text': null
}
}));
});
});
function lint() {
return tsProject.src()
.pipe(tslint({"formatter": "verbose"}))
.pipe(tslint.report());
}
function clean(cb) {
del(['dist', 'test-dist', 'coverage-dist', 'coverage']).then(paths => cb());
}
function test_build() {
return tsProject.src().pipe(tsProject()).pipe(gulp.dest("test-dist"));
}
const test = gulp.series(test_build, function() {
return gulp.src("test-dist/**/*.spec.js").pipe(jasmine());
});
function build_webpack(gtag, cb) {
webpack(getWebpackConfig(true, gtag), (err, stats) => {
cb();
});
}
function clean_dist(cb) {
del(['dist']).then(paths => cb());
}
function build_prod(cb) {
build_webpack("UA-112154345-1", cb);
}
function build_stage(cb) {
build_webpack("UA-112154345-2", cb);
}
exports.lint = lint;
exports.clean = clean;
exports.test = test;
exports.coverage = coverage;
exports.build_prod = gulp.series(clean_dist, build_prod);
exports.build_stage = gulp.series(clean_dist, build_stage);
exports.default = gulp.parallel(lint, gulp.series(test, coverage));

13
jasmine.json Normal file
View file

@ -0,0 +1,13 @@
{
"reporters": [{
"name": "jasmine-spec-reporter#SpecReporter",
"options": {
"displayStacktrace": "all"
}
}],
"spec_dir": "src",
"spec_files": ["**/*.spec.ts"],
"helpers": [
"./node_modules/babel-register/lib/node.js"
]
}

View file

@ -1,52 +1,26 @@
module.exports = function(config) {
var customLaunchers = {
sl_ie_10: {
base: "SauceLabs",
browserName: "internet explorer",
platform: "Windows 7",
version: "10"
},
sl_safari_7: {
base: "SauceLabs",
browserName: "safari",
platform: "OS X 10.10",
version: "8.0"
},
sl_ios_safari: {
base: 'SauceLabs',
browserName: 'safari',
platform: 'iOS',
deviceName: 'iPhone 6 Simulator',
deviceName: 'iPhone 7 Simulator',
version: '10.3',
deviceOrientation: 'portrait'
},
sl_android: {
sl_safari_7: {
base: "SauceLabs",
browserName: 'Browser',
patform: 'Android',
version: '5.1',
deviceName: 'Android Emulator',
deviceOrientation: 'portrait'
},
sl_chrome_41: {
base: "SauceLabs",
browserName: 'chrome',
platform: 'Linux',
version: '41'
},
sl_firefox_8: {
base: "SauceLabs",
browserName: 'firefox',
platform: 'Linux',
version: '8.0'
browserName: "safari",
platform: "OS X 10.11",
version: "10.0"
},
sl_edge_13: {
base: "SauceLabs",
browserName: 'MicrosoftEdge',
platform: 'Windows 10',
version: '13.10586'
},
},
ChromeHeadlessTravis: {
base: "ChromeHeadless",
flags: ['--no-sandbox']

8169
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -2,50 +2,47 @@
"name": "pwgen-for-bios",
"version": "2.0.0",
"description": "Password generator for BIOS",
"main": "decrypt_bios.js",
"main": "src/ui.ts",
"browserlist": "> 0.25%, not dead",
"dependencies": {
"long": "github:dcodeIO/long.js"
"jsbi": "^3.1.2"
},
"devDependencies": {
"@babel/core": "^7.10.1",
"@babel/preset-env": "^7.10.1",
"@types/jasmine": "^3.5.10",
"@types/long": "^3.0.32",
"gulp-jasmine": "^4.0.0",
"babel-loader": "^8.1.0",
"clean-webpack-plugin": "^3.0.0",
"closure-webpack-plugin": "^2.3.0",
"copy-webpack-plugin": "^5.1.1",
"coveralls": "^3.0.11",
"del": "^5.1.0",
"google-closure-compiler": "^20190819.0.0",
"gulp": "^4.0.2",
"gulp-istanbul": "^1.1.3",
"gulp-sourcemaps": "^2.6.4",
"gulp-tslint": "^8.1.3",
"gulp-typescript": "^5.0.1",
"coveralls": "^3.1.0",
"html-webpack-plugin": "^3.2.0",
"istanbul": "^0.4.5",
"karma": "^4.4.1",
"jasmine": "^3.5.0",
"jasmine-spec-reporter": "^5.0.2",
"karma": "^5.0.9",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^1.3.0",
"karma-jasmine": "^2.0.1",
"karma-jasmine": "^3.3.1",
"karma-sauce-launcher": "^1.2.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^4.0.2",
"remap-istanbul": "^0.13.0",
"nyc": "^15.0.1",
"terser-webpack-plugin": "^3.0.2",
"ts-loader": "^6.2.2",
"ts-node": "^8.10.2",
"tslint": "^5.20.1",
"typescript": "^3.8.3",
"webpack": "^4.42.1",
"typescript": "^3.9.3",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
"webpack-dev-server": "^3.11.0"
},
"scripts": {
"test": "gulp test",
"lint": "gulp lint",
"cover": "gulp coverage",
"clean": "gulp clean",
"all": "gulp default",
"build-prod": "gulp build_prod",
"build-stage": "gulp build_stage",
"test": "ts-node ./node_modules/jasmine/bin/jasmine --config=jasmine.json",
"lint": "tslint src/*.ts",
"cover": "nyc -r text -e .ts -x '**/*.spec.ts' npm test",
"send-coverage": "nyc report --reporter=text-lcov | coveralls",
"all": "npm test && npm run lint && npm run cover && npm run browser-test",
"build-prod": "PRODUCTION=1 GOOGLE_ANALYTICS_TAG=UA-112154345-1 webpack",
"build-stage": "PRODUCTION=1 GOOGLE_ANALYTICS_TAG=UA-112154345-2 webpack",
"browser-test": "karma start",
"webpack": "webpack",
"dev-server": "webpack-dev-server"

View file

@ -1,4 +1,4 @@
import * as Long from "long";
const JSBI = require("jsbi");
import { modularPow, sony4x4Keygen, sony4x4Solver } from "./sony_4x4";
describe("Sony 4x4 BIOS Keygen", () => {
@ -30,9 +30,9 @@ describe("Sony 4x4 BIOS Solver", () => {
describe("test modularPow", () => {
it("4 ^ 13 mod 497 == 445", () => {
expect(modularPow(Long.fromInt(4), 13, 497)).toEqual(445);
expect(modularPow(JSBI.BigInt(4), 13, 497)).toEqual(445);
});
it("100500 ^ 100500 mod 14 == 8", () => {
expect(modularPow(Long.fromInt(100500), 100500, 14)).toEqual(8);
expect(modularPow(JSBI.BigInt(100500), 100500, 14)).toEqual(8);
});
});

View file

@ -1,6 +1,8 @@
// based on dogbert's pwgen-sony-4x4.py
/* tslint:disable:no-bitwise */
import * as Long from "long";
import type JSBIT from "jsbi";
const JSBI = require("jsbi");
type JSBI = JSBIT;
import { makeSolver } from "./utils";
const otpChars: string = "9DPK7V2F3RT6HX8J";
@ -35,73 +37,79 @@ function encodePassword(pwd: number[]): string {
}
// http://numericalrecipes.blogspot.com/2009/03/modular-multiplicative-inverse.html
function extEuclideanAlg(a: Long, b: Long): [Long, Long, Long] {
if (b.isZero()) {
return [new Long(1), new Long(0), a];
function extEuclideanAlg(a: JSBI, b: JSBI): [JSBI, JSBI, JSBI] {
if (JSBI.EQ(b, 0)) {
return [JSBI.BigInt(1), JSBI.BigInt(0), a];
} else {
let [x, y, gcd] = extEuclideanAlg(b, a.mod(b));
return [y, x.sub(y.mul(a.div(b))), gcd];
let [x, y, gcd] = extEuclideanAlg(b, JSBI.remainder(a, b));
return [y, JSBI.subtract(x, JSBI.multiply(y, JSBI.divide(a, b))), gcd];
}
}
function modInvEuclid(a: Long, m: Long): Long | undefined {
function modInvEuclid(a: JSBI, m: JSBI): JSBI | undefined {
let [x, , gcd] = extEuclideanAlg(a, m);
if (gcd.eq(1)) {
if (JSBI.EQ(gcd, 1)) {
// hack for javascript modulo operation
// https://stackoverflow.com/questions/4467539/javascript-modulo-gives-a-negative-result-for-negative-numbers
const temp = x.mod(m);
return temp.gte(0) ? temp : temp.add(m);
const temp = JSBI.remainder(x, m);
return JSBI.GE(temp, 0) ? temp : JSBI.ADD(temp, m);
} else {
return undefined;
}
}
// https://en.wikipedia.org/wiki/Modular_exponentiation#Right-to-left_binary_method
export function modularPow(base: Long, exponent: number, modulus: number): number {
let result: Long = new Long(1, 0, true);
export function modularPow(base: JSBI, exponent: number, modulus: number | JSBI): number {
let result: JSBI = JSBI.BigInt(1);
if (modulus === 1) {
if (!(modulus instanceof JSBI)) {
modulus = JSBI.BigInt(modulus);
}
if (JSBI.EQ(modulus, 1)) {
return 0;
}
base = base.mod(modulus);
base = JSBI.remainder(base, modulus);
while (exponent > 0) {
if ((exponent & 1) === 1) {
result = result.mul(base).mod(modulus);
result = JSBI.remainder(JSBI.multiply(result, base), modulus);
}
exponent = exponent >> 1;
base = base.mul(base).mod(modulus);
base = JSBI.remainder(JSBI.multiply(base, base), modulus);
}
return result.toNumber();
return JSBI.toNumber(result);
}
function rsaDecrypt(code: number[]): number[] {
const low: number = arrayToNumber(code.slice(0, 4));
const high: number = arrayToNumber(code.slice(4, 8));
const c: Long = Long.fromBits(low, high, true);
const low: JSBI = JSBI.BigInt(arrayToNumber(code.slice(0, 4)));
const high: JSBI = JSBI.BigInt(arrayToNumber(code.slice(4, 8)));
const c: JSBI = JSBI.bitwiseOr(JSBI.leftShift(high, JSBI.BigInt(32)), low);
const p: number = 2795287379;
const q: number = 3544934711;
const e = 41;
const phi = (new Long(p - 1, 0, true)).mul(q - 1);
const d: Long = modInvEuclid(new Long(e, 0, true), phi) as Long;
const phi: JSBI = JSBI.multiply(JSBI.BigInt(p - 1), JSBI.BigInt(q - 1));
const d: JSBI = modInvEuclid(JSBI.BigInt(e), phi) as JSBI;
const dp = d.mod(p - 1);
const dq = d.mod(q - 1);
const qinv: Long = modInvEuclid(new Long(q), new Long(p)) as Long;
const dp: JSBI = JSBI.remainder(d, JSBI.BigInt(p - 1));
const dq: JSBI = JSBI.remainder(d, JSBI.BigInt(q - 1));
const qinv: JSBI = modInvEuclid(JSBI.BigInt(q), JSBI.BigInt(p)) as JSBI;
const m1 = modularPow(c, dp.toNumber(), p);
const m2 = modularPow(c, dq.toNumber(), q);
let h: Long;
const m1 = modularPow(c, JSBI.toNumber(dp), p);
const m2 = modularPow(c, JSBI.toNumber(dq), q);
let h: JSBI;
if (m1 < m2) {
h = Long.fromValue(m1 - m2).add(p).mul(qinv).mod(p);
h = JSBI.remainder(JSBI.multiply(JSBI.add(JSBI.BigInt(m1 - m2), JSBI.BigInt(p)), qinv), JSBI.BigInt(p));
} else {
h = Long.fromValue(m1 - m2).mul(qinv).mod(p);
h = JSBI.remainder(JSBI.multiply(JSBI.BigInt(m1 - m2), qinv), JSBI.BigInt(p));
}
const m = h.mul(q).add(m2);
return numberToArray(m.low).concat(numberToArray(m.high));
const m: JSBI = JSBI.add(JSBI.multiply(h, JSBI.BigInt(q)), JSBI.BigInt(m2));
return numberToArray(JSBI.toNumber(JSBI.asUintN(32, m))).concat(
numberToArray(JSBI.toNumber(JSBI.signedRightShift(m, JSBI.BigInt(32))))
);
}
export function sony4x4Keygen(hash: string): string {

View file

@ -2,7 +2,8 @@
"compilerOptions": {
"module": "commonjs",
"lib": ["dom", "es5"],
"target": "es3",
"target": "es5",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
@ -11,7 +12,8 @@
"strict": true,
"sourceMap": true,
"rootDir": "src/",
"outDir": "dist/"
"outDir": "dist/",
"typeRoots": ["./typings", "./node_modules/@types/"]
},
"exclude": [
"node_modules"

View file

@ -1,30 +1,13 @@
const path = require('path');
const ClosurePlugin = require('closure-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { DefinePlugin } = require('webpack');
const { exec } = require('child_process');
const Terser = require('terser-webpack-plugin');
const fs = require('fs');
function makeClosureCompiler() {
const externDir = path.join(__dirname, "externs");
const externs = [
path.join(externDir, "googleAnalytics.js"),
path.join(externDir, "performance.js"),
path.join(externDir, "webassembly.js")
];
var flags = {
compilation_level: "ADVANCED",
externs: externs
};
return new ClosurePlugin({mode: 'STANDARD'}, flags);
}
class VersionInfoPlugin {
constructor(options = {}) {
if (options.filename == void 0) {
@ -89,7 +72,6 @@ function getWebpackConfig(production, gtag) {
];
if (production) {
plugins.push(makeClosureCompiler());
webpackMode = "production";
} else {
webpackMode = "development";
@ -103,7 +85,10 @@ function getWebpackConfig(production, gtag) {
},
plugins: plugins,
optimization: {
concatenateModules: false
concatenateModules: false,
minimizer: [
new Terser({})
]
},
devtool: "source-map",
devServer: {
@ -119,7 +104,12 @@ function getWebpackConfig(production, gtag) {
{
test: /\.ts$/,
exclude: /node_modules/,
use: [{loader: 'ts-loader', options: {transpileOnly: true}}]
use: [{loader: 'ts-loader', options: {transpileOnly: false}}]
},
{
test: /\.m?js$/,
exclude: /node_modules/,
use: [{loader: 'babel-loader', options: {presets: ['@babel/preset-env']}}]
}
]
}