| 1 | /* Hive.h |
| 2 | Hive file access, pretty lame and bugged but do the work O_o |
| 3 | Thanks to B.D. for file structure info |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU General Public License |
| 7 | as published by the Free Software Foundation; either version 2 |
| 8 | of the License, or (at your option) any later version. |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | |
| 19 | This program is released under the GPL with the additional exemption |
| 20 | that compiling, linking, and/or using OpenSSL is allowed. |
| 21 | |
| 22 | Copyright (C) 2004-2006 Nicola Cuomo <[email protected]> |
| 23 | Improvments and some bugs fixes by Objectif Securité |
| 24 | <http://www.objectif-securite.ch> |
| 25 | */ |
| 26 | |
| 27 | #ifndef HIVE_H |
| 28 | #define HIVE_H |
| 29 | |
| 30 | #include <stdio.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <string.h> |
| 33 | |
| 34 | #define min(a, b) (((a) < (b)) ? (a) : (b)) |
| 35 | |
| 36 | #define NK_ID 0x6B6E |
| 37 | #define NK_ROOT 0x2c |
| 38 | #define LF_ID 0x666C |
| 39 | |
| 40 | #ifdef __cplusplus |
| 41 | extern "C" { |
| 42 | #endif |
| 43 | |
| 44 | struct hive |
| 45 | { |
| 46 | unsigned char *base; |
| 47 | }; |
| 48 | |
| 49 | typedef struct _nk_hdr |
| 50 | { |
| 51 | short int id; |
| 52 | short int type; |
| 53 | int t1, t2; |
| 54 | int unk1; |
| 55 | int parent_off; |
| 56 | int subkey_num; |
| 57 | int unk2; |
| 58 | int lf_off; |
| 59 | int unk3; |
| 60 | int value_cnt; |
| 61 | int value_off; |
| 62 | int sk_off; |
| 63 | int classname_off; |
| 64 | int unk4[4]; |
| 65 | int unk5; |
| 66 | short int name_len; |
| 67 | short int classname_len; |
| 68 | unsigned char *key_name; |
| 69 | } nk_hdr; |
| 70 | |
| 71 | typedef struct _hashrecord |
| 72 | { |
| 73 | |
| 74 | int nk_offset; |
| 75 | char keyname[4]; |
| 76 | } hashrecord; |
| 77 | |
| 78 | typedef struct _lf_hdr |
| 79 | { |
| 80 | short int id; |
| 81 | short int key_num; |
| 82 | unsigned char *hr; |
| 83 | } lf_hdr; |
| 84 | |
| 85 | typedef struct _vk_hdr |
| 86 | { |
| 87 | short int id; |
| 88 | short int name_len; |
| 89 | int data_len; |
| 90 | int data_off; |
| 91 | int data_type; |
| 92 | short int flag; |
| 93 | short int unk1; |
| 94 | unsigned char *value_name; |
| 95 | } vk_hdr; |
| 96 | |
| 97 | nk_hdr* read_nk(nk_hdr *nk, struct hive *h, int offset ); |
| 98 | lf_hdr* read_lf(lf_hdr *lf, struct hive *h, int offset ); |
| 99 | vk_hdr* read_vk(vk_hdr *vk, struct hive *h, int offset ); |
| 100 | hashrecord* read_hr(hashrecord *hr, unsigned char *pos, int index ); |
| 101 | int* read_valuelist(int *value, struct hive *h, int offset, int size); |
| 102 | unsigned char* read_data(struct hive *h, int offset ); |
| 103 | |
| 104 | void _RegCloseHive( struct hive *h ); |
| 105 | |
| 106 | void _InitHive( struct hive *h ); |
| 107 | |
| 108 | int _RegOpenHive( unsigned char *filename, struct hive *h ); |
| 109 | |
| 110 | int _RegOpenHiveBuffer( unsigned char *buffer, unsigned long size, struct hive *h ); |
| 111 | |
| 112 | long parself( struct hive *h, char *t, unsigned long off ); |
| 113 | |
| 114 | int _RegGetRootKey(struct hive *h, char **root_key); |
| 115 | |
| 116 | int _RegOpenKey( struct hive *h, char *path, nk_hdr **nr ); |
| 117 | |
| 118 | int _RegQueryValue( struct hive *h, char *name, nk_hdr *nr, unsigned char **buff, int *len ); |
| 119 | |
| 120 | int _RegEnumKey( struct hive *h, nk_hdr *nr, int index, char *name, int *namelen ); |
| 121 | |
| 122 | #ifdef __cplusplus |
| 123 | } |
| 124 | #endif |
| 125 | #endif |