Skip to content

Instantly share code, notes, and snippets.

@herrcore
Last active November 11, 2021 10:57
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • 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
@david8557
Copy link

Any way to make hotkey work?

@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