int TagDialog::changes() { int result=TagDialog::NOCHANGE; bool modified = false; modified |= !equalString( kComboBox_artist->lineEdit()->text(), m_bundle.artist() ); modified |= !equalString( kComboBox_album->lineEdit()->text(), m_bundle.album() ); modified |= !equalString( kComboBox_genre->lineEdit()->text(), m_bundle.genre() ); modified |= kIntSpinBox_year->value() != m_bundle.year(); modified |= kIntSpinBox_discNumber->value() != m_bundle.discNumber(); modified |= !equalString( kComboBox_composer->lineEdit()->text(), m_bundle.composer() ); modified |= !equalString( kTextEdit_comment->text(), m_bundle.comment() ); if (!m_urlList.count() || m_perTrack) { //ignore these on MultipleTracksMode modified |= !equalString( kLineEdit_title->text(), m_bundle.title() ); modified |= kIntSpinBox_track->value() != m_bundle.track(); } if (modified) result |= TagDialog::TAGSCHANGED; if (kIntSpinBox_score->value() != m_score) result |= TagDialog::SCORECHANGED; if (kComboBox_rating->currentItem() != ( m_bundle.rating() ? m_bundle.rating() - 1 : 0 ) ) result |= TagDialog::RATINGCHANGED; if ( !equalString( kTextEdit_lyrics->text(), m_lyrics ) ) result |= TagDialog::LYRICSCHANGED; return result; }
/* * params: * pBlockBodyStart -- pointer to first byte of block's body * varsLocal -- list of agrument's names, level up variables * blocks: * 1) function(...) block end * 2) do block end * 3) for ... do block end * 4) while ... do block end * 5) if ... then block end * 6) function type, this is similar to function, see item 1) * ============================= * obfuscate until not found "end" of current block * * return: * first byte after block's body * * varsStackBlock -- local variables in block * varsStackParent -- local variables in parent block * localModuleVars -- local variables in module * level -- block level, for module == 0 */ char* obfuscateLocalVarsInBlock(StringStream& stream, char *pBlockBodyStart, LocalVarsStack& varsStackBlock, LocalVarsStack& localModuleVars, int &level) { char *p = pBlockBodyStart; char wordBuffer[300]; char *pWordBuffer = wordBuffer; size_t wordLen = 0; size_t blockVarsCount = varsStackBlock.count(); // Count of variables in the block size_t currentBlockVarsCount = 0; const char *pBlockStart = p; const char *pBlockEnd = p + strlen(p) - 1; while (*p) { if (isStringStart(p)) { size_t size = skipStringAndMove(&p, NULL); stream.write(p - size, size); continue; } // "while loop" too if (*p == 'd') { if (equalString(p, "do", sizeof("do") - 1, pBlockStart, pBlockEnd)) { stream << "do" << *(p + 2); char *pBodyStart = p + 2 + 1; ++level; p = obfuscateLocalVarsInBlock(stream, pBodyStart, varsStackBlock, localModuleVars, level); --level; } } else if (*p == 'r') { // TODO: repeat block if (equalString(p, "repeat", sizeof("repeat") - 1, pBlockStart, pBlockEnd)) { stream << "repeat" << *(p + 6); } } else if (*p == 'f') { // if found global function if (!strncmp(p, "function", 8) && !isAlphaFun(*(p + 8))) { // LocalVarsStack localVarsStackBlock; stream << "function"; p += 8; p = readFunctionName(stream, p); size_t argCount = varsStackBlock.count(); p = readAndObfuscateFunctionArguments(stream, p, varsStackBlock); argCount = varsStackBlock.count() - argCount; ++level; p = obfuscateLocalVarsInBlock(stream, p, varsStackBlock, localModuleVars, level); varsStackBlock.pops(argCount); --level; } if (equalString(p, "for", sizeof("for") - 1, pBlockStart, pBlockEnd)) { stream << "for "; char *pInitStart = p + 3 + 1; size_t varInitCount = varsStackBlock.count(); p = readAndObfuscateForLocalVariables(stream, pInitStart, varsStackBlock, localModuleVars); varInitCount = varsStackBlock.count() - varInitCount; ++level; p = obfuscateLocalVarsInBlock(stream, p, varsStackBlock, localModuleVars, level); varsStackBlock.pops(varInitCount); --level; } } else if (*p == 't') { if (equalString(p, "then", sizeof("then") - 1, pBlockStart, pBlockEnd)) { stream << "then" << *(p + 4); char *pBodyStart = p + 4 + 1; ++level; p = obfuscateLocalVarsInBlock(stream, pBodyStart, varsStackBlock, localModuleVars, level); --level; } } else if (*p == 'e') { if (equalString(p, "end", sizeof("end") - 1, pBlockStart, pBlockEnd)) { stream << "end"; if (level) varsStackBlock.pops(currentBlockVarsCount); return p + 3; } if (equalString(p, "elseif", sizeof("elseif") - 1, pBlockStart, pBlockEnd)) { stream << "elseif"; if (level) varsStackBlock.pops(currentBlockVarsCount); return p + 6; } if (equalString(p, "else", sizeof("else") - 1, pBlockStart, pBlockEnd)) { // LocalVarsStack varsStackBlockNew; stream << "else" << *(p + 4); char *pBodyStart = p + 4 + 1; p = obfuscateLocalVarsInBlock(stream, pBodyStart, varsStackBlock, localModuleVars, level); --level; } } else if (*p == 'u') { if (equalString(p, "until", sizeof("until") - 1, pBlockStart, pBlockEnd)) { stream << "until"; return p + 5; } } else if (*p == 'l') { if (equalString(p, "local", sizeof("local") - 1, pBlockStart, pBlockEnd)) { stream << "local "; p += 6; bool bFunction = !strncmp(p, "function", sizeof("function") - 1) && !isAlphaFun(p[8]); if (bFunction && !isAlphaFun(p[8])) { LocalVarsStack localVarsStackBlock; stream << "function"; p += 8; p = readFunctionName(stream, p); p = readAndObfuscateFunctionArguments(stream, p, localVarsStackBlock); ++level; p = obfuscateLocalVarsInBlock(stream, p, localVarsStackBlock, localModuleVars, level); --level; } else { size_t tmpCount = varsStackBlock.count(); p = readAndObfuscateLocalVariables(stream, p, varsStackBlock, localModuleVars, level); blockVarsCount += varsStackBlock.count() - tmpCount; // TODO: compare blockVarsCount and currentBlockVarsCount currentBlockVarsCount += varsStackBlock.count() - tmpCount; continue; } } } if (isAlphaFun(*p)) { ++wordLen; *pWordBuffer = *p; ++pWordBuffer; ++p; continue; } else { *pWordBuffer = 0; char *pBefore = p - wordLen - 1; if (wordLen > 0) { // skip table's fields if (*pBefore == '.' && *(pBefore - 1) != '.') { stream << wordBuffer << *p; ++p; pWordBuffer = wordBuffer; wordLen = 0; continue; } std::string str(wordBuffer); stObfuscatedName var; var.name = str; bool bFind = false; if (level) bFind = varsStackBlock.find(var); if (!bFind) bFind = localModuleVars.find(var); if (bFind) { stream << var.fake_name; } else { stream << wordBuffer; } } wordLen = 0; pWordBuffer = wordBuffer; } if (*p) { // HACK: stream << *p; ++p; } } return p; }
int main( int argc, char **argv) { /* sample command lines -i bdv.bshort -o junk.bshort -V -# 16 */ OSErr error = noErr; static char id[] = "$Revision: 1.2 $$Date: 2002/09/10 22:06:02 $"; char headerName[ NAME_SIZE ]; char *extension; char ofName[ NAME_SIZE ]; int OutOrder; error = ProcessCommandLine( argc, argv ); ILError( error, "error in command line" ); extension = strrchr( u.InFileName, '.' ); if( !strlen(extension) ) { printf( "Input file name error\n" ); return 0; } if( !equalString( extension, ".bfloat" )) { printf( "This utility works only on bfloat images!\n" ); return 0; } // strcpy( headerName, u.InFileName, NAME_SIZE ); strcpy( headerName, u.InFileName ); //zrinka 09/10/02 extension = strrchr( headerName, '.' ); if( !strlen(extension) ) { printf( "Input file name error\n" ); return 0; } sprintf( extension, ".hdr" ); u.inFile = errfopen( headerName, "r" ); fscanf( u.inFile, "%d%d%d%d", &u.id.ys, &u.id.xs, &u.id.zs, &u.id.ByteOrder ); // error = ck_fclose( u.inFile, "input header" ); error = ck_fclose( u.inFile ); //zrinka 09/10/02 u.inFile = errfopen( u.InFileName, "rb" ); strcpy( ofName, u.OutFileName ); strcat( ofName, ".bfloat" ); u.outFile = errfopen( ofName, "wb" ); error = DoSwap( u.inFile, u.outFile ); ILError( error, argv[0] ); error = ck_fclose( u.inFile ); ILError( error, "infile" ); error = ck_fclose( u.outFile ); ILError( error, "infile" ); strcpy( ofName, u.OutFileName ); strcat( ofName, ".hdr" ); u.outFile = errfopen( ofName, "w" ); if( u.id.ByteOrder == 1 ) { // pc-dec bytOrder OutOrder = 0; } else { OutOrder = 1; } fprintf( u.outFile, "%d %d %d %d", u.id.ys, u.id.xs, u.id.zs, OutOrder ); error = ck_fclose( u.outFile ); ILError( error, "main" ); }