-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinteger floats.reg
More file actions
303 lines (132 loc) · 7.42 KB
/
integer floats.reg
File metadata and controls
303 lines (132 loc) · 7.42 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Cheat Engine\CustomTypes\Float (Integers)]
"Script"="// Courtesy of mgr.inz.Player http://forum.cheatengine.org/viewtopic.php?p=5735458#5735458
alloc(ConvertRoutine,1024)
alloc(ConvertBackRoutine,1024)
alloc(TypeName,256)
alloc(ByteSize,4)
alloc(UsesFloat,1)
alloc(CallMethod,1)
TypeName:
db 'Float (Integers)',0
ByteSize:
dd 4
UsesFloat:
db 1
CallMethod:
db 1
ConvertRoutine:
[64-bit]
mov eax,[rcx]
[/64-bit]
[32-bit]
mov eax,[esp+4]
mov eax,[eax]
[/32-bit]
movd xmm0,eax
cvtps2dq xmm1,xmm0 // convert single to integer
cvtdq2ps xmm1,xmm1 // convert integer to single
ucomiss xmm0,xmm1
je @f
mov eax,NaN
@@:
ret
// Taken from ParkourPenguin's script below since mgr.inz.Player's was readonly (just ret)
// cdecl void ConvertBackRoutine(int i, PTR_UINT address, unsigned char *output);
ConvertBackRoutine:
[64-bit]
mov [r8],ecx
ret
[/64-bit]
[32-bit]
mov eax,[esp+4]
mov ecx,[esp+C]
mov [ecx],eax
ret
[/32-bit]
/*
// lower level version courtesy of ParkourPenguin
// http://forum.cheatengine.org/viewtopic.php?p=5735442#5735442
alloc(ConvertRoutine,1024)
alloc(ConvertBackRoutine,1024)
alloc(TypeName,256)
alloc(ByteSize,4)
alloc(UsesFloat,1)
alloc(CallMethod,1)
TypeName:
db 'Float (Integers)',0
ByteSize:
dd 4
UsesFloat:
db 1
CallMethod:
db 1
//cdecl int ConvertRoutine(unsigned char *input, PTR_UINT address);
ConvertRoutine:
[64-bit]
// http://steve.hollasch.net/cgindex/coding/ieeefloat.html
// anatomy of a float / real32
// 1 Sign Bit, 8 Exponent bits, 23 mantissa bits
// S EEEEEEEE MMMMMMMM MMMMMMMM MMMMMMM_
// SEEEEEEE EMMMMMMM MMMMMMMM MMMMMMMM
// shr 0x17 = remove mantissa, S EEEEEEEE
mov eax,7fc00000 // QNaN default return value
mov edx,[rcx] // read float into edx
mov ecx,edx // copy float into ecx
shr ecx,0x17 // remove mantissa and put expontent into cl
inc cl // increment exponent
jns @f // return NaN if exponent is less than 127, which is actually 0 because reasons
// since negative exponents = dividing and if you're dividing you're not going to end up with a whole number
// this also excludes infinity and NaN which have an exponent of all 1s, +1 = 0, which is not signed
and ecx,7F // remove original sign bit and exponent sign bit (which was 1 or we'd have jumped ^)
// so 0 = 127, +1 = 128, &7F = 0
// 22 = 127+22 = 149, +1 = 150, &7F = 22 etc.
add ecx,9 // add 9 to exponent to account for sign and exponent bits later
mov r8d,edx // copy original value
and r8d,007fffff // keep only 23 mantissa bits
shl r8d,cl // shift mantissa by exponent (at least 9)
// with regards to C, it's undefined behaviour to shift a 32-bit value by >=32 positions
// in assembly, it's probably faster to check if any of bits 5-7 are set
test cl,E0 // test that exponent is greater than 32
cmovnz eax,edx // if set return original value
test r8d,r8d // if mantissa is now 0
cmovz eax,edx // return original value
@@:
ret
[/64-bit]
[32-bit]
push ebx
mov eax,[esp+8]
mov edx,[eax]
mov eax,7fc00000
mov ecx,edx
shr ecx,17
inc cl
jns @f
and ecx,7f
mov ebx,edx
and ebx,007fffff
add ecx,09
shl ebx,cl
test cl,60
cmovnz eax,edx
test ebx,ebx
cmovz eax,edx
@@:
pop ebx
ret
[/32-bit]
// cdecl void ConvertBackRoutine(int i, PTR_UINT address, unsigned char *output);
ConvertBackRoutine:
[64-bit]
mov [r8],ecx
ret
[/64-bit]
[32-bit]
mov eax,[esp+4]
mov ecx,[esp+C]
mov [ecx],eax
ret
[/32-bit]
*/
"