forked from astrand/pyobfuscate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyobfuscate-install
executable file
·76 lines (60 loc) · 1.89 KB
/
pyobfuscate-install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
# pyobfuscate - Python source code obfuscator
#
# Copyright 2004-2007 Peter Astrand <[email protected]> for Cendio AB
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
import os, sys
def get_origin_dir():
startdir = os.getcwd()
os.chdir(os.path.dirname(sys.argv[0]))
origin = os.getcwd()
os.chdir(startdir)
return origin
def usage():
print >>sys.stderr, """
Install and obfuscate a Python file in one step.
Usage:
pyobfuscate-install [-m <mode>] [pyobfuscate-args] <source> <dest>
"""
sys.exit(1)
def main():
if len(sys.argv) < 2:
usage()
origin = get_origin_dir()
mode = 0755
rest = []
next_is_mode = False
for arg in sys.argv[1:]:
if next_is_mode:
mode = int(arg, 8)
next_is_mode = False
elif arg == "-m":
next_is_mode = True
else:
rest.append(arg)
source = rest[0]
dest = rest[1]
if os.path.isdir(dest):
dest = os.path.join(dest, os.path.basename(source))
cmd = os.path.join(origin, "pyobfuscate")
cmd += " " + source + " >" + dest
print >>sys.stderr, "Calling", cmd
retcode = os.system(cmd)
os.chmod(dest, mode)
if retcode > 254:
retcode = 254
sys.exit(retcode)
if __name__ == "__main__":
main()