Changing Python Opcodes

Discussion in 'Python' started by Sreejith K, Aug 18, 2009.

  1. Sreejith K

    Sreejith K Guest

    Hi,

    I know this is not the best way to do it. But I have to do it at least
    to make it *hard* to decompile the python bytecode.

    I want to distribute a software written in Python without the source.
    So I compiled Python from source changing some opcode values (Taking
    care of HAVE_ARGUMENT value) and distributed with the .pyc files. It
    did compile but when I'm installing additional python modules using
    easy_install, the import fails with a segmentation fault. It worked in
    a 32 bit Centos 5.2 but not on 64bit Centos 5.2. I am using python
    2.5.4 source.

    I changed only the Include/opcode.py source with my jumbled opcode
    values. Was I correct here ? I would like to know what all changes to
    be made as to successfully compile a custom python with different
    opcode values ?
     
    Sreejith K, Aug 18, 2009
    #1
    1. Advertising

  2. Sreejith K schrieb:
    > Hi,
    >
    > I know this is not the best way to do it. But I have to do it at least
    > to make it *hard* to decompile the python bytecode.
    >
    > I want to distribute a software written in Python without the source.
    > So I compiled Python from source changing some opcode values (Taking
    > care of HAVE_ARGUMENT value) and distributed with the .pyc files. It
    > did compile but when I'm installing additional python modules using
    > easy_install, the import fails with a segmentation fault. It worked in
    > a 32 bit Centos 5.2 but not on 64bit Centos 5.2. I am using python
    > 2.5.4 source.
    >
    > I changed only the Include/opcode.py source with my jumbled opcode
    > values. Was I correct here ? I would like to know what all changes to
    > be made as to successfully compile a custom python with different
    > opcode values ?


    As you are the one who modified your Python, you are the one responsible
    for debugging that - noone else can.

    Did you try installing the egg *without* pyc-files in there? Because
    naturally those shouldn't work. They shouldn't crash the interpreter
    either, but then again - you *did* modify it.

    Diez
     
    Diez B. Roggisch, Aug 18, 2009
    #2
    1. Advertising

  3. Sreejith K

    Sreejith K Guest

    On Aug 18, 12:19 pm, "Diez B. Roggisch" <> wrote:

    > Did you try installing the egg *without* pyc-files in there? Because
    > naturally those shouldn't work. They shouldn't crash the interpreter
    > either, but then again - you *did* modify it.


    Hi Diez, thanks for the immediate reply :)

    I installed the setuptools using ez_setup.py script. Then I used the
    easy_install to install additional modules. When importing the
    installed modules segfault occurs. The module I installed was
    TurboGears.

    Then I thought that it happened maybe because the easy_install script
    is downloading eggs for original python (I'm not sure if it is what
    easy_install is doing). So I also tried to install the module by
    downloading all the dependencies (tar.gz files) and building it. Even
    then segfault occured. Is there any problem in changing only the
    opcodes.py file ? I did something horribly wrong here. Hope someone
    will help...
     
    Sreejith K, Aug 18, 2009
    #3
  4. Sreejith K wrote:

    > On Aug 18, 12:19 pm, "Diez B. Roggisch" <> wrote:
    >
    >> Did you try installing the egg *without* pyc-files in there? Because
    >> naturally those shouldn't work. They shouldn't crash the interpreter
    >> either, but then again - you *did* modify it.

    >
    > Hi Diez, thanks for the immediate reply :)
    >
    > I installed the setuptools using ez_setup.py script. Then I used the
    > easy_install to install additional modules. When importing the
    > installed modules segfault occurs. The module I installed was
    > TurboGears.
    >
    > Then I thought that it happened maybe because the easy_install script
    > is downloading eggs for original python (I'm not sure if it is what
    > easy_install is doing).


    Yep, that's actually it's main purpose.

    > So I also tried to install the module by
    > downloading all the dependencies (tar.gz files) and building it. Even
    > then segfault occured. Is there any problem in changing only the
    > opcodes.py file ? I did something horribly wrong here. Hope someone
    > will help...


    I don't know. You modified this yourself. If I were in your situation, what
    I would have done is to

    - modify the version-information stored in my PYC-files so that I'm sure I
    don't accidentally load any "normal" PYC-files. Python does check that
    through some magic number, make sure you use your own.

    - fire up the debugger and see where the segfault actually happens. Nobody
    can be helping you there, because it's *your* code, not Python anymore. And
    giving others access to it defies somewhat the purpose of the whole
    exercise....

    Diez
     
    Diez B. Roggisch, Aug 18, 2009
    #4
  5. Sreejith K

    Peter Otten Guest

    Diez B. Roggisch wrote:

    > Sreejith K wrote:


    >> So I compiled Python from source changing some opcode values


    > Nobody
    > can be helping you there, because it's *your* code, not Python anymore.
    > And giving others access to it defies somewhat the purpose of the whole
    > exercise....


    ....and everyone with the expertise to decompile your application and do
    something useful with the result will also be able to find this thread.
    Basically you're trying the security through obscurity stunt without the
    obscurity...

    Peter
     
    Peter Otten, Aug 18, 2009
    #5
  6. Sreejith K

    greg Guest

    Sreejith K wrote:

    > I know this is not the best way to do it. But I have to do it at least
    > to make it *hard* to decompile the python bytecode.
    > So I compiled Python from source changing some opcode values


    It probably wouldn't be all that hard for someone to
    figure this out. A possible avenue of attack would be
    to use your python to compile a known piece of code
    that exercises all the opcodes, and compare the result
    with that from a standard python.

    --
    Greg
     
    greg, Aug 19, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Samridhi Kumar Shukla
    Replies:
    1
    Views:
    540
    Alvin Bruney
    Nov 30, 2003
  2. Albretch
    Replies:
    4
    Views:
    913
    Larry Barowski
    Oct 2, 2004
  3. Peter Otten
    Replies:
    2
    Views:
    277
    Fabiano Sidler
    Sep 22, 2006
  4. Canny
    Replies:
    2
    Views:
    114
    Dr J R Stockton
    Jul 2, 2009
  5. Canny
    Replies:
    0
    Views:
    101
    Canny
    Jul 2, 2009
Loading...

Share This Page