1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
| BOOL AnalysisHiveFile(PTCHAR pszHiveFileName) { BOOL bRet = FALSE; HANDLE hFile = NULL, hFileMap = NULL; LPVOID pMemory = NULL; do { hFile = ::CreateFile(pszHiveFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, NULL); if (INVALID_HANDLE_VALUE == hFile) break; hFileMap = ::CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, NULL); if (NULL == hFileMap) break; pMemory = MapViewOfFile(hFileMap, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0); if (NULL == pMemory) break; bRet = AnalysisHiveHeader((PUCHAR)pMemory); } while (FALSE); if (pMemory) UnmapViewOfFile(pMemory); if (hFileMap) ::CloseHandle(hFileMap); if (hFile) ::CloseHandle(hFile); return bRet; };
BOOL AnalysisHiveHeader(PUCHAR pMemory) { BOOL bRet = FALSE; DWORD dwMajor = 0, dwMinor = 0; DWORD dwRootCellOffset = 0; DWORD dwLength = 0; WCHAR* pwszHiveName = NULL; PUCHAR pHBIN = NULL; dwMajor = *(DWORD*)(pMemory + 0x14); dwMinor = *(DWORD*)(pMemory + 0x18); dwRootCellOffset = *(DWORD*)(pMemory + 0x24); dwLength = *(DWORD*)(pMemory + 0x28); pwszHiveName = (WCHAR*)(pMemory + 0x30); printf("-----------------------------------------------------------------------\n"); printf("dwMajor=%d, dwMinor=%d\n", dwMajor, dwMinor); printf("RootCellOffset=0x%X, dwLength=0x%X\n", dwRootCellOffset, dwLength); printf("szHiveName=%S\n", pwszHiveName); printf("-----------------------------------------------------------------------\n\n"); pHBIN = pMemory + 0x1000; bRet = HiveNK(pHBIN, (pHBIN + dwRootCellOffset)); return bRet; };
BOOL HiveNK(PUCHAR pHBIN, PUCHAR pNode) { char* pszNodeName = NULL; USHORT usSignature = 0; DWORD dwSubNodeCount = 0; DWORD dwSubNodeOffset = 0; DWORD dwValueCount = 0; DWORD dwValueOffset = 0; DWORD dwNodeNameLength = 0; DWORD dwValueOffsetList = NULL; DWORD i = 0; usSignature = *(USHORT*)(pNode + 0x4); if (0x6B6E != usSignature) return FALSE; dwSubNodeCount = *(DWORD*)(pNode + 0x18); dwSubNodeOffset = *(DWORD*)(pNode + 0x20); dwValueCount = *(DWORD*)(pNode + 0x28); dwValueOffset = *(DWORD*)(pNode + 0x2C); dwNodeNameLength = *(DWORD*)(pNode + 0x4C); pszNodeName = (char*)(pNode + 0x50); for (i = 0; i < dwNodeNameLength; i++) printf("%c", pszNodeName[i]); printf("\n"); for (i = 0; i < dwValueCount; i++) { DWORD dwOffset = *(DWORD*)(pHBIN + dwValueOffset + 4 * (1 + i)); HiveVK(pHBIN, (pHBIN + dwOffset)); }; for (i = 0; i < dwSubNodeCount; i++) HiveList(pHBIN, (pHBIN + dwSubNodeOffset)); return TRUE; };
BOOL HiveVK(PUCHAR pHBIN, PUCHAR pValue) { char* pszValueName = NULL; USHORT usSignature = 0; USHORT usValueNameLength = 0; DWORD dwValueDataLength = 0; DWORD dwValueData = 0; DWORD dwValueType = 0; DWORD i = 0; usSignature = *(USHORT*)(pValue + 0x4); if (0x6B76 != usSignature) return FALSE; usValueNameLength = *(USHORT*)(pValue + 0x6); dwValueDataLength = *(DWORD*)(pValue + 0x8); dwValueData = *(DWORD*)(pValue + 0xC); dwValueType = *(DWORD*)(pValue + 0x10); pszValueName = (char*)(pValue + 0x18); for (i = 0; i < usValueNameLength; i++) printf("%c", pszValueName[i]); printf(", %d\n", dwValueType);
return TRUE; };
BOOL HiveList(PUCHAR pHBIN, PUCHAR pList) { USHORT usSignature = 0; USHORT usCount = 0; DWORD dwOffset = 0; USHORT i = 0; usSignature = *(USHORT*)(pList + 0x4); usCount = *(USHORT*)(pList + 0x6); if (0x666C == usSignature || 0x686C == usSignature) { for (i = 0; i < usCount; i++) { dwOffset = *(DWORD*)(pList + 0x8 + 8 * i); HiveNK(pHBIN, (pHBIN + dwOffset)); }; } else if (0x696C == usSignature || 0x6972 == usSignature) { for (i = 0; i < usCount; i++) { dwOffset = *(DWORD*)(pList + 0x8 + 4 * i); HiveList(pHBIN, (pHBIN + dwOffset)); }; } else if (0x6264 == usSignature) { dwOffset = *(DWORD*)(pList + 0x8); HiveVK(pHBIN, (pHBIN + dwOffset)); }; return TRUE; };
|