2018-04-02 12:15:30 +05:30
|
|
|
#include "devil1pld.h"
|
2018-04-02 13:51:21 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
|
2018-04-19 17:49:02 +05:30
|
|
|
static bool getpldh(struct PldHeader*, const char*);
|
|
|
|
|
|
|
|
static int sizeofpldstruct(struct PldHeader*, unsigned int, unsigned int);
|
|
|
|
|
|
|
|
static void printpldh(struct PldHeader*);
|
|
|
|
|
2018-04-18 08:33:06 +05:30
|
|
|
fn_devil1pld const DEVIL1PLD = {getpldh, sizeofpldstruct, printpldh};
|
2018-04-18 08:12:28 +05:30
|
|
|
|
2018-04-18 08:07:59 +05:30
|
|
|
static bool getpldh(struct PldHeader *ph, const char *filedata) {
|
2018-04-07 03:12:52 +05:30
|
|
|
bool good = false;
|
|
|
|
if (ph != NULL && filedata != NULL) {
|
|
|
|
ph -> numOffset = (int32_t)filedata[0];
|
|
|
|
ph -> offsets = (uint32_t*)(filedata + sizeof(int32_t));
|
2018-04-19 18:28:35 +05:30
|
|
|
if ( ph->numOffset > 0 ) {
|
|
|
|
good = true;
|
|
|
|
}
|
2018-04-07 03:12:52 +05:30
|
|
|
}
|
|
|
|
return good;
|
|
|
|
}
|
|
|
|
|
2018-04-07 04:18:44 +05:30
|
|
|
// determine the size of the i-th pld structure
|
2018-04-18 08:07:59 +05:30
|
|
|
static int sizeofpldstruct(struct PldHeader *ph, unsigned int i, unsigned int max) {
|
2018-04-07 04:18:44 +05:30
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-04-18 08:07:59 +05:30
|
|
|
static void printpldh(struct PldHeader *ph) {
|
2018-04-02 13:51:21 +05:30
|
|
|
if (ph == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("number of offsets = %i\n", ph -> numOffset);
|
2018-04-19 17:49:02 +05:30
|
|
|
printf("offsets = %p\n", ph -> offsets);
|
2018-04-02 13:51:21 +05:30
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < ph -> numOffset; i++) {
|
|
|
|
printf("offset %i = %x\n", i, ph -> offsets[i]);
|
|
|
|
}
|
|
|
|
}
|