class FirmwareHomie

Defines a class for storing all attributes of a Homie-firmware. Check kind of esp8266-firmware: Homie (>= V.2.0 because of magic bytes) Homie: see github.com/marvinroger/homie-esp8266 Returns hash with fw-details if <filename> includes magic bytes, returns empty hash if doesn't

Attributes

checksum[R]
file_path[R]
fw_brand[R]
fw_name[R]
fw_version[R]

Public Class Methods

new(filename) click to toggle source

Initialize a firmware-file for Homie-device. File is recognized by so called Homie-patterns (strings in binary file) that can be injected through sourcecode. Possible patterns are firmware-name, firmware-version and firmware-brand.

# File lib/hodmin/hodmin_tools.rb, line 29
def initialize(filename)
  @firmware_homie = false
  return unless homie_firmware?(filename)
  @file_path = filename
  @firmware_homie = true
  binfile = IO.binread(filename)
  @checksum = Digest::MD5.hexdigest(binfile)
  binfile = binfile.unpack('H*').first

  fw_name_pattern    = ["\xbf\x84\xe4\x13\x54".unpack('H*').first, "\x93\x44\x6b\xa7\x75".unpack('H*').first]
  fw_version_pattern = ["\x6a\x3f\x3e\x0e\xe1".unpack('H*').first, "\xb0\x30\x48\xd4\x1a".unpack('H*').first]
  fw_brand_pattern   = ["\xfb\x2a\xf5\x68\xc0".unpack('H*').first, "\x6e\x2f\x0f\xeb\x2d".unpack('H*').first]

  @fw_brand = @fw_name = @fw_version = '<none>'
  # find Firmware-Branding
  @fw_brand = fw_brand_pattern.find_pattern(binfile)
  # find Firmware-Name:
  @fw_name = fw_name_pattern.find_pattern(binfile)
  # find Firmware-Version:
  @fw_version = fw_version_pattern.find_pattern(binfile)
  Log.log.info "FW found: #{@fw_name}, #{@fw_version}, #{@checksum}"
end

Public Instance Methods

homie?() click to toggle source
# File lib/hodmin/hodmin_tools.rb, line 52
def homie?
  @firmware_homie
end