Skip to content
Snippets Groups Projects

Spectre Mitigations in Microsoft's C/C++ Compiler in 2024

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.

    Paul Kocher's 2018 blog post titled Spectre Mitigations in Microsoft's C/C++ Compiler highlighted 15 victim functions which demonstrate Spectre vulnerabilities. These functions were used as a litmus test to evaluate the Spectre mitigations provided by Microsoft's C compiler (MSVC).

    After 6 years and many cumulative updates to MSVC, I decided to test how MSVC fairs against these examples in 2024. I used MSVC to compile x86-64 binaries on Windows with SDK in a Docker container. Further details on the method is provided in https://gitlab.surrey.ac.uk/mg00634/spectre-db.

    7 of the victim functions have now been patched (up from 2 in the original post). These are Examples 1, 2, 3, 4, 11, 12 and 14. Attached are the code listings generated by MSVC.

    Edited
    ex.cod 17.99 KiB
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	victim_function_v01
    EXTRN	array1_size:QWORD
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    EXTRN	__ImageBase:BYTE
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 1\ex01.c
    ;	COMDAT victim_function_v01
    _TEXT	SEGMENT
    x$ = 8
    victim_function_v01 PROC				; COMDAT
    
    ; 5    :     if (x < array1_size) {
    
      00000	48 3b 0d 00 00
    	00 00		 cmp	 rcx, QWORD PTR array1_size
      00007	73 24		 jae	 SHORT $LN2@victim_fun
    
    ; 6    :         temp &= array2[array1[x] * 512];
    
      00009	0f ae e8	 lfence
      0000c	48 8d 15 00 00
    	00 00		 lea	 rdx, OFFSET FLAT:__ImageBase
      00013	0f b6 84 0a 00
    	00 00 00	 movzx	 eax, BYTE PTR array1[rdx+rcx]
      0001b	48 c1 e0 09	 shl	 rax, 9
      0001f	0f b6 84 10 00
    	00 00 00	 movzx	 eax, BYTE PTR array2[rax+rdx]
      00027	20 05 00 00 00
    	00		 and	 BYTE PTR temp, al
    $LN2@victim_fun:
    
    ; 7    :     }
    ; 8    : }
    
      0002d	c3		 ret	 0
    victim_function_v01 ENDP
    _TEXT	ENDS
    END
    
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	leakByteLocalFunction_v02
    PUBLIC	victim_function_v02
    EXTRN	array1_size:QWORD
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    EXTRN	__ImageBase:BYTE
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 2\ex02.c
    ;	COMDAT victim_function_v02
    _TEXT	SEGMENT
    x$ = 8
    victim_function_v02 PROC				; COMDAT
    
    ; 9    :     if (x < array1_size) {
    
      00000	48 3b 0d 00 00
    	00 00		 cmp	 rcx, QWORD PTR array1_size
      00007	73 24		 jae	 SHORT $LN4@victim_fun
    
    ; 10   :         leakByteLocalFunction_v02(array1[x]);
    
      00009	0f ae e8	 lfence
      0000c	48 8d 15 00 00
    	00 00		 lea	 rdx, OFFSET FLAT:__ImageBase
    
    ; 4    :     temp &= array2[(k)* 512];
    
      00013	0f b6 84 0a 00
    	00 00 00	 movzx	 eax, BYTE PTR array1[rdx+rcx]
      0001b	48 c1 e0 09	 shl	 rax, 9
      0001f	0f b6 84 10 00
    	00 00 00	 movzx	 eax, BYTE PTR array2[rax+rdx]
      00027	20 05 00 00 00
    	00		 and	 BYTE PTR temp, al
    $LN4@victim_fun:
    
    ; 11   :     }
    ; 12   : }
    
      0002d	c3		 ret	 0
    victim_function_v02 ENDP
    _TEXT	ENDS
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 2\ex02.c
    ;	COMDAT leakByteLocalFunction_v02
    _TEXT	SEGMENT
    k$ = 8
    leakByteLocalFunction_v02 PROC				; COMDAT
    
    ; 4    :     temp &= array2[(k)* 512];
    
      00000	0f b6 c1	 movzx	 eax, cl
      00003	48 8d 0d 00 00
    	00 00		 lea	 rcx, OFFSET FLAT:array2
      0000a	c1 e0 09	 shl	 eax, 9
      0000d	0f b6 04 08	 movzx	 eax, BYTE PTR [rax+rcx]
      00011	20 05 00 00 00
    	00		 and	 BYTE PTR temp, al
    
    ; 5    : }
    
      00017	c3		 ret	 0
    leakByteLocalFunction_v02 ENDP
    _TEXT	ENDS
    END
    
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	leakByteNoinlineFunction
    PUBLIC	victim_function_v03
    EXTRN	array1_size:QWORD
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 3\ex03.c
    ;	COMDAT victim_function_v03
    _TEXT	SEGMENT
    x$ = 8
    victim_function_v03 PROC				; COMDAT
    
    ; 9    :     if (x < array1_size)
    
      00000	48 3b 0d 00 00
    	00 00		 cmp	 rcx, QWORD PTR array1_size
      00007	73 13		 jae	 SHORT $LN2@victim_fun
    
    ; 10   :         leakByteNoinlineFunction(array1[x]);
    
      00009	0f ae e8	 lfence
      0000c	48 8d 05 00 00
    	00 00		 lea	 rax, OFFSET FLAT:array1
      00013	0f b6 0c 08	 movzx	 ecx, BYTE PTR [rax+rcx]
      00017	e9 00 00 00 00	 jmp	 leakByteNoinlineFunction
    $LN2@victim_fun:
    
    ; 11   : }
    
      0001c	c3		 ret	 0
    victim_function_v03 ENDP
    _TEXT	ENDS
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 3\ex03.c
    ;	COMDAT leakByteNoinlineFunction
    _TEXT	SEGMENT
    k$ = 8
    leakByteNoinlineFunction PROC				; COMDAT
    
    ; 4    :     temp &= array2[(k)* 512]; 
    
      00000	0f b6 c1	 movzx	 eax, cl
      00003	48 8d 0d 00 00
    	00 00		 lea	 rcx, OFFSET FLAT:array2
      0000a	c1 e0 09	 shl	 eax, 9
      0000d	0f b6 04 08	 movzx	 eax, BYTE PTR [rax+rcx]
      00011	20 05 00 00 00
    	00		 and	 BYTE PTR temp, al
    
    ; 5    : }
    
      00017	c3		 ret	 0
    leakByteNoinlineFunction ENDP
    _TEXT	ENDS
    END
    
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	victim_function_v04
    EXTRN	array1_size:QWORD
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    EXTRN	__ImageBase:BYTE
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 4\ex04.c
    ;	COMDAT victim_function_v04
    _TEXT	SEGMENT
    x$ = 8
    victim_function_v04 PROC				; COMDAT
    
    ; 5    :     if (x < array1_size)
    
      00000	48 3b 0d 00 00
    	00 00		 cmp	 rcx, QWORD PTR array1_size
      00007	73 24		 jae	 SHORT $LN2@victim_fun
    
    ; 6    :         temp &= array2[array1[x << 1] * 512];
    
      00009	0f ae e8	 lfence
      0000c	48 8d 15 00 00
    	00 00		 lea	 rdx, OFFSET FLAT:__ImageBase
      00013	0f b6 84 4a 00
    	00 00 00	 movzx	 eax, BYTE PTR array1[rdx+rcx*2]
      0001b	48 c1 e0 09	 shl	 rax, 9
      0001f	0f b6 84 10 00
    	00 00 00	 movzx	 eax, BYTE PTR array2[rax+rdx]
      00027	20 05 00 00 00
    	00		 and	 BYTE PTR temp, al
    $LN2@victim_fun:
    
    ; 7    : }
    
      0002d	c3		 ret	 0
    victim_function_v04 ENDP
    _TEXT	ENDS
    END
    
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	victim_function_v05
    EXTRN	array1_size:QWORD
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    EXTRN	__ImageBase:BYTE
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 5\ex05.c
    ;	COMDAT victim_function_v05
    _TEXT	SEGMENT
    x$ = 8
    victim_function_v05 PROC				; COMDAT
    
    ; 5    :     size_t i;
    ; 6    :     if (x < array1_size) {
    
      00000	48 3b 0d 00 00
    	00 00		 cmp	 rcx, QWORD PTR array1_size
      00007	73 2d		 jae	 SHORT $LN3@victim_fun
    
    ; 7    :         for (i = x - 1; i >= 0; i--)
    
      00009	0f b6 15 00 00
    	00 00		 movzx	 edx, BYTE PTR temp
      00010	4c 8d 05 00 00
    	00 00		 lea	 r8, OFFSET FLAT:__ImageBase
      00017	49 8d 80 ff ff
    	ff ff		 lea	 rax, QWORD PTR array1[r8-1]
      0001e	48 03 c1	 add	 rax, rcx
    $LL4@victim_fun:
    
    ; 8    :             temp &= array2[array1[i] * 512];
    
      00021	0f b6 08	 movzx	 ecx, BYTE PTR [rax]
      00024	48 8d 40 ff	 lea	 rax, QWORD PTR [rax-1]
      00028	48 c1 e1 09	 shl	 rcx, 9
      0002c	42 22 94 01 00
    	00 00 00	 and	 dl, BYTE PTR array2[rcx+r8]
      00034	eb eb		 jmp	 SHORT $LL4@victim_fun
    $LN3@victim_fun:
    
    ; 9    :     }
    ; 10   : }
    
      00036	c3		 ret	 0
    victim_function_v05 ENDP
    _TEXT	ENDS
    END
    
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	victim_function_v06
    EXTRN	array_size_mask:QWORD
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    EXTRN	__ImageBase:BYTE
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 6\ex06.c
    ;	COMDAT victim_function_v06
    _TEXT	SEGMENT
    x$ = 8
    victim_function_v06 PROC				; COMDAT
    
    ; 5    :     if ((x & array_size_mask) == x)
    
      00000	48 8b 05 00 00
    	00 00		 mov	 rax, QWORD PTR array_size_mask
      00007	48 23 c1	 and	 rax, rcx
      0000a	48 3b c1	 cmp	 rax, rcx
      0000d	75 21		 jne	 SHORT $LN2@victim_fun
    
    ; 6    :         temp &= array2[array1[x] * 512];
    
      0000f	48 8d 15 00 00
    	00 00		 lea	 rdx, OFFSET FLAT:__ImageBase
      00016	0f b6 84 0a 00
    	00 00 00	 movzx	 eax, BYTE PTR array1[rdx+rcx]
      0001e	48 c1 e0 09	 shl	 rax, 9
      00022	0f b6 84 10 00
    	00 00 00	 movzx	 eax, BYTE PTR array2[rax+rdx]
      0002a	20 05 00 00 00
    	00		 and	 BYTE PTR temp, al
    $LN2@victim_fun:
    
    ; 7    : }
    
      00030	c3		 ret	 0
    victim_function_v06 ENDP
    _TEXT	ENDS
    END
    
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	victim_function_v07
    EXTRN	array1_size:QWORD
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    EXTRN	__ImageBase:BYTE
    _BSS	SEGMENT
    ?last_x@?1??victim_function_v07@@9@9 DQ 01H DUP (?)	; `victim_function_v07'::`2'::last_x
    _BSS	ENDS
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 7\ex07.c
    ;	COMDAT victim_function_v07
    _TEXT	SEGMENT
    x$ = 8
    victim_function_v07 PROC				; COMDAT
    
    ; 5    :     static size_t last_x = 0;
    ; 6    :     if (x == last_x)
    
      00000	48 3b 0d 00 00
    	00 00		 cmp	 rcx, QWORD PTR ?last_x@?1??victim_function_v07@@9@9
      00007	75 21		 jne	 SHORT $LN2@victim_fun
    
    ; 7    :         temp &= array2[array1[x] * 512];
    
      00009	48 8d 15 00 00
    	00 00		 lea	 rdx, OFFSET FLAT:__ImageBase
      00010	0f b6 84 0a 00
    	00 00 00	 movzx	 eax, BYTE PTR array1[rdx+rcx]
      00018	48 c1 e0 09	 shl	 rax, 9
      0001c	0f b6 84 10 00
    	00 00 00	 movzx	 eax, BYTE PTR array2[rax+rdx]
      00024	20 05 00 00 00
    	00		 and	 BYTE PTR temp, al
    $LN2@victim_fun:
    
    ; 8    :     if (x < array1_size)
    
      0002a	48 3b 0d 00 00
    	00 00		 cmp	 rcx, QWORD PTR array1_size
      00031	73 07		 jae	 SHORT $LN3@victim_fun
    
    ; 9    :         last_x = x;
    
      00033	48 89 0d 00 00
    	00 00		 mov	 QWORD PTR ?last_x@?1??victim_function_v07@@9@9, rcx
    $LN3@victim_fun:
    
    ; 10   : }
    
      0003a	c3		 ret	 0
    victim_function_v07 ENDP
    _TEXT	ENDS
    END
    
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	victim_function_v08
    EXTRN	array1_size:QWORD
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    EXTRN	__ImageBase:BYTE
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 8\ex08.c
    ;	COMDAT victim_function_v08
    _TEXT	SEGMENT
    x$ = 8
    victim_function_v08 PROC				; COMDAT
    
    ; 5    :     temp &= array2[array1[x < array1_size ? (x + 1) : 0] * 512];
    
      00000	48 3b 0d 00 00
    	00 00		 cmp	 rcx, QWORD PTR array1_size
      00007	73 05		 jae	 SHORT $LN3@victim_fun
      00009	48 ff c1	 inc	 rcx
      0000c	eb 02		 jmp	 SHORT $LN4@victim_fun
    $LN3@victim_fun:
      0000e	33 c9		 xor	 ecx, ecx
    $LN4@victim_fun:
      00010	48 8d 15 00 00
    	00 00		 lea	 rdx, OFFSET FLAT:__ImageBase
      00017	0f b6 84 11 00
    	00 00 00	 movzx	 eax, BYTE PTR array1[rcx+rdx]
      0001f	48 c1 e0 09	 shl	 rax, 9
      00023	0f b6 84 10 00
    	00 00 00	 movzx	 eax, BYTE PTR array2[rax+rdx]
      0002b	20 05 00 00 00
    	00		 and	 BYTE PTR temp, al
    
    ; 6    : }
    
      00031	c3		 ret	 0
    victim_function_v08 ENDP
    _TEXT	ENDS
    END
    
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	victim_function_v09
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    EXTRN	__ImageBase:BYTE
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 9\ex09.c
    ;	COMDAT victim_function_v09
    _TEXT	SEGMENT
    x$ = 8
    x_is_safe$ = 16
    victim_function_v09 PROC				; COMDAT
    
    ; 5    :      if (*x_is_safe)
    
      00000	83 3a 00	 cmp	 DWORD PTR [rdx], 0
      00003	74 21		 je	 SHORT $LN2@victim_fun
    
    ; 6    :           temp &= array2[array1[x] * 512];
    
      00005	48 8d 15 00 00
    	00 00		 lea	 rdx, OFFSET FLAT:__ImageBase
      0000c	0f b6 84 11 00
    	00 00 00	 movzx	 eax, BYTE PTR array1[rcx+rdx]
      00014	48 c1 e0 09	 shl	 rax, 9
      00018	0f b6 84 10 00
    	00 00 00	 movzx	 eax, BYTE PTR array2[rax+rdx]
      00020	20 05 00 00 00
    	00		 and	 BYTE PTR temp, al
    $LN2@victim_fun:
    
    ; 7    : }
    
      00026	c3		 ret	 0
    victim_function_v09 ENDP
    _TEXT	ENDS
    END
    
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	victim_function_v10
    EXTRN	array1_size:QWORD
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 10\ex10.c
    ;	COMDAT victim_function_v10
    _TEXT	SEGMENT
    x$ = 8
    k$ = 16
    victim_function_v10 PROC				; COMDAT
    
    ; 5    :     if (x < array1_size) {
    
      00000	48 3b 0d 00 00
    	00 00		 cmp	 rcx, QWORD PTR array1_size
      00007	73 19		 jae	 SHORT $LN3@victim_fun
    
    ; 6    :         if (array1[x] == k)
    
      00009	48 8d 05 00 00
    	00 00		 lea	 rax, OFFSET FLAT:array1
      00010	38 14 01	 cmp	 BYTE PTR [rcx+rax], dl
      00013	75 0d		 jne	 SHORT $LN3@victim_fun
    
    ; 7    :             temp &= array2[0];
    
      00015	0f b6 05 00 00
    	00 00		 movzx	 eax, BYTE PTR array2
      0001c	20 05 00 00 00
    	00		 and	 BYTE PTR temp, al
    $LN3@victim_fun:
    
    ; 8    :     }
    ; 9    : }
    
      00022	c3		 ret	 0
    victim_function_v10 ENDP
    _TEXT	ENDS
    END
    
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	victim_function_v11
    EXTRN	array1_size:QWORD
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 11\ex11.c
    ;	COMDAT victim_function_v11
    _TEXT	SEGMENT
    x$ = 8
    victim_function_v11 PROC				; COMDAT
    
    ; 5    :      if (x < array1_size)
    
      00000	48 3b 0d 00 00
    	00 00		 cmp	 rcx, QWORD PTR array1_size
      00007	73 3b		 jae	 SHORT $LN2@victim_fun
    
    ; 6    :           temp = memcmp(&temp, array2 + (array1[x] * 512), 1);
    
      00009	0f ae e8	 lfence
      0000c	48 8d 05 00 00
    	00 00		 lea	 rax, OFFSET FLAT:array1
      00013	0f b6 0c 08	 movzx	 ecx, BYTE PTR [rax+rcx]
      00017	48 8d 05 00 00
    	00 00		 lea	 rax, OFFSET FLAT:array2
      0001e	48 c1 e1 09	 shl	 rcx, 9
      00022	48 03 c8	 add	 rcx, rax
      00025	0f b6 05 00 00
    	00 00		 movzx	 eax, BYTE PTR temp
      0002c	3a 01		 cmp	 al, BYTE PTR [rcx]
      0002e	75 09		 jne	 SHORT $LN4@victim_fun
      00030	33 c0		 xor	 eax, eax
      00032	88 05 00 00 00
    	00		 mov	 BYTE PTR temp, al
    
    ; 7    : }
    
      00038	c3		 ret	 0
    $LN4@victim_fun:
    
    ; 6    :           temp = memcmp(&temp, array2 + (array1[x] * 512), 1);
    
      00039	1b c0		 sbb	 eax, eax
      0003b	83 c8 01	 or	 eax, 1
      0003e	88 05 00 00 00
    	00		 mov	 BYTE PTR temp, al
    $LN2@victim_fun:
    
    ; 7    : }
    
      00044	c3		 ret	 0
    victim_function_v11 ENDP
    _TEXT	ENDS
    END
    
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	victim_function_v12
    EXTRN	array1_size:QWORD
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    EXTRN	__ImageBase:BYTE
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 12\ex12.c
    ;	COMDAT victim_function_v12
    _TEXT	SEGMENT
    x$ = 8
    y$ = 16
    victim_function_v12 PROC				; COMDAT
    
    ; 5    :      if ((x + y) < array1_size)
    
      00000	48 8d 04 11	 lea	 rax, QWORD PTR [rcx+rdx]
      00004	48 3b 05 00 00
    	00 00		 cmp	 rax, QWORD PTR array1_size
      0000b	73 2b		 jae	 SHORT $LN2@victim_fun
    
    ; 6    :           temp &= array2[array1[x + y] * 512];
    
      0000d	0f ae e8	 lfence
      00010	4c 8d 05 00 00
    	00 00		 lea	 r8, OFFSET FLAT:__ImageBase
      00017	49 8d 80 00 00
    	00 00		 lea	 rax, QWORD PTR array1[r8]
      0001e	48 03 c1	 add	 rax, rcx
      00021	0f b6 04 10	 movzx	 eax, BYTE PTR [rax+rdx]
      00025	48 c1 e0 09	 shl	 rax, 9
      00029	42 0f b6 84 00
    	00 00 00 00	 movzx	 eax, BYTE PTR array2[rax+r8]
      00032	20 05 00 00 00
    	00		 and	 BYTE PTR temp, al
    $LN2@victim_fun:
    
    ; 7    : }
    
      00038	c3		 ret	 0
    victim_function_v12 ENDP
    _TEXT	ENDS
    END
    
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	is_x_safe
    PUBLIC	victim_function_v13
    EXTRN	array1_size:QWORD
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    EXTRN	__ImageBase:BYTE
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 13\ex13.c
    ;	COMDAT victim_function_v13
    _TEXT	SEGMENT
    x$ = 8
    victim_function_v13 PROC				; COMDAT
    
    ; 3    : __forceinline int is_x_safe(size_t x) { if (x < array1_size) return 1; return 0; }
    
      00000	48 3b 0d 00 00
    	00 00		 cmp	 rcx, QWORD PTR array1_size
      00007	73 21		 jae	 SHORT $LN2@victim_fun
    
    ; 7    :      if (is_x_safe(x))
    ; 8    :           temp &= array2[array1[x] * 512];
    
      00009	48 8d 15 00 00
    	00 00		 lea	 rdx, OFFSET FLAT:__ImageBase
      00010	0f b6 84 0a 00
    	00 00 00	 movzx	 eax, BYTE PTR array1[rdx+rcx]
      00018	48 c1 e0 09	 shl	 rax, 9
      0001c	0f b6 84 10 00
    	00 00 00	 movzx	 eax, BYTE PTR array2[rax+rdx]
      00024	20 05 00 00 00
    	00		 and	 BYTE PTR temp, al
    $LN2@victim_fun:
    
    ; 9    : }
    
      0002a	c3		 ret	 0
    victim_function_v13 ENDP
    _TEXT	ENDS
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 13\ex13.c
    ;	COMDAT is_x_safe
    _TEXT	SEGMENT
    x$ = 8
    is_x_safe PROC						; COMDAT
    
    ; 3    : __forceinline int is_x_safe(size_t x) { if (x < array1_size) return 1; return 0; }
    
      00000	33 c0		 xor	 eax, eax
      00002	48 3b 0d 00 00
    	00 00		 cmp	 rcx, QWORD PTR array1_size
      00009	0f 92 c0	 setb	 al
      0000c	c3		 ret	 0
    is_x_safe ENDP
    _TEXT	ENDS
    END
    
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	victim_function_v14
    EXTRN	array1_size:QWORD
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    EXTRN	__ImageBase:BYTE
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 14\ex14.c
    ;	COMDAT victim_function_v14
    _TEXT	SEGMENT
    x$ = 8
    victim_function_v14 PROC				; COMDAT
    
    ; 5    :      if (x < array1_size)
    
      00000	48 3b 0d 00 00
    	00 00		 cmp	 rcx, QWORD PTR array1_size
      00007	73 2b		 jae	 SHORT $LN2@victim_fun
    
    ; 6    :           temp &= array2[array1[x ^ 255] * 512];
    
      00009	0f ae e8	 lfence
      0000c	48 81 f1 ff 00
    	00 00		 xor	 rcx, 255		; 000000ffH
      00013	48 8d 15 00 00
    	00 00		 lea	 rdx, OFFSET FLAT:__ImageBase
      0001a	0f b6 84 11 00
    	00 00 00	 movzx	 eax, BYTE PTR array1[rcx+rdx]
      00022	48 c1 e0 09	 shl	 rax, 9
      00026	0f b6 84 10 00
    	00 00 00	 movzx	 eax, BYTE PTR array2[rax+rdx]
      0002e	20 05 00 00 00
    	00		 and	 BYTE PTR temp, al
    $LN2@victim_fun:
    
    ; 7    : }
    
      00034	c3		 ret	 0
    victim_function_v14 ENDP
    _TEXT	ENDS
    END
    
    ; Listing generated by Microsoft (R) Optimizing Compiler Version 19.38.33135.0 
    
    include listing.inc
    
    INCLUDELIB MSVCRT
    INCLUDELIB OLDNAMES
    
    PUBLIC	victim_function_v15
    EXTRN	array1_size:QWORD
    EXTRN	array1:BYTE
    EXTRN	array2:BYTE
    EXTRN	temp:BYTE
    EXTRN	__ImageBase:BYTE
    ; Function compile flags: /Ogtpy
    ; File C:\BCB\Paul Kocher\Example 15\ex15.c
    ;	COMDAT victim_function_v15
    _TEXT	SEGMENT
    x$ = 8
    victim_function_v15 PROC				; COMDAT
    
    ; 5    :      if (*x < array1_size)
    
      00000	48 8b 01	 mov	 rax, QWORD PTR [rcx]
      00003	48 3b 05 00 00
    	00 00		 cmp	 rax, QWORD PTR array1_size
      0000a	73 21		 jae	 SHORT $LN2@victim_fun
    
    ; 6    :           temp &= array2[array1[*x] * 512];
    
      0000c	48 8d 0d 00 00
    	00 00		 lea	 rcx, OFFSET FLAT:__ImageBase
      00013	0f b6 84 08 00
    	00 00 00	 movzx	 eax, BYTE PTR array1[rax+rcx]
      0001b	48 c1 e0 09	 shl	 rax, 9
      0001f	0f b6 84 08 00
    	00 00 00	 movzx	 eax, BYTE PTR array2[rax+rcx]
      00027	20 05 00 00 00
    	00		 and	 BYTE PTR temp, al
    $LN2@victim_fun:
    
    ; 7    : }
    
      0002d	c3		 ret	 0
    victim_function_v15 ENDP
    _TEXT	ENDS
    END
    • Madlyn Townsend @madlyntownsend ·

      When choosing an essay writing service, it’s important to consider factors like reliability, quality, and customer support. Some platforms stand out for their expertise and timely delivery https://speedypaper.com/blog/best-finance-schools. For those interested in finance, looking into the best finance schools can provide crucial insights. It’s essential to select services that align with academic and career goals for a smooth experience.

    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment