forked from PhoenicisOrg/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
76 lines (63 loc) · 2.29 KB
/
script.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
const Wine = include("engines.wine.engine.object");
/**
* Regedit support
* @returns {Wine} Wine object
*/
Wine.prototype.regedit = function () {
var _wine = this;
this.open = function (args) {
_wine.run("regedit", [args], this.prefixDirectory(), false, true);
return _wine;
};
this.patch = function (patchContent) {
if (typeof patchContent.getClass !== "undefined" && patchContent.getClass().getCanonicalName() == "byte[]") {
var StringClass = Java.type('java.lang.String');
patchContent = new StringClass(patchContent);
}
var tmpFile = createTempFile("reg");
writeToFile(tmpFile, patchContent);
_wine.run("regedit", [tmpFile], this.prefixDirectory(), false, true);
return _wine;
};
this.deleteKey = function (keyPath) {
_wine.run("reg", ["delete", keyPath, "/f"], this.prefixDirectory(), false, true);
return _wine;
};
this.deleteValue = function (keyPath, value) {
_wine.run("reg", ["delete", keyPath, "/v", value, "/f"], this.prefixDirectory(), false, true);
return _wine;
};
this.fetchValue = function (keyPath) {
var root = keyPath[0];
var registryFile;
switch (root) {
case "HKEY_CURRENT_USER":
registryFile = "user.reg";
break;
case "HKEY_LOCAL_MACHINE":
registryFile = "system.reg";
break;
default:
throw "Illegal registry root exception";
}
keyPath.shift();
// ensure that correct type is passed to Java
var ArrayListClass = Java.type('java.util.ArrayList');
var keyPathList = new ArrayListClass();
for (var level in keyPath) {
keyPathList.add(keyPath[level]);
}
var FileClass = Java.type('java.io.File');
var registryValue = Bean("registryParser").parseFile(new FileClass(this.prefixDirectory() + "/" + registryFile), root).getChild(keyPathList);
if (registryValue == null) {
return null;
}
if (registryValue.getText) {
return registryValue.getText();
} else {
return registryValue;
}
};
return this;
};
Wine.prototype.registry = Wine.prototype.regedit;