Encrypting a function in Delphi

0

Is it possible to encrypt functions in delphi? Any type of encryption .... example, I need to encrypt this function:

  function REspacos(const str: String): string;
const
  cDouble = ' ';
   cOne = '';
begin
   result:=Str;
   while pos(cDouble,result) > 0 do
      result:=StringReplace(result,cDouble,cOne,[rfReplaceAll]);
end;

I would like to encrypt it to be illegible for the final client, of course, to work normal in delphi.

    
asked by anonymous 24.06.2014 / 18:59

1 answer

2

Easy answer: You can not.

Outline :

I do not even want to get into the merits of why, so for the "compiler" to understand what was written, the code must be legible.

One way around this would be to create a DLL containing the "hidden" functions and release it along with the sources.

Here's how to do it from here :

Go to File|New|Other|DLL Wizard ;

Replace the font created by this:

library TestLibrary;

uses SysUtils, Classes, Dialogs;

procedure DllMessage; export;
begin
  ShowMessage('Olá Mundo') ;
end;

exports DllMessage;

begin
end. 

Create a new project (for testing), add a button on form (button1) and replace the source with the following:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes,
  Graphics, Controls, Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject) ;
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;

 procedure DllMessage; external 'SimpleMessageDLL.dll';

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject) ;
begin
  DllMessage;
end;

end. 

When you click the button, the system will call the function created in the DLL. Change the function you need and distribute the DLL next to the font stating that it is needed.

    
24.06.2014 / 19:44