-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvmExtract.py
More file actions
40 lines (30 loc) · 996 Bytes
/
vmExtract.py
File metadata and controls
40 lines (30 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
栈式虚拟机入口特征:
1、栈提升: sub sp, #xxx
2、寄存器环境保存: 连续的stp或者str
"""
from typing import List
from unidbgTraceParser import InstructionInfo
def extractVMCode(instInfo_list: List[InstructionInfo]):
"""
删除栈式虚拟机入口特征和出口特征,仅保留正文
:param instInfo_list:
:return:
"""
# 假定头尾对称式 sub stp stp ... ... ldp ldp add 额外一个 ret
first_inst = instInfo_list[0]
if not first_inst.inst_str.startswith("sub sp"):
return instInfo_list
count = 1
while 1:
inst = instInfo_list[count]
if inst.inst_str.startswith("stp"):
count += 1
else:
break
start = count
end = len(instInfo_list) - (count + 1)
instInfo_list = instInfo_list[start: end]
# print(instInfo_list[0].inst_str)
# print(instInfo_list[-1].inst_str)
return instInfo_list