Rev 271 | Rev 292 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
256 | daniel-mar | 1 | /* |
2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
||
3 | Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au |
||
4 | Copyright (C) 2018-2021 Daniel Marschall, ViaThinkSoft |
||
5 | |||
6 | This program is free software; you can redistribute it and/or modify |
||
7 | it under the terms of the GNU General Public License as published by |
||
8 | the Free Software Foundation; either version 2 of the License, or |
||
9 | (at your option) any later version. |
||
10 | |||
11 | This program is distributed in the hope that it will be useful, |
||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | GNU General Public License for more details. |
||
15 | |||
16 | You should have received a copy of the GNU General Public License |
||
17 | along with this program; if not, write to the Free Software |
||
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
19 | */ |
||
20 | |||
21 | #include "ff.h" |
||
22 | |||
23 | #include "file_compat.h" |
||
24 | |||
25 | #include <string.h> |
||
26 | |||
27 | static UINT16 parm_id; |
||
28 | |||
29 | static BOOL CALLBACK enumnames(HMODULE hModule,LPCTSTR lpszType, |
||
30 | LPTSTR lpszName,LONG_PTR lParam) |
||
31 | { |
||
32 | if(IS_INTRESOURCE(lpszName)) |
||
33 | parm_id = (UINT16)((intptr_t)lpszName & 0xFFFF); |
||
34 | return false; // we only want the first one |
||
35 | } |
||
36 | |||
37 | Boolean readPARMresource(HMODULE hm,char **reason,int readobfusc){ |
||
38 | HRSRC resinfo; |
||
39 | HANDLE h; |
||
40 | Ptr pparm; |
||
41 | int res = false; |
||
42 | |||
43 | parm_id = PARM_ID; |
||
44 | EnumResourceNames(hm,"PARM",enumnames,0); |
||
45 | |||
46 | // load first PARM resource |
||
47 | if( (resinfo = FindResource(hm,MAKEINTRESOURCE(parm_id),"PARM")) ){ |
||
48 | if ((h = LoadResource(hm, resinfo)) && (pparm = (Ptr)LockResource(h))) { |
||
49 | res = readPARM(pparm, &gdata->parm, reason, 1 /*Windows format resource*/); |
||
50 | gdata->obfusc = false; |
||
51 | } |
||
52 | }else if( readobfusc && (resinfo = FindResource(hm,MAKEINTRESOURCE(OBFUSCDATA_ID),RT_RCDATA)) ){ |
||
53 | if( (h = LoadResource(hm,resinfo)) && (pparm = (Ptr)LockResource(h)) ){ |
||
54 | // Fix by DM, 18 Dec 2018: |
||
55 | // We need to copy the information, because the resource data is read-only |
||
56 | DWORD resSize = SizeofResource(hm,resinfo); |
||
271 | daniel-mar | 57 | if (resSize == sizeof(PARM_T)) { |
58 | PARM_T* copy = (PARM_T*)malloc(resSize); |
||
59 | if (!copy) return false; |
||
60 | memcpy(copy, pparm, resSize); |
||
61 | deobfusc(copy); |
||
62 | res = readPARM((Ptr)copy,&gdata->parm,reason,1); |
||
63 | gdata->obfusc = true; |
||
64 | free(copy); |
||
65 | } else { |
||
66 | // Obfuscationed PARM has wrong size. Should not happen! |
||
67 | gdata->obfusc = false; |
||
68 | return false; |
||
69 | } |
||
256 | daniel-mar | 70 | } |
71 | } |
||
72 | if (!res) { |
||
73 | gdata->obfusc = false; |
||
74 | } |
||
75 | return res; |
||
76 | } |
||
77 | |||
78 | Boolean loadfile(StandardFileReply *sfr,char **reason){ |
||
79 | Boolean readok = false; |
||
80 | HMODULE hm; |
||
81 | |||
82 | // First, try to read the file as AFS/PFF/TXT file |
||
83 | if( (readok = readfile(sfr,reason)) ){ |
||
84 | gdata->obfusc = false; |
||
85 | gdata->parmloaded = false; |
||
86 | } |
||
87 | |||
88 | // If that didn't work, try to load as Windows image file (Resource API for 8BF/PRM files) |
||
89 | if (!readok) { |
||
90 | char name[MAX_PATH+1]; |
||
91 | if (hm = LoadLibraryEx(myp2cstrcpy(name,sfr->sfFile.name),NULL,LOAD_LIBRARY_AS_DATAFILE)) { |
||
92 | if (readPARMresource(hm,reason,READ_OBFUSC)) { |
||
93 | if ((gdata->parm.cbSize != PARM_SIZE) && (gdata->parm.cbSize != PARM_SIZE_PREMIERE) && (gdata->parm.cbSize != PARM_SIG_MAC)) { |
||
276 | daniel-mar | 94 | if (gdata->parm.unknown2 == 4) { |
95 | // Obfuscation V4 is protected, because FF>=1.7.0.5 combines protection and obfuscation |
||
96 | *reason = _strdup("The filter is protected."); |
||
97 | } |
||
98 | else { |
||
99 | *reason = _strdup("Incompatible obfuscation."); |
||
100 | } |
||
256 | daniel-mar | 101 | return false; // Stop! We know the issue now. |
102 | } else if (gdata->parm.iProtected) { |
||
103 | *reason = _strdup("The filter is protected."); |
||
104 | return false; // Stop! We know the issue now. |
||
105 | } else { |
||
106 | readok = gdata->parmloaded = true; |
||
107 | } |
||
108 | } |
||
109 | FreeLibrary(hm); |
||
110 | } |
||
111 | } |
||
112 | |||
113 | // If nothing worked, we will try to find a PARM resource (MacOS plugin, or NE executable on Win64) |
||
114 | if (!readok) { |
||
115 | if (read8bfplugin(sfr, reason)) { |
||
116 | if (gdata->parm.iProtected) { |
||
117 | *reason = _strdup("The filter is protected."); |
||
118 | return false; // Stop! We know the issue now. |
||
119 | } |
||
120 | else { |
||
121 | readok = gdata->parmloaded = true; |
||
122 | } |
||
123 | } |
||
124 | } |
||
125 | |||
126 | // Check if we had success |
||
127 | if (!readok) { |
||
128 | *reason = _strdup("It is not a text parameter (AFS) file, nor a standalone Mac/PC filter made by Filter Factory/Filter Foundry."); |
||
129 | } |
||
130 | |||
131 | return readok; |
||
132 | } |