-
Notifications
You must be signed in to change notification settings - Fork 31
/
16_输入与输出.py
71 lines (56 loc) · 1.91 KB
/
16_输入与输出.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#coding=utf-8
import sys
import idc
import idaapi
import idautils
class IO_DATA():
def __init__(self):
self.start = idc.SelStart()
self.end = idc.SelEnd()
self.buffer = ''
self.ogLen = None
self.status = True
self.run()
def checkBounds(self):
if self.start is idc.BADADDR or self.end is idc.BADADDR:
self.status = False
def getData(self):
#获取起始地址和结束地址之间的数据,并将它们存入object.buffer中
self.ogLen = self.end - self.start
self.buffer = ''
try:
for byte in idc.GetManyBytes(self.start, self.ogLen):
self.buffer = self.buffer + byte
except:
self.start = False
return
def run(self):
#主要功能
self.checkBounds()
if self.status == False:
sys.stdout.write('ERROR:Please select valid data\n')
return
self.getData()
def patch(self, temp = None):
#用object.buffer中的数据给idb打补丁
if temp != None:
self.buffer = temp
for index,byte in enumerate(self.buffer):
idc.PatchByte(self.start + index, ord(byte))
def importb(self):
#将文件中的内容导入到buffer中
fileName = idc.AskFile(0, "*.*", 'Import File')
try:
self.buffer = open(fileName, 'rb').read()
except:
sys.stdout.write('ERROR:Cannot access file')
def export(self):
#将所选择的buffer保存到文件
exportFile = idc.AskFile(1, "*.*", "Export Buffer")
f = open(exportFile, 'wb')
f.write(self.buffer)
f.close()
def stats(self):
print "start: %s" % hex(self.start)
print "end: %s" % hex(self.end)
print "len: %s" % hex(len(self.buffer))