diff options
| author | awuctl | 2022-08-23 16:48:54 +0000 |
|---|---|---|
| committer | awuctl | 2022-08-23 16:48:54 +0000 |
| commit | 840fb76d797319ca0542dccc92a08feb1e9a8264 (patch) | |
| tree | a22723328b0a0de267898a86ac6dd55bd6f42b82 /hwid_dec.c | |
| download | hwid-stuff-840fb76d797319ca0542dccc92a08feb1e9a8264.zip | |
initial commit
Diffstat (limited to 'hwid_dec.c')
| -rw-r--r-- | hwid_dec.c | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/hwid_dec.c b/hwid_dec.c new file mode 100644 index 0000000..c426133 --- /dev/null +++ b/hwid_dec.c @@ -0,0 +1,108 @@ +#include <stdio.h> +#include <stdlib.h> +#include <inttypes.h> + +struct __attribute__((packed)) HWID { + uint16_t size; + uint16_t version; + uint16_t instances[9]; + uint16_t dock_or_PCMCIA; + uint16_t hashRAM; + uint16_t hashBIOS; + uint16_t instanceHashes[]; +}; + +struct __attribute__((packed)) TIMEWEIGHT { + uint8_t num_weights; + struct __attribute__((packed)) Weight { + uint8_t type; + uint16_t weight; + } weight[]; +}; + +const char *CLASS_NAMES[] = { + "CDROM", + "Hard Disk Controllers", + "Hard Disk Drives", + "Displays", + "SCSI Adapters", + "PCMCIA", + "Audio Adapters", + "Dock", + "Network Interface Cards", + "CPUs", + "Memory", + "UNUSED", + "BIOS", + "UNUSED", + "Mobile Broadband", + "Bluetooth Interfaces" +}; + +const char *HWID_NAMES[] = { + "CDROM / Mobile Broadband", + "Hard Disk Controllers", + "Hard Disk Drives", + "Displays", + "SCSI Adapters / Bluetooth Controllers", + "Audio Adapters", + "Unused", + "Network Interface Cards", + "CPUs" +}; + +void print_block(uint8_t *hw_block) { + uint32_t size = *(uint32_t *)hw_block; + uint16_t unknown = *(uint16_t *)(hw_block + 4); + unsigned instance_count = 0; + + puts("Block Information:"); + printf("Size : [%08x]\n", size); + printf("Unknown : [%08x]\n", unknown); + puts(""); + + struct HWID *hwid = (struct HWID *)(hw_block + 6); + puts("HWID Information:"); + printf("Size : [%04x]\n", hwid->size); + printf("Version : [%04x]\n", hwid->version); + for(size_t i = 0; i < 9; i++) { + instance_count += hwid->instances[i]; + printf("Inst. (%02zx) : [%04x] -> %s\n", i, hwid->instances[i], HWID_NAMES[i]); + } + printf("Dock/PCMCIA : [%04x]\n", hwid->dock_or_PCMCIA); + printf("RAM hash : [%02x]\n", hwid->hashRAM); + printf("SMBIOS hash : [%04x]\n", hwid->hashBIOS); + for(size_t i = 0; i < instance_count; i++) { + printf("Hash (%02zx) : [%04x] %s\n", i, hwid->instanceHashes[i], (hwid->instanceHashes[i] & 1) == 1 ? "[[Non-Removable]]" : ""); + } + puts(""); + + struct TIMEWEIGHT *tw = (struct TIMEWEIGHT *) ((hw_block + 6) + hwid->size); + puts("Timeweight Information:"); + printf("Weights : [%02x]\n", tw->num_weights); + + for(size_t i = 0; i < tw->num_weights; i++) { + printf("Weight (%02x) : [%04x] -> %s\n", tw->weight[i].type, tw->weight[i].weight, CLASS_NAMES[tw->weight[i].type]); + } + +} + +int main(int argc, char *argv[]) { + + if(argc != 2) { + puts("Invalid parameters.\nUsages:\n\thwid file"); + exit(1); + } + + FILE *fd = fopen(argv[1], "r"); + fseek(fd, 0, SEEK_END); + long fsize = ftell(fd); + rewind(fd); + + uint8_t *hw_block = malloc(fsize); + fread(hw_block, 1, fsize, fd); + + print_block(hw_block); + + return 0; +}
\ No newline at end of file |
