Skip to content

Instantly share code, notes, and snippets.

@herrcore
Last active August 23, 2024 08:41
Show Gist options
  • Save herrcore/01762779ae4ac130d3beb02bf8e99826 to your computer and use it in GitHub Desktop.
Save herrcore/01762779ae4ac130d3beb02bf8e99826 to your computer and use it in GitHub Desktop.
IDA Plugin for quickly copying disassembly as encoded hex bytes (updated for IDA 7xx) - moved https://github.com/OALabs/hexcopy-ida
Moved: https://github.com/OALabs/hexcopy-ida
@BiteFoo
Copy link

BiteFoo commented May 7, 2021

Hi,@herrcore,I found this script is not work at ida7.5 python3.7.7+ ,due to function

def copy_bytes():
    """
    Copy selected bytes to clipboard
    """
    if using_ida7api:
        start = idc.read_selection_start()
        end = idc.read_selection_end()
        if idaapi.BADADDR in (start, end):
            ea = idc.here()
            start = idaapi.get_item_head(ea)
            end = idaapi.get_item_end(ea)
        data = idc.get_bytes(start, end - start).encode('hex')
        print "Bytes copied: %s" % data
        copy_to_clip(data)
    else:
        start = idc.SelStart()
        end = idc.SelEnd()
        if idaapi.BADADDR in (start, end):
            ea = idc.here()
            start = idaapi.get_item_head(ea)
            end = idaapi.get_item_end(ea)
        data = idc.GetManyBytes(start, end-start).encode('hex')
        print "Bytes copied: %s" % data
        copy_to_clip(data)
    return 

at 3.7.+,this should be

def copy_bytes():
    """
    Copy selected bytes to clipboard
    """
    if using_ida7api:
        start = idc.read_selection_start()
        end = idc.read_selection_end()
        if idaapi.BADADDR in (start, end):
            ea = idc.here()
            start = idaapi.get_item_head(ea)
            end = idaapi.get_item_end(ea)
        # fix encode bug reference 
        # https://stackoverflow.com/questions/6624453/whats-the-correct-way-to-convert-bytes-to-a-hex-string-in-python-3
        data = idc.get_bytes(start, end - start).hex()
        print ("Bytes copied: %s" % data)
        copy_to_clip(data)
    else:
        start = idc.SelStart()
        end = idc.SelEnd()
        if idaapi.BADADDR in (start, end):
            ea = idc.here()
            start = idaapi.get_item_head(ea)
            end = idaapi.get_item_end(ea)
        data = idc.GetManyBytes(start, end-start).hex()
        print( "Bytes copied: %s" % data)
        copy_to_clip(data)
    return 

@herrcore
Copy link
Author

This gist has been moved to a complete repo https://github.com/OALabs/hexcopy-ida

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment