133 lines
3 KiB
Text
133 lines
3 KiB
Text
|
#!/usr/bin/ruby -d
|
||
|
|
||
|
require 'optparse'
|
||
|
|
||
|
require 'rubygems'
|
||
|
require 'bindata'
|
||
|
|
||
|
class XtmHeader < BinData::Record
|
||
|
# Offset Information Taille (octets)
|
||
|
# 0 Longueur du nom du programme 1
|
||
|
# 1 *Nom du programme 20
|
||
|
# 21 Longueur de la version 1
|
||
|
# 22 Version 4
|
||
|
# 26 Not used 10
|
||
|
# 36 Date 4
|
||
|
# 40 Longueur du nom du fichier original 1
|
||
|
# 41 Nom du fichier original 50
|
||
|
# 91 **Hash MD5 1
|
||
|
# 92 Nombre de fichiers 4
|
||
|
# 96 Taille du fichier original 8
|
||
|
|
||
|
endian :little
|
||
|
|
||
|
uint8 :progname_len, :value => lambda { progname_str.length }
|
||
|
string :progname_str, :length => 20
|
||
|
|
||
|
uint8 :version_len, :value => lambda { version_str.length }
|
||
|
string :version_str, :length => 4
|
||
|
|
||
|
string :unused, :length => 10
|
||
|
|
||
|
uint32le :date
|
||
|
|
||
|
uint8 :filename_len
|
||
|
stringz :filename_str, :length => 50
|
||
|
string :filename_str_pad, :length => lambda { 50 - filename_len - 1 }
|
||
|
|
||
|
uint8 :md5
|
||
|
|
||
|
uint32 :filecount
|
||
|
uint64 :filesize
|
||
|
|
||
|
def to_s
|
||
|
r = []
|
||
|
r << ( "Progname len : %s [%s]" % [self.progname_len, self.progname_len.offset] )
|
||
|
r << ( "Progname str : %s [%s]" % [self.progname_str, self.progname_str.offset] )
|
||
|
r << ( " Version len : %s [%s]" % [self.version_len, self.version_len.offset] )
|
||
|
r << ( " Version str : %s [%s]" % [self.version_str, self.version_str.offset] )
|
||
|
r << ( " Unused : %s [%s]" % [self.unused, self.unused.offset] )
|
||
|
r << ( " Date : %s [%s]" % [self.date, self.date.offset] )
|
||
|
r << ( "Filename len : %s [%s]" % [self.filename_len, self.filename_len.offset] )
|
||
|
r << ( "Filename str : %s [%s]" % [self.filename_str, self.filename_str.offset] )
|
||
|
r << ( " md5 : %s [%s]" % [self.md5, self.md5.offset] )
|
||
|
r << ( " Filecount : %d [%s]" % [self.filecount, self.filecount.offset] )
|
||
|
r << ( " Filesize : %s [%s]" % [self.filesize, self.filesize.offset] )
|
||
|
return r.join("\n")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
class XtmJoin
|
||
|
class XtmJoinArgumentError < ArgumentError ; end
|
||
|
|
||
|
attr_reader :opts
|
||
|
|
||
|
|
||
|
def initialize args
|
||
|
@args = []
|
||
|
@input_xtm = nil
|
||
|
parse_command_line args
|
||
|
end
|
||
|
|
||
|
def parse_command_line args
|
||
|
@args = args.clone
|
||
|
@opts = OptionParser.new do |opts|
|
||
|
opts.banner = "Usage: #{File.basename $0} [action] [options]\n"
|
||
|
|
||
|
opts.separator ""
|
||
|
opts.separator "Actions:"
|
||
|
|
||
|
opts.on("-i", "--input FILE", "Input XTM file") do |r|
|
||
|
@input_xtm = r
|
||
|
end
|
||
|
|
||
|
opts.separator ""
|
||
|
opts.separator "General options:"
|
||
|
|
||
|
opts.on("-h", "--help", "Show this help") do |h|
|
||
|
@help = h
|
||
|
end
|
||
|
opts.on("-v", "--verbose", "Show warnings too") do |v|
|
||
|
@verbose = v
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def validate!
|
||
|
@opts.parse!
|
||
|
|
||
|
raise XtmJoinArgumentError, "No input XTM file specified!" if @input_xtm.nil?
|
||
|
end
|
||
|
|
||
|
|
||
|
def run
|
||
|
validate!
|
||
|
|
||
|
File.open( @input_xtm, "rb" ) do |io|
|
||
|
header = XtmHeader::read io
|
||
|
puts header
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def self.main args
|
||
|
xj = nil
|
||
|
begin
|
||
|
xj = XtmJoin.new args
|
||
|
xj.run
|
||
|
exit 0
|
||
|
rescue XtmJoinArgumentError => e
|
||
|
STDERR.puts "%s" % xj.opts
|
||
|
STDERR.puts "error: %s" % e.message
|
||
|
|
||
|
exit 1
|
||
|
rescue SystemExit => e
|
||
|
raise e
|
||
|
rescue Exception => e
|
||
|
STDERR.puts "error: %s" % e.message
|
||
|
exit 1
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
XtmJoin.main ARGV
|