├── scripts ├── __init__.py └── boot_image_extractor.py ├── requirements.txt ├── tests ├── __init__.py └── test_boot_image_extractor.py ├── setup.py ├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── LICENSE ├── SECURITY.md ├── .gitignore ├── README.md ├── CODE_OF_CONDUCT.md └── CONTRIBUTING.md /scripts/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyfiglet -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | # Add the parent directory to the system path 5 | sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | # BootImageExtractor Setup File 2 | # ----------------------------- 3 | # 4 | # Install with: pip install . 5 | # 6 | # Usage: sudo boot_image_extractor.py 7 | 8 | from setuptools import setup 9 | 10 | setup( 11 | name='Boot-Image-Extractor', 12 | description='A tool to extract boot images from Android devices with root access.', 13 | author='Abhijeet', 14 | url='https://github.com/gitclone-url/Boot-image-Extractor', 15 | scripts=['scripts/boot_image_extractor.py'], 16 | install_requires=[ 17 | 'pyfiglet', 18 | ], 19 | classifiers=[ 20 | 'Programming Language :: Python :: 3', 21 | 'License :: OSI Approved :: MIT License', 22 | 'Operating System :: Android', 23 | ], 24 | ) 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Abhijeet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy for Boot Image Extractor 2 | 3 | ## Reporting Security Vulnerabilities 4 | 5 | Reporting Potential Security Issues 6 | If you have encountered a potential security vulnerability in this project, please report it to us at [Telegram](https://t.me/PhantomXPain). We will work with you to verify the vulnerability and fix it. 7 | 8 | When reporting issues, please provide the following information: 9 | 10 | - **Subject:** Use "Security Vulnerability Report" as the subject line to ensure prompt attention. 11 | - **Include the following details:** 12 | - **Component(s) affected:** Specify the part(s) of the project where the vulnerability exists. 13 | - **Description:** Provide a clear description of the vulnerability, including steps to reproduce it. 14 | - **Security Impact:** Describe the potential impact of the vulnerability if exploited. 15 | 16 | We kindly request that you give us the opportunity to verify and resolve the issue before disclosing it publicly. This approach helps protect our users and allows them to update their installations promptly. 17 | 18 | ## Response Procedure 19 | 20 | Upon receiving a vulnerability report, we will take the following steps: 21 | 22 | - **Assessment:** We will assess the reported vulnerability to determine its severity and potential impact. 23 | - **Resolution:** Develop and implement appropriate fixes or patches to address the vulnerability. 24 | - **Communication:** Maintain open communication with the reporter throughout the resolution process. 25 | - **Release:** Once fixed, we will issue a new release and notify users through our communication channels. 26 | 27 | ## Contact Us 28 | 29 | For any questions or concerns regarding this security policy or to report a security vulnerability, please contact us at [Telegram](https://t.me/PhantomXPain). 30 | -------------------------------------------------------------------------------- /scripts/boot_image_extractor.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | """A script to extract boot images from any Android device with root access.""" 4 | 5 | import os 6 | import sys 7 | import time 8 | import pyfiglet 9 | import subprocess 10 | 11 | def print_banner(title): 12 | max_width = os.get_terminal_size().columns 13 | banner = pyfiglet.figlet_format(title, font='small', width=max_width) 14 | print(banner.center(max_width)) 15 | 16 | def exit_with_error(error_message, error_detail): 17 | print("\033[91m\nError:\033[0m", error_message) 18 | print("\nReason:", error_detail) 19 | sys.exit(1) 20 | 21 | def extract_boot_image_for_ab_device(boot_a_path, boot_b_path): 22 | active_slot_suffix = subprocess.getoutput('getprop ro.boot.slot_suffix') 23 | print(f"\n- Current active slot: ({active_slot_suffix}).") 24 | time.sleep(1) 25 | 26 | while True: 27 | selected_slot = input("- Which boot slot image would you like to extract? (a/b): ").lower() 28 | if selected_slot == 'a': 29 | boot_image_path = boot_a_path 30 | break 31 | elif selected_slot == 'b': 32 | boot_image_path = boot_b_path 33 | break 34 | else: 35 | print("Invalid input. Please enter 'a' or 'b'.\n") 36 | 37 | print(f"\n- Extracting the boot image from {boot_image_path}...") 38 | time.sleep(1) 39 | try: 40 | subprocess.check_call(['dd', f'if={boot_image_path}', f'of=./boot_{selected_slot}.img']) 41 | print(f"\033[92m\n- Boot image successfully extracted and saved as boot_{selected_slot}.img in the current directory.\033[0m") 42 | except subprocess.CalledProcessError: 43 | exit_with_error("Extraction failed", "The dd command did not complete successfully.") 44 | 45 | def extract_boot_image_for_legacy_device(boot_path): 46 | print(f"\n- Extracting the boot image from {boot_path}...") 47 | time.sleep(1) 48 | try: 49 | subprocess.check_call(['dd', f'if={boot_path}', 'of=./boot.img']) 50 | time.sleep(1) 51 | print("\033[92m\n- Boot image successfully extracted and saved as boot.img in the current directory.\033[0m") 52 | except subprocess.CalledProcessError: 53 | exit_with_error("Extraction failed", "The dd command did not complete successfully.") 54 | 55 | def main(): 56 | if os.geteuid() != 0: 57 | exit_with_error("Insufficient privileges", "This script requires root access. Please run as root or use sudo.") 58 | 59 | print_banner("Boot Image Extractor") 60 | time.sleep(1) 61 | 62 | boot_partitions = {} 63 | for partition in ["boot", "boot_a", "boot_b"]: 64 | partition_path = subprocess.getoutput(f"find /dev/block -type b -o -type l -iname '{partition}' -print -quit 2>/dev/null") 65 | if partition_path: 66 | boot_partitions[partition] = os.path.realpath(partition_path) 67 | 68 | if 'boot_a' in boot_partitions and 'boot_b' in boot_partitions: 69 | print("\n- A/B partition style detected!.") 70 | time.sleep(1) 71 | extract_boot_image_for_ab_device(boot_partitions['boot_a'], boot_partitions['boot_b']) 72 | elif 'boot' in boot_partitions: 73 | print("\n- Legacy(non-A/B) partition style detected!.") 74 | time.sleep(1) 75 | extract_boot_image_for_legacy_device(boot_partitions['boot']) 76 | else: 77 | exit_with_error("No boot partition found", "Unable to locate block device files.") 78 | 79 | if __name__ == '__main__': 80 | main() -------------------------------------------------------------------------------- /tests/test_boot_image_extractor.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from unittest.mock import patch, MagicMock 3 | 4 | from scripts.boot_image_extractor import ( 5 | print_banner, exit_with_error, extract_boot_image_for_legacy_device, 6 | extract_boot_image_for_ab_device, main 7 | ) 8 | 9 | class TestBootImageExtractor(unittest.TestCase): 10 | """Provides unit tests for the Boot Image Extractor script to ensure its proper functionality 11 | in various scenarios. Additional test cases can be added to improve test coverage.""" 12 | 13 | def infinite_side_effect(self, *values): 14 | while True: 15 | for value in values: 16 | yield value 17 | 18 | @patch('builtins.print') 19 | def test_print_banner(self, mock_print): 20 | print_banner("Test Banner") 21 | mock_print.assert_called() 22 | 23 | @patch('builtins.print') 24 | @patch('subprocess.getoutput') 25 | @patch('os.geteuid', MagicMock(return_value=0)) 26 | def test_extract_boot_image_for_legacy_device(self, mock_getoutput, mock_print): 27 | mock_getoutput.return_value = '/dev/block/boot' 28 | with patch('subprocess.check_call', MagicMock()) as mock_check_call: 29 | extract_boot_image_for_legacy_device('/dev/block/boot') 30 | mock_check_call.assert_called_with(['dd', 'if=/dev/block/boot', 'of=./boot.img']) 31 | 32 | @patch('builtins.print') 33 | @patch('subprocess.getoutput') 34 | @patch('os.geteuid', MagicMock(return_value=0)) 35 | @patch('builtins.input', return_value='a') 36 | def test_extract_boot_image_for_ab_device(self, mock_input, mock_getoutput, mock_print): 37 | mock_getoutput.side_effect = ['_a', 'a'] 38 | with patch('subprocess.check_call', MagicMock()) as mock_check_call: 39 | extract_boot_image_for_ab_device('/dev/block/boot_a', '/dev/block/boot_b') 40 | mock_check_call.assert_called_with(['dd', 'if=/dev/block/boot_a', 'of=./boot_a.img']) 41 | 42 | @patch('os.geteuid', MagicMock(return_value=0)) 43 | @patch('subprocess.getoutput', return_value='') 44 | @patch('scripts.boot_image_extractor.print_banner', MagicMock()) 45 | @patch('scripts.boot_image_extractor.exit_with_error') 46 | def test_main_no_boot_partition_found(self, mock_exit_with_error, mock_getoutput): 47 | main() 48 | mock_exit_with_error.assert_called_with("No boot partition found", "Unable to locate block device files.") 49 | 50 | @patch('os.geteuid', MagicMock(return_value=0)) 51 | @patch('subprocess.getoutput') 52 | @patch('builtins.print') 53 | def test_main_legacy_partition_style(self, mock_print, mock_getoutput): 54 | mock_getoutput.side_effect = ['/dev/block/boot', '', ''] 55 | with patch('subprocess.check_call', MagicMock()) as mock_check_call: 56 | main() 57 | mock_print.assert_any_call("\n- Legacy(non-A/B) partition style detected!.") 58 | mock_check_call.assert_called_with(['dd', 'if=/dev/block/boot', 'of=./boot.img']) 59 | 60 | @patch('os.geteuid', MagicMock(return_value=0)) 61 | @patch('subprocess.getoutput') 62 | @patch('builtins.print') 63 | @patch('builtins.input', return_value='a') 64 | def test_main_ab_partition_style(self, mock_input, mock_print, mock_getoutput): 65 | # Set the side_effect to our infinite_side_effect function 66 | mock_getoutput.side_effect = self.infinite_side_effect('_a', '/dev/block/boot_a', '/dev/block/boot_b') 67 | with patch('subprocess.check_call', MagicMock()) as mock_check_call: 68 | main() 69 | mock_print.assert_any_call("\n- A/B partition style detected!.") 70 | mock_check_call.assert_called_with(['dd', 'if=/dev/block/boot_a', 'of=./boot_a.img']) 71 | 72 | if __name__ == '__main__': 73 | unittest.main() 74 | 75 | -------------------------------------------------------------------------------- /.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 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |