How to hide a folder?

Just starting out? Need help? Post your questions and find answers here.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

How to hide a folder?

Post by PB »

I have this exact query:

http://www.vbforums.com/showthread.php?t=371175

Basically it talks about "Folder Lock" and how it makes a folder totally invisible
to Explorer and also a DOS box. I'd love to do this with PureBasic, but nothing
I've tried works (eg. renaming the folder with Chr(255) and so on). Any ideas?

And I don't mean setting the folder's attribute to "Hidden" either. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
lexvictory
Addict
Addict
Posts: 1027
Joined: Sun May 15, 2005 5:15 am
Location: Australia
Contact:

Post by lexvictory »

the only way i can think of is by used A.D.S lik mentioned in that link, or by somehow making a 'rootkit' that intercepts certain winapi functions...
Demonio Ardente

Currently managing Linux & OS X Tailbite
OS X TailBite now up to date with Windows!
netfriends
User
User
Posts: 36
Joined: Wed Jan 18, 2006 8:25 am
Contact:

Post by netfriends »

Try the code

Code: Select all

; IDE Options = PureBasic v3.94 (Windows - x86)
;By netfriends
#FILE_LIST_DIRECTORY = $0001 
#FILE_SHARE_READ = $00000001
#FILE_SHARE_DELETE = $00000004
#OPEN_EXISTING = $3
#FILE_FLAG_BACKUP_SEMANTICS = $02000000


Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #String_0
  #Button_0
  #Button_1
