-
-
Notifications
You must be signed in to change notification settings - Fork 126
/
dexcalibur.js
executable file
·155 lines (129 loc) · 4.53 KB
/
dexcalibur.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env node
const _path_ = require('path');
const Process = require("process");
const FS = require("fs");
const ArgParser = require("./src/ArgUtils.js");
var err = null;
var projectArgs = {};
var Parser = new ArgParser(projectArgs, [
/* { name:"--api",
help: "The Android API version to use. It should be one entry of platform_available config option.",
hasVal:true,
callback:(ctx,param)=>{ ctx.api = param.value; } },
{ name:"--pull",
help: "To pull the APK file of the targeted application from the device",
hasVal:false,
callback:(ctx,param)=>{ ctx.pull = 1; } },
{ name:"--devices",
help: "To list connected devices",
hasVal:false,
callback:(ctx,param)=>{ ctx.devices = 1; } },
{ name:"--app",
help: "The targeted application name (if already analyzed)",
hasVal:true,
callback:(ctx,param)=>{ ctx.app = param.value; } },
{ name:"--apk",
help: "The path to the target APK file",
hasVal:true,
callback:(ctx,param)=>{ ctx.apk = param.value; } },
{ name:"--apk-stdin",
help: "Read the APK to analyze on STDIN",
hasVal:false,
callback:(ctx,param)=>{ ctx.apkStdin = 1; } },*/
{ name:"--port",
help: "The web server port number",
hasVal:true,
callback:(ctx,param)=>{ ctx.port = param.value; } },
{ name:"--ui",
help: "Change UI location",
hasVal:true,
callback:(ctx,param)=>{ ctx.uipath = param.value; } },
/* { name:"--emu",
help: "Use emulated device",
hasVal: false,
callback: (ctx,param)=>{ ctx.useEmu = true; } },*/
{ name:"--debug",
help: "Enable debug",
hasVal: false,
callback: (ctx,param)=>{ ctx.debug = true; } },
/*{ name:"--config",
help: "The path to a custom config file. Default : ./config.js",
hasVal:true,
callback:(ctx,param)=>{ ctx.config = param.value; } },*/
{ name:["--help","-h"],
help: "This menu",
hasVal:false,
callback:(ctx,param)=>{ ctx.help = 1; } },
/*{ name:"--no-frida",
help: "To disable Frida part. It allows to run Dexcalibur to analyze purpose even if Frida is not installed",
hasVal:false,
callback:(ctx,param)=>{ ctx.nofrida = 1; } },
{ name:"--buildClass",
help: "To generate Frida script with a Java.use for each class contained into the specified package (see docs)",
hasVal:true,
callback:(ctx,param)=>{ ctx.buildClass = param.value; } },
{ name:"--buildOut",
help: "The output directory",
hasVal:true,
callback:(ctx,param)=>{ ctx.buildOut = param.value; } },
{ name:"--buildApi",
help: "To build the representation of the specified Android API",
hasVal:true,
callback:(ctx,param)=>{ ctx.buildApi = param.value; } },*/
{ name:"--reinstall",
help: "To clear Dexcalibur configuration",
hasVal:false,
callback:(ctx,param)=>{ ctx.reinstall = true; } }
]);
Parser.parse(Process.argv);
const Logger_getInstance = require("./src/Logger.js");
var Logger = null;
if(projectArgs.debug){
Logger = Logger_getInstance({
testMode: false,
debugMode: true
},true);
}else{
Logger = Logger_getInstance({
testMode: false,
debugMode: false
},true);
}
const DexcaliburEngine = require("./src/DexcaliburEngine.js");
if(projectArgs.help != null){
console.log(Parser.getHelp());
Process.exit();
}
var dxcInstance = null, ready=false;
let dxcWebRoot = null;
if(projectArgs.uipath!==undefined){
dxcWebRoot = (projectArgs.uipath[0]=='/'? projectArgs.uipath : _path_.join(__dirname, projectArgs.uipath));
}else{
dxcWebRoot = _path_.join(__dirname, 'src', 'webserver', 'public');
}
if(projectArgs.reinstall == true){
DexcaliburEngine.clearInstall();
}
if( DexcaliburEngine.requireInstall() ){
// pass
dxcInstance = DexcaliburEngine.getInstance();
dxcInstance.prepareInstall(
(projectArgs.port!=null) ? projectArgs.port : 8000,
dxcWebRoot
);
dxcInstance.start(
projectArgs.port,
projectArgs.uipath!==undefined? projectArgs.uipath : null
);
}
else{
dxcInstance = DexcaliburEngine.getInstance();
dxcInstance.loadWorkspaceFromConfig();
ready = dxcInstance.boot(
projectArgs.restore===true? true : false,
dxcWebRoot
);
if(ready){
dxcInstance.start((projectArgs.port!=null) ? projectArgs.port : 8000 );
}
}