Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 07:46

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C++] Problem

Discussion on [C++] Problem within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Dec 2011
Posts: 367
Received Thanks: 199
[C++] Problem

Hi community!

I have a problem..

if i use the cycle for to decrypt the nostale login package, the content of the string login_packet remains only in the cycle for ...

cycle for = for(;{..}


i have a question :

how i use this content outside the cycle for?

example:

Code:
std::string str;
for(...){
...
str = "hello"; // i have a string
}
// how i call string outside the cycle for?
std::cout << str; // error, the string = "";
Please, speak english!
Kingrap is offline  
Old 07/06/2012, 13:03   #2
 
Crack-wtf's Avatar
 
elite*gold: 256
Join Date: Feb 2012
Posts: 1,370
Received Thanks: 2,917
str << "hello";

Edit: Srsly. Did i wrote that? XD
Crack-wtf is offline  
Old 07/06/2012, 13:41   #3
 
elite*gold: 0
Join Date: Dec 2011
Posts: 367
Received Thanks: 199
str << "hello"; ?!?

i have a error..

error C2784: 'std :: basic_ostream <_Elem,_Traits> & std :: operator << (std :: basic_ostream <_Elem,_Traits> &, const char *)': can not deduce a template argument for 'std :: basic_ostream <_Elem, _Traits> & 'from' std :: string '
Kingrap is offline  
Old 07/06/2012, 13:44   #4
 
.SkyneT.'s Avatar
 
elite*gold: 273
Join Date: Sep 2010
Posts: 1,831
Received Thanks: 786
Quote:
Originally Posted by Crack-wtf View Post
str << "hello";
wtf


Code:
#include <iostream>
#include <string>

int main()
{
    std::string str;
    
    for (int i = 0; i <= 10; i++)
    {
         str = "string";
    }

    std::cout << str << std::endl;
    
    return 0;
}
This works, so the problem has to be in the ... - stuff.
.SkyneT. is offline  
Old 07/06/2012, 13:55   #5
 
elite*gold: 0
Join Date: Dec 2011
Posts: 367
Received Thanks: 199
i have:

Code:
std::string login_packet;
for(int i=0;i<225;i++){
login_packet = recvbuf[i] - 15 ^ 195;
login_packet = Replace(login_packet,"~","");
}
std::cout << login_packet;
but login_packet = "";

while..

Code:
std::string login_packet;
for(int i=0;i<225;i++){
login_packet = recvbuf[i] - 15 ^ 195;
login_packet = Replace(login_packet,"~","");
std::cout << login_packet;
}
login_packet = "NoS0575 ...";
Kingrap is offline  
Old 07/06/2012, 14:47   #6
 
elite*gold: 9
Join Date: Dec 2009
Posts: 1,071
Received Thanks: 819
I guess it's because
Code:
std::string login_packet;
for(int i=0;i<225;i++){
login_packet = recvbuf[i] - 15 ^ 195;
login_packet = Replace(login_packet,"~","");
std::cout << login_packet;
}
prints every character seperately

while
Code:
std::string login_packet;
for(int i=0;i<225;i++){
login_packet = recvbuf[i] - 15 ^ 195;
login_packet = Replace(login_packet,"~","");
}
std::cout << login_packet;
just gives you the last character in your string
.Infinite is offline  
Old 07/06/2012, 15:51   #7
 
elite*gold: 5
Join Date: Sep 2006
Posts: 385
Received Thanks: 218
Quote:
Originally Posted by Kingrap View Post
i have:

Code:
std::string login_packet;
for(int i=0;i<225;i++){
login_packet = recvbuf[i] - 15 ^ 195;
login_packet = Replace(login_packet,"~","");
}
std::cout << login_packet;
but login_packet = "";
Well, you set the string to the current char in the buffer.

login_packet = recvbuf[0]; //packet = "N"
login_packet = recvbuf[1]; //packet = "o"
login_packet = recvbuf[2]; //packet = "S"
...
login_packet = recvbuf[254]; //packet = "" - recvbuf[i] is probably 0


Quote:
Originally Posted by Kingrap View Post
while..
Code:
std::string login_packet;
for(int i=0;i<225;i++){
login_packet = recvbuf[i] - 15 ^ 195;
login_packet = Replace(login_packet,"~","");
std::cout << login_packet;
}
login_packet = "NoS0575 ...";
See above. You set the string to the current char in the buffer and then you print it.

login_packet = recvbuf[0];
std::cout << login_packet; //N
login_packet = recvbuf[1];
std::cout << login_packet; //o
login_packet = recvbuf[2];
std::cout << login_packet; //S


You can fix this by pushing each char back to the packet.
login_packet.push_back(recvbuf[i] - 15 ^ 195);

Then you can print out the entire string at once.
Nightblizard is offline  
Old 07/06/2012, 16:23   #8
 
Lazeboy's Avatar
 
elite*gold: 0
Join Date: Jun 2008
Posts: 451
Received Thanks: 410
Code:
std::string login_packet;
for(int i=0;i<225;i++){
login_packet = recvbuf[i] - 15 ^ 195;
login_packet = Replace(login_packet,"~","");
}
std::cout << login_packet;
if you do it that way you overwrite the packetbuffer everytime . So only the last flow of crypted packed is in login_packet.


Code:
std::string login_packet;
for(int i=0;i<225;i++){
login_packet = recvbuf[i] - 15 ^ 195;
login_packet = Replace(login_packet,"~","");
std::cout << login_packet;
}

if you do it that way you overwrite the packetbuffer everytime, too. So only the last flow of crypted packed is in login_packet. But you print the result of every flow on screen and so you can see the crypted data in every flow. Thats what in some of the reapeats is a part of the good data.

You can get the complete string by add every character to string like this.

Code:
string login_packet;

for (int i = 0; i < strlen(recvbuf); i++) 
{
  	login_packet += (int)(recvbuf[i] - 0x0F ^ 0xC3);
}

std::cout << login_packet.c_str();
mfg Lazeboy
Lazeboy is offline  
Old 07/06/2012, 17:00   #9
 
xNopex's Avatar
 
elite*gold: 0
Join Date: May 2009
Posts: 827
Received Thanks: 471
Quote:
You can get the complete string by add every character to string like this.
Imho it is a better idea to work with a stringstream object:

Code:
std::stringstream string_buffer;
for (unsigned int i = 0; i < strlen(my_string); i++)
{
    string_buffer << (char)(my_string[i] - 0x0F ^ 0xC3);
}
xNopex is offline  
Old 07/06/2012, 17:26   #10
 
elite*gold: 0
Join Date: Dec 2011
Posts: 367
Received Thanks: 199
i solved,
thanks friends!
Kingrap is offline  
Reply


Similar Threads Similar Threads
[Problem]Habe ein Problem und zwar spinnt mein VPC etwas(ohne Grund)?!
07/28/2011 - Metin2 Private Server - 10 Replies
Also wie schon gesagt meins Server spinnt wodurch kiks usw. kommen :( ich lade euch die Screens in den Anhang, mit der Hoffnung, dass ihr mir helfen könnt :) wäre echt sehr nice :)



All times are GMT +2. The time now is 07:46.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.