-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathpatcher9x.h
257 lines (204 loc) · 8.81 KB
/
patcher9x.h
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/******************************************************************************
* Copyright (c) 2022 Jaroslav Hensl *
* *
* Permission is hereby granted, free of charge, to any person *
* obtaining a copy of this software and associated documentation *
* files (the "Software"), to deal in the Software without *
* restriction, including without limitation the rights to use, *
* copy, modify, merge, publish, distribute, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following *
* conditions: *
* *
* The above copyright notice and this permission notice shall be *
* included in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, *
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
* OTHER DEALINGS IN THE SOFTWARE. *
* *
*******************************************************************************/
#ifndef __PATCHER9X_INCLUDED__
#define __PATCHER9X_INCLUDED__
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <mspack.h>
#include <filesystem.h>
#include <extstring.h>
#include <pew.h>
#include "nocrt.h"
#include "version.h"
/*
* Program flow constants
*/
/* error codes */
#define PATCH_OK 0
#define PATCH_E_READ 1
#define PATCH_E_WRITE 2
#define PATCH_E_CHECK 3
#define PATCH_E_MEM 4
#define PATCH_E_OVERWRITE 5
#define PATCH_E_WRONG_TYPE 6
#define PATCH_E_CONVERT 7
#define PATCH_E_NOTFOUND 8
#define PATCH_E_PATCHED 9
#define PATCH_E_NOTFOUNDINCAB 10
#define PATCH_E_NOTFOUNDINCABS 11
/* compresion control */
#define PATCH_FORCE_W3 0x01000000
#define PATCH_FORCE_W4 0x02000000
/*
* Patches and it's versions
*/
/* target is W3/W4 file */
#define PATCH_VX_PACK 0x80000000
/* target could be part of VMM32 */
#define PATCH_VX_UNPACK 0x40000000
/* not really apply patch, only do search for them */
#define PATCH_DRY 0x10000000
/* TLB patch for windows 98 */
#define PATCH_VMM98 0x00000001
/* TLB patch for windows me */
#define PATCH_VMMME 0x00000002
/* TLB patch for windows 98 (for updated VMM.VXD) */
#define PATCH_VMM98_V2 0x00000004
/* CPU speed patch with 1 000 000 (0xF4240) LOOP */
#define PATCH_CPU_SPEED_V1 0x00000010
/* CPU speed patch with 2 000 000 (0x1E8480) LOOP */
#define PATCH_CPU_SPEED_V2 0x00000020
/* CPU speed patch with 10 000 000 (0x989680) LOOP */
#define PATCH_CPU_SPEED_V3 0x00000040
/* CPU speed patch with 10 000 000 (0x989680) LOOP + manually patched */
#define PATCH_CPU_SPEED_V4 0x00000080
#define PATCH_CPU_SPEED_V5 0x00000100
#define PATCH_CPU_SPEED_V6 0x00000200
#define PATCH_CPU_SPEED_V7 0x00000400
#define PATCH_CPU_SPEED_V8 0x00000800
/* CPU speed patch (for NDIS) with 1048576 (0x00100000) LOOP */
#define PATCH_CPU_SPEED_NDIS_V1 0x00001000
/* CPU speed patch (for NDIS) with 1 048 576 (0x00100000) LOOP with zero divide detection (WINDOWS 98 SE) */
#define PATCH_CPU_SPEED_NDIS_V2 0x00002000
/* CPU speed patch (for NDIS) with 10 485 760 (0x00A00000) LOOP - patched */
#define PATCH_CPU_SPEED_NDIS_V3 0x00008000
/* TLB patch for windows 98 (old version) */
#define PATCH_VMM98_OLD 0x00010000
/* TLB patch for windows 98 (oldversion) (for updated VMM.VXD) */
#define PATCH_VMM98_OLD_V2 0x00020000
/* TLB patch for windows 98 (older but more universal) */
#define PATCH_VMM98_SIMPLE 0x00040000
/* TLB patch for windows 98 (older but more universal - for updated VMM.VXD) */
#define PATCH_VMM98_SIMPLE_V2 0x00080000
/* sumary defs */
#define PATCH_CPU_SPEED_ALL (PATCH_CPU_SPEED_V1|PATCH_CPU_SPEED_V2|PATCH_CPU_SPEED_V3|PATCH_CPU_SPEED_V4|\
PATCH_CPU_SPEED_V5|PATCH_CPU_SPEED_V6|PATCH_CPU_SPEED_V7|PATCH_CPU_SPEED_V8)
#define PATCH_CPU_SPEED_NDIS_ALL (PATCH_CPU_SPEED_NDIS_V1|PATCH_CPU_SPEED_NDIS_V2|PATCH_CPU_SPEED_NDIS_V3)
#define PATCH_VMM_ALL (PATCH_VMM98|PATCH_VMMME|PATCH_VMM98_V2|PATCH_VMM98_OLD|PATCH_VMM98_OLD_V2|PATCH_VMM98_SIMPLE|PATCH_VMM98_SIMPLE_V2)
/* program modes */
#define MODE_AUTO 1 /* automaticly determine action from path */
#define MODE_INTERACTIVE 2 /* same as auto but ask user if sure */
#define MODE_EXACT 3 /* use steps by command line */
#define MODE_BATCH 4 /* use one step on command line */
/* patch lookup flags */
#define PATCH_LOOKUP_CABS 1 /* scan cab files */
#define PATCH_LOOKUP_EXTRACTWX 2 /* extract files from VX archives */
#define PATCH_LOOKUP_NO_VMM32 4 /* dont touch VMM32.VXD */
#define PATCH_LOOKUP_ONE_CAB 8 /* extract files from one specified cab */
/* paths and files */
#define DEFAULT_PATH "C:\\Windows\\System"
#define DEFAULT_INPUT_VX "VMM"
#define DEFAULT_INPUT_CAB "VMM32.VXD"
#define DEFAULT_OUTPUT_LE "VMM.VXD"
#define DEFAULT_OUTPUT_VX "VMM32.VXD"
/*
* Platform selection
*/
#if defined(__MSDOS__) || defined(_WIN32)
#define RUN_WITHOUT_ARGS
#endif
#if defined(__MSDOS__)
#define DOS_MODE
#endif
/*
* Structures
*/
typedef struct _options_t
{
int mode;
const char *path;
int print_help;
int print_version;
int cputest;
int cab_extract;
int wx_extract;
int patch;
int force_w3;
int force_w4;
int no_backup;
uint32_t patches;
uint32_t unmask;
//int millennium;
const char *input;
const char *output;
} options_t;
typedef struct _pmodfiles_t *pmodfiles_t;
struct scanned_files_list;
typedef struct scanned_files_list scanned_files_list_t;
/*
* Functions
*/
/* unpack.c */
int cab_search_unpack(const char *dirname, const char *infilename, const char *out);
int cab_unpack(const char *srccab, const char *infilename, const char *out, scanned_files_list_t *list);
int wx_unpack(const char *src, const char *infilename, const char *out, const char *tmpname);
int wx_to_w3(const char *in, const char *out);
int wx_to_w4(const char *in, const char *out);
struct cab_filelist;
typedef struct cab_filelist cab_filelist_t;
cab_filelist_t *cab_filelist_open(const char *file);
const char *cab_filelist_get(cab_filelist_t *list);
void cab_filelist_close(cab_filelist_t *list);
struct vxd_filelist;
typedef struct vxd_filelist vxd_filelist_t;
vxd_filelist_t *vxd_filelist_open(const char *file, const char *tmp);
const char *vxd_filelist_get(vxd_filelist_t *list);
void vxd_filelist_close(vxd_filelist_t *list);
/* patch.c */
int patch_apply(const char *srcfile, const char *dstfile, int flags, int *applied);
int patch_apply_wx(const char *srcfile, const char *dstfile, const char *tmpname, int flags);
int patch_backup_file(const char *path, int nobackup);
int patch_selected(FILE *fp, const char *dstfile, uint32_t to_apply, uint32_t *out_applied, uint32_t *out_exists);
void patch_print(uint32_t patches);
/* files.c */
pmodfiles_t files_lookup(const char *path, uint32_t global_flags, uint32_t global_unmask, uint32_t lookup_flags);
pmodfiles_t files_apply(const char *upath, uint32_t global_flags, uint32_t global_unmask);
int files_status(pmodfiles_t list);
void files_cleanup(pmodfiles_t *plist);
int files_commit(pmodfiles_t *plist, int nobackup);
void files_print(pmodfiles_t list);
/* exact.c */
int run_exact(options_t *options);
/* batch.c */
int batch_arg(const char *arg);
int batch_run(options_t *options, int id, int argc, char **argv);
void batch_help();
/* trace.c */
void print_trace();
FILE *fopen_log(const char *fn, const char *mode, const char *file, int line);
#define FOPEN_LOG(_fn, _mode) fopen_log(_fn, _mode, __FILE__, __LINE__)
void print_error(int code, const char *file, int line);
#define report_error(_code) print_error(_code, __FILE__, __LINE__);
/* cputest.c */
void cputest();
/* pwin32.c */
void set_default_path(char *default_path);
/*
* Globals
*/
extern char patcher9x_default_path[MAX_PATH];
#endif /* __PATCHER9X_INCLUDED__ */