* * *

Author Topic: Some questions about program protection  (Read 1917 times)

justnewbie

  • Full Member
  • ***
  • Posts: 129
Some questions about program protection
« on: March 22, 2018, 08:05:00 pm »
1./ As I know, Lazarus/Free Pascal makes native code, so regaining the source code from a binary (exe,dll ...) is impossible. In other words: decompiling is impossible. Is it true?
2./ If it is true, then why do Pascal-obfuscators exist?
3./ What is the best method to protect my Lazarus-made binaries (exe, dll) from getting decompiled?
4./ A concrete example, if I have this:
MyString: string = 'My special string';
Can I somehow protect the 'My special string' against decompilation?



howardpc

  • Hero Member
  • *****
  • Posts: 2669
Re: Some questions about program protection
« Reply #1 on: March 22, 2018, 08:30:34 pm »
1./ As I know, Lazarus/Free Pascal makes native code, so regaining the source code from a binary (exe,dll ...) is impossible. In other words: decompiling is impossible. Is it true?
No
Quote
2./ If it is true, then why do Pascal-obfuscators exist?
To make it (slightly) harder for others to reconstruct your source code.
Quote
3./ What is the best method to protect my Lazarus-made binaries (exe, dll) from getting decompiled?
Keep your exe or dll on a single machine running an unusual operating system that is never connected to the internet.
Quote
4./ A concrete example, if I have this:
MyString: string = 'My special string';
Can I somehow protect the 'My special string' against decompilation?
You can apply encryption of various strengths to the string. FPC offers several implementations of encryption algorithms. But you cannot protect it indefinitely from a determined hacker with a big enough array of super computers, given enough time.

justnewbie

  • Full Member
  • ***
  • Posts: 129
Re: Some questions about program protection
« Reply #2 on: March 22, 2018, 08:40:16 pm »
Based on my original questions:
1./ I read this: "You could do other things to reduce an attacker's ability to disable your software activation system, for example, but in a native-compiled system like Delphi, you can't recreate source code from the binaries." Link: https://stackoverflow.com/questions/6225081/when-and-how-should-i-obfuscate-my-delphi-code
So, it is not true?

2./ I know what obfuscation means, but I don't understand why to obfuscate a source that cannot be decompiled.

3./  :) Anything else?

4./ Obviously by using encryption, but how can you hide the key itself?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4572
    • wiki
Re: Some questions about program protection
« Reply #3 on: March 22, 2018, 08:58:30 pm »
1./ I read this: "You could do other things to reduce an attacker's ability to disable your software activation system, for example, but in a native-compiled system like Delphi, you can't recreate source code from the binaries." Link: https://stackoverflow.com/questions/6225081/when-and-how-should-i-obfuscate-my-delphi-code
So, it is not true?

It is true and false.

You can't get the exact original source code back (so long as you ship without debug info, and the like)
But you can get a compile-able source, and that in pascal or c whichever you want.

There are disassemblers, and there are tools that help transform assembler to higher languages. Though by far not as readable as the original source.

Now saying "there are tools"... They do not work all on there own. It takes a lot of extra work for a hacker to make it to a source...
But a hacker doesnt even need the source. They analyse the assembler. And they debug and analyse behaviour.

There is now way to stop a hacker. You can only make it harder.

---------------
For example, with RTTI (and that is required to have forms, unless you do not use the form designer at all) your application (without debug info) contains the name of every form, button, label. That is information a hacker can use.
If an obfuscater renames your "activation success" label, into "etouhr" then that is less helpful.
The hacker can still search for the actual text though. So next you need to encrypt all captions, (or have an obfuscater that does this)...

Still you can spend any amount of time, a good hacker still will break it.

justnewbie

  • Full Member
  • ***
  • Posts: 129
Re: Some questions about program protection
« Reply #4 on: March 22, 2018, 09:08:27 pm »
"There is no way to stop a hacker. You can only make it harder. "
Yes, I know, but want to make it a bit harder.

You wrote about RTTI in connection with forms and visual components.
What if it is a DLL without any form? If it is a DLL that only contains mathematical functions?
Also, is it possible to get back the original function names and variable names?

