TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: pkohut on March 10, 2010, 06:18:55 AM

Title: Reissue Challenge: Get all system variables with values
Post by: pkohut 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.

Title: Re: Reissue Challenge: Get all system variables with values
Post by: MP 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:
Title: Re: Reissue Challenge: Get all system variables with values
Post by: It's Alive! on March 10, 2010, 07:11:47 AM
here is from acad 2006
Title: Re: Reissue Challenge: Get all system variables with values
Post by: MP 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.
Title: Re: Reissue Challenge: Get all system variables with values
Post by: pkohut on March 10, 2010, 07:19:16 AM
here is from acad 2006

How long did it take to generate?
Title: Re: Reissue Challenge: Get all system variables with values
Post by: It's Alive! on March 10, 2010, 07:20:22 AM
about a second

here is acad 07
Title: Re: Reissue Challenge: Get all system variables with values
Post by: It's Alive! 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();
  }
Title: Re: Reissue Challenge: Get all system variables with values
Post by: pkohut 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.
Title: Re: Reissue Challenge: Get all system variables with values
Post by: pkohut 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.
Title: Re: Reissue Challenge: Get all system variables with values
Post by: It's Alive! 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();
  }

Title: Re: Reissue Challenge: Get all system variables with values
Post by: pkohut 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);

Title: Re: Reissue Challenge: Get all system variables with values
Post by: It's Alive! 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
Title: Re: Reissue Challenge: Get all system variables with values
Post by: It's Alive! on March 10, 2010, 08:23:02 AM
here is 2010s list
Title: Re: Reissue Challenge: Get all system variables with values
Post by: It's Alive! on March 10, 2010, 08:26:46 AM
Anyway, pretty cool find Paul
Title: Re: Reissue Challenge: Get all system variables with values
Post by: pkohut 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();
    }

} ;
Title: Re: Reissue Challenge: Get all system variables with values
Post by: It's Alive! on March 10, 2010, 08:36:44 AM
nice!
don't forget this

Code: [Select]
if(buf.restype == RTSTR)
  free(buf.resval.rstring);

Title: Re: Reissue Challenge: Get all system variables with values
Post by: T.Willey on March 10, 2010, 11:17:47 AM
Thanks for finding a way to do this Paul!  It really bothered me that I couldn't find a way to make it work.
Title: Re: Reissue Challenge: Get all system variables with values
Post by: pkohut on March 10, 2010, 01:42:11 PM
Thanks for finding a way to do this Paul!  It really bothered me that I couldn't find a way to make it work.

You guys were on the right path, just need to narrow the workload a bit.  8-)
Title: Re: Reissue Challenge: Get all system variables with values
Post by: T.Willey on March 10, 2010, 02:25:40 PM
'09 Electrical versions

With Lisp.
Ascii : 3.953 seconds
Unicode : 0.328 seconds
Title: Re: Reissue Challenge: Get all system variables with values
Post by: Lee Mac on March 10, 2010, 02:29:52 PM
Tim,

I'm a bit lost in with all the 'higher knowledge' of this thread, but just curious, how can this:

Code: [Select]
strings -u -n1 acad.exe > StringsU.txt
strings -a -n1 acad.exe > StringsA.txt

be applied with LISP? [ Assuming you went down that route ]
Title: Re: Reissue Challenge: Get all system variables with values
Post by: JohnK on March 10, 2010, 02:44:19 PM
What are the results you guys are getting after a parse of these strings?  ...the reason i ask is because i could have sworn that ive done this; let me look.
***
I had a list of `known' vars and i compared that to my `string' list i read from the mep 05 acad.exe whereupon i came up with the DATA file in this post: http://www.theswamp.org/index.php?topic=14632.0
With a var on its own line, i had about 700.

When i get some time i want to try and find some of the code i used to generate (compare files and such) that dat file and study this post more because im still a bit confused.

EDIT: Just saw Tim's post....
Title: Re: Reissue Challenge: Get all system variables with values
Post by: T.Willey on March 10, 2010, 03:17:44 PM
Tim,

I'm a bit lost in with all the 'higher knowledge' of this thread, but just curious, how can this:

Code: [Select]
strings -u -n1 acad.exe > StringsU.txt
strings -a -n1 acad.exe > StringsA.txt

be applied with LISP? [ Assuming you went down that route ]

I didn't Lee.  I use Lisp to evaluate what was returned by that.  I didn't want to take the time to figure out how to call the command through lisp, I just processed what it returned.
Title: Re: Reissue Challenge: Get all system variables with values
Post by: Lee Mac on March 10, 2010, 05:09:44 PM
Tim,

I'm a bit lost in with all the 'higher knowledge' of this thread, but just curious, how can this:

Code: [Select]
strings -u -n1 acad.exe > StringsU.txt
strings -a -n1 acad.exe > StringsA.txt

be applied with LISP? [ Assuming you went down that route ]

I didn't Lee.  I use Lisp to evaluate what was returned by that.  I didn't want to take the time to figure out how to call the command through lisp, I just processed what it returned.

Ah, I see thanks buddy  :-)
Title: Re: Reissue Challenge: Get all system variables with values
Post by: It's Alive! on March 11, 2010, 12:04:28 AM
So did anyone catch any strange undocumented sysvars?  :-)
Title: Re: Reissue Challenge: Get all system variables with values
Post by: Kerry on March 11, 2010, 12:52:31 AM
So did anyone catch any strange undocumented sysvars?  :-)

 :|
Does anyone have a list of the documented ones ?  :lol:
Title: Re: Reissue Challenge: Get all system variables with values
Post by: It's Alive! on March 11, 2010, 01:05:42 AM
So did anyone catch any strange undocumented sysvars?  :-)

 :|
Does anyone have a list of the documented ones ?  :lol:

good point  :-o
Title: Re: Reissue Challenge: Get all system variables with values
Post by: CAB on March 11, 2010, 09:33:33 AM
Uh, yes. 8-)
http://www.hyperpics.com/system_variables/index.asp
Title: Re: Reissue Challenge: Get all system variables with values
Post by: JohnK on March 11, 2010, 10:06:34 AM
I believe Kerry was just making a facetious remark.
Title: Re: Reissue Challenge: Get all system variables with values
Post by: Lee Mac on March 11, 2010, 10:10:00 AM
I believe Kerry was just making a facetious remark.

No flies on you John  :wink:
Title: Re: Reissue Challenge: Get all system variables with values
Post by: JohnK on March 11, 2010, 10:17:42 AM
/me confused.
I'm taking advantage of a situation?


I'm not trying to be difficult here i truly dont understand.



EDIT:
*shock!* we can use the " / me " tag?!?!?!
Title: Re: Reissue Challenge: Get all system variables with values
Post by: Kerry on March 11, 2010, 09:27:10 PM
< .. >

EDIT:
*shock!* we can use the " / me " tag?!?!?!


That should be great for the next time you change your name John.

//--

What are you confused about today Sir ??
Title: Re: Reissue Challenge: Get all system variables with values
Post by: JohnK on March 11, 2010, 09:40:46 PM
ha-ha-ha You find that me changing my name every two weeks is anoying too? I was thinkng of starting a spread sheet.

slash-me is an Old 'IRC' thing (I'm easily amused).

I was confused at what Lee Mac said; and how I had no flies on me. I thought that ment that i was taking advantage of a situation...But i could Be wrong as usual.
Title: Re: Reissue Challenge: Get all system variables with values
Post by: alanjt on March 11, 2010, 09:58:15 PM
I was confused at what Lee Mac said; and how I had no flies on me. I thought that ment that i was taking advantage of a situation...But i could Be wrong as usual.
Nah, I think he was just commenting on how much he enjoys your cleanliness.
Title: Re: Reissue Challenge: Get all system variables with values
Post by: JohnK on March 11, 2010, 10:07:12 PM
*lol* ...I do tend to bath quite regularly.
Title: Re: Reissue Challenge: Get all system variables with values
Post by: pkohut on March 11, 2010, 10:15:47 PM
*lol* ...I do tend to bath quite regularly.

We appreciate that.  Any less regularly could be a problem though.  ;-)
Title: Re: Reissue Challenge: Get all system variables with values
Post by: alanjt on March 11, 2010, 10:18:09 PM
*lol* ...I do tend to bath quite regularly.

We appreciate that.  Any less regularly could be a problem though.  ;-)
Big Brother monitoring bathing habits now?
Title: Re: Reissue Challenge: Get all system variables with values
Post by: Kerry on March 12, 2010, 12:04:57 AM
<  .. >
I was confused at what Lee Mac said; and how I had no flies on me. I thought that ment that i was taking advantage of a situation...But i could Be wrong as usual.

Here in Aus' that means you move too fast for the flies to settle .. (fast being both physical and/or mental of course )
Title: Re: Reissue Challenge: Get all system variables with values
Post by: Kerry on March 12, 2010, 12:17:24 AM

So, we can now return to our normal broadcast ...
Title: Re: Reissue Challenge: Get all system variables with values
Post by: CAB on March 12, 2010, 08:48:41 AM
You just couldn't resist stirring the pot could you. 8-)
Title: Re: Reissue Challenge: Get all system variables with values
Post by: JohnK on March 12, 2010, 01:46:03 PM
Well i found some of my code that i used to generate that dat file but there are two problems with it:
1. the code is very specific and not very good (looks like i wrote most of it in a hurry).
2. All i have is about a couple of hundred lines of `parsing' code left. i must have typed over my code instead of making a new procedures as i parsed the files.

I can post some of the more useful items i have left, like this list i got from SMadsen a long time ago.
Code: [Select]
(setq get-sys-vars-list
 '(
         ;;;System related
         (getenv "Path")                    ;string System search paths
         (getenv "COMSPEC")                 ;string Cmd.exe path
         (getenv "UserName")                ;string User logon name
         (getenv "Temp")                    ;string Temp path
         (getenv "TMP")                     ;string Temp path
         (getenv "ComputerName")            ;string Computer name
         (getenv "Windir")                  ;string Windows path
         (getenv "OS")                      ;string Operating system
         (getenv "UserProfile")             ;string Current user profile path
         (getenv "Pathext")                 ;string Exec extensions
         (getenv "SystemDrive")             ;string System drive
         (getenv "SystemRoot")              ;string System root path
         (getenv "MaxArray")                ;integer

         ;;;General
         (getenv "ACAD")                    ;string Support search paths
         (getenv "ANSIHatch")               ;string Pattern file for ANSI setup 1
         (getenv "ANSILinetype")            ;string Linetype file for ANSI setup 1
         (getenv "ISOHatch")                ;string Pattern file for ISO setup 1
         (getenv "ISOLinetype")             ;string Linetype file for ISO setup 1
         (getenv "StartUpType")             ;string Current default for StartUp dialog
         (getenv "Measureinit")             ;string MEASUREINIT
         (getenv "InsertUnitsDefSource")    ;integer INSUNITSDEFSOURCE
         (getenv "InsertUnitsDefTarget")    ;integer INSUNITSDEFTARGET
         (getenv "LastTemplate")            ;string Last DWT used
         (getenv "Pickstyle")               ;integer
         (getenv "Coords")                  ;integer
         (getenv "ShowProxyDialog")         ;integer
         (getenv "Osmode")                  ;integer
         (getenv "EdgeMode")                ;integer
         (getenv "PAPERUPDATE")             ;integer
         (getenv "ACADPLCMD")               ;string Plotter command string
         (getenv "ImageHighlight")          ;integer
         (getenv "Attdia")                  ;integer
         (getenv "Attreq")                  ;integer
         (getenv "Delobj")                  ;integer
         (getenv "Dragmode")                ;integer
         (getenv "UseMRUConfig")            ;integer
         (getenv "PLSPOOLALERT")            ;integer
         (getenv "PLOTLEGACY")              ;integer
         (getenv "PSTYLEPOLICY")            ;integer
         (getenv "OLEQUALITY")              ;integer
         (getenv "Anyport")                 ;integer
         (getenv "Validation Policy")       ;integer
         (getenv "Validation Strategy")     ;integer
         (getenv "CommandDialogs")          ;integer CMDDIA
         (getenv "TempDirectory")           ;string Temp dir
         (getenv "PlotSpoolerDirectory")    ;string Spooler dir
         (getenv "DefaultLoginName")        ;string Default login
         (getenv "MenuFile")                ;string Default menu path
         (getenv "NetLocation")             ;string Default URL
         (getenv "ACADDRV")                 ;string Driver path
         (getenv "ACADHELP")                ;string Help path
         (getenv "PrinterConfigDir")        ;string Plotter path
         (getenv "PrinterStyleSheetDir")    ;string Plot styles path
         (getenv "PrinterDescDir")          ;string Plotter driver path
         (getenv "NewStyleSheet")           ;string Default .stb/.ctb file
         (getenv "DefaultFormatForSave")    ;integer Default saveas
         (getenv "DefaultConfig")           ;string Default pc3
         (getenv "LastModifiedConfig")      ;string Last pc3
         (getenv "MRUConfig")               ;string pc3?
         (getenv "ACADLOGFILE")             ;string Logfile
         (getenv "MaxDwg")                  ;integer
         (getenv "AVEMAPS")                 ;string Texture files path
         (getenv "TemplatePath")            ;string Templates path
         (getenv "DatabaseWorkSpacePath")   ;string Data Links path
         (getenv "DefaultPlotStyle")        ;string e.g. "ByLayer"
         (getenv "DefaultLayerZeroPlotStyle") ;string e.g."Normal"
         (getenv "LineWeightUnits")         ;integer
         (getenv "LWDEFAULT")               ;integer Default lineweight
         (getenv "CustomColors")            ;integer
         (getenv "Blipmode")                ;integer
         (getenv "ToolTips")                ;string
         (getenv "acet-Enable")             ;string
         (getenv "acet-MenuLoad")           ;string Loading of Express Tools menu
         (getenv "AcetRText:type")          ;string Current default for RTEXT, e.g. "Diesel"
         ;;added 02.10.01
         (getenv "CmdVisLines")             ;string Number of lines in command line window
         (getenv "MaxHatch")                ;string Maximum number of segments allowed in hatch pattern. Range 100 - 10000000
         ;;added 10.10.01 that's not a binary address but a date
         (getenv "AutoSnapColor")           ;string AutoSnap colour Integer
         (getenv "AutomaticSaveMinutes")    ;string Minutes between AutoSave

         ;; 1 used by MEASUREINIT and MEASUREMENT sysvars

         ;;;Editor Configuration
         (getenv "SDF_AttributeExtractTemplateFile") ;string ??
         (getenv "AutoSnapPolarAng")        ;string POLARANG
         (getenv "AutoSnapPolarDistance")   ;string POLARDIST
         (getenv "AutoSnapPolarAddAng")     ;string POLARADDANG
         (getenv "AutoSnapControl")         ;integer AUTOSNAP
         (getenv "AutoSnapTrackPath")       ;integer TRACKPATH
         (getenv "PickBox")                 ;integer PICKBOX
         (getenv "AutoSnapSize")            ;integer
         (getenv "PickFirst")               ;integer PICKFIRST
         (getenv "PickAuto")                ;integer PICKAUTO
         (getenv "MenuOptionFlags")         ;integer MENUCTL
         (getenv "FontMappingFile")         ;string
         (getenv "LogFilePath")             ;string
         (getenv "PSOUT_PrologFileName")    ;string
         (getenv "MainDictionary")          ;strin
         (getenv "CustomDictionary")        ;string
         (getenv "MTextEditor")             ;string
         (getenv "XrefLoadPath")            ;string
         (getenv "SaveFilePath")            ;string
         (getenv "AcadLspAsDoc")            ;string

         ;;;Drawing Window
         (getenv "Background")              ;integer Background color
         (getenv "Layout background")       ;integer PS Background color
         (getenv "XhairPickboxEtc")         ;integer Crosshair color
         (getenv "LayoutXhairPickboxEtc")   ;integer PS Crosshair color
         (getenv "Autotracking vector")     ;integer Autotracking vector color
         (getenv "MonoVectors")             ;integer
         (getenv "FontFace")                ;string Screen Menu
         (getenv "FontHeight")              ;integer
         (getenv "FontWeight")              ;integer
         (getenv "FontItalic")              ;integer
         (getenv "FontPitchAndFamily")      ;integer
         (getenv "CursorSize")              ;integer
         (getenv "HideWarningDialogs")      ;integer
         (getenv "SDIMode")                 ;integer

         ;;;Command Line Windows
         (getenv "CmdLine.ForeColor")       ;integer
         (getenv "CmdLine.BackColor")       ;integer
         (getenv "TextWindow.ForeColor")    ;integert
         (getenv "TextWindow.BackColor")    ;integer
         (getenv "CmdLine.FontFace")        ;string
         (getenv "CmdLine.FontHeight")      ;integer
         (getenv "CmdLine.FontWeight")      ;integer
         (getenv "CmdLine.FontItalic")      ;integer
         (getenv "CmdLine.FontPitchAndFamily") ;integer
         (getenv "TextWindow.FontFace")     ;string
         (getenv "TextWindow.FontHeight")   ;integer
         (getenv "TextWindow.FontWeight")   ;integer
         (getenv "TextWindow.FontItalic")   ;integer
         (getenv "TextWindow.FontPitchAndFamily") ;integer
    )
 )
;;;  Just the strings...
;;; (mapcar '(lambda (x) (cadr x)) get-sys-vars-list)

I was also thinking that the acad.exe isnt going to hold a lot of the better easter eggs we could find.
Title: Re: Reissue Challenge: Get all system variables with values
Post by: dgorsman on March 12, 2010, 02:23:58 PM
It sounds a little roundabout, but I suppose you could set up a reactor to monitor and log system variable changes, along with a "learn" on/off switch so it doesn't bog too much down.  It might not get *all* of the system variables but it should pick up the ones actually being used.
Title: Re: Reissue Challenge: Get all system variables with values
Post by: Lee Mac on March 12, 2010, 02:24:58 PM
You just couldn't resist stirring the pot could you. 8-)


 :evil: