Index: trunk/python/pyregfi/__init__.py
===================================================================
--- trunk/python/pyregfi/__init__.py	(revision 205)
+++ trunk/python/pyregfi/__init__.py	(revision 206)
@@ -29,4 +29,13 @@
 regfi.regfi_free_record.restype = None
 
+regfi.regfi_fetch_classname.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK)]
+regfi.regfi_fetch_classname.restype = POINTER(REGFI_CLASSNAME)
+
+regfi.regfi_fetch_sk.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_NK)]
+regfi.regfi_fetch_sk.restype = POINTER(REGFI_SK)
+
+regfi.regfi_fetch_data.argtypes = [POINTER(REGFI_FILE), POINTER(REGFI_VK)]
+regfi.regfi_fetch_data.restype = POINTER(REGFI_DATA)
+
 regfi.regfi_iterator_new.argtypes = [POINTER(REGFI_FILE), REGFI_ENCODING]
 regfi.regfi_iterator_new.restype = POINTER(REGFI_ITERATOR)
@@ -50,7 +59,4 @@
 regfi.regfi_iterator_cur_key.restype = POINTER(REGFI_NK)
 
-regfi.regfi_iterator_cur_sk.argtypes = [POINTER(REGFI_ITERATOR)]
-regfi.regfi_iterator_cur_sk.restype = POINTER(REGFI_SK)
-
 regfi.regfi_iterator_first_subkey.argtypes = [POINTER(REGFI_ITERATOR)]
 regfi.regfi_iterator_first_subkey.restype = c_bool
@@ -76,11 +82,4 @@
 regfi.regfi_iterator_find_value.argtypes = [POINTER(REGFI_ITERATOR), c_char_p]
 regfi.regfi_iterator_find_value.restype = c_bool
-
-# XXX: possibly move REGFI_ENCODING to file object and eliminate need for ITERATOR here.
-regfi.regfi_iterator_fetch_classname.argtypes = [POINTER(REGFI_ITERATOR), POINTER(REGFI_NK)]
-regfi.regfi_iterator_fetch_classname.restype = POINTER(REGFI_CLASSNAME)
-
-regfi.regfi_iterator_fetch_data.argtypes = [POINTER(REGFI_ITERATOR), POINTER(REGFI_VK)]
-regfi.regfi_iterator_fetch_data.restype = POINTER(REGFI_DATA)
 
 
@@ -91,6 +90,42 @@
 
 def GetLogMessages():
-    return regfi.regfi_log_get_str()
-
+    msgs = regfi.regfi_log_get_str()
+    if msgs == None:
+        return ''
+    return msgs
+
+
+class _StructureWrapper():
+    "Handles memory management and proxies attribute access to base structures"
+    base = None
+
+    def __init__(self, base):
+        # XXX: check for NULL here, throw an exception if so.
+        self.base = base
+
+    def __del__(self):
+        regfi.regfi_free_record(self.base)
+
+    def __getattr__(self, name):
+        return getattr(self.base.contents, name)
+
+    def __eq__(self, other):
+        return (type(self) == type(other)) and (self.offset == other.offset)
+
+    def __ne__(self, other):
+        return (not self.__eq__(other))
+
+
+class Key(_StructureWrapper):
+    pass
+
+class Value(_StructureWrapper):
+    pass
+
+class Data(_StructureWrapper):
+    pass
+
+class Security(_StructureWrapper):
+    pass
 
 class Hive():    
@@ -126,9 +161,14 @@
         return HiveIterator(self)
 
+    def subtree(self, path):
+        hi = HiveIterator(self)
+        hi.descend(path)
+        return hi
+
 
 class HiveIterator():
     hive = None
     iter = None
-    root_traversed = False
+    iteration_root = None
 
     def __init__(self, hive):
@@ -147,13 +187,17 @@
 
     def __iter__(self):
+        self.iteration_root = None
         return self
 
     def __next__(self):
-        if self.root_traversed:
-            self.root_traversed = True
-            
+        if self.iteration_root == None:
+            self.iteration_root = self.current_key()            
         elif not regfi.regfi_iterator_down(self.iter):
             up_ret = regfi.regfi_iterator_up(self.iter)
-            while up_ret and not regfi.regfi_iterator_next_subkey(self.iter):
+            while (up_ret and
+                   not regfi.regfi_iterator_next_subkey(self.iter)):
+                if self.iteration_root == self.current_key():
+                    self.iteration_root = None
+                    raise StopIteration('')
                 up_ret = regfi.regfi_iterator_up(self.iter)
 
@@ -166,5 +210,22 @@
 
         regfi.regfi_iterator_first_subkey(self.iter)
-        print(regfi.regfi_iterator_cur_key(self.iter).contents.keyname)
-        return regfi.regfi_iterator_cur_key(self.iter)
-
+        return self.current_key()
+
+    def down(self):
+        pass
+
+    def up(self):
+        pass
+
+    def descend(self, path):
+        #set up generator
+        cpath = (bytes(p,'ascii') for p in path) 
+
+        # evaluate generator and create char* array
+        apath = (c_char_p*len(path))(*cpath)
+
+        if not regfi.regfi_iterator_walk_path(self.iter,apath):
+            raise Exception('Could not locate path.\n'+GetLogMessages())
+
+    def current_key(self):
+        return Key(regfi.regfi_iterator_cur_key(self.iter))
Index: trunk/python/pyregfi/structures.py
===================================================================
--- trunk/python/pyregfi/structures.py	(revision 205)
+++ trunk/python/pyregfi/structures.py	(revision 206)
@@ -83,6 +83,6 @@
 REGFI_VK._fields_ = [('offset', c_uint32),
                      ('cell_size', c_uint32),
-                     ('valuename', c_char_p),
-                     ('valuename_raw', POINTER(c_char)),
+                     ('name', c_char_p),
+                     ('name_raw', POINTER(c_char)),
                      ('name_length', c_uint16),
                      ('hbin_off', c_uint32),
@@ -119,6 +119,6 @@
                      ('name_length', c_uint16),
                      ('classname_length', c_uint16),
-                     ('keyname', c_char_p),
-                     ('keyname_raw', POINTER(c_char)),
+                     ('name', c_char_p),
+                     ('name_raw', POINTER(c_char)),
                      ('parent_off', c_uint32),
                      ('classname_off', c_uint32),
