-
-
Save heinermann/e58d3d3bf376084c0027c922eb6adaf9 to your computer and use it in GitHub Desktop.
Problem of the Week 1, What's up with compilers?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
int main() { | |
uint32_t ip; | |
scanf("%u", &ip); | |
uint8_t octets[4]; | |
memcpy(octets, &ip, sizeof(ip)); | |
printf("%u.%u.%u.%u\n", octets[3], octets[2], octets[1], octets[0]); | |
return 0; | |
} | |
~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.text:0000000140001000 ; int __cdecl main() | |
.text:0000000140001000 main proc near ; CODE XREF: __scrt_common_main_seh+118p | |
.text:0000000140001000 ; DATA XREF: .pdata:ExceptionDiro | |
.text:0000000140001000 | |
.text:0000000140001000 var_28 = dword ptr -28h | |
.text:0000000140001000 var_18 = dword ptr -18h | |
.text:0000000140001000 var_10 = qword ptr -10h | |
.text:0000000140001000 | |
.text:0000000140001000 sub rsp, 48h | |
.text:0000000140001004 mov rax, cs:__security_cookie | |
.text:000000014000100B xor rax, rsp | |
.text:000000014000100E mov [rsp+48h+var_10], rax | |
.text:0000000140001013 lea rdx, [rsp+48h+var_18] | |
.text:0000000140001018 lea rcx, _Format ; "%u" | |
.text:000000014000101F call scanf | |
.text:0000000140001024 mov edx, [rsp+48h+var_18] | |
.text:0000000140001028 mov eax, edx | |
.text:000000014000102A shr eax, 8 | |
.text:000000014000102D movzx ecx, dl | |
.text:0000000140001030 movzx r9d, al | |
.text:0000000140001034 mov eax, edx | |
.text:0000000140001036 shr eax, 10h | |
.text:0000000140001039 mov [rsp+48h+var_28], ecx | |
.text:000000014000103D lea rcx, aU_U_U_U ; "%u.%u.%u.%u\n" | |
.text:0000000140001044 movzx r8d, al | |
.text:0000000140001048 shr edx, 18h | |
.text:000000014000104B call printf | |
.text:0000000140001050 xor eax, eax | |
.text:0000000140001052 mov rcx, [rsp+48h+var_10] | |
.text:0000000140001057 xor rcx, rsp ; StackCookie | |
.text:000000014000105A call __security_check_cookie | |
.text:000000014000105F add rsp, 48h | |
.text:0000000140001063 retn | |
.text:0000000140001063 main endp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
int main() { | |
uint32_t ip; | |
scanf("%u", &ip); | |
printf("%u.%u.%u.%u\n", (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.text:0000000140001000 ; int __cdecl main() | |
.text:0000000140001000 main proc near ; CODE XREF: __scrt_common_main_seh+118p | |
.text:0000000140001000 ; DATA XREF: .pdata:ExceptionDiro | |
.text:0000000140001000 | |
.text:0000000140001000 var_28 = dword ptr -28h | |
.text:0000000140001000 var_18 = dword ptr -18h | |
.text:0000000140001000 var_10 = qword ptr -10h | |
.text:0000000140001000 | |
.text:0000000140001000 sub rsp, 48h | |
.text:0000000140001004 mov rax, cs:__security_cookie | |
.text:000000014000100B xor rax, rsp | |
.text:000000014000100E mov [rsp+48h+var_10], rax | |
.text:0000000140001013 lea rdx, [rsp+48h+var_18] | |
.text:0000000140001018 lea rcx, _Format ; "%u" | |
.text:000000014000101F call scanf | |
.text:0000000140001024 mov edx, [rsp+48h+var_18] | |
.text:0000000140001028 mov eax, edx | |
.text:000000014000102A shr eax, 8 | |
.text:000000014000102D movzx ecx, dl | |
.text:0000000140001030 movzx r9d, al | |
.text:0000000140001034 mov eax, edx | |
.text:0000000140001036 shr eax, 10h | |
.text:0000000140001039 mov [rsp+48h+var_28], ecx | |
.text:000000014000103D lea rcx, aU_U_U_U ; "%u.%u.%u.%u\n" | |
.text:0000000140001044 movzx r8d, al | |
.text:0000000140001048 shr edx, 18h | |
.text:000000014000104B call printf | |
.text:0000000140001050 xor eax, eax | |
.text:0000000140001052 mov rcx, [rsp+48h+var_10] | |
.text:0000000140001057 xor rcx, rsp ; StackCookie | |
.text:000000014000105A call __security_check_cookie | |
.text:000000014000105F add rsp, 48h | |
.text:0000000140001063 retn | |
.text:0000000140001063 main endp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
int main() { | |
typedef union { | |
uint32_t ipWord; | |
unsigned char octets[4]; | |
} ip_t; | |
ip_t ip; | |
scanf("%u", &ip.ipWord); | |
printf("%u.%u.%u.%u\n", ip.octets[3], ip.octets[2], ip.octets[1], ip.octets[0]); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.text:0000000140001000 ; int __cdecl main() | |
.text:0000000140001000 main proc near ; CODE XREF: __scrt_common_main_seh+118p | |
.text:0000000140001000 ; DATA XREF: .pdata:ExceptionDiro | |
.text:0000000140001000 | |
.text:0000000140001000 var_28 = dword ptr -28h | |
.text:0000000140001000 var_18 = byte ptr -18h | |
.text:0000000140001000 var_17 = byte ptr -17h | |
.text:0000000140001000 var_16 = byte ptr -16h | |
.text:0000000140001000 var_15 = byte ptr -15h | |
.text:0000000140001000 var_10 = qword ptr -10h | |
.text:0000000140001000 | |
.text:0000000140001000 sub rsp, 48h | |
.text:0000000140001004 mov rax, cs:__security_cookie | |
.text:000000014000100B xor rax, rsp | |
.text:000000014000100E mov [rsp+48h+var_10], rax | |
.text:0000000140001013 lea rdx, [rsp+48h+var_18] | |
.text:0000000140001018 lea rcx, _Format ; "%u" | |
.text:000000014000101F call scanf | |
.text:0000000140001024 movzx eax, [rsp+48h+var_18] | |
.text:0000000140001029 lea rcx, aU_U_U_U ; "%u.%u.%u.%u\n" | |
.text:0000000140001030 movzx r9d, [rsp+48h+var_17] | |
.text:0000000140001036 movzx r8d, [rsp+48h+var_16] | |
.text:000000014000103C movzx edx, [rsp+48h+var_15] | |
.text:0000000140001041 mov [rsp+48h+var_28], eax | |
.text:0000000140001045 call printf | |
.text:000000014000104A xor eax, eax | |
.text:000000014000104C mov rcx, [rsp+48h+var_10] | |
.text:0000000140001051 xor rcx, rsp ; StackCookie | |
.text:0000000140001054 call __security_check_cookie | |
.text:0000000140001059 add rsp, 48h | |
.text:000000014000105D retn | |
.text:000000014000105D main endp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment