-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7aaeb99
commit b56a126
Showing
16 changed files
with
252 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import styled from 'styled-components'; | ||
|
||
const Label = styled.label` | ||
input { | ||
vertical-align: middle; | ||
} | ||
`; | ||
|
||
interface CheckboxOptionProps | ||
extends React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {} | ||
export const CheckboxOption: React.FC<React.PropsWithChildren<CheckboxOptionProps>> = ({ children, ...other }) => ( | ||
<Label> | ||
<input type="checkbox" {...other} /> | ||
{children} | ||
</Label> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "@wcj/tools-react-js-obfuscator", | ||
"version": "1.9.4", | ||
"main": "./cjs/index.js", | ||
"module": "./esm/index.js", | ||
"scripts": { | ||
"build": "tsbb build", | ||
"watch": "tsbb watch" | ||
}, | ||
"keywords": [], | ||
"files": [ | ||
"cjs", | ||
"esm", | ||
"src" | ||
], | ||
"author": "Kenny Wong <wowohoo@qq.com>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@codemirror/lang-javascript": "^6.0.0", | ||
"@wcj/tools-react-components": "1.9.4", | ||
"javascript-obfuscator": "~4.0.0" | ||
}, | ||
"peerDependencies": { | ||
"react": ">=16.14.0", | ||
"react-dom": ">=16.14.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import { Fragment, useRef, useState } from 'react'; | ||
import { | ||
StyledLayout, | ||
CopyButton, | ||
ResultCode, | ||
Spacing, | ||
CodeEditor, | ||
Button, | ||
Wrapper, | ||
CheckboxOption, | ||
ErrorLayout, | ||
} from '@wcj/tools-react-components'; | ||
import { javascript } from '@codemirror/lang-javascript'; | ||
import { useTranslation } from 'react-i18next'; | ||
import styled from 'styled-components'; | ||
import { ReactCodeMirrorRef } from '@uiw/react-codemirror'; | ||
import { obfuscate, ObfuscatorOptions } from 'javascript-obfuscator'; | ||
import * as sample from './sample'; | ||
|
||
const Info = styled.span` | ||
color: var(--color-fg-subtle); | ||
`; | ||
|
||
const defaultOptions: ObfuscatorOptions = { | ||
compact: true, | ||
// compact: boolean; | ||
// controlFlowFlattening: boolean; | ||
// controlFlowFlatteningThreshold: number; | ||
// deadCodeInjection: boolean; | ||
// deadCodeInjectionThreshold: number; | ||
// debugProtection: boolean; | ||
// debugProtectionInterval: number; | ||
// disableConsoleOutput: boolean; | ||
// domainLock: string[]; | ||
// domainLockRedirectUrl: string; | ||
// forceTransformStrings: string[]; | ||
// identifierNamesCache: TIdentifierNamesCache; | ||
// identifierNamesGenerator: TTypeFromEnum<typeof IdentifierNamesGenerator>; | ||
// identifiersDictionary: string[]; | ||
// identifiersPrefix: string; | ||
// ignoreImports: boolean; | ||
// inputFileName: string; | ||
// log: boolean; | ||
// numbersToExpressions: boolean; | ||
// optionsPreset: TOptionsPreset; | ||
// renameGlobals: boolean; | ||
// renameProperties: boolean; | ||
// renamePropertiesMode: TRenamePropertiesMode; | ||
// reservedNames: string[]; | ||
// reservedStrings: string[]; | ||
// seed: string | number; | ||
// selfDefending: boolean; | ||
// simplify: boolean; | ||
// sourceMap: boolean; | ||
// sourceMapBaseUrl: string; | ||
// sourceMapFileName: string; | ||
// sourceMapMode: TTypeFromEnum<typeof SourceMapMode>; | ||
// sourceMapSourcesMode: TTypeFromEnum<typeof SourceMapSourcesMode>; | ||
// splitStrings: boolean; | ||
// splitStringsChunkLength: number; | ||
// stringArray: boolean; | ||
// stringArrayCallsTransform: boolean; | ||
// stringArrayCallsTransformThreshold: number; | ||
// stringArrayEncoding: TStringArrayEncoding[]; | ||
// stringArrayIndexesType: TStringArrayIndexesType[]; | ||
// stringArrayIndexShift: boolean; | ||
// stringArrayRotate: boolean; | ||
// stringArrayShuffle: boolean; | ||
// stringArrayWrappersChainedCalls: boolean; | ||
// stringArrayWrappersCount: number; | ||
// stringArrayWrappersParametersMaxCount: number; | ||
// stringArrayWrappersType: TStringArrayWrappersType; | ||
// stringArrayThreshold: number; | ||
// target: TTypeFromEnum<typeof ObfuscationTarget>; | ||
// transformObjectKeys: boolean; | ||
// unicodeEscapeSequence: boolean; | ||
}; | ||
|
||
export default function JSObfuscator() { | ||
const [options, setOptions] = useState<any>(defaultOptions); | ||
const { t } = useTranslation(['js-obfuscator', 'common']); | ||
const editor = useRef<ReactCodeMirrorRef>(null); | ||
const [type, setType] = useState<'raw' | 'obfuscator'>('raw'); | ||
const [value, setValue] = useState(sample.val || ''); | ||
const [valueObfuscate, setValueObfuscate] = useState(''); | ||
const [error, setError] = useState(''); | ||
function handleObfuscate() { | ||
if (type === 'raw') { | ||
const val = obfuscate(value, options); | ||
setValueObfuscate(val.getObfuscatedCode()); | ||
} else { | ||
} | ||
setType(type === 'raw' ? 'obfuscator' : 'raw'); | ||
} | ||
const codeSource = type === 'raw' ? value : valueObfuscate; | ||
return ( | ||
<Wrapper> | ||
<StyledLayout | ||
title="JavaScript Obfuscator" | ||
extra={ | ||
<Fragment> | ||
<Button onClick={() => handleObfuscate()}> | ||
{type === 'raw' ? t<string>('Obfuscator') : t<string>('Raw Code')} | ||
</Button> | ||
{codeSource && <CopyButton value={codeSource} />} | ||
<Button | ||
onClick={() => { | ||
editor.current?.view?.focus(); | ||
setValue(sample.val); | ||
setType('raw'); | ||
}} | ||
> | ||
{t<string>('Sample', { ns: 'common' })} | ||
</Button> | ||
</Fragment> | ||
} | ||
> | ||
<CodeEditor | ||
value={codeSource} | ||
ref={editor} | ||
height="calc(100vh - 87px)" | ||
extensions={[javascript()]} | ||
onChange={(value) => { | ||
type === 'raw' ? setValue(value) : setValueObfuscate(value); | ||
}} | ||
/> | ||
</StyledLayout> | ||
<StyledLayout | ||
title={t<string>('Options', { ns: 'common' })} | ||
style={{ maxWidth: 420 }} | ||
extra={ | ||
<Fragment> | ||
<Button onClick={() => setOptions(defaultOptions)}>Reset</Button> | ||
<Button onClick={() => setOptions({})}>None</Button> | ||
</Fragment> | ||
} | ||
> | ||
<ResultCode codeProps={{ style: { height: 'calc(100vh - 87px)', overflow: 'auto', margin: 0 } }}> | ||
<Spacing> | ||
<CheckboxOption | ||
checked={!!options.compact} | ||
onChange={({ target }) => { | ||
setOptions({ ...options, ...{ compact: target.checked } }); | ||
}} | ||
> | ||
{t<string>('compact')} <Info>{t<string>('Compact code output on one line.')}</Info> | ||
</CheckboxOption> | ||
</Spacing> | ||
</ResultCode> | ||
</StyledLayout> | ||
{error && <ErrorLayout>{error}</ErrorLayout>} | ||
</Wrapper> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const js = `function hello(who = "world") { console.log(\`Hello, \${who}!\`) }`; | ||
export const val = `function hello(who = "world") { | ||
console.log(\`Hello, \${who}!\`) | ||
return \`Hello, \${who}!\` | ||
} | ||
hello(); | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig", | ||
"include": ["src"], | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"outDir": "cjs", | ||
"noEmit": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,7 @@ | |
"Formatter": "格式化", | ||
"Minify": "压缩", | ||
"Options": "选项", | ||
"Copy": "复制", | ||
"Copied": "已复制", | ||
"Sample": "示例" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"Obfuscator": "混淆", | ||
"Raw Code": "原始代码", | ||
"Compact code output on one line.": "在一行上压缩代码输出" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"Obfuscator": "Obfuscator" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters