blob: 703b8da2a724b1085e6e9ddbf56209cfce40b802 (
plain)
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
|
/*
winreg rpc utility functions
Copyright Andrew Tridgell 2005
released under the GNU GPL v2 or later
*/
/*
open a hive
*/
function winreg_open_hive(reg, hive)
{
var io = irpcObj();
io.input.system_name = NULL;
io.input.access_required = reg.SEC_FLAG_MAXIMUM_ALLOWED;
var status;
if (hive == "HKLM") {
status = reg.winreg_OpenHKLM(io);
} else if (hive == "HKCR") {
status = reg.winreg_OpenHKCR(io);
} else if (hive == "HKPD") {
status = reg.winreg_OpenHKPD(io);
} else if (hive == "HKU") {
status = reg.winreg_OpenHKU(io);
} else {
println("Unknown hive " + hive);
return undefined;
}
if (!status.is_ok) {
return undefined;
}
return io.output.handle;
}
/*
open a handle to a path
*/
function winreg_open_path(reg, path)
{
var s = string_init();
var i, components = s.split('\\', path);
var list = new Object();
list.length = 0;
/* cope with a leading slash */
if (components[0] == '') {
for (i=0;i<(components.length-1);i++) {
components[i] = components[i+1];
}
components.length--;
}
if (components.length == 0) {
return undefined;
}
var handle = winreg_open_hive(reg, components[0]);
if (handle == undefined) {
return undefined;
}
if (components.length == 1) {
return handle;
}
var hpath = components[1];
for (i=2;i<components.length;i++) {
hpath = hpath + "\\" + components[i];
}
io = irpcObj();
io.input.handle = handle;
io.input.keyname = hpath;
io.input.unknown = 0;
io.input.access_mask = reg.SEC_FLAG_MAXIMUM_ALLOWED;
var status = reg.winreg_OpenKey(io);
if (!status.is_ok) {
return undefined;
}
if (io.output.result != "WERR_OK") {
return undefined;
}
return io.output.handle;
}
/*
return a list of keys for a winreg server given a path
usage:
list = winreg_enum_path(reg, path);
*/
function winreg_enum_path(reg, path)
{
var list = new Object();
list.length = 0;
if (path == null || path == "\\" || path == "") {
return new Array("HKLM", "HKU");
}
handle = winreg_open_path(reg, path);
if (handle == undefined) {
return undefined;
}
var io = irpcObj();
var wtime = new Object();
wtime.low = 2147483647;
wtime.high = 2147483647;
var keyname = new Object();
keyname.unknown = 522;
keyname.key_name = NULL;
io.input.handle = handle;
io.input.key_name_len = 0;
io.input.unknown = 1044;
io.input.in_name = keyname;
io.input.class = "";
io.input.last_changed_time = wtime;
var idx = 0;
for (idx=0;idx >= 0;idx++) {
io.input.enum_index = idx;
var status = reg.winreg_EnumKey(io);
if (!status.is_ok) return;
var out = io.output;
if (out.result != "WERR_OK") {
return list;
}
list[list.length] = out.out_name.name;
list.length++;
}
return list;
}
|