Luigi Auriemma

aluigi.org (ARCHIVE-ONLY FORUM!)
It is currently 19 Jul 2012 13:46

All times are UTC [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Steam Login Recovery
PostPosted: 01 Sep 2008 08:03 

Joined: 01 Sep 2008 07:40
Posts: 31
Luigi, I have written a very small program to parse the "SteamAppData.vdf" file (plain text) and retrieve the user name set as the "AutoLoginUser". I wanted to know if you could look at my code and tell me of a better way to search through and parse such a file as I feel my code is very inefficient, however it does work for me.

GetSteamUser.c
Code:
#include <stdio.h>
#include <windows.h>

FILE *hVDF;
HKEY hkey;
LONG lRet;
DWORD dwSize=128;
char szSteamUser[128], lpBuffer[128], lpLine[1024];
char szAppData[MAX_PATH];

int main(int argc, char *argv[]) {

   SetConsoleTitle("GetSteamUser - by desxor 2008");

   lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Valve\\Steam", 0, KEY_READ, &hkey);
   if(RegQueryValueEx(hkey, "InstallPath", NULL, NULL, szAppData, &dwSize) != ERROR_SUCCESS)
   {
      printf("Could not find Steam installation path in registry, exiting.\n");
      exit(-1);
   }
   else {
      printf("Found InstallPath value in registry:\n%s\n\n", szAppData);
   }
   RegCloseKey(hkey);

   strcat(szAppData,"\\config\\SteamAppData.vdf");

   hVDF = fopen(szAppData,"r");
   if(!hVDF) {
      printf("Failed opening: %s\n", szAppData);
      exit(-1);
   }
   while(fgets(lpLine,sizeof(lpLine),hVDF) != NULL)
   {
      int i,f;
      for (i=0, f=1; lpLine[i] != '\0'; i++, f++)
      {
         char *end = strchr(&lpLine[i],'"');
         if (end != NULL)
         {
            int length = end - &lpLine[i];
            switch (f)
            {
               case 2:
               sprintf(lpBuffer,"%*.*s", length, length, &lpLine[i]);

               case 4:
               if(strcmp(lpBuffer,"AutoLoginUser") == 0) sprintf(szSteamUser,"%*.*s", length, length, &lpLine[i]);
            }
         i += length;
         }
      }
   }
   fclose(hVDF);

   printf("AutoLoginUser: %s\n", szSteamUser);

   return(0);
}


Thank you for looking and maybe this will help others ;)


Top
 Profile  
 
 
 Post subject: Re: Steam Login Recovery
PostPosted: 02 Sep 2008 11:04 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
parsing text files in C is ever a pain due to the need of handling all the various spaces, tabs, delimiters and so on.
anyway your method is good


Top
 Profile  
 
 Post subject: Re: Steam Login Recovery
PostPosted: 03 Sep 2008 03:36 

Joined: 01 Sep 2008 07:40
Posts: 31
aluigi wrote:
parsing text files in C is ever a pain due to the need of handling all the various spaces, tabs, delimiters and so on.
anyway your method is good

true, and thank you.


Top
 Profile  
 
 Post subject: Re: Steam Login Recovery
PostPosted: 12 Sep 2008 14:06 

Joined: 11 Sep 2008 18:22
Posts: 1
i made one in c++ using this method, alot simpler :p

Code:
//does not belong to me
vector<string> str_explode( const string &inString,
                  const string &separator )
{
   vector<string> returnVector;
   string::size_type start = 0;
   string::size_type end = 0;

   while ((end = inString.find (separator, start)) != string::npos)
   {
      returnVector.push_back (inString.substr (start, end-start));
      start = end + separator.size();
   }

   returnVector.push_back (inString.substr (start));

   return returnVector;
}

bool ObtainVDFUsername( string *uname )
{
   //we are already "Steam.exe"
   ifstream file( g_pSteamApp->GetDirectoryFile("config\\SteamAppData.vdf") );

   if( !file.is_open() )
      return false;

   string filedata;
   char buffer[ 32 ] = {0};

   while( file.good() )
   {
      file.getline( buffer, 32 );
      filedata.append( buffer );
   }

   file.close();

   //the file buffer resides in
   vector<string> vExplodedQuotes = str_explode(
      filedata, "\"" );

   for( int f = 0; f < (int)vExplodedQuotes.size(); f++ )
   {
      string currentString = vExplodedQuotes[f];

      if( !strcmp( currentString.c_str(), "AutoLoginUser" ) )
      {
         uname[0] = vExplodedQuotes[f+2];
         return true;
      }
   }
   return false;
}


seems to be pretty reliable, it just splits the text by "


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC [ DST ]


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 post attachments in this forum

Search for: