Rev 189 | Rev 194 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 189 | Rev 192 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
3 | Copyright (C) 2003-2019 Toby Thain, toby@telegraphics.com.au |
3 | Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au |
- | 4 | Copyright (C) 2018-2019 Daniel Marschall, ViaThinkSoft |
|
4 | 5 | ||
5 | This program is free software; you can redistribute it and/or modify |
6 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
7 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
8 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
9 | (at your option) any later version. |
9 | 10 | ||
10 | This program is distributed in the hope that it will be useful, |
11 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
14 | GNU General Public License for more details. |
14 | 15 | ||
15 | You should have received a copy of the GNU General Public License |
16 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
17 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | */ |
19 | */ |
19 | 20 | ||
20 | #include "ff.h" |
21 | #include "ff.h" |
21 | 22 | ||
22 | #include "file_compat.h" |
23 | #include "file_compat.h" |
23 | 24 | ||
24 | #include <string.h> |
25 | #include <string.h> |
25 | 26 | ||
26 | static UINT16 parm_id; |
27 | static UINT16 parm_id; |
27 | 28 | ||
28 | // see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/findresource.asp |
29 | // see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/findresource.asp |
29 | static BOOL CALLBACK enumnames(HMODULE hModule,LPCTSTR lpszType, |
30 | static BOOL CALLBACK enumnames(HMODULE hModule,LPCTSTR lpszType, |
30 | LPTSTR lpszName,LONG_PTR lParam) |
31 | LPTSTR lpszName,LONG_PTR lParam) |
31 | { |
32 | { |
32 | if(IS_INTRESOURCE(lpszName)) |
33 | if(IS_INTRESOURCE(lpszName)) |
33 | parm_id = (UINT16)((intptr_t)lpszName & 0xFFFF); |
34 | parm_id = (UINT16)((intptr_t)lpszName & 0xFFFF); |
34 | return false; // we only want the first one |
35 | return false; // we only want the first one |
35 | } |
36 | } |
36 | 37 | ||
37 | Boolean readPARMresource(HMODULE hm,char **reason,int readobfusc){ |
38 | Boolean readPARMresource(HMODULE hm,char **reason,int readobfusc){ |
38 | HRSRC resinfo; |
39 | HRSRC resinfo; |
39 | HANDLE h; |
40 | HANDLE h; |
40 | Ptr pparm; |
41 | Ptr pparm; |
41 | int res = false; |
42 | int res = false; |
42 | 43 | ||
43 | parm_id = PARM_ID; |
44 | parm_id = PARM_ID; |
44 | EnumResourceNames(hm,"PARM",enumnames,0); |
45 | EnumResourceNames(hm,"PARM",enumnames,0); |
45 | 46 | ||
46 | // load first PARM resource |
47 | // load first PARM resource |
47 | if( (resinfo = FindResource(hm,MAKEINTRESOURCE(parm_id),"PARM")) ){ |
48 | if( (resinfo = FindResource(hm,MAKEINTRESOURCE(parm_id),"PARM")) ){ |
48 | if( (h = LoadResource(hm,resinfo)) && (pparm = LockResource(h)) ) |
49 | if( (h = LoadResource(hm,resinfo)) && (pparm = LockResource(h)) ) |
49 | res = readPARM(pparm,&gdata->parm,reason,1 /*Windows format resource*/); |
50 | res = readPARM(pparm,&gdata->parm,reason,1 /*Windows format resource*/); |
50 | }else if( readobfusc && (resinfo = FindResource(hm,MAKEINTRESOURCE(OBFUSCDATA_ID),RT_RCDATA)) ){ |
51 | }else if( readobfusc && (resinfo = FindResource(hm,MAKEINTRESOURCE(OBFUSCDATA_ID),RT_RCDATA)) ){ |
51 | if( (h = LoadResource(hm,resinfo)) && (pparm = LockResource(h)) ){ |
52 | if( (h = LoadResource(hm,resinfo)) && (pparm = LockResource(h)) ){ |
52 | // Fix by DM, 18 Dec 2018: |
53 | // Fix by DM, 18 Dec 2018: |
53 | // We need to copy the information, because the resource data is read-only |
54 | // We need to copy the information, because the resource data is read-only |
54 | DWORD resSize = SizeofResource(hm,resinfo); |
55 | DWORD resSize = SizeofResource(hm,resinfo); |
55 | char* copy = malloc(resSize); |
56 | char* copy = malloc(resSize); |
56 | memcpy(copy, pparm, resSize); |
57 | memcpy(copy, pparm, resSize); |
57 | obfusc((unsigned char*)copy, resSize); |
58 | obfusc((unsigned char*)copy, resSize); |
58 | res = readPARM(copy,&gdata->parm,reason,1); |
59 | res = readPARM(copy,&gdata->parm,reason,1); |
59 | free(copy); |
60 | free(copy); |
60 | } |
61 | } |
61 | } |
62 | } |
62 | return res; |
63 | return res; |
63 | } |
64 | } |
64 | 65 | ||
65 | Boolean loadfile(StandardFileReply *sfr,char **reason){ |
66 | Boolean loadfile(StandardFileReply *sfr,char **reason){ |
66 | Boolean readok = false; |
67 | Boolean readok = false; |
67 | HMODULE hm; |
68 | HMODULE hm; |
68 | 69 | ||
69 | // First, try to read the file as AFS/PFF/TXT file |
70 | // First, try to read the file as AFS/PFF/TXT file |
70 | if (readok = readfile(sfr,reason)) { |
71 | if (readok = readfile(sfr,reason)) { |
71 | gdata->parmloaded = false; |
72 | gdata->parmloaded = false; |
72 | } |
73 | } |
73 | 74 | ||
74 | // If that didn't work, try to load as Windows image file (Resource API for 8BF/PRM files) |
75 | // If that didn't work, try to load as Windows image file (Resource API for 8BF/PRM files) |
75 | if (!readok) { |
76 | if (!readok) { |
76 | // see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/loadlibraryex.asp |
77 | // see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/loadlibraryex.asp |
77 | char name[MAX_PATH+1]; |
78 | char name[MAX_PATH+1]; |
78 | if (hm = LoadLibraryEx(myp2cstrcpy(name,sfr->sfFile.name),NULL,LOAD_LIBRARY_AS_DATAFILE)) { |
79 | if (hm = LoadLibraryEx(myp2cstrcpy(name,sfr->sfFile.name),NULL,LOAD_LIBRARY_AS_DATAFILE)) { |
79 | if (readPARMresource(hm,reason,0)) { |
80 | if (readPARMresource(hm,reason,0)) { |
80 | if (gdata->parm.iProtected) { |
81 | if (gdata->parm.iProtected) { |
81 | *reason = "The filter is protected."; |
82 | *reason = "The filter is protected."; |
82 | } else { |
83 | } else { |
83 | readok = gdata->parmloaded = true; |
84 | readok = gdata->parmloaded = true; |
84 | } |
85 | } |
85 | } else { |
86 | } else { |
86 | *reason = "It is not a standalone filter made by Filter Factory/Filter Foundry."; |
87 | *reason = "It is not a standalone filter made by Filter Factory/Filter Foundry."; |
87 | } |
88 | } |
88 | FreeLibrary(hm); |
89 | FreeLibrary(hm); |
89 | } |
90 | } |
90 | } |
91 | } |
91 | 92 | ||
92 | // If nothing worked, we will try to find a PARM resource (MacOS plugin, or NE executable on Win64) |
93 | // If nothing worked, we will try to find a PARM resource (MacOS plugin, or NE executable on Win64) |
93 | if (!readok) { |
94 | if (!readok) { |
94 | if (readok = read8bfplugin(sfr, reason)) { |
95 | if (readok = read8bfplugin(sfr, reason)) { |
95 | gdata->parmloaded = true; |
96 | gdata->parmloaded = true; |
96 | } else { |
97 | } else { |
97 | *reason = "PARM resource was not found in this plugin file, or this is not a standalone plugin."; |
98 | *reason = "PARM resource was not found in this plugin file, or this is not a standalone plugin."; |
98 | } |
99 | } |
99 | } |
100 | } |
100 | 101 | ||
101 | // Check if we had success |
102 | // Check if we had success |
102 | if (!readok) { |
103 | if (!readok) { |
103 | *reason = "PARM resource was not found in this plugin file, or this is not a standalone plugin."; |
104 | *reason = "PARM resource was not found in this plugin file, or this is not a standalone plugin."; |
104 | } |
105 | } |
105 | 106 | ||
106 | return readok; |
107 | return readok; |
107 | } |
108 | } |
108 | 109 |