Class: Swd
- Inherits:
-
Object
- Object
- Swd
- Defined in:
- lib/class/swd/Swd.rb
Instance Method Summary collapse
- #detect ⇒ Object
- #do_swd_action(action, option = {}) ⇒ Object
- #erase ⇒ Object
- #export(filepath) ⇒ Object
- #import(filepath) ⇒ Object
-
#initialize(chip, console) ⇒ Swd
constructor
A new instance of Swd.
Constructor Details
#initialize(chip, console) ⇒ Swd
Returns a new instance of Swd.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/class/swd/Swd.rb', line 12 def initialize(chip, console) if HardsploitAPI.getNumberOfBoardAvailable > 0 @console = console @chip = chip else Qt::MessageBox.new( Qt::MessageBox::Critical, "Error", "Hardsploit not plugged. Operation canceled" ).exec end rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND ErrorMsg.new.hardsploit_not_found return false rescue HardsploitAPI::ERROR::USB_ERROR ErrorMsg.new.usb_error return false rescue Exception => msg ErrorMsg.new.unknow(msg) return false end |
Instance Method Details
#detect ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/class/swd/Swd.rb', line 71 def detect code = do_swd_action('detect') unless code == false @console.print('New action: SWD Detect') Qt::MessageBox.new( Qt::MessageBox::Information, "SWD detection", "Detected:\n"+ "DP.IDCODE: #{code[:DebugPortId].to_s(16)}\n"+ "AP.IDCODE: #{code[:AccessPortId].to_s(16)}\n"+ "CPU ID: #{code[:CpuId].to_s(16)}\n" ).exec end end |
#do_swd_action(action, option = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/class/swd/Swd.rb', line 34 def do_swd_action(action, option = {}) Firmware.new('SWD') api = HardsploitAPI_SWD.new( memory_start_address: @chip.swd_setting.memory_start_address, memory_size_address: @chip.swd_setting.memory_size_address, cpu_id_address: @chip.swd_setting.cpu_id_address, device_id_address: @chip.swd_setting.device_id_address ) return 0 if api.nil? case action when 'detect' return api.obtainCodes when 'export' $pgb = .new("SWD: #{action}...") $pgb.show api.dumpFlash(option) when 'import' $pgb = .new("SWD: #{action}...") $pgb.show api.writeFlash(option) when 'erase' api.eraseFlash end rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND ErrorMsg.new.hardsploit_not_found return false rescue HardsploitAPI::ERROR::USB_ERROR ErrorMsg.new.usb_error return false rescue HardsploitAPI::ERROR::SWD_ERROR ErrorMsg.new.swd_not_found return false rescue Exception => msg ErrorMsg.new.unknown(msg) return false end |
#erase ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/class/swd/Swd.rb', line 108 def erase msg = Qt::MessageBox.new msg.setWindowTitle("Delete the data") msg.setText("You are going to delete all the data. Continue?") msg.setIcon(Qt::MessageBox::Information) msg.setStandardButtons(Qt::MessageBox::Cancel | Qt::MessageBox::Ok) msg.setDefaultButton(Qt::MessageBox::Cancel) if msg.exec == Qt::MessageBox::Ok unless do_swd_action('erase') == false Qt::MessageBox.new( Qt::MessageBox::Information, "SWD Erase Action", "Erase finished" ).exec end end end |
#export(filepath) ⇒ Object
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/class/swd/Swd.rb', line 86 def export(filepath) unless do_swd_action('export', filepath) == false Qt::MessageBox.new( Qt::MessageBox::Information, "SWD Export Action", "Dump finished" ).exec $pgb.close end end |
#import(filepath) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/class/swd/Swd.rb', line 97 def import(filepath) unless do_swd_action('import', filepath) == false Qt::MessageBox.new( Qt::MessageBox::Information, "SWD Import Action", "Import finished" ).exec $pgb.close end end |