-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
287 lines (225 loc) · 10.7 KB
/
index.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
const { app, BrowserWindow } = require('electron');
const WebSocketServer = require('ws');
const fs = require('fs');
var { exec } = require('child_process');
var JavaScriptObfuscator = require('javascript-obfuscator');
var electronInstaller = require('electron-winstaller');
const App = () => {
const win = new BrowserWindow({
width: 1100,
height: 750,
minWidth: 600,
autoHideMenuBar: true,
icon: __dirname + '/icon.ico',
})
win.loadFile('main.html');
}
app.whenReady().then(async () => {
App();
});
app.on('closed', function() {
app = null
})
app.on('window-all-closed', () => {
if (process.platform === 'darwin') {
return false;
}
app.quit();
});
function Pourcentage(pourcentage){
return '<div class="progress"><div class="progress-bar progress-bar-striped bg-danger progress-bar-animated" role="progressbar" style="width: ' + pourcentage + '%;" aria-valuenow="' + pourcentage + '" aria-valuemin="0" aria-valuemax="' + pourcentage + '">' + pourcentage + '%</div></div>';
}
function ObfusqueFile(filename){
var obfuscationResult = JavaScriptObfuscator.obfuscate(fs.readFileSync(filename).toString().replace(/\r/gi, ""),
{
compact: true,
controlFlowFlattening: true,
controlFlowFlatteningThreshold: 1,
deadCodeInjection: true,
deadCodeInjectionThreshold: 1,
debugProtection: true,
debugProtectionInterval: 4000,
disableConsoleOutput: true,
identifierNamesGenerator: 'hexadecimal',
log: false,
numbersToExpressions: true,
renameGlobals: false,
selfDefending: true,
simplify: true,
splitStrings: true,
splitStringsChunkLength: 5,
stringArray: true,
stringArrayCallsTransform: true,
stringArrayEncoding: ['rc4'],
stringArrayIndexShift: true,
stringArrayRotate: true,
stringArrayShuffle: true,
stringArrayWrappersCount: 5,
stringArrayWrappersChainedCalls: true,
stringArrayWrappersParametersMaxCount: 5,
stringArrayWrappersType: 'function',
stringArrayThreshold: 1,
transformObjectKeys: true,
unicodeEscapeSequence: false
}
);
fs.writeFile(filename, obfuscationResult.getObfuscatedCode(), err => {
if (err) {
console.error(err);
}
// file written successfully
});
}
function getFilesizeInBytes(filename) {
var stats = fs.statSync(filename);
var fileSizeInBytes = stats.size;
return fileSizeInBytes;
}
const wss = new WebSocketServer.Server({ port: 8029 });
wss.on("connection", async ws => {
ws.on("message", async data => {
var json = JSON.parse(data);
console.log(data);
if (json.compile){
if (json.directory_app == "" || json.directory_output == "" || json.directory_icon == "" || json.directory_loading == "" || json.authors == ""){
ws.send(JSON.stringify({ result: '<p class="text-danger">Please fill all fields !</p>' }));
}else{
ws.send(JSON.stringify({ result: Pourcentage(10) }));
var packageJson = require(json.directory_app + '/package.json');
console.log(packageJson);
console.log(packageJson.main);
var StreamMainFile = fs.createWriteStream(json.directory_app + '/' + packageJson.main, {
flags: 'a'
});
if (!fs.readFileSync(json.directory_app + '/' + packageJson.main).toString().replace(/\r/gi, "").includes(fs.readFileSync("./squirrel.js").toString().replace(/\r/gi, ""))){
StreamMainFile.write(fs.readFileSync("./squirrel.js").toString().replace(/\r/gi, ""));
console.log("squirrel.js added");
}
setTimeout(() => {
ws.send(JSON.stringify({ result: Pourcentage(25) }));
exec(`npx electron-packager ${json.directory_app} --platform=win32 --arch=x64 --icon=${json.directory_app}/icon.ico`, (error, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
CreateSetup();
});
}, 10 * 1000);
function CreateSetup(){
if (json.check_obfuscate === true){
fs.readdir(packageJson.name + "-win32-x64/resources/app", (err, files) => {
files.forEach(file => {
if (file.includes(".js") && !file.includes(".json")){
if (getFilesizeInBytes("./" + packageJson.name + "-win32-x64/resources/app/" + file) > 50000) return false;
console.log("OBFUSCATE => " + file);
ws.send(JSON.stringify({ result: '<p class="text-danger">Obfuscate => ' + file + '</p>' }));
ObfusqueFile(packageJson.name + "-win32-x64/resources/app/" + file);
}
if (!file.includes(".")){
if (file === "node_modules") return false;
fs.readdir(packageJson.name + "-win32-x64/resources/app/" + file, (err, files) => {
files.forEach(file2 => {
if (file2.includes(".js") && !file2.includes(".json")){
if (getFilesizeInBytes("./" + packageJson.name + "-win32-x64/resources/app/" + file + "/" + file2) > 50000) return false;
console.log("OBFUSCATE => " + file2);
ws.send(JSON.stringify({ result: '<p class="text-danger">Obfuscate => ' + file2 + '</p>' }));
ObfusqueFile(packageJson.name + "-win32-x64/resources/app/" + file + "/" + file2);
}
});
});
}
});
});
ws.send(JSON.stringify({ result: '<p class="text-danger">Long Step Please Wait !</p>' }));
setTimeout(function() { ws.send(JSON.stringify({ result: Pourcentage(50) })); }, 3 * 1000);
}
ws.send(JSON.stringify({ result: '<p class="text-danger">Long Step Please Wait !</p>' }));
setTimeout(function() { ws.send(JSON.stringify({ result: Pourcentage(50) })); }, 3 * 1000);
var settings = {
appDirectory: './' + packageJson.name + "-win32-x64",
outputDirectory: json.directory_output,
authors: json.authors,
exe: './' + packageJson.name + '.exe',
loadingGif: json.directory_loading,
};
resultPromise = electronInstaller.createWindowsInstaller(settings);
resultPromise.then(() => {
ws.send(JSON.stringify({ result: Pourcentage(75) }));
try {
fs.rmSync('./' + packageJson.name + "-win32-x64", { recursive: true });
} catch (error) {
ws.send(JSON.stringify({ result: Pourcentage(100) }));
}
ws.send(JSON.stringify({ result: Pourcentage(100) }));
console.log("The installers of your application were succesfully created !");
}, (e) => {
console.log(`Well, sometimes you are not so lucky: ${e.message}`);
ws.send(JSON.stringify({ result: '<p class="text-danger">Error Restart App !</p>' }));
});
}
}
}
ws.on("close", () => {
console.log("[WS] Close");
});
// handling client connection error
ws.onerror = function () {
console.log("Some Error occurred")
}
});
});
console.log("The WebSocket server is running on port 8080");
/*===========
Squirrel Module
=============*/
if (handleSquirrelEvent(app)) {
// squirrel event handled and app will exit in 1000ms, so don't do anything else
return;
}
function handleSquirrelEvent(application) {
if (process.argv.length === 1) {
return false;
}
const ChildProcess = require('child_process');
const path = require('path');
const appFolder = path.resolve(process.execPath, '..');
const rootAtomFolder = path.resolve(appFolder, '..');
const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe'));
const exeName = path.basename(process.execPath);
const spawn = function(command, args) {
let spawnedProcess, error;
try {
spawnedProcess = ChildProcess.spawn(command, args, {
detached: true
});
} catch (error) {}
return spawnedProcess;
};
const spawnUpdate = function(args) {
return spawn(updateDotExe, args);
};
const squirrelEvent = process.argv[1];
switch (squirrelEvent) {
case '--squirrel-install':
case '--squirrel-updated':
// Optionally do things such as:
// - Add your .exe to the PATH
// - Write to the registry for things like file associations and
// explorer context menus
// Install desktop and start menu shortcuts
spawnUpdate(['--createShortcut', exeName]);
setTimeout(application.quit, 1000);
return true;
case '--squirrel-uninstall':
// Undo anything you did in the --squirrel-install and
// --squirrel-updated handlers
// Remove desktop and start menu shortcuts
spawnUpdate(['--removeShortcut', exeName]);
setTimeout(application.quit, 1000);
return true;
case '--squirrel-obsolete':
// This is called on the outgoing version of your app before
// we update to the new version - it's the opposite of
// --squirrel-updated
application.quit();
return true;
}
};