Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
copying a string
05-31-2010, 01:09 AM
Post: #1
copying a string
Hey all,

I'm trying to do something like this, copy different parts into a string.

const int social_items = 10;
string social[social_items] =
{
"site:myspace.com","site:linkedin.com","site:facebook.com","site:adultfriendfinder.com",
"site:friendfinder.com","site:bebo.com","site:meetspot.com","site:twitter.com","site:meetup.com", "site:groups.google.com"
};

for (int i=0; i<social_items; i++)
{
strncpy(search_string, google_base, max_data);
strncpy(search_string, social[i], max_data);
}


the problem with the code is here:

strncpy(search_string, google_base, max_data);
strncpy(search_string, social[i], max_data);

It works, but what ever the last strncpy is, is what it prints out. What I'm looking to do is basically appending the information to it like

http://google.com is the first and then this is added:
http://google.com site:foo and finally we have
http://google.com site:foo intext:bar

Any suggestions? (i also tried to use string, and it errors out the yin/yang.)

./x86
Find all posts by this user
Quote this message in a reply
05-31-2010, 01:21 AM
Post: #2
RE: copying a string
So , you're creating an array of 10 Strings.

And on the loop you're looping from 0-10
the function for strncpy is
Code:
char * strncpy ( char * destination, const char * source, size_t num );

And, since this is your whole code, I really can't help too much.

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
05-31-2010, 01:29 AM
Post: #3
RE: copying a string
Ok sorry about that, maybe i should include the whole portion, because i was trying to truncate it to the problem areas. Here ya go buddy...

#include <iostream>
#include <string.h>
#include <cstdlib>
using namespace std;

//DEMO STRING: http://www.google.com/#hl=en&source=hp&q...intext:foo

int main()
{
char url_search[1024] = "";
const char google_base [128] = "http://google.com/";
const int social_items = 10;
string social[social_items] =
{
"site:myspace.com","site:linkedin.com","site:facebook.com","site:adultfriendfinder.com",
"site:friendfinder.com","site:bebo.com","site:meetspot.com","site:twitter.com","site:meetup.com",
"site:groups.google.com"
};
char fullname[1024] = "";
char phone[1024] = "0";
char street_address[1024] = "";
char email_address[1024] = "";

//SET THE STRING WE NEEDS
char search_string[1024] = "";
char search_reloc[1024] = "";
//MAX COPY DATA
const int max_data = 1024;

//CLEAR THE TERMINAL
system("clear");
//PRINT BANNER INFORMATION
// banner();
//COLLECT USER INFORMATION
cout << "What is the Targets Full Name?: ";
cin.get (fullname, 1024);
//GET TARGET EMAIL ADDRESS
cout << "What is the Targets E-mail Address?: ";
cin >> email_address;

//COLLECT ADDRESS
cout << "What is the targets Residing Address?: ";
cin.ignore();
cin.get (street_address, 1024);

//COLLECT USER ADDRESS AND PHONE NUMBER
cout << "What is the Targets Phone Number? (###-###-####): ";
cin >> phone;


//PRINT THE INFORMATION TO CONFIRM TO THE USER.

cout << "The following details have been collected." << endl
<< "Targets Full Name: \t" << fullname << endl
<< "Targets E-mail:\t" << email_address << endl
<< "Targets Phone: \t" << phone << endl
<< "Targets Address:\t" << street_address << endl << endl;

//CAUCULATE THE INFORMATION BASED ON NAME
for (int i=0; i<social_items; i++)
{
strncpy(search_string, google_base, max_data);

cout << "Searching " << search_string << endl;
cout << "String2: " << search_reloc << endl;
}

//CALCULATE THE INFORMATION

return 0;

}
Find all posts by this user
Quote this message in a reply
05-31-2010, 01:51 AM
Post: #4
RE: copying a string
Thanks, I'll get back to you when I have enough time to go over this code Smile

"Character is determined more by the lack of certain experiences than by those one has had."
Friedrich Nietzsche
Visit this user's website Find all posts by this user
Quote this message in a reply
05-31-2010, 08:26 AM
Post: #5
RE: copying a string
Mind explaining what your trying to do?

What I see, is that your asking user for information, storing them in variables.
Then you want to search google with site:facebook, etc, for information or something?

are you trying to use Google as a search? Maybe use Googles API..
Code:
http://www.google.ca/#hl=en&source=hp&q=YOURSEARCHTEXTHERE&aq=f&aqi=&aql=&oq=&gs_rfai=&fp=290a43085aba2861

[Image: 30ifbbd.png]
Find all posts by this user
Quote this message in a reply
05-31-2010, 10:57 AM
Post: #6
RE: copying a string
(05-31-2010 08:26 AM)BlueMelon Wrote:  Mind explaining what your trying to do?

What I see, is that your asking user for information, storing them in variables.
Then you want to search google with site:facebook, etc, for information or something?

are you trying to use Google as a search? Maybe use Googles API..
Code:
http://www.google.ca/#hl=en&source=hp&q=YOURSEARCHTEXTHERE&aq=f&aqi=&aql=&oq=&gs_rfai=&fp=290a43085aba2861

Yes, I'm trying to get a tool going to help during penetration tests that can generate listings such as this. I have a working example i designed in VB6, but i need to port it out for linux and os x. I'm trying to append multiple lines to a single string, for example

search_string = http://google.com/
record = "site:this.com"
other = "intext:foo"

and have one record called say final_search and it will = "http://google.comsite:this.com intext:foo" but when i do a strncpy it erases the first portion (google.com) and replaces it with intext:foo. If I'm explaining this properly.

thanks,
./x86
Find all posts by this user
Quote this message in a reply
06-01-2010, 05:59 AM
Post: #7
RE: copying a string
then you can use
Code:
strcat()

[Image: 30ifbbd.png]
Find all posts by this user
Quote this message in a reply
06-01-2010, 02:01 PM
Post: #8
RE: copying a string
(06-01-2010 05:59 AM)BlueMelon Wrote:  then you can use
Code:
strcat()

ok cool, thanks bluemelon, i will look into it.

./x86
Find all posts by this user
Quote this message in a reply
06-03-2010, 03:59 AM
Post: #9
RE: copying a string
(06-01-2010 02:01 PM)amvx86 Wrote:  
(06-01-2010 05:59 AM)BlueMelon Wrote:  then you can use
Code:
strcat()

ok cool, thanks bluemelon, i will look into it.

./x86

Bluemelon,

I did the strncat, and it looks as if the information is stored in there thanks =) but now when i do this...

for (int i=0; i<social_sites; i++)
{

strncat(complete_search_string, google_base_url, max_length);
strncat(complete_search_string, social_items[i].c_str(), max_length);
cout << "Searching: " << complete_search_string << endl;
complete_search_string[1024] = NULL;
}

the string of complete_Search_string becomes this...

google.com/searchgoogle.com/search and with each one it adds each line over and over again. I tried to clear it as shown, but it's not working. Any suggestions or links i can take a look at? I've searched google, and it said it's either "" or NULL at the end to clear it, but I might be missing something. Thanks.

./x86.
Find all posts by this user
Quote this message in a reply
06-03-2010, 04:28 AM
Post: #10
RE: copying a string
Well, it adds every line over and over again because of the

Code:
for (int i=0; i<social_sites; i++)

[Image: 30ifbbd.png]
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


 Quick Theme: