Author Topic: Reissue Challenge: Get all system variables with values  (Read 13043 times)

0 Members and 1 Guest are viewing this topic.

pkohut

  • Guest
Reissue Challenge: Get all system variables with values
« on: March 10, 2010, 06:18:55 AM »
From a long long time ago -
I don't know how one would accomplish this, and thought it might be fun.  I will look into this a little more when I get back from lunch.

Since this challenge was never completed I thought it would be cool to reissue it. http://www.theswamp.org/index.php?topic=12882.msg157207#msg157207

As an alternative to the brute force method that was originally tried, how about mining strings from the executable? You can get a program to do just that from Microsoft Technet http://technet.microsoft.com/en-us/sysinternals/bb897439.aspx.  Generate a working dataset of strings from the Windows command line by issuing the following commands -
Code: [Select]
strings -u -n1 acad.exe > StringsU.txt
strings -a -n1 acad.exe > StringsA.txt
Then process the dataset using your favorite programming language to find the strings that can be used with GETVAR.

The dataset will be huge, so the challenge then becomes how to effectivly work with the generated data, reducing runtime.


MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Reissue Challenge: Get all system variables with values
« Reply #1 on: March 10, 2010, 06:40:34 AM »
Generate a working dataset of strings from the Windows command line by issuing the following commands -
Code: [Select]
strings -u [color=red]-n1[/color] acad.exe > StringsU.txt
strings -a [color=red]-n1[/color] acad.exe > StringsA.txt

Then process the dataset using your favorite programming language to find the strings that can be used with GETVAR.

tiny fix:

Code: [Select]
strings -u[color=red] -n 1[/color] acad.exe > StringsU.txt
strings -a [color=red]-n 1[/color] acad.exe > StringsA.txt

edit: having look at the spawned data, strings sorted and unique, the unicode file while smaller appears to have much more promise than the ascii file

could be wrong tho, i'm enjoying a sleepless night so i'm kinda crossed eyed  :doa:
« Last Edit: March 10, 2010, 06:54:36 AM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Reissue Challenge: Get all system variables with values
« Reply #2 on: March 10, 2010, 07:11:47 AM »
here is from acad 2006

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Reissue Challenge: Get all system variables with values
« Reply #3 on: March 10, 2010, 07:16:52 AM »
2008 attached.

Simple test: Open the files and search for "ltscale" or "viewmode" etc. It suggests _StringsU.txt will be the one that is the most revealing.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

pkohut

  • Guest
Re: Reissue Challenge: Get all system variables with values
« Reply #4 on: March 10, 2010, 07:19:16 AM »
here is from acad 2006

How long did it take to generate?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Reissue Challenge: Get all system variables with values
« Reply #5 on: March 10, 2010, 07:20:22 AM »
about a second

here is acad 07

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Reissue Challenge: Get all system variables with values
« Reply #6 on: March 10, 2010, 07:21:04 AM »
Code: [Select]
static void ArxGetVar_doit(void)
  {
    std::wstring temp;
    std::vector<std::wstring> strings;
    std::wifstream ifs( _T("c:\\StringsU.txt") );
    std::wofstream ofs( _T("c:\\StringsUOut.txt") );

    while( getline( ifs, temp ) )
      strings.push_back(temp);

    resbuf buf;
    for(size_t i=0;i<strings.size();i++)
    {
      if(acedGetVar(strings[i].c_str(),&buf) == RTNORM)
      {
        ofs << strings[i] << std::endl;
      }
    }
    ofs.close();
    ifs.close();
  }
« Last Edit: March 10, 2010, 07:25:47 AM by Daniel »

pkohut

  • Guest
Re: Reissue Challenge: Get all system variables with values
« Reply #7 on: March 10, 2010, 07:26:24 AM »
2008 attached.

Simple test: Open the files and search for "ltscale" or "viewmode" etc. It suggests _StringsU.txt will be the one that is the most revealing.

I think your right.  Also look if someone is to parse the list then the strings starting with the * character will need to strip the * before testing.  Just saw Daniels results.  Nice.

pkohut

  • Guest
