#include "devil1pld.h" #include fn_devil1pld const DEVIL1PLD = {getpldh, sizeofpldstruct, printpldh}; static bool getpldh(struct PldHeader *ph, const char *filedata) { bool good = false; if (ph != NULL && filedata != NULL) { ph -> numOffset = (int32_t)filedata[0]; ph -> offsets = (uint32_t*)(filedata + sizeof(int32_t)); good = true; } return good; } // determine the size of the i-th pld structure static int sizeofpldstruct(struct PldHeader *ph, unsigned int i, unsigned int max) { unsigned int size = -1; if (ph == NULL) { fprintf(stderr, "Error: given null pointer\n"); return size; } if (i > ph -> numOffset) { fprintf(stderr, "Error: i exceeds pldHeader -> numOffset\n"); return size; } unsigned int start = 0, end = 0; start = ph -> offsets[i]; end = (i == (ph -> numOffset) - 1) ? max : ph -> offsets[i + 1]; size = end - start; return size; } static void printpldh(struct PldHeader *ph) { if (ph == NULL) { return; } printf("number of offsets = %i\n", ph -> numOffset); printf("offsets = %x\n", ph -> offsets); unsigned int i; for (i = 0; i < ph -> numOffset; i++) { printf("offset %i = %x\n", i, ph -> offsets[i]); } }