selph
selph
发布于 2022-03-30 / 396 阅读
0
0

《xchg rax,rax》片段分析0x20--乘以1337

前言

本次是该系列的的第0x20篇,本篇介绍了一个数通过shl和and的方法给一个数乘以1337,不知道这是什么意思


实验环境:

  • Windows10 + VS2022 + masm

0x20

代码片段链接:xorpd | xchg rax,rax 0x20

mov      rcx,rax
shl      rcx,2
add      rcx,rax
shl      rcx,3
add      rcx,rax
shl      rcx,1
add      rcx,rax
shl      rcx,1
add      rcx,rax
shl      rcx,3
add      rcx,rax

代码分析

给定rax = 0x1,输出0x539

给定rax = 0x5,输出5*0x539 = 0x1a1d

给定rax = 0x10,输出0x5390

0x539 = 1337

该片段的功能是rcx = rax*1337

测试代码:

.code
main proc
    mov     rax, 005h

	mov      rcx,rax	; rcx = rax
	shl      rcx,2		; rcx = rcx << 2
	add      rcx,rax	; rcx = rcx + rax
	shl      rcx,3		; rcx = rcx << 3
	add      rcx,rax	; rcx = rcx + rax
	shl      rcx,1		; rcx = rcx << 1
	add      rcx,rax	; rcx = rcx + rax
	shl      rcx,1		; rcx = rcx << 1
	add      rcx,rax	; rcx = rcx + rax
	shl      rcx,3		; rcx = rcx << 3
	add      rcx,rax	; rcx = rcx + rax

	ret
main ENDP
END

评论