Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.

My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.


SOURCE

1
2
3
# you can find the original source here - https://github.com/shapedbyregret/actionscript-3-obfuscator
# special thanks goes to Erik Johnson for making a great script and commenting the code EXTREMELY WELL so that a python noob can use it

ORIGINAL

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# Actionscript 3.0 Obfuscator
#
# Copyright (c) 2008 Erik Johnson (shapedbyregret@gmail.com)
#
# 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, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.




#========================================
# Import modules
#
#========================================
import os.path
import re
import random
import string
import sys


#========================================
# Options
#
#========================================
removeComments = True
changeVarName = True
encodeStrings = True

# Following options should not be changed.
# They are either incomplete or incorrectly implemented.
removeWhitespace = False
changeFileName = True


#========================================
# Declare Variables
#
#========================================
blockCommentFound = False
varDeclareFound = False
varsFound = []
varsNew = []
varLength = 5
varCharSet = string.ascii_uppercase + string.ascii_lowercase + string.digits


#========================================
# Function declarations
#
#========================================

#========================================
# strip_white_space(String)
# First replaces each newline with an empty string, then splits at each
# tab, and then joins it all back together before returning.
def strip_white_space(someText):
    tmpLine = someText.replace("\n", "", 1)
    tmpList = tmpLine.split("\t")
    tmpLine = "".join(["%s" % k for k in tmpList])
    return tmpLine

#========================================
# string_to_hex(String)
# Iterates over each character in oldString and converts it first to an
# int, and then to a hex string. All "0" chars are replaced with "\"
# and added to newString.
def string_to_hex(oldString):
    newString = ""
    for char in oldString:
        tmpString = hex(ord(char))
        tmpString = tmpString.replace("0", "\\", 1)
        newString += tmpString
    return newString


#========================================
# Handle arguments
#
#========================================

# Check if arguments given
if len(sys.argv)>1:
    filePath = sys.argv[1]
    fullFileName = os.path.split(filePath)[1]
    fileName = fullFileName.rsplit(".", 1)[0]
    if len(sys.argv)>2:
        newFilePath = sys.argv[2]
        newFullFileName = newFilePath.rsplit("/", 1)[1]
        newFileName = newFullFileName.rsplit(".", 1)[0]
    else:
        # Create new file path
        tmpList = filePath.rsplit(".", 1)
        if len(tmpList)>1: # Check if there is a file extension
            newFilePath = tmpList[0] + "_Obfs." + tmpList[1]
        else:
            newFilePath = fileName + "_Obfs"

        # Create new file name
        tmpList = fullFileName.rsplit(".", 1)
        if len(tmpList)>1:
            newFullFileName = tmpList[0] + "_Obfs." + tmpList[1]
        else:
            newFullFileName = fileName + "_Obfs"

        newFileName = fileName + "_Obfs"
else:
    print "Filename not provided."
    exit()


#========================================
# Open File
#
#========================================
fileToChange = open(filePath, "r")
listLines = fileToChange.readlines() # Store fileToChange to memory in a list
fileToChange.close() # Close file

#========================================
# Iterate over file, one line at a time
#
#========================================
for line in listLines:

    newLine = line

    #========================================
    # Remove comments
    if removeComments:
	
        #========================================
        # Remove and delete all inline block comments
        # Replaces everything between "/*" and "*/" with an empty string.
        tmpLine = re.sub(r"(/\*).*?(\*/)", "", newLine)
        if tmpLine != "":
            newLine = tmpLine

        #========================================
        # Remove all other block comments.
        # Attempts to find beginning of block comment statement.
        if newLine.find("/*") != -1:
            blockCommentFound = True

        # If we find the end of the block comment, then we will store
        # everything past it, otherwise simply replace entire line with
        # a newline ("\n"), which helps to preserve code structure.
        if blockCommentFound:
            if newLine.find("*/") != -1:
                tmpLine = newLine.rsplit("*/", 1)
                newLine = tmpLine[1]
                blockCommentFound = False
            else:
                newLine = "\n"

        #========================================
        # Remove single line comments i.e. all text following "//"
        # Find last instance of "//" and determine if it is after semicolon.
        # If so then it is safe to delete. Which we do by splitting at the
        # last instance of found "//", appending a "\n" and storing it.
        # Note: The following relies on the assumption that the code being
        #       read uses semicolons to end statements.
        tmpLine = re.sub("//(?<=//)[^\r]*", "", newLine)
        if tmpLine != "":
            newLine = tmpLine
    
    #========================================
    # Collect variable names
    if changeVarName:
        tmpList = []

        # Store indices of AS3 reserved words "var", "function", or "const"
        varIndex = newLine.find("var")
        functionIndex = newLine.find("function")
        constIndex = newLine.find("const")
        if varIndex != -1 or functionIndex != -1 or constIndex != -1:
            varDeclareFound = True

