objcopy

copy and translate object files:

常用參數

objcopy [`-I' bfdname|`--input-target='bfdname]
        [`-O' bfdname|`--output-target='bfdname]
        [`-B' bfdarch|`--binary-architecture='bfdarch]
        [`-S'|`--strip-all']
        [`-g'|`--strip-debug']
        [`-j' sectionname|`--only-section='sectionname]
        [`-R' sectionname|`--remove-section='sectionname]
        [`--help']
        infile [outfile]

GNU binutil manual

使用範例

  1. 列出可用的 BFD target
    $ objdump -i
    
    BFD header file version (GNU Binutils for Ubuntu) 2.18
    elf32-i386
     (header little endian, data little endian)
      i386
    a.out-i386-linux
     (header little endian, data little endian)
      i386
    efi-app-ia32
     (header little endian, data little endian)
      i386
    elf32-little
     (header little endian, data little endian)
      i386
    elf32-big
     (header big endian, data big endian)
      i386
    elf64-x86-64
     (header little endian, data little endian)
      i386
    efi-app-x86_64
     (header little endian, data little endian)
      i386
    elf64-little
     (header little endian, data little endian)
      i386
    elf64-big
     (header big endian, data big endian)
      i386
    srec
     (header endianness unknown, data endianness unknown)
      i386
    symbolsrec
     (header endianness unknown, data endianness unknown)
      i386
    tekhex
     (header endianness unknown, data endianness unknown)
      i386
    binary
     (header endianness unknown, data endianness unknown)
      i386
    ihex
     (header endianness unknown, data endianness unknown)
      i386
    trad-core
     (header endianness unknown, data endianness unknown)
    
                   elf32-i386 a.out-i386-linux efi-app-ia32 elf32-little elf32-big
              i386 elf32-i386 a.out-i386-linux efi-app-ia32 elf32-little elf32-big
    
                   elf64-x86-64 efi-app-x86_64 elf64-little elf64-big srec
              i386 elf64-x86-64 efi-app-x86_64 elf64-little elf64-big srec
    
                   symbolsrec tekhex binary ihex trad-core
              i386 symbolsrec tekhex binary ihex ---------
    
  2. 將一個 JPEG 圖片檔 做成 .o 檔
    $ objcopy -I binary -O elf32-i386 -B i386  image.jpg  image.o
    
  3. 把執行碼從 ELF 中抽取出來,去除 symbol table, relocation information, .comment section, 和 .note section
    $ objcopy -O binary -S -R .comment -R .note  code.o  code.bin
    
  4. 只抽取指定的 section
    $ objcopy -O binary -j .text  code.o  code.bin
    

Last Modified: 

CreativeCommons: 姓名標示-非商業性-相同方式分享 3.0 本著作係採用 Creative Commons 條款 授權.