void adc_main() {
printf(
"Start to calc kbsync.\n"
);
auto KeybagSyncOperation
=
NSClassFromString(@
"KeybagSyncOperation"
);
printf(
"Get KeybagSyncOperation class: %p.\n"
, KeybagSyncOperation);
auto method
=
class_getInstanceMethod(KeybagSyncOperation,
NSSelectorFromString(@
"run"
));
printf(
"Get run method: %p.\n"
, method);
auto imp
=
method_getImplementation(method);
printf(
"Get run implementation: %p.\n"
, imp);
const uint32_t
*
kbsync_caller
=
(uint32_t
*
)imp;
const uint8_t mov_w1_0xb[]
=
{
0x61
,
0x01
,
0x80
,
0x52
};
while
(
*
kbsync_caller
+
+
!
=
*
(uint32_t
*
)&mov_w1_0xb[
0
]);
printf(
"Parsed kbsync caller: %p.\n"
, kbsync_caller);
/
/
decode the bl instruction to get the real kbsyn callee
/
/
31
30
29
28
27
26
25
...
0
/
/
1
0
0
1
0
1
-
imm
-
int
blopcode
=
*
(
int
*
)kbsync_caller;
int
blmask
=
0xFC000000
;
if
(blopcode & (
1
<<
26
)) {
/
/
sign extend
blopcode |
=
blmask;
}
else
{
blopcode &
=
~blmask;
}
long
kbsync_entry
=
(
long
)kbsync_caller
+
(blopcode <<
2
);
printf(
"Decoded kbsync entry: 0x%lx.\n"
, kbsync_entry);
/
/
call the kbsync calc entry
NSData
*
kbsync
=
((NSData
*
(
*
)(
long
,
int
))kbsync_entry)(
1111
,
0xB
);
/
/
send result to our python callback
if
(kbsync) {
str2py(
"kbsync_result_callback"
, [kbsync base64EncodedStringWithOptions:
0
].UTF8String,
0
);
}
else
{
str2py(
"kbsync_result_callback"
,
"error, you should download something in the AppStore to init kbsync."
,
0
);
}
printf(
"Finished calc kbsync.\n"
);
}