| View previous topic :: View next topic |
| Author |
Message |
123qwe Newbie cheater
Reputation: 0
Joined: 26 Dec 2006 Posts: 21
|
Posted: Fri Jan 16, 2009 10:12 pm Post subject: c++ crash issue - SIMPLE |
|
|
hey, so i run the program, but it crashes instantly, im using visual c++ express, and it compiles with no errors, and im lost as to whats wrong with it. thanks!
It loads a password from a txt file into char *passwds. now
| Code: |
int nsize = 32;
char *passwds = "";
ifstream myfilea;
myfilea.open("password.txt");
myfilea.read(passwds,nsize);
myfilea.close();
Sleep(2000);
TypeStr(passwds);
Sleep(1000);
keybd_event(VK_RETURN, 0, 0, 0);
Sleep(200);
keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
Sleep(5000); |
the typestr funct
| Code: | void TypeStr(char *lpszString)
{
char cChar;
while((cChar=*lpszString++)) // loops through chars
{
short vk=VkKeyScan(cChar); // keycode of char
if((vk>>8)&1){keybd_event(VK_LSHIFT,0,0,0);} // hold shift if necessary
keybd_event((unsigned char)vk,0,0,0); // key in
keybd_event((unsigned char)vk,0,KEYEVENTF_KEYUP,0); // key out
if((vk>>8)&1){keybd_event(VK_LSHIFT,0,KEYEVENTF_KEYUP,0);} // release shift if necessary
}
} |
| Quote: |
thanks for everything! =] |
|
|
| Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Fri Jan 16, 2009 10:45 pm Post subject: |
|
|
| You have to allocate memory for passwds. Since you are reading a static size, might as well use an array of nsize + 1.
|
|
| Back to top |
|
 |
crayzbeef Expert Cheater
Reputation: 0
Joined: 21 Jan 2007 Posts: 101
|
Posted: Sat Jan 17, 2009 3:33 am Post subject: |
|
|
| Or actually make use of fucking STL and use a vector instead of an array.
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Sat Jan 17, 2009 4:14 am Post subject: |
|
|
| crayzbeef wrote: | | Or actually make use of fucking STL and use a vector instead of an array. |
I see no array.
|
|
| Back to top |
|
 |
&Vage Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Jul 2008 Posts: 1053
|
Posted: Sat Jan 17, 2009 11:07 am Post subject: |
|
|
| crayzbeef wrote: | | Or actually make use of fucking STL and use a vector instead of an array. |
You're fucking stupid.
The reason is you're initializing a char* without allocating memory to it. Do
| Code: |
char* passwds = new char[10]; //10 should be enough you could change this if you need more.
|
|
|
| Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Sat Jan 17, 2009 11:42 am Post subject: |
|
|
| _void_ wrote: | | crayzbeef wrote: | | Or actually make use of fucking STL and use a vector instead of an array. |
You're fucking stupid.
The reason is you're initializing a char* without allocating memory to it. Do
| Code: |
char* passwds = new char[10]; //10 should be enough you could change this if you need more.
|
|
First useful post i've seen from you.
Also, remember if you do this..to..
Also, why not just use strings? Easier in this case.
|
|
| Back to top |
|
 |
crayzbeef Expert Cheater
Reputation: 0
Joined: 21 Jan 2007 Posts: 101
|
Posted: Sat Jan 17, 2009 11:49 am Post subject: |
|
|
| noz3001 wrote: | | crayzbeef wrote: | | Or actually make use of fucking STL and use a vector instead of an array. |
I see no array. |
The first post suggests using an array. Are you blind?
|
|
| Back to top |
|
 |
Anden100 Grandmaster Cheater
Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Sat Jan 17, 2009 12:15 pm Post subject: |
|
|
| crayzbeef wrote: | | noz3001 wrote: | | crayzbeef wrote: | | Or actually make use of fucking STL and use a vector instead of an array. |
I see no array. |
The first post suggests using an array. Are you blind? |
Wow... i dont remember seeing one post from you, without an aggressive tone...
|
|
| Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Sat Jan 17, 2009 12:54 pm Post subject: |
|
|
There isn't a need for a vector. You're not going to use its functions or change the size. Only reason to use it is if you don't want to allocate memory yourself. Using an array would be better since all you need is a buffer.
Here is an example of how I would of done it. Done in c++ (not sure if the original poster know any c)
| Code: |
#include <iostream>
#include <fstream>
void InitializeDynamicArray(char * addr, size_t length);
int main()
{
char * buff;
int buffLen;
std::ifstream iStream("password.txt", std::ios::in);
if (!iStream.fail())
{
iStream.seekg(0, std::ios::end);
buffLen = iStream.tellg();
iStream.seekg(0, std::ios::beg);
if (buffLen >= 1)
{
buff = new char[buffLen + 1];
InitializeDynamicArray(buff, buffLen + 1);
iStream.read(buff, buffLen);
iStream.close();
std::cout << buff << std::endl;
delete[] buff;
}
else
{
std::cout << "Nothing to read from file\n";
iStream.close();
}
}
else
std::cout << "File not found\n";
return 0;
}
void InitializeDynamicArray(char * addr, size_t length)
{
for (int i = 0; i < length; i++)
addr[i] = 0;
}
|
|
|
| Back to top |
|
 |
|