Re: Reissue Challenge: Get all system variables with values
« Reply #8 on: March 10, 2010, 07:31:16 AM »
Code: [Select]
static void ArxGetVar_doit(void)
  {
    std::wstring temp;
    std::vector<std::wstring> strings;
    std::wifstream ifs( _T("c:\\StringsU.txt") );
    std::wofstream ofs( _T("c:\\StringsUOut.txt") );

How about using std::set instead?  That should reduce the dataset quite a bit.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Reissue Challenge: Get all system variables with values
« Reply #9 on: March 10, 2010, 07:45:48 AM »
Code: [Select]
static void ArxGetVar_doit(void)
  {
    std::wstring temp;
    std::vector<std::wstring> strings;
    std::wifstream ifs( _T("c:\\StringsU.txt") );
    std::wofstream ofs( _T("c:\\StringsUOut.txt") );
How about using std::set instead?  That should reduce the dataset quite a bit.

like this?
Code: [Select]
  typedef std::set<std::wstring> stringset;
  static void ArxGetVar_doit(void)
  {
    std::wstring temp;
    stringset strings;
    stringset::iterator iter;
    std::wifstream ifs( _T("c:\\StringsU.txt") );
    std::wofstream ofs( _T("c:\\StringsUOut.txt") );

    while( getline( ifs, temp ) )
      strings.insert(temp);

    resbuf buf;
    for(iter = strings.begin();iter!=strings.end();++iter)
    {
      if(iter->size() > 0 )
      {
        if(iter->at(0) != '*')
        {
          if(acedGetVar(iter->c_str(),&buf) == RTNORM)
          {
            ofs << *iter << std::endl;
            if(buf.restype == RTSTR)
              free(buf.resval.rstring);
          }
        }
      }
    }
    ofs.close();
    ifs.close();
  }

« Last Edit: March 10, 2010, 07:55:04 AM by Daniel »

pkohut

  • Guest
Re: Reissue Challenge: Get all system variables with values
« Reply #10 on: March 10, 2010, 07:56:49 AM »
Code: [Select]
static void ArxGetVar_doit(void)
  {
    std::wstring temp;
    [color=brown]std::vector<std::wstring> strings;[/color]
    std::wifstream ifs( _T("c:\\StringsU.txt") );
    std::wofstream ofs( _T("c:\\StringsUOut.txt") );
How about using std::set instead?  That should reduce the dataset quite a bit.

std::set<std::wstring> strings;

and this to get rid of duplicates (untested) -
   while( getline( ifs, temp ) )
      strings.insert(std::transform(temp.begin(), temp.end(), temp.begin(), std::toupper);


It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Reissue Challenge: Get all system variables with values
« Reply #11 on: March 10, 2010, 08:08:40 AM »
edit: updated with Paul's mods  :kewl:
Code: [Select]
 typedef std::set<std::wstring> stringset;
  static void ArxGetVar_doit(void)
  {
    std::wstring temp;
    stringset strings;
    std::wifstream ifs( _T("c:\\StringsU.txt") );
    std::wofstream ofs( _T("c:\\StringsUOut.txt") );

    while( getline( ifs, temp ) )
    {
      std::transform(temp.begin(), temp.end(), temp.begin(), std::toupper);
      if(temp[0] == '*')
        strings.insert(temp.substr(1));
      else
        strings.insert(temp);
    }

    resbuf buf;
    for(stringset::iterator iter = strings.begin();iter!=strings.end();++iter)
    {
      if(acedGetVar(iter->c_str(),&buf) == RTNORM)
      {
        ofs << *iter << std::endl;
        if(buf.restype == RTSTR)
          free(buf.resval.rstring);
      }
    }
    ofs.close();
    ifs.close();
  }

07 output
« Last Edit: March 10, 2010, 09:08:22 AM by Daniel »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Reissue Challenge: Get all system variables with values
« Reply #12 on: March 10, 2010, 08:23:02 AM »
here is 2010s list
« Last Edit: March 10, 2010, 09:07:07 AM by Daniel »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8661
  • AKA Daniel
Re: Reissue Challenge: Get all system variables with values
« Reply #13 on: March 10, 2010, 08:26:46 AM »
Anyway, pretty cool find Paul

pkohut

  • Guest
Re: Reissue Challenge: Get all system variables with values
« Reply #14 on: March 10, 2010, 08:32:42 AM »
Here's a couple tweeks to your code.  Gets rid of duplicates by promoting all strings to upper case, then adding them to a std::set.  Also, ignores the first character of a string if it is *

Code: [Select]
#include <set>
#include <fstream>
#include <string>
#include <cctype>


    static void ArxGetVar_doit(void)
    {
        std::wstring temp;
        std::set<std::wstring> strings;
        std::wifstream ifs( _T("c:\\StringsU.txt") );
        std::wofstream ofs( _T("c:\\StringsUOut.txt") );

        while( getline( ifs, temp ) ) {
            std::transform(temp.begin(), temp.end(), temp.begin(), std::toupper);
            if(temp[0] == L'*')
                strings.insert(temp.substr(1));
            else
                strings.insert(temp);
        }

        resbuf buf;
        for(std::set<std::wstring>::iterator it = strings.begin(); it != strings.end(); it++)
        {
            if(acedGetVar(it->c_str(),&buf) == RTNORM)
            {
                ofs << it->c_str() << std::endl;
            }
        }
        ofs.close();
        ifs.close();
    }

} ;