Subversion Repositories filter_foundry

Rev

Rev 271 | Rev 292 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
259 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 <Resources.h>
24
 
25
#include "file_compat.h"
26
 
27
Boolean readPARMresource(HMODULE hm,char **reason,int readobfusc){
28
        Boolean res = false;
29
        Handle h;
30
 
31
        if( !(h = Get1Resource(PARM_TYPE,PARM_ID))
32
          && readobfusc
33
          && (h = Get1Resource('DATA',OBFUSCDATA_ID)) ){
34
                HLock(h);
271 daniel-mar 35
                if(GetHandleSize(h) == sizeof(PARM_T)) {
36
                        deobfusc((PARM_T*)*h);
37
                        gdata->obfusc = true;
38
                } else {
39
                        // Obfuscated PARM has wrong size. Should not happen
40
                        gdata->obfusc = false;
41
                        ReleaseResource(h);
42
                        return false;
43
                }
259 daniel-mar 44
        }
45
        if(h){
46
                HLock(h);
47
                res = readPARM(*h, &gdata->parm, reason, 0 /*Mac format resource*/);
48
                ReleaseResource(h);
49
                gdata->obfusc = false;
50
        }
51
        if (!res) {
52
                gdata->obfusc = false;
53
        }
54
        return res;
55
}
56
 
57
static Boolean readmacplugin(StandardFileReply *sfr,char **reason){
58
        Boolean res = false;
59
        short rrn = FSpOpenResFile(&sfr->sfFile,fsRdPerm);
60
 
61
        if(rrn != -1){
62
                if(readPARMresource(NULL,reason,0))
63
                        res = true;
64
                CloseResFile(rrn);
65
        }else
66
                *reason = "Could not open file.";
67
        return res;
68
}
69
 
70
Boolean loadfile(StandardFileReply *sfr,char **reason){
71
        Boolean readok = false;
72
        FInfo fndrInfo;
73
 
74
        if(FSpGetFInfo(&sfr->sfFile,&fndrInfo) == noErr){
75
                // first try to read text parameters (AFS, TXT, PFF)
76
                if( (readok = readfile(sfr,reason)) ) {
77
                        gdata->parmloaded = false;
78
                        gdata->obfusc = false;
79
                        // then try plugin formats (Mac first, then Windows .8bf or .prm DLL)
80
                }else if( (readok = readmacplugin(sfr,reason) || read8bfplugin(sfr,reason)) ){
81
                        if ((gdata->parm.cbSize != PARM_SIZE) && (gdata->parm.cbSize != PARM_SIZE_PREMIERE) && (gdata->parm.cbSize != PARM_SIG_MAC)) {
276 daniel-mar 82
                                if (gdata->parm.unknown2 == 4) {
83
                                        // Obfuscation V4 is protected, because FF>=1.7.0.5 combines protection and obfuscation
84
                                        *reason = "The filter is protected.";
85
                                }
86
                                else {
87
                                        *reason = "Incompatible obfuscation.";
88
                                }
259 daniel-mar 89
                                return false; // Stop! We know the issue now.
90
                        }else if(gdata->parm.iProtected){
91
                                *reason = "The filter is protected.";
92
                                return false;
93
                        }else
94
                                gdata->parmloaded = true;
95
                }else
96
                        *reason = "It is not a text parameter (AFS) file, nor a standalone Mac/PC filter made by Filter Factory/Filter Foundry.";
97
        }
98
 
99
        return readok;
100
}