10
0
Fork 0

begin integrating SIMcopy

This commit is contained in:
Kevin Redon 2011-05-11 11:27:28 +02:00
parent 596855adf0
commit 1f191d492c
2 changed files with 131 additions and 2 deletions

118
src/copy_client.rb Normal file
View File

@ -0,0 +1,118 @@
=begin
This file is part of softSIM.
softSIM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
softSIM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with sofSIM. If not, see <http://www.gnu.org/licenses/>.
Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
=end
# this class copies all files from the SIM to an xml file
require 'sap/client'
require 'lib/apdu'
require 'xml'
class Copy
include APDU
# to show the exact file being processed
VERBOSE = false
# create a Copy class
# io : I/O to the SAP server
def initialize(io)
@client = Client.new(io)
@client.start
@client.connect
end
# tell APDU methods how to send
def transmit_apdu(apdu)
return @client.apdu(apdu)
end
# copy the content to a file
def copy(file="sim.xml")
@sim = XML::Node.new("sim")
# get the ATR
@sim["atr"] = @client.atr.to_hex
end
# get all the files in the current directory
# does a recursive call
# files are saved in the xml file
# path is an arry of MF/DF
# return xml node representing the folder and content
def explore(path)
puts "exploring #{path.flatten.to_hex_disp}" if VERBOSE
# go to parent folder
cd path[0..-2]
# get info and select folder
data = file(path[-1])
return nil unless data
node = file2node(data)
# read all EF
ef_id = EF_LEVELS[path.length]
if ef_id then
0x100.times do |i|
id = [ef_id,i]
begin
data=file(id)
next unless data # if file does not exist
if VERBOSE then
puts "found EF #{id.to_hex_disp}"
elsif PROGRESS
print "."
STDOUT.flush
end
ef_node = file2node(data)
node << ef_node
@nb_files = 0 unless @nb_files
@nb_files += 1
rescue Exception => e
puts "file error : #{e.to_s}"
select_decode(select(id))
end
end
end
# read all DF
df_id = DF_LEVELS[path.length]
if df_id then
# read all DF
0x100.times do |i|
id = [df_id,i]
df_node = explore(path+[id])
next unless df_node
if VERBOSE then
puts "found DF #{id.to_hex_disp}"
elsif PROGRESS
print ","
STDOUT.flush
end
node << df_node
@nb_directories = 0 unless @nb_directories
@nb_directories += 1
end
end
return node
end
# close the copy
def close
@client.disconnect
end
end

View File

@ -21,12 +21,13 @@ Copyright (C) 2011 Kevin "tsaitgaist" Redon kevredon@mail.tsaitgaist.info
require 'sap/client'
require 'lib/apdu'
require 'info_client'
require 'copy_client'
#=============
#== default ==
#=============
# client use (demo,info)
# client use (demo,info,copy)
@type = "demo"
# which IO to use (tcp,unix,bt)
@socket = "tcp"
@ -36,6 +37,8 @@ require 'info_client'
@host = "localhost"
# unix socket
@unix = "/tmp/sap.socket"
# file were to save the copy
@file = "sim.xml"
# bluetooth rfcomm serial port
@bt = nil
# the verbosity (from common)
@ -61,11 +64,12 @@ def print_help
puts ""
puts "options :"
puts " --help,-h\t\tprint this help"
puts " --type,-t client\tclient type : demo,info (default #{@type})"
puts " --type,-t client\tclient type : demo,info,copy (default #{@type})"
puts " --socket,-s type\tsocket type : tcp,unix,bt (default #{@socket})"
puts " --tcp,-p port\t\ttcp port (default #{@port})"
puts " --host,-l host\t\ttcp host (default #{@host})"
puts " --unix,-u file\t\tunix socket (default #{@unix})"
puts " --file,-f path\t\tfile where to save the sim copy (default #{@file})"
puts " --bluetooth,-s rfcomm\tbluetooth rfcomm serial port (default #{@bt ? @bt : 'self discovery'})"
puts " --verbosity,-v\t\tdebug verbosity 0..5 (default #{$verbosity})"
end
@ -96,6 +100,9 @@ while arg=ARGV.shift do
when "--unix","-u"
param = ARGV.shift
@unix = param if param
when "--file","-f"
param = ARGV.shift
@file = param if param
when "--bluetooth","-s"
param = ARGV.shift
@bt = param if param
@ -170,6 +177,10 @@ when "info"
@client = Info.new(io)
@client.display
@client.close
when "copy"
@client = Copy.new(io)
@client.copy(@file)
@client.close
else
raise "please defined which type to use"
end