Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[Trick]Hide Ini file as part of the script file


  • Please log in to reply
9 replies to this topic
None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
This is an example of hiding the ini file inside the script file (works with compiled scripts also :D ) using properties of the NTFS file system (File Streams). This makes it so you don't have to create a seperate file to save settings for compiled scripts.
IniRead, OutputVar, %A_ScriptFullPath%:Stream:$DATA, Settings, Pass,error 
If (OutputVar="error")
 { 
 InputBox, OutputVar , New, Please select a password, HIDE 
 IniWrite, %OutputVar%, %A_ScriptFullPath%:Stream:$DATA, Settings, Pass 
 } 
Else 
 { 
 InputBox, Output , Returning, Please enter your password, HIDE 
 If (OutputVar<>Output) 
  ExitApp 
 } 
MsgBox Your Script Started
Note: The stream thing also works with FileAppend, FileRead, and FileDelete.

LazyMan
  • Members
  • 587 posts
  • Last active: Oct 21 2014 05:13 PM
  • Joined: 17 Feb 2011
Thanks for sharing this! :D

guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011
very interesting, ill have to do some tests with compiled scripts

so the data isnt even visible?

i expected the trick to be this one thats been shown before:

[untested code, real example is somewhere on forums]

/*  -- start INI section
[section]
key=value
*/  -- end INI section

IniRead, var, %A_ScriptFullPath%, section, key
msgbox, %var%

return


LazyMan
  • Members
  • 587 posts
  • Last active: Oct 21 2014 05:13 PM
  • Joined: 17 Feb 2011

so the data isnt even visible?

Cygwin's diff reported no difference between the file before and after the password was set. :shock:

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010
Sweet trick :) If someone makes a more extensive example (proof of concept), I would like to see that.

MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009
Very interesting.
Would sharing an EXE file after using this method work?

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio França -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


iwanttolearnahk
  • Members
  • 7 posts
  • Last active: Apr 07 2011 03:05 PM
  • Joined: 22 Mar 2011
this is really interesting. im not on my computer at the moment, would someone mind testing if this would read the data out of another .ahk or compiled .exe?

AnotherFilePath=insert file path here
IniRead, OutputVar, %AnotherFilePath%:Stream:$DATA, Settings, Pass,error
If (OutputVar="error")
 {
 InputBox, OutputVar , New, Please select a password, HIDE
 IniWrite, %OutputVar%, %AnotherFilePath%:Stream:$DATA, Settings, Pass
 }
Else
 {
 InputBox, Output , Returning, Please enter your password, HIDE
 If (OutputVar<>Output)
  ExitApp
 }
MsgBox Your Script Started
also, i would like to know how does the script stores the data.

flak
  • Members
  • 283 posts
  • Last active: Jan 01 2012 06:20 PM
  • Joined: 02 Oct 2009
It's just stored in alternate file stream.
<!-- m -->http://msdn.microsof...ibrary/aa364404<!-- m -->

guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011
heres an older thread that is related for reference, with a demonstration of hiding/embedding an exe into a stream:
<!-- m -->http://www.autohotke...pic.php?t=13411<!-- m -->

lifeweaver
  • Members
  • 868 posts
  • Last active: Jan 25 2016 01:29 AM
  • Joined: 04 Mar 2013

Just as an addition you can actually view a list of all alternate data streams, and their contents using PowerShell!(original)

 

See Streams:

Get-item -Path path_to_file -stream *

; Output
Stream                   Length
 ------                  ------
:$DATA                  1183232
Stream                      224

View content:(In this case we are looking at the Alternate Data Stream 'Stream')

Get-Content -Path path_to_file -stream Stream

;Output (Using NONE's example IniWrite)
[Settings]
Pass=blah

My script runs in A_AhkVersion:=1.1.22.07, get the latest version at http://ahkscript.org/download/

Check out this AutoHotkey tutorial: http://ahkscript.git...o/AHK_Tutorial/

Read the documentation: http://ahkscript.org.../AutoHotkey.htm