Skip to content

Development

Joachim Metz edited this page Sep 11, 2016 · 4 revisions

Python development

Get version

import pyvhdi

pyvhdi.get_version()

Open file

import pyvhdi


vhdi_file = pyvhdi.file()

vhdi_file.open("image.vhd")

vhdi_file.close()

The explicit call to vhdi_file.close() is not required.

Open file using a file-like object

import pyvhdi


file_object = open("image.vhd", "rb")

vhdi_file = pyvhdi.file()

vhdi_file.open_file_object(file_object)

vhdi_file.close()

The explicit call to vhdi_file.close() is not required.

Combining pyvhdi with pytsk3

import pyvhdi
import pytsk3


class vhdi_Img_Info(pytsk3.Img_Info):
  def __init__(self, vhdi_file):
    self._vhdi_file = vhdi_file
    super(vhdi_Img_Info, self).__init__(
        url="", type=pytsk3.TSK_IMG_TYPE_EXTERNAL)

  def close(self):
    self._vhdi_file.close()

  def read(self, offset, size):
    self._vhdi_file.seek(offset)
    return self._vhdi_file.read(size)

  def get_size(self):
    return self._vhdi_file.get_media_size()


vhdi_file = pyvhdi.file()

vhdi_file.open("image.vhd")

img_info = vhdi_Img_Info(vhdi_file)

fs_info = pytsk3.FS_Info(img_info, offset=63 * 512)

Also see

import pyvhdi

help(pyvhdi)
help(pyvhdi.file)
Clone this wiki locally