Skip to content

Commit

Permalink
[FEATURE] Added support for TAG files (Issue #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed Jul 31, 2018
1 parent a5d23ed commit 2a3bd01
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions ifl.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,13 +812,16 @@ def _listFunctionsAddr(self):
fn_list.append(start)
return fn_list

def _saveFunctionsNames(self, file_name):
"""Saves functions names and offsets from the internal mappings into a CSV file.
def _saveFunctionsNames(self, file_name, ext):
"""Saves functions names and offsets from the internal mappings into a file.
Fromats: CSV (default), or TAG (PE-bear, PE-sieve compatibile).
"""

if file_name is None or len(file_name) == 0:
return False
delim = ","
if ".tag" in ext: # a TAG format was chosen
delim = ";"
fn_list = list()
for func in Functions():
start = GetFunctionAttr(func, FUNCATTR_START)
Expand All @@ -833,16 +836,20 @@ def _saveFunctionsNames(self, file_name):
return True
return False

def _loadFunctionsNames(self, file_name):
"""Loads functions names from the given CSV file into the internal mappings.
def _loadFunctionsNames(self, file_name, ext):
"""Loads functions names from the given file into the internal mappings.
Fromats: CSV (default), or TAG (PE-bear, PE-sieve compatibile).
"""

if file_name is None or len(file_name) == 0:
return False
curr_functions = self._listFunctionsAddr()
delim = "," # new delimiter (for CSV format)
delim2 = ":" # old delimiter
loaded = 0
if ".tag" in ext: # a TAG format was chosen
delim2 = ";"
functions = 0
comments = 0
with open(file_name, 'r') as f:
for line in f.readlines():
line = line.strip()
Expand All @@ -858,11 +865,11 @@ def _loadFunctionsNames(self, file_name):

if start in curr_functions:
if self.subDataManager.setFunctionName(start, func_name) == True:
loaded += 1
functions += 1
else:
MakeRptCmt(start, func_name) #set the name as a comment

return loaded
comments += 1
return (functions, comments)

def _setup_sorted_model(self, view, model):
"""Connects the given sorted data model with the given view.
Expand Down Expand Up @@ -1146,21 +1153,21 @@ def importNames(self):
"""Imports functions list from a CSV file.
"""

file_name, ext = QtWidgets.QFileDialog.getOpenFileName( None, "Export functions names", QtCore.QDir.homePath(), "CSV Files (*.csv);;TXT Files (*.txt);;All files (*)")
file_name, ext = QtWidgets.QFileDialog.getOpenFileName( None, "Export functions names", QtCore.QDir.homePath(), "CSV Files (*.csv);;TAG Files (*.tag);;All files (*)")
if file_name is not None and len(file_name) > 0 :
loaded = self._loadFunctionsNames(file_name)
if loaded == 0:
(loaded, comments) = self._loadFunctionsNames(file_name, ext)
if loaded == 0 and comments == 0:
idaapi.warning("Failed importing functions names! Not matching offsets!")
else:
idaapi.info("Imported %d function names " % (loaded))
idaapi.info("Imported %d function names and %d comments" % (loaded, comments))

def exportNames(self):
"""Exports functions list to a CSV file.
"""

file_name, ext = QtWidgets.QFileDialog.getSaveFileName( None, "Import functions names", QtCore.QDir.homePath(), "CSV Files (*.csv)")
file_name, ext = QtWidgets.QFileDialog.getSaveFileName( None, "Import functions names", QtCore.QDir.homePath(), "CSV Files (*.csv);;TAG Files (*.tag)")
if file_name is not None and len(file_name) > 0 :
if self._saveFunctionsNames(file_name) == False:
if self._saveFunctionsNames(file_name, ext) == False:
idaapi.warning("Failed exporting functions names!")
else:
idaapi.info("Exported to: "+ file_name)
Expand Down

0 comments on commit 2a3bd01

Please sign in to comment.