|
// Attempt to walk the datastructures layed out in the programmer's guide |
|
|
|
#include <stdio.h> |
|
|
|
#define FILE_LENGTH 0x2000 |
|
#define PS_OFFSET 0x48 |
|
|
|
typedef struct { |
|
unsigned short id; |
|
unsigned char version_major; |
|
unsigned char version_minor; |
|
unsigned short pskey_length; |
|
unsigned short data_length; |
|
unsigned char eeprom_flag; |
|
} Header; |
|
|
|
typedef struct { |
|
unsigned char id; |
|
unsigned char length; |
|
unsigned int* data; |
|
} Envelope; |
|
|
|
void fill_buffer(char* buffer, char* filename) { |
|
FILE *fd; |
|
|
|
fd = fopen(filename, "r"); |
|
if (fd == NULL) { |
|
perror("File open errror"); |
|
} |
|
|
|
// Read in the whole dump |
|
if (fread(buffer, FILE_LENGTH, 1, fd) != 1) { |
|
perror("File wasn't read properly, or wasn't the right size"); |
|
} |
|
} |
|
|
|
int print_envelope(char* buffer, int offset) { |
|
Envelope* ps = (Envelope*)(buffer + offset); |
|
|
|
printf("PS Key (id: 0x%X)\n", ps->id); |
|
printf("---------------------------\n"); |
|
printf(" Length: %hhu\n", ps->length); |
|
printf(" Data: \n "); |
|
|
|
//if (ps->length == 0) |
|
// return -1; |
|
|
|
unsigned char* data = (unsigned char*)ps + 2; |
|
for (int i = 0; i < ps->length; i++) |
|
printf("%04X ", data[i]); |
|
|
|
printf("\n\n"); |
|
|
|
return offset + (ps->length * 2) + 2; |
|
} |
|
|
|
int main(int count, char** args) { |
|
Header* head; |
|
char buffer[FILE_LENGTH]; |
|
fill_buffer(buffer, args[1]); |
|
int offset = PS_OFFSET + atoi(args[2]); |
|
|
|
// Lay the header overtop of or binary dumpage |
|
head = (Header*)buffer; |
|
|
|
// Print header infos: |
|
printf("\nMemory Dump Information:\n"); |
|
printf("===========================\n"); |
|
printf(" Chip ID: %2X\n", head->id); |
|
printf(" Version: %hhu.%hhu\n", head->version_major, head->version_minor); |
|
printf(" Key Length: %u\n", head->pskey_length); |
|
printf(" Data Length: %u\n", head->data_length); |
|
printf(" EEPROM: %02X\n", head->eeprom_flag); |
|
printf("\n"); |
|
|
|
while (offset < head->pskey_length) { |
|
offset = print_envelope(buffer, offset); |
|
|
|
if (offset == -1) { |
|
printf("Lost pointer\n\n"); |
|
return -1; |
|
} |
|
} |
|
|
|
printf("\n\n"); |
|
} |