Class: Resilience::MBR

Inherits:
BootTable show all
Defined in:
lib/resilience/tables/boot.rb

Constant Summary collapse

SIG_ADDRESS =
0x1FE
SIG =
[0x55, 0xAA]
PARTITION_ADDRESSES =
[0x1C6, 0x1D6, 0x1E6, 0x1F6]

Constants inherited from BootTable

BootTable::SECTOR_SIZE

Instance Method Summary collapse

Methods inherited from BootTable

#refs_offset, #refs_offsets

Methods included from OnImage

#image, image, included, restore_pos, #restore_pos, store_pos, #store_pos

Instance Method Details

#detected?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/resilience/tables/boot.rb', line 33

def detected?
  image.seek SIG_ADDRESS
  sig = image.read(2)
  sig == SIG
end

#fs_offsetsObject



39
40
41
42
43
44
45
46
47
# File 'lib/resilience/tables/boot.rb', line 39

def fs_offsets
  offsets = []
  PARTITION_ADDRESSES.each do |address|
    image.seek address
    address = image.read(4).unpack('V').first
    offsets << address * SECTOR_SIZE unless address == 0
  end
  offsets
end

#gpt_offsetObject



59
60
61
# File 'lib/resilience/tables/boot.rb', line 59

def gpt_offset
  gpt_offsets.first
end

#gpt_offsetsObject



49
50
51
52
53
54
55
56
57
# File 'lib/resilience/tables/boot.rb', line 49

def gpt_offsets
  offsets = []
  fs_offsets.each do |address|
    image.seek address
    sig = image.read(GPT::SIG.size).unpack('C*')
    offsets << address if sig == GPT::SIG
  end
  offsets
end