gpt4 book ai didi

ios - 是否可以混淆UIViewAlertForUnsatisfiableConstraints?

转载 作者:行者123 更新时间:2023-12-01 18:10:21 28 4
gpt4 key购买 nike

我想知道UIViewAlertForUnsatisfiableConstraints是否是我可以选择的选择器。到目前为止,我所知道的只是UIViewAlertForUnsatisfiableConstraints是一种可以用来放置符号断点的符号。但是我在任何公开课上都找不到这个符号。有人知道它在哪里吗?

请注意,我希望在单元测试中而不是在生产代码中执行此操作。

最佳答案

因为UIViewAlertForUnsatisfiableConstraints是C函数,所以混淆它比典型的Objective C方法需要更多的工作。

最简单的方法(大多数消息人士说这是唯一可能的方法)是通过Substrate的MSHookFunction进行的,但是这需要越狱的手机。如果这是一个有效的选项,我建议您使用它来简单地钩住函数。

在非越狱环境中,需要高级运行时操作。出于某种原因,我真的很喜欢浪费时间学习即将成为死语的语言..所以这里是完整的解决方案!这个link提供了巨大的帮助。

#import <dlfcn.h>
#import <objc/runtime.h>
#include <sys/mman.h>

int64_t originalOffset;
int64_t *origFunc;

void swizzled_UIViewAlertForUnsatisfiableConstraints(NSLayoutConstraint *offendingConstraint, NSArray *allConstraints) {
// inject swizzle code here
NSLog(@"swizzled!");

// call the original function (if you want!)
if (origFunc) {
// replace jump instruction w/ the original memory offset
*origFunc = originalOffset;
((void(*)(NSLayoutConstraint*, NSArray*))origFunc)(offendingConstraint, allConstraints);
}
}

static inline BOOL swizzleAlertForUnsatisfiableConstraints() {

// get the original function and hold onto it's memory offset
origFunc = dlsym(RTLD_DEFAULT, "UIViewAlertForUnsatisfiableConstraints");
if (!origFunc) {
return NO;
}
originalOffset = *origFunc;

// define the swizzled implementation
int64_t *swizzledFunc = (int64_t*)&swizzled_UIViewAlertForUnsatisfiableConstraints;

// make the memory containing the original funcion writable
size_t pageSize = sysconf(_SC_PAGESIZE);
uintptr_t start = (uintptr_t)origFunc;
uintptr_t end = start + 1;
uintptr_t pageStart = start & -pageSize;
mprotect((void *)pageStart, end - pageStart, PROT_READ | PROT_WRITE | PROT_EXEC);

//Calculate the relative offset needed for the jump instruction
//Since relative jumps are calculated from the address of the next instruction,
// 5 bytes must be added to the original address (jump instruction is 5 bytes)
int64_t offset = (int64_t)swizzledFunc - ((int64_t)origFunc + 5 * sizeof(char));

//Set the first instruction of the original function to be a jump
// to the replacement function.
//E9 is the x86 opcode for an unconditional relative jump
int64_t instruction = 0xe9 | offset << 8;
*origFunc = instruction;

return YES;
}

关于ios - 是否可以混淆UIViewAlertForUnsatisfiableConstraints?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32671327/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com