Skip to content

Instantly share code, notes, and snippets.

@danzek danzek/ewf_ext_helper.py
Last active Jan 2, 2018

Embed
What would you like to do?
EWF Extensions Helper
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Expert Witness Format (EWF) Extension Helper
Provides generator methods that provide the next expected file extension for EWF and EWF 2 file formats. For instance:
* E01
* E02
* ...
* E99
* EAA
* EAB
* ...
* EAZ
* EBA
* ...
* EZZ
* FAA
* ...
* ZZZ
It does this for E01, L01, Ex01, and Lx01 file extensions.
These generator functions follow the extension patterns identified in the libewf documentation provided by Joachim Metz
listed below:
- `EWF v1 Specification <https://53efc0a7187d0baa489ee347026b8278fe4020f6.googledrive.com/host/0B3fBvzttpiiSMTdoaVExWWNsRjg/Expert%20Witness%20Compression%20Format%20%28EWF%29.pdf>`_
- `EWF v2 Specification <https://53efc0a7187d0baa489ee347026b8278fe4020f6.googledrive.com/host/0B3fBvzttpiiSMTdoaVExWWNsRjg/Expert%20Witness%20Compression%20Format%202%20%28EWF2%29.pdf>`_
-----------------------------------------
Copyright (c) 2016, Dan O'Day (d@4n68r.com)
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
__author__ = "Dan O'Day"
__copyright__ = "Copyright 2016, Dan O'Day (d@4n68r.com)"
__credits__ = "Joachim Metz"
__license__ = "MIT"
__maintainer__ = "Dan O'Day"
__email__ = "d@4n68r.com"
class EWFExtensionGenerators(object):
@staticmethod
def _ext_num_formatter(prefix, n):
return "{pre}{num}".format(pre=prefix.lower(), num=str(n).zfill(2))
@staticmethod
def _ext_char_formatter(char1, char2, char3):
return "{one}{two}{three}".format(one=char1, two=char2, three=char3)
@staticmethod
def _next_letter(current_letter):
return chr(ord(current_letter) + 1)
def _next_ewf_ext(self, prefix, version=1):
if version == 1:
antepenultimate_char = prefix
elif version == 2:
antepenultimate_char = 'x'
else:
raise RuntimeError("Invalid EWF version")
penultimate_char = 'a'
final_char = 'a'
n = 1
if version == 1:
ext = self._ext_num_formatter(antepenultimate_char, n) # initial value (always starts with prefix + number)
else:
ext = self._ext_num_formatter(prefix + antepenultimate_char, n)
while n <= 99: # 'e99'
if version == 1:
ext = self._ext_num_formatter(antepenultimate_char, n)
else:
ext = self._ext_num_formatter(prefix + antepenultimate_char, n)
yield ext
n += 1
while ext[-3:] != 'zzz':
if version == 1:
ext = self._ext_char_formatter(antepenultimate_char, penultimate_char, final_char)
else:
ext = self._ext_char_formatter(prefix + antepenultimate_char, penultimate_char, final_char)
yield ext
if final_char != 'z':
final_char = self._next_letter(final_char)
else: # last char is 'z'
if penultimate_char != 'z':
final_char = 'a'
penultimate_char = self._next_letter(penultimate_char)
else: # penultimate and last chars are 'z'
if antepenultimate_char != 'z':
penultimate_char = 'a'
final_char = 'a'
antepenultimate_char = self._next_letter(antepenultimate_char)
def e01_generator(self):
g = self._next_ewf_ext('e')
for ext in g:
yield ext
def l01_generator(self):
g = self._next_ewf_ext('l')
for ext in g:
yield ext
def ex01_generator(self):
g = self._next_ewf_ext('e', version=2)
for ext in g:
yield ext
def lx01_generator(self):
g = self._next_ewf_ext('l', version=2)
for ext in g:
yield ext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.