Rev 106 | Rev 116 | 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 | |||
114 | dmarschall | 26 | static UINT 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)) |
114 | dmarschall | 33 | parm_id = (int)lpszName; // FIXME: How to remove compiler warning in Win64? |
34 | // Note: This typecast is safe. We just need the lower 32 bits of the 64 bit "pointer" |
||
35 | toby | 35 | return false; // we only want the first one |
36 | } |
||
37 | |||
87 | toby | 38 | Boolean readPARMresource(HMODULE hm,char **reason,int readobfusc){ |
2 | toby | 39 | HRSRC resinfo; |
40 | HANDLE h; |
||
41 | Ptr pparm; |
||
87 | toby | 42 | int res = false; |
106 | dmarschall | 43 | |
35 | toby | 44 | parm_id = PARM_ID; |
45 | EnumResourceNames(hm,"PARM",enumnames,0); |
||
106 | dmarschall | 46 | |
35 | toby | 47 | // load first PARM resource |
87 | toby | 48 | if( (resinfo = FindResource(hm,MAKEINTRESOURCE(parm_id),"PARM")) ){ |
49 | if( (h = LoadResource(hm,resinfo)) && (pparm = LockResource(h)) ) |
||
50 | res = readPARM(pparm,&gdata->parm,reason,1 /*Windows format resource*/); |
||
51 | }else if( readobfusc && (resinfo = FindResource(hm,MAKEINTRESOURCE(OBFUSCDATA_ID),RT_RCDATA)) ){ |
||
52 | if( (h = LoadResource(hm,resinfo)) && (pparm = LockResource(h)) ){ |
||
106 | dmarschall | 53 | // Fix by DM, 18 Dec 2018: |
54 | // We need to copy the information, because the resource data is read-only |
||
55 | DWORD resSize = SizeofResource(hm,resinfo); |
||
56 | byte* copy = malloc(resSize); |
||
57 | memcpy(copy, pparm, resSize); |
||
58 | obfusc(copy, resSize); |
||
59 | res = readPARM(copy,&gdata->parm,reason,1); |
||
60 | free(copy); |
||
85 | toby | 61 | } |
62 | } |
||
87 | toby | 63 | return res; |
2 | toby | 64 | } |
65 | |||
66 | // see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/loadlibraryex.asp |
||
67 | |||
68 | Boolean loadfile(StandardFileReply *sfr,char **reason){ |
||
69 | Boolean readok = false; |
||
70 | HMODULE hm; |
||
71 | |||
72 | sfr->sfFile.name[*sfr->sfFile.name+1] = 0; // add terminating null |
||
73 | |||
74 | if(sfr->nFileExtension){ |
||
75 | if(!strcasecmp((char*)sfr->sfFile.name + 1 + sfr->nFileExtension,"8bf")){ |
||
23 | toby | 76 | if( (hm = LoadLibraryEx((char*)sfr->sfFile.name+1,NULL,LOAD_LIBRARY_AS_DATAFILE)) ){ |
87 | toby | 77 | if(readPARMresource(hm,reason,0)){ |
2 | toby | 78 | if(gdata->parm.iProtected) |
85 | toby | 79 | *reason = "The filter is protected."; |
2 | toby | 80 | else |
81 | readok = gdata->parmloaded = true; |
||
85 | toby | 82 | }else |
83 | *reason = "It is not a standalone filter made by Filter Factory/Filter Foundry."; |
||
2 | toby | 84 | FreeLibrary(hm); |
85 | }else{ |
||
86 | *reason = "Could not open file (LoadLibrary failed)."; |
||
87 | dbglasterror("LoadLibrary"); |
||
88 | } |
||
89 | }else{ |
||
23 | toby | 90 | if( (readok = readfile(sfr,reason)) ) |
2 | toby | 91 | gdata->parmloaded = false; |
92 | } |
||
93 | } |
||
94 | |||
95 | return readok; |
||
96 | } |