-
Notifications
You must be signed in to change notification settings - Fork 20
/
0x37.asm
44 lines (40 loc) · 1.24 KB
/
0x37.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
;
; $Id: 0x37.asm,v 1.1.1.1 2016/03/27 08:40:13 raptor Exp $
;
; 0x37 explanation - from xchg rax,rax by [email protected]
; Copyright (c) 2016 Marco Ivaldi <[email protected]>
;
; This snippet takes the value in rax and replaces each 0x00 byte
; (including leading zeros) with a 0x80, setting any other byte
; to 0x00.
;
; Here are a couple of interesting observations:
; - In 0x0101010101010101 the last bit of each byte is set, that is:
; 0b0000000100000001000000010000000100000001000000010000000100000001
; - In 0x8080808080808080 the first bit of each byte is set, that is:
; 0b1000000010000000100000001000000010000000100000001000000010000000
;
; I've written the following C code to help with the analysis:
; #include <stdio.h>
; main()
; {
; long long rax, i;
; for (i = 0x00; i < 0xff; i++) {
; rax = i;
; rax = (rax - 0x0101010101010101) & (~rax & 0x8080808080808080);
; printf("in:\t0x%llx\t\tout:\t0x%llx\n", i, rax);
; }
; }
;
BITS 64
SECTION .text
global main
main:
mov rdx,rax ;
not rdx ;
mov rcx,0x8080808080808080 ;
and rdx,rcx ; rdx = ~rax & 0x8080808080808080
mov rcx,0x0101010101010101 ;
sub rax,rcx ; rax = rax - 0x0101010101010101
and rax,rdx ;
; rax = (rax - 0x0101010101010101) & (~rax & 0x8080808080808080)