Subversion Repositories filter_foundry

Rev

Rev 393 | Rev 416 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 393 Rev 402
Line 28... Line 28...
28
#include "versioninfo_modify_win.h"
28
#include "versioninfo_modify_win.h"
29
#include "version.h"
29
#include "version.h"
30
 
30
 
31
extern HINSTANCE hDllInstance;
31
extern HINSTANCE hDllInstance;
32
 
32
 
33
Boolean doresources(HMODULE srcmod,char *dstname, int bits);
33
Boolean doresources(char *dstname, int bits);
34
 
34
 
35
void dbglasterror(char *func){
35
void dbglasterror(char *func){
36
        char s[0x100];
36
        char s[0x100];
37
 
37
 
38
        strcpy(s,func);
38
        strcpy(s,func);
Line 355... Line 355...
355
typedef struct {
355
typedef struct {
356
        char funcname[8];
356
        char funcname[8];
357
        char referencename[8];
357
        char referencename[8];
358
} symndef_t;
358
} symndef_t;
359
 
359
 
360
Boolean doresources(HMODULE srcmod,char *dstname, int bits){
360
Boolean doresources(char *dstname, int bits){
361
        HRSRC datarsrc,aetersrc,manifestsrc;
361
        HRSRC datarsrc,aetersrc,manifestsrc;
362
        HGLOBAL datah,aeteh,hupdate,manifesth;
362
        HGLOBAL datah,aeteh,hupdate,manifesth;
363
 
363
 
364
        operdef_t dummy_oper;
364
        operdef_t dummy_oper;
365
        funcdef_t dummy_func;
365
        funcdef_t dummy_func;
Line 374... Line 374...
374
        LPCTSTR parm_type;
374
        LPCTSTR parm_type;
375
        LPCSTR parm_id;
375
        LPCSTR parm_id;
376
        Boolean discard = true;
376
        Boolean discard = true;
377
        uint64_t obfuscseed = 0;
377
        uint64_t obfuscseed = 0;
378
        long event_id;
378
        long event_id;
379
        Boolean mustFreeSrcMod;
-
 
380
 
379
 
381
        memset(&dummy_oper, 0, sizeof(operdef_t));
380
        memset(&dummy_oper, 0, sizeof(operdef_t));
382
        memset(&dummy_func, 0, sizeof(funcdef_t));
381
        memset(&dummy_func, 0, sizeof(funcdef_t));
383
        memset(&dummy_symn, 0, sizeof(symndef_t));
382
        memset(&dummy_symn, 0, sizeof(symndef_t));
384
 
383
 
385
        if (srcmod == NULL) {
-
 
386
                srcmod = LoadLibraryEx(dstname, NULL, LOAD_LIBRARY_AS_DATAFILE);
-
 
387
                if (!srcmod) {
-
 
388
                        dbglasterror(_strdup("LoadLibraryEx"));
-
 
389
                        return false;
-
 
390
                }
-
 
391
                mustFreeSrcMod = true;
-
 
392
        }
-
 
393
        else {
-
 
394
                mustFreeSrcMod = false;
-
 
395
        }
-
 
396
 
-
 
397
        if( (hupdate = _BeginUpdateResource(dstname,false)) ){
384
        if( (hupdate = _BeginUpdateResource(dstname,false)) ){
398
                DBG("BeginUpdateResource OK");
385
                DBG("BeginUpdateResource OK");
399
                if( (datarsrc = FindResource(srcmod,MAKEINTRESOURCE(16000), "TPLT"))
386
                if( (datarsrc = FindResource(hDllInstance,MAKEINTRESOURCE(16000 + bits), "TPLT"))
400
                        && (datah = LoadResource(srcmod,datarsrc))
387
                        && (datah = LoadResource(hDllInstance,datarsrc))
401
                        && (datap = (Ptr)LockResource(datah))
388
                        && (datap = (Ptr)LockResource(datah))
402
                        && (aetersrc = FindResource(srcmod, MAKEINTRESOURCE(16000), "AETE"))
389
                        && (aetersrc = FindResource(hDllInstance, MAKEINTRESOURCE(16000), "AETE"))
403
                        && (aeteh = LoadResource(srcmod, aetersrc))
390
                        && (aeteh = LoadResource(hDllInstance, aetersrc))
404
                        && (aetep = (Ptr)LockResource(aeteh))
391
                        && (aetep = (Ptr)LockResource(aeteh))
405
                        && (manifestsrc = FindResource(srcmod, MAKEINTRESOURCE(1), "TPLT"))
392
                        && (manifestsrc = FindResource(hDllInstance, MAKEINTRESOURCE(1), "TPLT"))
406
                        && (manifesth = LoadResource(srcmod, manifestsrc))
393
                        && (manifesth = LoadResource(hDllInstance, manifestsrc))
407
                        && (manifestp = (Ptr)LockResource(manifesth)) )
394
                        && (manifestp = (Ptr)LockResource(manifesth)) )
408
                {
395
                {
409
                        char* newmanifest;
396
                        char* newmanifest;
410
                        int manifestsize = SizeofResource(srcmod, manifestsrc);
397
                        int manifestsize = SizeofResource(hDllInstance, manifestsrc);
411
 
398
 
412
                        newmanifest = (char*)malloc(manifestsize + 4096/*+4KiB for name,description,etc.*/);
399
                        newmanifest = (char*)malloc(manifestsize + 4096/*+4KiB for name,description,etc.*/);
413
 
400
 
414
                        DBG("loaded DATA, PiPL");
401
                        DBG("loaded DATA, PiPL");
415
 
402
 
416
                        strcpy(title,gdata->parm.szTitle);
403
                        strcpy(title,gdata->parm.szTitle);
417
                        if(gdata->parm.popDialog)
404
                        if(gdata->parm.popDialog)
418
                                strcat(title,"...");
405
                                strcat(title,"...");
419
 
406
 
420
                        origsize = SizeofResource(srcmod,datarsrc);
407
                        origsize = SizeofResource(hDllInstance,datarsrc);
421
 
408
 
422
                        if( (newpipl = (Ptr)malloc(origsize+0x300))
409
                        if( (newpipl = (Ptr)malloc(origsize+0x300))
423
                         && (newaete = (Ptr)malloc(4096))
410
                         && (newaete = (Ptr)malloc(4096))
424
                         && (pparm = (PARM_T*)malloc(sizeof(PARM_T))) )
411
                         && (pparm = (PARM_T*)malloc(sizeof(PARM_T))) )
425
                        {
412
                        {
Line 470... Line 457...
470
                                   language than the resource we are saving (Neutral), so we might end up having
457
                                   language than the resource we are saving (Neutral), so we might end up having
471
                                   multiple languages for the same resource. Therefore, the language "Neutral" was
458
                                   multiple languages for the same resource. Therefore, the language "Neutral" was
472
                                   set in the Scripting.rc file for the resource AETE and PIPL.rc for the resources PIPL. */
459
                                   set in the Scripting.rc file for the resource AETE and PIPL.rc for the resources PIPL. */
473
 
460
 
474
                                if(_UpdateResource(hupdate, "TPLT" /* note: caps!! */, MAKEINTRESOURCE(1), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0)  // clean up things we don't need in the standalone plugin
461
                                if(_UpdateResource(hupdate, "TPLT" /* note: caps!! */, MAKEINTRESOURCE(1), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0)  // clean up things we don't need in the standalone plugin
-
 
462
                                        && _UpdateResource(hupdate, "TPLT" /* note: caps!! */, MAKEINTRESOURCE(16032), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0) // clean up things we don't need in the standalone plugin
475
                                        && _UpdateResource(hupdate, "TPLT" /* note: caps!! */, MAKEINTRESOURCE(16000), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0) // clean up things we don't need in the standalone plugin
463
                                        && _UpdateResource(hupdate, "TPLT" /* note: caps!! */, MAKEINTRESOURCE(16064), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0) // clean up things we don't need in the standalone plugin
476
                                        && _UpdateResource(hupdate, RT_DIALOG, MAKEINTRESOURCE(ID_BUILDDLG), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NULL, 0) // clean up things we don't need in the standalone plugin
464
                                        && _UpdateResource(hupdate, RT_DIALOG, MAKEINTRESOURCE(ID_BUILDDLG), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NULL, 0) // clean up things we don't need in the standalone plugin
477
                                        && _UpdateResource(hupdate, RT_DIALOG, MAKEINTRESOURCE(ID_MAINDLG), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NULL, 0) // clean up things we don't need in the standalone plugin
465
                                        && _UpdateResource(hupdate, RT_DIALOG, MAKEINTRESOURCE(ID_MAINDLG), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NULL, 0) // clean up things we don't need in the standalone plugin
478
                                        && _UpdateResource(hupdate, RT_GROUP_ICON, "CAUTION_ICO", MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0) // clean up things we don't need in the standalone plugin
466
                                        && _UpdateResource(hupdate, RT_GROUP_ICON, "CAUTION_ICO", MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0) // clean up things we don't need in the standalone plugin
479
//                                      && _UpdateResource(hupdate, RT_ICON, MAKEINTRESOURCE(1)/*Caution*/, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0) // clean up things we don't need in the standalone plugin
467
//                                      && _UpdateResource(hupdate, RT_ICON, MAKEINTRESOURCE(1)/*Caution*/, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0) // clean up things we don't need in the standalone plugin
480
                                        && _UpdateResource(hupdate, RT_GROUP_CURSOR, MAKEINTRESOURCE(IDC_FF_HAND_QUESTION), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0) // clean up things we don't need in the standalone plugin
468
                                        && _UpdateResource(hupdate, RT_GROUP_CURSOR, "HAND_QUESTION", MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0) // clean up things we don't need in the standalone plugin
481
//                                      && (
-
 
482
//                                              // TODO: Sometimes, the cursors get ID 1,2,3 and somestimes 4,5,6. How to do it better?
469
                                        // TODO: Removing the single resources don't work correctly. Sometimes the cursors are numbered 4,5,6 and sometimes 1,2,3 . Probably conflicts with icons
483
//                                              // TODO: If we do this, we get "Internal error"
-
 
484
//                                              _UpdateResource(hupdate, RT_CURSOR, MAKEINTRESOURCE(3)/*QuestionHand*/, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0)
-
 
485
//                                              || _UpdateResource(hupdate, RT_CURSOR, MAKEINTRESOURCE(6)/*QuestionHand*/, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0) ) // clean up things we don't need in the standalone plugin
470
//                                      && _UpdateResource(hupdate, RT_CURSOR, MAKEINTRESOURCE(3)/*QuestionHand*/, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0) // clean up things we don't need in the standalone plugin
486
                                        && ((bits != 32) || _UpdateResource(hupdate, "DLL", "UNICOWS", MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), NULL, 0)) // clean up things we don't need in the standalone plugin
-
 
487
                                        && _UpdateResource(hupdate, "PIPL" /* note: caps!! */,MAKEINTRESOURCE(16000), MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),newpipl,(DWORD)piplsize)
471
                                        && _UpdateResource(hupdate, "PIPL" /* note: caps!! */,MAKEINTRESOURCE(16000), MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL),newpipl,(DWORD)piplsize)
488
                                        && _UpdateResource(hupdate, "AETE" /* note: caps!! */, MAKEINTRESOURCE(16000), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), newaete, (DWORD)aetesize)
472
                                        && _UpdateResource(hupdate, "AETE" /* note: caps!! */, MAKEINTRESOURCE(16000), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), newaete, (DWORD)aetesize)
489
                                        // OPER and FUNC are written so that "Plugin Manager 2.1" thinks that this plugin is a Filter Factory plugin! SYNM is not important, though.
473
                                        // OPER and FUNC are written so that "Plugin Manager 2.1" thinks that this plugin is a Filter Factory plugin! SYNM is not important, though.
490
                                        && (gdata->obfusc || _UpdateResource(hupdate, "OPER", MAKEINTRESOURCE(16000), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), &dummy_oper, sizeof(dummy_oper)))
474
                                        && (gdata->obfusc || _UpdateResource(hupdate, "OPER", MAKEINTRESOURCE(16000), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), &dummy_oper, sizeof(dummy_oper)))
491
                                        && (gdata->obfusc || _UpdateResource(hupdate, "FUNC", MAKEINTRESOURCE(16000), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), &dummy_func, sizeof(dummy_func)))
475
                                        && (gdata->obfusc || _UpdateResource(hupdate, "FUNC", MAKEINTRESOURCE(16000), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), &dummy_func, sizeof(dummy_func)))
Line 500... Line 484...
500
                        }
484
                        }
501
 
485
 
502
                }else dbglasterror(_strdup("Find-, Load- or LockResource"));
486
                }else dbglasterror(_strdup("Find-, Load- or LockResource"));
503
 
487
 
504
                // Here, the file will be saved
488
                // Here, the file will be saved
505
                if (mustFreeSrcMod) {
-
 
506
                        FreeLibrary(srcmod);
-
 
507
                }
-
 
508
                if (!_EndUpdateResource(hupdate, discard)) {
489
                if (!_EndUpdateResource(hupdate, discard)) {
509
                        dbglasterror(_strdup("EndUpdateResource"));
490
                        dbglasterror(_strdup("EndUpdateResource"));
510
                }
491
                }
511
                else {
492
                else {
512
 
493
 
Line 624... Line 605...
624
                // we must now remove the signature, because the embedding of parameter data has invalidated it.
605
                // we must now remove the signature, because the embedding of parameter data has invalidated it.
625
                // Do it before we manipulate anything, in order to avoid that there is an invalid binary (which might annoy AntiVirus software)
606
                // Do it before we manipulate anything, in order to avoid that there is an invalid binary (which might annoy AntiVirus software)
626
                StripAuthenticode(dstname);
607
                StripAuthenticode(dstname);
627
 
608
 
628
                // Now do the resources
609
                // Now do the resources
629
                res = doresources(NULL, dstname, bits);
610
                res = doresources(dstname, bits);
630
                if (!res) {
611
                if (!res) {
631
                        DeleteFile(dstname);
612
                        DeleteFile(dstname);
632
                        sprintf(err, "Could not create %d bit standalone plugin (doresources failed).", bits);
613
                        sprintf(err, "Could not create %d bit standalone plugin (doresources failed).", bits);
633
                        alertuser(_strdup(&err[0]), _strdup(""));
614
                        alertuser(_strdup(&err[0]), _strdup(""));
634
                }
615
                }
Line 642... Line 623...
642
        }
623
        }
