Subversion Repositories filter_foundry

Rev

Rev 558 | 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);
  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);
  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 != LOADING_OK) {
  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 (LOADING_OK == (res = readfile_afs_pff(sfr))) {
  90.                                 parm_reset(true, false, true, false);
  91.                                 gdata->obfusc = false;
  92.                                 return LOADING_OK;
  93.                         }
  94.                         if (res == MSG_INVALID_FILE_SIGNATURE_ID) res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
  95.                 }
  96.  
  97.                 // Try to read the file as FFL file
  98.                 if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
  99.                         if (LOADING_OK == (res = (readfile_ffl(sfr)))) {
  100.                                 parm_reset(true, true, true, true);
  101.                                 gdata->obfusc = false;
  102.                                 return LOADING_OK;
  103.                         }
  104.                         if (res == MSG_INVALID_FILE_SIGNATURE_ID) res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
  105.                 }
  106.  
  107.                 // then try "Filters Unlimited" file (FFX)
  108.                 if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
  109.                         if (LOADING_OK == (res = (readfile_ffx(sfr)))) {
  110.                                 gdata->obfusc = false;
  111.                                 return LOADING_OK;
  112.                         }
  113.                         if (res == MSG_INVALID_FILE_SIGNATURE_ID) res = MSG_LOADFILE_UNKNOWN_FORMAT_ID;
  114.                 }
  115.  
  116.                 // then try "PluginCommander TXT" file (TXT)
  117.                 if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
  118.                         if (LOADING_OK == (res = (readfile_picotxt(sfr)))) {
  119.                                 gdata->obfusc = false;
  120.                                 return LOADING_OK;
  121.                         }
  122.                 }
  123.  
  124.                 // Is it a "GIMP UserFilter (GUF)" file? (Only partially compatible with Filter Factory!!!)
  125.                 if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
  126.                         if (LOADING_OK == (res = (readfile_guf(sfr)))) {
  127.                                 return LOADING_OK;
  128.                         }
  129.                 }
  130.  
  131.                 // Try Mac plugin resource
  132.                 if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
  133.                         if (LOADING_OK == (res = (readmacplugin(sfr)))) {
  134.                                 if (gdata->parm.iProtected) {
  135.                                         parm_reset(true, true, true, true);
  136.                                         res = MSG_FILTER_PROTECTED_ID;
  137.                                 } else {
  138.                                         return LOADING_OK;
  139.                                 }
  140.                         }
  141.                 }
  142.  
  143.                 // Try Windows resources (we need to do a binary scan)
  144.                 // Note that we cannot detect obfuscated filters here!
  145.                 if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) {
  146.                         if (LOADING_OK == (res = (readfile_8bf(sfr)))) {
  147.                                 if (gdata->parm.iProtected) {
  148.                                         parm_reset(true, true, true, true);
  149.                                         res = MSG_FILTER_PROTECTED_ID;
  150.                                 } else {
  151.                                         return LOADING_OK;
  152.                                 }
  153.                         }
  154.                 }
  155.  
  156.                 return res;
  157.         } else {
  158.                 return MSG_CANNOT_OPEN_FILE_ID;
  159.         }
  160. }
  161.