This commit is contained in:
Namhyeon Go 2020-11-20 17:44:50 +09:00
parent b82e1006b4
commit 43b7562b8d
6 changed files with 123 additions and 56 deletions

View File

@ -6,10 +6,12 @@ var SYS = require("lib/system");
var FILE = require("lib/file");
var ChromeObject = function() {
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\:profileName\\Application";
this.binPath = this.workingDirectory + "\\chrome.exe";
this.workingDirectory = SYS.getEnvString("PROGRAMFILES") + "\\Google\\Chrome\\Application";
this.binPath = SYS.getEnvString("PROGRAMFILES") + "\\Google\\:installedDir\\Application\\chrome.exe";
this.processID = 0;
this.installedDir = "Chrome";
this.profileName = "Default";
this.userDataDir = null;
this.proxyPort = 1080;
this.processList = [];
@ -18,10 +20,21 @@ var ChromeObject = function() {
return this;
};
this.setProfileName = function(profileName) {
this.setProfile = function(profileName, installedDir) {
this.profileName = (profileName == "Default" ? "Chrome" : profileName);
this.workingDirectory = this.workingDirectory.replace(":profileName", this.profileName);
this.binPath = this.binPath.replace(":profileName", this.profileName);
this.installedDir = installedDir;
//this.workingDirectory = this.workingDirectory.replace(":installedDir", this.installedDir);
this.binPath = this.binPath.replace(":installedDir", this.installedDir);
return this;
};
this.setUserDataDir = function(dirname) {
this.userDataDir = dirname;
return this;
};
this.setInstalledDir = function(dirname) {
this.installedDir = dirname;
return this;
};
@ -34,14 +47,31 @@ var ChromeObject = function() {
return this.processList;
};
this.createShoutcut = function(url) {
if (!this.userDataDir) {
this.userDataDir = SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName;
}
SHELL.createDesktopIcon("Chrome Prototype (" + this.installedDir + ")", [
"cscript",
"app.js",
"shoutcut",
"chrome",
this.installedDir,
"--profile-directory=\"" + this.profileName + "\"",
"--user-data-dir=\"" + this.userDataDir + "\"",
url
].join(' '), SYS.getCurrentScriptDirectory());
};
this.open = function(url) {
this.setProfileName(this.profileName);
this.setProfile(this.profileName, this.installedDir);
// 파일이 없는 경우, 32비트 설치 폴더에 위치하는지 한번 더 확인
if (!FILE.fileExists(this.binPath)) {
this.workingDirectory = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Google\\:profileName\\Application";
this.binPath = this.workingDirectory + "\\chrome.exe";
this.setProfileName(this.profileName);
this.workingDirectory = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Google\\Chrome\\Application";
this.binPath = SYS.getEnvString("PROGRAMFILES(X86)") + "\\Google\\:installedDir\\Application\\chrome.exe";
this.setProfile(this.profileName, this.installedDir);
}
// 파일 찾기
@ -51,39 +81,22 @@ var ChromeObject = function() {
}
// 바로가기 생성
SHELL.createDesktopIcon("Chrome (" + this.profileName + ")", [
"cscript",
"app.js",
"shoutcut",
"chrome",
this.profileName
], SYS.getCurrentScriptDirectory());
this.createShoutcut();
/*
var process;
while (this.processID == 0) {
try {
/*
process = SB.start(this.profileName, [
this.binPath,
"--profile-directory=" + this.profileName,
"--proxy-server=socks5://127.0.0.1:" + this.proxyPort,
url
]);
*/
/*
process = SHELL.createProcess([
this.binPath,
"--profile-directory=" + this.profileName,
"--proxy-server=socks5://127.0.0.1:" + this.proxyPort,
url
], this.workingDirectory);
*/
if (!this.userDataDir) {
this.userDataDir = SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName;
}
var shell = SHELL.create().setWorkingDirectory(this.workingDirectory);
var process = shell.createProcess([
"\"" + this.binPath + "\"",
"--profile-directory=\"" + this.profileName + "\"",
"--proxy-server=\"socks5://127.0.0.1:" + this.proxyPort + "\"",
"--user-data-dir=\"" + SYS.getCurrentScriptDirectory() + "\\UserData_Chrome_" + this.profileName + "\"",
"--user-data-dir=\"" + this.userDataDir + "\"",
"\"" + url + "\""
].join(" "));
sleep(1000);
@ -95,15 +108,46 @@ var ChromeObject = function() {
sleep(1000);
}
}
*/
try {
if (!this.userDataDir) {
this.userDataDir = SHELL.getPathOfMyDocuments() + "\\UserData_Chrome_" + this.profileName;
}
var shell = SHELL.create().setWorkingDirectory(this.workingDirectory);
shell.runAs(this.binPath, [
"--profile-directory=\"" + this.profileName + "\"",
"--proxy-server=\"socks5://127.0.0.1:" + this.proxyPort + "\"",
"--user-data-dir=\"" + this.userDataDir + "\"",
"\"" + url + "\""
]);
sleep(3000);
shell.release();
} catch (e) {
console.error("ChromeObject.open() -> " + e.message);
sleep(1000);
}
return this;
};
};
exports.create = function() {
return new ChromeObject();
};
exports.getProcessIDs = function() {
return (new ChromeObject()).getProcessIDs();
};
exports.start = function(url, proxyPort, profileName) {
return (new ChromeObject()).setProxyPort(proxyPort).setProfileName(profileName).open(url).processID;
exports.start = function(url, proxyPort, profileName, userDataDir, installedDir) {
return (new ChromeObject())
.setProxyPort(proxyPort)
.setProfile(profileName, installedDir)
.setUserDataDir(userDataDir)
.setInstalledDir(installedDir)
.open(url)
.processID
;
};

View File

@ -55,7 +55,7 @@ var FileObject = function() {
this.open = function(filename) {
this.filename = filename;
if (!this.exists()) {
console.warn("FileObject.open() -> The file does not exists.");
console.warn("FileObject.open() -> The file does not exists: " + this.filename);
}
return this;
};

View File

@ -101,8 +101,12 @@ var ShellObject = function() {
this.runAs = function(FN, args) {
var oShell = CreateObject("Shell.Application");
var _args = null;
console.info("ShellObject.runAs() -> " + FN);
oShell.shellExecute(FN, args, this.workingDirectory, "runas", (!this.isVisibleWindow ? 0 : 1));
if (typeof(args) !== "undefined") {
_args = args.join(' ');
}
oShell.shellExecute(FN, _args, this.workingDirectory, "runas", (!this.isVisibleWindow ? 0 : 1));
return oShell;
};
@ -114,7 +118,7 @@ var ShellObject = function() {
var link = this.interface.CreateShortcut(path);
link.TargetPath = "cmd";
link.Arguments = "/q /c " + this.build(cmd);
link.WindowStyle = 3;
link.WindowStyle = 7;
link.WorkingDirectory = workingDirectory;
//link.Hotkey = "";
//link.IconLocation = "";
@ -122,6 +126,10 @@ var ShellObject = function() {
}
};
this.getPathOfMyDocuments = function() {
return this.interface.SpecialFolders("MyDocuments");
};
this.release = function() {
console.info("ShellObject.release() -> " + this.currentDirectory);
this.interface.CurrentDirectory = this.currentDirectory;
@ -166,6 +174,10 @@ exports.createDesktopIcon = function(name, cmd, workingDirectory) {
return (new ShellObject()).createDesktopIcon(name, cmd, workingDirectory);
};
exports.getPathOfMyDocuments = function() {
return (new ShellObject()).getPathOfMyDocuments();
};
exports.VERSIONINFO = "Shell interface (shell.js) version 0.2";
exports.global = global;
exports.require = global.require;

View File

@ -143,7 +143,7 @@ exports.createShortcut = function(shoutcutName, fileName) {
var link = WSH.CreateShortcut(desktopPath + "\\" + shoutcutName + ".lnk");
link.IconLocation = fileName + ",1";
link.TargetPath = workingDirectory + "\\" + fileName;
link.WindowStyle = 3;
link.WindowStyle = 1;
link.WorkingDirectory = workingDirectory;
link.Save();
};

View File

@ -135,27 +135,19 @@ var check_NoxPlayer = function() {
// App 3. Chrome
var check_Chrome = function() {
var ssPort, ssPID;
for (var uniqueId in Apps.Chrome) {
if (AppsMutex.indexOf("chrome_" + uniqueId) < 0) {
console.info("Starting Google Chrome: " + uniqueId);
console.info("Creating Chrome Shoutcut: " + uniqueId);
var ss = SS.connect(Apps.Chrome[uniqueId]);
ssPort = ss.listenPort;
ssPID = ss.processID;
console.info("Wait 10 seconds...")
sleep(10000);
Chrome.start("https://whatismyipaddress.com/", ssPort, uniqueId);
AppsPID.push([ssPID]);
// 바탕화면에 바로가기만 생성
Chrome.create().setProfile(uniqueId, uniqueId).createShoutcut("https://google.com");
AppsMutex.push("chrome_" + uniqueId);
}
}
};
// Check dead processes
/*
var check_Exits = function() {
var alivePIDList = SYS.getProcessList().reduce(function(acc, process) {
acc.push(process.ProcessID);
@ -176,6 +168,7 @@ var check_Exits = function() {
});
});
};
*/
var main = function() {
console.info("Waiting new launched");

View File

@ -1,6 +1,8 @@
var SS = require("lib/shadowsocks");
var XML = require("lib/xml");
var Chrome = require("lib/chrome");
var SHELL = require("lib/shell");
var SYS = require("lib/system");
var Apps = {
LDPlayer: {},
@ -24,7 +26,23 @@ for (var i = 0; i < items.length; i++) {
} catch (e) {}
}
var do_Chrome = function(_uniqueId) {
var do_Chrome = function(args) {
var _uniqueId = args[1];
var _args = {};
var _url = "https://google.com";
for (var i = 0; i < args.length; i++) {
var pos = args[i].indexOf('=');
if (pos > -1) {
if (args[i].indexOf("--") == 0) {
_args[args[i].substring(2, pos)] = args[i].substring(pos + 1);
} else {
_args[args[i].substring(0, pos)] = args[i].substring(pos + 1);
}
} else if (args[i] != "chrome") {
_url = args[i];
}
}
var ssPort, ssPID;
for (var uniqueId in Apps.Chrome) {
if (_uniqueId == uniqueId && AppsMutex.indexOf("chrome_" + uniqueId) < 0) {
@ -34,10 +52,10 @@ var do_Chrome = function(_uniqueId) {
ssPort = ss.listenPort;
ssPID = ss.processID;
console.info("Wait 10 seconds...")
sleep(10000);
console.info("Wait 3 seconds...")
sleep(3000);
Chrome.start("https://whatismyipaddress.com/", ssPort, uniqueId);
Chrome.start(_url, ssPort, _args['profile-directory'], _args['user-data-dir'], _uniqueId);
AppsPID.push([ssPID]);
AppsMutex.push("chrome_" + uniqueId);
@ -55,7 +73,7 @@ exports.main = function(args) {
sleep(1000);
switch (args[0]) {
case "chrome":
return do_Chrome(args[1]);
return do_Chrome(args);
}
}
};