hide python code !

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bayazee

    hide python code !

    hi
    can we hide a python code ?
    if i want to write a commercial software can i hide my source code from
    users access ?
    we can conver it to pyc but this file can decompiled ... so ...!!
    do you have any idea about this ...?

    ---------------------------------------
    First Iranian Open Source Community : www.python.ir

  • John Machin

    #2
    Re: hide python code !


    Bayazee wrote:
    hi
    can we hide a python code ?
    if i want to write a commercial software can i hide my source code from
    ^^^^^^^^^^^^^^^ ^^^^^^^^^[1]
    users access ?
    we can conver it to pyc but this file can decompiled ... so ...!!
    do you have any idea about this ...?
    >
    ---------------------------------------
    First Iranian Open Source Community : www.python.ir
    ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^[2]


    [1] and [2] don't seem to be compatible.

    Really the only way to keep your code secret is not to distribute it --
    provide the functionality from a web server.

    If you want to distribute obfuscated code, consider writing it in perl
    :-)

    Comment

    • Bayazee

      #3
      Re: hide python code !

      hi
      in compiled languages when we compile a code to an executable file it
      convert to a machine code so now we cant access to source ...
      but in python we easily open the program executable(asci i) file and
      read source ....
      i meen than any way to protect my code or convert it to executable
      witch can not be decompiled (python code)....

      Comment

      • John Machin

        #4
        Re: hide python code !


        Bayazee wrote:
        hi
        in compiled languages when we compile a code to an executable file it
        convert to a machine code so now we cant access to source ...
        but in python we easily open the program executable(asci i) file and
        read source ....
        i meen than any way to protect my code or convert it to executable
        witch can not be decompiled (python code)....
        I know what you mean.

        However consider this: There is no such thing as an executable which
        cannot be decompiled; if the code can be executed, then anybody with
        read access to the code can disassemble/decompile/whatever it -- there
        is no theoretical difference between disassembling an .exe file and
        decompiling a .pyc file. What's in a .pyc file is just the machine code
        for a virtual machine ...

        Consider changing your business plan: write crappy software, charge
        heaps for support -- it's not a novel idea :-)

        Comment

        • Steven D'Aprano

          #5
          Re: hide python code !

          On Thu, 10 Aug 2006 17:03:51 -0700, Bayazee wrote:
          hi
          in compiled languages when we compile a code to an executable file it
          convert to a machine code so now we cant access to source ...
          There are disassemblers for machine code. If somebody really wants to see
          how your code works, they can do it.
          but in python we easily open the program executable(asci i) file and read
          source ....
          Yes. That is by design.
          i meen than any way to protect my code or convert it to executable witch
          can not be decompiled (python code)....
          In your first email, you wrote:

          "First Iranian Open Source Community : www.python.ir"

          Hiding source code is incompatible with Open Source software. You can hide
          code, or be Open Source, but not both.

          What makes you think that your code is so special that it is worth
          stealing? Do you have incredible secret algorithms that nobody has ever
          seen before? Or are you just so ashamed of it that you don't want people
          to see it?

          Or maybe you've copied other people's code, and you don't want them to see
          that? What are you hiding?

          Whatever your reasons for hiding the source code, there are things which
          you can do to obfuscate Python code which will make it difficult for
          people to get to the source code. Google for "python obfuscate" for links.
          But I'm guessing that, if you hide your source code, most people will
          wonder what you are hiding and avoid your program.

          If you really want something which compiles to machine code, then Python
          is not the language for you. Use another language.



          --
          Steven D'Aprano

          Comment

          • enigmadude

            #6
            Re: hide python code !

            I don't think you're the first person that has wondered about this. But
            you might have some options:

            1. If you are running it on Windows only, use py2exe to wrap it up as
            an executable.
            2. I've never done this, but you might be able to encrypt or otherwise
            turn you modules into binary form, and then use a clever import hook. I
            know zipimport in the standard lib gives you more control over
            importing zip files, but I don't think it can handle encrypted ones.
            3. Write a custom module importer in C using Python's API so you can
            encrypt your modules any way you want as long as you know how to use C
            to decrypt them again.

            There's probably a thousand other ways if you're clever enough (e.g.
            write it in Jython and package it as .jar files). As long as your
            program sticks closer to pure Python, the easier it will be. If you're
            using a lot of open source modules to help you out, you might want to
            double-check their licensing to see if what you're doing is allowed
            anyway.


            Bayazee wrote:
            hi
            can we hide a python code ?
            if i want to write a commercial software can i hide my source code from
            users access ?
            we can conver it to pyc but this file can decompiled ... so ...!!
            do you have any idea about this ...?
            >
            ---------------------------------------
            First Iranian Open Source Community : www.python.ir

            Comment

            • Simon Forman

              #7
              Re: hide python code !

              Bayazee wrote:
              hi
              in compiled languages when we compile a code to an executable file it
              convert to a machine code so now we cant access to source ...
              It can still be disassembled and reverse engineered.
              but in python we easily open the program executable(asci i) file and
              read source ....
              i meen than any way to protect my code or convert it to executable
              witch can not be decompiled (python code)....
              How do you reconcile this desire with being part of "First Iranian Open
              Source Community"?

              I am not hostile, just curious.


              BTW, John Machin's suggestion of presenting your code as a web service
              is a good one.

              Peace,
              ~Simon

              Comment

              • Cameron Laird

                #8
                Re: hide python code !

                In article <pan.2006.08.11 .00.21.06.65827 2@REMOVEME.cybe rsource.com.au> ,
                Steven D'Aprano <steve@REMOVEME .cybersource.co m.auwrote:
                >On Thu, 10 Aug 2006 17:03:51 -0700, Bayazee wrote:
                >
                >hi
                >in compiled languages when we compile a code to an executable file it
                >convert to a machine code so now we cant access to source ...
                >
                >There are disassemblers for machine code. If somebody really wants to see
                >how your code works, they can do it.
                >
                >but in python we easily open the program executable(asci i) file and read
                >source ....
                >
                >Yes. That is by design.
                >
                >i meen than any way to protect my code or convert it to executable witch
                >can not be decompiled (python code)....
                >
                >In your first email, you wrote:
                >
                >"First Iranian Open Source Community : www.python.ir"
                >
                >Hiding source code is incompatible with Open Source software. You can hide
                >code, or be Open Source, but not both.
                >
                >What makes you think that your code is so special that it is worth
                >stealing? Do you have incredible secret algorithms that nobody has ever
                >seen before? Or are you just so ashamed of it that you don't want people
                >to see it?
                >
                >Or maybe you've copied other people's code, and you don't want them to see
                >that? What are you hiding?
                >
                >Whatever your reasons for hiding the source code, there are things which
                >you can do to obfuscate Python code which will make it difficult for
                >people to get to the source code. Google for "python obfuscate" for links.
                >But I'm guessing that, if you hide your source code, most people will
                >wonder what you are hiding and avoid your program.
                >
                >If you really want something which compiles to machine code, then Python
                >is not the language for you. Use another language.

                Comment

                • Ben Finney

                  #9
                  Re: hide python code !

                  "Bayazee" <bayazee@gmail. comwrites:
                  can we hide a python code ?
                  Sure; don't distribute it to anyone. Then they can't run the program
                  or inspect it or anything.
                  if i want to write a commercial software can i hide my source code
                  from users access ?
                  You can write commercial software and sell it without hiding the
                  source code.
                  we can conver it to pyc but this file can decompiled ... so ...!!
                  Indeed. So?

                  --
                  \ "For of those to whom much is given, much is required." -- |
                  `\ John F. Kennedy |
                  _o__) |
                  Ben Finney

                  Comment

                  • Bruno Desthuilliers

                    #10
                    Re: hide python code !

                    Bayazee wrote:
                    hi
                    can we hide a python code ?
                    if i want to write a commercial software can i hide my source code from
                    users access ?
                    we can conver it to pyc but this file can decompiled ... so ...!!
                    It's just the same with java byte-code or machine code. FWIW, I had a
                    cracked (and localised) copy of Steinberg's Cubase midi sequencer v1.1
                    *before* v1.0 was publicly available in France... And believe me, they
                    had made their best to protect the software (dongle etc...).

                    The only secure way to protect "critical" code is to not distribute it -
                    make it run on your own server, and require the application to access
                    the server.


                    Comment

                    • Bruno Desthuilliers

                      #11
                      Re: hide python code !

                      Steven D'Aprano wrote:
                      (snip)
                      If you really want something which compiles to machine code, then Python
                      is not the language for you. Use another language.
                      >
                      But that won't protect your software from piracy anyway.

                      Comment

                      • Rob Wolfe

                        #12
                        Re: hide python code !


                        John Machin wrote:
                        If you want to distribute obfuscated code, consider writing it in perl
                        :-)
                        LOL

                        That's really strong protection. Machine code is too easy
                        to reverse engineer. :)

                        Regards,
                        Rob

                        Comment

                        • Slawomir Nowaczyk

                          #13
                          Re: hide python code !

                          On Thu, 10 Aug 2006 17:35:27 -0700
                          enigmadude <enigmadude@roc k.comwrote:

                          #2. I've never done this, but you might be able to encrypt or otherwise
                          #turn you modules into binary form, and then use a clever import
                          #hook.

                          Please observe that whatever the "clever import hook" is, it actually
                          needs to know the way to *decrypt* the module (secret key or
                          whatever). It means that if somebody decompiles the importing code, he
                          can just as well decompile the "hidden" one.

                          --
                          Best wishes,
                          Slawomir Nowaczyk
                          ( Slawomir.Nowacz yk@cs.lth.se )

                          Children are natural mimics, who act like their parents despite
                          every effort to teach them good manners.

                          Comment

                          • Paul Boddie

                            #14
                            Re: hide python code !

                            Cameron Laird wrote:
                            Steven D'Aprano wrote:
                            Hiding source code is incompatible with Open Source software. You can hide
                            code, or be Open Source, but not both.
                            [...]
                            I also disagree with your characterizatio n of Open Source.
                            I don't know which part of the open source movement would tolerate the
                            hiding of source code whilst simultaneously calling the resulting
                            software "open source", but I'd imagine they'd have a hard time
                            justifying their "open source" label. Of course, it is possible to be
                            the "First Iranian Open Source Community" in terms of consuming open
                            source software rather than producing it, so perhaps that's what the
                            questioner intended to communicate in their signature.

                            [...]
                            Myself, I just marvel at the different worlds in which we live. *My*
                            experience has to do with how tough it is to deploy and maintain
                            correct, working stuff, even with teams of seasoned pros. The thought
                            that users will routinely reverse-engineer our applications, and ...
                            well, I marvel.
                            I've previously mentioned a very interesting paper which not only
                            described the reverse engineering of the Skype protocol and software
                            but also described how to make interoperating Skype clients. Given that
                            the well-financed developers spent a lot of time introducing various
                            protection measures (encryption, verification, etc.) and yet someone
                            can write the aforementioned stuff up in a paper, I'd recommend an
                            upgrade to any business plan which relies on obfuscation to prevent
                            "unauthoris ed" use or modification. Indeed, I'd recommend that any such
                            entrepreneur think twice about starting a traditional proprietary
                            software business in this day and age.

                            Paul

                            Comment

                            • Fuzzyman

                              #15
                              Re: hide python code !


                              Bayazee wrote:
                              hi
                              can we hide a python code ?
                              if i want to write a commercial software can i hide my source code from
                              users access ?
                              we can conver it to pyc but this file can decompiled ... so ...!!
                              do you have any idea about this ...?
                              >
                              ---------------------------------------
                              First Iranian Open Source Community : www.python.ir

                              You can distribute the compiled byte-code files (*.pyc) which are
                              harder to turn back into source code.

                              There was a product called decompyle which could do it, but although
                              there is a version floating around which works for Python 2.4 I've
                              never heard of anyone getting it to work.

                              Import hooks and encrypted source are a good option.

                              Py2exe embeds the byte-code file for your main script into the
                              executable which is also pretty good.

                              All of these make it hard enough to deter most people who will ever
                              want to abuse your source code. Until you have *lots* of users this is
                              probably enough.

                              I never understand the knee-jerk reaction on this mailing list to
                              answer people who ask this question by telling them they don't really
                              want to do it...

                              Fuzzyman


                              Comment

                              Working...