- Timestamp:
- 09/06/10 23:03:36 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/regfi.c
r206 r207 1721 1721 1722 1722 1723 1724 /****************************************************************************** 1725 *****************************************************************************/ 1726 uint32_t regfi_fetch_num_subkeys(const REGFI_NK* key) 1727 { 1728 uint32_t num_in_list = 0; 1729 if(key->subkeys != NULL) 1730 num_in_list = key->subkeys->num_keys; 1731 1732 if(num_in_list != key->num_subkeys) 1733 { 1734 regfi_log_add(REGFI_LOG_INFO, "Key at offset 0x%.8X contains %d keys in its" 1735 " subkey list but reports %d should be available.", 1736 key->offset, num_in_list, key->num_subkeys); 1737 return (num_in_list < key->num_subkeys)?num_in_list:key->num_subkeys; 1738 } 1739 1740 return num_in_list; 1741 } 1742 1743 1744 /****************************************************************************** 1745 *****************************************************************************/ 1746 uint32_t regfi_fetch_num_values(const REGFI_NK* key) 1747 { 1748 uint32_t num_in_list = 0; 1749 if(key->values != NULL) 1750 num_in_list = key->values->num_values; 1751 1752 if(num_in_list != key->num_values) 1753 { 1754 regfi_log_add(REGFI_LOG_INFO, "Key at offset 0x%.8X contains %d values in" 1755 " its value list but reports %d should be available.", 1756 key->offset, num_in_list, key->num_values); 1757 return (num_in_list < key->num_values)?num_in_list:key->num_values; 1758 } 1759 1760 return num_in_list; 1761 } 1762 1763 1723 1764 /****************************************************************************** 1724 1765 *****************************************************************************/ … … 1836 1877 /****************************************************************************** 1837 1878 *****************************************************************************/ 1838 bool regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* subkey_name) 1839 { 1840 REGFI_NK* subkey; 1841 bool found = false; 1842 uint32_t old_subkey = i->cur_subkey; 1843 1844 if(subkey_name == NULL) 1845 return false; 1846 1847 /* XXX: this alloc/free of each sub key might be a bit excessive */ 1848 regfi_iterator_first_subkey(i); 1849 while((subkey = regfi_iterator_cur_subkey(i)) != NULL && (found == false)) 1850 { 1851 if(subkey->name != NULL 1852 && strcasecmp(subkey->name, subkey_name) == 0) 1853 found = true; 1854 else 1855 { 1856 talloc_unlink(NULL, subkey); 1857 regfi_iterator_next_subkey(i); 1858 } 1859 } 1860 1861 if(found == false) 1862 { 1863 i->cur_subkey = old_subkey; 1864 return false; 1865 } 1866 1867 talloc_unlink(NULL, subkey); 1868 return true; 1879 bool regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* name) 1880 { 1881 uint32_t new_index; 1882 1883 if(regfi_find_subkey(i->f, i->cur_key, name, &new_index)) 1884 { 1885 i->cur_subkey = new_index; 1886 return true; 1887 } 1888 1889 return false; 1869 1890 } 1870 1891 … … 1922 1943 1923 1944 return ((i->cur_key != NULL) && (i->cur_key->subkeys_off!=REGFI_OFFSET_NONE) 1924 && (i->cur_subkey < i->cur_key->num_subkeys));1945 && (i->cur_subkey < regfi_fetch_num_subkeys(i->cur_key))); 1925 1946 } 1926 1947 … … 1930 1951 const REGFI_NK* regfi_iterator_cur_subkey(REGFI_ITERATOR* i) 1931 1952 { 1932 uint32_t nk_offset; 1933 1934 if((i->cur_key != NULL) && (i->cur_key->subkeys_off!=REGFI_OFFSET_NONE) 1935 && (i->cur_subkey < i->cur_key->num_subkeys)) 1936 { 1937 nk_offset = i->cur_key->subkeys->elements[i->cur_subkey].offset; 1938 1939 return regfi_load_key(i->f, nk_offset+REGFI_REGF_SIZE, 1940 i->f->string_encoding, true); 1941 } 1942 1943 return NULL; 1953 return regfi_get_subkey(i->f, i->cur_key, i->cur_subkey); 1944 1954 } 1945 1955 … … 1952 1962 1953 1963 return ((i->cur_key != NULL) && (i->cur_key->subkeys_off!=REGFI_OFFSET_NONE) 1954 && (i->cur_subkey < i->cur_key->num_subkeys));1964 && (i->cur_subkey < regfi_fetch_num_subkeys(i->cur_key))); 1955 1965 } 1956 1966 … … 1958 1968 /****************************************************************************** 1959 1969 *****************************************************************************/ 1960 bool regfi_iterator_find_value(REGFI_ITERATOR* i, const char* value_name) 1961 { 1962 const REGFI_VK* cur; 1963 bool found = false; 1964 uint32_t old_value = i->cur_value; 1965 1966 /* XXX: cur->name can be NULL in the registry. 1967 * Should we allow for a way to search for that? 1968 */ 1969 if(value_name == NULL) 1970 return false; 1971 1972 regfi_iterator_first_value(i); 1973 while((cur = regfi_iterator_cur_value(i)) != NULL && (found == false)) 1974 { 1975 if((cur->name != NULL) 1976 && (strcasecmp(cur->name, value_name) == 0)) 1977 found = true; 1978 else 1979 { 1980 regfi_free_record(cur); 1981 regfi_iterator_next_value(i); 1982 } 1983 } 1984 1985 if(found == false) 1986 { 1987 i->cur_value = old_value; 1988 return false; 1989 } 1990 1991 regfi_free_record(cur); 1992 return true; 1970 bool regfi_iterator_find_value(REGFI_ITERATOR* i, const char* name) 1971 { 1972 uint32_t new_index; 1973 1974 if(regfi_find_value(i->f, i->cur_key, name, &new_index)) 1975 { 1976 i->cur_value = new_index; 1977 return true; 1978 } 1979 1980 return false; 1993 1981 } 1994 1982 … … 2000 1988 i->cur_value = 0; 2001 1989 return (i->cur_key->values != NULL && i->cur_key->values->elements != NULL 2002 && (i->cur_value < i->cur_key->values->num_values));1990 && (i->cur_value < regfi_fetch_num_values(i->cur_key))); 2003 1991 } 2004 1992 … … 2008 1996 const REGFI_VK* regfi_iterator_cur_value(REGFI_ITERATOR* i) 2009 1997 { 2010 REGFI_VK* ret_val = NULL; 2011 uint32_t voffset; 2012 2013 if(i->cur_key->values != NULL && i->cur_key->values->elements != NULL 2014 && (i->cur_value < i->cur_key->values->num_values)) 2015 { 2016 voffset = i->cur_key->values->elements[i->cur_value]; 2017 ret_val = regfi_load_value(i->f, voffset+REGFI_REGF_SIZE, 2018 i->f->string_encoding, true); 2019 } 2020 2021 return ret_val; 1998 return regfi_get_value(i->f, i->cur_key, i->cur_value); 2022 1999 } 2023 2000 … … 2029 2006 i->cur_value++; 2030 2007 return (i->cur_key->values != NULL && i->cur_key->values->elements != NULL 2031 && (i->cur_value < i->cur_key->values->num_values));2008 && (i->cur_value < regfi_fetch_num_values(i->cur_key))); 2032 2009 } 2033 2010 … … 2141 2118 2142 2119 return ret_val; 2120 } 2121 2122 2123 2124 /****************************************************************************** 2125 *****************************************************************************/ 2126 bool regfi_find_subkey(REGFI_FILE* file, const REGFI_NK* key, 2127 const char* name, uint32_t* index) 2128 { 2129 const REGFI_NK* cur; 2130 uint32_t i; 2131 uint32_t num_subkeys = regfi_fetch_num_subkeys(key); 2132 bool found = false; 2133 2134 /* XXX: cur->name can be NULL in the registry. 2135 * Should we allow for a way to search for that? 2136 */ 2137 if(name == NULL) 2138 return false; 2139 2140 for(i=0; (i < num_subkeys) && (found == false); i++) 2141 { 2142 cur = regfi_get_subkey(file, key, i); 2143 if(cur == NULL) 2144 return false; 2145 2146 if((cur->name != NULL) 2147 && (strcasecmp(cur->name, name) == 0)) 2148 { 2149 found = true; 2150 *index = i; 2151 } 2152 2153 regfi_free_record(cur); 2154 } 2155 2156 return found; 2157 } 2158 2159 2160 2161 /****************************************************************************** 2162 *****************************************************************************/ 2163 bool regfi_find_value(REGFI_FILE* file, const REGFI_NK* key, 2164 const char* name, uint32_t* index) 2165 { 2166 const REGFI_VK* cur; 2167 uint32_t i; 2168 uint32_t num_values = regfi_fetch_num_values(key); 2169 bool found = false; 2170 2171 /* XXX: cur->name can be NULL in the registry. 2172 * Should we allow for a way to search for that? 2173 */ 2174 if(name == NULL) 2175 return false; 2176 2177 for(i=0; (i < num_values) && (found == false); i++) 2178 { 2179 cur = regfi_get_value(file, key, i); 2180 if(cur == NULL) 2181 return false; 2182 2183 if((cur->name != NULL) 2184 && (strcasecmp(cur->name, name) == 0)) 2185 { 2186 found = true; 2187 *index = i; 2188 } 2189 2190 regfi_free_record(cur); 2191 } 2192 2193 return found; 2194 } 2195 2196 2197 2198 /****************************************************************************** 2199 *****************************************************************************/ 2200 const REGFI_NK* regfi_get_subkey(REGFI_FILE* file, const REGFI_NK* key, 2201 uint32_t index) 2202 { 2203 if(index < regfi_fetch_num_subkeys(key)) 2204 { 2205 return regfi_load_key(file, 2206 key->subkeys->elements[index].offset+REGFI_REGF_SIZE, 2207 file->string_encoding, true); 2208 } 2209 2210 return NULL; 2211 } 2212 2213 2214 2215 /****************************************************************************** 2216 *****************************************************************************/ 2217 const REGFI_VK* regfi_get_value(REGFI_FILE* file, const REGFI_NK* key, 2218 uint32_t index) 2219 { 2220 if(index < regfi_fetch_num_values(key)) 2221 { 2222 return regfi_load_value(file, 2223 key->values->elements[index]+REGFI_REGF_SIZE, 2224 file->string_encoding, true); 2225 } 2226 2227 return NULL; 2143 2228 } 2144 2229
Note: See TracChangeset
for help on using the changeset viewer.