Subversion Repositories filter_foundry

Compare Revisions

Regard whitespace Rev 509 → Rev 510

/trunk/Obfuscation.md
File deleted
/trunk/ff.h
170,6 → 170,9
__declspec(noinline)
#endif
uint64_t GetObfuscSeed2();
#ifdef WIN_ENV
Boolean obfusc_seed_replace(FSSpec* dst, uint64_t search1, uint64_t search2, uint64_t replace1, uint64_t replace2, int maxamount1, int maxamount2);
#endif
int obfuscation_version(PARM_T* pparm);
void obfusc(PARM_T* pparm, uint64_t* out_initial_seed, uint64_t* out_initial_seed2);
void deobfusc(PARM_T* pparm);
/trunk/main.c
423,6 → 423,7
if(setup(pb)){
DoStart(pb);
}else{
simplealert_id(MSG_SAVED_EXPR_ERR_ID);
*result = filterBadParameters;
}
}
/trunk/make_win.c
274,38 → 274,6
return res == noErr; // res=0 means everything was noErr, res=1 means something was !=noErr
}
 
int binary_replace_file(FSSpec* dst, uint64_t search, uint64_t replace, Boolean align, int maxamount) {
uint64_t srecord = 0;
int found = 0;
FILEREF fptr;
FILECOUNT cnt;
 
if (FSpOpenDF(dst, fsRdWrPerm, &fptr) != noErr) return -1;
 
cnt = sizeof(srecord);
while (FSRead(fptr, &cnt, &srecord) == noErr)
{
if (cnt != sizeof(srecord)) break; // EOF reached
if (srecord == search) {
srecord = replace;
SetFPos(fptr, fsFromMark, -1 * (long)sizeof(srecord));
cnt = (int)sizeof(srecord);
FSWrite(fptr, &cnt, &srecord);
SetFPos(fptr, fsFromStart, 0); // important for fseek
found++;
if (found == maxamount) break;
}
else {
if (!align) {
SetFPos(fptr, fsFromMark, -1 * (long)(sizeof(srecord) - 1));
}
}
}
FSClose(fptr);
 
return found;
}
 