ADDED

1
2
3
	# NOTE - using this to only obfuscate private and function-scoped members
        if newLine.find("public") != -1 or newLine.find("protected") != -1 or newLine.find("internal") != -1 or newLine.find("mx_internal") != -1:
	    varDeclareFound = False

ORIGINAL

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
        # If "function" was found, then we make a list of all words preceding
        # a ":" or "(". Otherwise only store words preceding ":".
        # After we've found our words we add them to varsFound and create a
        # jumbled replacement name for each one.
        if varDeclareFound:
            tmpList = re.findall("(?<=var.)\w+|(?<=function.)\w+|(?<=const.)\w+", newLine)

            for tmpLine in tmpList:
                # Skip over constructor name
                if tmpLine.find(fileName) == -1:
                    varsFound.append(tmpLine)
				
                # Create new variable name.
                # Keep searching until find a unique name consisting of an
                # underscore preceding a random number from 1-5000.
                newVarName = ""
                foundNewName = False
                while not foundNewName:
                    #newVarName = "_" + str(random.randrange(1,5000))
                    newVarName = "_"
                    newVarName += "".join(random.choice(varCharSet) for x in range(varLength))
                    if newVarName not in varsNew:
                        foundNewName = True
                varsNew.append(newVarName)

            # Reached a semicolon or open bracket and presumably end of
            # var/function/const declaration.
            if newLine.find(";") != -1 or newLine.find("{") != -1:
                varDeclareFound = False

    #========================================
    # Encode strings
    # Iterates over each character in string until a single or double
    # quote is found. If quote has not been escaped, then convert
    # following chars to their hex string equivalent until another quote
    # is found.
    if encodeStrings:
        tmpLine = ""
        inSingleQuote = False
        inDoubleQuote = False
        for x in range(0, len(newLine)):
            if newLine[x]=="\"" and not inSingleQuote:
                if x>0 and newLine[x-1]!="\\":
                    if inDoubleQuote:
                        inDoubleQuote = False
                    else:
                        inDoubleQuote = True
                    tmpLine += newLine[x]
                else:
                    tmpLine += string_to_hex( newLine[x] )
            elif newLine[x]=="\'" and not inDoubleQuote:
                if x>0 and newLine[x-1]!="\\":
                    if inSingleQuote:
                        inSingleQuote = False
                    else:
                        inSingleQuote = True
                    tmpLine += newLine[x]
                else:
                    tmpLine += string_to_hex( newLine[x] )
            else:
                if inDoubleQuote or inSingleQuote:
                    tmpLine += string_to_hex( newLine[x] )
                else:
                    tmpLine += newLine[x]
			
        newLine = tmpLine

    #========================================
    # Remove newlines and tabs
    if removeWhitespace:
        newLine = strip_white_space(newLine)

    #========================================
    # Change constructor to match new file name
    if changeFileName:
        tmpLine = re.sub(fileName, newFileName, newLine)
        if tmpLine != "":
            newLine = tmpLine

    #========================================
    # Replace line
    lineIndex = listLines.index(line)
    listLines.remove(line)
    listLines.insert(lineIndex, newLine)


#========================================
# Change Variable names
# Iterates over file again and attempts to replace all instances of
# variables previously found.
# TODO: Find less expensive way to implement.
if changeVarName:
    for line in listLines:
        newLine = line	
        # Attempt to find import at beginning of line
        tmpLine = strip_white_space(newLine)
        tmpIndex = tmpLine.find("import")
        if( tmpIndex!=0 ):
            for j in range(0, len(varsFound)):
                newLine = re.sub(r"\b"+varsFound[j]+r"\b", varsNew[j], newLine)
            lineIndex = listLines.index(line)
            listLines.remove(line)
            listLines.insert(lineIndex, newLine)


#========================================
# Write to file
#
#========================================
if changeFileName:
    fileToWrite = open(newFilePath, "w")
else:
    fileToWrite = open(filePath, "w")
for line in listLines:
    fileToWrite.write(line)

# Close file after writing
fileToWrite.close()