643
 
624
 
644
        return res ? noErr : ioErr;
625
        return res ? noErr : ioErr;
645
}
626
}
646
 
627
 
647
Boolean check_unicows() {
-
 
648
        // Unicows.dll is required for Win9x to implement the BeginUpdateResource functionalities
-
 
649
 
-
 
650
        if (isWin32NT()) {
-
 
651
                // Modern Windows don't require UnicoWS
-
 
652
                return true;
-
 
653
        } else {
-
 
654
                HMODULE hLib;
-
 
655
 
-
 
656
                hLib = LoadLibraryA("UNICOWS.DLL");
-
 
657
                if (!hLib) {
-
 
658
                        char dstname[MAX_PATH + 1];
-
 
659
 
-
 
660
                        // Try to install UnicoWS automatically
-
 
661
                        GetSystemDirectoryA(&dstname[0], MAX_PATH);
-
 
662
                        strcat(&dstname[0], "\\UNICOWS.DLL");
-
 
663
                        extract_file("DLL", "UNICOWS", &dstname[0]); // included in make_win.rc
-
 
664
 
-
 
665
                        hLib = LoadLibraryA("UNICOWS.DLL");
-
 
666
                        if (!hLib) {
-
 
667
                                // This should not happen
-
 
668
                                simplealert(_strdup("To build standalone plugins using this version of\nWindows, you need to install UNICOWS.DLL\n\nPlease download it from the Internet\nand place it into your system directory"));
-
 
669
 
-
 
670
                                return false;
-
 
671
                        }
-
 
672
                        else {
-
 
673
                                FreeLibrary(hLib);
-
 
674
                                return true;
-
 
675
                        }
-
 
676
                }
-
 
677
                else {
-
 
678
                        FreeLibrary(hLib);
-
 
679
                        return true;
-
 
680
                }
-
 
681
        }
-
 
682
}
-
 
