📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

@olaf-mix/olaf-mix

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@olaf-mix/olaf-mix - npm Package Compare versions

Comparing version

to
0.0.2

20

package.json
{
"name": "@olaf-mix/olaf-mix",
"version": "0.0.2-beta2",
"version": "0.0.2",
"description": "A flexible obfuscation tool",

@@ -11,3 +11,3 @@ "main": "./src/index.js",

"scripts": {
"dev-rollup": "rollup -c --watch --config ./config/rollup.config.dev.js",
"dev": "rollup -c --watch --config ./config/rollup.config.js",
"test": "jest"

@@ -30,23 +30,17 @@ },

"dependencies": {
"core-js": "3",
"loglevel": "^1.6.6",
"md5": "^2.2.1",
"numeral": "^2.0.6",
"uglify-js": "^3.7.1"
"numeral": "^2.0.6"
},
"devDependencies": {
"@babel/core": "^7.7.4",
"@babel/preset-env": "^7.7.4",
"@rollup/plugin-node-resolve": "^6.0.0",
"@rollup/pluginutils": "^3.0.0",
"babel-loader": "^8.0.6",
"jest": "^24.9.0",
"jscodeshift": "^0.6.4",
"rollup": "^1.27.7",
"rollup": "^1.27.13",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-uglify": "^6.0.0",
"webpack": "^4.41.3",
"webpack-cli": "^3.3.10"
"@rollup/plugin-node-resolve": "^6.0.0",
"@rollup/pluginutils": "^3.0.0",
"@olaf-mix/rollup-plugin-olaf-mix": "^1.0.0"
}
}

@@ -1,11 +0,129 @@

const j = require('jscodeshift');
const {transformHandler} = require('./main')
const numeral = require('numeral');
const log = require('loglevel');
log.setLevel(process.env.RUN_MODE === 'debug' ? 'debug' : 'warn')
const j = require('jscodeshift')
const {MIX_LIST} = require('./util/GlobalConstant');
require('./methods/registerMethods');
module.exports = function(fileInfo, api, options){
console.log('transforming', fileInfo.path);
const root = api.jscodeshift(fileInfo.source);
transformHandler(root);
return root.toSource({quote: 'single'});
function injectedHelperCode(root) {
root.findImmediateChildren(j.Program).forEach(_ => {
_.getValueProperty('body').unshift(
j.variableDeclaration('const',
MIX_LIST.map(({k, v}) => {
return j.variableDeclarator(
j.identifier(k),
j.literal(v)
);
})
)
)
});
}
function visitOlafMix(comment, root, callback){
root.find(j.Comment).forEach(_ => {
const commentValue = _.getValueProperty('value');
if (!~commentValue.indexOf(comment)){
return;
} else {
j(_).replaceWithKey('value', _ => _.value.replace(comment, '@olaf-finish'))
}
callback(_.parentPath.parentPath);
})
}
let isInjectedHelperCode = false;
const transformHandler = function(root, options = {forceInjected: false}) {
log.debug('********************')
const {forceInjected} = options;
if (forceInjected || !isInjectedHelperCode){
injectedHelperCode(root);
isInjectedHelperCode = true;
}
visitOlafMix('@olaf-mix', root,npath => {
const ncollection = j(npath)
const ntype = npath.getValueProperty('type');
if (ntype === 'MethodDefinition'){
log.debug('******** 方法定义 ********')
ncollection
.findImmediateChildren(j.Identifier)
.refactorIdentifierToStringExpression()
log.debug('******** 函数定义 ********')
// ncollection
// .find(j.FunctionDeclaration)
// .findImmediateChildren(j.Identifier)
log.debug('******** 表达式子树 ********')
ncollection
.find(j.BlockStatement)
.find(j.ExpressionStatement)
.find(j.Identifier)
.forEach(_ => {
// log.debug(_.getValueProperty('name'));
});
log.debug('******** 变量定义子树 ********')
ncollection
.find(j.BlockStatement)
.find(j.VariableDeclaration)
.find(j.Identifier)
.forEach(_ => {
// log.debug(_.getValueProperty('name'));
})
log.debug('******** 方法调用 ********')
ncollection
.find(j.CallExpression)
.findImmediateChildren(j.MemberExpression)
.renameMemberExpressionVariable()
log.debug('******** 常量定义 ********')
ncollection
.find(j.Literal)
.refactorLiteralValue()
} else if (ntype === 'ClassDeclaration'){
log.debug('定义类');
} else if (ntype === 'VariableDeclaration') {
ncollection
.find(j.Literal)
.refactorLiteralValue()
log.debug('异常定义');
}
});
visitOlafMix('@olaf-string', root,npath => {
const ncollection = j(npath)
const ntype = npath.getValueProperty('type');
if (ntype === 'VariableDeclaration') {
ncollection
.find(j.Literal)
.refactorLiteralValue(1)
} else {
log.debug('异常定义');
}
})
log.debug('--------------------')
return true;
};
const JSCODESHIFT_DEFAULT_OPTION = {
quote: 'single'
};
const DEFAULT_OPTION = {
forceInjected: false,
returnAST: false,
jscodeshift: JSCODESHIFT_DEFAULT_OPTION
};
const mixCode = function(code, options){
options = {
...DEFAULT_OPTION,
...options
}
const root = j(code);
transformHandler(root, options.forceInjected);
if (options.returnAST){
return root;
}
return root.toSource({...options.jscodeshift});
}
module.exports = {
mixCode,
};