windows – ruby win32apistructs(VerQueryValue)
发布时间:2020-09-18 17:03:01 所属栏目:Windows 来源:互联网
导读:我试图使用 win32-api library调用标准的Win32 API函数来获取文件版本信息. 3 version.dll函数是GetFileVersionInfoSize,GetFileVersionInfo和VerQueryValue.然后我调用kernel32.dll中的RtlMoveMemory来获取VS_FIXEDFILEINFO结构的副本(请参阅Microsoft文档:
我试图使用 win32-api library调用标准的Win32 API函数来获取文件版本信息. 3 version.dll函数是GetFileVersionInfoSize,GetFileVersionInfo和VerQueryValue.然后我调用kernel32.dll中的RtlMoveMemory来获取VS_FIXEDFILEINFO结构的副本(请参阅Microsoft文档:http://msdn.microsoft.com/en-us/library/ms646997(VS.85).aspx). 我从使用VB看到的一个例子中得出:http://support.microsoft.com/kb/139491. 我的问题是最终返回的数据似乎与预期的结构不匹配,实际上它甚至没有返回一致的值.我怀疑数据在某些时候会被破坏,可能是在VerQueryValue或RtlMoveMemory中. 这是代码: GetFileVersionInfoSize = Win32::API.new('GetFileVersionInfoSize','PP','I','version.dll') GetFileVersionInfo = Win32::API.new('GetFileVersionInfo','PIIP','version.dll') VerQueryValue = Win32::API.new('VerQueryValue','PPPP','version.dll') RtlMoveMemory = Win32::API.new('RtlMoveMemory','PPI','V','kernel32.dll') buf = [0].pack('L') version_size = GetFileVersionInfoSize.call(myfile + " ",buf) raise Exception.new if version_size == 0 #TODO version_info = 0.chr * version_size version_ok = GetFileVersionInfo.call(file,version_size,version_info) raise Exception.new if version_ok == 0 #TODO addr = [0].pack('L') size = [0].pack('L') query_ok = VerQueryValue.call(version_info," ",addr,size) raise Exception.new if query_ok == 0 #TODO # note that at this point,size == 4 -- is that right? fixed_info = Array.new(13,0).pack('L*') RtlMoveMemory.call(fixed_info,fixed_info.length) # fixed_info.unpack('L*') #=> seemingly random data,usually only the first two dwords' worth and the rest 0.这是我工作的完整代码,以防其他人正在寻找这样的功能. 返回一个包含四个产品/文件版本号部分的数组(即,在dll文件属性窗口中称为“文件版本”): def file_version ref,options = {} options = {:path => LIBDIR,:extension => 'dll'}.merge(options) begin file = File.join(ROOT,options[:path],"#{ref}.#{options[:extension]}").gsub(///,"") buf = [0].pack('L') version_size = GetFileVersionInfoSize.call(file + " ",buf) raise Exception.new if version_size == 0 #TODO version_info = 0.chr * version_size version_ok = GetFileVersionInfo.call(file,version_info) raise Exception.new if version_ok == 0 #TODO addr = [0].pack('L') size = [0].pack('L') query_ok = VerQueryValue.call(version_info,size) raise Exception.new if query_ok == 0 #TODO fixed_info = Array.new(18,0).pack('LSSSSSSSSSSLLLLLLL') RtlMoveMemory.call(fixed_info,addr.unpack('L')[0],fixed_info.length) fixed_info.unpack('LSSSSSSSSSSLLLLLLL')[5..8].reverse rescue [] end end (编辑:岳阳站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Win10远程桌面 出现 身份验证错误,要求的函数不受支持,这
- windows下编译支持https的libcurl
- win10家庭版升级专业版出现0x80070422错误
- 适用于Windows的Theano安装,Python 3,64位
- window python2.7 ImportError: No module named MySQLdb
- 深度学习番外篇---WIN10+PyTorch0.4.0+CUDA9.1环境配置
- xaml – Windows 8 App,更改BackButtonStyle的颜色
- windows – 如何使wget正确安静?
- 如何在Windows PowerShell中进行屏幕截图?
- Windows系统·添加Python import 的库/模块路径
推荐文章
站长推荐
热点阅读