Skip to content

Instantly share code, notes, and snippets.

@AngheloAlf
Created December 15, 2018 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AngheloAlf/9966498dfa08f140c2665bcd0cc349ce to your computer and use it in GitHub Desktop.
Save AngheloAlf/9966498dfa08f140c2665bcd0cc349ce to your computer and use it in GitHub Desktop.
Script to parse a [flare](http://www.nowrap.de/flare.html) decompiled swf into a json file.
#!/usr/bin/python3
import json
import os
import sys
import codecs
import io
class ShowPercent:
def __init__(self, full_size, step=5.0):
self.full_size = full_size
self.next_percent = step
self.step = step
def show(self, size_counter):
new_percent = 100.0 * size_counter / self.full_size
if new_percent >= self.next_percent:
print(str(round(new_percent, 2)) + "%")
self.next_percent += self.step
def flr_to_json(in_file, out_file, indent=2):
flr_file = codecs.open(in_file, encoding="utf-8")
dic = dict()
sp = ShowPercent(os.path.getsize(in_file))
size_counter = 0.0
TOKEN = " = new "
# needed for eval
true = True
null = None
false = False
for line in flr_file:
if TOKEN in line:
key = line.strip().split(TOKEN)[0]
dic[key] = dict()
else:
if " = " in line.strip():
key, value = line.strip().split(" = ")
if "[" not in key:
print("ERROR:", line)
print("\t skiping")
continue
var, i = key.split("[")
i = i.split("]")[0]
if "'" not in i and '"' not in i:
i = int(i)
if var in dic:
dic[var][i] = eval(value[:-1]) # [:-1] removes semicolon
else:
print("ERROR:", line)
print("\t skiping")
continue
size_counter += len(line)
sp.show(size_counter)
flr_file.close()
with io.open(out_file, "w", encoding="utf8") as json_file:
json.dumps(dic, json_file, ensure_ascii=False, indent=indent)
return dic
def main(argv):
if len(argv) < 3:
print("Usage:", argv[0], "input_file output_file <indent=2>")
exit(-1)
in_file = argv[1]
out_file = argv[2]
if len(argv) > 3:
indent = int(argv[3])
flr_to_json(in_file, out_file, indent)
else:
flr_to_json(in_file, out_file)
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment