{"id":538,"date":"2013-02-18T22:14:19","date_gmt":"2013-02-18T13:14:19","guid":{"rendered":"http:\/\/43.203.250.216\/?p=538"},"modified":"2013-02-18T22:14:19","modified_gmt":"2013-02-18T13:14:19","slug":"binaryhack11-%ec%8b%a4%ed%96%89-%ed%8c%8c%ec%9d%bc%ec%97%90-%eb%8d%b0%ec%9d%b4%ed%84%b0-%ec%82%bd%ec%9e%85%ed%95%98%ea%b8%b0-64bits","status":"publish","type":"post","link":"https:\/\/litcoder.com\/?p=538","title":{"rendered":"[BinaryHack#11] \uc2e4\ud589 \ud30c\uc77c\uc5d0 \ub370\uc774\ud130 \uc0bd\uc785\ud558\uae30 (64bits)"},"content":{"rendered":"<p>&#8216;Binary Hacks&#8217;\uc758 hack #11\uc5d0\ub294 objcopy\ub97c \uc774\uc6a9\ud574\uc11c \uc2e4\ud589\ud30c\uc77c\uc5d0 binary\ub97c \ucd94\uac00\ud558\ub294 \ubc29\ubc95\uc774 \ub098\uc628\ub2e4. \uc774\uac83\uc744 \ub530\ub77c 64 bits machine\uc5d0\uc11c build\ud558\uba74 i386:x86-64 \ucd9c\ub825\ubb3c\uacfc i386 \ucd9c\ub825\ubb3c\uc774 incompatible \ud574\uc11c link\ud560 \uc218 \uc5c6\ub2e4\ub294 \uc624\ub958\uac00 \ubc1c\uc0dd\ud55c\ub2e4.<\/p>\n<pre class=\"lang:default highlight:0 decode:true\">$&gt; objcopy -I binary -O elf32-i386 -B i386 binary.bmp binary.o\n$&gt; gcc -c main.c\n$&gt; gcc -o program main.o binary.o\n\/usr\/bin\/ld: i386 architecture of input file 'binary.o' is incompatible with i386:x86-64 output\ncollect2: error: ld returned 1 exit status<\/pre>\n<p>gcc\ub85c \ub9cc\ub4e4\uc5b4\uc9c4 main.o\ub294 ELF-64 format\uc778\ub370 objcopy\ub85c \uc0dd\uc131\ud55c ELF-32 format\uc774\uc5b4\uc11c \ud568\uaed8 link\ud560 \uc218 \uc5c6\ub2e4\ub294 \uac83\uc774\ub2e4. \uc774 \ubb38\uc81c\ub294 \ub3d9\uc77c\ud55c ELF format\uc774 \ub418\ub3c4\ub85d \ud558\uba74 \ud574\uacb0\ub41c\ub2e4. \uc989, gcc\ub85c compile\ud55c \uacb0\uacfc\ubb3c\uc774 objcopy\uc758 \uacb0\uacfc\ubb3c\uc778 ELF-32\uc640 \ub3d9\uc77c\ud558\uac8c \ub418\ub3c4\ub85d \ud558\uac70\ub098 objcopy\uc758 \uacb0\uacfc \ubb3c\uc774 main.o\uc640 \ub3d9\uc77c\ud55c ELF-64\uac00 \ub418\ub3c4\ub85d \ud574\uc57c\ud55c\ub2e4.<\/p>\n<p>\uccab\ubc88\uc9f8 \ubc29\ubc95 &#8211; ELF-32 format\uc73c\ub85c object\ub97c compile<br \/>\ngcc\uc5d0 -m32 option\uc744 \ucd94\uac00\ud558\uba74 ELF32\ub85c compile\ub41c object file\uc744 \uc5bb\uc744 \uc218 \uc788\ub2e4. \uc774\uac83\uc744 objcopy\uc758 \uacb0\uacfc \ubb3c\uacfc link\ud55c\ub2e4.<\/p>\n<pre class=\"lang:default highlight:0 decode:true\">$&gt; objcopy -I binary -O elf32-i386 -B i386 binary.bmp binary.o\n$&gt; gcc -m32 -c main.c\n$&gt; gcc -m32 -o program main.o binary.o<\/pre>\n<p>\ub450\ubc88\uc9f8 \ubc29\ubc95 &#8211; ELF-64 format\uc73c\ub85c binary\ub97c \uc0dd\uc131<br \/>\nobjcopy\uac00 ELF64\ub97c \uc0dd\uc131\ud558\ub3c4\ub85d \ud558\uba74 gcc\ub85c compile\ud55c \ub2e4\ub978 object file\ub4e4\uacfc link\ud560 \uc218 \uc788\ub2e4.<\/p>\n<pre class=\"lang:default highlight:0 decode:true\">$&gt; objcopy -I binary -O elf64-x86-64 -B i386 binary.bmp binary.o\n$&gt; gcc -c main.c\n$&gt; gcc -o program main.o binary.o<\/pre>\n<p>&nbsp;<\/p>\n<p>* objcopy\ub85c \uc0dd\uc131\ub41c ELF object\uc5d0\uc11c \ub2f4\uace0 \uc788\ub294 symbol\uc758 \ubaa9\ub85d\uc740 nm \uba85\ub839\uc5b4\ub098 readelf -s option\uc73c\ub85c \ubcfc \uc218 \uc788\ub2e4.<\/p>\n<pre class=\"lang:default highlight:0 decode:true\">$&gt; nm binary.o\n00000000002fd036 D _binary_binary_bmp_end\n00000000002fd036 A _binary_binary_bmp_size\n0000000000000000 D _binary_binary_bmp_start\n\n$&gt;readelf -s binary.o\nSymbol table '.symtab' contains 5 entries:\n   Num:    Value          Size Type    Bind   Vis      Ndx Name\n     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND \n     1: 0000000000000000     0 SECTION LOCAL  DEFAULT    1 \n     2: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT    1 _binary_binary_bmp_start\n     3: 00000000002fd036     0 NOTYPE  GLOBAL DEFAULT    1 _binary_binary_bmp_end\n     4: 00000000002fd036     0 NOTYPE  GLOBAL DEFAULT  ABS _binary_binary_bmp_size<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8216;Binary Hacks&#8217;\uc758 hack #11\uc5d0\ub294 objcopy\ub97c \uc774\uc6a9\ud574\uc11c \uc2e4\ud589\ud30c\uc77c\uc5d0 binary\ub97c \ucd94\uac00\ud558\ub294 \ubc29\ubc95\uc774 \ub098\uc628\ub2e4. \uc774\uac83\uc744 \ub530\ub77c 64 bits machine\uc5d0\uc11c build\ud558\uba74 i386:x86-64 \ucd9c\ub825\ubb3c\uacfc i386 \ucd9c\ub825\ubb3c\uc774 incompatible \ud574\uc11c link\ud560 \uc218 \uc5c6\ub2e4\ub294 \uc624\ub958\uac00 \ubc1c\uc0dd\ud55c\ub2e4. $&gt; objcopy -I binary -O elf32-i386 -B i386 binary.bmp binary.o $&gt; gcc -c main.c $&gt; gcc -o program main.o binary.o \/usr\/bin\/ld: i386 architecture of input file &#8216;binary.o&#8217; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[21,40,89],"class_list":["post-538","post","type-post","status-publish","format-standard","hentry","category-programming","tag-binaryhack","tag-elf","tag-objcopy"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/posts\/538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/litcoder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=538"}],"version-history":[{"count":0,"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/posts\/538\/revisions"}],"wp:attachment":[{"href":"https:\/\/litcoder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/litcoder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/litcoder.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}