-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunpacker.c
55 lines (47 loc) · 1.62 KB
/
unpacker.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
#include <exec/types.h>
#include "hdrs/packer.h"
/*------------------------------------------------------------------------*/
#define UGetByte() (*source++)
#define UPutByte(c) (*dest++ = (c))
/*------------------------------------------------------------------------*/
BOOL UnPackRow(BYTE **pSource, BYTE **pDest, WORD srcBytes0, WORD dstBytes0)
{
REGISTER BYTE *source=*pSource;
REGISTER BYTE *dest =*pDest;
REGISTER WORD n;
REGISTER BYTE c;
REGISTER WORD srcBytes=srcBytes0,
dstBytes=dstBytes0;
BOOL error=TRUE;
WORD minus128=-128;
while(dstBytes>0){
if((srcBytes-=1)<0)
goto ErrorExit;
n=UGetByte();
if(n>=0){
n+=1;
if((srcBytes-=n)<0)
goto ErrorExit;
if((dstBytes-=n)<0)
goto ErrorExit;
do {
UPutByte(UGetByte());
} while(--n>0);
}else if(n!=minus128){
n=-n+1;
if((srcBytes-=1)<0)
goto ErrorExit;
if((dstBytes-=n)<0)
goto ErrorExit;
c=UGetByte();
do {
UPutByte(c);
} while(--n>0);
}
}
error=FALSE;
ErrorExit:
*pSource=source;
*pDest =dest;
return(error);
}