Skip to content

Commit

Permalink
Enable UIDevice to get device info (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
sledgeh4w authored May 3, 2024
1 parent 60a8db5 commit 10875d5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
7 changes: 0 additions & 7 deletions examples/example_ios_ali_vmp_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ def hook_ns_bundle(emu):
emu.add_interceptor("-[NSBundle infoDictionary]", hook_retval(pyobj2nsobj(emu, bundle_info)))


def hook_ui_device(emu):
emu.add_interceptor("-[UIDevice systemVersion]", hook_retval(pyobj2nsobj(emu, "14.4.0")))
emu.add_interceptor("-[UIDevice name]", hook_retval(pyobj2nsobj(emu, "iPhone")))
emu.add_interceptor("-[UIDevice model]", hook_retval(pyobj2nsobj(emu, "iPhone13,1")))


def main():
emu = Chomper(
arch=ARCH_ARM64,
Expand All @@ -61,7 +55,6 @@ def main():
objc = ObjC(emu)

hook_ns_bundle(emu)
hook_ui_device(emu)

# Skip a file operation
emu.add_interceptor("_fopen", hook_retval(0))
Expand Down
7 changes: 0 additions & 7 deletions examples/example_ios_bangbang.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ def hook_sec_item(emu):
emu.add_interceptor("_CFRelease", hook_retval(0))


def hook_ui_device(emu):
emu.add_interceptor("-[UIDevice systemVersion]", hook_retval(pyobj2nsobj(emu, "14.4.0")))
emu.add_interceptor("-[UIDevice name]", hook_retval(pyobj2nsobj(emu, "iPhone")))
emu.add_interceptor("-[UIDevice model]", hook_retval(pyobj2nsobj(emu, "iPhone13,1")))


def main():
emu = Chomper(
arch=ARCH_ARM64,
Expand All @@ -48,7 +42,6 @@ def main():
objc = ObjC(emu)

hook_sec_item(emu)
hook_ui_device(emu)

emu.load_module(os.path.join(base_path, "ios/apps/com.ceair.b2m/ceair_iOS_branch"))

Expand Down
18 changes: 17 additions & 1 deletion src/chomper/os/ios/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from unicorn.unicorn import UC_HOOK_CODE_TYPE

from chomper.utils import pyobj2nsobj
from chomper.objc import ObjC

hooks: Dict[str, UC_HOOK_CODE_TYPE] = {}

Expand Down Expand Up @@ -431,13 +432,28 @@ def hook_os_log_type_enabled(uc, address, size, user_data):
return 0


@register_hook("_MGCopyAnswer")
def hook_mg_copy_answer(uc, address, size, user_data):
emu = user_data["emu"]
objc = ObjC(emu)

str_ptr = objc.msg_send(emu.get_arg(0), "cStringUsingEncoding:", 4)
key = emu.read_string(str_ptr)

if key in emu.os.device_info:
return pyobj2nsobj(emu, emu.os.device_info[key])

return 0


@register_hook("__CFPreferencesCopyAppValueWithContainerAndConfiguration")
def hook_cf_preferences_copy_app_value_with_container_and_configuration(
uc, address, size, user_data
):
emu = user_data["emu"]
objc = ObjC(emu)

str_ptr = emu.read_pointer(emu.get_arg(0) + 0x10)
str_ptr = objc.msg_send(emu.get_arg(0), "cStringUsingEncoding:", 4)
key = emu.read_string(str_ptr)

if key in emu.os.preferences:
Expand Down
18 changes: 14 additions & 4 deletions src/chomper/os/ios/os.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ def __init__(self, emu, **kwargs):

self.loader = MachoLoader(emu)

# By hooking functions:
# `__CFPreferencesCopyAppValueWithContainerAndConfiguration`,
# `___CFXPreferencesCopyCurrentApplicationStateWithDeadlockAvoidance`,
# enable the program to obtain preferences.
# By hooking CF preferences related functions,
# enable the program to get preferences.
self.preferences = self._default_preferences.copy()

# By hooking `_MGCopyAnswer`, enable `UIDevice` to get device info.
self.device_info = self._default_device_info.copy()

@property
def _default_preferences(self) -> dict:
"""Define default preferences."""
Expand All @@ -38,6 +39,15 @@ def _default_preferences(self) -> dict:
"AppleLocale": "zh-Hans",
}

@property
def _default_device_info(self) -> dict:
"""Define default device info."""
return {
"UserAssignedDeviceName": "iPhone",
"DeviceName": "iPhone13,1",
"ProductVersion": "14.4.0",
}

def _setup_hooks(self):
"""Initialize the hooks."""
self.emu.hooks.update(get_hooks())
Expand Down

0 comments on commit 10875d5

Please sign in to comment.