####################################################################################### # # Copyright (c) 2007 Paolo Palumbo # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # * The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # Import needed stuff from idaapi import * from idc import * ########################### # Custom chooser used to # display the hex view. It can # be fully customized to do # interesting stuff. # # Version 0.1 - Comes straight # from Gergely Erdelyi's example # included into IDA Python # distribution class HexViewer(Choose): # Override the standard Chooser init def __init__(self, list=[], name="HexViewer"): # Create the JumpingChooser object Choose.__init__(self, list, name) # Specify how wide it should be and # where the window should be positioned self.width = 80 self.x0 = 120 self.y0 = 0 self.x1 = 220 self.y1 = 80 # Override the default behaviour when enter is # pressed. In this case. def enter(self, n): # Please customize here! print "You have pressed !" print "Please replace me with something more useful!" ############################ # This function builds the text # will end up into the hex view # # Version 0.1 - 30 April 2007 def PrepareHexDump(StartAddress = get_screen_ea(), Size = 0x500): # Check that we will not attempt reading past the end of the # file if (StartAddress + Size) > MaxEA(): Size = MaxEA() - StartAddress # Init some vars Walker = StartAddress ByteList = [] # Prepare top header line TempString = "0x%x: +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F" % Walker AsciiValues = "; " # Read the data while Walker < StartAddress + Size: # Read the current byte ByteValue = Byte(Walker) # Check if we need to end our line here or not if (Walker - StartAddress) % 0x10 != 0: TempString = TempString + " %2.2x" % ByteValue if ( 0x20 <= ByteValue <= 0xFD): AsciiValues = AsciiValues + "%c" % ByteValue else: AsciiValues = AsciiValues + "." else: TempString = TempString + " " + AsciiValues ByteList.append(TempString) AsciiValues = "; " if ( 0x20 <= ByteValue <= 0x7E): AsciiValues = AsciiValues + "%c" % ByteValue else: AsciiValues = AsciiValues + "." TempString = "0x%x: %2.2x" % (Walker,ByteValue) # Move to next byte Walker = Walker + 1 # Append the last line to our list TempString = TempString + " " + AsciiValues ByteList.append(TempString) ByteList.append(TempString) # Append empty line, to handle display error ByteList.append(" ") return ByteList ########################## # HexViewer "program" :P # ########################## HexDump = HexViewer(PrepareHexDump(get_screen_ea(),0x1000),"[ - Hexdump Window - ]") HexDump.choose()