Subversion Repositories filter_foundry

Rev

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

Rev 509 Rev 510
Line 98... Line 98...
98
        // Additional seed for Obfusc V7. It is always in the data segment,
98
        // Additional seed for Obfusc V7. It is always in the data segment,
99
        // while obfusc seed 1 is in the code segment (if the compiler allows it)
99
        // while obfusc seed 1 is in the code segment (if the compiler allows it)
100
        return obfusc_seed2;
100
        return obfusc_seed2;
101
}
101
}
102
       
102
 
-
 
103
#ifdef WIN_ENV
-
 
104
Boolean obfusc_seed_replace(FSSpec* dst, uint64_t search1, uint64_t search2, uint64_t replace1, uint64_t replace2, int maxamount1, int maxamount2) {
-
 
105
        uint64_t srecord = 0;
-
 
106
        int found1 = 0, found2 = 0;
-
 
107
        Boolean done = false;
-
 
108
        FILEREF fptr;
-
 
109
        FILECOUNT cnt;
-
 
110
 
-
 
111
        if (FSpOpenDF(dst, fsRdWrPerm, &fptr) != noErr) return -1;
-
 
112
 
-
 
113
        cnt = sizeof(srecord);
-
 
114
        while (FSRead(fptr, &cnt, &srecord) == noErr)
-
 
115
        {
-
 
116
                if (cnt != sizeof(srecord)) break; // EOF reached
-
 
117
                if (srecord == search1) {
-
 
118
                        srecord = replace1;
-
 
119
                        SetFPos(fptr, fsFromMark, -1 * (long)sizeof(srecord));
-
 
120
                        cnt = (int)sizeof(srecord);
-
 
121
                        FSWrite(fptr, &cnt, &srecord);
-
 
122
                        SetFPos(fptr, fsFromStart, 0); // important for fseek
-
 
123
                        found1++;
-
 
124
                        done = (found1 == maxamount1) && (found2 == maxamount2);
-
 
125
                        if (done) break;
-
 
126
                }
-
 
127
                else if (srecord == search2) {
-
 
128
                        srecord = replace2;
-
 
129
                        SetFPos(fptr, fsFromMark, -1 * (long)sizeof(srecord));
-
 
130
                        cnt = (int)sizeof(srecord);
-
 
131
                        FSWrite(fptr, &cnt, &srecord);
-
 
132
                        SetFPos(fptr, fsFromStart, 0); // important for fseek
-
 
133
                        found2++;
-
 
134
                        done = (found1 == maxamount1) && (found2 == maxamount2);
-
 
135
                        if (done) break;
-
 
136
                }
-
 
137
                else {
-
 
138
                        SetFPos(fptr, fsFromMark, -1 * (long)(sizeof(srecord) - 1));
-
 
139
                }
-
 
140
        }
-
 
141
        FSClose(fptr);
-
 
142
 
-
 
143
        return done;
-
 
144
}
-
 
145
#endif
-
 
146
       
103
int rand_msvcc(unsigned int* seed) {
147
int rand_msvcc(unsigned int* seed) {
104
        *seed = *seed * 214013L + 2531011L;
148
        *seed = *seed * 214013L + 2531011L;
105
        return (*seed >> 16) & 0x7fff; /* Scale between 0 and RAND_MAX */
149
        return (*seed >> 16) & 0x7fff; /* Scale between 0 and RAND_MAX */
106
}
150
}
107
 
151
 
Line 320... Line 364...
320
 
364
 
321
        unsigned char* p;
365
        unsigned char* p;
322
        uint64_t initial_seed, initial_seed2, rolseed;
366
        uint64_t initial_seed, initial_seed2, rolseed;
323
        uint32_t xorseed;
367
        uint32_t xorseed;
324
        uint64_t xorseed2;
368
        uint64_t xorseed2;
-
 
369
        size_t size = sizeof(PARM_T);
-
 
370
        int rand_iters, i, j;
325
 
371
 
326
#ifdef MAC_ENV
372
#ifdef MAC_ENV
327
        // Currently, make_mac.c does not implement modifying the executable code (TODO),
373
        // Currently, make_mac.c does not implement modifying the executable code (TODO),
328
        // so we will use the default initial_seed!
374
        // so we will use the default initial_seed!
329
        initial_seed = GetObfuscSeed();
