-
Notifications
You must be signed in to change notification settings - Fork 1
/
load_mac.c
160 lines (141 loc) · 4.71 KB
/
load_mac.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
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
/*
This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.net
Copyright (C) 2018-2023 Daniel Marschall, ViaThinkSoft
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "ff.h"
#include <Resources.h>
#include "file_compat.h"
FFLoadingResult readPARMresource(HMODULE hm){
FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
Handle h;
if( (h = Get1Resource(PARM_TYPE,PARM_ID_NEW)) ||
(h = Get1Resource(PARM_TYPE,PARM_ID_OLD)) )
{
HLock(h);
if(GetHandleSize(h) == sizeof(PARM_T)) {
res = readPARM(&gdata->parm, *h);
gdata->obfusc = false;
ReleaseResource(h);
} else {
// PARM has wrong size. Should not happen
gdata->obfusc = false;
ReleaseResource(h);
return MSG_INVALID_FILE_SIGNATURE_ID;
}
}
else if( ((h = Get1Resource(OBFUSCDATA_TYPE_NEW,OBFUSCDATA_ID_NEW)) ||
(h = Get1Resource(OBFUSCDATA_TYPE_OLD,OBFUSCDATA_ID_OLD))) )
{
HLock(h);
if(GetHandleSize(h) == sizeof(PARM_T)) {
deobfusc((PARM_T*)*h);
res = readPARM(&gdata->parm, *h);
gdata->obfusc = true;
ReleaseResource(h);
} else {
// Obfuscated PARM has wrong size. Should not happen
gdata->obfusc = false;
ReleaseResource(h);
return MSG_INCOMPATIBLE_OBFUSCATION_ID;
}
}
if (res != LOADING_OK) {
gdata->obfusc = false;
}
return res;
}
FFLoadingResult Boolean readmacplugin(StandardFileReply *sfr){
FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
short rrn = FSpOpenResFile(&sfr->sfFile,fsRdPerm);
if(rrn != -1){
res = readPARMresource(NULL);
CloseResFile(rrn);
}
else
res = MSG_CANNOT_OPEN_FILE_ID;
return res;
}
FFLoadingResult loadfile(StandardFileReply *sfr){
Boolean readok = false;
FInfo fndrInfo;
FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
if(FSpGetFInfo(&sfr->sfFile,&fndrInfo) == noErr){
// first try to read text parameters (AFS, TXT, PFF)
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
if (LOADING_OK == (res = readfile_afs_pff(sfr))) {
parm_reset(true, false, true, false);
gdata->obfusc = false;
return LOADING_OK;
}
if (res == MSG_INVALID_FILE_SIGNATURE_ID) res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
}
// Try to read the file as FFL file
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
if (LOADING_OK == (res = (readfile_ffl(sfr)))) {
parm_reset(true, true, true, true);
gdata->obfusc = false;
return LOADING_OK;
}
if (res == MSG_INVALID_FILE_SIGNATURE_ID) res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
}
// then try "Filters Unlimited" file (FFX)
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
if (LOADING_OK == (res = (readfile_ffx(sfr)))) {
gdata->obfusc = false;
return LOADING_OK;
}
if (res == MSG_INVALID_FILE_SIGNATURE_ID) res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
}
// then try "PluginCommander TXT" file (TXT)
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
if (LOADING_OK == (res = (readfile_picotxt(sfr)))) {
gdata->obfusc = false;
return LOADING_OK;
}
}
// Is it a "GIMP UserFilter (GUF)" file? (Only partially compatible with Filter Factory!!!)
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
if (LOADING_OK == (res = (readfile_guf(sfr)))) {
return LOADING_OK;
}
}
// Try Mac plugin resource
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
if (LOADING_OK == (res = (readmacplugin(sfr)))) {
if (gdata->parm.iProtected) {
parm_reset(true, true, true, true);
res = MSG_FILTER_PROTECTED_ID;
} else {
return LOADING_OK;
}
}
}
// Try Windows resources (we need to do a binary scan)
// Note that we cannot detect obfuscated filters here!
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
if (LOADING_OK == (res = (readfile_8bf(sfr)))) {
if (gdata->parm.iProtected) {
parm_reset(true, true, true, true);
res = MSG_FILTER_PROTECTED_ID;
} else {
return LOADING_OK;
}
}
}
return res;
} else {
return MSG_CANNOT_OPEN_FILE_ID;
}
}