What does "without debug info" mean?
« Last Edit: March 22, 2018, 09:27:29 pm by justnewbie »

GetMem

  • Hero Member
  • *****
  • Posts: 3022
Re: Some questions about program protection
« Reply #5 on: March 22, 2018, 09:49:21 pm »
Quote
Also, is it possible to get back the original function names and variable names?
No, but you don't need it. Take a look at the attached image: http://forum.lazarus.freepascal.org/index.php/topic,37045.msg247844.html#msg247844 You can debug it line by line.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4572
    • wiki
Re: Some questions about program protection
« Reply #6 on: March 22, 2018, 09:49:48 pm »
In the dll case you probably have no rtti. You should avoid any "published" section, as they cause rtti with names. (there may be an option, to disable this)

Enums and sets also cause rtti. Nothing you can do about this. (except obfuscate)

Some managed types (arrays) have rtti (but not sure if they include names), just so the data can be managed (eg refcounts of nested elements). That is probably not to big an issue.

Debug info is in "project options" (and packages too).
You will notice an increase in exe size.
You can always use strip.exe to remove it.

Debug info contains the original names of each function, line numbers, variable names....

justnewbie

  • Full Member
  • ***
  • Posts: 129
Re: Some questions about program protection
« Reply #7 on: March 22, 2018, 09:57:47 pm »
OK guys, thank you, I'm trying to digest these things (am just a newbie).
Probably I will come again with some questions ...

avra

  • Hero Member
  • *****
  • Posts: 1291
    • Additional info
Re: Some questions about program protection
« Reply #8 on: March 23, 2018, 01:26:08 am »
ct2laz - Easily convert components and projects between Lazarus and CodeTyphon

justnewbie

  • Full Member
  • ***
  • Posts: 129
Re: Some questions about program protection
« Reply #9 on: March 23, 2018, 10:17:40 am »
Thank you, I will study it.

justnewbie

  • Full Member
  • ***
  • Posts: 129
Re: Some questions about program protection
« Reply #10 on: March 23, 2018, 12:26:19 pm »
Martin_fr mentioned strip.exe.
Is it a standalone program from a 3rd party? How do I get it?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4572
    • wiki
Re: Some questions about program protection
« Reply #11 on: March 23, 2018, 12:29:25 pm »
On *nix systems it is usually installed as "strip"

On Windows, in is part of the Lazarus installer, look into the fpc/....../bin directory

justnewbie

  • Full Member
  • ***
  • Posts: 129
Re: Some questions about program protection
« Reply #12 on: March 23, 2018, 12:40:54 pm »
Got it, thanks! It made a 1.9MB file from my original 16MB. Awesome.

justnewbie

  • Full Member
  • ***
  • Posts: 129
Re: Some questions about program protection
« Reply #13 on: March 23, 2018, 12:43:54 pm »
I was reading somewhere earlier that a stripped binary can be made within Lazarus by using a certain settings in options.
Is it true and how?

Handoko

  • Hero Member
  • *****
  • Posts: 2255
  • My goal: build my own game engine using Lazarus
Re: Some questions about program protection
« Reply #14 on: March 23, 2018, 01:02:58 pm »
You can try:
- Using Build Modes
- Manually configure the settings

Using Build Modes:
01. Lazarus main menu > Project > Project Options > Compiler Options
02. On the right panel > click the 3 dots at the right of "Build modes (Default)"
03. Click "Create Debug and Release Modes"
04. Change the "Build modes (Debug)" to "Build modes (Release)"
05. Click "OK" and rebuild the program


Do It Manually:
01. Lazarus main menu > Project Options > Compiler Options > Compilation and Linking
02. Enable "Smaller rather than faster (-Os)"
03. Enable "Smart linkable (-CX)"
04. Enable "Link smart (-XX)"
05. Lazarus main menu > Project Options > Compiler Options > Debugging
06. Disable all items of "Checks and assertion"
07. Disable "Generate debugging info for GDB"
08. Enable "Strip symbols from execuable (-Xs)"
09. Click "Ok" and rebuild the program
« Last Edit: March 23, 2018, 01:05:18 pm by Handoko »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus