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 


Environment Variables and Win32 API Functions

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Sat Aug 21, 2010 2:29 pm    Post subject: Environment Variables and Win32 API Functions Reply with quote

I'm trying to use FindFirstFile and FindNextFile using %appdata%\\* as my argument. Why won't it work?

Code:
LPCTSTR lpFileName = _T("%appdata%\\Macromedia\\Flash Player\\#SharedObjects\\*");


Produces exit code 3.


Code:
LPCTSTR lpFileName = _T("%appdata%*");


Produces exit code 2.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Sat Aug 21, 2010 3:07 pm    Post subject: This post has 1 review(s) Reply with quote

Not sure if FindFirstFile/NextFile will let you use environment variables inside the strings, which may be causing your exit codes.

Error code 2 is: file not found.
Error code 3 is: path not found.

Instead, you could try using getenv to obtain the environment variable first then append the rest to that.

You can also use:
- GetEnvironmentStrings
- GetEnvironmentVariable

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Sat Aug 21, 2010 7:10 pm    Post subject: Reply with quote

Conversion disaster Sad I'm trying to append the rest of the path onto the LPCTSTR for FindFirstFile but I'm having trouble.

Suggestions?
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sat Aug 21, 2010 7:20 pm    Post subject: Reply with quote

ExpandEnvironmentStrings()
Back to top
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 891

PostPosted: Sun Aug 22, 2010 8:32 am    Post subject: Reply with quote

justa_dude <3 buffer overflow
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Aug 22, 2010 10:50 am    Post subject: Reply with quote

That function takes a size parameter..
Back to top
View user's profile Send private message
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Sun Aug 22, 2010 11:19 am    Post subject: Reply with quote

Slugsnack wrote:
That function takes a size parameter..


Don't worry about it. I did this and it worked.

Quote:
LPTSTRING lpFileName = _tgetenv(_T("AppData"));

. . .

_tcscat(lpFileName, _T("\\Path\\To\\Folder\\*));


Thank you Wiccaan and Slugsnack.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Sun Aug 22, 2010 4:42 pm    Post subject: Reply with quote

Be careful with things like that, you can lead into overflows and such.

MSDN wrote:
Returns a pointer to the environment table entry containing varname. It is not safe to modify the value of the environment variable using the returned pointer.


You can define paths with MAX_PATH and just append to the buffers. Such as:

Code:
TCHAR* lpEnvVar = _tgetenv( _T( "AppData" ) );
TCHAR tszFilePath[ MAX_PATH ] = { 0 };
_tcscpy_s( tszFilePath, MAX_PATH, lpEnvVar );
_tcscat_s( tszFilePath, MAX_PATH, _T( "\\Path\\To\\Folder\\*" ) );


Also with that, I'd suggest looking at the secured versions of the CRT library functions to prevent overflows and so on.

getenv_s:
http://msdn.microsoft.com/en-us/library/tb2sfw2z%28VS.80%29.aspx

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
nwongfeiying
Grandmaster Cheater
Reputation: 2

Joined: 25 Jun 2007
Posts: 695

PostPosted: Sun Aug 22, 2010 9:28 pm    Post subject: Reply with quote

Wiccaan wrote:
Be careful with things like that, you can lead into overflows and such.

MSDN wrote:
Returns a pointer to the environment table entry containing varname. It is not safe to modify the value of the environment variable using the returned pointer.


You can define paths with MAX_PATH and just append to the buffers. Such as:

Code:
TCHAR* lpEnvVar = _tgetenv( _T( "AppData" ) );
TCHAR tszFilePath[ MAX_PATH ] = { 0 };
_tcscpy_s( tszFilePath, MAX_PATH, lpEnvVar );
_tcscat_s( tszFilePath, MAX_PATH, _T( "\\Path\\To\\Folder\\*" ) );


Also with that, I'd suggest looking at the secured versions of the CRT library functions to prevent overflows and so on.

getenv_s:
http://msdn.microsoft.com/en-us/library/tb2sfw2z%28VS.80%29.aspx


Thanks Wiccaan. Areas that I always fall short on are these access violations because I'm doing something I'm not suppose to and overflows.
Back to top
View user's profile Send private message
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