当我尝试使用下面的代码进行编译时,我收到以下错误。我不知道如何解决它。我用Google搜索了。也问其他人,但没有人能够帮助我。 通过theos在mac上编译。 如果有人可以帮助我,我将非常感激。
错误输出
error: assigning to
'kern_return_t' (aka 'int') from incompatible type 'uint *'
(aka 'unsigned int *')
err = reinterpret_cast<uint *>(address* sizeof(data));
代码
bool writeData(vm_address_t address, string str) {
//declaring variables
kern_return_t err = 0;
mach_port_t port = mach_task_self();
size_t find = str.find("0x");
if (find != -1) {
str.replace(find, 2, "");
}
int len = str.size();
char data[len / 2];
int x = 0;
for(int i = 0; i < len; i += 2) {
string dat = str.substr(i, 2);
uint8_t tmp;
sscanf(dat.c_str(), "%hhx", &tmp);
data[x] = tmp;
x++;
}
//set memory protections to allow us writing code there
err = vm_protect(port, (vm_address_t)address, sizeof(data), NO, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_COPY);
//check if the protection fails
if (err != KERN_SUCCESS)
return FALSE;
//write code to memory
err = reinterpret_cast<uint64_t *>(address* sizeof(data));
if (err != KERN_SUCCESS)
return FALSE;
//set the protections back to normal so the app can access this address as usual
err = vm_protect(port, (vm_address_t)address, sizeof(data), NO, VM_PROT_READ | VM_PROT_EXECUTE);
if (err != KERN_SUCCESS)
return FALSE;
return TRUE;
}