Update testloader.js and more

This commit is contained in:
Namhyeon Go 2023-10-31 05:41:52 +09:00
parent f393a99dc5
commit 0efc455cf9
8 changed files with 332 additions and 222 deletions

View File

@ -0,0 +1 @@
Write-Output "hello world"

View File

@ -1,32 +1,32 @@
// a mafia style PIPE IPC based file I/O test var PipeIPC = require("lib/pipe-ipc");
var RAND = require("lib/rand");
var FILE = require("lib/file"); var texts = [
var filename = "data\\dead_targets.txt"; "Think like a man of action and act like man of thought.",
"Courage is very important. Like a muscle, it is strengthened by use.",
function recordDead(name) { "Life is the art of drawing sufficient conclusions from insufficient premises.",
FILE.rotateFile(filename, name + "\r\n", 1000, FILE.CdoCharset.CdoUTF_8); "By doubting we come at the truth.",
} "A man that hath no virtue in himself, ever envieth virtue in others.",
"When money speaks, the truth keeps silent."
function checkIsDead(name) { ];
var text = FILE.readFile(filename, FILE.CdoCharset.CdoUTF_8);
var deadNames = splitLn(text);
return deadNames.indexOf(name) > -1;
}
function main(args) { function main(args) {
while (true) { var pipe = PipeIPC.create("helloworld");
recordDead("kim@example.org"); var sender = RAND.uuidv4();
//recordDead("lee@example.org");
recordDead("park@example.org");
//recordDead("choi@example.org");
recordDead("hong@example.org");
console.log(checkIsDead("kim@example.org") ? "DEAD" : "ALIVE"); while (true) {
console.log(checkIsDead("lee@example.org") ? "DEAD" : "ALIVE"); var text_out = RAND.one(texts);
console.log(checkIsDead("park@example.org") ? "DEAD" : "ALIVE"); pipe.write("<" + sender + "> " + text_out);
console.log(checkIsDead("choi@example.org") ? "DEAD" : "ALIVE"); console.log("Sent: " + text_out);
console.log(checkIsDead("hong@example.org") ? "DEAD" : "ALIVE");
var text_in = pipe.read();
while (text_in == ("<" + sender + "> " + text_out) || text_in == "") {
sleep(1);
text_in = pipe.read();
} }
console.log("Recieved: " + text_in);
} }
};
exports.main = main; exports.main = main;

33
examples/rotate_file.js Normal file
View File

@ -0,0 +1,33 @@
// a mafia style PIPE IPC based file I/O test
var FILE = require("lib/file");
var filename = "data\\dead_targets.txt";
function recordDead(name) {
FILE.rotateFile(filename, name + "\r\n", 1000, FILE.CdoCharset.CdoUTF_8);
}
function checkIsDead(name) {
var text = FILE.readFile(filename, FILE.CdoCharset.CdoUTF_8);
var deadNames = splitLn(text);
return deadNames.indexOf(name) > -1;
}
function main(args) {
while (true) {
recordDead("kim@example.org");
//recordDead("lee@example.org");
recordDead("park@example.org");
//recordDead("choi@example.org");
recordDead("hong@example.org");
console.log(checkIsDead("kim@example.org") ? "DEAD" : "ALIVE");
console.log(checkIsDead("lee@example.org") ? "DEAD" : "ALIVE");
console.log(checkIsDead("park@example.org") ? "DEAD" : "ALIVE");
console.log(checkIsDead("choi@example.org") ? "DEAD" : "ALIVE");
console.log(checkIsDead("hong@example.org") ? "DEAD" : "ALIVE");
}
}
exports.main = main;

View File

@ -1,29 +0,0 @@
var ExtraMath = require("lib/extramath");
function main(args) {
var a = "this is an apple";
var b = "this is red apple";
var dtm = new ExtraMath.DTM();
dtm.add(a);
dtm.add(b);
var mat = dtm.toArray();
console.log("This is a Cosine similarity calculator");
console.log("Original sentance");
console.log(a);
console.log(b);
console.log("Done");
console.log("Create a DTM(Document-Term Matrix)");
console.log(mat[0].join(' '));
console.log(mat[1].join(' '));
console.log("Done");
console.log("Measure Cosine Similarity");
console.log('' + ExtraMath.arrayCos(mat[0], mat[1]));
console.log('' + ExtraMath.measureSimilarity(a, b));
console.log("Done");
}
exports.main = main;

View File

@ -1187,6 +1187,14 @@ var ChromeObject = function(interfaces) {
return parseInt(this.getEvaluatedValue('__getWindow().innerHeight')); return parseInt(this.getEvaluatedValue('__getWindow().innerHeight'));
}; };
this.getWindowPageYOffset = function() {
return this.getEvaluatedValue('__getWindow().pageYOffset');
};
this.getDocumentBodyOffsetHeight = function() {
return this.getEvaluatedValue('__getDocument().body.offsetHeight');
};
this.getDocumentScrollTop = function() { this.getDocumentScrollTop = function() {
return parseInt(this.getEvaluatedValue('__getDocument().documentElement.scrollTop')); return parseInt(this.getEvaluatedValue('__getDocument().documentElement.scrollTop'));
}; };
@ -1196,6 +1204,10 @@ var ChromeObject = function(interfaces) {
return (elementPosition.y > 0 && (elementPosition.y + elementPosition.h < this.getWindowInnerHeight())); return (elementPosition.y > 0 && (elementPosition.y + elementPosition.h < this.getWindowInnerHeight()));
}; };
this.isPageScrollEnded = function() {
return (this.getWindowInnerHeight() + this.getWindowPageYOffset()) >= this.getDocumentBodyOffsetHeight;
};
this.__escape = function(value) { this.__escape = function(value) {
var pos = value.indexOf("__escaped:"); var pos = value.indexOf("__escaped:");
if (pos === 0) if (pos === 0)

View File

@ -43,7 +43,7 @@ var PowershellObject = function() {
// http:// // http://
// https:// // https://
// data:text/plain;base64,SGVsbG8sIFdvcmxkIQ== // data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==
this.loadUri = function(uri) { this.loadURI = function(uri) {
var pos = uri.indexOf(':'); var pos = uri.indexOf(':');
var scheme = (pos < 0 ? '' : url.substring(0, pos)); var scheme = (pos < 0 ? '' : url.substring(0, pos));
var target = (pos < 0 ? uri : url.substring(pos + 1)); var target = (pos < 0 ? uri : url.substring(pos + 1));
@ -125,24 +125,27 @@ var PowershellObject = function() {
}; };
} }
function create() {
return new PowershellObject();
}
function execScript(scriptName, args) { function execScript(scriptName, args) {
return (new PowershellObject()).loadFile(scriptName).exec(args); return create().loadFile(scriptName).exec(args);
}; }
function execCommand(cmd) { function execCommand(cmd) {
return (new PowershellObject()).loadCommand(cmd).exec(); return create().loadCommand(cmd).exec();
}; }
function runAs(cmd) { function runAs(cmd) {
return (new PowershellObject()).setExecType("cmd").runAs(); return create().setExecType("cmd").runAs();
}; }
exports.execScript = execScript; exports.execScript = execScript;
exports.execCommand = execCommand; exports.execCommand = execCommand;
exports.runAs = runAs; exports.runAs = runAs;
exports.VERSIONINFO = "Powershell Interface (powershell.js) version 0.1.2"; exports.VERSIONINFO = "Powershell Interface (powershell.js) version 0.1.3";
exports.AUTHOR = "abuse@catswords.net"; exports.AUTHOR = "abuse@catswords.net";
exports.global = global; exports.global = global;
exports.require = global.require; exports.require = global.require;

View File

@ -1,19 +0,0 @@
(function() {
return {
setUp: function() {
inform('Starting...');
},
tearDown: function() {
inform('Finishing...')
},
testGreenTest: function () {
assert("this is true", true);
},
testRedTest: function () {
assert("this is false", false);
}
};
})();

View File

@ -181,23 +181,36 @@ var test_implements = {
}, },
"powershell_set_command": function() { "powershell_set_command": function() {
var PS = require("lib/powershell");
var PSInstance = PS.create();
PSInstance.load("Write-Output \"hello world\"");
console.log("설정된 명령어: " + PSInstance.target);
}, },
"powershell_set_file": function() { "powershell_set_file": function() {
var PS = require("lib/powershell");
var PSInstance = PS.create();
PSInstance.loadFile("app\\assets\\ps1\\helloworld");
console.log("설정된 파일: " + PSInstance.target);
}, },
"powershell_set_uri": function() { "powershell_set_uri": function() {
var PS = require("lib/powershell");
var PSInstance = PS.create();
PSInstance.loadURI("data:text/plain;base64,V3JpdGUtT3V0cHV0ICJoZWxsbyB3b3JsZCI=");
console.log("설정된 URI: " + PSInstance.target);
}, },
"powershell_execute": function() { "powershell_execute": function() {
var PS = require("lib/powershell");
var response = PS.execScript("app\\assets\\ps1\\helloworld");
console.log("실행 결과 값: " + response);
}, },
"powershell_run_as": function() { "powershell_run_as": function() {
var PS = require("lib/powershell");
var response = PS.runAs("app\\assets\\ps1\\helloworld");
console.log("실행 결과 값: " + response);
}, },
"system_resolve_env": function() { "system_resolve_env": function() {
@ -276,38 +289,49 @@ var test_implements = {
}, },
"system_pipe_ipc": function() { "system_pipe_ipc": function() {
var SHELL = require("lib/shell");
for (var i = 0; i < 3; i++) {
SHELL.show(["cscript", "app.js", "examples/ipctest"]);
}
}, },
"vhid_find_window": function() { "vhid_find_window": function() {
var SHELL = require("lib/shell"); console.log("동일한 기능이 포함된 chromium_send_click 또는 chromium_send_keys 테스트를 수행하십시오");
var Toolkit = require("lib/toolkit");
// 메모장 열기
SHELL.run(["notepad"]);
// 3초 대기
sleep(5000);
// 키 보내기
Toolkit.sendKeys("제목 없음 - Windows 메모장", "dasdasdasdasasdasdasd");
console.log("키를 보냈습니다.");
}, },
"vhid_send_click": function() { "vhid_send_click": function() {
console.log("동일한 기능이 포함된 chromium_send_click 테스트를 수행하십시오");
}, },
"vhid_send_keys": function() { "vhid_send_keys": function() {
console.log("동일한 기능이 포함된 chromium_send_keys 테스트를 수행하십시오");
}, },
"vhid_send_key_enter": function() { "vhid_send_key_enter": function() {
var Chrome = require("lib/chrome");
var wbInstance = Chrome.startDebugInPrivate("https://en.key-test.ru/", null, "welsonjs_test", 9222, true);
console.log("참고: vhid_send_key_enter 테스트의 엔터 키 기능은 웹 브라우저가 키코드를 처리하도록 작성되었습니다.");
console.log("5초 후 명령을 수행합니다.");
sleep(5000);
wbInstance.focus();
wbInstance.sendEnterKey();
sleep(1000);
}, },
"vhid_send_key_functions": function() { "vhid_send_key_functions": function() {
var Toolkit = require("lib/toolkit");
var Chrome = require("lib/chrome");
var wbInstance = Chrome.startDebugInPrivate("https://example.org", null, "welsonjs_test", 9222, true);
console.log("웹 브라우저를 열고 F1 키를 눌러 도움말 페이지를 열겠습니다.");
console.log("5초 후 명령을 수행합니다.");
sleep(5000);
wbInstance.focus();
Toolkit.sendFnKey(wbInstance.pageId.substring(0, 6), 1); // F1 키 누름
}, },
"vhid_alert": function() { "vhid_alert": function() {
@ -331,27 +355,52 @@ var test_implements = {
}, },
"network_http_get": function() { "network_http_get": function() {
var HTTP = require("lib/http");
console.log("HTTP GET 요청으로 내 외부 IP를 확인합니다.");
var response = HTTP.get("https://api.ipify.org/", {}, {});
console.log("내 외부 IP: " + response);
}, },
"network_http_post": function() { "network_http_post": function() {
var HTTP = require("lib/http");
var response = HTTP.get("https://httpbin.org/post", {}, {});
console.log("응답: " + response);
}, },
"network_http_extended": function() { "network_http_extended": function() {
var HTTP = require("lib/http");
var response1 = HTTP.put("https://httpbin.org/put", {}, {});
console.log("응답: " + response1);
var response2 = HTTP.put("https://httpbin.org/patch", {}, {});
console.log("응답: " + response2);
}, },
"network_attach_debugger": function() { "network_attach_debugger": function() {
var HTTP = require("lib/http");
HTTP.create("CURL")
.attachDebugger("FIDDLER")
.get("https://api.ipify.org/");
}, },
"network_detect_charset": function() { "network_detect_charset": function() {
var HTTP = require("lib/http");
var response = HTTP.get("https://example.org/", {}, {});
var charset = HTTP.create("CURL").detectCharset(response);
console.log("감지된 문자셋: " + charset);
}, },
"network_detect_http_ssl": function() { "network_detect_http_ssl": function() {
var HTTP = require("lib/http");
var response = HTTP.create("CURL").get("https://example.org/");
var charset = HTTP.create("CURL").detectCharset(response);
}, },
"network_send_icmp": function() { "network_send_icmp": function() {
@ -439,7 +488,9 @@ var test_implements = {
}, },
"chromium_create_profile": function() { "chromium_create_profile": function() {
var Chrome = require("lib/chrome");
console.log("welsonjs_test 프로파일을 생성합니다. (웹 브라우저를 실행하여 생성합니다.)");
Chrome.startDebug("https://example.org", null, "welsonjs_test", 9222, true);
}, },
"chromium_run_incognito": function() { "chromium_run_incognito": function() {
@ -519,7 +570,16 @@ var test_implements = {
wbInstance.focus(); wbInstance.focus();
}, },
"chromium_adjust_window_size": function() {}, "chromium_adjust_window_size": function() {
var Chrome = require("lib/chrome");
var wbInstance = Chrome.startDebugInPrivate("https://example.org", null, "welsonjs_test", 9222, true);
console.log("5초 후 명령을 수행합니다.");
sleep(5000);
wbInstance.focus();
wbInstance.autoAdjustByWindow(10, 10, 1024, 1280, 720, 768);
},
"chromium_get_element_position": function() { "chromium_get_element_position": function() {
var Chrome = require("lib/chrome"); var Chrome = require("lib/chrome");
@ -543,19 +603,68 @@ var test_implements = {
}, },
"chromium_set_value_to_textbox": function() { "chromium_set_value_to_textbox": function() {
var Chrome = require("lib/chrome");
var wbInstance = Chrome.startDebugInPrivate("https://html5doctor.com/demos/forms/forms-example.html", null, "welsonjs_test", 9222, true);
console.log("5초 후 명령을 수행합니다.");
sleep(5000);
wbInstance.setValue("#given-name", "길동");
wbInstance.setValue("#family-name", "홍");
}, },
"chromium_send_click": function() { "chromium_send_click": function() {
var RAND = require("lib/rand");
var Chrome = require("lib/chrome");
var wbInstance = Chrome.startDebugInPrivate("https://html5doctor.com/demos/forms/forms-example.html", null, "welsonjs_test", 9222, true);
console.log("5초 후 명령을 수행합니다.");
sleep(5000);
wbInstance.focus();
wbInstance.traceMouseClick();
while (true) {
wbInstance.vMouseClick(RAND.getInt(20, 200), RAND.getInt(20, 200));
sleep(2000);
}
}, },
"chromium_send_keys": function() { "chromium_send_keys": function() {
var Chrome = require("lib/chrome");
var wbInstance = Chrome.startDebugInPrivate("https://html5doctor.com/demos/forms/forms-example.html", null, "welsonjs_test", 9222, true);
console.log("5초 후 명령을 수행합니다.");
sleep(5000);
wbInstance.focus();
wbInstance.traceMouseClick();
console.log("이메일 필드 위치 찾기");
var emailInputPosition = wbInstance.getElementPosition("#email");
wbInstance.vMouseClick(emailInputPosition.x + 2, emailInputPosition.y + 2);
sleep(1000);
console.log("가상 키 보내기");
wbInstance.vSendKeys("hong@example.org");
}, },
"chromium_auto_scroll_until_end": function() { "chromium_auto_scroll_until_end": function() {
var Chrome = require("lib/chrome");
var wbInstance = Chrome.startDebugInPrivate("https://en.wikipedia.org/wiki/Lorem_ipsum", null, "welsonjs_test", 9222, true);
console.log("5초 후 명령을 수행합니다.");
sleep(5000);
wbInstance.focus();
wbInstance.traceMouseClick();
console.log("스크롤이 끝날 때까지 계속 스크롤을 조정합니다.");
while(!wbInstance.isPageScrollEnded()) {
wbInstance.scrollBy(0, 150);
sleep(2000);
}
}, },
"grpc_run_server": function() { "grpc_run_server": function() {