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
45
46
47
48
49
50
|
; Version : 0.1
; Last update : 7/3/2020
; Description : A self modifying opcode test for the ror instruction. Returns 0 if the instruction gives the expected answer, or exits with "illegal instruction" if not.
; Copyright (C) : 2020 Gentoo-libre Install
; License : GPLv3+
section .data
modify: ror edx, 2 ;this is modified to the wanted ror bitshift amount
ret
section .text
global _start
_start:
mov eax,31 ;the amount to right rotate edx by (Cannot be greater than 31)
cmp eax,1 ;ror by 1 and ror 2-32 have different opcodes
ja twoplus ;if eax > 1, ror will have the second opcode
mov edx,2 ;the original number
mov byte[modify],0xD1 ;change to single right rotate opcode
mov byte[modify+1],0xCA ;edx is the register used
mov byte[modify+2],0xC3 ;place the ret opcode one up, since the instruction has shrunk by one byte
call modify ;call the changed ror instruction
cmp edx,1 ;check result
je Exit ;return 0 if the correct value is recieved
ud2 ;otherwise, illegal instruction
twoplus:
;c1 ca 02
mov byte[modify+2],al ;overwrite the 0x02 in the instruction with new number
mov edx,8 ;the original number
call modify ;call the modified ror instruction
cmp edx,16 ;check result
je Exit ;return 0 if correct value is reached
ud2 ; otherwise, return illegal instruction
Exit:
mov eax,60 ;code for sys_exit
xor edi,edi ;Return value of 0
syscall ;Do sys_exit
|