forked from darknesswind/IsDcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisDcc.cpp
158 lines (127 loc) · 3.41 KB
/
isDcc.cpp
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
isDcc
(c) 1998 Andrew de Quincey
See README.TXT for copying/distribution/modification details.
*/
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <string.h>
#include <conio.h>
#include "common.h"
#include "util.h"
#include "ishield.h"
#include "header.h"
#include "decode.h"
#include "output.h"
char version[] = "3.1";
int Scramble(char *filename)
{
long size;
unsigned char *buffer;
unsigned char *xbuffer;
int XOR_VAL = 0xF1;
char txt[256];
int j;
FILE *f1;
FILE *f = fopen(filename,"rb");
fseek(f,0,SEEK_END);
size = ftell(f);
fseek(f,0,SEEK_SET);
buffer = (unsigned char *)malloc(size);
xbuffer = (unsigned char *)malloc(size);
fread(buffer,size,1,f);
fclose(f);
for(j=0;j<size;j++)
{
int c = buffer[j];
c += (j % 71);
c = (( c << 2)&0xFF) | ((c>>6)&0x3);
c ^= XOR_VAL;
xbuffer[j] = c;
}
sprintf(txt,"%s.inx",filename);
f1 = fopen(txt,"wb");
fwrite(xbuffer,size,1,f1);
fclose(f1);
free(xbuffer);
free(buffer);
return 0;
}
int unScramble(char *filename)
{
unsigned char *buffer;
unsigned char *xbuffer;
long size;
int XOR_VAL = 0xF1;
int b,j;
char txt[256];
FILE *f1;
FILE *f = fopen(filename,"rb");
fseek(f,0,SEEK_END);
size = ftell(f);
fseek(f,0,SEEK_SET);
buffer = (unsigned char *)malloc(size);
xbuffer = (unsigned char *)malloc(size);
fread(buffer,size,1,f);
fclose(f);
for(j=0;j<size;j++)
{
int c = buffer[j];
c ^= XOR_VAL;
b = (unsigned char)((c >> 2) | (c << 6)) - (j % 71);
xbuffer[j] = b;
}
sprintf(txt,"%s.dec",filename);
f1 = fopen(txt,"wb");
fwrite(xbuffer,size,1,f1);
fclose(f1);
return 0;
}
int main(int argc, char* argv[])
{
int fd;
ISData isData;
fprintf(stderr, "isDcc v%s, (c) 1998 Andrew de Quincey\n", version);
fprintf(stderr, "isDcc v2.00, (c) 2000 Mr. Smith\n"); //version2
fprintf(stderr, "isDcc v2.10, (c) 2001 Mr. Smith\n"); //version2.1
fprintf(stderr, "isDcc v3.10, (c) 2001 Mr Won't tell:) \n"); //version3.1
fprintf(stderr, "Syntax : isDcc -u filename.inx //To Unscramble the script file\n"); //version3.1
fprintf(stderr, "Syntax : isDcc -s filename.inx.dec //To Scramble the script file\n"); //version3.1
fprintf(stderr, "Syntax : isDcc filename.inx.dec //To desassemble the script file\n"); //version3.1
// --------------------------------------------------------------------------
// check params
// modified for version2
if ((argc > 3 ) || ( argc < 2))
exit(1);
if ( strcmp(argv[1],"-u") == 0 )
{
unScramble(argv[2]);
exit(0);
}
if ( strcmp(argv[1],"-s") == 0 )
{
Scramble(argv[2]);
exit(0);
}
argnum = argc;
// --------------------------------------------------------------------------
// open file
if ((fd = open(argv[argc-1], O_RDONLY | O_BINARY)) == -1)
error("Cannot open file %s for reading\n", argv[argc-1]); //version2
// --------------------------------------------------------------------------
// initialise the opTable stuff
initDecode();
// --------------------------------------------------------------------------
// parse the header
parseHeader(fd, &isData);
// decode the code
decode(fd, &isData);
// do any extra conversion on the code
//optimise(&isData);
// output it
output(fd, &isData, 1);
close(fd);
}