views:

192

answers:

8

I am working on a project that requires reading text files, extracting data from them, and then generating reports (text files). Since there are a lot of string parsing, I decided to do it in Perl or Python or PHP (preference in that order). But I don't want to expose the source code to my client. Is there any good compiler for compiling perl/python/php scripts into linux executables?

I am not looking for a 100% perfect one, but I am looking for an at least 90% perfect one. By perfect, I mean the compiler doesn't require to write scripts with a limited subset of language features.

A: 

For Python You can call your code and give the *.pyc file to the client.

Quonux
@Quonux - I need to compile into linux executables, not windows .exe file. And I prefer perl, though python and php are also acceptable if there is not a solution for perl. I have googled "perl compiler for linux" and could not any solution. Thanks anyway!
Ethan
@Ethan: I'm not sure where you got the idea that this would create a windows .exe file. A .pyc file contains Python bytecode that is run by the Python VM. It's portable across any platform on which Python is installed.
intuited
Oh sorry. I replied too quick. Seems that Quonux edited his answer right after he posted. It was "... py2exe ..." I perfer perl because I am not familiar with python. But I will go with .pyc if there is not better solution.
Ethan
A: 

For linux an executable is something which has +x set, so there's no need to compile scripts. To hide your sourcecode you could use an obfuscator. This makes your sourcecode unreadable.

DiggyF
A: 

I've never used this, so I don't know how easy it is to setup, but you could use HipHop PHP to turn your PHP scripts into C++ code and compile them. (Assuming you choose to write them in PHP)

http://developers.facebook.com/blog/post/358

http://github.com/facebook/hiphop-php

Arctic Fire
+3  A: 

There does exist a Compiler for perl, called perlcc. I'm not familar with perl, but it looks like what you're looking for.

nebukadnezzar
It looks like that project was abandoned.
Kinopiko
Kinopiko: It is now available on CPAN.
Alexandr Ciornii
Negative. It was formerly included in the perl distribution (which is why it shows up on CPAN), but it was dropped because it was never very useful. Notice how if you search for it the dist that turns up is perl-5.8.9? That's because 5.10+ don't include it.
hobbs
hobbs: After it was removed from 5.10, Reini Urban started maintaining it, making it compatible with 5.10 and (almost) 5.12.
Alexandr Ciornii
chorny is right; I edited the link in the answer to point to the latest CPAN version.
daxim
+2  A: 

There are 3 options of encrypting Perl code:

  1. Use PAR to create executable file with PAR::Filter::Obfuscate or PAR::Filter::Crypto

  2. Use Filter::Crypto::CryptFile (will require some modules installed on target OS)

  3. Turn into module and encrypt into Module::Crypt.

Also you can try B::C - it was removed from core Perl distribution and is now available on CPAN.

Alexandr Ciornii
The first two depend on the user not knowing what Google is (the decrypt tool is *publicly available*); the third is a little tougher but it doesn't even try to ward off the obvious gdb attack :)
hobbs
hobbs, links, please? You're not talking about Filter::Crypto::Decrypt, are you? Read the Filter::Crypto manpage. It goes through some pain to make the recovery at least unpleasant.
tsee
@tsee no, I mean Filter::Crypto::CryptFile / crypt_file (from the same distro). The "security" is based entirely on the user not having that module and not finding it on the internet. If you find it, you can run "crypt_file --crypt-mode=decrypt", so it doesn't matter what tricks Filter::Crypto::Decrypt does.
hobbs
hobbs: "crypt_file --crypt-mode=decrypt" will work only on developers computer.
Alexandr Ciornii
+3  A: 

I'm sorry, it's simply not worth spending your time on. For any language you choose (from among the ones you listed), for any compiler/obfuscator someone chooses to come up with, I promise you I can get readable source code out of it (within an hour if it's Perl; longer if it's Python or PHP simply because I'm less acquainted with the implementations of those languages, not because it's intrinsically harder with those languages).

I think you should take a better look at what your goals are and why you want to work for a client that you're assuming a priori wants to rip you off. And if you still want to go ahead with such a scheme, write in C or Fortran -- certainly not anything starting with "P".

hobbs
A: 

For Python you can use cx.freeze. I have not used this but I believe that it basically bundles the .pyc into a zip file and adds an executable front-end.

Alternatively you could try compiling you Python code with Cython. this translates a modified version of the Python language into C code, which can then be compiled. This is normally used to write high performance extensions or interface with existing C libraries, but the latest version can also be used to make a complete executable.

Dave Kirby
+1  A: 

So far we've heard about perlcc and PAR with some obfuscation filters. These may work.

I have had very good luck with ActiveState's PerlApp which is part of their Perl Dev Kit.

It works well to bundle your code and hide it. You can try it for free, and it comes with some nice extras. Whether it is expensive or cheap depends on your perspective. For me, it was cheap. The cost in time of getting code hiding working and reliable with PAR or messing with perlcc was easily less than the price of the package. YMMV.

daotoad
+1 for perlapp, but you know that you can contribute to PAR to make it better, right? Even if it's "just" how-to style documentation.
tsee
PAR is great, my intention was not to slag it. The real problem is that philosophically, it favors openness--it is easy to extract the packaged code. For my personal values, this is fantastic. For many businesses and a business people, this is a fundamental problem. They demand reliable protection of their assets. They also want someone to assure them that their assets are properly protected. $300 to ActiveState, who have put a lot of work into the Perl ecosystem, is a pretty small price to keep these people happy and simplify my life.
daotoad