This commit is contained in:
Namhyeon Go 2023-10-30 19:51:48 +09:00
parent 141c7709b3
commit 934009a6c0
3 changed files with 127 additions and 39 deletions

View File

@ -46,13 +46,13 @@
"tags": ["Windows 시스템", "레지스트리(Registry) 제어"]
},
{
"id": "registry_read",
"description": "레지스트리 기",
"id": "registry_write",
"description": "레지스트리 기",
"tags": ["Windows 시스템", "레지스트리(Registry) 제어"]
},
{
"id": "registry_write",
"description": "레지스트리 기",
"id": "registry_read",
"description": "레지스트리 기",
"tags": ["Windows 시스템", "레지스트리(Registry) 제어"]
},
{

View File

@ -4,52 +4,49 @@
var SHELL = require("lib/shell");
exports.VERSIONINFO = "Registry Module (registry.js) version 0.1";
exports.global = global;
exports.require = global.require;
// http://apidock.com/ruby/Win32/Registry/Constants
exports.HKCR = 0x80000000;
exports.HKCU = 0x80000001;
exports.HKLM = 0x80000002;
var HKCR = 0x80000000;
var HKCU = 0x80000001;
var HKLM = 0x80000002;
exports.STRING = 0;
exports.BINARY = 1;
exports.DWORD = 2;
exports.QWORD = 3;
var STRING = 0;
var BINARY = 1;
var DWORD = 2;
var QWORD = 3;
exports.provider = function(computer) {
function getProvider(computer) {
var computer = (typeof(computer) !== "undefined") ? computer : ".";
var reg = GetObject("winmgmts:\\\\" + computer + "\\root\\default:StdRegProv");
return reg;
}
exports.write = function(hKey, path, key, value, valType, computer) {
var reg = exports.provider(computer);
function write(hKey, path, key, value, valType, computer) {
var reg = getProvider(computer);
reg.CreateKey(hKey, path);
if (valType == exports.STRING)
if (valType == STRING)
reg.SetStringValue(hKey, path, key, value);
else if (valType == exports.DWORD)
else if (valType == DWORD)
reg.SetDWORDValue(hKey, path, key, value);
else if (valType == exports.QWORD)
else if (valType == QWORD)
reg.SetQWORDValue(hKey, path, key, value);
else if (valType == exports.BINARY)
else if (valType == BINARY)
reg.SetBinaryValue(hKey, path, key, value);
}
exports.read = function(hKey, path, key, valType, computer) {
var reg = exports.provider(computer);
function read(hKey, path, key, valType, computer) {
/*
var reg = getProvider(computer);
var methodName = "";
if (valType == exports.STRING)
if (valType == STRING)
methodName = "GetStringValue";
else if (valType == exports.DWORD)
else if (valType == DWORD)
methodName = "GetDWORDValue";
else if (valType == exports.QWORD)
else if (valType == QWORD)
methodName = "GetQWORDValue";
else if (valType == exports.BINARY)
else if (valType == BINARY)
methodName = "GetBinaryValue";
if (methodName == "")
@ -62,20 +59,46 @@ exports.read = function(hKey, path, key, valType, computer) {
inparams.sSubKeyName = path;
inparams.sValueName = key;
var outparams = reg.ExecMethod_(method.Name, inparams);
console.log(method.Name);
console.log(JSON.stringify(inparams));
var outparams = reg.ExecMethod_(method.Name, inparams);
return outparams;
*/
// using IPC to read registry value
var SHELL = require("lib/shell");
var result = '';
var hKeyStr = '';
if (hKey == HKCR)
hKeyStr = "HKCR";
else if (hKey == HKCU)
hKeyStr = "HKCU";
else if (hKey == "HKLM")
hKeyStr = "HKLM";
if (hKeyStr != '') {
result = (function(s) {
s = s.substring(s.indexOf("REG_") + 4);
s = s.substring(s.indexOf(' '));
s = s.trim();
return s;
})(splitLn(SHELL.exec("reg query " + hKeyStr + "\\" + path))[2]);
}
exports.destroy = function(hKey, path, key, computer) {
var reg = exports.provider(computer);
return result;
}
function destroy(hKey, path, key, computer) {
var reg = getProvider(computer);
var loc = (key == "") ? path : path + "\\" + key;
return reg.DeleteKey(hKey, loc);
}
/*
// DEPRECATED
exports.create = function(hiveKey, path, key, computer) {
function create(hiveKey, path, key, computer) {
console.log("Warning! Registry.create method is DEPRECATED.");
var computer = (typeof(computer) !== "undefined") ? computer : ".";
@ -115,6 +138,26 @@ exports.create = function(hiveKey, path, key, computer) {
}
*/
exports.execFile = function(FN) {
function execFile(FN) {
return SHELL.exec(["reg", "import", FN].join(' '));
};
}
exports.getProvider = getProvider;
exports.write = write;
exports.read = read;
exports.destroy = destroy;
//exports.create = create; // DEPRECATED
exports.execFile = execFile;
exports.HKCR = HKCR;
exports.HKCU = HKCU;
exports.HKLM = HKLM;
exports.STRING = STRING;
exports.BINARY = BINARY;
exports.DWORD = DWORD;
exports.QWORD = QWORD;
exports.VERSIONINFO = "Registry Module (registry.js) version 0.2.1";
exports.global = global;
exports.require = global.require;

View File

@ -8,13 +8,58 @@ var profile = JSON.parse(FILE.readFile("data/test-oss-20231030.json", FILE.CdoCh
// implement the tests
var test_implements = {
"es5_polyfills": function() {},
"registry_find_provider": function() {},
// Ref 1: https://gist.github.com/CityRay/c56e4fa874af9370cc1a367bd43095b0
"es5_polyfills": function() {
var parseIntIgnoresLeadingZeros = (function () {
return parseInt('010', 10) === 10;
}());
console.log("parseIntIgnoresLeadingZeros: " + String(parseIntIgnoresLeadingZeros) + " (Default on the built-in engine: true)");
"registry_read": function() {},
var DateISOString = (function () {
return !!(Date && Date.prototype && Date.prototype.toISOString);
}());
console.log("DateISOString: " + String(DateISOString) + " (Default on the built-in engine: false)");
"registry_write": function() {},
var result = !!(parseIntIgnoresLeadingZeros && DateISOString);
console.log(result ?
"ECMAScript 5 수준의 런타임입니다. 필수 테스트를 모두 통과하였습니다." :
"ECMAScript 5 수준의 런타임이 아닙니다. 필수 테스트 중 하나를 실패하였습니다.");
},
// Ref 1: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/regprov/stdregprov
"registry_find_provider": function() {
var REG = require("lib/registry");
console.log("레지스트리 제공자(StdRegProv) 클래스에 접근을 시도합니다.");
var provider = REG.getProvider();
console.log(typeof provider !== "undefined" ?
"레지스트리 제공자 클래스에 성공적으로 연결되었습니다." :
"레지스트리 제공자 클래스에 연결하는데 문제가 있습니다.");
},
"registry_write": function() {
var REG = require("lib/registry");
var appName = "welsonjs";
console.log("레지스트리에 쓰기를 시도합니다.");
REG.write(REG.HKCU, appName + "\\WelsonJSTest", "", "here are in", REG.STRING);
console.log("레지스트리에 쓰기를 완료하였습니다.");
},
"registry_read": function() {
var REG = require("lib/registry");
var appName = "welsonjs";
console.log("레지스트리 읽기를 시도합니다.");
var response = REG.read(REG.HKCU, appName + "\\WelsonJSTest", "", REG.STRING);
console.log("읽음: " + response);
console.log(response === "here are in" ?
"레지스트리를 정상적으로 읽었습니다." :
"레지스트리를 읽는데 문제가 있습니다.");
},
"wmi_create_object": function() {},