Changeset 200
- Timestamp:
- 06/03/10 01:08:20 (15 years ago)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
test/pyregfi-smoketest.py
r199 r200 15 15 16 16 17 def walk_tree(iter):18 total_keys = 119 total_values = iter_values(iter)20 print "total_values:", total_values21 22 for sub_key in iter:23 print sub_key.keyname24 25 print iter.down()26 num_keys,num_values = walk_tree(iter)27 total_keys += num_keys28 total_values += num_values29 iter.up()30 31 return (total_keys, total_values)32 33 34 17 for f in files: 35 18 rf = pyregfi.RegistryFile(f) 36 19 iter = rf.get_key() 37 print walk_tree(iter) 20 21 num_keys = 0 22 num_values = 0 23 # The iterator now walks the entire registry hive, depth-first 24 for key in iter: 25 #print key.keyname 26 num_keys +=1 27 num_values += iter_values(iter) 28 29 print "keys: %d" % num_keys 30 print "values: %d" % num_values -
trunk/include/regfi.h
r199 r200 1067 1067 1068 1068 /** Sets the internal subkey index to the first subkey referenced by the current 1069 * key and returns that key.1069 * key. 1070 1070 * 1071 1071 * @param i the iterator 1072 1072 * 1073 * @return A newly allocated key structure for the newly referenced first 1074 * subkey, or NULL on failure. Failure may be due to a lack of any 1075 * subkeys or other errors. Newly allocated keys must be freed with 1076 * @ref regfi_free_record. 1073 * @return True if the current key has any subkeys, false otherwise. 1077 1074 * 1078 1075 * @ingroup regfiIteratorLayer … … 1094 1091 1095 1092 1096 /** Increments the internal subkey index to the next key in the subkey-list and 1097 * returns the subkey for that index. 1093 /** Increments the internal subkey index to the next key in the subkey-list. 1098 1094 * 1099 1095 * @param i the iterator 1100 1096 * 1101 * @return A newly allocated key structure for the next subkey or NULL on 1102 * failure. Newly allocated keys must be freed with 1103 * @ref regfi_free_record. 1097 * @return True if another subkey should exist, false otherwise. 1104 1098 * 1105 1099 * @ingroup regfiIteratorLayer … … 1123 1117 1124 1118 /** Sets the internal value index to the first value referenced by the current 1125 * key and returns that value.1119 * key. 1126 1120 * 1127 1121 * @param i the iterator 1128 1122 * 1129 * @return A newly allocated value structure for the newly referenced first 1130 * value, or NULL on failure. Failure may be due to a lack of any 1131 * values or other errors. Newly allocated keys must be freed with 1132 * @ref regfi_free_record. 1123 * @return True if the current key has any values, false otherwise. 1133 1124 * 1134 1125 * @ingroup regfiIteratorLayer … … 1150 1141 1151 1142 1152 /** Increments the internal value index to the next value in the value-list and 1153 * returns the value for that index. 1143 /** Increments the internal value index to the next value in the value-list. 1154 1144 * 1155 1145 * @param i the iterator 1156 1146 * 1157 * @return A newly allocated key structure for the next value or NULL on 1158 * failure. Newly allocated keys must be freed with 1159 * @ref regfi_free_record. 1147 * @return True if another value should exist, false otherwise. 1160 1148 * 1161 1149 * @ingroup regfiIteratorLayer -
trunk/lib/regfi.c
r199 r200 67 67 void regfi_init() 68 68 { 69 fprintf(stderr, "regfi_init called\n"); 69 70 int err; 70 71 if((err = pthread_key_create(®fi_log_key, regfi_log_free)) != 0) -
trunk/python2/regfi/pyregfi.h
r199 r200 49 49 CLASS(KeyIterator, Object) 50 50 PRIVATE REGFI_ITERATOR *iter; 51 PRIVATE bool first_called;51 PRIVATE bool root_traversed; 52 52 53 53 KeyIterator METHOD(KeyIterator, Con, struct RegistryFile_t *file, char **path, … … 56 56 struct ValueIterator_t *METHOD(KeyIterator, list_values); 57 57 58 KeyIteratorMETHOD(KeyIterator, __iter__);59 REGFI_NK_REC *METHOD(KeyIterator, iternext);58 void METHOD(KeyIterator, __iter__); 59 BORROWED REGFI_NK_REC *METHOD(KeyIterator, iternext); 60 60 61 61 int METHOD(KeyIterator, down); … … 71 71 72 72 void METHOD(ValueIterator, __iter__); 73 R awDataMETHOD(ValueIterator, iternext);73 REGFI_VK_REC *METHOD(ValueIterator, iternext); 74 74 END_CLASS 75 75 -
trunk/python2/regfi/regfi.c
r199 r200 30 30 31 31 if(!self->reg) { 32 /*RaiseError(ERuntimeError, "REGFI Error: %s", regfi_log_get_str());*/32 RaiseError(ERuntimeError, "REGFI Error: %s", regfi_log_get_str()); 33 33 /*char* e = regfi_log_get_str();*/ 34 34 /*fprintf(stderr, "%p\n", e);*/ … … 61 61 } 62 62 63 static KeyIterator KeyIterator_Con(KeyIterator self, RegistryFile file, char **path, 64 REGFI_ENCODING encoding) { 63 static KeyIterator KeyIterator_Con(KeyIterator self, 64 RegistryFile file, 65 char **path, 66 REGFI_ENCODING encoding) 67 { 65 68 self->iter = regfi_iterator_new(file->reg, encoding); 66 69 … … 80 83 } 81 84 82 fprintf(stderr, "Con called\n"); 83 self->first_called = false; 85 self->root_traversed = false; 84 86 85 87 return self; … … 88 90 } 89 91 90 static KeyIterator KeyIterator__iter__(KeyIterator self) { 91 return self; 92 } 93 94 95 static const REGFI_NK_REC* KeyIterator_next(KeyIterator self) { 96 97 fprintf(stderr, "next called\n"); 98 99 if(!self->first_called) 92 static void KeyIterator__iter__(KeyIterator self) 93 { 94 return; 95 } 96 97 98 static const REGFI_NK_REC *KeyIterator_next(KeyIterator self) 99 { 100 if(!self->root_traversed) 101 self->root_traversed = true; 102 else if(!regfi_iterator_down(self->iter)) 100 103 { 101 regfi_iterator_first_subkey(self->iter); 102 self->first_called = true; 103 } 104 else 105 regfi_iterator_next_subkey(self->iter); 106 107 return regfi_iterator_cur_subkey(self->iter); 104 do 105 { 106 if(!regfi_iterator_up(self->iter)) 107 return NULL; 108 } while(!regfi_iterator_next_subkey(self->iter)); 109 110 /* XXX: This is an error condition. 111 * Probably should throw an exception or something. */ 112 if(!regfi_iterator_down(self->iter)) 113 return NULL; 114 } 115 116 regfi_iterator_first_subkey(self->iter); 117 return regfi_iterator_cur_key(self->iter); 108 118 } 109 119 110 120 111 121 static int KeyIterator_down(KeyIterator self) { 112 fprintf(stderr, "down cur_subkey: %d\n", self->iter->cur_subkey);113 122 int result = regfi_iterator_down(self->iter); 114 fprintf(stderr, "down result: %d\n", result);115 123 regfi_iterator_first_subkey(self->iter); 116 124 regfi_iterator_first_value(self->iter); … … 153 161 } 154 162 155 static ValueIteratorValueIterator__iter__(ValueIterator self) {156 return self;157 } 158 159 static R awDataValueIterator_iternext(ValueIterator self) {163 static void ValueIterator__iter__(ValueIterator self) { 164 return; 165 } 166 167 static REGFI_VK_REC* ValueIterator_iternext(ValueIterator self) { 160 168 RawData result; 161 169 const REGFI_DATA* data; … … 172 180 rec = regfi_iterator_cur_value(self->iter); 173 181 182 return rec; 183 174 184 if(!rec) return NULL; 175 185 … … 177 187 * Instead, make data fetching a method and parse it then. 178 188 */ 189 /* 179 190 data = (REGFI_DATA *)regfi_iterator_fetch_data(self->iter, rec); 180 191 if(!data) { … … 198 209 break; 199 210 } 211 */ 200 212 201 213 return result;
Note: See TracChangeset
for help on using the changeset viewer.