-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_prc_data.c
106 lines (83 loc) · 1.82 KB
/
read_prc_data.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <stdio.h>
#include <stdlib.h>
#include "rom.h"
#include "DataPrv.h"
#include "SystemResources.h"
#include "extract.h"
#include "utils.h"
#include "byte_swap.h"
void* DecompressDATA (void* data,
int* pLen)
{
char* pData = (char*)data;
void* pRetData = NULL;
char* pCopyData = NULL;
if (! pData || ! pLen)
return NULL;
/* Skip over 4 bytes of offset to xrefs */
pData += 4;
memcpy(pLen, pData, sizeof(*pLen));
/* REMOVE FOR PALM */ *pLen = BYTE_SWAP_32(*pLen);
/* The length in the header is the negative of the actual length */
*pLen = 0 - *pLen;
pData += 4;
pRetData = (void*)malloc(*pLen);
if (! pRetData)
return NULL;
memset(pRetData, 0, *pLen);
/*
* The data comes in blocks of at most 128-bytes.
* These blocks consist of 1-byte of length followed
* by the bytes of data.
*/
pCopyData = (char*)pRetData;
while (*pData & 0x80)
{
unsigned char BlkLen = (*pData - 0x7F);
memcpy(pCopyData, pData+1, BlkLen);
pData += BlkLen + 1;
pCopyData += BlkLen;
}
return pRetData;
}
void OutputBytes (void* data,
int nBytes)
{
unsigned char* pData = (unsigned char*)data;
int idex;
fprintf (stdout, "%d bytes\n", nBytes);
for (idex = 0; idex < nBytes; idex++)
{
if (idex && ((idex % 16) == 0))
fprintf (stdout, "\n");
fprintf (stdout, "%02X ", pData[idex]);
}
fprintf (stdout, "\n");
}
int main (int argc,
char* argv[])
{
PRCPtr pPRC;
RsrcEntryPtr pRsrc;
if ((pPRC = ReadPRC(argv[1])) == NULL)
{
fprintf (stderr, "Error\n");
return -1;
}
if ((pRsrc = LocateResource(pPRC->pDB, sysResTAppGData, 0)) != NULL)
{
char* pData = (char*)pRsrc->localChunkID;
int nBytes;
void* pBlock = DecompressDATA(pData, &nBytes);
if (! pBlock)
{
fprintf (stderr, "Error 2\n");
}
else
{
OutputBytes(pBlock, nBytes);
}
}
FreePRC(pPRC);
return 0;
}