Skip to content

Commit

Permalink
Little changes with intepreatition
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooky committed Mar 3, 2014
1 parent e32cadb commit d00bb54
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Controllers/Controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def initEditFrame(self, keyName = "", keyValue = ""):
self.ef.Bind(wx.EVT_BUTTON, self.OnCancelClick, self.ef.btn_cancel)

self.ef.key_name.SetValue(keyName)
self.ef.key_value.SetValue(keyValue)
self.ef.key_value.SetValue(str(keyValue))

self.ef.Show()

Expand Down
Binary file added KEYS_TESTING
Binary file not shown.
70 changes: 50 additions & 20 deletions Models/HivexManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def getValues(self, node):
val = self.h.node_get_value(node, keyName)
valType = self.h.value_type(val)[0]

value2 = self.getIntepretation(valType, val)
value2 = self.getStringIntepretation(valType, val)
stringType = typ.getStringType(valType)

res.append([keyName, stringType, value2])
Expand Down Expand Up @@ -108,8 +108,10 @@ def getValue(self, node, keyName):
val = self.h.node_get_value(node, keyName)
valType = self.h.value_type(val)[0]

editableValue = self.getStringIntepretation(valType, val, True)

#print valType, val
return [self.getIntepretation(valType, val), valType]
return [editableValue, valType]

def setValue(self, node, value):

Expand All @@ -132,33 +134,61 @@ def close(self):
return self.h.close()

'''
Display format value -> string
Display format value -> readable string
'''
def getIntepretation(self, val_type, val):
def getStringIntepretation(self, val_type, val, edit = False):

if val_type == Type.STRING:
res = self.h.value_string(val)
result = str(self.h.value_string(val))
elif val_type == Type.INTEGER:
result = str(self.h.value_dword(val))
elif val_type == Type.INTEGER_64:
result = str(self.h.value_dword(val))
elif val_type == Type.SYS_STRING:
res = self.h.value_string(val)
result = str(self.h.value_string(val))
elif val_type == Type.LIST_STRING:

result = self.h.value_multiple_strings(val)
if not edit:
result = str(result)
else:
result = '\n'.join(result)

elif val_type == Type.BINARY:
string = self.h.value_value(val)[1]
#print repr(string)
#print type(string)
print "binary"
res = repr(string)
#res = hex(string,2)
result = self.h.value_value(val)[1] # Result is in hexadecimal
if not edit:
result = '0x' + ''.join(['%x' % ord(x) for x in result]) # překodování
else:
result = ''.join(['%x' % ord(x) for x in result]) # překodování
else:
#print typ.getStringType(val_type)
result = self.h.value_value(val)[1]
result = result.decode('utf-16le').encode('utf-8')

return result
'''
Interpreatce v realnem formatu pro python
'''
def getRealIntepretation(self, val_type, val):

if val_type == Type.STRING:
result = str(self.h.value_string(val))
elif val_type == Type.INTEGER:
res = self.h.value_value(val)[1].decode('utf-16le').encode('utf-8')
elif val_type == Type.INTEGER_BIG_ENDIAN:
res = self.h.value_value(val)[1].decode('utf-16be').encode('utf-8')
elif val_type == Type.LINK:
res = self.h.value_string(val)
result = int(self.h.value_dword(val))
elif val_type == Type.INTEGER_64:
result = int(self.h.value_dword(val))
elif val_type == Type.SYS_STRING:
result = str(self.h.value_string(val))
elif val_type == Type.LIST_STRING:
res = self.h.value_multiple_strings(val)
result = self.h.value_multiple_strings(val)
elif val_type == Type.BINARY:
result = self.h.value_value(val)[1] # Result is in hexadecimal
#result = ' '.join(['%x' % ord(x) for x in result]) # překodování
else:
res = self.h.value_value(val)[1]
#print typ.getStringType(val_type)
result = self.h.value_value(val)[1]

return str(res)
return result

