Skip to content

Instantly share code, notes, and snippets.

@lucasdemarchi
Created June 23, 2016 22:39
Show Gist options
  • Save lucasdemarchi/ce374f13f760c2e592eaddfba947c164 to your computer and use it in GitHub Desktop.
Save lucasdemarchi/ce374f13f760c2e592eaddfba947c164 to your computer and use it in GitHub Desktop.
0000000000400630 <foo(int)>:
400630: 89 f8 mov %edi,%eax
400632: 41 89 c0 mov %eax,%r8d
400635: 0f b6 f0 movzbl %al,%esi
400638: 0f b6 d4 movzbl %ah,%edx
40063b: c1 e8 10 shr $0x10,%eax
40063e: 41 c1 e8 18 shr $0x18,%r8d
400642: 0f b6 c8 movzbl %al,%ecx
400645: bf 90 07 40 00 mov $0x400790,%edi
40064a: 31 c0 xor %eax,%eax
40064c: e9 9f fe ff ff jmpq 4004f0 <printf@plt>
400651: 66 66 66 66 66 66 2e data16 data16 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
400658: 0f 1f 84 00 00 00 00
40065f: 00
0000000000400660 <bar(int)>:
400660: 89 f8 mov %edi,%eax
400662: 41 89 c0 mov %eax,%r8d
400665: 0f b6 f0 movzbl %al,%esi
400668: 0f b6 d4 movzbl %ah,%edx
40066b: c1 e8 10 shr $0x10,%eax
40066e: 41 c1 e8 18 shr $0x18,%r8d
400672: 0f b6 c8 movzbl %al,%ecx
400675: bf 90 07 40 00 mov $0x400790,%edi
40067a: 31 c0 xor %eax,%eax
40067c: e9 6f fe ff ff jmpq 4004f0 <printf@plt>
400681: 66 66 66 66 66 66 2e data16 data16 data16 data16 data16 nopw %cs:0x0(%rax,%rax,1)
400688: 0f 1f 84 00 00 00 00
40068f: 00
ELF>0@@p@8 @@@@@@��88@8@@@  �
`�
`TX �
`�
`TT@T@DDP�td��@�@DDQ�tdR�td�
`�
`  /lib64/ld-linux-x86-64.so.2GNU GNU��+����V��U�=f��N|�  �3 O �libstdc++.so.6__gmon_start___Jv_RegisterClasses_ITM_deregisterTMCloneTable_ITM_registerTMCloneTablelibm.so.6libgcc_s.so.1libc.so.6printfstrtol__libc_start_mainGLIBC_2.2.5�ui ��`` `(`H��H�- H��t�KH����5" �%$ @�%" h������% h������% h������%�
f�1�I��^H��H���PTI��p@H��@H�ǐ@�����fD�?`UH-8`H��H��v�H��t]�8`��f�]�@f.��8`UH��8`H��H��H��H��?H�H��t�H��t ]�8`��]�fD�=M
uUH���n���]�:
��@��
`H�?u��H��t�UH����]�z���f.���A��������A���ȿ�@1�����ffffff.���A��������A���ȿ�@1��o���ffffff.�UAWAVSPH�~1�
�i�����D���������ؿ�@1�D��A�׉�A��� �����@1�D��D���A��� ���1�H��[A^A_]�f.�f�AWAVA��AUATL�%� UH�-� SI��I��L)�H��H������H��t 1��L��L��D��A��H��H9�u�H��[]A\A]A^A_Ðf.���H��H���%#.2x %#.2x %#.2x %#.2x
;@4��������\���������������T��� ����TzRx � ���*zRx �$����@FJ w�?;*3$"D����!\����!$t����dABB A(A0����D�@���eB�B�E �B(�H0�H8�M@r8A0A(B BBB�h���@�@is� �@
t@�
`�
`���o�@x@�@
� `Hx@`@ ���o@@���o���o0@�
`�@@@GCC: (GNU) 6.1.1 20160510 (Red Hat 6.1.1-2)clang version 3.8.0 (tags/RELEASE_380/final)8@T@t@�@�@x@0@@@ `@
x@ �@ �@
@0@t@�@�@�@�
`�
`�
`�
`�``0`4`�� �
``@�@.�@D4`S�
`z@��
`������ @��
`����@�`��
`�
`�
`� 0` 4p@�0@*D S g`@!>t@o� ��@� �0`�8`�0@!��@@e%4`�8`14`8�@d �@crtstuff.c__JCR_LIST__deregister_tm_clones__do_global_dtors_auxcompleted.6936__do_global_dtors_aux_fini_array_entryframe_dummy__frame_dummy_init_array_entry/tmp/a.cpp__FRAME_END____JCR_END____GNU_EH_FRAME_HDR_GLOBAL_OFFSET_TABLE___init_array_end__init_array_start_DYNAMICprintf@@GLIBC_2.2.5__libc_csu_fini__gmon_start___Jv_RegisterClasses_Z3bari__libc_start_main@@GLIBC_2.2.5_ITM_deregisterTMCloneTable_IO_stdin_used_ITM_registerTMCloneTable__data_start__TMC_END___Z3fooi__dso_handlestrtol@@GLIBC_2.2.5__libc_csu_init__bss_start_edatamain.symtab.strtab.shstrtab.interp.note.ABI-tag.note.gnu.build-id.gnu.hash.dynsym.dynstr.gnu.version.gnu.version_r.rela.dyn.rela.plt.init.plt.got.text.fini.rodata.eh_frame_hdr.eh_frame.init_array.fini_array.jcr.dynamic.got.plt.data.bss.comment8@8#T@T 1t@t$D���o�@�N �@��Vx@x�^���o0@0k���o@@@ z`@`�Bx@xH��@���@�@� @ �0@0B�t@t ��@�)��@�D��@�,��
`�
��
`�
��
`�
��
`�
��`��`0�0`0�4`404Y] ��/  =#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
union Bla {
int a;
char b;
inline uint8_t &operator[](size_t i) { return reinterpret_cast<uint8_t *>(this)[i]; }
inline uint8_t operator[](size_t i) const { return reinterpret_cast<const uint8_t *>(this)[i]; }
};
union Bli {
int a;
char b;
uint8_t bytes[0];
};
void foo(int p)
{
Bla bla{};
bla.a = p;
printf("%#.2x %#.2x %#.2x %#.2x\n", bla[0], bla[1], bla[2], bla[3]);
}
void bar(int p)
{
Bli bli{};
bli.a = p;
printf("%#.2x %#.2x %#.2x %#.2x\n", bli.bytes[0], bli.bytes[1], bli.bytes[2], bli.bytes[3]);
}
int main(int argc, const char *argv[])
{
int p = atoi(argv[1]);
foo(p);
bar(p);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment