├── .gitignore ├── README.md └── flutter_extractor.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flutter_extractor 2 | Extracting strings and function names from Flutter apks, based on this blogpost - https://medium.com/@rondalal54/reverse-engineering-flutter-apps-5d620bb105c0 3 | 4 | ## Usage 5 | ``` 6 | flutter_extractor.py [OPTIONS] APP_PATH 7 | 8 | app_path: path to the extracted apk directory (the output directory of the apktool) 9 | 10 | Options: 11 | --out TEXT The output dir 12 | --help Show this message and exit. 13 | ``` 14 | **Please use [ApkTool](https://ibotpeaches.github.io/Apktool/) or jadx** before running the extractor. Due to the fact that APKs are somewhat a zip file, there's need to extract the files first, for the extractor to use them. 15 | 16 | ## Example 17 | ```python flutter_extractor.py /path/to/extracted_apk/ --out ./flutter_data``` 18 | -------------------------------------------------------------------------------- /flutter_extractor.py: -------------------------------------------------------------------------------- 1 | import click 2 | import subprocess 3 | import os 4 | import re 5 | 6 | # Could be changed due to changes in the Flutter engine 7 | DATA_FILE = "isolate_snapshot_data" 8 | POSSIBLE_DATA_TYPES = [{"type": "functions", 9 | "pattern":b"([a-zA-Z_]{1}\w+)@[0-9]+", 10 | "filename": "functions"}, 11 | {"type": "strings", # including functions 12 | "pattern":b"[\w]{4,}", 13 | "filename": "strings"}] 14 | 15 | def get_data_from_snapshot(app_path): 16 | data_path = os.path.join(app_path, "assets", "flutter_assets", DATA_FILE) 17 | data = "" 18 | 19 | with open(data_path, 'rb') as data_file_handle: 20 | data = data_file_handle.read() 21 | 22 | return data 23 | 24 | def extract_by_pattern_to_file(data, pattern, out_path): 25 | extracted_strings = set(re.findall(pattern, data)) # using set() to remove duplicates 26 | extracted_strings = b"\n".join(extracted_strings) 27 | 28 | click.echo("Writing to %s" % out_path) 29 | with open(out_path, "wb") as file_handle: 30 | file_handle.write(extracted_strings) 31 | 32 | def mkdir_if_not_exist(directory): 33 | if not os.path.exists(directory): 34 | os.makedirs(directory) 35 | 36 | @click.command() 37 | @click.option('--out', default="./flutter_data", help='The output dir') 38 | @click.argument('app_path') 39 | def main(app_path, out): 40 | """app_path: path to the extracted apk directory (for example - output directory of the apktool)""" 41 | mkdir_if_not_exist(out) 42 | 43 | click.echo("Reading from the isolate data file...") 44 | data = get_data_from_snapshot(app_path) 45 | 46 | for data_type in POSSIBLE_DATA_TYPES: 47 | out_path = os.path.join(out, data_type["filename"]) 48 | extract_by_pattern_to_file(data, data_type["pattern"], out_path) 49 | 50 | if __name__ == '__main__': 51 | main() 52 | --------------------------------------------------------------------------------