python - 为什么我在系统 DLL 上的 Powershell 和 32 位 Python 之间得到不同的 SHA1 哈希值?

标签 python powershell x86 64-bit

我正在尝试针对二进制文件计算 Python 中的 SHA1 哈希值,以便稍后进行比较。为了确保一切正常,我使用了几种方法来检查结果的有效性。而且,我很高兴我做到了。 Powershell 和 Python 返回不同的值。 7zip 的 SHA1 函数与 Powershell 的结果一致,Microsoft 的 FCIV 与 Python 的结果一致。

python :

import hashlib
with open("C:\\Windows\\system32\\wbem\\wmiutils.dll", "rb") as f:
     print(hashlib.sha1(f.read()).hexdigest())

电源外壳:

PS C:\> Get-FileHash C:\Windows\System32\wbem\wmiutils.dll -Algorithm SHA1

结果:

Python: d25f5b57d3265843ed3a0e7b6681462e048b29a9
Powershell: B8C757BA70F6B145AD191A1B09C225FBA2BD55FB

EDIT: 32-bit Python and 64-bit Powershell against a system32 dll. That was the problem. I have some homework to do but basically, 32-bit and 64-bit applications receive a different file and thus, different hash results. I launched 64-bit python and ran the exact same code against the dll and as a 64-bit powershell process. Received consistent results when running both processes as 32-bit.

EDIT2: Found this resource that explains things a bit. At least it helped me understand what's going on: https://www.sepago.com/blog/2008/04/20/windows-x64-all-the-same-yet-very-different-part-7-file-system-and-registry

最佳答案

发生这种情况是因为您正在运行 32 位版本的 Python 并访问系统 dll——Windows 神奇地将您重定向到 32 位版本的 dll,而 PowerShell 作为 64 位进程运行并看到 64 位版本的 DLL .

我不确定我是庆幸我知道这一点还是感到悲伤。

关于python - 为什么我在系统 DLL 上的 Powershell 和 32 位 Python 之间得到不同的 SHA1 哈希值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32857015/

相关文章:

azure - 将 Azure 应用服务添加到新的 VNet 集成预览

powershell - 如何更改 PowerShell 的辅助/多行 (>>) 提示符

x86 - x86 遗留指令的解释

python - tf.gfile 在 TensorFlow 中做了什么?

python - GridSearchCV 结果热图

powershell - 使用多个psobject时,Get-Member不返回NoteProperty

assembly - 编译器可以优化汇编中的函数前导码吗?

assembly - AT&T 到 Intel 汇编转换器

python - 如何根据或/或比较合并 2 个数据帧?

python - 为什么 requests.get() 不返回? requests.get() 使用的默认超时是多少?