Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Concealing Perl Code

by Gorby (Monk)
on Aug 13, 2004 at 17:01 UTC ( #382751=perlquestion: print w/replies, xml ) Need Help??
Gorby has asked for the wisdom of the Perl Monks concerning the following question:

Hello Wise Monks,

Is there a way I can "compile" my perl code so that others can only run it, not read it?

Thanks in advance.


Replies are listed 'Best First'.
Re: Concealing Perl Code
by insensate (Hermit) on Aug 13, 2004 at 17:08 UTC
Re: Concealing Perl Code
by diotalevi (Canon) on Aug 13, 2004 at 17:13 UTC
Re: Concealing Perl Code
by Aristotle (Chancellor) on Aug 14, 2004 at 19:39 UTC

    Is there a way I can "compile" my perl code so that others can only run it, not read it?

    Yes. Don't give them the code. Run the code on a server you control, and let the users run queries against it over the network.

    That's not what you want to do? You need to let them run your code on their own hardware?

    Ok, still possible. Do not grant redistributing/relicensing permissions for your code, either in part on completely (up to you).

    That's not what you want do do? You wanted it to be concealed via technical measures?

    Sorry, no can do.

    As far as I'm concerned, that's a good thing. CPAN might never have happened otherwise.

    Makeshifts last the longest.

Re: Concealing Perl Code
by zentara (Archbishop) on Aug 14, 2004 at 13:04 UTC
    jaco wrote:

    "I saw a method of doing this awhile ago where the code was wrapped into c binary. It only prevented novices from viewing the code, since all you needed to do was open the binary file and browse through it."

    Maybe you were thinking of "the generic script compiler" at shc.html ? It takes any script, shell or perl, and compiles it into a self-decrypting RC4 encoded c-binary. It can't be read by looking at the binary, but it CAN be easily cracked by a knowledgable user. It works well however, and stymies the average computer user.

    I'm not really a human, but I play one on earth. flash japh
Re: Concealing Perl Code
by jaco (Pilgrim) on Aug 13, 2004 at 18:11 UTC

    I saw a method of doing this awhile ago where the code was wrapped into c binary. It only prevented novices
    from viewing the code, since all you needed to do was open the binary file and browse through it.

    i have a snippet from one of my chat logs ...
    /*#define MULTIPLICITY */ /* try not to be a bad boy, avoid tinkering +with the interpreter's internal structure! */ \#include <EXTERN.h> \#include <perl.h> \#include <stdlib.h> static PerlInterpreter *pi; static char *script = $scriptText; int main(int argc, char **argv, char **envv) { int l, i, p_argc; char **p_argv; char *e_switch = \"-e\"; char *real_name = argv[0]; char *s_argv[2] = { e_switch, script } ; char **p_envv = envv; p_argc = argc+2; p_argv = (char **)malloc(sizeof(char*)*argc); p_argv[0] = argv[0]; p_argv[1] = s_argv[0]; p_argv[2] = s_argv[1]; for(i=1;i<argc;i++) { p_argv[i+2]=argv[i]; } pi = perl_alloc(); perl_construct(pi); perl_parse(pi,NULL,p_argc,p_argv,p_envv); { SV *sv; sv = perl_get_sv(\"0\",FALSE); if (!SvOK(sv)) { printf(\"%s: unrecoverable error\\n\",argv[0]); exit(EXIT_FAILURE); } sv_setpv(sv,argv[0]); } perl_run(pi); perl_destruct(pi); perl_free(pi); return EXIT_SUCCESS; }
    I wish i could remember what it was called or who wrote it.
    I'll try and find it on my old disks
Re: Concealing Perl Code
by CountZero (Bishop) on Aug 14, 2004 at 10:27 UTC
    I think far more programs (even those compiled into machine-code) are simpy copied and used without due respect to the laws of copyright, than programs are decompiled, studied and incorporated into other code.

    Do not over-rate the intellectual capacity of the users of your programs (any dumb-ass with a CD-burner can faster copy and distribute your program than you can write it), nor deceive yourself about the quality of your programming: it may be a shock to all of us programmers, but the world at large is most probably not interested at all in how we programmed things, just that it works (and how they can get away with it without paying).


    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Concealing Perl Code
by jacques (Priest) on Aug 14, 2004 at 12:30 UTC
    Check out PAR.

    (and Super Search next time ... this question has been asked many times already)

Re: Concealing Perl Code
by Wassercrats on Aug 13, 2004 at 21:37 UTC
    The thing I hate most about Perl might be the misleading information I was getting about file protection/concealing the source code with Perl. Nothing I read, until recently when I started asking questions and more deeply looking into hiding source code, suggested that it was more difficult to do in Perl than other popular languages, and impossible to do well unless a major compiler is written. One has been in the works for years, and it still doesn't work well. If I had known this when I was deciding what language to learn, it might have contributed to me choosing a different language.

    The following is one such misleading statement, from perlfaq3. It gives no indication that Perl code is less protectable than any other code.

    You can try using encryption via source filters (Filter::* from CPAN), but any decent programmer will be able to decrypt it. You can try using the byte code compiler and interpreter described below, but the curious might still be able to de-compile it. You can try using the native-code compiler described below, but crackers might be able to disassemble it. These pose varying degrees of difficulty to people wanting to get at your code, but none can definitively conceal it (true of every language, not just Perl).

    If you're concerned about people profiting from your code, then the bottom line is that nothing but a restrictive license will give you legal security. License your software and pepper it with threatening statements like ``This is unpublished proprietary software of XYZ Corp. Your access to it does not give you permission to use it blah blah blah.'' We are not lawyers, of course, so you should see a lawyer if you want to be sure your license's wording will stand up in court.

      At the levels described here, I'm not sure what other caveats you'd like to have seen. Assembly is easy enough to read, machine code is easily enough converted to assembly. Everything else is higher level and apt to be even easier (provided that someone has written code to handle that level). The structure of what is in there isn't so different from what you might find in the source of a compiled VB, Java, or C# executable.

      I'm listening, I'm just not understanding what feature other languages would have that you don't have here with regard to code privacy.

      Added: You aren't dead yet, you can go learn other languages, you know. I'm learning to use lisp right now.

        I'd accept machine code. I just don't want Perl to be more deficient in something that could protect my source code than another language. I want my language to support the best copy protection and source code concealing possible. There are far fewer people who know Assembly than people who know the common higher level languages, which means the chances of someone finding a hole are greatly decreased if it's in machine language.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://382751]
Approved by blokhead
Jar. Jar!...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2017-03-28 19:45 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (340 votes). Check out past polls.