Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78453

Re: Obscuring Python source from end users

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'element': 0.07; 'table.': 0.07; 'string': 0.09; 'consistency': 0.09; 'happen.': 0.09; 'pep': 0.09; 'todo:': 0.09; 'cc:addr :python-list': 0.11; 'def': 0.12; 'translation': 0.12; 'ast': 0.16; 'be:': 0.16; 'file1': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'imports': 0.16; 'interest,': 0.16; 'knock': 0.16; 'len,': 0.16; 'ought': 0.16; 'renaming': 0.16; 'wrote:': 0.18; 'module': 0.19; 'seems': 0.21; 'import': 0.22; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'replace': 0.24; 'mon,': 0.24; 'together.': 0.24; 'cc:2**0': 0.24; 'source': 0.25; 'this:': 0.26; 'pass': 0.26; 'least': 0.26; 'header:In- Reply-To:1': 0.27; 'idea': 0.28; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'that.': 0.31; 'end,': 0.31; 'sep': 0.31; 'subject:end': 0.31; 'subject:users': 0.31; 'table,': 0.31; 'this.': 0.32; 'figure': 0.32; 'maintaining': 0.32; 'subject:from': 0.34; 'could': 0.34; 'something': 0.35; 'objects': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; "i'll": 0.36; 'possible': 0.36; 'should': 0.36; 'so,': 0.37; 'two': 0.37; 'list': 0.37; 'implement': 0.38; 'problems': 0.38; 'files': 0.38; 'pm,': 0.38; 'short': 0.38; 'use.': 0.39; 'length': 0.61; 'new': 0.61; 'name': 0.63; 'pick': 0.64; 'between': 0.67; '100%': 0.77; 'local,': 0.84; 'subject:source': 0.84; 'to:none': 0.92; 'technique': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=dUFsSVhQ5UqJ6az3PiQS5PoGEi7n3oYo0KPNb64Z9YY=; b=Yv4kGYkk0eRUKgXtsCO3kkuWIAAmnC5IoaC3ADdGn/BLGzL3H3DJS4ksrbdbsc79+t q78/Io1dDSSTCrbUEnhB5+7DfOq7TWnK4K6WSXWxe5ugANVdS19B/dkIqg2FkflcbXU9 b3uSHqFjwXnlEAHOTWldZkODVJ4EdJ8cf7kXR1KcFPj7RQCzXsrGJ5tjpa7e4SBlkd8S lKTkThM4SloNtr7TAF9M0L+U06Hx6RjvvIBhdcAVyx/sb3YU4kSC6uXenzRbXjLUux3q HsnIWkQ2cGUIgwfCPYIMIaIh+7DjdUsEcFqt5lUe9wzJ2Nki3c8pKKW00zRK6pdthkbH KMpQ==
MIME-Version 1.0
X-Received by 10.152.205.38 with SMTP id ld6mr1560811lac.97.1411980941776; Mon, 29 Sep 2014 01:55:41 -0700 (PDT)
In-Reply-To <9ad69bd8-ca77-438f-adfe-87d727ca170c@googlegroups.com>
References <89381545-5edc-4f85-a4b8-86eebfdf34ee@googlegroups.com> <mailman.14461.1411977165.18130.python-list@python.org> <9ad69bd8-ca77-438f-adfe-87d727ca170c@googlegroups.com>
Date Mon, 29 Sep 2014 18:55:41 +1000
Subject Re: Obscuring Python source from end users
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14462.1411980943.18130.python-list@python.org> (permalink)
Lines 50
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1411980943 news.xs4all.nl 2976 [2001:888:2000:d::a6]:59105
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:78453

Show key headers only | View raw


On Mon, Sep 29, 2014 at 6:41 PM,  <norman.ives@gmail.com> wrote:
> Crunching the source is an interesting idea that could achieve that end, but it seems fraught with problems like maintaining consistency between renaming objects in a module and renaming where imports happen.
>

Here's a technique that you could use. Pick two prefixes, one for long
names and one for short names, and maintain a translation table. So,
for instance, you could have two source files like this:

# file1.py
# Do something with the length and the count
def xx_some_func(length, cnt):
    # TODO: Implement me.
    pass

# file2.py
import file1

def xx_foo(lst, len, count):
    # Do something for every element in the list
    # where the something is blah blah blah
    for element in lst:
        file1.xx_some_func(len, count)


And then your crunched files might be:

# file1.py:
def x_a(a,b):
 pass

# file2.py
import file1
def x_b(a,b,c):
 for d in a:
  file2.x_a(b,c)


The translation is 100% mechanical: any place you find "xx_some_func",
you replace it with "x_a". If you find a string that begins "xx_" and
isn't in your translation table, you construct a new name (don't
forget that you can use x_A as well as x_a) and add it to the table.

It ought to be possible to do an AST reconstitution for at least part
of this. I can hunt down some of my PEP 463 test code to help out with
that. It should be possible to figure out what names are local, and
then just use those.

If this is of interest, I'll see what I can knock together.

ChrisA

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Obscuring Python source from end users norman.ives@gmail.com - 2014-09-29 00:36 -0700
  Re: Obscuring Python source from end users Chris Angelico <rosuav@gmail.com> - 2014-09-29 17:52 +1000
    Re: Obscuring Python source from end users norman.ives@gmail.com - 2014-09-29 01:41 -0700
      Re: Obscuring Python source from end users Chris Angelico <rosuav@gmail.com> - 2014-09-29 18:55 +1000
      Re: Obscuring Python source from end users Chris Angelico <rosuav@gmail.com> - 2014-09-29 20:14 +1000
  Re: Obscuring Python source from end users alister <alister.nospam.ware@ntlworld.com> - 2014-09-29 08:42 +0000
  Re: Obscuring Python source from end users Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-29 21:47 +1000
    Re: Obscuring Python source from end users Sturla Molden <sturla.molden@gmail.com> - 2014-09-29 14:51 +0000
    Re: Obscuring Python source from end users Dan Stromberg <drsalists@gmail.com> - 2014-10-01 15:06 -0700
      Re: Obscuring Python source from end users Marko Rauhamaa <marko@pacujo.net> - 2014-10-02 08:17 +0300
        Re: Obscuring Python source from end users Terry Reedy <tjreedy@udel.edu> - 2014-10-02 03:19 -0400
        Re: Obscuring Python source from end users Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-02 17:22 +1000
  Re: Obscuring Python source from end users Sturla Molden <sturla.molden@gmail.com> - 2014-09-29 14:53 +0000
    Re: Obscuring Python source from end users Johannes Bauer <dfnsonfsduifb@gmx.de> - 2014-10-02 09:50 +0200
      Re: Obscuring Python source from end users Chris Angelico <rosuav@gmail.com> - 2014-10-02 18:32 +1000

csiph-web