Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 84 additions & 9 deletions plugins/codatify/codatify.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# IDA plugin that converts all data in data segments to defined data types, and all data in code segments to code.
#
# Use by going to Options->Define data and code.
# Use by going to Options->Fixup code or Options->Fixup data
#
# Craig Heffner
# Tactical Network Solutions

import idc
import idaapi
import idautils
import string
if idaapi.IDA_SDK_VERSION <= 695:
import idc
import idaapi
import idautils
import string
if idaapi.IDA_SDK_VERSION >= 700:
import idc
import ida_idaapi
#import ida_kerwin
from idaapi import *
else:
pass

class StructEntry(object):

Expand Down Expand Up @@ -354,6 +362,44 @@ def codeify(self, ea=idc.BADADDR):
print "Created %d new functions and %d new code blocks\n" % (func_count, code_count)


# Use try to avoid breaking ida versions below 6.8
try:
class FixCodeHandler(idaapi.action_handler_t):

def __init__(self):
idaapi.action_handler_t.__init__(self)

def activate(self, ctx):
# b = codatify_t()
# b.fix_code()
return 1

# This action is always available.
def update(self, ctx):
return idaapi.AST_ENABLE_ALWAYS

except AttributeError:
pass

try:
class FixDataHandler(idaapi.action_handler_t):

def __init__(self):
idaapi.action_handler_t.__init__(self)

def activate(self, ctx):
# c = codatify_t()
# c.fix_data()
return 1

# This action is always available.
def update(self, ctx):
return idaapi.AST_ENABLE_ALWAYS

except AttributeError:
pass



class codatify_t(idaapi.plugin_t):
flags = 0
Expand All @@ -363,12 +409,41 @@ class codatify_t(idaapi.plugin_t):
wanted_hotkey = ""

def init(self):
self.menu_context = idaapi.add_menu_item("Options/", "Fixup code", "", 0, self.fix_code, (None,))
self.menu_context = idaapi.add_menu_item("Options/", "Fixup data", "", 0, self.fix_data, (None,))
if idaapi.IDA_SDK_VERSION >= 680 and idaapi.IDA_SDK_VERSION <= 695:
self.menu_context = idaapi.add_menu_item("Options/", "Fixup code", "", 0, self.fix_code, (None,))
self.menu_context = idaapi.add_menu_item("Options/", "Fixup data", "", 0, self.fix_data, (None,))
if idaapi.IDA_SDK_VERSION >= 700:
# Create our "Fixup code" action
action_desc = idaapi.action_desc_t(
"codatify:fixupcodeaction", # Name
"Fixup code", # Label (what the user sees)
FixCodeHandler(), # Handler. Called on activation and for updates
"", # Shortcut (optional)
"Fixup code" # Tooltip (optional)
)
# Register the "Fixup code" action and add it to the menu
idaapi.register_action(action_desc)
idaapi.attach_action_to_menu("Options/", "codatify:fixupcodeaction", idaapi.SETMENU_APP)

# Create our "Fixup data" action
action_desc = idaapi.action_desc_t(
"codatify:fixupdataaction",
"Fixup data",
FixDataHandler(),
"",
"Fixup data"
)
# Register the "Fixup code" action and add it to the menu
idaapi.register_action(action_desc)
idaapi.attach_action_to_menu("Options/", "codatify:fixupdataaction", idaapi.SETMENU_APP)
else:
pass

return idaapi.PLUGIN_KEEP

def term(self):
idaapi.del_menu_item(self.menu_context)
if idaapi.IDA_SDK_VERSION <= 695 and idaapi.IDA_SDK_VERSION >= 680:
idaapi.del_menu_item(self.menu_context)
return None

def run(self, arg):
Expand All @@ -385,6 +460,6 @@ def fix_data(self, arg):
cd.pointify()
StructFinder().parse_function_tables()


def PLUGIN_ENTRY():
return codatify_t()