Recent

Author Topic: Recursive Procedure  (Read 2515 times)

J-G

  • Hero Member
  • *****
  • Posts: 966
Recursive Procedure
« on: March 18, 2022, 05:54:47 pm »
I'm probably going about this isssue in a totally incorrect way but I tend to learn by making mistakes!

I've never previously needed to think about IP Protection but my current project will go to a third party that I don't know personally for testing & review so I thought that it was about time I incorporated some sort of 'Pass Code' to at least look as if I care :)

The logic of creating a number from a string of characters is no problem nor retreiving same for comparison. Nor are the issues of getting the 'user' details upon first running the program, saving those and getting them back on subsequent runs.  What I can't do is get the [Pass Code] dialogue to appear and be editable on subsequent runs.

I eventually hit upon the idea to call the testing routine,    as in:
Code: Pascal  [Select][+][-]
  1. procedure Get_PassCode;
  2. begin
  3.   Form1.Test_Panel.show;
  4.   GoodToGo := false;
  5.   Repeat
  6.     Form1.Pass_Code_TestEditingDone(Nil);
  7.   until GoodToGo;
  8.   Form1.Test_Panel.Hide;
  9.  
  10.   Form1.ThreadFormList.Enabled:=False;
  11. end;
  12.  

The test procedure takes the number typed into a TEdit and compares it to the known code - viz.
 
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Pass_Code_TestEditingDone(Sender: TObject);
  2. begin
  3.   Pass_Test := StrToFloat(Pass_Code_Test.Text);
  4.   GoodToGo  := (Pass_Code-Pass_Test = 0);
  5.   If Pass_Test = 0 then
  6.     begin
  7.       Application.Terminate;
  8.     end;
  9.  
  10.   If GoodToGo then
  11.     begin
  12.       Form1.Hello_Label.Caption:='Thanks';
  13.       Form1.Hello_Label.Color:=clOlive;
  14.       Form1.User_FirstName_Label.Caption:=UserName;
  15.       Form1.User_FirstName_Label.Show;
  16.       Form1.Hello_Label.Show;
  17.       Application.ProcessMessages;
  18.  
  19.       Sleep(1000);
  20.  
  21.       KillPanel;
  22.       Form1.Test_Panel.Hide;
  23.       Form1.ThreadFormList.Enabled:=True;
  24.     end
  25.   else
  26.     begin
  27.       Form1.Hello_Label.Caption:='ERROR';
  28.       Form1.Hello_Label.Color:=clRed;
  29.       Form1.Hello_Label.Show;
  30.     end;
  31. end;
  32.  

As you can see, the TEdit is on a TPanel which can be shown or hidden and that part works as expected. What happens is that if I 'initiallize' Pass_Code_Test.Text the panel doesn't appear for entry/editing and if I don't initiallize it then I get an 'Error:  "" is an invalid float' and the panel appears after clicking [OK]

(The 'KillPanel' is  just a fancy way to make it deminish in size rather than just vanish as in .Hide)



FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Bart

  • Hero Member
  • *****
  • Posts: 5649
    • Bart en Mariska's Webstek
Re: Recursive Procedure
« Reply #1 on: March 19, 2022, 02:04:54 pm »
I would do it like this (assuming that all of this is done on 1 form):

In Get_PassCode:
- show the panel
- disable all other components on the form

In Pass_Code_TestEditingDone:
- use TryStrToFloat to avoid exceptions
- if (Pass_Code-Pass_Test = 0) then hide the panel en show enable the other controls again, then proceed with whatever you want to do

I think I would prefer another solution where asking for the Pass Code was done on a separate for, which was shown using ShowModal, and the calling routine will check the value of ModalResult (which you can set to a value that indicates failure inside the OnEditingDone of the Edit in which yoy let the user type the Pass Code.

Bart

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Recursive Procedure
« Reply #2 on: March 19, 2022, 05:49:17 pm »
Thanks for your Input  Bart & Jamie.

With the unusual lack of response for two days  -  (this forum usually gets a positive response within hours  ;D )  I've been working on a completely different aproach.

I did say that I thought my basic concept was flawed!

So as not to clutter up this thread I'll start another with a different approach.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

mas steindorff

  • Hero Member
  • *****
  • Posts: 560
Re: Recursive Procedure
« Reply #3 on: March 19, 2022, 08:04:25 pm »
just one comment: A simple program like processHacker can scan a program and list it's embedded strings for the user. You shouldn't store your pass code as a single string.
Mas
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Recursive Procedure
« Reply #4 on: March 19, 2022, 08:19:56 pm »
just one comment: A simple program like processHacker can scan a program and list it's embedded strings for the user. You shouldn't store your pass code as a single string.
Mas
Good point - and no I don't store it, I calculate it on the fly and compare it to the entered value (which isn't stored either).
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

dbannon

  • Hero Member
  • *****
  • Posts: 3616
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Recursive Procedure
« Reply #5 on: March 20, 2022, 12:01:14 am »
While the topic of such protection has been discussed to death, I must still comment.

You need to supply the binary to someone to test, and the passcode. You are worried that someone may give your work to someone else ?  Whats to stop them also handing the passcode on ?

If its being supplied for review, maybe a time limit would work better, "this app will stop working after April 2022" ?

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Recursive Procedure
« Reply #6 on: March 20, 2022, 12:24:14 am »
If its being supplied for review, maybe a time limit would work better, "this app will stop working after April 2022" ?

Davo

That is EXACTLY the approach I am now taking Davo, thanks for  the confirmation that I'm moving in the right direction :)

There's no real 'worry' I don't do [Worry]  ::) 

If the program were to be passed on, - and it's no great shakes if it is - the first thing that happens on running it is a request for a 'Data Directory' and the second is confirmation of the User Details. If they are changed then the PassCode will not be the same.

To be honest, I don't even think that it might be passed on and this is just a nerd's excercise to prove to myself that some sort of protection is possible and that 'passing off' is traceable.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Recursive Procedure
« Reply #7 on: March 20, 2022, 07:50:01 pm »
Continuing my research into 'simple' program protection, I've come across an oddity.

My logic tells me that these two code fragments ought to return the same number :

Code: Pascal  [Select][+][-]
  1.   N := Length(S);
  2.   for i := 1 to length(S) do
  3.      N := N + Ord(S[1]) * i;
  4.  

Code: Pascal  [Select][+][-]
  1.   N := Length(S);
  2.   for i := 1 to length(S) do
  3.     begin
  4.       X := S[i];
  5.       O := Ord(X) * i;
  6.       N := N+O;
  7.     end;
  8.  

... but they don't  -  and I can't see why.  %)

The var declarations are :

N : Longword;
O : Word;
X : Char;
i : byte;

I'd appreciate some guidance as to the failure in my logic!
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

wp

  • Hero Member
  • *****
  • Posts: 13270
Re: Recursive Procedure
« Reply #8 on: March 20, 2022, 08:00:31 pm »
There's an S[1] in the first fragment (instead of S)

rvk

  • Hero Member
  • *****
  • Posts: 6910
Re: Recursive Procedure
« Reply #9 on: March 20, 2022, 08:05:20 pm »
There's an S[1] in the first fragment (instead of S)
You can use nobbc-tag  to quote [i]   :D

See:
There's an S[1] in the first fragment (instead of S[i])

J-G

  • Hero Member
  • *****
  • Posts: 966
Re: Recursive Procedure
« Reply #10 on: March 21, 2022, 12:13:14 am »
There's an S[1] in the first fragment (instead of S)

D'oh!   -  What a pillock I am!!

Such an obvious mistake, and I can't even imagine how I first typed a '1' rather than 'i' and second how I didn't see it on the many times I reviewed the code  :-[

At least I now know that my logic isn't flawed ( well, in this instance!).
« Last Edit: March 21, 2022, 02:47:12 am by J-G »
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

 

TinyPortal © 2005-2018