Recent

Author Topic: Uncloseable App.  (Read 2228 times)

Jake012345

  • Sr. Member
  • ****
  • Posts: 260
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Uncloseable App.
« Reply #15 on: June 12, 2020, 02:05:32 am »
But What are the:

Quote
Code: Pascal  [Select][+][-]
  1. if ServerOn Then
  2. if Not ServerOn Then
  3.  

Simple variables?
« Last Edit: June 12, 2020, 02:11:10 am by Jake012345 »
Check my ProjectShare site and share your content: FPCShare

Jake012345

  • Sr. Member
  • ****
  • Posts: 260
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Uncloseable App.
« Reply #16 on: June 12, 2020, 02:26:53 am »
I got range check error when I tried to load in the files.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, FileUtil;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     SelectFolderDialog: TSelectDirectoryDialog;
  16.     SelectedEdit: TEdit;
  17.     StartButton: TButton;
  18.     LocateButton: TButton;
  19.     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  20.     procedure LocateButtonClick(Sender: TObject);
  21.     procedure StartButtonClick(Sender: TObject);
  22.   private
  23.  
  24.   public
  25.     DenyStreams: array of TFileStream;
  26.     FileList: TStringList;
  27.   end;
  28.  
  29. var
  30.   Form1: TForm1;
  31.  
  32. implementation
  33.  
  34. {$R *.lfm}
  35.  
  36. { TForm1 }
  37.  
  38. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  39. begin
  40.   if PasswordBox('Authentication', 'Type the password:') <> 'asd' then
  41.     CloseAction := caNone;
  42. end;
  43.  
  44. procedure TForm1.LocateButtonClick(Sender: TObject);
  45. begin
  46.   if SelectFolderDialog.Execute then
  47.     SelectedEdit.Text := SelectFolderDialog.FileName;
  48. end;
  49.  
  50. procedure TForm1.StartButtonClick(Sender: TObject);
  51.  var i:integer;
  52. begin
  53.   SetCurrentDir(SelectedEdit.Text);
  54.   FileList := TStringList.Create;
  55.   FindAllFiles(FileList, GetCurrentDir, '*', False, faDirectory);
  56.   ShowMessage('Theese will be locked:' + #13#10 + FileList.Text);
  57.   for i:=0 to FileList.Count do
  58.   DenyStreams[i]:=TFileStream.Create(FileList.Strings[i],fmOpenRead or fmShareDenyWrite);
  59.   FileList.Free;
  60. end;
  61.  
  62. end.
  63.  

Somewhere in the 'for' cycle
« Last Edit: June 12, 2020, 02:28:30 am by Jake012345 »
Check my ProjectShare site and share your content: FPCShare

TRon

  • Hero Member
  • *****
  • Posts: 536
Re: Uncloseable App.
« Reply #17 on: June 12, 2020, 03:04:15 am »
Somewhere in the 'for' cycle
Really ? somewhere ?  ;D

Try to find out where exactly and then conclude that array indices are one of the most discussed topics on this forums  ;)

edit: I just noticed it is even worse
Code: Pascal  [Select][+][-]
  1. procedure TForm1.StartButtonClick(Sender: TObject);
  2. var
  3.   Filename: string;
  4.   i : integer = 0;
  5. begin
  6.   SetCurrentDir(SelectedEdit.Text);
  7.   FileList := TStringList.Create;
  8.   FindAllFiles(FileList, GetCurrentDir, '*', False, faDirectory);
  9.   ShowMessage('Theese will be locked:' + #13#10 + FileList.Text);
  10.   SetLength(DenyStreams, FileList.Count);
  11.   for Filename in FileList do
  12.   begin
  13.     DenyStreams[i]:=TFileStream.Create(Filename,fmOpenRead or fmShareDenyWrite);
  14.     inc(i);
  15.   end;
  16.   FileList.Free;
  17. end;
  18.  

Also do not forget to free those DenyStreams when you're done with them as otherwise you'll end up with some leak.
« Last Edit: June 12, 2020, 03:24:01 am by TRon »

dbannon

  • Hero Member
  • *****
  • Posts: 1167
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Uncloseable App.
« Reply #18 on: June 12, 2020, 06:51:00 am »
So, Jake012345, why ?  Not something where the end user cannot use their computer until they put some bitcoins in your account ?

Anyway, in the unix world (actually its heaps older than unix) you do a "Robin Hood", two processes, each endlessly checking the other one is running, if not, it restarts it.  So, if someone kills one process, the other (nearly) immediately restarts it.  You can kill them both but have to do it at (nearly) the same time, easy enough on the command line, difficult with a GUI.

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 587
Re: Uncloseable App.
« Reply #19 on: June 12, 2020, 10:17:24 am »
If you don't want your program to be easily terminated, then may be you should turn it into service/daemon?
DynamicData 3.0 is released!
Since now development is frozen - only optimization passes will be made at some point.
Lack of multiple inheritance turns it into abomination.

Handoko

  • Hero Member
  • *****
  • Posts: 3868
  • My goal: build my own game engine using Lazarus
Re: Uncloseable App.
« Reply #20 on: June 12, 2020, 11:34:43 am »
+1 Mr.Madguy

I saw many antiviruses use this technique.

Jake012345

  • Sr. Member
  • ****
  • Posts: 260
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Uncloseable App.
« Reply #21 on: June 12, 2020, 01:44:33 pm »
Once I will work with daemons... when I can.

But here's the app.
Now just the connection needed.
Check my ProjectShare site and share your content: FPCShare

Jake012345

  • Sr. Member
  • ****
  • Posts: 260
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Uncloseable App.
« Reply #22 on: June 12, 2020, 04:11:36 pm »
How can I use the Open dialog for just 'Mark dialog'? I just need the file's name and it trys to open it. (so I can't reach the section that about the protected files)
Check my ProjectShare site and share your content: FPCShare

