Sha256: f1c7407e29ffef65805784edd09f8259dd8eaa7b410b4e7ce852770708e272f9

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

#!/usr/bin/env ruby

$:.unshift File.expand_path('../lib', __dir__)
require_relative '../lib/smcutil'
require 'optparse'

BANNER = <<-BANNER
  Usage: smcutil {command} [PARAMS]

  Command is one of:

    validate {file.smc}:
      Causes smcutil to parse the Apple SMC file and validate correctness and signature.

    info {file.smc}:
      Prints information about the SMC update file.

    decode {file.smc} {output.bin}:
      Pretends to execute an update of the SMC flash as though the output.bin file is the SMC flash ROM.

      The output can then be loaded with the ROMs to allow for emulation / analysis.

    shred {file.smc} {output_directory}:
      As smc files may re-flash the same region multiple times, this outputs each flash page to a folder without
      overwriting and suffixing the region with the pass.

    save {output.bin}:
      Has magical cow powers.  Assuming I can make this work: GOLDEN TICKET
BANNER

def show_usage
  puts BANNER
  exit
end

command = (ARGV.shift || '').to_sym

COMMANDS = [ :validate, :info, :decode, :save, :shred ]

show_usage unless COMMANDS.include? command

case command
  when :validate
    begin
    file = ARGV.shift
    show_usage unless file
    reader = SmcUtil::FileReader.parse file

    validator = SmcUtil::FileValidator.new reader

    if validator.valid?
      puts "The file '#{file}' is valid."
    else
      validator.errors.each do |error|
        puts "ERROR: #{error}"
      end
    end
    rescue => ex
      puts ex
      puts ex.backtrace
    end
  when :decode, :shred
    begin
      input = ARGV.shift
      output = ARGV.shift

      show_usage unless input && output
      reader = SmcUtil::FileReader.parse input
      extractor = SmcUtil::FileExtractor.new reader

      if command == :decode
        extractor.extract_to output
      else
        extractor.shred_to output
      end
    rescue => ex
      puts ex
      puts ex.backtrace
    end
  when :info

  else
    show_usage
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
smcutil-0.1.6 exe/smcutil
smcutil-0.1.5 exe/smcutil