Closed wkingnet closed 3 years ago
After several hours of trying, I wrote a small piece of code to convert float to hex, which worked very well
def float2hex(_float):
import struct
result = ""
for i in struct.pack('f', _float):
i = hex(i)[2:]
if len(i) % 2 == 1:
i = "0" + i
result = result + i
result = "68" + result # 68 means "push" 0x????
return result
code += x86.Raw(float2hex(pos_dst_y - pos_cur_y))
Hello,
Thank you for the issue, and well done for the solution.
As none of simple_x86
and simple_x64
implement any float instruction, and as I am not that familiar with CPython float
representation nor IEEE Standard for Floating-Point Arithmetic (IEEE 754)
. I think that trying float interpretation here would break more thing than the potential benefit.
For your use-case what you should be able to do is something similar to your solution by using struct to reeinterpret a float as a int with :
def float_as_int(_float):
return struct.unpack("<I", struct.pack("f", _float))[0]
>>> windows.native_exec.simple_x86.Push(float_as_int(22271.2)).get_code()
b'hf\xfe\xadF'
Even here, I am not sur this is the exact result you are looking for.
Hi, I'm here again. I'm continuing to hack my game, now I am studying how to control the game characters to walk. This part of the work requires the construction of several floating-point stack parameters.
Now i have a new problem. It seems that PythonForWindows cannot assemble float correctly.
this is my python code:
In game, the assembly stack of the game itself is like this, float 32bit:
But if running the code through python, the stack parameter becomes unsigned short 16bit:
debug in pycharm, it is still float variable:
So, how can I correctly assemble floating-point numbers?
By the way, could you update the version on Pypi? It will be very convenient for users to update
Thanks.