Git Product home page Git Product logo

pyobfuscate's Introduction

pyobfuscate - Python source code obfuscator
===========================================

pyobfuscate is a source code obfuscator: It makes Python source code
hard to read for humans, while still being executable for the Python
interpreter. 


Why obfuscate?
--------------

Obfuscation makes little sense for Open Source
(http://www.opensource.org/) programs, but vendors developing
commercial applications are usually not happy with shipping the
original source code to customers. 

Several obfuscators for other languages, like Java, already
exists. With Python, the problem is even more severe than with Java,
because Python bytecode is not compatible between different Python
versions. Also, bytecode is very easy to "decompile" to source code by
using "decompyle": http://www.crazy-compilers.com/decompyle/.

If shipping original source code is the only option for distributing
Python applications, then many vendors might choose another
programming language instead. 


What does pyobfuscate do?
-------------------------

pyobfuscate transforms the source code in several ways. Some of these
transformations are reversible (can be "un-obfuscated"); some are
not. Here's a list of what pyobfuscate currently does:

* Removes comments and docstrings (not reversible)

* Changes indentation (reversible)

* Adds whitespace between tokens (somewhat reversible)

* Renames functions, classes and variables (not reversible)

* Inserts bogus lines instead of blank lines. 


Limitations
-----------

pyobfuscate operates on one single source file at a time. It does not
obfuscate the interface between several files. 

pyobfuscate cannot obfuscate methods, class variables or other
attributes, currently. See the TODO for more information.


pyobfuscate's People

Contributors

astrand avatar cendioniko avatar cendioossman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyobfuscate's Issues

there is error when i use byte

error:
charset=re.compile(b'<meta[^>]charset=['"]?([a-z0-8-]+)['"]?[^>]?>',re.IGNORECASE).findall(html)
correct:
charset=re.compile(r'<meta[^>]charset=['"]?([a-z0-8-]+)['"]?[^>]
?>',re.IGNORECASE).findall(html)

pyobfuscate can't handle function parameters in lambdas

Moved from http://bugzilla.lysator.liu.se/show_bug.cgi?id=1583:

As seen by the below example, pyobfuscate incorrectly obfuscates function
parameters when they are used in lambdas.

cat ~/slask/pyobf_lambda.py
def foo(bar):
lambda x: x.startswith(bar)

pyobfuscate ~/slask/pyobf_lambda.py
def oo000 ( bar ) :
lambda ii : ii . startswith ( oOOo )

------- Comment #1 From Erik Forsberg 2005-10-14 12:57:32 [reply] -------

I've implemented a test case in the test suite for this bug, but the actual bug
remains to be solved. I'll leave that to Mr Åstrand.

No Documentation on Usability : Please advise - Thank you Sir

Dear Author,

With sincere appreciation, Is it possible to provide simple documentation on how to use this tool.
I have a.py to be obfuscated.
What steps I need follow.
pyobfuscate a.py aob.py
Is this correct and After I obfuscate file how to use them in python 2.7
Please provide simple example - this will greatly help

Thank you very much Sir. Awaiting your reply - I am held up
BRE

Install location hardcoded as `/usr/bin`

Ticket inspired by http://stackoverflow.com/questions/43600414/error-errno-1-operation-not-permitted-usr-bin-pyobfuscate-macos-sierra/43600504


The setup.py for pyobfuscate treats the executable as data. This bypasses several desirable behaviors:

  • In general, distutils will honor --prefix, --exec-prefix, or to try to install to a location under the user's home directory if passed --user; hardcoding /usr/bin bypasses all of these behaviors.
  • In general, distutils will honor the install location for an active virtualenv.
  • In general, distutils will fix up the shebang used by any installed script to point to a locally available interpreter.

To fix this:

data_files=[('/usr/bin', ['pyobfuscate'])]

should be replaced with:

scripts=['pyobfuscate']

something wrong with css in pandas library

image
image

env :python 3.6.5,
library in context:pandas(css)

I know that css is newly for the add of pandas. May the author will have the time to experience the example to complete the library so perfectly.
May this library better and better.
My pleasure to request here!

Cannot be used in Python 3.10

How can I fix the issue where symbols and parsers cannot be used in Python 3.10, resulting in the functionality being unusable.

Does this still work?

I did a clean install following this:
https://www.smallsurething.com/category/obfuscation/

then tried to obfuscate file, but recive error:
[root@mikkm ~]# pyobfuscate init.py
Traceback (most recent call last):
File "/usr/bin/pyobfuscate", line 1188, in
main()
File "/usr/bin/pyobfuscate", line 1175, in main
ce = ColumnExtractor(source, cw.names)
File "/usr/bin/pyobfuscate", line 809, in init
self.parse(f)
File "/usr/bin/pyobfuscate", line 846, in parse
if occurancelist[seen_times]:
IndexError: list index out of range

pyobfuscate throw Error if 'None' found inside lambda

Hello,

I am trying pyobfuscate for encrypting my file. File contains below code piece in which pyobfuscate raise error:
File "/usr/bin/pyobfuscate", line 841, in parse
raise RuntimeError("Overlooked symbol '%s' on line %d column %d" % (t_string, srow, scol))
RuntimeError: Overlooked symbol 'None' on line 51 column 39

Code:
'name': lambda self,cr,uid,ctx=None: '/'

Waiting for reply.
Thank You

UnicodeEncodeError: 'utf-8' codec can't encode character '\ud8c1' in position 157202: surrogates not allowed

Hi,

I have Python 3.7.7 and I get this error message when I run copy:

Traceback (most recent call last):
  File "opy.py", line 537, in <module>
    main ()
  File "opy.py", line 520, in main
    targetFile.write (content)
  File "C:\Users\Nino\AppData\Local\Programs\Python\Python37\lib\codecs.py", line 721, in write
    return self.writer.write(data)
  File "C:\Users\Nino\AppData\Local\Programs\Python\Python37\lib\codecs.py", line 377, in write
    data, consumed = self.encode(object, self.errors)
UnicodeEncodeError: 'utf-8' codec can't encode character '\ud8c1' in position 157202: surrogates not allowed

Can you help me please?

pyobfuscate generates incorrect source code

From http://bugzilla.lysator.liu.se/show_bug.cgi?id=1606:

Here is the source code "setup.py":

from distutils.core import setup
import py2exe

setup(
# The first three parameters are not required, if at least a
# 'version' is given, then a versioninfo resource is built from
# them and added to the executables.
version = "0.1.01",
description = "py2exe sample script",
name = "py2exe samples",

# targets to build
windows = ['IntServerApp.py']
#windows = ["test_wx.py"],
#console = ["hello.py"],
)

When I run this through pyobfuscate it produces:

if 64 - 64: i11iIiiIii
if 65 - 65: O0 / iIii1I11I1II1 % OoooooooOO - i1IIi
from distutils . core import setup
import py2exe
if 73 - 73: II111iiii
setup (

As you can expect, this won't compile.

Thanks.

namespace resolution problem (?)

Moved from http://bugzilla.lysator.liu.se/show_bug.cgi?id=1393:

Opened: 2004-08-01 01:07

see the example:


def test1():
a='apple'
def test2():
print a
test2()

class foo:
def init(self):
pass

def test3(self,arg):
pass

def test4(self):
self.test3(1)
map(lambda x:self.test3(x),[1,2,3])


this example obfuscates to:

def oo000 ( ) :
ii = 'apple'
def oOOo ( ) :
print a
oOOo ( )
class IIi1IiiiI1Ii :
def init ( self ) :
pass
def test3 ( self , arg ) :
pass
def test4 ( self ) :
self . test3 ( 1 )
map ( lambda O0oO : o0oO0 . test3 ( O0oO ) , [ 1 , 2 , 3 ] )


there are two errors:

  1. the variable 'a' in test1 is obfuscated but not in test2
  2. self.test3 is preserved in test4, but gets obfuscated in the lambda function

problem with lambda & list comprehension

Moved from http://bugzilla.lysator.liu.se/show_bug.cgi?id=1603:

Dear Sirs:

the following Python code line

f = lambda x: [v for v in x]

does not get through the pyobfuscate and generates an error when compiled (see below traceback
report).
Best regards,

Marco Lombardi


Traceback (most recent call last):
File "/Users/mlombard/bin/pyobfuscate", line 1101, in ?
main()
File "/Users/mlombard/bin/pyobfuscate", line 1078, in main
cw = CSTWalker(source_no_encoding, pae.pubapi)
File "/Users/mlombard/bin/pyobfuscate", line 125, in init
self.walk(elements, [self.symtab])
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 211, in walk
self.handle_lambdef(elements, symtabs)
File "/Users/mlombard/bin/pyobfuscate", line 633, in handle_lambdef
self.walk(node, symtabs + [lambdatab])
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 187, in walk
self.handle_power(elements, symtabs)
File "/Users/mlombard/bin/pyobfuscate", line 662, in handle_power
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 203, in walk
self.handle_atom(elements, symtabs)
File "/Users/mlombard/bin/pyobfuscate", line 476, in handle_atom
self.walk(node, symtabs)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 214, in walk
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 187, in walk
self.handle_power(elements, symtabs)
File "/Users/mlombard/bin/pyobfuscate", line 662, in handle_power
self.walk(node, symtabs, functioncall)
File "/Users/mlombard/bin/pyobfuscate", line 203, in walk
self.handle_atom(elements, symtabs)
File "/Users/mlombard/bin/pyobfuscate", line 431, in handle_atom
s = tab.lookup(id)
File "/Users/mlombard/bin/pyobfuscate", line 107, in lookup
return self.symtabs[0].lookup(name)
File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/symtable.py", line 107, in
lookup
flags = self._table.symbols[name]
KeyError: 'v'

Pyobfuscate doesn't support type hints

Pyobfuscate throws an error when code contains type hints in method declarations.
RuntimeError: Overlooked symbol 'list' on line 70 column 40

Eg.
def some_method(users: list):
pass

fails on syntactically correct program

Traceback (most recent call last):
File "/usr/bin/pyobfuscate", line 1170, in
main()
File "/usr/bin/pyobfuscate", line 1145, in main
cw = CSTWalker(source_no_encoding, pae.pubapi)
File "/usr/bin/pyobfuscate", line 130, in init
self.walk(elements, [self.symtab])
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 169, in walk
self.handle_funcdef(elements, symtabs)
File "/usr/bin/pyobfuscate", line 367, in handle_funcdef
self.walk(node, symtabs + functabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 183, in walk
self.handle_atom(elements, symtabs)
File "/usr/bin/pyobfuscate", line 569, in handle_atom
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 185, in walk
self.handle_trailer(elements, symtabs)
File "/usr/bin/pyobfuscate", line 586, in handle_trailer
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 194, in walk
self.walk(node, symtabs)
File "/usr/bin/pyobfuscate", line 189, in walk
self.handle_argument(elements, symtabs)
File "/usr/bin/pyobfuscate", line 644, in handle_argument
elements = elements[3]

Comments block parsing?

Moved from http://bugzilla.lysator.liu.se/show_bug.cgi?id=1605:

The following code

d = {"a": "A", "b": "B",
# comment
"c": "C"}

is not correctly handled: the last line containing the dictionary key "c" is ignored, and the generated
obfuscated code is something like

oo000 = { "a" : "A" , "b" : "B" ,

if 9 - 9: Ii . o0o00Oo0O - iI11I1II1I1I

Marco Lombardi

------- Comment #1 From Marco Lombardi 2006-04-03 13:28:40 [reply] -------

I checked the problem in more detail, and it seems that this bug is due to the
code lines

        elif t_type == tokenize.STRING:
            if self.first_on_line and self.brlevel == 0:
                # Skip over docstrings
                # FIXME: This simple approach fails with:
                # "foo"; print 3

In other words, the part of the dictionary after the comment is (wrongly)
recognized as a docstring. A
simple patch for this, which I did implement already, is to keep track for the
number of parenthesis (),
braces {}, and brackets [] encountered so far, and to prevent the recognition
as a docstring of strings if
we are inside a tuple, dictionary, or list.

------- Comment #2 From Peter �strand 2006-04-03 18:47:51 [reply] -------

Can you attach your patch to this bug?

------- Comment #3 From Marco Lombardi 2006-04-04 12:01:57 [reply] -------

Created an attachment (id=95) [details]
Patched pyobfuscate

This patched version of pyobfuscate should solve a few bugs:

  1. It does the parsing of list comprehension, including multiple for/if such as
    [a*b for a in as for b in bs]
  2. It fixes a problem with global variables (which inside functions are not
    recognized as such, but taken as local variables)
  3. Avoid the use of noop lines inside tuples, lists, or dictionaries
  4. Changes the way a source is read to match exactly the Python library (in
    particular, use "U" to read sources in different newline formats, and add a
    "\n" at the end of the source; see compile.parseFile)

------- Comment #4 From Marco Lombardi 2006-04-04 12:03:05 [reply] -------

Forgot to mention... The patched version is based on the STABLE source, and not
on the CVS.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.