mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-26 00:38:55 +05:30
Added function for iterating through offsets
This commit is contained in:
parent
7179aba632
commit
37ce23db73
24
main.c
24
main.c
@ -4,6 +4,21 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
void unpackpld(const char *buffer, struct PldHeader *pldh) {
|
||||||
|
unsigned int i = 0;
|
||||||
|
char *wbuffer = NULL; // write buffer that will change.
|
||||||
|
unsigned int wsize = 0; // size of wbuffer.
|
||||||
|
for (i; (i + 1) < (pldh -> numOffset); i++) {
|
||||||
|
printf("start: %x - end: %x\n",
|
||||||
|
pldh -> offsets[i],
|
||||||
|
pldh -> offsets[i + 1]);
|
||||||
|
/* wsize = offsets[i + 1] - offsets[i];
|
||||||
|
wbuffer = (char*)malloc(sizeof(char) * wsize);
|
||||||
|
memcpy(wbuffer, buffer[offsets[i]], wsize); */
|
||||||
|
}
|
||||||
|
free(wbuffer);
|
||||||
|
}
|
||||||
|
|
||||||
void disp_pldheader(struct PldHeader *x) {
|
void disp_pldheader(struct PldHeader *x) {
|
||||||
printf("number of offsets = %i\n", x -> numOffset);
|
printf("number of offsets = %i\n", x -> numOffset);
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
@ -14,8 +29,10 @@ void disp_pldheader(struct PldHeader *x) {
|
|||||||
|
|
||||||
bool read_pldheader(const char *buffer) {
|
bool read_pldheader(const char *buffer) {
|
||||||
int32_t *n = (int32_t*)buffer;
|
int32_t *n = (int32_t*)buffer;
|
||||||
struct PldHeader *ph = (struct PldHeader*)malloc(sizeof(struct PldHeader));
|
struct PldHeader *ph = (struct PldHeader*)malloc(
|
||||||
unsigned int size_offsets = sizeof(uint32_t) * n[0];
|
sizeof(struct PldHeader)
|
||||||
|
);
|
||||||
|
uint32_t size_offsets = sizeof(uint32_t) * n[0];
|
||||||
ph -> offsets = (uint32_t*)malloc(size_offsets);
|
ph -> offsets = (uint32_t*)malloc(size_offsets);
|
||||||
if (ph -> offsets == NULL) {
|
if (ph -> offsets == NULL) {
|
||||||
perror("Error 4: ");
|
perror("Error 4: ");
|
||||||
@ -27,6 +44,7 @@ bool read_pldheader(const char *buffer) {
|
|||||||
ph -> numOffset = n[0];
|
ph -> numOffset = n[0];
|
||||||
memcpy(ph -> offsets, buffer + sizeof(int32_t), size_offsets);
|
memcpy(ph -> offsets, buffer + sizeof(int32_t), size_offsets);
|
||||||
disp_pldheader(ph);
|
disp_pldheader(ph);
|
||||||
|
unpackpld(buffer, ph);
|
||||||
free(ph -> offsets);
|
free(ph -> offsets);
|
||||||
free(ph);
|
free(ph);
|
||||||
return true;
|
return true;
|
||||||
@ -65,7 +83,7 @@ bool readpld(const char *fname) {
|
|||||||
|
|
||||||
int main(int argc, char ** argv) {
|
int main(int argc, char ** argv) {
|
||||||
char *filename = argv[1];
|
char *filename = argv[1];
|
||||||
bool status = readpld(filename);
|
bool status = readpld(filename);
|
||||||
if (status) {
|
if (status) {
|
||||||
printf("Read OK");
|
printf("Read OK");
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user