'''
Return format for save string -> value
Expand Down
4 changes: 2 additions & 2 deletions Models/Type.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def getStringType(self, x):
elif x == self.LINK:
res = "REG_LINK"
elif x == self.LIST_STRING:
res = "LIST_STRING"
res = "REG_MULTI_SZ"
else:
res = "Unknow"

return res



20 changes: 6 additions & 14 deletions PyRedit.geany
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@ long_line_behaviour=1
long_line_column=72

[files]
current_page=1
FILE_NAME_0=1328;Python;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Fsrc%2FViews%2FFrame.py;0;4
FILE_NAME_1=2986;Python;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Fsrc%2FModels%2FHivexManager.py;0;4
FILE_NAME_2=182;Python;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Fsrc%2FViews%2FMenuBar.py;0;4
FILE_NAME_3=337;Python;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Fsrc%2FViews%2FDialog.py;0;4
FILE_NAME_4=1006;Python;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Fsrc%2Fhivex-test.py;0;4
FILE_NAME_5=5177;Python;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Ftools%2Fhivex%2Fhivex-1.3.7%2Fpython%2Fhivex.py;0;4
FILE_NAME_6=141;Python;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Fsrc%2Fapp2.py;0;4
FILE_NAME_7=20;Markdown;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Fsrc%2FREADME.md;0;4
FILE_NAME_8=661;Python;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Fsrc%2FControllers%2FController.py;0;4
FILE_NAME_9=81;Python;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Fsrc%2FModels%2FType.py;0;4
FILE_NAME_10=19022;C;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Ftools%2Fhivex%2Fhivex-1.3.7%2Fpython%2Fhivex-py.c;0;4
FILE_NAME_11=5454;C;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Ftools%2Fhivex%2Fhivex-1.3.7%2Flib%2Fhivex.h;0;4
FILE_NAME_12=77465;C;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Ftools%2Fhivex%2Fhivex-1.3.7%2Flib%2Fhivex.c;0;4
current_page=3
FILE_NAME_0=9338;Python;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Fsrc%2FControllers%2FController.py;0;4
FILE_NAME_1=1151;Python;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Fsrc%2Fhivex-test.py;0;4
FILE_NAME_2=416;Python;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Fsrc%2FModels%2FType.py;0;4
FILE_NAME_3=2233;Python;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Fsrc%2FModels%2FHivexManager.py;0;4
FILE_NAME_4=4635;Python;0;EUTF-8;1;1;0;%2Fhome%2Fworker%2FBachelor%2Ftools%2Fhivex%2Fhivex-1.3.7%2Fpython%2Fhivex.py;0;4

[VTE]
last_dir=/home/worker/Bachelor/src/Models
Expand Down
57 changes: 46 additions & 11 deletions hivex-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
from Models import Type
import struct

def hextobin(hexval):
'''
Takes a string representation of hex data with
arbitrary length and converts to string representation
of binary. Includes padding 0s
'''
thelen = len(hexval)*4
binval = bin(int(hexval, 16))[2:]
while ((len(binval)) < thelen):
binval = '0' + binval
return binval

'''
# Use hivex to pull out a registry key.
Expand All @@ -23,46 +34,57 @@
print values
'''

h = hivex.Hivex ("Data/NTUSER.DAT_CHANGED", write=True)
h = hivex.Hivex ("Data/NTUSER.DAT_key_types", write=True)
#h = hivex.Hivex ("DEFAULT")

typ = Type()
root = h.root ()
key = h.node_get_child (root, "Environment")
key = h.node_get_child (root, "Keys")

#for child in h.node_children(root):

#name = h.node_name(child);
#print name
'''
Test string
'''
value = "čeština"
value = value.decode("utf-8").encode("utf-16le")
value1 = { "key": "Key3", "t": Type.STRING, "value": value }
h.node_set_value(key, value1)

'''
Test int
'''
Test int
#value = 150
value = struct.unpack("<h", "150")
value1 = { "key": "Key3", "t": Type.INTEGER, "value": value }
h.node_set_value(key, value1)

'''
for value in h.node_values(key):

keyName = h.value_key(value)

#print h.node_name(value)
val = h.node_get_value(key, keyName)
valType = h.value_type(val)[0]

#print valType
if(valType == Type.STRING):
if valType == Type.STRING:
value2 = h.value_string(val)

elif valType == Type.INTEGER:
value2 = h.value_dword(val)
elif valType == Type.INTEGER_64:
value2 = h.value_dword(val)
elif valType == Type.SYS_STRING:
value2 = h.value_string(val)
elif valType == Type.LIST_STRING:
value2 = h.value_multiple_strings(val)
elif valType == Type.BINARY:
value2 = h.value_value(val)[1] # Result is in hexadecimal
value2 = ''.join(['%x' % ord(x) for x in value2])
else:
print typ.getStringType(valType)
value2 = h.value_value(val)[1]
Expand All @@ -74,13 +96,26 @@
'''
h.node_add_child (root, "D")
b = h.node_get_child (root, "D")
'''
stringa = "test".decode('utf-8').encode('utf-16le')
stringb = "test2".decode('utf-8').encode('utf-16le')

x = 150
integer = struct.pack('>BH', x >> 32, x & 0xFFFF)
hexvalue = hextobin("A5")
values = [
{ "key": "Key1", "t": 3, "value": "ABC" },
{ "key": "Key2", "t": 3, "value": "DEF" }
{ "key": "TEST-Binary(string)", "t": Type.BINARY, "value": "ABC" },
{ "key": "TEST-Binary(hex)", "t": Type.BINARY, "value": "test" },
{ "key": "TEST-Dword", "t": Type.INTEGER, "value": '15'.decode('utf-8').encode('utf-16le') },
{ "key": "TEST-MultiString", "t": Type.LIST_STRING, "value": stringa + "\x00\x00" + stringb + "\x00\x00\x00\x00" },
]
h.node_set_values (b, values)
#h.node_set_values (key, values)

value = 150
value1 = { "key": "Key3", "t": Type.INTEGER, "value": "15" }
h.node_set_value(key, value1)
h.commit("KEYS_TESTING")
'''
value1 = { "key": "Key3", "t": 3, "value": "GHI" }
h.node_set_value (b, value1)
string = "JKL".decode('utf-8').encode('utf-16le')
Expand Down

0 comments on commit d00bb54

Please sign in to comment.