-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pwnlib.adb.bootimg for 'ANDROID!' format boot.img images
- Loading branch information
1 parent
1f8f294
commit 76413fc
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from __future__ import unicode_literals | ||
|
||
import ctypes | ||
import io | ||
import os | ||
import sys | ||
|
||
from pwnlib.log import getLogger | ||
|
||
log = getLogger(__name__) | ||
|
||
BOOT_MAGIC = b"ANDROID!" | ||
BOOT_MAGIC_SIZE = 8 | ||
BOOT_NAME_SIZE = 16 | ||
BOOT_ARGS_SIZE = 512 | ||
BOOT_EXTRA_ARGS_SIZE = 1024 | ||
|
||
|
||
class boot_img_hdr(ctypes.Structure): | ||
_fields_ = [ | ||
('magic', ctypes.c_char * BOOT_MAGIC_SIZE), | ||
|
||
('kernel_size', ctypes.c_uint32), | ||
('kernel_addr', ctypes.c_uint32), | ||
|
||
('ramdisk_size', ctypes.c_uint32), | ||
('ramdisk_addr', ctypes.c_uint32), | ||
|
||
('second_size', ctypes.c_uint32), | ||
('second_addr', ctypes.c_uint32), | ||
|
||
('tags_addr', ctypes.c_uint32), | ||
('page_size', ctypes.c_uint32), | ||
('unused', ctypes.c_uint32), | ||
|
||
('os_version', ctypes.c_uint32), | ||
|
||
('name', ctypes.c_char * BOOT_NAME_SIZE), | ||
('cmdline', ctypes.c_char * BOOT_ARGS_SIZE), | ||
('id', ctypes.c_char * 8), | ||
|
||
('extra_cmdline', ctypes.c_char * BOOT_EXTRA_ARGS_SIZE), | ||
] | ||
|
||
class BootImage(object): | ||
def __init__(self, data): | ||
self.data = data | ||
self.header = boot_img_hdr.from_buffer_copy(data) | ||
|
||
PAGE = self.header.page_size | ||
|
||
self.kernel = self.data[PAGE:PAGE+self.header.kernel_size] | ||
|
||
def __getattr__(self, name): | ||
value = getattr(self.header, name, None) | ||
if value is not None: | ||
return value | ||
return getattr(super(BootImage, self), name) |