Class: Chip_management
- Inherits:
-
Qt::MainWindow
- Object
- Qt::MainWindow
- Chip_management
- Defined in:
- lib/class/Chip_management.rb
Instance Method Summary collapse
- #add_chip ⇒ Object
- #check_hardsploit_connection ⇒ Object
- #console_view ⇒ Object
- #create_action_nodes(parent_node) ⇒ Object
- #create_bus_nodes(bus, parent_node) ⇒ Object
- #delete_chip ⇒ Object
- #display_current_firmware ⇒ Object
- #edit_chip ⇒ Object
- #export ⇒ Object
- #feed_chip_array ⇒ Object
- #feed_manufacturer_cbx ⇒ Object
- #feed_type_cbx ⇒ Object
- #filter_chips ⇒ Object
- #get_chip_buses(chip) ⇒ Object
- #get_db_path ⇒ Object
- #get_hardsploit_versions ⇒ Object
- #get_hardsploit_website ⇒ Object
- #get_log_path ⇒ Object
- #import ⇒ Object
-
#initialize(versionGUI) ⇒ Chip_management
constructor
A new instance of Chip_management.
- #load_chip_action(item, column) ⇒ Object
- #load_i2c_module(i2c_module) ⇒ Object
- #load_parallel_module(parallel_module) ⇒ Object
- #load_spi_module(spi_module) ⇒ Object
- #load_swd_module(swd_module) ⇒ Object
- #load_tree(line, column) ⇒ Object
- #load_uart_module(uart_module) ⇒ Object
- #open_signal_mapper ⇒ Object
- #set_firmware ⇒ Object
- #update_uc_firmware ⇒ Object
- #wire_chip ⇒ Object
Constructor Details
#initialize(versionGUI) ⇒ Chip_management
Returns a new instance of Chip_management.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/class/Chip_management.rb', line 38 def initialize(versionGUI) super() @view = Ui_Chip_management.new @view.setupUi(self) @view.img_search.setPixmap(Qt::Pixmap.new(File.(File.dirname(__FILE__)) + "/../images/search.png")) inputRestrict(@view.lie_search, 2) feed_chip_array feed_manufacturer_cbx feed_type_cbx @console = Console.new(@view.tbl_console) @versionGUI = versionGUI check_hardsploit_connection rescue Exception => msg ErrorMsg.new.unknown(msg) return false end |
Instance Method Details
#add_chip ⇒ Object
323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/class/Chip_management.rb', line 323 def add_chip if sender.objectName == 'tw_chip' or sender.objectName == 'actionTemplate' unless @chip_clicked.nil? add_chip = Chip_editor.new(self, @chip_clicked, 'temp') else ErrorMsg.new.no_chip_loaded end else add_chip = Chip_editor.new(self, 'none', 'new') end add_chip.show end |
#check_hardsploit_connection ⇒ Object
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/class/Chip_management.rb', line 480 def check_hardsploit_connection if HardsploitAPI.getNumberOfBoardAvailable > 0 HardsploitAPI.id = ARGV[0].to_i @console.print( "Hardsploit board detected GUI V#{@versionGUI} "+ "API V#{HardsploitAPI::VERSION::API} "+ "BOARD : #{HardsploitAPI.instance.getVersionNumber}" ) @console.print('Hardsploit ready to suck chip souls !') else @console.print( 'Hardsploit board unconnected: '+ 'Wiring and command execution disabled' ) end end |
#console_view ⇒ Object
67 68 69 |
# File 'lib/class/Chip_management.rb', line 67 def console_view sender.isChecked ? @view.tbl_console.show : @view.tbl_console.hide end |
#create_action_nodes(parent_node) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/class/Chip_management.rb', line 105 def create_action_nodes(parent_node) wiring_lvl = Qt::TreeWidgetItem.new wiring_lvl.setText(0, "Wiring") parent_node.addChild(wiring_lvl) edit_lvl = Qt::TreeWidgetItem.new edit_lvl.setText(0, "Edit") parent_node.addChild(edit_lvl) template_lvl = Qt::TreeWidgetItem.new template_lvl.setText(0, "Template") parent_node.addChild(template_lvl) delete_lvl = Qt::TreeWidgetItem.new delete_lvl.setText(0, "Delete") parent_node.addChild(delete_lvl) return parent_node end |
#create_bus_nodes(bus, parent_node) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/class/Chip_management.rb', line 121 def create_bus_nodes(bus, parent_node) case bus when 'UART' settings_lvl = Qt::TreeWidgetItem.new settings_lvl.setText(0, "Settings") parent_node.addChild(settings_lvl) console_lvl = Qt::TreeWidgetItem.new console_lvl.setText(0, "Console") parent_node.addChild(console_lvl) when 'SWD' settings_lvl = Qt::TreeWidgetItem.new settings_lvl.setText(0, "Settings") parent_node.addChild(settings_lvl) scan_lvl = Qt::TreeWidgetItem.new scan_lvl.setText(0, "PIN Scanner") parent_node.addChild(scan_lvl) detect_lvl = Qt::TreeWidgetItem.new detect_lvl.setText(0, "Detect") parent_node.addChild(detect_lvl) import_lvl = Qt::TreeWidgetItem.new import_lvl.setText(0, "Import") parent_node.addChild(import_lvl) export_lvl = Qt::TreeWidgetItem.new export_lvl.setText(0, "Dump") parent_node.addChild(export_lvl) erase_lvl = Qt::TreeWidgetItem.new erase_lvl.setText(0, "Erase") parent_node.addChild(erase_lvl) when 'SPI' settings_lvl = Qt::TreeWidgetItem.new settings_lvl.setText(0, "Settings") parent_node.addChild(settings_lvl) cmd_lvl = Qt::TreeWidgetItem.new cmd_lvl.setText(0, "Commands") parent_node.addChild(cmd_lvl) import_lvl = Qt::TreeWidgetItem.new import_lvl.setText(0, "Import") parent_node.addChild(import_lvl) export_lvl = Qt::TreeWidgetItem.new export_lvl.setText(0, "Export") parent_node.addChild(export_lvl) sniffer_lvl = Qt::TreeWidgetItem.new sniffer_lvl.setText(0, "Sniffer") parent_node.addChild(sniffer_lvl) when 'I2C' settings_lvl = Qt::TreeWidgetItem.new settings_lvl.setText(0, "Settings") parent_node.addChild(settings_lvl) scanner_lvl = Qt::TreeWidgetItem.new scanner_lvl.setText(0, "PIN Scanner") parent_node.addChild(scanner_lvl) cmd_lvl = Qt::TreeWidgetItem.new cmd_lvl.setText(0, "Commands") parent_node.addChild(cmd_lvl) import_lvl = Qt::TreeWidgetItem.new import_lvl.setText(0, "Import") parent_node.addChild(import_lvl) export_lvl = Qt::TreeWidgetItem.new export_lvl.setText(0, "Export") parent_node.addChild(export_lvl) when 'PARALLEL' settings_lvl = Qt::TreeWidgetItem.new settings_lvl.setText(0, "Settings") parent_node.addChild(settings_lvl) # Not implemented yet #import_lvl = Qt::TreeWidgetItem.new #import_lvl.setText(0, "Import") #parent_node.addChild(import_lvl) export_lvl = Qt::TreeWidgetItem.new export_lvl.setText(0, "Export") parent_node.addChild(export_lvl) end return parent_node end |
#delete_chip ⇒ Object
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/class/Chip_management.rb', line 343 def delete_chip return ErrorMsg.new.no_chip_loaded if @chip_clicked.nil? msg = Qt::MessageBox.new msg.setWindowTitle("Delete current chip") msg.setText("Delete #{@chip_clicked.reference}? Commands will be deleted too.") msg.setIcon(Qt::MessageBox::Question) msg.setStandardButtons(Qt::MessageBox::Cancel | Qt::MessageBox::Ok) msg.setDefaultButton(Qt::MessageBox::Cancel) if msg.exec == Qt::MessageBox::Ok @chip_clicked.destroy @chip_clicked = nil feed_chip_array @view.tw_chip.clear end end |
#display_current_firmware ⇒ Object
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/class/Chip_management.rb', line 384 def display_current_firmware if $currentFirmware.nil? Qt::MessageBox.new( Qt::MessageBox::Information, 'Firmware', 'No firmware loaded' ).exec else Qt::MessageBox.new( Qt::MessageBox::Information, 'Firmware', "Actual firmware: #{$currentFirmware}" ).exec end end |
#edit_chip ⇒ Object
337 338 339 340 341 |
# File 'lib/class/Chip_management.rb', line 337 def edit_chip return ErrorMsg.new.no_chip_loaded if @chip_clicked.nil? edit_chip = Chip_editor.new(self, @chip_clicked, 'edit') edit_chip.show end |
#export ⇒ Object
377 378 379 380 381 382 |
# File 'lib/class/Chip_management.rb', line 377 def export return ErrorMsg.new.no_chip_loaded if @chip_clicked.nil? export = Export.new(@view.tbl_chip.selectedItems) export.setWindowModality(Qt::ApplicationModal) export.show end |
#feed_chip_array ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/class/Chip_management.rb', line 196 def feed_chip_array @view.tbl_chip.clearContents chips = filter_chips @view.tbl_chip.setRowCount(chips.count); # Insert chip table rows chips.to_enum.with_index(0).each do |c, i| # Reference item = Qt::TableWidgetItem.new(c.reference) item.setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled) @view.tbl_chip.setItem(i, 0, item) # Chip Type item2 = Qt::TableWidgetItem.new(ChipType.find(c.chip_type_id).name) item2.setFlags(Qt::ItemIsEnabled) @view.tbl_chip.setItem(i, 1, item2) # Chip Manufacturer item3 = Qt::TableWidgetItem.new(Manufacturer.find(c.manufacturer_id).name) item3.setFlags(Qt::ItemIsEnabled) @view.tbl_chip.setItem(i, 2, item3) bus_list = get_chip_buses(c) bus_list_str = '' bus_list.each do |b| bus_list_str = bus_list_str + "#{b} " end # Chip Bus(es) item4 = Qt::TableWidgetItem.new(bus_list_str) item4.setFlags(Qt::ItemIsEnabled) @view.tbl_chip.setItem(i, 3, item4) end @view.tbl_chip.resizeColumnsToContents @view.tbl_chip.resizeRowsToContents @view.tbl_chip.horizontalHeader.stretchLastSection = true @view.tbl_console.horizontalHeader.stretchLastSection = true end |
#feed_manufacturer_cbx ⇒ Object
61 62 63 64 65 |
# File 'lib/class/Chip_management.rb', line 61 def feed_manufacturer_cbx ChipType.all.each do |c| @view.cbx_type.addItem(c.name) end end |
#feed_type_cbx ⇒ Object
55 56 57 58 59 |
# File 'lib/class/Chip_management.rb', line 55 def feed_type_cbx Manufacturer.all.each do |m| @view.cbx_manufacturer.addItem(m.name) end end |
#filter_chips ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/class/Chip_management.rb', line 230 def filter_chips if @view.lie_search.text.empty? chips = Chip.all else chips = Chip.where("reference LIKE ?", "%#{@view.lie_search.text}%") end unless @view.cbx_manufacturer.currentIndex.zero? man_id = Manufacturer.find_by(name: @view.cbx_manufacturer.currentText).id chips = chips.where(manufacturer_id: man_id) end unless @view.cbx_type.currentIndex.zero? type_id = ChipType.find_by(name: @view.cbx_type.currentText).id chips = chips.where(chip_type_id: type_id) end return chips end |
#get_chip_buses(chip) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/class/Chip_management.rb', line 71 def get_chip_buses(chip) chip_buses = [] chip.pins.each do |pin| chip_buses.push(pin.signall.buses[0].name) end chip_buses.delete("NA") return chip_buses.uniq end |
#get_db_path ⇒ Object
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/class/Chip_management.rb', line 442 def get_db_path msg = Qt::MessageBox.new msg.setWindowTitle('Database path') msg.setText("Path: #{$dbFilePath}\n") msg.setIcon(Qt::MessageBox::Information) close_btn = msg.setStandardButtons(Qt::MessageBox::Close) open_btn = msg.addButton('Open folder', Qt::MessageBox::ActionRole) open_btn.setObjectName('open_btn') backup_btn = msg.addButton('Create backup', Qt::MessageBox::ActionRole) backup_btn.setObjectName('backup_btn') msg.exec if msg.clickedButton.objectName == 'backup_btn' system("cp #{$dbFilePath} #{$dbFilePath}.bck") Qt::MessageBox.new( Qt::MessageBox::Information, 'Backup status', 'db.bck created' ).exec end if msg.clickedButton.objectName == 'open_btn' system("xdg-open #{$dbFilePath}") end end |
#get_hardsploit_versions ⇒ Object
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/class/Chip_management.rb', line 409 def get_hardsploit_versions if HardsploitAPI.getNumberOfBoardAvailable > 0 Qt::MessageBox.new( Qt::MessageBox::Information, 'Hardsploit versions', "GUI VERSION : #{@versionGUI}\n"+ "API VERSION : #{HardsploitAPI::VERSION::API}\n"+ "BOARD : #{HardsploitAPI.instance.getVersionNumber}" ).exec else Qt::MessageBox.new( Qt::MessageBox::Information, 'Hardsploit versions', "GUI VERSION : #{@versionGUI}\n "+ "API VERSION : #{HardsploitAPI::VERSION::API}" ).exec end end |
#get_hardsploit_website ⇒ Object
466 467 468 469 470 471 472 |
# File 'lib/class/Chip_management.rb', line 466 def get_hardsploit_website Qt::MessageBox.new( Qt::MessageBox::Information, 'Hardsploit website', 'Find all the news about Hardsploit on our website: http://hardsploit.io' ).exec end |
#get_log_path ⇒ Object
428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/class/Chip_management.rb', line 428 def get_log_path msg = Qt::MessageBox.new msg.setWindowTitle('Log file path') msg.setText("Path: #{$logFilePath}") msg.setIcon(Qt::MessageBox::Information) close_btn = msg.setStandardButtons(Qt::MessageBox::Close) open_btn = msg.addButton('Open folder', Qt::MessageBox::ActionRole) open_btn.setObjectName('open_btn') msg.exec if msg.clickedButton.objectName == 'open_btn' system("xdg-open #{$logFilePath}") end end |
#import ⇒ Object
367 368 369 370 371 372 373 374 375 |
# File 'lib/class/Chip_management.rb', line 367 def import if @chip_clicked.nil? import = Import.new(self) else import = Import.new(self, @chip_clicked) end import.setWindowModality(Qt::ApplicationModal) import.show end |
#load_chip_action(item, column) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/class/Chip_management.rb', line 247 def load_chip_action(item, column) return 0 unless item.childCount.zero? if item.parent.text(0) == 'Manage' case item.text(0) when 'Wiring' ; wire_chip when 'Edit' ; edit_chip when 'Template' ; add_chip when 'Delete' ; delete_chip end else case item.parent.text(0) when 'SPI' ; load_spi_module(item.text(0)) when 'I2C' ; load_i2c_module(item.text(0)) when 'PARALLEL' ; load_parallel_module(item.text(0)) when 'SWD' ; load_swd_module(item.text(0)) when 'UART' ; load_uart_module(item.text(0)) end end end |
#load_i2c_module(i2c_module) ⇒ Object
277 278 279 280 281 282 283 284 285 |
# File 'lib/class/Chip_management.rb', line 277 def load_i2c_module(i2c_module) case i2c_module when 'Settings' ; I2c_settings.new(@chip_clicked).show when 'PIN Scanner' ; I2c_scanner.new.show when 'Commands' ; Generic_commands.new(@chip_clicked, 'I2C').show when 'Import' ; I2c_import.new(@chip_clicked).show when 'Export' ; I2c_export.new(@chip_clicked).show end end |
#load_parallel_module(parallel_module) ⇒ Object
287 288 289 290 291 292 293 |
# File 'lib/class/Chip_management.rb', line 287 def load_parallel_module(parallel_module) case parallel_module when 'Settings' ; Parallel_settings.new(@chip_clicked).show when 'Import' ; Parallel_import.new(@chip_clicked).show when 'Export' ; Parallel_export.new(@chip_clicked).show end end |
#load_spi_module(spi_module) ⇒ Object
267 268 269 270 271 272 273 274 275 |
# File 'lib/class/Chip_management.rb', line 267 def load_spi_module(spi_module) case spi_module when 'Settings' ; Spi_settings.new(@chip_clicked).show when 'Commands' ; Generic_commands.new(@chip_clicked, 'SPI').show when 'Import' ; Spi_import.new(@chip_clicked).show when 'Export' ; Spi_export.new(@chip_clicked).show when 'Sniffer' ; Spi_sniffer.new(@chip_clicked).show end end |
#load_swd_module(swd_module) ⇒ Object
295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'lib/class/Chip_management.rb', line 295 def load_swd_module(swd_module) case swd_module when 'Settings' ; Swd_settings.new(@chip_clicked).show when 'PIN Scanner' ; Swd_scanner.new.show when 'Detect' ; Swd.new(@chip_clicked, @console).detect when 'Import' filepath = Qt::FileDialog.getOpenFileName(self, tr('Select a file'), '/') Swd.new(@chip_clicked, @console).import(filepath) unless filepath.nil? when 'Dump' filepath = Qt::FileDialog.getSaveFileName(self, tr('Select a file'), '/') Swd.new(@chip_clicked, @console).export(filepath) unless filepath.nil? when 'Erase' ; Swd.new(@chip_clicked, @console).erase end end |
#load_tree(line, column) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/class/Chip_management.rb', line 80 def load_tree(line, column) return 0 unless column.zero? @view.tw_chip.clear @chip_clicked = Chip.find_by(reference: @view.tbl_chip.item(line, column).text) # CHIP LEVEL chip_lvl = Qt::TreeWidgetItem.new chip_lvl.setText(0, @view.tbl_chip.item(line, column).text) @view.tw_chip.addTopLevelItem(chip_lvl) chip_lvl.setExpanded(true) # ACTION LEVEL action_lvl = Qt::TreeWidgetItem.new action_lvl.setText(0, 'Manage') chip_lvl.addChild(create_action_nodes(action_lvl)) action_lvl.setExpanded(true) # BUS LEVEL(S) chip_bus = get_chip_buses(@chip_clicked) chip_bus.each do |b| @bus_lvl = Qt::TreeWidgetItem.new @bus_lvl.setText(0, b) chip_lvl.addChild(create_bus_nodes(b, @bus_lvl)) @bus_lvl.setExpanded(true) unless @bus_lvl.nil? end end |
#load_uart_module(uart_module) ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/class/Chip_management.rb', line 310 def load_uart_module(uart_module) case uart_module when 'Settings' settingsUart = Uart_settings.new(@chip_clicked) settingsUart.setWindowModality(Qt::ApplicationModal) settingsUart.show when 'Console' consoleUart = Uart_console.new(@chip_clicked) consoleUart.setWindowModality(Qt::ApplicationModal) consoleUart.show end end |
#open_signal_mapper ⇒ Object
474 475 476 477 478 |
# File 'lib/class/Chip_management.rb', line 474 def open_signal_mapper signal_mapper = Signal_mapper.new signal_mapper.setWindowModality(Qt::ApplicationModal) signal_mapper.show end |
#set_firmware ⇒ Object
400 401 402 403 |
# File 'lib/class/Chip_management.rb', line 400 def set_firmware Firmware.new(sender.objectName[6, sender.objectName.length]) display_current_firmware end |
#update_uc_firmware ⇒ Object
405 406 407 |
# File 'lib/class/Chip_management.rb', line 405 def update_uc_firmware Firmware.new('uC') end |
#wire_chip ⇒ Object
359 360 361 362 363 364 365 |
# File 'lib/class/Chip_management.rb', line 359 def wire_chip return ErrorMsg.new.hardsploit_not_found unless HardsploitAPI.getNumberOfBoardAvailable > 0 return ErrorMsg.new.no_chip_loaded if @chip_clicked.nil? wire_helper = Wire_helper.new(@chip_clicked) wire_helper.setWindowModality(Qt::ApplicationModal) wire_helper.show end |