Subversion Repositories filter_foundry

Rev

Rev 85 | Rev 107 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 85 Rev 106
Line 1... Line 1...
1
/*
1
/*
2
    This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
2
    This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
3
    Copyright (C) 2003-5 Toby Thain, toby@telegraphics.com.au
3
    Copyright (C) 2003-5 Toby Thain, toby@telegraphics.com.au
4
 
4
 
5
    This program is free software; you can redistribute it and/or modify
5
    This program is free software; you can redistribute it and/or modify
6
    it under the terms of the GNU General Public License as published by  
6
    it under the terms of the GNU General Public License as published by
7
    the Free Software Foundation; either version 2 of the License, or
7
    the Free Software Foundation; either version 2 of the License, or
8
    (at your option) any later version.
8
    (at your option) any later version.
9
 
9
 
10
    This program is distributed in the hope that it will be useful,
10
    This program is distributed in the hope that it will be useful,
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    GNU General Public License for more details.
13
    GNU General Public License for more details.
14
 
14
 
15
    You should have received a copy of the GNU General Public License  
15
    You should have received a copy of the GNU General Public License
16
    along with this program; if not, write to the Free Software
16
    along with this program; if not, write to the Free Software
17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
*/
18
*/
19
 
19
 
20
#include <stddef.h>
20
#include <stddef.h>
Line 28... Line 28...
28
 
28
 
29
long event_id;
29
long event_id;
30
 
30
 
31
/*
31
/*
32
Find a printable 4-character key, remembering (see PS API guide):
32
Find a printable 4-character key, remembering (see PS API guide):
33
All IDÕs starting with an uppercase letter are reserved by Adobe.
33
All IDÕs starting with an uppercase letter are reserved by Adobe.
34
All IDÕs that are all uppercase are reserved by Apple.
34
All IDÕs that are all uppercase are reserved by Apple.
35
All IDÕs that are all lowercase are reserved by Apple.
35
All IDÕs that are all lowercase are reserved by Apple.
36
This leaves all IDÕs that begin with a lowercase letter and have at least
36
This leaves all IDÕs that begin with a lowercase letter and have at least
37
one uppercase letter for you and other plug-in developers.
37
one uppercase letter for you and other plug-in developers.
38
*/
38
*/
Line 62... Line 62...
62
 
62
 
63
        p = (char*)pipl + origsize;
63
        p = (char*)pipl + origsize;
64
        prop = (PIProperty*)p;
64
        prop = (PIProperty*)p;
65
 
65
 
66
        /* add Title/Name property key */
66
        /* add Title/Name property key */
67
       
67
 
68
        prop->vendorID = kPhotoshopSignature;
68
        prop->vendorID = kPhotoshopSignature;
69
        prop->propertyKey = PINameProperty;
69
        prop->propertyKey = PINameProperty;
70
        prop->propertyID = 0;
70
        prop->propertyID = 0;
71
        prop->propertyLength = title[0]+1;
71
        prop->propertyLength = title[0]+1;
72
        PLstrcpy((StringPtr)prop->propertyData,title);
72
        PLstrcpy((StringPtr)prop->propertyData,title);
73
       
73
 
74
        // skip past new property record, and any padding
74
        // skip past new property record, and any padding
75
        p += (offsetof(PIProperty,propertyData) + prop->propertyLength + 3) & -4;
75
        p += (offsetof(PIProperty,propertyData) + prop->propertyLength + 3) & -4;
76
        prop = (PIProperty*)p;
76
        prop = (PIProperty*)p;
77
       
77
 
78
        /* add Category property key */
78
        /* add Category property key */
79
       
79
 
80
        prop->vendorID = kPhotoshopSignature;
80
        prop->vendorID = kPhotoshopSignature;
81
        prop->propertyKey = PICategoryProperty;
81
        prop->propertyKey = PICategoryProperty;
82
        prop->propertyID = 0;
82
        prop->propertyID = 0;
83
        prop->propertyLength = gdata->parm.category[0]+1;
83
        prop->propertyLength = gdata->parm.category[0]+1;
84
        PLstrcpy((StringPtr)prop->propertyData,gdata->parm.category);
84
        PLstrcpy((StringPtr)prop->propertyData,gdata->parm.category);
85
       
85
 
86
        p += (offsetof(PIProperty,propertyData) + prop->propertyLength + 3) & -4;
86
        p += (offsetof(PIProperty,propertyData) + prop->propertyLength + 3) & -4;
87
        prop = (PIProperty*)p;
87
        prop = (PIProperty*)p;
88
 
88
 
89
        /* add HasTerminology property key */  
89
        /* add HasTerminology property key */
90
 
90
 
91
        /* construct scope string by concatenating Category and Title - hopefully unique! */
91
        /* construct scope string by concatenating Category and Title - hopefully unique! */
92
        hstm = (struct hstm_data*)prop->propertyData;
92
        hstm = (struct hstm_data*)prop->propertyData;
93
        scopelen = sprintf(hstm->scope,"%s %s",
93
        scopelen = sprintf(hstm->scope,"%s %s",
94
                                           INPLACEP2CSTR(gdata->parm.category),
94
                                           INPLACEP2CSTR(gdata->parm.category),
Line 104... Line 104...
104
        prop->propertyLength = offsetof(struct hstm_data,scope) + scopelen + 1;
104
        prop->propertyLength = offsetof(struct hstm_data,scope) + scopelen + 1;
105
        hstm->version = 0;
105
        hstm->version = 0;
106
        hstm->class_id = plugInClassID;
106
        hstm->class_id = plugInClassID;
107
        hstm->event_id = event_id;
107
        hstm->event_id = event_id;
108
        hstm->aete_resid = AETE_ID;
108
        hstm->aete_resid = AETE_ID;
109
       
109
 
110
        p += (16+prop->propertyLength+3) & -4;
110
        p += (16+prop->propertyLength+3) & -4;
111
 
111
 
112
        return p - (char*)pipl;  // figure how many bytes were added
112
        return p - (char*)pipl;  // figure how many bytes were added
113
}
113
}
114
 
114
 
Line 121... Line 121...
121
#define SKIP_PSTR(j) (j += 1+aete[j])
121
#define SKIP_PSTR(j) (j += 1+aete[j])
122
 
122
 
123
long fixaete(unsigned char *aete,long origsize,StringPtr title){
123
long fixaete(unsigned char *aete,long origsize,StringPtr title){
124
        int offset,oldlen,newlen,desclen,oldpad,newpad;
124
        int offset,oldlen,newlen,desclen,oldpad,newpad;
125
        Str255 desc;
125
        Str255 desc;
126
       
126
 
127
        offset = 8; /* point at suite name */
127
        offset = 8; /* point at suite name */
128
 
128
 
129
        SKIP_PSTR(offset); /* skip suite name (vendor) [maybe this should become author??] */
129
        SKIP_PSTR(offset); /* skip suite name (vendor) [maybe this should become author??] */
130
        SKIP_PSTR(offset); /* skip suite description [set this from dialog field??] */
130
        SKIP_PSTR(offset); /* skip suite description [set this from dialog field??] */
131
        ALIGNWORD(offset);
131
        ALIGNWORD(offset);
Line 143... Line 143...
143
        newpad = (newlen + desclen) & 1;
143
        newpad = (newlen + desclen) & 1;
144
#else
144
#else
145
        oldpad = newpad = 0;
145
        oldpad = newpad = 0;
146
#endif
146
#endif
147
        /* shift latter part of aete data, taking into account new string lengths */
147
        /* shift latter part of aete data, taking into account new string lengths */
148
        memcpy(aete+offset+1+newlen+newpad,
148
        memcpy(aete+offset+1+newlen+newpad,
149
                   aete+offset+1+oldlen+oldpad,
149
                   aete+offset+1+oldlen+oldpad,
150
                   origsize-offset-1-oldlen-oldpad); /* phew! */
150
                   origsize-offset-1-oldlen-oldpad); /* phew! */
151
        /* copy in new title string */
151
        /* copy in new title string */
152
        PLstrcpy((StringPtr)(aete+offset),title);
152
        PLstrcpy((StringPtr)(aete+offset),title);
153
        /* copy description string into right place... [this could be new description from dialog field??] */
153
        /* copy description string into right place... [this could be new description from dialog field??] */
154
        PLstrcpy((StringPtr)(aete+offset+1+newlen),desc);
154
        PLstrcpy((StringPtr)(aete+offset+1+newlen),desc);
155
       
155
 
156
        SKIP_PSTR(offset); /* skip (new) event name */
156
        SKIP_PSTR(offset); /* skip (new) event name */
157
        SKIP_PSTR(offset); /* skip event description */
157
        SKIP_PSTR(offset); /* skip event description */
158
        ALIGNWORD(offset);
158
        ALIGNWORD(offset);
159
       
159
 
160
        /* set event ID */
160
        /* set event ID */
161
        *(unsigned long*)(aete+offset+4) = event_id; /* FIXME: this might be unaligned access on some platforms?? */
161
        *(unsigned long*)(aete+offset+4) = event_id; /* FIXME: this might be unaligned access on some platforms?? */
162
 
162
 
163
        return origsize-oldlen-oldpad+newlen+newpad;
163
        return origsize-oldlen-oldpad+newlen+newpad;
164
}
164
}
165
 
165
 
166
void obfusc(unsigned char *pparm,size_t size){
166
void obfusc(unsigned char *pparm,size_t size){
167
        int i;
167
        int i;
168
        unsigned char *p;
168
        unsigned char *p;
-
 
169
 
-
 
170
        /* Do a small self-test to test if the stdlib implementation works as expected, i.e. that it only
-
 
171
         * depends on the seed set by srand() and on nothing else.
-
 
172
         */
-
 
173
        srand(0xdc43df3c);
-
 
174
        int selftest1 = rand();
-
 
175
        int selftest2 = rand();
-
 
176
        int selftest3 = rand();
-
 
177
 
-
 
178
        srand(0xdc43df3c);
-
 
179
        if ((rand() != selftest1) || (rand() != selftest2) || (rand() != selftest3)) {
-
 
180
                // This should never happen
-
 
181
                simplealert("Stdcall rand() implementation does not work as expected. Obfuscation operation will be cancelled.");
-
 
182
                return; // apply no obfuscation
169
       
183
        }
-
 
184
 
170
        /* Very simplistic. meant to hide from casual observation/loading only.
185
        /* Very simplistic. meant to hide from casual observation/loading only.
171
         * Results are platform dependent, but this should not matter. */
186
         * Results are platform dependent, but this should not matter. */
172
        srand(0xdc43df3c);
187
        srand(0xdc43df3c);
173
        for(i = size, p = pparm; i--;)
188
        for(i = size, p = pparm; i--;)
174
                *p++ ^= rand();
189
                *p++ ^= rand();