Jake012345

  • Sr. Member
  • ****
  • Posts: 260
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Uncloseable App.
« Reply #23 on: June 12, 2020, 07:51:02 pm »
Properties>options>ofNoValidate
Check my ProjectShare site and share your content: FPCShare

Jake012345

  • Sr. Member
  • ****
  • Posts: 260
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Uncloseable App.
« Reply #24 on: June 12, 2020, 07:53:22 pm »
I'm almost done with the application!

But I have an error on the unlock all in selected directory procedure. ('Unlock' Button)
Check my ProjectShare site and share your content: FPCShare

TRon

  • Hero Member
  • *****
  • Posts: 536
Re: Uncloseable App.
« Reply #25 on: June 12, 2020, 08:10:48 pm »
I'm almost done with the application!
Doesn't seem that way to me, according to the error below  ;)

Quote
But I have an error on the unlock all in selected directory procedure. ('Unlock' Button)
Those pesky indices again. Imagine you have a wall of bricks, stacked on top of each other. Now from the bottom you are going to take away one brick at a time, to finally end at the highest brick. That is exactly what your code is doing, e.g. fix that by deleting things backwards from your lists.

Jake012345

  • Sr. Member
  • ****
  • Posts: 260
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Uncloseable App.
« Reply #26 on: June 12, 2020, 08:19:35 pm »
You mean I have to use 'for maxof() downto 0 do' ?
Check my ProjectShare site and share your content: FPCShare

TRon

  • Hero Member
  • *****
  • Posts: 536
Re: Uncloseable App.
« Reply #27 on: June 12, 2020, 08:56:48 pm »
You mean I have to use 'for maxof() downto 0 do' ?
Yes, from high() to low(), or as another fix use while loops.

What i think you fail to see is that when you do a count-1 in a for loop then that value is permanent for the for loop, it isn't 're-loaded' on every iteration. So you keep deleting but the .count decreases on each iteration.

Jake012345

  • Sr. Member
  • ****
  • Posts: 260
  • 'The knowledge is the key.'
    • FPCProjectShare
Re: Uncloseable App.
« Reply #28 on: June 22, 2020, 12:51:08 pm »
I Can't do it.. ;(
Check my ProjectShare site and share your content: FPCShare

Warfley

  • Sr. Member
  • ****
  • Posts: 313
Re: Uncloseable App.
« Reply #29 on: June 22, 2020, 02:01:06 pm »
What you are trying to archive is against the mere concept of PCs. On a PC the owner is King, and there is no way to protect your processes from the admin.

You should go a different route, rather disabling the files until the user entered a password, just enable these files when the user has entered a password. Because this is possible.

Here are three possibilities by using encryption:

1. Encrypted Archive
Simple, have an encrypted archive (tar, zip, whatever) in which your files are stored. On password entry, decrypt these files and put them into the directory. Then use them like normal. As soon as your program that uses them is closed/the user logged out, archive these files again (you can also do it in regular intervals to be more robust against force shutdowns). Even if you don't delete these files, and they get edited, you will have the originals in the archive, and when your program starts, the corrupted files will be replaced by the archived files.

2. Virtual Drive
Take a look at for example veracrypt. This program allows you to create encrypted files that represent filesystems. When you start veracrypt you can encrypt them and veracrypt creates a virtual drive, through which you can access these files. The unencrypted files will never touch the harddrive and as soon as the veracrypt process is killed, the virtual drive, and all data in it, is gone, and only the encrypted veracrypt file is left on the machine.

3. Virtual process only filesystem
Emulate a (very simple) filesystem in your own program without using the OS filesystem. You can write an internal API to access the files in that (e.g. via creating your own TStream derivates for accessing the data), and this API in the backend than reads and writes the data into a single encrypted archive

Approach 1 is the easiest, but does not protect the files from being read. Approach 2 requires a lot of system API usage or to use an external program like veracrypt, but you can still use normal file access as much as you please and approach 3 requires the most work, you might need to rewrite your file accesses completely, but is better portable than approach 2

 

TinyPortal © 2005-2018