mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
0.28.0 release
Support of BigInt
This commit is contained in:
+1
-1
@@ -11,6 +11,6 @@ export function StringArrayRotateFunctionTemplate (): string {
|
||||
};
|
||||
|
||||
{code}
|
||||
})({stringArrayName}, 0x{stringArrayRotationAmount});
|
||||
})({stringArrayName}, {stringArrayRotationAmount});
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -37,12 +37,11 @@ export class HexadecimalIdentifierNamesGenerator extends AbstractIdentifierNames
|
||||
const rangeMaxInteger: number = 99_999_999;
|
||||
const randomInteger: number = this.randomGenerator.getRandomInteger(rangeMinInteger, rangeMaxInteger);
|
||||
const hexadecimalNumber: string = NumberUtils.toHex(randomInteger);
|
||||
const prefixLength: number = Utils.hexadecimalPrefix.length + 1;
|
||||
const baseNameLength: number = nameLength
|
||||
? nameLength - prefixLength
|
||||
: HexadecimalIdentifierNamesGenerator.baseIdentifierNameLength;
|
||||
const prefixLength: number = Utils.hexadecimalPrefix.length;
|
||||
const baseNameLength: number = (nameLength ?? HexadecimalIdentifierNamesGenerator.baseIdentifierNameLength)
|
||||
+ prefixLength;
|
||||
const baseIdentifierName: string = hexadecimalNumber.substr(0, baseNameLength);
|
||||
const identifierName: string = `_${Utils.hexadecimalPrefix}${baseIdentifierName}`;
|
||||
const identifierName: string = `_${baseIdentifierName}`;
|
||||
|
||||
if (!this.isValidIdentifierName(identifierName)) {
|
||||
return this.generateNext(nameLength);
|
||||
|
||||
@@ -118,6 +118,7 @@ export class LiteralTransformer extends AbstractNodeTransformer {
|
||||
break;
|
||||
|
||||
case 'number':
|
||||
case 'bigint':
|
||||
newLiteralNode = this.literalObfuscatingReplacerFactory(
|
||||
LiteralObfuscatingReplacer.NumberLiteralObfuscatingReplacer
|
||||
).replace(literalNode);
|
||||
|
||||
+5
-6
@@ -8,7 +8,6 @@ import { IOptions } from '../../../../interfaces/options/IOptions';
|
||||
import { AbstractObfuscatingReplacer } from '../AbstractObfuscatingReplacer';
|
||||
import { NodeFactory } from '../../../../node/NodeFactory';
|
||||
import { NumberUtils } from '../../../../utils/NumberUtils';
|
||||
import { Utils } from '../../../../utils/Utils';
|
||||
|
||||
@injectable()
|
||||
export class NumberLiteralObfuscatingReplacer extends AbstractObfuscatingReplacer {
|
||||
@@ -33,8 +32,8 @@ export class NumberLiteralObfuscatingReplacer extends AbstractObfuscatingReplace
|
||||
public replace (literalNode: ESTree.SimpleLiteral): ESTree.Node {
|
||||
const literalValue: ESTree.SimpleLiteral['value'] = literalNode.value;
|
||||
|
||||
if (typeof literalValue !== 'number') {
|
||||
throw new Error('`NumberLiteralObfuscatingReplacer` should accept only literals with `number` value');
|
||||
if (typeof literalValue !== 'number' && typeof literalValue !== 'bigint') {
|
||||
throw new Error('`NumberLiteralObfuscatingReplacer` should accept only literals with `number` and `bigint` value');
|
||||
}
|
||||
|
||||
let rawValue: string;
|
||||
@@ -42,10 +41,10 @@ export class NumberLiteralObfuscatingReplacer extends AbstractObfuscatingReplace
|
||||
if (this.numberLiteralCache.has(literalValue)) {
|
||||
rawValue = <string>this.numberLiteralCache.get(literalValue);
|
||||
} else {
|
||||
if (!NumberUtils.isCeil(literalValue)) {
|
||||
rawValue = String(literalValue);
|
||||
if (NumberUtils.isCeil(literalValue)) {
|
||||
rawValue = NumberUtils.toHex(literalValue);
|
||||
} else {
|
||||
rawValue = `${Utils.hexadecimalPrefix}${NumberUtils.toHex(literalValue)}`;
|
||||
rawValue = String(literalValue);
|
||||
}
|
||||
|
||||
this.numberLiteralCache.set(literalValue, rawValue);
|
||||
|
||||
+1
-2
@@ -15,7 +15,6 @@ import { AbstractObfuscatingReplacer } from '../AbstractObfuscatingReplacer';
|
||||
import { NodeMetadata } from '../../../../node/NodeMetadata';
|
||||
import { NodeFactory } from '../../../../node/NodeFactory';
|
||||
import { NumberUtils } from '../../../../utils/NumberUtils';
|
||||
import { Utils } from '../../../../utils/Utils';
|
||||
|
||||
@injectable()
|
||||
export class StringLiteralObfuscatingReplacer extends AbstractObfuscatingReplacer implements IInitializable {
|
||||
@@ -129,7 +128,7 @@ export class StringLiteralObfuscatingReplacer extends AbstractObfuscatingReplace
|
||||
private replaceWithStringArrayCallNode (stringArrayStorageItemData: IStringArrayStorageItemData): ESTree.Node {
|
||||
const { index, decodeKey } = stringArrayStorageItemData;
|
||||
|
||||
const hexadecimalIndex: string = `${Utils.hexadecimalPrefix}${NumberUtils.toHex(index)}`;
|
||||
const hexadecimalIndex: string = NumberUtils.toHex(index);
|
||||
const callExpressionArgs: (ESTree.Expression | ESTree.SpreadElement)[] = [
|
||||
StringLiteralObfuscatingReplacer.getHexadecimalLiteralNode(hexadecimalIndex)
|
||||
];
|
||||
|
||||
@@ -42,7 +42,7 @@ export class StringArrayStorage extends MapStorage <string, IStringArrayStorageI
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
private static readonly stringArrayNameLength: number = 7;
|
||||
private static readonly stringArrayNameLength: number = 4;
|
||||
|
||||
/**
|
||||
* @type {IArrayUtils}
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
import { Utils } from './Utils';
|
||||
|
||||
export class NumberUtils {
|
||||
/**
|
||||
* @param {number} dec
|
||||
* @param {number} number
|
||||
* @returns {string}
|
||||
*/
|
||||
public static toHex (dec: number): string {
|
||||
public static toHex (number: number | bigint): string {
|
||||
const radix: number = 16;
|
||||
|
||||
return dec.toString(radix);
|
||||
const basePart: string = typeof number === 'number'
|
||||
? number.toString(radix)
|
||||
: `${number.toString(radix)}n`;
|
||||
|
||||
return `${Utils.hexadecimalPrefix}${basePart}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} number
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isCeil (number: number): boolean {
|
||||
return number % 1 === 0;
|
||||
public static isCeil (number: number | bigint): boolean {
|
||||
return typeof number === 'number'
|
||||
? number % 1 === 0
|
||||
: true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user