375
        initial_seed = GetObfuscSeed();
Line 353... Line 399...
353
 
399
 
354
        rolseed = initial_seed;
400
        rolseed = initial_seed;
355
        p = (unsigned char*)pparm;
401
        p = (unsigned char*)pparm;
356
        rolshift(&p, &rolseed, sizeof(PARM_T));
402
        rolshift(&p, &rolseed, sizeof(PARM_T));
357
 
403
 
-
 
404
        rand_iters = 0xFFF - (initial_seed & 0xFF) + (initial_seed2 & 0xFF);
-
 
405
        if (rand_iters < 0) rand_iters = 0;
-
 
406
        for (j = rand_iters; j >= 0; j--) {
-
 
407
                uint32_t rand_seed = (initial_seed + initial_seed2 + j) & 0xFFFFFFFF;
-
 
408
                p = (unsigned char*)pparm;
-
 
409
                for (i = 0; i < 10; i++) {
-
 
410
                        rand_msvcc(&rand_seed);
-
 
411
                }
-
 
412
                for (i = 0; i < (int)size; i++) {
-
 
413
                        *p++ ^= (int)(rand_msvcc(&rand_seed) * 1.0 / ((double)RAND_MAX + 1) * 256);
-
 
414
                }
-
 
415
        }
-
 
416
 
358
        xorseed2 = initial_seed2;
417
        xorseed2 = initial_seed2;
359
        p = (unsigned char*)pparm;
418
        p = (unsigned char*)pparm;
360
        xorshift64(&p, &xorseed2, sizeof(PARM_T));
419
        xorshift64(&p, &xorseed2, sizeof(PARM_T));
361
 
420
 
362
        pparm->unknown2 = 7; // obfusc version
421
        pparm->unknown2 = 7; // obfusc version
Line 493... Line 552...
493
 
552
 
494
                        initial_seed = GetObfuscSeed(); // this value will be manipulated during the building of each individual filter (see make_win.c)
553
                        initial_seed = GetObfuscSeed(); // this value will be manipulated during the building of each individual filter (see make_win.c)
495
 
554
 
496
                        if (obfusc_version >= 7) {
555
                        if (obfusc_version >= 7) {
497
                                uint64_t xorseed2, initial_seed2;
556
                                uint64_t xorseed2, initial_seed2;
-
 
557
                                int rand_iters, i, j;
-
 
558
 
498
                                initial_seed2 = GetObfuscSeed2(); // this value will be manipulated during the building of each individual filter (see make_win.c)
559
                                initial_seed2 = GetObfuscSeed2(); // this value will be manipulated during the building of each individual filter (see make_win.c)
499
                                xorseed2 = initial_seed2;
560
                                xorseed2 = initial_seed2;
500
                                p = (unsigned char*)pparm;
561
                                p = (unsigned char*)pparm;
501
                                xorshift64(&p, &xorseed2, sizeof(PARM_T));
562
                                xorshift64(&p, &xorseed2, sizeof(PARM_T));
-
 
563
 
-
 
564
                                rand_iters = 0xFFF - (initial_seed & 0xFF) + (initial_seed2 & 0xFF);
-
 
565
                                if (rand_iters < 0) rand_iters = 0;
-
 
566
                                for (j = 0; j <= rand_iters; j++) {
-
 
567
                                        uint32_t rand_seed = (initial_seed + initial_seed2 + j) & 0xFFFFFFFF;
-
 
568
                                        p = (unsigned char*)pparm;
-
 
569
                                        for (i = 0; i < 10; i++) {
-
 
570
                                                rand_msvcc(&rand_seed);
-
 
571
                                        }
-
 
572
                                        for (i = 0; i < (int)size; i++) {
-
 
573
                                                *p++ ^= (int)(rand_msvcc(&rand_seed) * 1.0 / ((double)RAND_MAX + 1) * 256);
-
 
574
                                        }
-
 
575
                                }
502
                        }
576
                        }
503
 
577
 
504
                        rolseed = initial_seed;
578
                        rolseed = initial_seed;
505
                        p = (unsigned char*)pparm;
579
                        p = (unsigned char*)pparm;
506
                        rolshift(&p, &rolseed, sizeof(PARM_T));
580
                        rolshift(&p, &rolseed, sizeof(PARM_T));