hardsploit_gui 2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +22 -0
  3. data/Rakefile +1 -0
  4. data/bin/hardsploit_gui +3 -0
  5. data/lib/Firmware/FPGA/I2C/I2C_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_I2C_INTERACT.rpd +0 -0
  6. data/lib/Firmware/FPGA/PARALLEL/NO_MUX_PARALLEL_MEMORY/HARDSPLOIT_FIRMWARE_FPGA_NO_MUX_PARALLEL_MEMORY.rpd +0 -0
  7. data/lib/Firmware/FPGA/SPI/SPI_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SPI_INTERACT.rpd +0 -0
  8. data/lib/Firmware/FPGA/SWD/SWD_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SWD_INTERACT.rpd +0 -0
  9. data/lib/Firmware/FPGA/TEST/TEST_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_TEST_INTERACT.rpd +0 -0
  10. data/lib/Firmware/FPGA/VersionFPGA.rb +5 -0
  11. data/lib/Firmware/UC/HARDSPLOIT_FIRMWARE_UC.bin +0 -0
  12. data/lib/Firmware/UC/VersionUC.rb +12 -0
  13. data/lib/HardsploitAPI/HardsploitAPI.rb +134 -0
  14. data/lib/HardsploitAPI/HardsploitAPI_CONSTANT.rb +145 -0
  15. data/lib/HardsploitAPI/HardsploitAPI_FIRMWARE.rb +311 -0
  16. data/lib/HardsploitAPI/HardsploitAPI_I2C.rb +218 -0
  17. data/lib/HardsploitAPI/HardsploitAPI_NO_MUX_PARALLELE_MEMORY.rb +229 -0
  18. data/lib/HardsploitAPI/HardsploitAPI_SPI.rb +179 -0
  19. data/lib/HardsploitAPI/HardsploitAPI_TEST_INTERACT.rb +98 -0
  20. data/lib/HardsploitAPI/HardsploitAPI_USB_COMMUNICATION.rb +149 -0
  21. data/lib/HardsploitAPI/LICENSE.txt +674 -0
  22. data/lib/HardsploitAPI/README.md +22 -0
  23. data/lib/HardsploitAPI/SWD/HardsploitAPI_SWD.rb +249 -0
  24. data/lib/HardsploitAPI/SWD/HardsploitAPI_SWD_DEBUG.rb +102 -0
  25. data/lib/HardsploitAPI/SWD/HardsploitAPI_SWD_MEM_AP.rb +78 -0
  26. data/lib/HardsploitAPI/SWD/HardsploitAPI_SWD_STM32.rb +104 -0
  27. data/lib/HardsploitAPI/TRADEMARK +3 -0
  28. data/lib/LICENSE.txt +674 -0
  29. data/lib/README.md +22 -0
  30. data/lib/TRADEMARK +3 -0
  31. data/lib/class/Chip_editor.rb +448 -0
  32. data/lib/class/Command_editor.rb +268 -0
  33. data/lib/class/Command_table.rb +239 -0
  34. data/lib/class/Console.rb +28 -0
  35. data/lib/class/Export_manager.rb +124 -0
  36. data/lib/class/Firmware.rb +29 -0
  37. data/lib/class/Generic_commands.rb +275 -0
  38. data/lib/class/HardsploitGUI.rb +462 -0
  39. data/lib/class/I2C/I2c_command.rb +48 -0
  40. data/lib/class/I2C/I2c_export.rb +121 -0
  41. data/lib/class/I2C/I2c_import.rb +92 -0
  42. data/lib/class/I2C/I2c_settings.rb +117 -0
  43. data/lib/class/PARALLEL/Parallel_export.rb +146 -0
  44. data/lib/class/PARALLEL/Parallel_import.rb +88 -0
  45. data/lib/class/PARALLEL/Parallel_settings.rb +102 -0
  46. data/lib/class/SPI/Spi_export.rb +141 -0
  47. data/lib/class/SPI/Spi_import.rb +112 -0
  48. data/lib/class/SPI/Spi_settings.rb +90 -0
  49. data/lib/class/Wire_helper.rb +246 -0
  50. data/lib/db/associations.rb +125 -0
  51. data/lib/db/hs.db +0 -0
  52. data/lib/gui/gui_chip_editor.rb +355 -0
  53. data/lib/gui/gui_chip_management.rb +372 -0
  54. data/lib/gui/gui_command_editor.rb +218 -0
  55. data/lib/gui/gui_export_manager.rb +93 -0
  56. data/lib/gui/gui_generic_commands.rb +164 -0
  57. data/lib/gui/gui_generic_export.rb +148 -0
  58. data/lib/gui/gui_generic_import.rb +126 -0
  59. data/lib/gui/gui_i2c_command.rb +115 -0
  60. data/lib/gui/gui_i2c_settings.rb +201 -0
  61. data/lib/gui/gui_parallel_settings.rb +194 -0
  62. data/lib/gui/gui_spi_import.rb +126 -0
  63. data/lib/gui/gui_spi_settings.rb +187 -0
  64. data/lib/gui/gui_wire_helper.rb +99 -0
  65. data/lib/gui_designer/gui_chip_editor.ui +553 -0
  66. data/lib/gui_designer/gui_chip_management.ui +842 -0
  67. data/lib/gui_designer/gui_command_editor.ui +347 -0
  68. data/lib/gui_designer/gui_export_manager.ui +115 -0
  69. data/lib/gui_designer/gui_generic_commands.ui +258 -0
  70. data/lib/gui_designer/gui_generic_export.ui +179 -0
  71. data/lib/gui_designer/gui_generic_import.ui +142 -0
  72. data/lib/gui_designer/gui_i2c_command.ui +145 -0
  73. data/lib/gui_designer/gui_i2c_settings.ui +261 -0
  74. data/lib/gui_designer/gui_parallel_settings.ui +244 -0
  75. data/lib/gui_designer/gui_processing.ui +81 -0
  76. data/lib/gui_designer/gui_spi_settings.ui +321 -0
  77. data/lib/gui_designer/gui_wire_helper.ui +117 -0
  78. data/lib/hardsploit.rb +122 -0
  79. data/lib/images/search.png +0 -0
  80. data/lib/logs/error.log +0 -0
  81. metadata +236 -0
@@ -0,0 +1,48 @@
1
+ #===================================================
2
+ # Hardsploit GUI - By Opale Security
3
+ # www.opale-security.com || www.hardsploit.io
4
+ # License: GNU General Public License v3
5
+ # License URI: http://www.gnu.org/licenses/gpl.txt
6
+ #===================================================
7
+
8
+ require_relative '../../gui/gui_i2c_command'
9
+ class I2c_command < Qt::Widget
10
+ slots 'open_generic_cmd()'
11
+
12
+ def initialize(api, chip, bus_id, parent)
13
+ super()
14
+ @i2c_command_gui = Ui_I2c_command.new
15
+ centerWindow(self)
16
+ @i2c_command_gui.setupUi(self)
17
+ @i2c_command_gui.rbn_read.setChecked(true)
18
+ inputRestrict(@i2c_command_gui.lie_size, 0)
19
+ @chip = chip
20
+ @chip_settings = I2C.find_by(i2c_chip: chip.chip_id)
21
+ @api = api
22
+ @bus_id = bus_id
23
+ @parent = parent
24
+ end
25
+
26
+ def open_generic_cmd
27
+ return 0 if check_form_param.zero?
28
+ if @i2c_command_gui.rbn_read.isChecked
29
+ mode = "r"
30
+ addr = @chip_settings.i2c_address_r
31
+ else
32
+ mode = "w"
33
+ addr = @chip_settings.i2c_address_w
34
+ end
35
+ i2c_cmd_form = Command_editor.new(0, nil, @chip, @bus_id, @parent, @api, :mode => mode, :size => @i2c_command_gui.lie_size.text, :addr => addr)
36
+ i2c_cmd_form.setWindowModality(Qt::ApplicationModal)
37
+ i2c_cmd_form.show
38
+ close
39
+ end
40
+
41
+ def check_form_param
42
+ if @i2c_command_gui.lie_size.text.empty? || @i2c_command_gui.lie_size.text.to_i.zero?
43
+ Qt::MessageBox.new(Qt::MessageBox::Information, "Form invalid", "Payload size must be filled and superior to 0").exec
44
+ return 0
45
+ end
46
+ return 1
47
+ end
48
+ end
@@ -0,0 +1,121 @@
1
+ #===================================================
2
+ # Hardsploit GUI - By Opale Security
3
+ # www.opale-security.com || www.hardsploit.io
4
+ # License: GNU General Public License v3
5
+ # License URI: http://www.gnu.org/licenses/gpl.txt
6
+ #===================================================
7
+
8
+ require_relative '../../HardsploitAPI/HardsploitAPI'
9
+ require_relative '../../gui/gui_generic_export'
10
+
11
+ class I2c_export < Qt::Widget
12
+ slots 'export()'
13
+ slots 'select_export_file()'
14
+
15
+ def initialize(api, chip)
16
+ super()
17
+ @i2c_export_gui = Ui_Generic_export.new
18
+ centerWindow(self)
19
+ @i2c_export_gui.setupUi(self)
20
+ @i2c_export_gui.lbl_chip.setText(chip.chip_reference)
21
+ inputRestrict(@i2c_export_gui.lie_start, 0)
22
+ inputRestrict(@i2c_export_gui.lie_stop, 0)
23
+ @api = api
24
+ @chip_settings = I2C.find_by(i2c_chip: chip.chip_id)
25
+ end
26
+
27
+ def select_export_file
28
+ @filepath = Qt::FileDialog.getSaveFileName(self, tr('Select a file'), '/', tr('Bin file (*.bin)'))
29
+ unless @filepath.nil?
30
+ $file = File.open("#{@filepath}", 'w')
31
+ @i2c_export_gui.btn_export.setEnabled(true)
32
+ @i2c_export_gui.btn_full_export.setEnabled(true)
33
+ end
34
+ rescue Exception => msg
35
+ logger = Logger.new($logFilePath)
36
+ logger.error msg
37
+ Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while openning the export file. Consult the logs for more details').exec
38
+ end
39
+
40
+ def close_file
41
+ unless $file.nil?
42
+ $file.close
43
+ end
44
+ rescue Exception => msg
45
+ logger = Logger.new($logFilePath)
46
+ logger.error msg
47
+ Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while closing the export file. Consult the logs for more details').exec
48
+ end
49
+
50
+ def export
51
+ if sender.objectName == 'btn_full_export'
52
+ return 0 if control_export_settings('full').zero?
53
+ else
54
+ return 0 if control_export_settings('partial').zero?
55
+ end
56
+ Firmware.new(@api, 'I2C')
57
+ time = Time.new
58
+ if sender.objectName == 'btn_full_export'
59
+ @api.i2c_Generic_Dump(@chip_settings.i2c_frequency, @chip_settings.i2c_address_w.to_i(16), 0, @chip_settings.i2c_total_size - 1, @chip_settings.i2c_total_size)
60
+ close_file
61
+ control_export_result('full', @chip_settings.i2c_total_size - 1, time)
62
+ else
63
+ @api.i2c_Generic_Dump(@chip_settings.i2c_frequency, @chip_settings.i2c_address_w.to_i(16), @i2c_export_gui.lie_start.text.to_i, @i2c_export_gui.lie_stop.text.to_i, @chip_settings.i2c_total_size)
64
+ close_file
65
+ control_export_result('partial', @i2c_export_gui.lie_stop.text.to_i, time)
66
+ end
67
+ @i2c_export_gui.btn_export.setEnabled(false)
68
+ @i2c_export_gui.btn_full_export.setEnabled(false)
69
+ rescue Exception => msg
70
+ logger = Logger.new($logFilePath)
71
+ logger.error msg
72
+ Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while full export operation. Consult the logs for more details').exec
73
+ end
74
+
75
+ def control_export_result(type, stop, time)
76
+ time = Time.new - time
77
+ if type == 'partial'
78
+ toCompare = ((stop - @i2c_export_gui.lie_start.text.to_i) + 1)
79
+ else
80
+ toCompare = @chip_settings.i2c_total_size
81
+ end
82
+ file_size = File.size(@filepath)
83
+ if toCompare == file_size
84
+ Qt::MessageBox.new(Qt::MessageBox::Information, 'Information', "Dump finished at #{((file_size / time)).round(2)}Bytes/s (#{(file_size)} Bytes in #{time.round(4)} s)").exec
85
+ else
86
+ Qt::MessageBox.new(Qt::MessageBox::Critical, 'Error', 'Dump error: Size does not match').exec
87
+ end
88
+ p "DUMP #{((file_size / time)).round(2)}Bytes/s (#{(file_size)}Bytes in #{time.round(4)} s)"
89
+ end
90
+
91
+ def control_export_settings(type)
92
+ if @chip_settings.nil?
93
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C settings', 'No settings saved for this chip').exec
94
+ return 0
95
+ end
96
+ if @chip_settings.i2c_frequency.nil? || @chip_settings.i2c_address_w.nil?
97
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C settings', 'Write base address or frequency settings missing').exec
98
+ return 0
99
+ end
100
+ if type == 'full'
101
+ if @chip_settings.i2c_total_size.zero? || @chip_settings.i2c_total_size.nil?
102
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Empty field', 'Full size setting missing or equal 0').exec
103
+ return 0
104
+ end
105
+ else
106
+ if @i2c_export_gui.lie_start.text.empty? || @i2c_export_gui.lie_stop.text.empty?
107
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Empty field', 'Start and stop address must be filled').exec
108
+ return 0
109
+ end
110
+ if @i2c_export_gui.lie_start.text.to_i > @i2c_export_gui.lie_stop.text.to_i
111
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Wrong value', 'Start address must be inforior to the stop address').exec
112
+ return 0
113
+ end
114
+ if @i2c_export_gui.lie_start.text.to_i > (@chip_settings.i2c_total_size - 1) || @i2c_export_gui.lie_stop.text.to_i > (@chip_settings.i2c_total_size - 1)
115
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Wrong value', 'Start and stop address must be inforior to the chip total size').exec
116
+ return 0
117
+ end
118
+ end
119
+ return 1
120
+ end
121
+ end
@@ -0,0 +1,92 @@
1
+ #===================================================
2
+ # Hardsploit GUI - By Opale Security
3
+ # www.opale-security.com || www.hardsploit.io
4
+ # License: GNU General Public License v3
5
+ # License URI: http://www.gnu.org/licenses/gpl.txt
6
+ #===================================================
7
+
8
+ require_relative '../../HardsploitAPI/HardsploitAPI'
9
+ require_relative '../../gui/gui_generic_import'
10
+
11
+ class I2c_import < Qt::Widget
12
+ slots 'import()'
13
+ slots 'select_import_file()'
14
+
15
+ def initialize(api, chip)
16
+ super()
17
+ @i2c_import_gui = Ui_Generic_import.new
18
+ centerWindow(self)
19
+ @i2c_import_gui.setupUi(self)
20
+ @i2c_import_gui.lbl_chip.setText(chip.chip_reference)
21
+ inputRestrict(@i2c_import_gui.lie_start, 0)
22
+ @api = api
23
+ @chip_settings = I2C.find_by(i2c_chip: chip.chip_id)
24
+ end
25
+
26
+ def select_import_file
27
+ @filepath = Qt::FileDialog.getOpenFileName(self, tr('Select a file'), '/', tr('Bin file (*.bin)'))
28
+ unless @filepath.nil?
29
+ $file = File.open("#{@filepath}", 'w')
30
+ @i2c_import_gui.btn_import.setEnabled(true)
31
+ end
32
+ rescue Exception => msg
33
+ logger = Logger.new($logFilePath)
34
+ logger.error msg
35
+ Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while openning the export file. Consult the logs for more details').exec
36
+ end
37
+
38
+ def close_file
39
+ unless $file.nil?
40
+ $file.close
41
+ end
42
+ rescue Exception => msg
43
+ logger = Logger.new($logFilePath)
44
+ logger.error msg
45
+ Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while closing the export file. Consult the logs for more details').exec
46
+ end
47
+
48
+ def import
49
+ return 0 if control_import_settings.zero?
50
+ start = @i2c_import_gui.lie_start.text.to_i
51
+ Firmware.new(@api, 'I2C')
52
+ time = Time.new
53
+ # I2C API IMPORT COMMAND GOES HERE
54
+ rescue Exception => msg
55
+ logger = Logger.new($logFilePath)
56
+ logger.error msg
57
+ Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while partial import operation. Consult the logs for more details').exec
58
+ end
59
+
60
+ def control_import_settings
61
+ file_size = File.size("#{@filepath}")
62
+ if @chip_settings.nil?
63
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C settings', 'No settings saved for this chip').exec
64
+ return 0
65
+ end
66
+ if @chip_settings.i2c_total_size.nil?
67
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C settings', 'Total size setting missing').exec
68
+ return 0
69
+ end
70
+ if @chip_settings.i2c_frequency.nil? || @chip_settings.i2c_address_w.nil?
71
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C settings', 'Write base address or frequency settings missing').exec
72
+ return 0
73
+ end
74
+ if @chip_settings.i2c_mode.nil?
75
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing I2C setting', 'Mode setting missing').exec
76
+ return 0
77
+ end
78
+ if @i2c_import_gui.lie_start.text.empty?
79
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing start address', 'Please fill the Start address field').exec
80
+ return 0
81
+ end
82
+ if file_size > @chip_settings.i2c_total_size
83
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Incorrect file size', 'The file size is superior to the chip capacity').exec
84
+ return 0
85
+ end
86
+ if file_size > (@chip_settings.i2c_total_size - @i2c_import_gui.lie_start)
87
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Incorrect file size', 'Starting at this address, the file size is superior to the chip capacity').exec
88
+ return 0
89
+ end
90
+ return 1
91
+ end
92
+ end
@@ -0,0 +1,117 @@
1
+ #===================================================
2
+ # Hardsploit GUI - By Opale Security
3
+ # www.opale-security.com || www.hardsploit.io
4
+ # License: GNU General Public License v3
5
+ # License URI: http://www.gnu.org/licenses/gpl.txt
6
+ #===================================================
7
+
8
+ require_relative '../../HardsploitAPI/HardsploitAPI'
9
+ require_relative '../../gui/gui_i2c_settings'
10
+ class I2c_settings < Qt::Widget
11
+ slots 'save_settings()'
12
+ slots 'bus_scan()'
13
+
14
+ def initialize(api, chip)
15
+ super()
16
+ @i2c_settings_gui = Ui_I2c_settings.new
17
+ centerWindow(self)
18
+ @i2c_settings_gui.setupUi(self)
19
+ @i2c_settings_gui.lbl_chip.setText(chip.chip_reference)
20
+ inputRestrict(@i2c_settings_gui.lie_total_size, 0)
21
+ inputRestrict(@i2c_settings_gui.lie_address_r, 3)
22
+ inputRestrict(@i2c_settings_gui.lie_address_w, 3)
23
+ @i2c_settings_gui.tbl_bus_scan.resizeColumnsToContents
24
+ @i2c_settings_gui.tbl_bus_scan.resizeRowsToContents
25
+ @i2c_settings_gui.tbl_bus_scan.horizontalHeader.stretchLastSection = true
26
+ @chip_settings = I2C.find_by(i2c_chip: chip.chip_id)
27
+ @chip = chip
28
+ @api = api
29
+ feed_settings_form
30
+ end
31
+
32
+ def save_settings
33
+ if @chip_settings.nil?
34
+ create
35
+ else
36
+ @chip_settings = I2C.find_by(i2c_chip: @chip.chip_id)
37
+ update
38
+ end
39
+ end
40
+
41
+ def feed_settings_form
42
+ unless @chip_settings.nil?
43
+ @i2c_settings_gui.cbx_frequency.setCurrentIndex(@i2c_settings_gui.cbx_frequency.findText(@chip_settings.i2c_frequency.to_s))
44
+ @i2c_settings_gui.lie_address_r.setText(@chip_settings.i2c_address_r)
45
+ @i2c_settings_gui.lie_address_w.setText(@chip_settings.i2c_address_w)
46
+ @i2c_settings_gui.lie_total_size.setText(@chip_settings.i2c_total_size.to_s)
47
+ end
48
+ rescue Exception => msg
49
+ logger = Logger.new($logFilePath)
50
+ logger.error msg
51
+ Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error while loading the form. Consult the log for more details').exec
52
+ end
53
+
54
+ def create
55
+ @chip_settings = I2C.create(
56
+ i2c_frequency: @i2c_settings_gui.cbx_frequency.currentText,
57
+ i2c_address_r: @i2c_settings_gui.lie_address_r.text,
58
+ i2c_address_w: @i2c_settings_gui.lie_address_w.text,
59
+ i2c_total_size: @i2c_settings_gui.lie_total_size.text,
60
+ i2c_chip: @chip.chip_id
61
+ )
62
+ Qt::MessageBox.new(Qt::MessageBox::Information, 'Succes', 'I2C parameters created successfully').exec
63
+ rescue Exception => msg
64
+ logger = Logger.new($logFilePath)
65
+ logger.error msg
66
+ Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured when creating the I2C parameters. Consult the log for more details').exec
67
+ end
68
+
69
+ def update
70
+ if @chip_settings.i2c_frequency != @i2c_settings_gui.cbx_frequency.currentText.to_i
71
+ @chip_settings.update(i2c_frequency: @i2c_settings_gui.cbx_frequency.currentText.to_i)
72
+ end
73
+ if @chip_settings.i2c_address_r != @i2c_settings_gui.lie_address_r.text
74
+ @chip_settings.update(i2c_address_r: @i2c_settings_gui.lie_address_r.text)
75
+ end
76
+ if @chip_settings.i2c_address_w != @i2c_settings_gui.lie_address_w.text
77
+ @chip_settings.update(i2c_address_w: @i2c_settings_gui.lie_address_w.text)
78
+ end
79
+ if @chip_settings.i2c_total_size != @i2c_settings_gui.lie_total_size.text
80
+ @chip_settings.update(i2c_total_size: @i2c_settings_gui.lie_total_size.text)
81
+ end
82
+ Qt::MessageBox.new(Qt::MessageBox::Information, 'Succes', 'I2C parameters saved successfully').exec
83
+ rescue Exception => msg
84
+ logger = Logger.new($logFilePath)
85
+ logger.error msg
86
+ Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured when saving the I2C parameters. Consult the log for more details').exec
87
+ end
88
+
89
+ def bus_scan
90
+ @i2c_settings_gui.tbl_bus_scan.setRowCount(0)
91
+ Firmware.new(@api, 'I2C')
92
+ scan_result = @api.i2c_Scan(0)
93
+ if scan_result.include?(1)
94
+ scan_result.each_with_index do |v, i|
95
+ if v == 1
96
+ @i2c_settings_gui.tbl_bus_scan.insertRow(@i2c_settings_gui.tbl_bus_scan.rowCount)
97
+ @i2c_settings_gui.tbl_bus_scan.setItem(@i2c_settings_gui.tbl_bus_scan.rowCount - 1, 0, Qt::TableWidgetItem.new(i.to_s(16).upcase))
98
+ if i % 2 == 0
99
+ @i2c_settings_gui.tbl_bus_scan.setItem(@i2c_settings_gui.tbl_bus_scan.rowCount - 1, 1, Qt::TableWidgetItem.new('Write'))
100
+ else
101
+ @i2c_settings_gui.tbl_bus_scan.setItem(@i2c_settings_gui.tbl_bus_scan.rowCount - 1, 1, Qt::TableWidgetItem.new('Read'))
102
+ end
103
+ end
104
+ end
105
+ @i2c_settings_gui.tbl_bus_scan.resizeColumnsToContents
106
+ @i2c_settings_gui.tbl_bus_scan.resizeRowsToContents
107
+ @i2c_settings_gui.tbl_bus_scan.horizontalHeader.stretchLastSection = true
108
+ Qt::MessageBox.new(Qt::MessageBox::Information, "Bus Scan", "Bus scan ended correctly: #{@i2c_settings_gui.tbl_bus_scan.rowCount} address(es) found").exec
109
+ else
110
+ Qt::MessageBox.new(Qt::MessageBox::Information, "Bus addresses", "No valid addresses have been returned by the scan").exec
111
+ end
112
+ rescue Exception => msg
113
+ logger = Logger.new($logFilePath)
114
+ logger.error msg
115
+ Qt::MessageBox.new(Qt::MessageBox::Critical, "Critical error", "Error occured when scanning I2C. Consult the log for more details").exec
116
+ end
117
+ end
@@ -0,0 +1,146 @@
1
+ #===================================================
2
+ # Hardsploit GUI - By Opale Security
3
+ # www.opale-security.com || www.hardsploit.io
4
+ # License: GNU General Public License v3
5
+ # License URI: http://www.gnu.org/licenses/gpl.txt
6
+ #===================================================
7
+
8
+ require_relative '../../HardsploitAPI/HardsploitAPI'
9
+ require_relative '../../gui/gui_generic_export'
10
+
11
+ class Parallel_export < Qt::Widget
12
+ slots 'export()'
13
+ slots 'select_export_file()'
14
+
15
+ def initialize(api, chip)
16
+ super()
17
+ @parallel_export_gui = Ui_Generic_export.new
18
+ centerWindow(self)
19
+ @parallel_export_gui.setupUi(self)
20
+ @parallel_export_gui.lbl_chip.setText(chip.chip_reference)
21
+ inputRestrict(@parallel_export_gui.lie_start, 0)
22
+ inputRestrict(@parallel_export_gui.lie_stop, 0)
23
+ @api = api
24
+ @chip_settings = Parallel.find_by(parallel_chip: chip.chip_id)
25
+ end
26
+
27
+ def select_export_file
28
+ @filepath = Qt::FileDialog.getSaveFileName(self, tr('Select a file'), '/', tr('Bin file (*.bin)'))
29
+ unless @filepath.nil?
30
+ $file = File.open("#{@filepath}", 'w')
31
+ @parallel_export_gui.btn_export.setEnabled(true)
32
+ @parallel_export_gui.btn_full_export.setEnabled(true)
33
+ end
34
+ rescue Exception => msg
35
+ logger = Logger.new($logFilePath)
36
+ logger.error msg
37
+ Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while openning the export file. Consult the logs for more details').exec
38
+ end
39
+
40
+ def close_file
41
+ unless $file.nil?
42
+ $file.close
43
+ end
44
+ rescue Exception => msg
45
+ logger = Logger.new($logFilePath)
46
+ logger.error msg
47
+ Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while closing the export file. Consult the logs for more details').exec
48
+ end
49
+
50
+ def export
51
+ if sender.objectName == 'btn_full_export'
52
+ return 0 if control_export_settings('full').zero?
53
+ else
54
+ return 0 if control_export_settings('partial').zero?
55
+ end
56
+ Firmware.new(@api, 'PARALLEL')
57
+ time = Time.new
58
+ if sender.objectName == 'btn_full_export'
59
+ if @chip_settings.parallel_word_size.zero?
60
+ check_SendAndReceivedData(@api.read_Memory_WithoutMultiplexing(0, @chip_settings.parallel_total_size - 1, true, @chip_settings.parallel_read_latency))
61
+ else
62
+ check_SendAndReceivedData(@api.read_Memory_WithoutMultiplexing(0, @chip_settings.parallel_total_size - 1, false, @chip_settings.parallel_read_latency))
63
+ end
64
+ close_file
65
+ control_export_result(@chip_settings.parallel_total_size - 1, time)
66
+ else
67
+ if @chip_settings.parallel_word_size.zero?
68
+ check_SendAndReceivedData(@api.read_Memory_WithoutMultiplexing(@parallel_export_gui.lie_start.text.to_i, @parallel_export_gui.lie_stop.text.to_i, true, @chip_settings.parallel_read_latency))
69
+ else
70
+ check_SendAndReceivedData(@api.read_Memory_WithoutMultiplexing(@parallel_export_gui.lie_start.text.to_i, @parallel_export_gui.lie_stop.text.to_i, true, @chip_settings.parallel_read_latency))
71
+ end
72
+ close_file
73
+ control_export_result(@parallel_export_gui.lie_stop.text.to_i, time)
74
+ end
75
+ @parallel_export_gui.btn_export.setEnabled(false)
76
+ @parallel_export_gui.btn_full_export.setEnabled(false)
77
+ rescue Exception => msg
78
+ logger = Logger.new($logFilePath)
79
+ logger.error msg
80
+ Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while full export operation. Consult the logs for more details').exec
81
+ end
82
+
83
+ def control_export_result(stop, time)
84
+ time = Time.new - time
85
+ file_size = File.size("#{@filepath}")
86
+ # 8 bits test
87
+ if @chip_settings.parallel_word_size.zero?
88
+ if (stop - @cw.lie_start.text.to_i + 1) == file_size
89
+ Qt::MessageBox.new(Qt::MessageBox::Information, "Information", "Dump finished at #{((file_size / time)).round(2)}Bytes/s (#{(file_size)} Bytes in #{time.round(4)} s)").exec
90
+ else
91
+ Qt::MessageBox.new(Qt::MessageBox::Critical, "Error", "Dump error: Size does not match").exec
92
+ end
93
+ else
94
+ if (stop - @cw.lie_start.text.to_i + 1) == (file_size / 2)
95
+ Qt::MessageBox.new(Qt::MessageBox::Information, "Information", "Dump finished at #{((file_size / time)).round(2)}Bytes/s (#{(file_size)} Bytes in #{time.round(4)} s)").exec
96
+ else
97
+ Qt::MessageBox.new(Qt::MessageBox::Critical, "Error", "Dump error: File size and dump size does not match").exec
98
+ end
99
+ end
100
+ p "DUMP #{((file_size/time)).round(2)}Bytes/s (#{(file_size)}Bytes in #{time.round(4)} s)"
101
+ end
102
+
103
+ def control_export_settings(type)
104
+ if @chip_settings.nil?
105
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing parallel settings', 'No settings saved for this chip').exec
106
+ return 0
107
+ end
108
+ if @chip_settings.parallel_read_latency.nil? || @chip_settings.parallel_word_size.nil?
109
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing parallel settings', 'Read latency or word size settings missing').exec
110
+ return 0
111
+ end
112
+ if type == 'full'
113
+ if @chip_settings.parallel_total_size.zero? || @chip_settings.parallel_total_size.nil?
114
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Empty field', 'Full size setting missing or equal 0').exec
115
+ return 0
116
+ end
117
+ else
118
+ if @parallel_export_gui.lie_start.text.empty? || @parallel_export_gui.lie_stop.text.empty?
119
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Empty field', 'Start and stop address must be filled').exec
120
+ return 0
121
+ end
122
+ if @parallel_export_gui.lie_start.text.to_i > @parallel_export_gui.lie_stop.text.to_i
123
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Wrong value', 'Start address must be inforior to the stop address').exec
124
+ return 0
125
+ end
126
+ if @parallel_export_gui.lie_start.text.to_i > (@chip_settings.parallel_total_size - 1) || @parallel_export_gui.lie_stop.text.to_i > (@chip_settings.parallel_total_size - 1)
127
+ Qt::MessageBox.new(Qt::MessageBox::Warning, 'Wrong value', 'Start and stop address must be inforior to the chip total size').exec
128
+ return 0
129
+ end
130
+ end
131
+ return 1
132
+ end
133
+
134
+ def check_SendAndReceivedData(value)
135
+ case value
136
+ when HardsploitAPI::USB_STATE::PACKET_IS_TOO_LARGE
137
+ Qt::MessageBox.new(Qt::MessageBox::Critical, "Critical error", "PACKET_IS_TOO_LARGE max: #{HardsploitAPI::USB::USB_TRAME_SIZE}").exec
138
+ when HardsploitAPI::USB_STATE::ERROR_SEND
139
+ Qt::MessageBox.new(Qt::MessageBox::Critical, "Critical error", "ERROR_SEND").exec
140
+ when HardsploitAPI::USB_STATE::BUSY
141
+ Qt::MessageBox.new(Qt::MessageBox::Warning, "BUSY", "Device busy").exec
142
+ else
143
+ return value
144
+ end
145
+ end
146
+ end