Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Access Violation

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Fri Mar 13, 2009 8:16 pm    Post subject: Access Violation Reply with quote

I'm trying to compile some code to parse through some command line arguments and I keep getting an access violation. My code is:

Code:

   Commands = (char*)HeapAlloc(GetProcessHeap(), 0, sizeof(CHAR)*(strlen(lpCmdLine)+1));
   if(Commands != NULL) {
      strcpy(Commands, lpCmdLine);
   }
   char *c = new char[1]; //the new char[1] fixed a previous error
   int i = 0;
   int j = 0;
   do {
      c[1] = Commands[i]; //access violation on this line
      Open[j] = c[1];
      i++;
      j++;
   } while(strcmp(c, " ") != 0);
   do {
      c[1] = Commands[i];
      RecvUserName[j] = c[1];
      i++;
      j++;
   } while(strcmp(c, " ") != 0);
   i += 1;
   j = 0;
   do {
      c[1] = Commands[i];
      RecvFileName[j] = c[1];
      i++;
      j++;
   } while(strcmp(c, '\0') != 0);
   delete [] c;


The access violation is:

Quote:

'IBIM Transfer.exe': Loaded 'C:\Documents and Settings\OIB\My Documents\Visual Studio 2008\Projects\IBIM Transfer\Debug\IBIM Transfer.exe', Symbols loaded.
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\user32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\comdlg32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\secur32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shell32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ws2_32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ws2help.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shimeng.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\imm32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\wbsys.dll'
First-chance exception at 0x7c91b1fa in IBIM Transfer.exe: 0xC0000005: Access violation writing location 0x00000010.
'IBIM Transfer.exe': Unloaded 'C:\WINDOWS\system32\wbsys.dll'
'IBIM Transfer.exe': Unloaded 'C:\WINDOWS\system32\shimeng.dll'
First-chance exception at 0x00416cb2 in IBIM Transfer.exe: 0xC0000005: Access violation reading location 0x000000b2.
Unhandled exception at 0x00416cb2 in IBIM Transfer.exe: 0xC0000005: Access violation reading location 0x000000b2.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Fri Mar 13, 2009 9:09 pm    Post subject: Reply with quote

Code:
c[1]


Probably that.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Fri Mar 13, 2009 10:07 pm    Post subject: Reply with quote

Changed to c[0] and I'm still getting access violations.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Sat Mar 14, 2009 12:02 am    Post subject: Reply with quote

Post your full code + maybe think about using tokens.
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Sat Mar 14, 2009 3:07 am    Post subject: Reply with quote

Code:
char *c = new char[128];


Question
Back to top
View user's profile Send private message MSN Messenger
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat Mar 14, 2009 10:31 am    Post subject: Reply with quote

Sorry noz that didn't help.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Sat Mar 14, 2009 10:49 am    Post subject: Reply with quote

Code:
Commands = (char*)HeapAlloc(GetProcessHeap(), 0, strlen(lpCmdLine)+1);
if(Commands) {
   strcpy(Commands, lpCmdLine);
 
int i = 0;
int j = 0;

for( ; ! isspace( Commands[i] ); i++, j++ )
{
   Open[j] = Commands[i];
}


for( ; ! isspace( Commands[i] ); i++, j++ )
{
   RecvUserName[j] = Commands[i]; // I R DINK PROBLEMZ HERE
}

for( i += 1, j = 0; Commands[i] != '\0'; i++, j++ )
{
   RecvFileName[j] = Commands[i]; I R DINK PROBLEMZ HERE
}


}
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat Mar 14, 2009 11:29 am    Post subject: Reply with quote

Zand with your code I still get an access violation. Except its on the line:

Code:

for(;!isspace(Commands[i]); i++, j++ )


Access violation:

Quote:

'IBIM Transfer.exe': Loaded 'C:\Documents and Settings\OIB\My Documents\Visual Studio 2008\Projects\IBIM Transfer\Debug\IBIM Transfer.exe', Symbols loaded.
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\user32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\comdlg32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\secur32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shlwapi.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shell32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ws2_32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\ws2help.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\shimeng.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\imm32.dll'
'IBIM Transfer.exe': Loaded 'C:\WINDOWS\system32\wbsys.dll', Binary was not built with debug information.
First-chance exception at 0x7c91b1fa in IBIM Transfer.exe: 0xC0000005: Access violation writing location 0x00000010.
'IBIM Transfer.exe': Unloaded 'C:\WINDOWS\system32\wbsys.dll'
'IBIM Transfer.exe': Unloaded 'C:\WINDOWS\system32\shimeng.dll'
First-chance exception at 0x00416caa in IBIM Transfer.exe: 0xC0000005: Access violation reading location 0x000000b2.
Unhandled exception at 0x00416caa in IBIM Transfer.exe: 0xC0000005: Access violation reading location 0x000000b2.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat Mar 14, 2009 12:18 pm    Post subject: Reply with quote

For the love of god, tokenize the string first using strtok() or something.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat Mar 14, 2009 1:38 pm    Post subject: Reply with quote

Thanks Flyte. strtok worked.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites