astrand / pyobfuscate Goto Github PK
View Code? Open in Web Editor NEWpyobfuscate
License: GNU General Public License v2.0
pyobfuscate
License: GNU General Public License v2.0
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.
only pathon2? can not suport pathon3?
pip install ... on windows --> ValueError: path '/usr/bin' cannot be absolute
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)
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.
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
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:
--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.To fix this:
data_files=[('/usr/bin', ['pyobfuscate'])]
should be replaced with:
scripts=['pyobfuscate']
How can I fix the issue where symbols and parsers cannot be used in Python 3.10, resulting in the functionality being unusable.
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
有没有中文版使用说明:
使用方法是怎么样的?
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
I want to use this project, but in my code, there are lots of list comprehension and decorator, It fails to obfuscate, and I find that there are alreay issues here, so can you please fix these problems for us? Thanks.
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?
From http://bugzilla.lysator.liu.se/show_bug.cgi?id=1585:
If you have a construction like this:
foo = [1, # My number one
2,
3]
the obfuscated code will look like:
oo000 = [ 1 ,if 9 - 9: Ii . o0o00Oo0O - iI11I1II1I1I
2 ,
3 ]
Thus, a dummy-line construction has been inserted at the position of the comment.
A workaround is to turn off dummy lines, ie either use --removeblanks or
--keepblanks
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.
Moved from http://bugzilla.lysator.liu.se/show_bug.cgi?id=1691:
Opened: 2010-09-15 00:08
IE.
class foo:
@staticmethod
def bar(x):
pass
------- Comment #1 From Al Gettier 2010-09-15 00:11:52 [reply] -------
class foo:
@staticmethod
def bar():
pass
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:
no document?
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 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
Moved from http://bugzilla.lysator.liu.se/show_bug.cgi?id=1359:
pyobfuscate doesn't handle constructs like:
print "foo bar %(somevariable)s" % locals()
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]
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:
------- 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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.