Closed Yiiff closed 7 months ago
What is your final target? It is possible to create an NSURLRequest
object, but chomper currently does not support networking, so you cannot actually send a network request at this time.
Regarding this exception, it was raised by function _os_variant_allows_internal_security_policie
and the function depend on a sysctl command kern.osvariant_status
(chomper not handled this scene correctly). The simplest solution is to add hook to the function and make it return 1
direct. For the handling of kern.osvariant_status
, I will fix it later.
emu.add_interceptor("_os_variant_allows_internal_security_policies", hook_retval(1))
In addition, there is an little error in your second case: initWithString:
-> initWithURL:
(This is also the part currently lacking in chomper, friendly error prompts).
What is your final target? It is possible to create an
NSURLRequest
object, but chomper currently does not support networking, so you cannot actually send a network request at this time.Regarding this exception, it was raised by function
_os_variant_allows_internal_security_policie
and the function depend on a sysctl commandkern.osvariant_status
(chomper not handled this scene correctly). The simplest solution is to add hook to the function and make it return1
direct. For the handling ofkern.osvariant_status
, I will fix it later.emu.add_interceptor("_os_variant_allows_internal_security_policies", hook_retval(1))
In addition, there is an little error in your second case:
initWithString:
->initWithURL:
(This is also the part currently lacking in chomper, friendly error prompts).
My ultimate goal is not to complete the network request, but the function to be hooked has an input parameter of type NSURLRequest, so I need to construct this object to complete the function call.
The error you mentioned has been fixed. Thank you. It was indeed my oversight. The current error prompts is indeed not very convenient. It takes some time to analyze.
I took your advice, but I still can't create an NSURLRequest object
I suspect it's because one of the input parameters of NSURLRequest is NSURL, and I have a problem passing the NSURL object directly
Additionally, there is no problem creating NSDictionary, NSString, NSArray, NSURL and other classes.
Strange, I tested your code and there were no errors. Can you post your whole code?
Strange, I tested your code and there were no errors. Can you post your whole code?
Sure, this is my py file
import logging
import os
from chomper.core import Chomper
from chomper.const import ARCH_ARM64, OS_IOS
from chomper.os.ios.options import IosOptions
base_path = os.path.abspath(os.path.dirname(__file__))
log_format = "%(asctime)s - %(name)s - %(levelname)s: %(message)s"
logging.basicConfig(
format=log_format,
level=logging.INFO,
)
logger = logging.getLogger(__name__)
def create_emulator():
options = IosOptions(enable_objc=True, enable_ui_kit=True)
emu = Chomper(
arch=ARCH_ARM64,
os_type=OS_IOS,
logger=logger,
rootfs_path=os.path.join(base_path, "ios/rootfs"),
os_options=options,
)
return emu
def objc_get_class(emu, class_name):
return emu.call_symbol("_objc_getClass", emu.create_string(class_name))
def objc_sel_register_name(emu, sel_name):
return emu.call_symbol("_sel_registerName", emu.create_string(sel_name))
def create_ns_string(emu, s):
ns_string_class = objc_get_class(emu, "NSString")
string_with_utf8_string_sel = objc_sel_register_name(emu, "stringWithUTF8String:")
obj = emu.call_symbol(
"_objc_msgSend",
ns_string_class,
string_with_utf8_string_sel,
emu.create_string(s),
)
return obj
def read_ns_string(emu, obj):
c_string_using_encoding_sel = objc_sel_register_name(emu, "cStringUsingEncoding:")
ptr = emu.call_symbol("_objc_msgSend", obj, c_string_using_encoding_sel, 4)
return emu.read_string(ptr)
def create_ns_url(emu, s):
cls = objc_get_class(emu, "NSURL")
alloc_sel = objc_sel_register_name(emu, "alloc")
init_sel = objc_sel_register_name(emu, "initWithString:")
space = emu.call_symbol("_objc_msgSend", cls, alloc_sel)
return emu.call_symbol("_objc_msgSend", space, init_sel, create_ns_string(emu, s))
def create_ns_mutable_url_request(emu, s):
ns_url_obj = create_ns_url(emu, s)
cls = objc_get_class(emu, class_name="NSURLRequest")
sel = objc_sel_register_name(emu, "requestWithURL:")
req_obj = emu.call_symbol("_objc_msgSend", cls, sel, ns_url_obj)
emu.add_interceptor("_os_variant_allows_internal_security_policies", hook_retval(1))
return req_obj
def hook_retval(retval):
def decorator(uc, address, size, user_data):
return retval
return decorator
def hook_sec_item(emu):
emu.add_interceptor("_SecItemCopyMatching", hook_retval(0))
emu.add_interceptor("_SecItemUpdate", hook_retval(0))
emu.add_interceptor("_CFRelease", hook_retval(0))
def main():
emu = create_emulator()
hook_sec_item(emu)
emu.load_module(module_file=os.path.join(base_path, "ios/apps/com.xxx.xx/target"))
logger.info("[Test] exec load")
url_str = "https://www.test.com"
url_obj = create_ns_mutable_url_request(emu, s=url_str)
logger.info("[Test] finish.")
if __name__ == "__main__":
logger.info("[Test] launch")
main()
You should add the hook before create object, just like hook_sec_item
.
You should add the hook before create object, just like
hook_sec_item
.
Thank you for your support. I will try it. I copied hook_sec_item from the demo. I don't really understand its function. So I kept it in the code.
But your description gave me a new question. If I don't hook, can't I use the calling class directly?
You should add the hook before create object, just like
hook_sec_item
.
I understand what you mean by hook, but I don't understand what to hook. For example, I need to actively call NSURLRequest and construct an object to pass parameters, so I need to hook NSURLRequest in advance?
Although it's a bit embarrassing because I haven't figured it out, can you provide your code that works? Then I want to study where I went wrong.
What I mean is:
emu.add_interceptor("_os_variant_allows_internal_security_policies", hook_retval(1))
create_ns_mutable_url_request(emu, s=url_str)
What I mean is:
emu.add_interceptor("_os_variant_allows_internal_security_policies", hook_retval(1)) create_ns_mutable_url_request(emu, s=url_str)
I understand it wrongly, the problem is solved, thank you
Crash with creating
NSURLRequest
object.The reference code is:
Code1:
Code2:
The crash happens on this line:
Error Log: