2018-04-02 12:15:30 +05:30
|
|
|
#include "devil1pld.h"
|
2018-04-02 13:51:21 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2018-04-02 12:15:30 +05:30
|
|
|
|
2018-04-07 03:12:52 +05:30
|
|
|
/* struct PldHeader *getpldh(const char *filedata) {
|
2018-04-02 13:51:21 +05:30
|
|
|
if (filedata == NULL) {
|
2018-04-02 12:15:30 +05:30
|
|
|
return NULL;
|
|
|
|
}
|
2018-04-02 13:51:21 +05:30
|
|
|
int32_t *n = (int32_t*)filedata;
|
2018-04-02 12:15:30 +05:30
|
|
|
struct PldHeader *ph = (struct PldHeader*)malloc(
|
|
|
|
sizeof(struct PldHeader)
|
|
|
|
);
|
|
|
|
uint32_t size_offsets = sizeof(uint32_t) * n[0];
|
|
|
|
ph -> offsets = (uint32_t*)malloc(size_offsets);
|
|
|
|
if (ph -> offsets == NULL) {
|
|
|
|
perror("Error 4: ");
|
|
|
|
free(ph);
|
|
|
|
free(ph -> offsets);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// set data of struct.
|
|
|
|
ph -> numOffset = n[0];
|
2018-04-02 13:51:21 +05:30
|
|
|
memcpy(ph -> offsets, filedata + sizeof(int32_t), size_offsets);
|
2018-04-02 12:15:30 +05:30
|
|
|
return ph;
|
2018-04-07 03:12:52 +05:30
|
|
|
} */
|
2018-04-02 13:51:21 +05:30
|
|
|
|
|
|
|
void destroypldh(struct PldHeader *ph) {
|
|
|
|
free(ph -> offsets);
|
|
|
|
free(ph);
|
|
|
|
ph = NULL;
|
|
|
|
}
|
|
|
|
|
2018-04-07 03:12:52 +05:30
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-04-02 13:51:21 +05:30
|
|
|
void printpldh(struct PldHeader *ph) {
|
|
|
|
if (ph == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
printf("number of offsets = %i\n", ph -> numOffset);
|
2018-04-07 03:12:52 +05:30
|
|
|
printf("offsets = %x\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]);
|
|
|
|
}
|
|
|
|
}
|