python - 如何在 Python 中模拟 XMM 寄存器行为
问题描述
如何实现与使用 128 位无符号整数汇编寄存器相同的行为。
例如右移时,最高有效位将被清零,或者当您左移时,总大小不会扩大,将继续保持 128 位。Numpy 只上升到 64 位整数。
这是一个实际的例子:
int128bits = 0x00000001000000010000000100000001
int128bits = int128bits << 0xff
期待:
int128bits = 0x00000000000000000000000000000000
现实:
int128bits = 0x8000000080000000800000008000000000000000000000000000000000000000000000000000000000000000
解决方案
我用 PeachPy 偶然发现的一个解决方案
from peachpy import *
from peachpy.x86_64 import *
def decrypt(dword1):
#Assembler instructions to Transform
x = Argument(uint64_t)
with Function("DotProduct", (x,), uint64_t) as asm_function:
#Load var and Shift right
LOAD.ARGUMENT(rax, x)
MOVQ(xmm2, rax)
MOVLHPS(xmm2, xmm2)
PSRLDQ(xmm2, 0xf)
MOVQ(rax, xmm1)
RETURN(rax)
#Read Assembler Return
python_function = asm_function.finalize(abi.detect()).encode().load()
return python_function(dword1)
print(decrypt(0x0000000100000001))
推荐阅读
- sql - #1452 - 无法添加或更新子行:外键约束失败 Policy_payment
- ruby-on-rails - gem install mimemagic -v '0.3.10' 无法在 Big Sur 上安装
- flutter - 如何使用flutters video_player或chewie或video_viewer插件播放m3u8链接?
- c - 如何在 cython 中调用 C 内联汇编 asm?
- python - 语义突出显示问题vscode windows 10
- c# - 即使使用控制器,MVC 视图也会返回 404 错误
- node.js - REST Post API - 从 TinyURL 方法检索结果
- flutter - 颤振中的多级下拉按钮 - 我们可以消除 if 语句吗?
- docker - 使用额外的 pip install 命令扩展 Dockerfile
- python - 从python中的mysql请求中获取错误