-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrashunpacker.c
More file actions
64 lines (59 loc) · 1.33 KB
/
Copy pathcrashunpacker.c
File metadata and controls
64 lines (59 loc) · 1.33 KB
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
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
struct pasc
{
unsigned a : 7;
unsigned b : 7;
unsigned c : 7;
unsigned d : 7;
unsigned e : 7;
unsigned f : 7;
unsigned g : 7;
unsigned h : 7;
} __attribute__((packed));
void unpackA(char *, uint32_t);
typedef struct pasc pasc_t;
void unpackA(char *inbuf, uint32_t length)
{
pasc_t packs;
unsigned i = 0;
length = (length * 8) / 7;
while (i < length)
{
packs = *(pasc_t *)&inbuf[i];
bcopy(&inbuf[i + 7], &inbuf[i + 8], MAX(0, (int)(length - i - 8)));
inbuf[i++] = packs.a;
inbuf[i++] = packs.b;
inbuf[i++] = packs.c;
inbuf[i++] = packs.d;
inbuf[i++] = packs.e;
inbuf[i++] = packs.f;
inbuf[i++] = packs.g;
inbuf[i++] = packs.h;
}
}
int main(int argc, char *argv[])
{
if (argc < 2)
{
printf("Usage: %s [file]\n", argv[0]);
return 1;
}
FILE *f = fopen(argv[1], "rb");
if (f == NULL)
{
perror("Failed to open file");
return 1;
}
fseek(f, 0, SEEK_END);
uint32_t size = ftell(f);
fseek(f, 0, SEEK_SET);
char *buffer = malloc(size + 1);
fread(buffer, size, 1, f);
fclose(f);
unpackA(buffer, size);
printf("%s\n", buffer);
return 0;
}