[C++] Problem

07/06/2012 12:27 Kingrap#1
:rolleyes: 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!
07/06/2012 13:03 Crack-wtf#2
str << "hello";

Edit: Srsly. Did i wrote that? XD
07/06/2012 13:41 Kingrap#3
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 '
07/06/2012 13:44 .SkyneT.#4
Quote:
Originally Posted by Crack-wtf View Post
str << "hello";
wtf :confused:


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.
07/06/2012 13:55 Kingrap#5
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 ...";
07/06/2012 14:47 .Infinite#6
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
07/06/2012 15:51 Nightblizard#7
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.
07/06/2012 16:23 Lazeboy#8
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
07/06/2012 17:00 xNopex#9
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);
}
07/06/2012 17:26 Kingrap#10
i solved,
thanks friends! :D