nsresult nsDOMStorageDBWrapper::GetDomainFromScopeKey(const nsACString& aScope, nsACString& aDomain) { nsCAutoString reverseDomain, scope; scope = aScope; scope.Left(reverseDomain, scope.FindChar(':')-1); ReverseString(reverseDomain, aDomain); return NS_OK; }
nsresult nsDOMStorageDBWrapper::CreateDomainScopeDBKey(const nsACString& aAsciiDomain, nsACString& aKey) { if (aAsciiDomain.IsEmpty()) return NS_ERROR_NOT_AVAILABLE; ReverseString(aAsciiDomain, aKey); aKey.AppendLiteral("."); return NS_OK; }
void ReverseWords(char *buf) { char current_char; int first = 0; int current = 0; while(current < strlen(buf)){ current_char = buf[current]; if (current_char == ' '){ printf("Current state:%s\n", buf); ReverseString(buf[first], first, current - 1); printf("Current state:%s\n", buf); current++; first = current; } else{ current++; } } printf("first = %d current = %d\n", first, current); ReverseString(buf[first], first, current - 1); }
// 通过c++ Interop调用函数ReverseString void WrapperClass::ReverseString_CppInterop() { wchar_t* buf = new wchar_t[500]; // c++ Interop调用ReverseString函数 ReverseString(L"String_CppInterop", buf, 500); // 根据返回值创建System.String的实例 String^ result = gcnew String(buf); delete [] buf; Console::WriteLine("翻转字符串结果(C++ Interop):{0} -> {1}", "String_CppInterop", result); }
nsresult CreateReversedDomain(const nsACString& aAsciiDomain, nsACString& aKey) { if (aAsciiDomain.IsEmpty()) { return NS_ERROR_NOT_AVAILABLE; } ReverseString(aAsciiDomain, aKey); aKey.AppendLiteral("."); return NS_OK; }
int main(void) { char buffer[50] = {'\0'}; while(strcmp(buffer, "-1")){ printf("Enter the sentence. -1 to end\n"); gets(buffer); buffer[strlen(buffer)] = '\0'; ReverseString(buffer, 0, (strlen(buffer)-1)); ReverseWords(buffer); printf("After reversing words: %s\n", buffer); } printf("Good Bye!\n"); return 0; }
char * IntToAscii(int n) { unsigned index=0; for(;index<11;index++)IntOut[index]=0; int i, sign; if ((sign = n) < 0) /* record sign */ n = -n; /* make n positive */ i = 0; do { /* generate digits in reverse order */ IntOut[i++] = n % 10 + '0'; /* get next digit */ } while ((n /= 10) > 0); /* delete it */ if (sign < 0) IntOut[i++] = '-'; IntOut[i] = '\0'; ReverseString(IntOut); return IntOut; }
void ReverseWords( char *str ) { int start = 0, end = 0; while( str[ start ] != '\0' ) { while( ( str[end + 1] != ' ' ) && ( str[end + 1] != '\0' ) ) { end = end + 1; } ReverseString( str + start, str + end ); start = end; start = start + 1; end = start; if( str[start] == ' ' ) { start = start + 1; end = start; } } }
void GetReversedHostname(const nsString& aForward, nsString& aRevHost) { ReverseString(aForward, aRevHost); aRevHost.Append(char16_t('.')); }
char* ReverseString(char* str){ int len = strlen(str); ReverseString(str,0,len-1); return str; }
void OutputPairedSAM(const BestMatch& best_match_1, const BestMatch& best_match_2, const Genome& genome, const string& read_name, const string& read_seq1, const string& read_score1, const string& read_seq2, const string& read_score2, const int& len, const int& flag_1, const int& flag_2, StatPairedReads& stat_paired_reads, FILE * fout) { uint32_t chr_id_1 = getChromID(genome.start_index, best_match_1.genome_pos); uint32_t chr_id_2 = getChromID(genome.start_index, best_match_2.genome_pos); uint32_t s1 = 0, s2 = 0, e1 = 0, e2 = 0; ForwardChromPosition(best_match_1.genome_pos, best_match_1.strand, chr_id_1, read_seq1.size(), genome, s1, e1); ForwardChromPosition(best_match_2.genome_pos, best_match_2.strand, chr_id_2, read_seq2.size(), genome, s2, e2); uint32_t mismatch1 = best_match_1.mismatch; uint32_t mismatch2 = best_match_2.mismatch; if (best_match_1.times == 0) { s1 = 0; mismatch1 = 0; } else { s1 += 1; } if (best_match_2.times == 0) { s2 = 0; mismatch2 = 0; } else { s2 += 1; } int len1 = best_match_1.strand == '+' ? len : -len; int len2 = best_match_2.strand == '+' ? len : -len; string rnext1 = "=", rnext2 = "="; if (flag_1 & 0x2) { rnext1 = "="; rnext2 = "="; } else { if (best_match_1.times == 0) { rnext1 = "*"; } else { rnext1 = genome.name[chr_id_1].c_str(); } if (best_match_2.times == 0) { rnext2 = "*"; } else { rnext2 = genome.name[chr_id_2].c_str(); } } string read_seq1_tmp = read_seq1; string read_seq2_tmp = read_seq2; string read_score1_tmp = read_score1; string read_score2_tmp = read_score2; if (best_match_1.strand == '-') { read_seq1_tmp = ReverseComplimentString(read_seq1_tmp); read_score1_tmp = ReverseString(read_score1_tmp); } if (best_match_2.strand == '-') { read_seq2_tmp = ReverseComplimentString(read_seq2_tmp); read_score2_tmp = ReverseString(read_score2_tmp); } uint32_t read_len1 = read_seq1.size(); uint32_t read_len2 = read_seq2.size(); if (best_match_1.times == 0 && stat_paired_reads.stat_single_reads_1.unmapped) { fprintf(fout, "%s\t%d\t*\t%u\t255\t*\t%s\t%u\t%d\t%s\t%s\tNM:i:%u\n", read_name.c_str(), flag_1, s1, rnext2.c_str(), s2, len1, read_seq1_tmp.c_str(), read_score1_tmp.c_str(), mismatch1); } else if (best_match_1.times == 1) { fprintf(fout, "%s\t%d\t%s\t%u\t255\t%uM\t%s\t%u\t%d\t%s\t%s\tNM:i:%u\n", read_name.c_str(), flag_1, genome.name[chr_id_1].c_str(), s1, read_len1, rnext2.c_str(), s2, len1, read_seq1_tmp.c_str(), read_score1_tmp.c_str(), mismatch1); } else if (best_match_1.times >= 2 && stat_paired_reads.stat_single_reads_1.ambiguous) { fprintf(fout, "%s\t%d\t%s\t%u\t255\t%uM\t%s\t%u\t%d\t%s\t%s\tNM:i:%u\n", read_name.c_str(), flag_1, genome.name[chr_id_1].c_str(), s1, read_len1, rnext2.c_str(), s2, len1, read_seq1_tmp.c_str(), read_score1_tmp.c_str(), mismatch1); } if (best_match_2.times == 0 && stat_paired_reads.stat_single_reads_2.unmapped) { fprintf(fout, "%s\t%d\t*\t%u\t255\t*\t%s\t%u\t%d\t%s\t%s\tNM:i:%u\n", read_name.c_str(), flag_2, s2, rnext1.c_str(), s1, len2, read_seq2_tmp.c_str(), read_score2_tmp.c_str(), mismatch2); } else if (best_match_2.times == 1) { fprintf(fout, "%s\t%d\t%s\t%u\t255\t%uM\t%s\t%u\t%d\t%s\t%s\tNM:i:%u\n", read_name.c_str(), flag_2, genome.name[chr_id_2].c_str(), s2, read_len2, rnext1.c_str(), s1, len2, read_seq2_tmp.c_str(), read_score2_tmp.c_str(), mismatch2); } else if (best_match_2.times >= 2 && stat_paired_reads.stat_single_reads_2.ambiguous) { fprintf(fout, "%s\t%d\t%s\t%u\t255\t%uM\t%s\t%u\t%d\t%s\t%s\tNM:i:%u\n", read_name.c_str(), flag_2, genome.name[chr_id_2].c_str(), s2, read_len2, rnext1.c_str(), s1, len2, read_seq2_tmp.c_str(), read_score2_tmp.c_str(), mismatch2); } }
int OutputBestPairedResults(const CandidatePosition& r1, const CandidatePosition& r2, const int& frag_range, const uint32_t& read_len1, const uint32_t& read_len2, const Genome& genome, const string& read_name, const string& read_seq1, const string& read_score1, const string& read_seq2, const string& read_score2, const bool& SAM, FILE * fout) { string read_seq2_rev = ReverseComplimentString(read_seq2); string read_scr2_rev = ReverseString(read_score2); uint32_t chr_id1 = getChromID(genome.start_index, r1.genome_pos); uint32_t chr_id2 = getChromID(genome.start_index, r2.genome_pos); uint32_t s1 = 0, s2 = 0, e1 = 0, e2 = 0; ForwardChromPosition(r1.genome_pos, r1.strand, chr_id1, read_len1, genome, s1, e1); ForwardChromPosition(r2.genome_pos, r2.strand, chr_id2, read_len2, genome, s2, e2); uint32_t overlap_s = MAX(s1, s2); uint32_t overlap_e = MIN(e1, e2); uint32_t one_l = r1.strand == '+' ? s1 : MAX(overlap_e, s1); uint32_t one_r = r1.strand == '+' ? MIN(overlap_s, e1) : e1; uint32_t two_l = r1.strand == '+' ? MAX(overlap_e, s2) : s2; uint32_t two_r = r1.strand == '+' ? e2 : MIN(overlap_s, e2); int len = r1.strand == '+' ? (two_r - one_l) : (one_r - two_l); if (SAM) { return len; } string seq(len, 'N'); string scr(len, 'B'); if (len > 0 && len <= frag_range) { // lim_one: offset in merged sequence where overlap starts uint32_t lim_one = one_r - one_l; copy(read_seq1.begin(), read_seq1.begin() + lim_one, seq.begin()); copy(read_score1.begin(), read_score1.begin() + lim_one, scr.begin()); uint32_t lim_two = two_r - two_l; copy(read_seq2_rev.end() - lim_two, read_seq2_rev.end(), seq.end() - lim_two); copy(read_scr2_rev.end() - lim_two, read_scr2_rev.end(), scr.end() - lim_two); // deal with overlapping part if (overlap_s < overlap_e) { uint32_t one_bads = count(read_seq1.begin(), read_seq1.end(), 'N'); int info_one = read_len1 - (one_bads + r1.mismatch); uint32_t two_bads = count(read_seq2_rev.begin(), read_seq2_rev.end(), 'N'); int info_two = read_len2 - (two_bads + r2.mismatch); // use the mate with the most info to fill in the overlap if (info_one >= info_two) { uint32_t a = r1.strand == '+' ? (overlap_s - s1) : (e1 - overlap_e); uint32_t b = r1.strand == '+' ? (overlap_e - s1) : (e1 - overlap_s); copy(read_seq1.begin() + a, read_seq1.begin() + b, seq.begin() + lim_one); copy(read_score1.begin() + a, read_score1.begin() + b, scr.begin() + lim_one); } else { uint32_t a = r1.strand == '+' ? (overlap_s - s2) : (e2 - overlap_e); uint32_t b = r1.strand == '+' ? (overlap_e - s2) : (e2 - overlap_s); copy(read_seq2_rev.begin() + a, read_seq2_rev.begin() + b, seq.begin() + lim_one); copy(read_scr2_rev.begin() + a, read_scr2_rev.begin() + b, scr.begin() + lim_one); } } } uint32_t start_pos = r1.strand == '+' ? s1 : s2; fprintf(fout, "%s\t%u\t%u\tFRAG:%s\t%u\t%c\t%s\t%s\n", genome.name[chr_id1].c_str(), start_pos, start_pos + len, read_name.c_str(), r1.mismatch + r2.mismatch, r1.strand, seq.c_str(), scr.c_str()); return 0; }
void BattleNetSocket::InformationRequest() { /*if (reader->ReadBuffer() < 11) { delete reader; printf( "[InformationRequest] Packet has no header. Refusing to handle." ); return; }*/ if (FirstAuth) FirstAuth = false; else { InformationRequestSecond(); return; } InformationRequestStruct infoR; int32 n = reader->ReadInt32(32); char chars[5] = { 0 }; memcpy(chars, &n, 4 * sizeof(char)); infoR.program = ReverseString(chars); n = reader->ReadInt32(32); memcpy(chars, &n, 4 * sizeof(char)); infoR.platform = ReverseString(chars); n = reader->ReadInt32(32); memcpy(chars, &n, 4 * sizeof(char)); infoR.locale = ReverseString(chars); infoR.componentCount = reader->ReadInt32(6); infoR.components.resize(infoR.componentCount); for (int32 i = 0; i < infoR.componentCount; ++i) { InfRequestComponents comp; n = reader->ReadInt32(32); memcpy(chars, &n, 4 * sizeof(char)); comp.program = ReverseString(chars); n = reader->ReadInt32(32); memcpy(chars, &n, 4 * sizeof(char)); comp.platform = ReverseString(chars); comp.Build = reader->ReadInt32(32); infoR.components.at(i) = comp; } infoR.hasAccountName = reader->ReadInt32(1); if (!infoR.hasAccountName) { delete reader; printf("WARNING: Account tried to connect with no account name.\n"); SendError(AUTH_BAD_CREDENTIALS); Disconnect(); return; } infoR.accountName = reader->ReadAsciiString(9, 3); delete reader; if (infoR.accountName.length() == 0) { SendError(AUTH_BAD_CREDENTIALS); Disconnect(); return; } if (infoR.program != "WoW") { printf("Someone tried to connect who is not using WoW! They use: %s.\n", infoR.program); SendError(AUTH_INVALID_PROGRAM); Disconnect(); return; } // Check for a possible IP ban on this client. BAN_STATUS ipb = IPBanner::getSingleton().CalculateBanStatus(GetRemoteAddress()); if( ipb != BAN_STATUS_NOT_BANNED ) { printf("Battle.net detected ban person logging in. Refusing.", GetRemoteIP().c_str()); SendError(LOGIN_BANNED); Disconnect(); return; } // Make account name uppercase transform(infoR.accountName.begin(), infoR.accountName.end(),infoR.accountName.begin(), ::toupper); m_account = AccountMgr::getSingleton().GetAccount(infoR.accountName); if(m_account == 0) { SendError(AUTH_BAD_CREDENTIALS); printf("[Battlenet] Invalid account name: %s.", infoR.accountName.c_str()); Disconnect(); return; } if(m_account->Banned != 0) { SendError(LOGIN_BANNED); Disconnect(); return; } //////////////////////////////////////////////////////////////////////////////////// // We need to check the build which is sent in the components // Build is loaded from component-locale-wow.txt which is located in the highest priority MPQ // Changing the build causes WoW to crash when logging in with Battle.net 2 protocol // So instead we will hackfix by parsing build in with username, yay! //////////////////////////////////////////////////////////////////////////////// // TO DO ////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // Now for proof response // Header writer = new BitWriter_BN(206+321+1024); // (( (4*8) + (4*8) + 32 ) * 2) + 3 + 11 = 206 writer->WriteHeader(2, 0); // HasError is only written when there is an error int32 moduleCount = 2; writer->WriteBits(moduleCount, 3); // Passwords.dll writer->WriteFourCC("auth"); int16 _Zero = 1; writer->WriteBits(_Zero, 16); string EU = "EU"; string US = "US"; if (infoR.locale == "enUS") writer->WriteBits(*(int32*)US.c_str(), 16); else writer->WriteBits(*(int32*)EU.c_str(), 16); const char * moduleID = "8f52906a2c85b416a595702251570f96d3522f39237603115f2f1ab24962043c"; writer->WriteBits(moduleID, 32); // Size of module data this must be int32 blobSize = 0; writer->WriteBits(blobSize, 10); // Module Data, starts with 0 BN_Crypto * crypto = new BN_Crypto(m_account->BNPassword); unsigned char * userSalt = crypto->userSalt; unsigned char * passSalt = crypto->passSalt; unsigned char * publicB = crypto->publicB; unsigned char * Something = crypto->Something; // usersalt (offset 1, size 0x20) // passsalt (offset 21, size 0x20) // publicB (offset 41, size 0x80) // Eh, hex to binary of something, maybe password.dll data (offset 0xc1, size 0x80) // 1 + 0x20 + 0x20 + 0x80 + 0x80 = 321 unsigned char * moduleData = new unsigned char[321]; moduleData[0] = '\0'; memcpy(moduleData + 1, userSalt, 0x20); memcpy(moduleData + 0x21, passSalt, 0x20); memcpy(moduleData + 0x41, publicB, 0x80); memcpy(moduleData + 0xc1, Something, 0x80); writer->WriteBytes(moduleData, 321); // Thumbnails.dll writer->WriteFourCC("auth"); writer->WriteFourCC(infoR.locale); const char * moduleID2 = "36b27cd911b33c61730a8b82c8b2495fd16e8024fc3b2dde08861c77a852941c"; writer->WriteBits(moduleID2, 32); // What to write unsigned char * moduleData2 = new unsigned char[1024]; vector<unsigned char> bin; string hex = "\023DE12E08B3CEF5C2BB5DF2BC82D9F0D2F55ECD47C7616B3122ED1ED0C1C75B0CEDADC9DAB44815AD7C1D551A8437954D2FFAB5E5F34379298F08BF98A907821348CAF24D4F18B6EBEE951CB3B08154792D74E41A04657E038777648425AA26053C3F5C6882B7A794C042CECD529C8B7D0C41921EB9A75C9D75FCB468F95B12B4E62FF6C60EC9704BAFFEF33578DFE0745624FADA2FCEE67D4DEEEAF451875601FFB90B3EEC5484CE76888C540A0AC480F6CB5BC6D77F971A52937D6AD482186E5692F14E7212EBC744FD57D55AF6C294F4E184A32855110D08E418DD2D491CF480230CA1CE3BCE8ADE148B66D986F1B37DF7977D7E747F3172DA60F2189013EE653BE163A501E81C84CBFE138EAFDEEEBD9365C7756670256A2CD804ADE31E44480A59AD98B182A41AD45FE7BC858912D466B07FFB61B707325E2853B79ABC21CD9897706689B943AE3BF2704EFB987F5A437F2C79F6F16C838A05DB56CF00EAC4BBDC438D7171148E69AFF67A72E87BF44938A7408EF3562656201874C4BB09533ABE919A67B66B0432607FD8300C9836A1377CF00C93DD63287C637594E5AAEF24F788DBC9A87C3C1C85744336A8511F4BD2F73F801E6A4A0FAD34C95FF84192D7FFE4CDD1319CAB1533C903A1DF8CA33775FECF48B0DC8C1223A8324C6EF06AF490745FCCA476AD0D8DA5EEABE778C80EDF21B15B6C092277ABDB1C33E71"; writer->HexadecimalToBinary(hex, bin); // Size of module data int32 blobSize2 = ((hex.length() - 1) * 4) + 1; // 4 bits to a hexadecimal digit + \0 writer->WriteBits(blobSize2, 10); // Write module data moduleData2 = reinterpret_cast<unsigned char*>(bin.data()); writer->WriteBytes(moduleData2, 1024); // We will need to disable RSA check (which is what this module is) in the client // Send Send(writer->Buffer(), 206+321+1024); delete writer; }
void ReverseWordsInString( char *str ) { ReverseWords( str ); ReverseString( str, str + strlen(str) - 1 ); }
nsresult ArabicShaping(const PRUnichar* aString, PRUint32 aLen, PRUnichar* aBuf, PRUint32 *aBufLen, PRBool aInputLogical, PRBool aOutputLogical) { nsAutoString tempString(aString, aLen); if (tempString.Length() != aLen) return NS_ERROR_OUT_OF_MEMORY; PRUnichar *tempBuf = tempString.BeginWriting(); if (aInputLogical) { ReverseString(tempBuf, aLen); } const PRUnichar* src = tempBuf; const PRUnichar* p; PRUnichar* dest = aBuf; PRUnichar formB; PRInt8 leftJ, thisJ, rightJ; PRInt8 leftNoTrJ, rightNoTrJ; thisJ = leftNoTrJ = eNJ; rightJ = GetJoiningClass(*(src)); while(src<tempBuf+aLen-1) { leftJ = thisJ; if ((eTr != leftJ) || ((leftJ == eTr) && ( ( (src-1) >= tempBuf) && !IS_ARABIC_CHAR(*(src-1))))) leftNoTrJ = thisJ; if(src-2 >= (tempBuf)){ for(p=src-2; (p >= (tempBuf))&& (eTr == leftNoTrJ) && (IS_ARABIC_CHAR(*(p+1))) ; p--) leftNoTrJ = GetJoiningClass(*(p)) ; } thisJ = rightJ; rightJ = rightNoTrJ = GetJoiningClass(*(src+1)) ; if(src+2 <= (tempBuf+aLen-1)){ for(p=src+2; (p <= (tempBuf+aLen-1))&&(eTr == rightNoTrJ) && (IS_ARABIC_CHAR(*(src+1))); p++) rightNoTrJ = GetJoiningClass(*(p)) ; } formB = PresentationFormB(*src, DecideForm(leftNoTrJ, thisJ, rightNoTrJ)); *dest++ = formB; src++; } if((eTr != thisJ) || ((thisJ == eTr) && (((src-1)>=tempBuf) && (!IS_ARABIC_CHAR(*(src-1)))))) leftNoTrJ = thisJ; if(src-2 >= (tempBuf)){ for(p=src-2; (src-2 >= (tempBuf)) && (eTr == leftNoTrJ) && (IS_ARABIC_CHAR(*(p+1))); p--) leftNoTrJ = GetJoiningClass(*(p)) ; } formB = PresentationFormB(*src, DecideForm(leftNoTrJ, rightJ, eNJ)); *dest++ = formB; src++; PRUnichar *lSrc = aBuf; PRUnichar *lDest = aBuf; while(lSrc < (dest-1)) { PRUnichar next = *(lSrc+1); if(((0xFEDF == next) || (0xFEE0 == next)) && (0xFE80 == (0xFFF1 & *lSrc))) { PRBool done = PR_FALSE; PRUint16 key = ((*lSrc) << 8) | ( 0x00FF & next); PRUint16 i; for(i=0;i<8;i++) { if(key == gArabicLigatureMap[i]) { done = PR_TRUE; // lam and alef in the source are mapped to a lam-alef ligature in the // destination, so lSrc is incremented by 2 here *lDest++ = 0xFEF5 + i; lSrc+=2; break; } } if(! done) *lDest++ = *lSrc++; } else if (0x200C == *lSrc || 0x200D == *lSrc) // Strip zero-width joining controls ZWJ and ZWNJ from the shaped text lSrc++; else *lDest++ = *lSrc++; } if(lSrc < dest) *lDest++ = *lSrc++; *aBufLen = lDest - aBuf; NS_ASSERTION(*aBufLen <= aLen, "ArabicShaping() likely did a buffer overflow!"); if (aOutputLogical) { ReverseString(aBuf, *aBufLen); } return NS_OK; }
void LeftRotateString(char s[], int n, int m) { ReverseString(s, 0, m-1); ReverseString(s, m, n-1); ReverseString(s, 0, n-1); }