Rev 149 | Rev 153 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | toby | 1 | /* |
18 | toby | 2 | This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop |
85 | toby | 3 | Copyright (C) 2003-7 Toby Thain, toby@telegraphics.com.au |
2 | toby | 4 | |
5 | This program is free software; you can redistribute it and/or modify |
||
106 | dmarschall | 6 | it under the terms of the GNU General Public License as published by |
2 | toby | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
||
9 | |||
10 | This program is distributed in the hope that it will be useful, |
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
13 | GNU General Public License for more details. |
||
14 | |||
106 | dmarschall | 15 | You should have received a copy of the GNU General Public License |
2 | toby | 16 | 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 | */ |
||
19 | |||
20 | #include "ff.h" |
||
21 | |||
22 | #include "file_compat.h" |
||
23 | |||
24 | #include <string.h> |
||
25 | |||
116 | dmarschall | 26 | static UINT16 parm_id; |
35 | toby | 27 | |
28 | // see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/introductiontoresources/resourcereference/resourcefunctions/findresource.asp |
||
62 | toby | 29 | static BOOL CALLBACK enumnames(HMODULE hModule,LPCTSTR lpszType, |
30 | LPTSTR lpszName,LONG_PTR lParam) |
||
31 | { |
||
35 | toby | 32 | if(IS_INTRESOURCE(lpszName)) |
116 | dmarschall | 33 | parm_id = (UINT16)((intptr_t)lpszName & 0xFFFF); |
35 | toby | 34 | return false; // we only want the first one |
35 | } |
||
36 | |||
87 | toby | 37 | Boolean readPARMresource(HMODULE hm,char **reason,int readobfusc){ |
2 | toby | 38 | HRSRC resinfo; |
39 | HANDLE h; |
||
40 | Ptr pparm; |
||
87 | toby | 41 | int res = false; |
106 | dmarschall | 42 | |
35 | toby | 43 | parm_id = PARM_ID; |
44 | EnumResourceNames(hm,"PARM",enumnames,0); |
||
106 | dmarschall | 45 | |
35 | toby | 46 | // load first PARM resource |
87 | toby | 47 | if( (resinfo = FindResource(hm,MAKEINTRESOURCE(parm_id),"PARM")) ){ |
48 | if( (h = LoadResource(hm,resinfo)) && (pparm = LockResource(h)) ) |
||
49 | res = readPARM(pparm,&gdata->parm,reason,1 /*Windows format resource*/); |
||
50 | }else if( readobfusc && (resinfo = FindResource(hm,MAKEINTRESOURCE(OBFUSCDATA_ID),RT_RCDATA)) ){ |
||
51 | if( (h = LoadResource(hm,resinfo)) && (pparm = LockResource(h)) ){ |
||
106 | dmarschall | 52 | // Fix by DM, 18 Dec 2018: |
53 | // We need to copy the information, because the resource data is read-only |
||
54 | DWORD resSize = SizeofResource(hm,resinfo); |
||
55 | byte* copy = malloc(resSize); |
||
56 | memcpy(copy, pparm, resSize); |
||
57 | obfusc(copy, resSize); |
||
58 | res = readPARM(copy,&gdata->parm,reason,1); |
||
59 | free(copy); |
||
85 | toby | 60 | } |
61 | } |
||
87 | toby | 62 | return res; |
2 | toby | 63 | } |
64 | |||
65 | // see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/loadlibraryex.asp |
||
66 | |||
67 | Boolean loadfile(StandardFileReply *sfr,char **reason){ |
||
68 | Boolean readok = false; |
||
69 | HMODULE hm; |
||
70 | |||
71 | sfr->sfFile.name[*sfr->sfFile.name+1] = 0; // add terminating null |
||
72 | |||
73 | if(sfr->nFileExtension){ |
||
152 | dmarschall | 74 | if (!strcasecmp((char*)sfr->sfFile.name + 1 + sfr->nFileExtension,"bin")) { // FilterFactory Mac standalone plugin |
75 | if (readok = read8bfplugin(sfr, reason)) { |
||
76 | gdata->parmloaded = true; |
||
77 | } else { |
||
78 | *reason = "PARM resource was not found in this plugin file, or this is not a standalone plugin."; |
||
79 | } |
||
80 | } else if ((!strcasecmp((char*)sfr->sfFile.name + 1 + sfr->nFileExtension,"8bf")) || // FilterFactory/FilterFoundry Windows standalone plugin |
||
81 | (!strcasecmp((char*)sfr->sfFile.name + 1 + sfr->nFileExtension,"prm"))) { // Premiere Windows standalone plugin |
||
145 | dmarschall | 82 | // File extention is 8bf or prm |
23 | toby | 83 | if( (hm = LoadLibraryEx((char*)sfr->sfFile.name+1,NULL,LOAD_LIBRARY_AS_DATAFILE)) ){ |
87 | toby | 84 | if(readPARMresource(hm,reason,0)){ |
2 | toby | 85 | if(gdata->parm.iProtected) |
85 | toby | 86 | *reason = "The filter is protected."; |
2 | toby | 87 | else |
88 | readok = gdata->parmloaded = true; |
||
85 | toby | 89 | }else |
90 | *reason = "It is not a standalone filter made by Filter Factory/Filter Foundry."; |
||
2 | toby | 91 | FreeLibrary(hm); |
92 | }else{ |
||
147 | dmarschall | 93 | //*reason = "Could not open file (LoadLibrary failed)."; |
94 | //dbglasterror("LoadLibraryEx"); |
||
95 | |||
96 | // Maybe it is 16 bit Windows? Try to find the resource |
||
152 | dmarschall | 97 | if (readok = read8bfplugin(sfr, reason)) { |
98 | gdata->parmloaded = true; |
||
99 | } else { |
||
100 | *reason = "PARM resource was not found in this plugin file, or this is not a standalone plugin."; |
||
147 | dmarschall | 101 | } |
2 | toby | 102 | } |
103 | }else{ |
||
145 | dmarschall | 104 | // Try to read as AFS/PFF/TXT file |
23 | toby | 105 | if( (readok = readfile(sfr,reason)) ) |
2 | toby | 106 | gdata->parmloaded = false; |
107 | } |
||
108 | } |
||
109 | |||
110 | return readok; |
||
111 | } |