2013-02-08 51 views
0

我正在使用python msilib庫讀取MSI文件。我的目標是從二進制表中提取[Binary Data]並將其轉儲到文件中。 (使用ORCA工具,我們可以通過雙擊[Binary Data]單元並寫入文件來提取二進制數據)如何從MSI文件中獲取[Binary Data]值

我無法找到任何msilib方法來獲取二進制數據。它有使用Record.GetString(field)獲取字符串數據的方法。但正如預期的那樣,這對[二進制數據]不起作用並給出錯誤。

這裏是代碼片段

import msilib 
# msi file path which is to be read 
msiFilePath = "C:/msi/test.msi" 
dbObj = msilib.OpenDatabase(msiFilePath, msilib.MSIDBOPEN_READONLY) 
sqlQuery = "select * from Binary" 
view = dbObj.OpenView(sqlQuery) 
view.Execute(None) 
cur_record = viewObj.Fetch() 
# In Binary table; Column no 1 have string data and Column # 2 have [Binary Data] 
cur_record.GetString(2) 

而且在執行: -

Traceback (most recent call last): 
File "<pyshell#17>", line 1, in <module> 
cur_record.GetString(2) 
_msi.MSIError: unknown error 70c 

有沒有辦法做到這一點?

回答

7

msilibnot fully featured。具體來說,它不能讀取二進制數據。

Pygame的舉辦更全功能和可擴展性(因爲它是一個用Python編寫的ctypes)msidb。它似乎沒有在pygame文檔中涵蓋,但源代碼非常簡單。

您所需要的MSI API是MsiRecordReadStream這pygame.msidb在get_field_stream包裝所使用由其Cursor類。

+0

@aberry,有什麼我可以做,讓這個答案更容易接受你? – jimhark