Commit 36539bf3 authored by ratel group's avatar ratel group

add code

parents
Pipeline #840 canceled with stages
# kdiff3 ignore
*.orig
# maven ignore
target/
# eclipse ignore
.settings/
.project
.classpath
# idea ignore
.idea/
*.ipr
*.iml
*.iws
# temp ignore
*.log
*.cache
*.diff
*.patch
*.tmp
# system ignore
.DS_Store
Thumbs.db
# package ignore (optional)
# *.jar
# *.war
# *.zip
# *.tar
# *.tar.gz
#location
.metadata
RemoteSystemsTempFiles
Servers
.externalToolBuilders
out/
bin/
.springBeans
catalina.base_IS_UNDEFINED/
#shade plugin ignore
dependency-reduced-pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.virjar</groupId>
<artifactId>geetest-crack</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
This diff is collapsed.
package com.virjar.geetest.crack;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import java.util.List;
/**
* Created by virjar on 2017/9/8.
*/
public class CodeEntry {
private List<Integer> entryID;// 路径ID,代表状态机状态ID
private JSONArray codeSegment; // 对应的执行片段
private boolean isReturnEntry = false;// 是否是结束语句
private String sateControlValName;
private List<Integer> singleNext;
private List<Integer> testNext;
private List<Integer> textNotNext;
private JSONObject testCondition;
private List<List<Integer>> preStates = Lists.newLinkedList();
public List<Integer> getSingleNext() {
return singleNext;
}
public void setSingleNext(List<Integer> singleNext) {
this.singleNext = singleNext;
}
public List<Integer> getTestNext() {
return testNext;
}
public void setTestNext(List<Integer> testNext) {
this.testNext = testNext;
}
public List<Integer> getTestNotNext() {
return textNotNext;
}
public void setTextNotNext(List<Integer> textNotNext) {
this.textNotNext = textNotNext;
}
public JSONObject getTestCondition() {
return testCondition;
}
public void setTestCondition(JSONObject testCondition) {
this.testCondition = testCondition;
}
public List<Integer> getEntryID() {
return entryID;
}
public void setEntryID(List<Integer> entryID) {
this.entryID = entryID;
}
public JSONArray getCodeSegment() {
return codeSegment;
}
public void setCodeSegment(JSONArray codeSegment) {
if (codeSegment == null) {
System.out.println("null");
}
this.codeSegment = codeSegment;
}
public boolean isReturnEntry() {
return isReturnEntry;
}
public void setReturnEntry(boolean returnEntry) {
isReturnEntry = returnEntry;
}
public String getSateControlValName() {
return sateControlValName;
}
public void setSateControlValName(String sateControlValName) {
this.sateControlValName = sateControlValName;
}
public List<List<Integer>> getPreStates() {
return preStates;
}
}
This diff is collapsed.
package com.virjar.geetest.crack;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import java.util.LinkedHashSet;
import java.util.List;
/**
* Created by virjar on 2017/9/8.
*/
public class Util {
public static List<Integer> calcStateMachine(JSONObject init) {
if (!StringUtils.equalsIgnoreCase(init.getString("type"), "MemberExpression")) {
return null;
}
List<Integer> memberAccessSequence = Lists.newLinkedList();
try {
while (StringUtils.equalsIgnoreCase(init.getString("type"), "MemberExpression")) {
if (init.getJSONObject("property") == null) {
return null;
}
memberAccessSequence.add(init.getJSONObject("property").getInteger("value"));
init = init.getJSONObject("object");// 这个对象的属性访问
}
} catch (NumberFormatException e) {
return null;
}
// 必须是一个函数调用的结果的属性访问
if (!StringUtils.equalsIgnoreCase(init.getString("type"), "CallExpression")) {
return null;
}
JSONObject callee = init.getJSONObject("callee");
if (!StringUtils.equalsIgnoreCase(callee.getString("type"), "MemberExpression")) {
return null;
}
String functionName = callee.getJSONObject("property").getString("name");
if (!(StringUtils.equalsIgnoreCase(functionName, "k9r") || StringUtils.equalsIgnoreCase(functionName, "L9r"))) {
return null;
}
return Lists.reverse(memberAccessSequence);
}
public static JSONObject buildIfBlock(JSONObject testCondition, JSONArray consequent, JSONArray alternate) {
JSONObject ret = new JSONObject();
ret.put("type", "IfStatement");
ret.put("test", testCondition);
JSONObject consequentJson = new JSONObject();
consequentJson.put("type", "BlockStatement");
consequentJson.put("body", consequent);
ret.put("consequent", consequentJson);
JSONObject alternateJson = new JSONObject();
alternateJson.put("type", "BlockStatement");
alternateJson.put("body", alternate);
ret.put("alternate", alternateJson);
return ret;
}
public static JSONObject buildWhileBlock(JSONObject testCondition, JSONArray body) {
JSONObject ret = new JSONObject();
ret.put("type", "WhileStatement");
ret.put("test", testCondition);
JSONObject bodyJson = new JSONObject();
bodyJson.put("type", "BlockStatement");
bodyJson.put("body", body);
ret.put("body", bodyJson);
return ret;
}
public static JSONObject revertTestCondition(JSONObject testCondition) {
JSONObject ret = new JSONObject();
ret.put("type", "UnaryExpression");
ret.put("operator", "!");
ret.put("argument", testCondition);
return ret;
}
public static boolean isAssignStateControllStatement(JSONObject codeLine, String stateControlValName) {
return StringUtils.equalsIgnoreCase(codeLine.getString("type"), "ExpressionStatement")
&& StringUtils.equalsIgnoreCase(codeLine.getJSONObject("expression").getString("type"),
"AssignmentExpression")
&& StringUtils.equalsIgnoreCase(codeLine.getJSONObject("expression").getString("operator"), "=")
&& StringUtils.equalsIgnoreCase(
codeLine.getJSONObject("expression").getJSONObject("left").getString("name"),
stateControlValName);
}
public static <E> int indexForLinkedHashSet(LinkedHashSet<E> linkedHashSet, E entry) {
int i = 0;
for (E e : linkedHashSet) {
if (e.equals(entry)) {
return i;
}
i++;
}
return -1;
}
}
package com.virjar.geetest.crack.net;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.Header;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* 探测字符集 Created by virjar on 16/9/20.
*/
public class CharsetDetector {
/**
* 通过头部解析
*
* @param headers
* @return
*/
public static String detectHeader(Header[] headers) {
if (headers == null || headers.length == 0) {
return null;
}
for (Header header : headers) {
String s = parseContentType(header.getValue());
if (!StringUtils.isEmpty(s)) {
return s;
}
}
return null;
}
public static String detectHeader(Header header) {
if (header == null) {
return null;
}
String s = parseContentType(header.getValue());
if (!StringUtils.isEmpty(s)) {
return s;
}
return null;
}
public static String[] substringsBetween(final byte[] str, final byte[] open, final byte[] close) {
if (str == null || open == null || close == null) {
return null;
}
final int strLen = str.length;
if (strLen == 0) {
return ArrayUtils.EMPTY_STRING_ARRAY;
}
final int closeLen = close.length;
final int openLen = open.length;
final List<String> list = new ArrayList<>();
int pos = 0;
while (pos < strLen - closeLen) {
int start = indexOf(str, 0, str.length, open, 0, open.length, pos);
if (start < 0) {
break;
}
start += openLen;
final int end = indexOf(str, 0, str.length, close, 0, close.length, start);
if (end < 0) {
break;
}
// 这里就不考虑编码了
list.add(new String(Arrays.copyOfRange(str, start, end)));
pos = end + closeLen;
}
if (list.isEmpty()) {
return null;
}
return list.toArray(new String[list.size()]);
}
private static int indexOf(byte[] source, int sourceOffset, int sourceCount, byte[] target, int targetOffset,
int targetCount, int fromIndex) {
if (fromIndex >= sourceCount) {
return (targetCount == 0 ? sourceCount : -1);
}
if (fromIndex < 0) {
fromIndex = 0;
}
if (targetCount == 0) {
return fromIndex;
}
byte first = target[targetOffset];
int max = sourceOffset + (sourceCount - targetCount);
for (int i = sourceOffset + fromIndex; i <= max; i++) {
/* Look for first character. */
if (source[i] != first) {
while (++i <= max && source[i] != first)
;
}
/* Found first character, now look at the rest of v2 */
if (i <= max) {
int j = i + 1;
int end = j + targetCount - 1;
for (int k = targetOffset + 1; j < end && source[j] == target[k]; j++, k++)
;
if (j == end) {
/* Found whole string. */
return i - sourceOffset;
}
}
}
return -1;
}
/**
* 通过响应内容解析,底层支持,要求高速处理
*
* @param content
* @return
*/
public static String detectHtmlContent(final byte[] content) {
String[] metas = substringsBetween(content, "<meta".getBytes(), ">".getBytes());// #4
if (metas == null) {
return null;
}
for (String meta : metas) {
if (meta.toLowerCase().contains("Content-Type".toLowerCase())) {
String contentType = parseContentType(StringUtils.substringBetween(meta, "content=\"", "\""));
if (contentType != null) {
return contentType;
}
} else if (meta.contains("charset=\"")) {// html5 <meta charset="UTF-8" />
int i = meta.indexOf("charset=\"");//需要继续优化
String substring = meta.substring(i + 9);
int end = substring.indexOf("\"");
if (end > 0) {
return substring.substring(0, end);
}
}
}
return null;
}
private static String parseContentType(String contentType) {
if (StringUtils.isEmpty(contentType)) {
return null;
}
contentType = contentType.toLowerCase();
int charset = contentType.indexOf("charset");
if (charset < 0) {
return null;
}
contentType = contentType.substring(charset + 7).trim();
if (contentType.startsWith("=")) {
return contentType.substring(1);
}
return contentType;
}
}
package com.virjar.geetest.crack.net;
import com.google.common.collect.Lists;
import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import java.util.List;
/**
* 默认添加的请求头,具体是否需要根据方法添加,后续讨论<br/>
* 源码追踪发现可能会覆盖requestConfig里面存在的header,待确认<br/>
* Created by virjar on 16/9/28.
*/
public class HeaderUtil {
public static final List<Header> defaultHeaders = Lists.newArrayList();
static {
defaultHeaders.add(new BasicHeader("Accept",
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"));
//这个默认会添加,值为 gzip, deflate
//defaultHeaders.add(new BasicHeader("Accept-Encoding", "gzip, deflate, sdch, br"));
defaultHeaders.add(new BasicHeader("Accept-Language", "en-US,en;q=0.8"));
defaultHeaders.add(new BasicHeader("Cache-Control", "max-age=0"));
}
}
package com.virjar.geetest.crack.net;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.config.SocketConfig;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.LaxRedirectStrategy;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.nio.charset.Charset;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Map;
/**
* 以静态方式封装httpclient,方便的http请求客户端<br/>
* Created by virjar on 16/10/4.
*/
public class HttpInvoker {
private static CrawlerHttpClient crawlerHttpClient;
static {// TODO 是否考虑cookie reject
SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).setSoLinger(-1).setSoReuseAddress(false)
.setSoTimeout(ProxyConstant.SOCKETSO_TIMEOUT).setTcpNoDelay(true).build();
X509TrustManager x509mgr = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] xcs, String string) {
}
@Override
public void checkServerTrusted(X509Certificate[] xcs, String string) {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[]{x509mgr}, null);
} catch (Exception e) {
//// TODO: 16/11/23
}
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext,
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
crawlerHttpClient = CrawlerHttpClientBuilder.create().setMaxConnTotal(1000).setMaxConnPerRoute(50)
.setDefaultSocketConfig(socketConfig).setSSLSocketFactory(sslConnectionSocketFactory).setRedirectStrategy(new LaxRedirectStrategy()).build();
}
public static String postJSON(String url, Object entity, Header[] headers) {
return crawlerHttpClient.postJSON(url, entity, headers);
}
public static String get(String url) {
return crawlerHttpClient.get(url);
}
public static String get(String url, Charset charset) {
return crawlerHttpClient.get(url, charset);
}
public static String get(String url, Charset charset, Header[] headers) {
return crawlerHttpClient.get(url, charset, headers);
}
public static String get(String url, Charset charset, Header[] headers, String proxyIp, int proxyPort) {
return crawlerHttpClient.get(url, charset, headers, proxyIp, proxyPort);
}
public static String get(String url, Charset charset, String proxyIp, int proxyPort) {
return crawlerHttpClient.get(url, charset, proxyIp, proxyPort);
}
public static String get(String url, Header[] headers) {
return crawlerHttpClient.get(url, headers);
}
public static String get(String url, Header[] headers, String proxyIp, int proxyPort) {
return crawlerHttpClient.get(url, headers, proxyIp, proxyPort);
}
public static String get(String url, HttpClientContext httpClientContext) {
return crawlerHttpClient.get(url, httpClientContext);
}
public static String get(String url, List<NameValuePair> nameValuePairs, Header[] headers, String proxyIp,
int proxyPort) {
return crawlerHttpClient.get(url, nameValuePairs, headers, proxyIp, proxyPort);
}
public static String get(String url, List<NameValuePair> params) {
return crawlerHttpClient.get(url, params);
}
public static String get(String url, List<NameValuePair> params, Charset charset) {
return crawlerHttpClient.get(url, params, charset);
}
public static String get(String url, List<NameValuePair> params, Charset charset, Header[] headers) {
return crawlerHttpClient.get(url, params, charset, headers);
}
public static String get(String url, List<NameValuePair> params, Charset charset, Header[] headers, String proxyIp,
int proxyPort) {
return crawlerHttpClient.get(url, params, charset, headers, proxyIp, proxyPort);
}
public static String get(String url, List<NameValuePair> params, Charset charset, Header[] headers, String proxyIp,
int proxyPort, HttpClientContext httpClientContext) {
return crawlerHttpClient.get(url, params, charset, headers, proxyIp, proxyPort, httpClientContext);
}
public static String get(String url, List<NameValuePair> params, Charset charset, String proxyIp, int proxyPort) {
return crawlerHttpClient.get(url, params, charset, proxyIp, proxyPort);
}
public static String get(String url, List<NameValuePair> params, Header[] headers) {
return crawlerHttpClient.get(url, params, headers);
}
public static String get(String url, List<NameValuePair> params, String proxyIp, int proxyPort) {
return crawlerHttpClient.get(url, params, proxyIp, proxyPort);
}
public static String get(String url, Map<String, String> params, Charset charset, Header[] headers, String proxyIp,
int proxyPort) {
return crawlerHttpClient.get(url, params, charset, headers, proxyIp, proxyPort);
}
public static String get(String url, String proxyIp, int proxyPort) {
return crawlerHttpClient.get(url, proxyIp, proxyPort);
}
public static int getStatus(String url, String proxyIp, int proxyPort) {
return crawlerHttpClient.getStatus(url, proxyIp, proxyPort);
}
public static String post(String url, HttpEntity entity, Charset charset, Header[] headers, String proxyIp,
int proxyPort) {
return crawlerHttpClient.post(url, entity, charset, headers, proxyIp, proxyPort);
}
public static String post(String url, String entity) {
return crawlerHttpClient.post(url, entity);
}
public static String post(String url, String entity, Charset charset, Header[] headers, String proxyIp,
int proxyPort) {
return crawlerHttpClient.post(url, entity, charset, headers, proxyIp, proxyPort);
}
public static String post(String url, String entity, Header[] headers) {
return crawlerHttpClient.post(url, entity, headers);
}
public static String post(String url, List<NameValuePair> params) {
return crawlerHttpClient.post(url, params);
}
public static String post(String url, List<NameValuePair> params, Charset charset, Header[] headers, String proxyIp,
int proxyPort) {
return crawlerHttpClient.post(url, params, charset, headers, proxyIp, proxyPort);
}
public static String post(String url, List<NameValuePair> params, Header[] headers) {
return crawlerHttpClient.post(url, params, headers);
}
public static String post(String url, Map<String, String> params) {
return crawlerHttpClient.post(url, params);
}
public static String post(String url, Map<String, String> params, Charset charset, Header[] headers, String proxyIp,
int proxyPort) {
return crawlerHttpClient.post(url, params, charset, headers, proxyIp, proxyPort);
}
public static String post(String url, Map<String, String> params, Header[] headers) {
return crawlerHttpClient.post(url, params, headers);
}
public static String postJSON(String url, Object entity) {
return crawlerHttpClient.postJSON(url, entity);
}
public static String postJSON(String url, Object entity, Charset charset, Header[] headers, String proxyIp,
int proxyPort) {
return crawlerHttpClient.postJSON(url, entity, charset, headers, proxyIp, proxyPort);
}
}
package com.virjar.geetest.crack.net;
/**
* Created by virjar on 16/11/24.
*/
public class ProxyConstant {
// socket超时时间
public static final int SOCKET_TIMEOUT = 30000;
// 连接超时
public static final int CONNECT_TIMEOUT = 30000;
// 连接池分配连接超时时间,一般用处不大
public static final int REQUEST_TIMEOUT = 30000;
public static final int SOCKETSO_TIMEOUT = 15000;
}
This diff is collapsed.
# 极验滑块js代码逆向工程支持
\ No newline at end of file
#!/usr/bin/env node
'use strict';
const fs = require('fs');
require('colors');
const escodegen = require('escodegen');
//0:node; 1:cli.js ; 2:被混淆的js代码 3:输出js代码
if ([3, 4].indexOf(process.argv.length) > -1) {
let src = process.argv[2];
let dst = process.argv[3];//dst可能为空,表示输出到控制台
let code = fs.readFileSync(src).toString('utf8');;
code = JSON.parse(code);
code = escodegen.generate(code);
if (dst)//如果有输出路径,则往指定文件路径写,否则写入到控制台
fs.writeFileSync(dst, code);
else
console.log(code.green);
} else if (process.argv.length === 2) {
process.stdin.setEncoding('utf8');
process.stdin.on('readable', function() {
var chunk = process.stdin.read();
if (chunk && chunk.length) {
try {
console.log(escodegen.generate(JSON.parse(chunk)));
} catch (ex) {
if (ex.lineNumber && ex.column) {
console.log(`Error: ${ex.description} at line ${ex.lineNumber}, col ${ex.column}`.red);
}
}
}
process.stdout.write('> ');
});
}
'use strict';
var source_json = "Users/virjar/git/gt2/src/main/webapp/static/js/geetest.6.0.9_beauty_02.json";
var dst = "/Users/virjar/git/gt2/src/main/webapp/static/js/geetest.6.0.9_beauty_02.js";
let ast_json_string = fs.readFileSync(source_json).toString('utf8');
let ast = JSON.parse(ast_json_string);
let code = escodegen.generate(ast);
if (dst)//如果有输出路径,则往指定文件路径写,否则写入到控制台
fs.writeFileSync(dst, code);
else {
console.log(code)
}
\ No newline at end of file
{
"compilerOptions": {
"target": "ES6",
"module": "system"
}
}
\ No newline at end of file
'use strict';
const Constants = {
Properties: {
'string': ['length'],
'regex': ['source'],
'array': ['length']
},
Methods: {
'string': ['anchor', 'big', 'blink', 'bold', 'charAt', 'charCodeAt',
'codePointAt', 'concat', 'endsWith', 'fixed', 'fontcolor',
'fontsize', 'includes', 'indexOf', 'italics', 'lastIndexOf',
'length', 'link', 'localeCompare', 'match', 'normalize', 'repeat',
'replace', 'search', 'slice', 'small', 'split', 'startsWith',
'strike', 'sub', 'substr', 'substring', 'sup', 'toLocaleLowerCase',
'toLocaleUpperCase', 'toLowerCase', 'toString', 'toUpperCase',
'trim', 'trimLeft', 'trimRight'
],
'number': ['toString'],
'array': ['concat', 'indexOf', 'join', 'lastIndexOf', 'pop',
'push', 'reverse', 'shift', 'slice', 'unshift'
]
},
Objects: {
'String': ['apply', 'call', 'fromCharCode', 'fromCodePoint'],
'Date': ['parse', 'UTC'],
'Number': ['parseInt', 'parseFloat', 'isNaN', 'isFinite',
'isInteger', 'isSafeInteger'
],
'Math': ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2',
'atanh', 'cbrt', 'ceil', 'clz32', 'cos', 'cosh', 'exp', 'expm1',
'floor', 'fround', 'hypot', 'imul', 'log', 'log10', 'log1p',
'log2', 'max', 'min', 'pow', 'round', 'sign', 'sin', 'sinh',
'sqrt', 'tan', 'tanh', 'trunc'
],
'global': ['Infinity', 'NaN']
},
Constants: {
'Number': ['EPSILON', 'MAX_SAFE_INTEGER', 'MAX_VALUE',
'MIN_SAFE_INTEGER', 'MIN_VALUE', 'NaN', 'NEGATIVE_INFINITY',
'POSITIVE_INFINITY'
],
'Math': ['E', 'LN10', 'LN2', 'LOG10E', 'LOG2E', 'PI', 'SQRT1_2', 'SQRT2'],
},
Functions: ['isFinite', 'isNaN', 'parseFloat', 'parseInt', 'decodeURI',
'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 'escape',
'atob', 'btoa'
]
};
module.exports = Constants;
\ No newline at end of file
This diff is collapsed.
'use strict';
const esprima = require('esprima');
const Syntax = esprima.Syntax;
/**
* test if an array consists of static literals
* @param {Node} node AST node
* @return {Boolean} is static
*/
const isStatic = exports.isStatic = function(node) {
if (!node)
return false;
switch (node.type) {
case Syntax.Literal:
return true;
case Syntax.ArrayExpression:
return node.elements.every(isStatic);
case Syntax.ObjectExpression:
return node.properties.every(
property => isStatic(property.value) && [Syntax.Literal, Syntax.Identifier]
.indexOf(property.key.type) > -1);
default:
return false;
}
};
/**
* parse an expression
* @param {Node} node AST node
* @return {Any} actual value
*/
const parseStatic = exports.parseStatic = function(node) {
if (!node)
return false;
switch (node.type) {
case Syntax.Literal:
return node.value;
case Syntax.ArrayExpression:
return node.elements.map(parseStatic);
case Syntax.ObjectExpression:
let obj = {};
node.properties.forEach(property => obj[property.key.name ||
property.key.value] = parseStatic(property.value));
return obj;
default:
// Unknown expression
return null;
}
};
/**
* test if call arguments are constant
* @param {Node} node AST node
* @return {Boolean} is static
*/
exports.isStaticArguments = node =>
node.type === Syntax.CallExpression &&
node.arguments.every(isStatic);
/**
* parse arguments list to an array
* @param {Node} node AST node
* @return {Array} Actual value of arguments
*/
exports.parseArguments = node =>
node.arguments.map(parseStatic);
/**
* convert code to AST
* @param {[type]} code [description]
* @return {[type]} [description]
*/
exports.expression = code =>
esprima.parse(code).body[0].expression;
{
"name": "esprima_support",
"version": "1.1.1",
"description": "A simple deobfuscator",
"main": "index.js",
"directories": {
"test": "tests"
},
"scripts": {
"test": "make test-all"
},
"repository": {
"type": "git",
"url": "git@github.com:ChiChou/etacsufbo.git"
},
"bin": {
"deobfuscate": "cli.js"
},
"keywords": [
"obfuscate",
"beautify",
"javascript"
],
"engines": {
"node": ">4.0"
},
"author": "ChiChou <zhi.zhou@chaitin.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/ChiChou/etacsufbo/issues"
},
"homepage": "https://github.com/ChiChou/etacsufbo",
"devDependencies": {
"chai": "^3.2.0",
"coveralls": "^2.11.3",
"istanbul": "^0.4.2",
"jshint": "^2.8.0",
"mocha": "^2.2.5"
},
"dependencies": {
"colors": "^1.1.2",
"escodegen": "^1.6.1",
"esprima": "^2.4.1"
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment