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 36... Line 36...
36
                return false; // we only want the first one
36
                return false; // we only want the first one
37
        }
37
        }
38
        else return true;
38
        else return true;
39
}
39
}
40
 
40
 
41
Boolean readPARMresource(HMODULE hm, TCHAR** reason) {
41
FFLoadingResult readPARMresource(HMODULE hm) {
42
        HRSRC resinfo;
42
        HRSRC resinfo;
43
        HANDLE h;
43
        HANDLE h;
44
        Ptr pparm;
44
        Ptr pparm;
45
 
45
 
46
        UINT16 parm_id = 1;
46
        UINT16 parm_id = 1;
47
        EnumResourceNames(hm, PARM_TYPE, enum_find_resname, (LONG_PTR)&parm_id); // callback function enum_find_resname() will find the actual found parm_id
47
        EnumResourceNames(hm, PARM_TYPE, enum_find_resname, (LONG_PTR)&parm_id); // callback function enum_find_resname() will find the actual found parm_id
48
 
48
 
49
        // load first PARM resource
49
        // load first PARM resource
50
        if ((resinfo = FindResource(hm, MAKEINTRESOURCE(parm_id), PARM_TYPE))) {
50
        if ((resinfo = FindResource(hm, MAKEINTRESOURCE(parm_id), PARM_TYPE))) {
51
                if ((h = LoadResource(hm, resinfo)) && (pparm = (Ptr)LockResource(h))) {
51
                if ((h = LoadResource(hm, resinfo)) && (pparm = (Ptr)LockResource(h))) {
52
                        Boolean res = readPARM(&gdata->parm, pparm);
52
                        FFLoadingResult res = readPARM(&gdata->parm, pparm);
53
                        gdata->obfusc = false;
53
                        gdata->obfusc = false;
54
                        return res;
54
                        return res;
55
                }
55
                }
56
        }
56
        }
57
        else if (
57
        else if (
Line 60... Line 60...
60
                if ((h = LoadResource(hm, resinfo)) && (pparm = (Ptr)LockResource(h))) {
60
                if ((h = LoadResource(hm, resinfo)) && (pparm = (Ptr)LockResource(h))) {
61
                        // Fix by DM, 18 Dec 2018:
61
                        // Fix by DM, 18 Dec 2018:
62
                        // We need to copy the information, because the resource data is read-only
62
                        // We need to copy the information, because the resource data is read-only
63
                        DWORD resSize = SizeofResource(hm, resinfo);
63
                        DWORD resSize = SizeofResource(hm, resinfo);
64
                        if (resSize == sizeof(PARM_T)) {
64
                        if (resSize == sizeof(PARM_T)) {
65
                                Boolean res;
65
                                FFLoadingResult res;
66
                                PARM_T* copy = (PARM_T*)malloc(resSize);
66
                                PARM_T* copy = (PARM_T*)malloc(resSize);
67
                                if (!copy) return false;
67
                                if (!copy) return MSG_OUT_OF_MEMORY_ID;
68
                                memcpy(copy, pparm, resSize);
68
                                memcpy(copy, pparm, resSize);
69
                                deobfusc(copy);
69
                                deobfusc(copy);
70
                                res = readPARM(&gdata->parm, (Ptr)copy);
70
                                res = readPARM(&gdata->parm, (Ptr)copy);
71
                                if (!res) {
-
 
72
                                        if (reason) *reason = FF_GetMsg_Cpy(MSG_INCOMPATIBLE_OBFUSCATION_ID);
-
 
73
                                }
-
 
74
                                free(copy);
71
                                free(copy);
75
                                gdata->obfusc = true;
72
                                gdata->obfusc = true;
76
                                return res;
73
                                return res;
77
                        }
74
                        }
78
                        else {
75
                        else {
79
                                // Obfuscationed PARM has wrong size. It is probably a file with different RCDATA
76
                                // Obfuscationed PARM has wrong size. It is probably a file with different RCDATA
80
                                gdata->obfusc = false;
77
                                gdata->obfusc = false;
81
                                return false;
78
                                return MSG_INVALID_PARAMETER_DATA_ID;
82
                        }
79
                        }
83
                }
80
                }
84
        }
81
        }
85
        return false;
82
        return MSG_LOADFILE_UNKNOWN_FORMAT_ID;
86
}
83
}
87
 
84
 
88
Boolean loadfile(StandardFileReply* sfr, TCHAR** reason) {
85
FFLoadingResult loadfile(StandardFileReply* sfr) {
89
        HMODULE hm;
86
        HMODULE hm;
90
        TCHAR* reasonstr;
-
 
91
 
-
 
92
        // The different read-functions will return true if the resource was successfully loaded,
87
        FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
93
        // or false otherwise. If *reason is set, then the answer is clearly "No". If the result
-
 
94
        // is just false, it means that the program should continue with the next read-function.
-
 
95
        reasonstr = NULL;
-
 
96
 
88
 
97
        // First, try to read the file as AFS/PFF/TXT file
89
        // First, try to read the file as AFS/PFF/TXT file
98
        if (reasonstr == NULL) {
90
        if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
99
                if (readfile_afs_pff(sfr, &reasonstr)) {
91
                if (0 == (res = readfile_afs_pff(sfr))) {
100
                        gdata->obfusc = false;
92
                        gdata->obfusc = false;
101
                        parm_reset(true, false, true, false);
93
                        parm_reset(true, false, true, false);
102
                        return true;
94
                        return 0;
103
                }
95
                }
104
        }
96
        }
105
 
97
 
106
        // Try to read the file as FFL file
98
        // Try to read the file as FFL file
107
        if (reasonstr == NULL) {
99
        if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
108
                if (readfile_ffl(sfr, &reasonstr)) {
100
                if (0 == (res = readfile_ffl(sfr))) {
109
                        gdata->obfusc = false;
101
                        gdata->obfusc = false;
110
                        parm_reset(true, true, true, true);
102
                        parm_reset(true, true, true, true);
111
                        return true;
103
                        return 0;
112
                }
104
                }
113
        }
105
        }
114
 
106
 
115
        // If that didn't work, try to load as Windows image file (Resource API for 8BF/PRM files)
107
        // If that didn't work, try to load as Windows image file (Resource API for 8BF/PRM files)
116
        if (reasonstr == NULL) {
108
        if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
117
                if (hm = LoadLibraryEx(sfr->sfFile.szName, NULL, LOAD_LIBRARY_AS_DATAFILE)) {
109
                if (hm = LoadLibraryEx(sfr->sfFile.szName, NULL, LOAD_LIBRARY_AS_DATAFILE)) {
118
                        if (readPARMresource(hm, &reasonstr)) {
110
                        if (0 == (res = readPARMresource(hm))) {
119
                                gdata->parm.standalone = false; // just because the loaded file is standalone, does not mean that WE are standalone
111
                                gdata->parm.standalone = false; // just because the loaded file is standalone, does not mean that WE are standalone
120
                                if (gdata->parm.iProtected) {
112
                                if (gdata->parm.iProtected) {
121
                                        parm_reset(true, true, true, true);
113
                                        parm_reset(true, true, true, true);
122
                                        reasonstr = FF_GetMsg_Cpy(MSG_FILTER_PROTECTED_ID);
114
                                        res = MSG_FILTER_PROTECTED_ID;
123
                                }
115
                                }
124
                                else {
116
                                else {
125
                                        FreeLibrary(hm);
117
                                        FreeLibrary(hm);
126
                                        return true;
118
                                        return 0;
127
                                }
119
                                }
128
                        }
120
                        }
129
                        FreeLibrary(hm);
121
                        FreeLibrary(hm);
130
                }
122
                }
131
        }
123
        }
132
 
124
 
133
        // Is it a "Filters Unlimited" FFX filter? (Only partially compatible with Filter Factory!!!)
125
        // Is it a "Filters Unlimited" FFX filter? (Only partially compatible with Filter Factory!!!)
134
        if (reasonstr == NULL) {
126
        if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
135
                if (readfile_ffx(sfr, &reasonstr)) {
127
                if (0 == (res = readfile_ffx(sfr))) {
136
                        return true;
128
                        return 0;
137
                }
129
                }
138
        }
130
        }
139
 
131
 
140
        // Is it a "Filters Unlimited" TXT filter? (Only partially compatible with Filter Factory!!!)
132
        // Is it a "Filters Unlimited" TXT filter? (Only partially compatible with Filter Factory!!!)
141
        if (reasonstr == NULL) {
133
        if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
142
                if (readfile_picotxt_or_ffdecomp(sfr, &reasonstr)) {
134
                if (0 == (res = readfile_picotxt_or_ffdecomp(sfr))) {
143
                        return true;
135
                        return 0;
144
                }
136
                }
145
        }
137
        }
146
 
138
 
147
        // Is it a "GIMP UserFilter (GUF)" file? (Only partially compatible with Filter Factory!!!)
139
        // Is it a "GIMP UserFilter (GUF)" file? (Only partially compatible with Filter Factory!!!)
148
        if (reasonstr == NULL) {
140
        if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
149
                if (readfile_guf(sfr, &reasonstr)) {
141
                if (0 == (res = readfile_guf(sfr))) {
150
                        return true;
142
                        return 0;
151
                }
143
                }
152
        }
144
        }
153
 
145
 
154
        // If nothing worked, we will try to find a PARM resource (MacOS plugin, or 64 bit 8BF on Win32 OS)
146
        // If nothing worked, we will try to find a PARM resource (MacOS plugin, or 64 bit 8BF on Win32 OS)
155
        // Note that we cannot detect obfuscated filters here!
147
        // Note that we cannot detect obfuscated filters here!
156
        if (reasonstr == NULL) {
148
        if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
157
                if (readfile_8bf(sfr, &reasonstr)) {
149
                if (0 == (res = readfile_8bf(sfr))) {
158
                        if (gdata->parm.iProtected) {
150
                        if (gdata->parm.iProtected) {
159
                                // This is for purely protected filters before the time when obfuscation and protection was merged
151
                                // This is for purely protected filters before the time when obfuscation and protection was merged
160
                                parm_reset(true, true, true, true);
152
                                parm_reset(true, true, true, true);
161
                                reasonstr = FF_GetMsg_Cpy(MSG_FILTER_PROTECTED_ID);
153
                                res = MSG_FILTER_PROTECTED_ID;
162
                        }
154
                        }
163
                        else {
155
                        else {
164
                                return true;
156
                                return 0;
165
                        }
-
 
166
                }
157
                        }
167
        }
158
                }
168
 
-
 
169
        // We didn't had success. If we have a clear reason, return false and the reason.
-
 
170
        // If we don't have a clear reason, set a generic reason and return false.
-
 
171
        if (reasonstr == NULL) {
-
 
172
                reasonstr = FF_GetMsg_Cpy(MSG_LOADFILE_UNKNOWN_FORMAT_ID);
-
 
173
        }
159
        }
174
 
160
 
175
        if (reason) *reason = reasonstr;
-
 
176
 
-
 
177
        return false;
161
        return res;
178
}
162
}