Giter VIP home page Giter VIP logo

samsung-patcher's Introduction

Samsung Patcher

This piece of software allows you to patch a samsung kernel binary WITHOUT SOURCES.

The binary takes in two files: a kernel ELF (For more info on this, read Using this tool) as well as a patch object file.

The patch object file used in this case was kernel_patch/patch.o. This file can be generated via running make all in kernel_patch. Note that the aarch64-linux-gnu-* toolchain is required.

This patch (Found in patch.S) modifies el0_svc to provide full kernel read, write, and execute.

To choose what function the patch is applied to modify FUNCTION_TO_APPLY_PATCH in the main.rs.

Using this tool

The kernel ELF can be obtained by obtaining the boot.img file (Usually included in firmware upgrades) and running unpack_bootimg.py (Found here: https://android.googlesource.com/platform/system/tools/mkbootimg/+/refs/heads/main). Make sure to run unpack_bootimg.py with --format mkbootimg flag as that will output the arguments needed to roll back the kernel into a new boot.img file.

Once you have run unpack_bootimg.py the output folder should have a file called kernel. That is your kernel image.

From here, download vmlinux-to-elf (Found here: https://github.com/marin-m/vmlinux-to-elf) and run vmlinux-to-elf on the kernel binary. This should output a ELF file. This is your kernel ELF.

From here run cargo run [elf file] [patch file] to obtain a new kernel image. There will be two output files. The first is patched_vmlinux and the second will be patched_kernel. The patched_vmlinux can be used for debugging purposes to see if your patch actually applied properly and patched_kernel can be used to roll back into a boot image.

To roll it back into a boot image run mkbootimg.py along with the arguments you got from --format mkbootimg (Make sure to replace the kernel flag with patched_kernel as well as supply an output file).

Internals

The core of this tool is that vmlinux-to-elf simply prepends a ELF header to the file as well as appends symbol information. So, we can simply take our ELF, apply the patches, and chop off the ELF header to get our boot image back. This resulting image is perfectly bootable (The phone does not care about the symbol info at the end).

samsung-patcher's People

Contributors

mineo333 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.