EndEnumeration
Procedure Open_Window_0()
  If OpenWindow(#Window_0, 336, 161, 563, 201,  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar , "CT+pro Studio")
    If CreateGadgetList(WindowID())
      StringGadget(#String_0, 50, 40, 460, 20, "")
      ButtonGadget(#Button_0, 50, 90, 210, 50, "lock")
      ButtonGadget(#Button_1, 290, 90, 210, 50, "unlock")
      
    EndIf
  EndIf
EndProcedure


If OpenLibrary(0,"kernel32.dll")
Open_Window_0()
Repeat
    EventID = WaitWindowEvent()

    If EventID = #PB_Event_Gadget
      If EventGadgetID() = #Button_0 ; Read
      
hDir.l=CallFunction(0, "CreateFileA",GetGadgetText(#String_0),#FILE_LIST_DIRECTORY,0,0,#OPEN_EXISTING,#FILE_FLAG_BACKUP_SEMANTICS,0)

ElseIf EventGadgetID() = #Button_1

   CallFunction(0, "CloseHandle",hDir)
   
     
    
      EndIf
    EndIf

  Until EventID = #PB_Event_CloseWindow

  EndIf
┏┓ CT+pro Studio - www_ct-pro_com
█┛ From China
┏█ MSN:ct1676@hotmail.com
┗┛ I have felt the pure power already.
|-.-|`o`|`_`|o_o|:_:|'_'|^.^|-_-!|
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

@netfriends: Although it's a neat trick may I ask what the above code has to do with invisible folders? All it does is to temporary lock a file/folder from being modfied or deleted. And that only as long as the application is running.

@PB: The only reason why someone should need such a thing is to prevent some data, no matter what kind of, from being read/used/modified. Such as, files from a commecial application or sensible data like passwords. That right?

Anyway, as far as I'm concerned it's not possible to create a folder that is "completely" invisible, even for the operating system. Maybe I'm wrong tho'. But if you want to "protect" some specific data why not not simply encrypt it?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Inf0Byt3
PureBasic Fanatic
PureBasic Fanatic
Posts: 2236
Joined: Fri Dec 09, 2005 12:15 pm
Location: Elbonia

Post by Inf0Byt3 »

@PB: This is a hard thing to do, really... The best idea is to follow lexvictory's idea, and to code a driver that gets in ring0 that intercepts the findfirstfilea, findnextfilea, openfile, etc API's and manipulate the parameters. That is the only way to do it correctly. You can read this to see how this works:


http://www.purebasic.fr/english/viewtopic.php?t=23373
None are more hopelessly enslaved than those who falsely believe they are free. (Goethe)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

@netfriends: Great tip; it works well and is a cool alternative. Thanks!

@Fluid Byte: The reason I need it is to protect files from deletion. If you
encrypt such files, they can still be deleted. Also, the files can be large,
such as my MP3 folder -- encrypting over 2000 files is not the right way
to do it, as they'd also need decrypting just to hear them. So hiding the
folder, or just making it locked, is a far better and easier alternative.
But I note files within it can still be launched with RunProgram. Still, it's
a good way to stop people opening folders that they shouldn't be in.

> it's not possible to create a folder that is "completely" invisible,
> even for the operating system

Yes it is, and that's what the "Folder Lock" app does. I've tried it. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: How to hide a folder?

Post by PB »

As an experiment I watched what "Folder Lock" did with FileMon (see below).
So to lock its "Locker" folder it was doing something with adding ")8$5(" to
the folder's path and playing with its attributes. Still can't work it out, though.

LOCKING:

1 3:47:30 PM Folder Lock.exe:3344 OPEN C:\Program Files\Folder Lock\Locker SUCCESS Options: Open Directory Access: All
2 3:47:30 PM Folder Lock.exe:3344 QUERY INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS FileAttributeTagInformation
3 3:47:30 PM Folder Lock.exe:3344 QUERY INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS FileNameInformation
4 3:47:30 PM Folder Lock.exe:3344 DELETE C:\Program Files\Folder Lock\Locker NOT EMPTY
5 3:47:30 PM Folder Lock.exe:3344 CLOSE C:\Program Files\Folder Lock\Locker SUCCESS
6 3:47:30 PM Folder Lock.exe:3344 QUERY INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS Attributes: D
7 3:47:39 PM Folder Lock.exe:3344 DIRECTORY C:\Program Files\Folder Lock\ SUCCESS FileBothDirectoryInformation: Locker
8 3:47:39 PM Folder Lock.exe:3344 CREATE C:\Program Files\Folder Lock\Locker\)8$5( SUCCESS Options: Create Directory Access: All
9 3:47:39 PM Folder Lock.exe:3344 CLOSE C:\Program Files\Folder Lock\Locker\)8$5( SUCCESS
10 3:47:39 PM Folder Lock.exe:3344 OPEN C:\Program Files\Folder Lock\Locker\)8$5( SUCCESS Options: Open Directory Access: All
11 3:47:39 PM Folder Lock.exe:3344 QUERY INFORMATION C:\Program Files\Folder Lock\Locker\)8$5( SUCCESS FileAttributeTagInformation
12 3:47:39 PM Folder Lock.exe:3344 QUERY INFORMATION C:\Program Files\Folder Lock\Locker\)8$5( SUCCESS FileNameInformation
13 3:47:39 PM Folder Lock.exe:3344 DELETE C:\Program Files\Folder Lock\Locker\)8$5( SUCCESS
14 3:47:39 PM Folder Lock.exe:3344 CLOSE C:\Program Files\Folder Lock\Locker\)8$5( SUCCESS
15 3:47:39 PM Folder Lock.exe:3344 OPEN C:\Program Files\Folder Lock\Locker SUCCESS Options: Open Access: All
16 3:47:39 PM Folder Lock.exe:3344 QUERY INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS FileAttributeTagInformation
17 3:47:39 PM Folder Lock.exe:3344 QUERY INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS FileNameInformation
18 3:47:39 PM Folder Lock.exe:3344 QUERY INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS Attributes: D
19 3:47:39 PM Folder Lock.exe:3344 SET INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS FileRenameInformation
20 3:47:39 PM Folder Lock.exe:3344 OPEN C:\Program Files\Folder Lock\Locker NOT FOUND Options: Open Directory Access: All

UNLOCKING:

1 3:50:11 PM Folder Lock.exe:3004 OPEN C:\Program Files\Folder Lock\Locker NOT FOUND Options: Open Directory Access: All
2 3:50:11 PM Folder Lock.exe:3004 OPEN C:\Program Files\Folder Lock\Locker NOT FOUND Options: Open Access: All
3 3:50:11 PM Folder Lock.exe:3004 QUERY INFORMATION C:\Program Files\Folder Lock\Locker NOT FOUND Attributes: Error
4 3:50:12 PM Folder Lock.exe:3004 OPEN C:\Program Files\Folder Lock\Locker NOT FOUND Options: Open Directory Access: All
5 3:50:12 PM Folder Lock.exe:3004 DIRECTORY C:\Program Files\Folder Lock\ NO SUCH FILE FileBothDirectoryInformation: Locker
6 3:50:12 PM Folder Lock.exe:3004 OPEN C:\Program Files\Folder Lock\Locker SUCCESS Options: Open Access: All
7 3:50:12 PM Folder Lock.exe:3004 CLOSE C:\Program Files\Folder Lock\Locker SUCCESS
8 3:50:13 PM Folder Lock.exe:3004 QUERY INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS Attributes: D
9 3:50:13 PM Folder Lock.exe:3004 QUERY INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS Attributes: D
10 3:50:13 PM Folder Lock.exe:3004 QUERY INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS Attributes: D
11 3:50:13 PM Folder Lock.exe:3004 QUERY INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS Attributes: D
12 3:50:13 PM Folder Lock.exe:3004 OPEN C:\Program Files\Folder Lock\Locker\pegtag.$s8 NOT FOUND Options: Open Access: All
13 3:50:13 PM Folder Lock.exe:3004 OPEN C:\Program Files\Folder Lock\Locker\ SUCCESS Options: Open Directory Access: All
14 3:50:13 PM Folder Lock.exe:3004 QUERY INFORMATION C:\Program Files\Folder Lock\Locker\ SUCCESS FileNameInformation
15 3:50:13 PM Folder Lock.exe:3004 DIRECTORY C:\Program Files\Folder Lock\Locker\ NO SUCH FILE FileBothDirectoryInformation: pegtag.$s8
16 3:50:13 PM Folder Lock.exe:3004 CLOSE C:\Program Files\Folder Lock\Locker\ SUCCESS
17 3:50:13 PM Folder Lock.exe:3004 DIRECTORY C:\Program Files\Folder Lock\ SUCCESS FileBothDirectoryInformation: Locker"*
18 3:50:13 PM explorer.exe:240 OPEN C:\Program Files\Folder Lock\Locker\ SUCCESS Options: Open Directory Access: All
19 3:50:13 PM explorer.exe:240 QUERY INFORMATION C:\Program Files\Folder Lock\Locker\ SUCCESS FileNameInformation
20 3:50:13 PM explorer.exe:240 DIRECTORY C:\Program Files\Folder Lock\Locker\ SUCCESS FileBothDirectoryInformation: *
21 3:50:13 PM explorer.exe:240 QUERY INFORMATION C:\Program Files\Folder Lock\Locker\ SUCCESS FileNameInformation
22 3:50:13 PM explorer.exe:240 DIRECTORY C:\Program Files\Folder Lock\Locker\ SUCCESS FileBothDirectoryInformation
23 3:50:13 PM explorer.exe:240 QUERY INFORMATION C:\Program Files\Folder Lock\Locker\ SUCCESS FileNameInformation
24 3:50:13 PM explorer.exe:240 DIRECTORY C:\Program Files\Folder Lock\Locker\ NO MORE FILES FileBothDirectoryInformation
25 3:50:13 PM explorer.exe:240 CLOSE C:\Program Files\Folder Lock\Locker\ SUCCESS
26 3:50:13 PM explorer.exe:240 OPEN C:\Program Files\Folder Lock\Locker SUCCESS Options: Open Directory Access: All
27 3:50:13 PM explorer.exe:240 DIRECTORY C:\Program Files\Folder Lock\Locker NOTIFY CLEANUP Change Notify
28 3:50:13 PM explorer.exe:240 QUERY INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS Attributes: D
29 3:50:13 PM explorer.exe:240 DIRECTORY C:\Program Files\Folder Lock\ SUCCESS FileBothDirectoryInformation: Locker
30 3:50:13 PM explorer.exe:240 QUERY INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS Attributes: D
31 3:50:13 PM explorer.exe:240 DIRECTORY C:\Program Files\Folder Lock\ SUCCESS FileBothDirectoryInformation: Locker
32 3:50:13 PM explorer.exe:240 QUERY INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS Attributes: D
33 3:50:15 PM explorer.exe:240 QUERY INFORMATION C:\Program Files\Folder Lock\Locker SUCCESS Attributes: D
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Post by eJan »

I have playing with FolderLock, when I try to open C:\ with WinHex it can't open it because MFT (master file table) is locked. But which method is used in FAT partitioins?
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: How to hide a folder?

Post by ricardo »

PB wrote:As an experiment I watched what "Folder Lock" did with FileMon (see below).
So to lock its "Locker" folder it was doing something with adding ")8$5(" to
the folder's path and playing with its attributes. Still can't work it out, though.
This is a similar problem that one that i accidentally has some days ago wasnt able to delete somefiles because accidentaly add some strange chars in the path.

FolderLock does that and make the folder system one, so its invisible and because the path additions its not listed when you try to list folders.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: How to hide a folder?

Post by PB »

> This is a similar problem that one that i accidentally has some days ago
> wasnt able to delete somefiles

Tell me: did my "kill explorer.exe" let you delete them? Because as far as
I know, that always works with files in the way you described them (I've
had the same symptoms for undeleteable files in the past).
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: How to hide a folder?

Post by ricardo »

PB wrote:> This is a similar problem that one that i accidentally has some days ago
> wasnt able to delete somefiles

Tell me: did my "kill explorer.exe" let you delete them? Because as far as
I know, that always works with files in the way you described them (I've
had the same symptoms for undeleteable files in the past).
Nope. I tried but still same until i use the software i told there.

problem was not because file was used or locked, but for some strange characters in the name... i know because i create it and by error add as name part of what i was trying to add as content.
Strangelky, those part DO NOT show as name, but i know was there in some way and was an obstacle to delete it.

Once, using folder lock (i buy a licence 2 years ago) i had a crash or something and then i find some folder locked by folderlock, was invisible as system folder and has some strange characters as the first part of the name.

I was able to see the folder, but was not able to find it using the PB search for directory... i dont remember how i solve the problem and copy the files inside the folder but i was sucesfully to done it without folderlock because folderlock because a bug was not able to find the folder.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

@netfriends: At first I praised your code, but then realised it doesn't lock the
C:\Program Files\Internet Explorer path for some reason. So maybe your tip
doesn't work for all folders?

[Update]

I'm running XP Pro. After further testing of the folder lock code, it seems that
trying to lock any folder in "C:\Program Files\" that belongs to Windows, can't
be done. For example, IE can't be locked, nor can "Windows NT" (which holds
the Windows apps of Dialer.exe, Pinball.exe, and so on). But, I can lock things
that do NOT actually belong to Windows, such as "C:\Program Files\Xerox\"
and "C:\Program Files\Cyberlink\".
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Booger
Enthusiast
Enthusiast
Posts: 134
Joined: Tue Sep 04, 2007 2:18 pm

Re: How to hide a folder?

Post by Booger »

This may not be a answer. But I remember in my old Dos days, we kept sensitive information in a virtual folder.
The virtual folder was actually just a large file with its own FAT and file system just like a drive would have been. Perhaps .pk3 or ISO would be acceptable today? Except it was encrypted. The only readable access was with a memory resident translator that had the correct password passed to it. This way, no access was granted to the contents even if the drive was removed or other OS bypass of drivers or such. Perhaps even today, a TSR style resident could set something in the registry so when protected virtual folders were double clicked the TSR would be invoked to manage the Virtual folder?

Sorry for the babble, but just wondering how or even feasible this would be in windows today?
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re:

Post by SFSxOI »

PB wrote:
@Fluid Byte: The reason I need it is to protect files from deletion. If you
encrypt such files, they can still be deleted. Also, the files can be large,
such as my MP3 folder -- encrypting over 2000 files is not the right way
to do it, as they'd also need decrypting just to hear them. So hiding the
folder, or just making it locked, is a far better and easier alternative.
But I note files within it can still be launched with RunProgram. Still, it's
a good way to stop people opening folders that they shouldn't be in.
Hiding the folder purposely is a big no-no, and may be illegal in certain jurisdictions (several states sued or prosecuted Sony for it with their root-kit fiasco when Sony used $sys$ to hide folders/files/processes). Just set the folder permissions to allow your app the only access. Something else to remember also, several worms/trojans/viruses either search out or create hidden folders in which to hide their files which makes getting rid of these things especially hard to do sometimes (several such pieces of malware took advantage of the Sony root-kit hidden folders to hide their destructive payloads.)
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: How to hide a folder?

Post by Fluid Byte »

Posted: Fri Sep 01, 2006 3:19 pm
:wink:
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Post Reply