vector<uint64_t> search_svc_from_asm(void
*
file_buf, vector<string> asmStrArray)
{
vector<uint64_t> resultVec;
/
/
声明一个
int
型向量
vector<struct section_64 const
*
> sectionArray
=
gain_sections(file_buf);
if
(sectionArray.size()<
1
){
NSLog(@
"找不到代码段--3"
);
return
resultVec;
}
for
(
int
i
=
0
; i<sectionArray.size(); i
+
+
){
struct section_64 const
*
sectionTxt
=
sectionArray[i];
/
/
展示 Section64_Header中的 offset 和 size
uint64_t offset
=
sectionTxt
-
>offset;
uint64_t text_size
=
sectionTxt
-
>size;
int
tmp_length
=
4
;
/
/
单条汇编所占内存
/
/
反汇编
Disasm
*
disasm
=
[[Disasm alloc] init];
uint32_t my_offset
=
(uint32_t)
0
;
uint64_t my_addr
=
(uint64_t)offset;
uint32_t my_size
=
0x640
;
/
/
400
条
int
asmStrCount
=
(
int
)asmStrArray.size();
while
(
1
){
my_size
=
0x640
;
if
(my_offset
=
=
0
){
my_offset
=
(uint32_t)offset;
}
else
{
my_offset
=
my_offset
+
my_size
-
(asmStrCount
-
1
)
*
tmp_length;
}
if
(my_offset < text_size
+
offset && my_offset
+
my_size > text_size
+
offset)
{
my_size
=
(uint32_t)(text_size
+
offset
-
my_offset);
}
else
if
(my_offset>text_size
+
offset){
break
;
}
NSArray
*
asmArrayTmp
=
[disasm disAsmWithBuff:file_buf offset:my_offset size:my_size addr:(uint64_t)my_addr];
int
count
=
(
int
)[asmArrayTmp count];
uint64_t first_addr
=
(uint32_t)my_offset;
int
samecount
=
0
;
for
(
int
i
=
0
; i<count; i
+
+
){
NSString
*
curAsm
=
[asmArrayTmp objectAtIndex:i];
for
(
int
j
=
0
; j<asmStrCount; j
+
+
){
if
(j
=
=
samecount){
NSString
*
strTmp
=
[NSString stringWithCString:(asmStrArray[j]).c_str() encoding:NSUTF8StringEncoding];
if
([strTmp isEqualToString:curAsm])
{
samecount
=
samecount
+
1
;
break
;
}
else
{
samecount
=
0
;
break
;
}
}
}
if
(samecount
=
=
asmStrCount){
uint64_t target_addr
=
(uint64_t)(first_addr
+
i
*
4
);
NSLog(@
"查找到svc调用反动态调试:0x%lx %@"
, target_addr, curAsm);
resultVec.push_back(target_addr);
break
;
}
}
}
}
return
resultVec;
}