Skip to content

Instantly share code, notes, and snippets.

@argp
Created October 27, 2014 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save argp/1b749195a7956d884892 to your computer and use it in GitHub Desktop.
Save argp/1b749195a7956d884892 to your computer and use it in GitHub Desktop.
from macholib.MachO import MachO as macho
FILE = './xuanyuansword'
FILE_ICON = './xuanyuansword_icon'
macho_obj = macho(FILE)
for (load_cmd, cmd, data) in macho_obj.headers[0].commands:
try:
segname = getattr(cmd, 'segname')
except:
continue
if segname.startswith('__DATA'):
print('[+] segname: __DATA')
nsects = getattr(cmd, 'nsects')
print('[+] nsects: %d' % (nsects))
for section in data:
sectname = getattr(section, 'sectname')
if sectname.startswith('__icon'):
icon_offset = getattr(section, 'offset')
icon_size = getattr(section, 'size')
print('[+] __icon section: offset 0x%x size 0x%x' % \
(icon_offset, icon_size))
fh = open(FILE, 'rb')
fh.seek(icon_offset + 0x4000)
open(FILE_ICON, 'wb').write(fh.read(icon_size))
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment