Skip to content

Commit 589a982

Browse files
committed
Added flag functionality to specify that a created registry key should be volatile, and changed the default behavior to instead create non-volatile keys
1 parent a023ef3 commit 589a982

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

examples/reg.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def run(self, remoteName, remoteHost):
186186
if self.__action == 'QUERY':
187187
self.query(dce, self.__options.keyName)
188188
elif self.__action == 'ADD':
189-
self.add(dce, self.__options.keyName)
189+
self.add(dce, self.__options.keyName, self.__options.volatile)
190190
elif self.__action == 'DELETE':
191191
self.delete(dce, self.__options.keyName)
192192
elif self.__action == 'SAVE':
@@ -256,8 +256,14 @@ def query(self, dce, keyName):
256256
# ans5 = rrp.hBaseRegGetVersion(rpc, ans2['phkResult'])
257257
# ans3 = rrp.hBaseRegEnumKey(rpc, ans2['phkResult'], 0)
258258

259-
def add(self, dce, keyName):
259+
def add(self, dce, keyName, volatile):
260260
hRootKey, subKey = self.__strip_root_key(dce, keyName)
261+
262+
# Convert volatile flag into option.
263+
dwOption = 0x00000000
264+
if volatile is True:
265+
dwOption = 0x00000001
266+
261267

262268
# READ_CONTROL | rrp.KEY_SET_VALUE | rrp.KEY_CREATE_SUB_KEY should be equal to KEY_WRITE (0x20006)
263269
if self.__options.v is None: # Try to create subkey
@@ -270,9 +276,9 @@ def add(self, dce, keyName):
270276
# Should I use ans2?
271277

272278
ans3 = rrp.hBaseRegCreateKey(
273-
dce, hRootKey, subKeyCreate,
274-
samDesired=READ_CONTROL | rrp.KEY_SET_VALUE | rrp.KEY_CREATE_SUB_KEY
275-
)
279+
dce, hRootKey, subKeyCreate, dwOptions=dwOption,
280+
samDesired=READ_CONTROL | rrp.KEY_SET_VALUE | rrp.KEY_CREATE_SUB_KEY)
281+
276282
if ans3['ErrorCode'] == 0:
277283
print('Successfully set subkey %s' % (
278284
keyName
@@ -570,6 +576,8 @@ def __parse_lp_data(valueType, valueData):
570576
add_parser.add_argument('-vd', action='append', metavar="VALUEDATA", required=False, help='Specifies the registry '
571577
'value data that is to be set. In case of adding a REG_MULTI_SZ value, set this option once for each '
572578
'line you want to add.', default=[])
579+
add_parser.add_argument('--volatile', action='store_true', required=False, help='Specify that the key is intended to be volitile '
580+
'and deleted upon system reboot')
573581

574582
# An delete command
575583
delete_parser = subparsers.add_parser('delete', help='Deletes a subkey or entries from the registry')

0 commit comments

Comments
 (0)