40,7 → 40,6 |
HRSRC resinfo; |
HANDLE h; |
Ptr pparm; |
int res = false; |
|
parm_id = 1; |
EnumResourceNames(hm,PARM_TYPE,enumnames,0); // callback function enumnames() will find the actual found parm_id |
48,10 → 47,12 |
// load first PARM resource |
if( (resinfo = FindResource(hm,MAKEINTRESOURCE(parm_id),PARM_TYPE)) ){ |
if ((h = LoadResource(hm, resinfo)) && (pparm = (Ptr)LockResource(h))) { |
res = readPARM(&gdata->parm,pparm); |
int res = readPARM(&gdata->parm, pparm); |
gdata->obfusc = false; |
return res; |
} |
}else if( readobfusc && |
} |
else if (readobfusc && |
((resinfo = FindResource(hm,OBFUSCDATA_ID_NEW,OBFUSCDATA_TYPE_NEW)) || |
(resinfo = FindResource(hm,OBFUSCDATA_ID_OLD,OBFUSCDATA_TYPE_OLD))) ){ |
if( (h = LoadResource(hm,resinfo)) && (pparm = (Ptr)LockResource(h)) ){ |
59,14 → 60,20 |
// We need to copy the information, because the resource data is read-only |
DWORD resSize = SizeofResource(hm,resinfo); |
if (resSize == sizeof(PARM_T)) { |
int res; |
PARM_T* copy = (PARM_T*)malloc(resSize); |
if (!copy) return false; |
memcpy(copy, pparm, resSize); |
deobfusc(copy); |
res = readPARM(&gdata->parm,(Ptr)copy); |
if (!res) { |
*reason = _strdup("Incompatible obfuscation."); |
} |
free(copy); |
gdata->obfusc = true; |
free(copy); |
} else { |
return res; |
} |
else { |
// Obfuscationed PARM has wrong size. It is probably a file with different RCDATA |
gdata->obfusc = false; |
return false; |
73,74 → 80,80 |
} |
} |
} |
if (!res) { |
gdata->obfusc = false; |
return false; |
} |
return res; |
} |
|
Boolean loadfile(StandardFileReply *sfr,char **reason){ |
Boolean readok = false; |
HMODULE hm; |
|
// The different read-functions will return true if the resource was successfully loaded, |
// or false otherwise. If *reason is set, then the answer is clearly "No". If the result |
// is just false, it means that the program should continue with the next read-function. |
*reason = NULL; |
|
// First, try to read the file as AFS/PFF/TXT file |
if( (readok = readfile_afs_pff(sfr,reason)) ){ |
if (*reason == NULL) { |
if (readfile_afs_pff(sfr, reason)) { |
gdata->obfusc = false; |
gdata->parmloaded = false; |
return true; |
} |
} |
|
// If that didn't work, try to load as Windows image file (Resource API for 8BF/PRM files) |
if (!readok) { |
if (*reason == NULL) { |
char name[MAX_PATH+1]; |
if (hm = LoadLibraryEx(myp2cstrcpy(name,sfr->sfFile.name),NULL,LOAD_LIBRARY_AS_DATAFILE)) { |
if (readPARMresource(hm,reason,READ_OBFUSC)) { |
if ((gdata->parm.cbSize != PARM_SIZE) && (gdata->parm.cbSize != PARM_SIZE_PREMIERE) && (gdata->parm.cbSize != PARM_SIG_MAC)) { |
*reason = _strdup("Incompatible obfuscation."); |
//gdata->parmloaded = false; |
return false; // Stop! We know the issue now. |
} else if (gdata->parm.iProtected) { |
if (gdata->parm.iProtected) { |
*reason = _strdup("The filter is protected."); |
//gdata->parmloaded = false; |
return false; // Stop! We know the issue now. |
} else { |
readok = gdata->parmloaded = true; |
} |
else { |
gdata->parmloaded = true; |
FreeLibrary(hm); |
return true; |
} |
} |
FreeLibrary(hm); |
} |
} |
|
// Is it a "Filters Unlimited" filter? (Only partially compatible with Filter Factory!!!) |
if (!readok) { |
if (*reason == NULL) { |
if (readfile_ffx(sfr, reason)) { |
readok = gdata->parmloaded = true; |
gdata->parmloaded = true; |
return true; |
} |
} |
|
// Is it a "Filters Unlimited" filter? (Only partially compatible with Filter Factory!!!) |
if (!readok) { |
if (*reason == NULL) { |
if (readfile_picotxt(sfr, reason)) { |
readok = gdata->parmloaded = true; |
gdata->parmloaded = true; |
return true; |
} |
} |
|
// If nothing worked, we will try to find a PARM resource (MacOS plugin, or NE executable on Win64) |
if (!readok) { |
// If nothing worked, we will try to find a PARM resource (MacOS plugin, or 64 bit 8BF on Win32 OS) |
// Note that we cannot detect obfuscated filters here! |
if (*reason == NULL) { |
if (readfile_8bf(sfr, reason)) { |
if (gdata->parm.iProtected) { |
// This is for purely protected filters before the time when obfuscation and protection was merged |
*reason = _strdup("The filter is protected."); |
return false; // Stop! We know the issue now. |
} |
else { |
readok = gdata->parmloaded = true; |
gdata->parmloaded = true; |
return true; |
} |
} |
} |
|
// Check if we had success |
if (!readok) { |
*reason = _strdup("It is not a text parameter (AFS) file, nor a standalone Mac/PC filter made by Filter Factory/Filter Foundry."); |
// We didn't had success. If we have a clear reason, return false and the reason. |
// If we don't have a clear reason, set a generic reason and return false. |
if (*reason == NULL) { |
*reason = _strdup("It is not a text parameter file, nor a standalone Mac/PC filter created by Filter Factory/Filter Foundry."); |
} |
|
return readok; |
} |
return false; |
} |