Skip to content

Commit 1d5a9a1

Browse files
committed
Set up -W API method mocks
Now store saved registry strings as copies of the buffer passed, not as strings.
1 parent 5f88a5d commit 1d5a9a1

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

test/mock/adv_api.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ var advApi = {
4545
_Inout_opt_ LPDWORD lpcbData
4646
);
4747
*/
48-
RegQueryValueExA: function (hKey, valueName, shouldBeNull, lpType, lpData, lpcbData) {
49-
debug('RegQueryValueExA');
48+
RegQueryValueExW: function (hKey, valueName, shouldBeNull, lpType, lpData, lpcbData) {
49+
debug('RegQueryValueExW');
5050
if (lpData === null) {
5151
debug(keys[hKey.address()].values.test_value_name);
5252
lpType.writeUInt32LE(windef.REG_VALUE_TYPE.REG_SZ, 0);
5353
lpcbData.writeUInt32LE(keys[hKey.address()].values[valueName].length, 0);
5454
return 0;
5555
}
5656

57-
lpData.write(keys[hKey.address()].values[valueName].value, 'utf8');
57+
keys[hKey.address()].values[valueName].valueBuffer.copy(lpData);
5858
lpType.writeUInt16LE(windef.REG_VALUE_TYPE.REG_SZ);
5959
return 0;
6060
},
@@ -67,9 +67,9 @@ var advApi = {
6767
_Out_ PHKEY phkResult
6868
);
6969
*/
70-
RegOpenKeyExA: function (hKey, subKeyName, shouldBeZero, accessLevel, pHkey) {
70+
RegOpenKeyExW: function (hKey, subKeyName, shouldBeZero, accessLevel, pHkey) {
7171
var accessLevelFound = findValueInHash(accessLevel, windef.KEY_ACCESS);
72-
debug('Mock: RegOpenKeyExA subkey: ' + subKeyName);
72+
debug('Mock: RegOpenKeyExW subkey: ' + subKeyName);
7373
if (hKey.address) {
7474
debug('Mock: hKey address:' + hKey.address());
7575
}
@@ -123,8 +123,8 @@ var advApi = {
123123
_In_ DWORD cbData
124124
);
125125
*/
126-
RegSetValueExA: function (hKey, valueName, shouldBeNull, valueType, valueBuffer, bufferLength) {
127-
debug('Mock: RegSetValueExA');
126+
RegSetValueExW: function (hKey, valueName, shouldBeNull, valueType, valueBuffer, bufferLength) {
127+
debug('Mock: RegSetValueExW');
128128
// predefined key
129129
if (typeof hKey === 'number') {
130130
assert(findValueInHash(hKey, windef.HKEY), 'Mock: Invalid predefined key specified');
@@ -136,9 +136,16 @@ var advApi = {
136136
assert(valueBuffer.constructor === Buffer);
137137
assert(typeof bufferLength === 'number');
138138

139+
// Use the passed length, not the length of valueBuffer
140+
var value = ref.reinterpret(valueBuffer, bufferLength, 0);
141+
142+
// Copy the value to a new buffer and store that
143+
var valueCopy = new Buffer(bufferLength);
144+
value.copy(valueCopy, 0, 0, bufferLength);
145+
139146
keys[hKey.address()].values[valueName] = {
140147
valueType: valueType,
141-
value: ref.readCString(valueBuffer),
148+
valueBuffer: valueCopy,
142149
length: bufferLength
143150
};
144151
return 0;
@@ -156,8 +163,8 @@ var advApi = {
156163
_Out_opt_ LPDWORD lpdwDisposition
157164
);
158165
*/
159-
RegCreateKeyExA: function (hKey, subKeyName, shouldBeNull, shouldBeNull2, securityAttributes, accessLevel, shouldBeNull3, pHkey, shouldBeNull4) {
160-
debug('Mock: RegCreateKeyExA');
166+
RegCreateKeyExW: function (hKey, subKeyName, shouldBeNull, shouldBeNull2, securityAttributes, accessLevel, shouldBeNull3, pHkey, shouldBeNull4) {
167+
debug('Mock: RegCreateKeyExW');
161168
assert(hKey.constructor === Buffer);
162169
assert(typeof subKeyName === 'string');
163170
assert(shouldBeNull === null);
@@ -192,7 +199,7 @@ var advApi = {
192199
_In_opt_ LPCTSTR lpSubKey
193200
);
194201
*/
195-
RegDeleteTreeA: function (hKey, subKeyName) {
202+
RegDeleteTreeW: function (hKey, subKeyName) {
196203
if (typeof hKey === 'number') {
197204
assert(findValueInHash(hKey, windef.HKEY), 'Mock: Invalid predefined key specified');
198205
} else {

test/mock/ffi.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ module.exports = {
88
var lib;
99
switch (libFile) {
1010
case 'Advapi32':
11-
assert(funcs.RegOpenKeyExA.constructor === Array);
12-
if(funcs.RegOpenKeyExA[1][0].indirection === types.HKEY.indirection &&
13-
funcs.RegOpenKeyExA[1][0].name === types.HKEY.name) {
11+
assert(funcs.RegOpenKeyExW.constructor === Array);
12+
if(funcs.RegOpenKeyExW[1][0].indirection === types.HKEY.indirection &&
13+
funcs.RegOpenKeyExW[1][0].name === types.HKEY.name) {
1414
// this is redefition for the library only specifying
1515
// a different key type
1616
lib = advApi;
1717
break;
1818
}
19-
assert(funcs.RegQueryValueExA.constructor === Array);
20-
assert(funcs.RegCreateKeyExA.constructor === Array);
21-
assert(funcs.RegDeleteTreeA.constructor === Array);
19+
assert(funcs.RegQueryValueExW.constructor === Array);
20+
assert(funcs.RegCreateKeyExW.constructor === Array);
21+
assert(funcs.RegDeleteTreeW.constructor === Array);
2222
assert(funcs.RegCloseKey.constructor === Array);
23-
assert(funcs.RegSetValueExA.constructor === Array);
23+
assert(funcs.RegSetValueExW.constructor === Array);
2424
assert(typeof funcs === 'object');
2525
lib = advApi;
2626
break;

test/mock/shell32.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ var SHELLEXECUTEINFO = struct({
3434
});
3535

3636
var shell32Mock = {
37-
ShellExecuteExA: function () {
37+
ShellExecuteExW: function () {
3838
}
3939
};
40-
shell32Mock.ShellExecuteExA.async = function (type, cb) {
40+
shell32Mock.ShellExecuteExW.async = function (type, cb) {
4141
debug('async');
4242
debug(type.deref().lpFile);
4343
assert.deepEqual(type.type.fields.cbSize, SHELLEXECUTEINFO.fields.cbSize);

0 commit comments

Comments
 (0)