import
sys
import
traceback
import
idc
from PySide
import
QtGui
from PySide
import
QtCore
from PySide.QtCore
import
Qt
def addstruc(name,size):
id
=AddStrucEx(-1,name,0)
AddStrucMember(
id
,
"vtbl"
,0,0x20000400,-1,4)
i=4
length=size-1
for
i
in
range(length):
AddStrucMember(
id
,
"field_"
+str(hex(i))[2:].upper(),i,FF_DWRD,-1,4)
print
"Done"
class MakeUserStruct(QtGui.QDialog):
def on_ok_button(self):
self.
done
(QtGui.QDialog.Accepted)
name=self.nameText.text()
size=self.sizeText.text()
addstruc(name.encode(
"ascii"
),int(size.encode(
"ascii"
)))
idaapi.set_script_timeout(0)
def populate_form(self):
layout=QtGui.QVBoxLayout()
strinfo=
"this plugin will help you create a struct"
layout.addWidget(QtGui.QLabel(strinfo))
stlayout=QtGui.QHBoxLayout()
self.nameText=QtGui.QLineEdit()
self.nameText.setReadOnly(False)
stlayout.addWidget(self.nameText)
self.sizeText=QtGui.QLineEdit()
self.sizeText.setReadOnly(False)
stlayout.addWidget(self.sizeText)
groupBox=QtGui.QGroupBox(
"please input name && size"
)
groupBox.setLayout(stlayout)
layout.addWidget(groupBox)
buttonOk=QtGui.QPushButton(
"&OK"
)
buttonOk.setDefault(True)
buttonOk.clicked.connect(self.on_ok_button)
layout.addWidget(buttonOk)
buttonCel=QtGui.QPushButton(
"&Cancel"
)
buttonCel.clicked.connect(self.on_ok_button)
layout.addWidget(buttonCel)
hlayout=QtGui.QHBoxLayout()
hlayout.addLayout(layout)
self.setLayout(hlayout)
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
self.setWindowTitle(
"Make User Struct"
)
self.populate_form()
if
__name__ ==
'__main__'
:
dlg = MakeUserStruct()
t = idaapi.set_script_timeout(0)
dlg.exec_()
idaapi.set_script_timeout(t)