683
 
-
 
684
OSErr make_standalone(StandardFileReply *sfr){
628
OSErr make_standalone(StandardFileReply *sfr){
685
        OSErr tmpErr, outErr;
629
        OSErr tmpErr, outErr;
686
        char dstname[MAX_PATH+1];
630
        char dstname[MAX_PATH+1];
687
 
631
 
688
        outErr = noErr;
632
        outErr = noErr;
689
 
633
 
690
        check_unicows();
-
 
691
 
-
 
692
        // Make 32 bit:
634
        // Make 32 bit:
693
        // Destfile = no64_or_32(chosenname)
635
        // Destfile = no64_or_32(chosenname)
694
        myp2cstrcpy(dstname, sfr->sfFile.name);
636
        myp2cstrcpy(dstname, sfr->sfFile.name);
695
        remove_64_filename_prefix(dstname);
637
        remove_64_filename_prefix(dstname);
696
        tmpErr = do_make_standalone(&dstname[0], 32);
638
        tmpErr = do_make_standalone(&dstname[0], 32);
697
        if (tmpErr != noErr)
639
        if (tmpErr != noErr)
698
                outErr = tmpErr;
640
                outErr = tmpErr;
699
        else
641
        else
700
                showmessage(_strdup("32 bit standalone filter was successfully created"));
642
                showmessage(_strdup("32 bit standalone filter was successfully created"));
701
 
643
 
702
        if (isWin32NT()) {
-
 
703
                // Make 64 bit:
644
        // Make 64 bit:
704
                // Destfile = no64_or_32(chosenname) + 64
645
        // Destfile = no64_or_32(chosenname) + 64
705
                myp2cstrcpy(dstname, sfr->sfFile.name);
646
        myp2cstrcpy(dstname, sfr->sfFile.name);
706
                remove_64_filename_prefix(dstname);
647
        remove_64_filename_prefix(dstname);
707
                add_64_filename_prefix(dstname);
648
        add_64_filename_prefix(dstname);
708
                tmpErr = do_make_standalone(&dstname[0], 64);
649
        tmpErr = do_make_standalone(&dstname[0], 64);
709
                if (tmpErr != noErr)
650
        if (tmpErr != noErr)
710
                        outErr = tmpErr;
651
                outErr = tmpErr;
711
                else
652
        else
712
                        showmessage(_strdup("64 bit standalone filter was successfully created"));
653
                showmessage(_strdup("64 bit standalone filter was successfully created"));
713
        }
-
 
714
        else {
-
 
715
                // Unicows.dll cannot edit resources of 64 bit DLLs. (Tested with UnicoWS 1.1.3790.0)
-
 
716
                // On WinNT+, the normal Kernel function BeginUpdateResource can edit 64 bit DLLs, even in NT4.0 SP6
-
 
717
                simplewarning(_strdup("Note: A 64 bit standalone filter cannot be created with your Windows version"));
-
 
718
        }
-
 
719
 
654
 
720
        return outErr;
655
        return outErr;
721
}
656
}
722
 
657