uint32_t calculate_checksum(FSSpec* dst) {
//Calculate checksum of image
// Taken from "PE Bliss" Cross-Platform Portable Executable C++ Library
547,11 → 515,9
// and if that failed, try without alignment ("1").
// We only need to set maxamount to "1", because "const volatile" makes sure that
// the compiler won't place (inline) it at several locations in the code.
// TODO: This is very slow
if ((binary_replace_file(dst, GetObfuscSeed(), obfuscseed, /*0 means "align to 1"*/0, /*maxamount=*/1) == 0) ||
(binary_replace_file(dst, GetObfuscSeed2(), obfuscseed2, /*0 means "align to 1"*/0, /*maxamount=*/1) == 0))
if (!obfusc_seed_replace(dst, GetObfuscSeed(), GetObfuscSeed2(), obfuscseed, obfuscseed2, 1, 1))
{
simplewarning((TCHAR*)TEXT("binary_replace_file failed")); // TODO (Not so important): TRANSLATE
simplewarning((TCHAR*)TEXT("obfusc_seed_replace failed")); // TODO (Not so important): TRANSLATE
discard = true;
}
}
/trunk/obfusc.c
100,6 → 100,50
return obfusc_seed2;
}
#ifdef WIN_ENV
Boolean obfusc_seed_replace(FSSpec* dst, uint64_t search1, uint64_t search2, uint64_t replace1, uint64_t replace2, int maxamount1, int maxamount2) {
uint64_t srecord = 0;
int found1 = 0, found2 = 0;
Boolean done = false;
FILEREF fptr;
FILECOUNT cnt;
 
if (FSpOpenDF(dst, fsRdWrPerm, &fptr) != noErr) return -1;
 
cnt = sizeof(srecord);
while (FSRead(fptr, &cnt, &srecord) == noErr)
{
if (cnt != sizeof(srecord)) break; // EOF reached
if (srecord == search1) {
srecord = replace1;
SetFPos(fptr, fsFromMark, -1 * (long)sizeof(srecord));
cnt = (int)sizeof(srecord);
FSWrite(fptr, &cnt, &srecord);
SetFPos(fptr, fsFromStart, 0); // important for fseek
found1++;
done = (found1 == maxamount1) && (found2 == maxamount2);
if (done) break;
}
else if (srecord == search2) {
srecord = replace2;
SetFPos(fptr, fsFromMark, -1 * (long)sizeof(srecord));
cnt = (int)sizeof(srecord);
FSWrite(fptr, &cnt, &srecord);
SetFPos(fptr, fsFromStart, 0); // important for fseek
found2++;
done = (found1 == maxamount1) && (found2 == maxamount2);
if (done) break;
}
else {
SetFPos(fptr, fsFromMark, -1 * (long)(sizeof(srecord) - 1));
}
}
FSClose(fptr);
 
return done;
}
#endif
int rand_msvcc(unsigned int* seed) {
*seed = *seed * 214013L + 2531011L;
return (*seed >> 16) & 0x7fff; /* Scale between 0 and RAND_MAX */
322,6 → 366,8
uint64_t initial_seed, initial_seed2, rolseed;
uint32_t xorseed;
uint64_t xorseed2;
size_t size = sizeof(PARM_T);
int rand_iters, i, j;
 
#ifdef MAC_ENV
// Currently, make_mac.c does not implement modifying the executable code (TODO),
355,6 → 401,19
p = (unsigned char*)pparm;
rolshift(&p, &rolseed, sizeof(PARM_T));
 
rand_iters = 0xFFF - (initial_seed & 0xFF) + (initial_seed2 & 0xFF);
if (rand_iters < 0) rand_iters = 0;
for (j = rand_iters; j >= 0; j--) {
uint32_t rand_seed = (initial_seed + initial_seed2 + j) & 0xFFFFFFFF;
p = (unsigned char*)pparm;
for (i = 0; i < 10; i++) {
rand_msvcc(&rand_seed);
}
for (i = 0; i < (int)size; i++) {
*p++ ^= (int)(rand_msvcc(&rand_seed) * 1.0 / ((double)RAND_MAX + 1) * 256);
}
}
 
xorseed2 = initial_seed2;
p = (unsigned char*)pparm;
xorshift64(&p, &xorseed2, sizeof(PARM_T));
495,11 → 554,26
 
if (obfusc_version >= 7) {
uint64_t xorseed2, initial_seed2;
int rand_iters, i, j;
 
initial_seed2 = GetObfuscSeed2(); // this value will be manipulated during the building of each individual filter (see make_win.c)
xorseed2 = initial_seed2;
p = (unsigned char*)pparm;
xorshift64(&p, &xorseed2, sizeof(PARM_T));
 
rand_iters = 0xFFF - (initial_seed & 0xFF) + (initial_seed2 & 0xFF);
if (rand_iters < 0) rand_iters = 0;
for (j = 0; j <= rand_iters; j++) {
uint32_t rand_seed = (initial_seed + initial_seed2 + j) & 0xFFFFFFFF;
p = (unsigned char*)pparm;
for (i = 0; i < 10; i++) {
rand_msvcc(&rand_seed);
}
for (i = 0; i < (int)size; i++) {
*p++ ^= (int)(rand_msvcc(&rand_seed) * 1.0 / ((double)RAND_MAX + 1) * 256);
}
}
}
 
rolseed = initial_seed;
p = (unsigned char*)pparm;
/trunk/ui.c
229,6 → 229,8
/* uh oh, couldn't parse one of the saved expressions...this is fatal */
DISABLEDLGITEM(dp,IDOK);
if(gdata->standalone){
// TODO: But before this happens, we get filterBadParameters in filterSelectorStart, since setup() failed
// so, do we need this message here at all?
simplealert_id(MSG_SAVED_EXPR_ERR_ID);
}else{
DISABLEDLGITEM(dp,SAVEITEM);