日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

VHD(Virtual Hard Disk)的解析(上篇)——PyVinil的使用

發(fā)布時(shí)間:2025/3/20 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 VHD(Virtual Hard Disk)的解析(上篇)——PyVinil的使用 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

前言:

? 最近接到一個(gè)新的任務(wù),是關(guān)于虛擬化的中的虛擬磁盤文件(VHD)的。一開始的思路就是去尋找一些相關(guān)的源碼工具,或是相關(guān)的庫(C/Java/Python都o(jì)k的)。不好找,以下就是關(guān)于Python工具源碼——PyVinil。版本為PyVinil-0.1.0.


概述:

? VHD 是Microsoft Virtual Hard Disk format(微軟虛擬磁盤文件)的簡稱。可以由Microsoft Virtual PC2007,Windows Vista,Windows 7/8,Hyper-V,Windows Server 2008R2/2012,Microsoft Virtual Server 2005等創(chuàng)建,Virtual Box,VMWare等可以掛載使用。
? VHD文件格式可以被壓縮成單個(gè)文件存放在宿主機(jī)器的文件系統(tǒng)上,主要包括虛擬機(jī)啟動(dòng)所需系統(tǒng)文件。


本文鏈接:http://blog.csdn.net/lemon_tree12138/article/details/49664873 --?編程小笙
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?--轉(zhuǎn)載請注明出處


筆者環(huán)境:

1.系統(tǒng)環(huán)境:

? CentOS 6.5

? python 2.7.3??
? gcc version 4.4.7
? gcc-c++

2.依賴環(huán)境:

? CMake v2.8.3 # yum
? Check v0.9.8 # 下載安裝包
? Doxygen 1.7.4 # yum

? libvinil # 下載安裝包

? libuuid-devel


依賴環(huán)境的安裝:

1.CMake v2.8.3

? # yum -y install cmake

2.Check v0.9.8

? # 下載安裝包

? #?cd package_home/

? # ./configure

? # make install

3.Doxygen 1.7.4

? # yum -y install doxygen

4.libuuid-devel

? # yum -y install libuuid-devel

5.libvinil

? # 下載安裝包

? # cd package_home/

? # cmake . # 注意此處要有一個(gè)'.'

? # make & make install



PyVinil的使用

1.小試牛刀

? 在我們的依賴環(huán)境都OK了之后,我們就可以下載PyVinil,并使用了。

? 筆者這里的PyVinil使用的是v-0.1.0版本。安裝過程如下:

? # python setup.py build

? # python setup.py install

? 安裝完成之后,我們可以進(jìn)行如下操作:

??


2.代碼測試

# encoding=utf-8from pyvinil.vhd import VHD from pyvinil import utilsdef main():vhd = VHD.open("/root/upload/new.vhd")vhd.footer.disk_type = 3vhd.footer.uuid = utils.uuid_generate()print '-' * 50print "pointer: ", vhd.vhd_pointer.valueprint '-' * 50print "DLL: ", vhd.vinil_dllprint '-' * 50print "Footer: ", vhd.footerprint "disk_type: ", vhd.footer.disk_typeprint "real: ", vhd.footer.disk_type.realprint "denominator: ", vhd.footer.disk_type.denominatorprint "imag: ", vhd.footer.disk_type.imagprint "numerator: ", vhd.footer.disk_type.numeratorprint "bit_length: ", vhd.footer.disk_type.bit_length()print "UUID: ", get_string_Hex_nox(vhd.footer.uuid)print "COMMIT: ", vhd.commit_structural_changes()print '-' * 50print "TELL: ", vhd.tell()print '-' * 50vhd_read = vhd.read(1)print "READ ", vhd_read.title(), ":"print "TITLE : ", vhd_read.title()print "CAPITALIZE : ", vhd_read.capitalize()print "FORMAT : ", vhd_read.format()print "ISALNUM : ", vhd_read.isalnum()print "ISALPHA : ", vhd_read.isalpha()print "ISDIGIT : ", vhd_read.isdigit()print "ISLOWER : ", vhd_read.islower()print "ISSPACE : ", vhd_read.isspace()print "ISTITLE : ", vhd_read.istitle()print "ISUPPER : ", vhd_read.isupper()print '-' * 50print "TELL: ", vhd.tell()print '-' * 50vhd_read_2 = vhd.read(2)print "READ ", vhd_read_2.title(), ":"print "TITLE : ", vhd_read_2.title()print "CAPITALIZE : ", vhd_read_2.capitalize()print "FORMAT : ", vhd_read_2.format()print "ISALNUM : ", vhd_read_2.isalnum()print "ISALPHA : ", vhd_read_2.isalpha()print "ISDIGIT : ", vhd_read_2.isdigit()print "ISLOWER : ", vhd_read_2.islower()print "ISSPACE : ", vhd_read_2.isspace()print "ISTITLE : ", vhd_read_2.istitle()print "ISUPPER : ", vhd_read_2.isupper()# 將一個(gè)可見字符串轉(zhuǎn)成其對應(yīng)的十六進(jìn)制表示 def get_string_Hex_nox(substr):byte_list = bytearray(substr)hexStr = ''for item in byte_list:tmp = hex(item)[2:]if len(tmp) % 2 == 1:tmp = '0' + tmphexStr += tmpreturn hexStrif __name__ == '__main__':main()

3.測試結(jié)果

[root@localhost python]# python test_vhd.py -------------------------------------------------- pointer: 31212112 -------------------------------------------------- DLL: <CDLL 'libvinil.so', handle 1e1ac50 at 7fd287189490> -------------------------------------------------- Footer: <pyvinil.vhd.VHDFooterStructure object at 0x7fd2871d35f0> disk_type: 3 real: 3 denominator: 1 imag: 0 numerator: 3 bit_length: 2 UUID: dc88c8c382a94d06bd86d0aa898b02f6 COMMIT: None -------------------------------------------------- TELL: 0 -------------------------------------------------- READ Conectix : TITLE : Conectix CAPITALIZE : Conectix FORMAT : conectix ISALNUM : True ISALPHA : True ISDIGIT : False ISLOWER : True ISSPACE : False ISTITLE : False ISUPPER : False -------------------------------------------------- TELL: 1 -------------------------------------------------- READ Cxsparse???????? : TITLE : Cxsparse???????? CAPITALIZE : Cxsparse???????? FORMAT : cxsparse???????? ISALNUM : False ISALPHA : False ISDIGIT : False ISLOWER : True ISSPACE : False ISTITLE : False ISUPPER : False [root@localhost python]#

小結(jié):

? 從以上的測試和結(jié)果來看,可以看到這個(gè)工具并沒有提供給我們更多的內(nèi)容。這些結(jié)果我們本就可以通過參考VHD結(jié)構(gòu)文檔手動(dòng)去解析獲得。

? 不過從PyVinil-0.1.0的源碼以及系統(tǒng)環(huán)境的配置過程來看,這里只是對相關(guān)的C的庫函數(shù)的調(diào)用而已。所以,要想從這里獲得更多的信息,可能已經(jīng)走不通了。在后期的調(diào)研中,我們要做的事情是自己動(dòng)手來解析VHD.或是通過一些磁盤掛載程序來掛載硬盤,再從掛載后的磁盤里讀數(shù)據(jù)。(關(guān)于掛載vhd磁盤,其實(shí)也并非易事。下篇博客再作介紹吧。)

總結(jié)

以上是生活随笔為你收集整理的VHD(Virtual Hard Disk)的解析(上篇)——PyVinil的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。