Subversion Repositories filter_foundry

Rev

Rev 550 | Rev 554 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 550 Rev 552
Line 22... Line 22...
22
 
22
 
23
#include <Resources.h>
23
#include <Resources.h>
24
 
24
 
25
#include "file_compat.h"
25
#include "file_compat.h"
26
 
26
 
27
Boolean readPARMresource(HMODULE hm,char **reason){
27
FFLoadingResult readPARMresource(HMODULE hm){
28
        Boolean res = false;
28
        FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
29
        Handle h;
29
        Handle h;
30
 
30
 
31
        if( (h = Get1Resource(PARM_TYPE,PARM_ID_NEW)) ||
31
        if( (h = Get1Resource(PARM_TYPE,PARM_ID_NEW)) ||
32
            (h = Get1Resource(PARM_TYPE,PARM_ID_OLD)) )
32
            (h = Get1Resource(PARM_TYPE,PARM_ID_OLD)) )
33
        {
33
        {
34
                HLock(h);
34
                HLock(h);
35
                if(GetHandleSize(h) == sizeof(PARM_T)) {
35
                if(GetHandleSize(h) == sizeof(PARM_T)) {
36
                        res = readPARM(*h, &gdata->parm, reason, 0 /*Mac format resource*/);
36
                        res = readPARM(&gdata->parm, *h, 0 /*Mac format resource*/);
37
                        gdata->obfusc = false;
37
                        gdata->obfusc = false;
38
                        ReleaseResource(h);
38
                        ReleaseResource(h);
39
                } else {
39
                } else {
40
                        // PARM has wrong size. Should not happen
40
                        // PARM has wrong size. Should not happen
41
                        gdata->obfusc = false;
41
                        gdata->obfusc = false;
42
                        ReleaseResource(h);
42
                        ReleaseResource(h);
43
                        return false;
43
                        return MSG_INVALID_FILE_SIGNATURE_ID;
44
                }
44
                }
45
        }
45
        }
46
        else if( ((h = Get1Resource(OBFUSCDATA_TYPE_NEW,OBFUSCDATA_ID_NEW)) ||
46
        else if( ((h = Get1Resource(OBFUSCDATA_TYPE_NEW,OBFUSCDATA_ID_NEW)) ||
47
                  (h = Get1Resource(OBFUSCDATA_TYPE_OLD,OBFUSCDATA_ID_OLD))) )
47
                  (h = Get1Resource(OBFUSCDATA_TYPE_OLD,OBFUSCDATA_ID_OLD))) )
48
        {
48
        {
49
                HLock(h);
49
                HLock(h);
50
                if(GetHandleSize(h) == sizeof(PARM_T)) {
50
                if(GetHandleSize(h) == sizeof(PARM_T)) {
51
                        deobfusc((PARM_T*)*h);
51
                        deobfusc((PARM_T*)*h);
52
                        res = readPARM(*h, &gdata->parm, reason, 0 /*Mac format resource*/);
52
                        res = readPARM(&gdata->parm, *h, 0 /*Mac format resource*/);
53
                        gdata->obfusc = true;
53
                        gdata->obfusc = true;
54
                        ReleaseResource(h);
54
                        ReleaseResource(h);
55
                } else {
55
                } else {
56
                        // Obfuscated PARM has wrong size. Should not happen
56
                        // Obfuscated PARM has wrong size. Should not happen
57
                        gdata->obfusc = false;
57
                        gdata->obfusc = false;
58
                        ReleaseResource(h);
58
                        ReleaseResource(h);
59
                        return false;
59
                        return MSG_INCOMPATIBLE_OBFUSCATION_ID;
60
                }
60
                }
61
        }
61
        }
62
        if (!res) {
62
        if (!res) {
63
                gdata->obfusc = false;
63
                gdata->obfusc = false;
64
        }
64
        }
65
        return res;
65
        return res;
66
}
66
}
67
 
67
 
68
static Boolean readmacplugin(StandardFileReply *sfr,char **reason){
68
FFLoadingResult Boolean readmacplugin(StandardFileReply *sfr){
69
        Boolean res = false;
69
        FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
70
        short rrn = FSpOpenResFile(&sfr->sfFile,fsRdPerm);
70
        short rrn = FSpOpenResFile(&sfr->sfFile,fsRdPerm);
71
 
71
 
72
        if(rrn != -1){
72
        if(rrn != -1){
73
                if(readPARMresource(NULL,reason))
73
                res = readPARMresource(NULL);
74
                        res = true;
-
 
75
                CloseResFile(rrn);
74
                CloseResFile(rrn);
-
 
75
        }
76
        }else
76
        else
77
                *reason = "Could not open file.";
77
                res = MSG_CANNOT_OPEN_FILE_ID;
78
        return res;
78
        return res;
79
}
79
}
80
 
80
 
81
Boolean loadfile(StandardFileReply *sfr,char **reason){
81
FFLoadingResult loadfile(StandardFileReply *sfr){
82
        Boolean readok = false;
82
        Boolean readok = false;
83
        FInfo fndrInfo;
83
        FInfo fndrInfo;
84
 
-
 
85
        // The different read-functions will return true if the resource was successfully loaded,
84
        FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
86
        // or false otherwise. If *reason is set, then the answer is clearly "No". If the result
-
 
87
        // is just false, it means that the program should continue with the next read-function.
-
 
88
        *reason = NULL;
-
 
89
 
85
 
90
        if(FSpGetFInfo(&sfr->sfFile,&fndrInfo) == noErr){
86
        if(FSpGetFInfo(&sfr->sfFile,&fndrInfo) == noErr){
91
                // first try to read text parameters (AFS, TXT, PFF)
87
                // first try to read text parameters (AFS, TXT, PFF)
92
                if (*reason == NULL) {
88
                if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
93
                        if (readfile_afs_pff(sfr,reason)) {
89
                        if (0 == (res = readfile_afs_pff(sfr))) {
94
                                parm_reset(true, false, true, false);
90
                                parm_reset(true, false, true, false);
95
                                gdata->obfusc = false;
91
                                gdata->obfusc = false;
96
                                return true;
92
                                return 0;
97
                        }
93
                        }
98
                }
94
                }
99
 
95
 
100
                // Try to read the file as FFL file
96
                // Try to read the file as FFL file
101
                if (*reason == NULL) {
97
                if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
102
                        if (readfile_ffl(sfr,reason)) {
98
                        if (0 == (res = (readfile_ffl(sfr)))) {
103
                                parm_reset(true, true, true, true);
99
                                parm_reset(true, true, true, true);
104
                                gdata->obfusc = false;
100
                                gdata->obfusc = false;
105
                                return true;
101
                                return 0;
106
                        }
102
                        }
107
                }
103
                }
108
 
104
 
109
                // then try "Filters Unlimited" file (FFX)
105
                // then try "Filters Unlimited" file (FFX)
110
                if (*reason == NULL) {
106
                if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
111
                        if (readfile_ffx(sfr,reason)) {
107
                        if (0 == (res = (readfile_ffx(sfr)))) {
112
                                gdata->obfusc = false;
108
                                gdata->obfusc = false;
113
                                return true;
109
                                return 0;
114
                        }
110
                        }
115
                }
111
                }
116
 
112
 
117
                // then try "PluginCommander TXT" file (TXT)
113
                // then try "PluginCommander TXT" file (TXT)
118
                if (*reason == NULL) {
114
                if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
119
                        if (readfile_picotxt(sfr,reason)) {
115
                        if (0 == (res = (readfile_picotxt(sfr)))) {
120
                                gdata->obfusc = false;
116
                                gdata->obfusc = false;
121
                                return true;
117
                                return 0;
122
                        }
118
                        }
123
                }
119
                }
124
 
120
 
125
                // Is it a "GIMP UserFilter (GUF)" file? (Only partially compatible with Filter Factory!!!)
121
                // Is it a "GIMP UserFilter (GUF)" file? (Only partially compatible with Filter Factory!!!)
126
                if (*reason == NULL) {
122
                if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
127
                        if (readfile_guf(sfr,reason)) {
123
                        if (0 == (res = (readfile_guf(sfr)))) {
128
                                return true;
124
                                return 0;
129
                        }
125
                        }
130
                }
126
                }
131
 
127
 
132
                // Try Mac plugin resource
128
                // Try Mac plugin resource
133
                if (*reason == NULL) {
129
                if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
134
                        if (readmacplugin(sfr,reason)) {
130
                        if (0 == (res = (readmacplugin(sfr)))) {
135
                                if (gdata->parm.iProtected) {
131
                                if (gdata->parm.iProtected) {
136
                                        parm_reset(true, true, true, true);
132
                                        parm_reset(true, true, true, true);
137
                                        *reason = "The filter is protected.";
133
                                        res = MSG_FILTER_PROTECTED_ID;
138
                                } else {
134
                                } else {
139
                                        return true;
135
                                        return 0;
140
                                }
136
                                }
141
                        }
137
                        }
142
                }
138
                }
143
 
139
 
144
                // Try Windows resources (we need to do a binary scan)
140
                // Try Windows resources (we need to do a binary scan)
145
                // Note that we cannot detect obfuscated filters here!
141
                // Note that we cannot detect obfuscated filters here!
146
                if (*reason == NULL) {
142
                if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
147
                        if (readfile_8bf(sfr,reason)) {
143
                        if (0 == (res = (readfile_8bf(sfr)))) {
148
                                if (gdata->parm.iProtected) {
144
                                if (gdata->parm.iProtected) {
149
                                        parm_reset(true, true, true, true);
145
                                        parm_reset(true, true, true, true);
150
                                        *reason = "The filter is protected.";
146
                                        res = MSG_FILTER_PROTECTED_ID;
151
                                } else {
147
                                } else {
152
                                        return true;
148
                                        return 0;
153
                                }
149
                                }
154
                        }
150
                        }
155
                }
151
                }
156
 
152
 
157
                // We didn't had success. If we have a clear reason, return false and the reason.
-
 
158
                // If we don't have a clear reason, set a generic reason and return false.
-
 
159
                if (*reason == NULL) {
-
 
160
                        *reason = "It is not a text parameter file, nor a standalone Mac/PC filter created by Filter Factory/Filter Foundry.";
-
 
161
                }
-
 
162
                return false;
153
                return res;
163
        } else {
154
        } else {
164
                *reason = "File cannot be opened";
155
                return MSG_CANNOT_OPEN_FILE_ID;
165
                return false;
-
 
166
        }
156
        }
167
}
157
}