Subversion Repositories filter_foundry

Rev

Rev 385 | Rev 440 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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_NEW))
  32.           && !(h = Get1Resource(PARM_TYPE,PARM_ID_OLD))
  33.           && readobfusc
  34.           && ((h = Get1Resource(OBFUSCDATA_TYPE_NEW,OBFUSCDATA_ID_NEW)) ||
  35.               (h = Get1Resource(OBFUSCDATA_TYPE_OLD,OBFUSCDATA_ID_OLD))) ){
  36.                 HLock(h);
  37.                 if(GetHandleSize(h) == sizeof(PARM_T)) {
  38.                         deobfusc((PARM_T*)*h);
  39.                         gdata->obfusc = true;
  40.                 } else {
  41.                         // Obfuscated PARM has wrong size. Should not happen
  42.                         gdata->obfusc = false;
  43.                         ReleaseResource(h);
  44.                         return false;
  45.                 }
  46.         }
  47.         if(h){
  48.                 HLock(h);
  49.                 res = readPARM(*h, &gdata->parm, reason, 0 /*Mac format resource*/);
  50.                 ReleaseResource(h);
  51.                 gdata->obfusc = false;
  52.         }
  53.         if (!res) {
  54.                 gdata->obfusc = false;
  55.         }
  56.         return res;
  57. }
  58.  
  59. static Boolean readmacplugin(StandardFileReply *sfr,char **reason){
  60.         Boolean res = false;
  61.         short rrn = FSpOpenResFile(&sfr->sfFile,fsRdPerm);
  62.  
  63.         if(rrn != -1){
  64.                 if(readPARMresource(NULL,reason,0))
  65.                         res = true;
  66.                 CloseResFile(rrn);
  67.         }else
  68.                 *reason = "Could not open file.";
  69.         return res;
  70. }
  71.  
  72. Boolean loadfile(StandardFileReply *sfr,char **reason){
  73.         Boolean readok = false;
  74.         FInfo fndrInfo;
  75.  
  76.         // The different read-functions will return true if the resource was successfully loaded,
  77.         // or false otherwise. If *reason is set, then the answer is clearly "No". If the result
  78.         // is just false, it means that the program should continue with the next read-function.
  79.         *reason = NULL;
  80.  
  81.         if(FSpGetFInfo(&sfr->sfFile,&fndrInfo) == noErr){
  82.                 // first try to read text parameters (AFS, TXT, PFF)
  83.                 if (*reason == NULL) {
  84.                         if (readfile_afs_pff(sfr,reason)) {
  85.                                 gdata->parmloaded = false;
  86.                                 gdata->obfusc = false;
  87.                                 return true;
  88.                         }
  89.                 }
  90.                
  91.                 // then try "Filters Unlimited" file (FFX)
  92.                 if (*reason == NULL) {
  93.                         if (readfile_ffx(sfr,reason)) {
  94.                                 gdata->parmloaded = true;
  95.                                 gdata->obfusc = false;
  96.                                 return true;
  97.                         }
  98.                 }
  99.                
  100.                 // then try "PluginCommander TXT" file (TXT)
  101.                 if (*reason == NULL) {
  102.                         if (readfile_picotxt(sfr,reason)) {
  103.                                 gdata->parmloaded = true;
  104.                                 gdata->obfusc = false;
  105.                                 return true;
  106.                         }
  107.                 }
  108.                
  109.                 // Try Mac plugin resource
  110.                 if (*reason == NULL) {
  111.                         if (readmacplugin(sfr,reason)) {
  112.                                 if (gdata->parm.iProtected) {
  113.                                         *reason = "The filter is protected.";
  114.                                 } else {
  115.                                         gdata->parmloaded = true;
  116.                                         return true;
  117.                                 }
  118.                         }
  119.                 }
  120.                
  121.                 // Try Windows resources (we need to do a binary scan)
  122.                 // Note that we cannot detect obfuscated filters here!
  123.                 if (*reason == NULL) {
  124.                         if (readfile_8bf(sfr,reason)) {
  125.                                 if (gdata->parm.iProtected) {
  126.                                         *reason = "The filter is protected.";
  127.                                 } else {
  128.                                         gdata->parmloaded = true;
  129.                                         return true;
  130.                                 }
  131.                         }
  132.                 }
  133.  
  134.                 // We didn't had success. If we have a clear reason, return false and the reason.
  135.                 // If we don't have a clear reason, set a generic reason and return false.
  136.                 if (*reason == NULL) {         
  137.                         *reason = "It is not a text parameter file, nor a standalone Mac/PC filter created by Filter Factory/Filter Foundry.";
  138.                 }
  139.                 return false;
  140.         } else {
  141.                 *reason = "File cannot be opened";
  142.                 return false;
  143.         }
  144. }
  145.