Subversion Repositories filter_foundry

Rev

Rev 550 | Rev 554 | 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.net
  4.     Copyright (C) 2018-2023 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. FFLoadingResult readPARMresource(HMODULE hm){
  28.         FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
  29.         Handle h;
  30.  
  31.         if( (h = Get1Resource(PARM_TYPE,PARM_ID_NEW)) ||
  32.             (h = Get1Resource(PARM_TYPE,PARM_ID_OLD)) )
  33.         {
  34.                 HLock(h);
  35.                 if(GetHandleSize(h) == sizeof(PARM_T)) {
  36.                         res = readPARM(&gdata->parm, *h, 0 /*Mac format resource*/);
  37.                         gdata->obfusc = false;
  38.                         ReleaseResource(h);
  39.                 } else {
  40.                         // PARM has wrong size. Should not happen
  41.                         gdata->obfusc = false;
  42.                         ReleaseResource(h);
  43.                         return MSG_INVALID_FILE_SIGNATURE_ID;
  44.                 }
  45.         }
  46.         else if( ((h = Get1Resource(OBFUSCDATA_TYPE_NEW,OBFUSCDATA_ID_NEW)) ||
  47.                   (h = Get1Resource(OBFUSCDATA_TYPE_OLD,OBFUSCDATA_ID_OLD))) )
  48.         {
  49.                 HLock(h);
  50.                 if(GetHandleSize(h) == sizeof(PARM_T)) {
  51.                         deobfusc((PARM_T*)*h);
  52.                         res = readPARM(&gdata->parm, *h, 0 /*Mac format resource*/);
  53.                         gdata->obfusc = true;
  54.                         ReleaseResource(h);
  55.                 } else {
  56.                         // Obfuscated PARM has wrong size. Should not happen
  57.                         gdata->obfusc = false;
  58.                         ReleaseResource(h);
  59.                         return MSG_INCOMPATIBLE_OBFUSCATION_ID;
  60.                 }
  61.         }
  62.         if (!res) {
  63.                 gdata->obfusc = false;
  64.         }
  65.         return res;
  66. }
  67.  
  68. FFLoadingResult Boolean readmacplugin(StandardFileReply *sfr){
  69.         FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
  70.         short rrn = FSpOpenResFile(&sfr->sfFile,fsRdPerm);
  71.  
  72.         if(rrn != -1){
  73.                 res = readPARMresource(NULL);
  74.                 CloseResFile(rrn);
  75.         }
  76.         else
  77.                 res = MSG_CANNOT_OPEN_FILE_ID;
  78.         return res;
  79. }
  80.  
  81. FFLoadingResult loadfile(StandardFileReply *sfr){
  82.         Boolean readok = false;
  83.         FInfo fndrInfo;
  84.         FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
  85.  
  86.         if(FSpGetFInfo(&sfr->sfFile,&fndrInfo) == noErr){
  87.                 // first try to read text parameters (AFS, TXT, PFF)
  88.                 if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
  89.                         if (0 == (res = readfile_afs_pff(sfr))) {
  90.                                 parm_reset(true, false, true, false);
  91.                                 gdata->obfusc = false;
  92.                                 return 0;
  93.                         }
  94.                 }
  95.  
  96.                 // Try to read the file as FFL file
  97.                 if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
  98.                         if (0 == (res = (readfile_ffl(sfr)))) {
  99.                                 parm_reset(true, true, true, true);
  100.                                 gdata->obfusc = false;
  101.                                 return 0;
  102.                         }
  103.                 }
  104.  
  105.                 // then try "Filters Unlimited" file (FFX)
  106.                 if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
  107.                         if (0 == (res = (readfile_ffx(sfr)))) {
  108.                                 gdata->obfusc = false;
  109.                                 return 0;
  110.                         }
  111.                 }
  112.  
  113.                 // then try "PluginCommander TXT" file (TXT)
  114.                 if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
  115.                         if (0 == (res = (readfile_picotxt(sfr)))) {
  116.                                 gdata->obfusc = false;
  117.                                 return 0;
  118.                         }
  119.                 }
  120.  
  121.                 // Is it a "GIMP UserFilter (GUF)" file? (Only partially compatible with Filter Factory!!!)
  122.                 if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
  123.                         if (0 == (res = (readfile_guf(sfr)))) {
  124.                                 return 0;
  125.                         }
  126.                 }
  127.  
  128.                 // Try Mac plugin resource
  129.                 if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
  130.                         if (0 == (res = (readmacplugin(sfr)))) {
  131.                                 if (gdata->parm.iProtected) {
  132.                                         parm_reset(true, true, true, true);
  133.                                         res = MSG_FILTER_PROTECTED_ID;
  134.                                 } else {
  135.                                         return 0;
  136.                                 }
  137.                         }
  138.                 }
  139.  
  140.                 // Try Windows resources (we need to do a binary scan)
  141.                 // Note that we cannot detect obfuscated filters here!
  142.                 if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
  143.                         if (0 == (res = (readfile_8bf(sfr)))) {
  144.                                 if (gdata->parm.iProtected) {
  145.                                         parm_reset(true, true, true, true);
  146.                                         res = MSG_FILTER_PROTECTED_ID;
  147.                                 } else {
  148.                                         return 0;
  149.                                 }
  150.                         }
  151.                 }
  152.  
  153.                 return res;
  154.         } else {
  155.                 return MSG_CANNOT_OPEN_FILE_ID;
  156.         }
  157. }
  158.