hardsploit_gui 2.3 → 2.4.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 (149) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -22
  3. data/Rakefile +1 -1
  4. data/bin/hardsploit_gui +3 -3
  5. data/lib/Firmwares/FPGA/I2C/I2C_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_I2C_INTERACT.rpd +0 -0
  6. data/lib/Firmwares/FPGA/PARALLEL/NO_MUX_PARALLEL_MEMORY/HARDSPLOIT_FIRMWARE_FPGA_NO_MUX_PARALLEL_MEMORY.rpd +0 -0
  7. data/lib/Firmwares/FPGA/SPI/SPI_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SPI_INTERACT.rpd +0 -0
  8. data/lib/Firmwares/FPGA/SPI/SPI_SNIFFER/HARDSPLOIT_FIRMWARE_FPGA_SPI_SNIFFER.rpd +0 -0
  9. data/lib/Firmwares/FPGA/SWD/SWD_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SWD_INTERACT.rpd +0 -0
  10. data/lib/Firmwares/FPGA/UART/UART_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_UART_INTERACT.rpd +0 -0
  11. data/lib/Firmwares/FPGA/VersionFPGA.rb +5 -5
  12. data/lib/Firmwares/UC/VersionUC.rb +12 -12
  13. data/lib/HardsploitAPI/Core/HardsploitAPI.rb +210 -210
  14. data/lib/HardsploitAPI/Core/HardsploitAPI_CONSTANT.rb +150 -150
  15. data/lib/HardsploitAPI/Core/HardsploitAPI_ERROR.rb +109 -109
  16. data/lib/HardsploitAPI/Core/HardsploitAPI_FIRMWARE.rb +305 -305
  17. data/lib/HardsploitAPI/Core/HardsploitAPI_PROGRESS.rb +28 -28
  18. data/lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb +166 -166
  19. data/lib/HardsploitAPI/Modules/I2C/HardsploitAPI_I2C.rb +356 -356
  20. data/lib/HardsploitAPI/Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.rb +206 -206
  21. data/lib/HardsploitAPI/Modules/NRF24L01/HardsploitAPI_NRF24L01.rb +306 -306
  22. data/lib/HardsploitAPI/Modules/SPI/HardsploitAPI_SPI.rb +340 -340
  23. data/lib/HardsploitAPI/Modules/SPI_SNIFFER/HardsploitAPI_SPI_SNIFFER.rb +83 -83
  24. data/lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD.rb +367 -367
  25. data/lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_DEBUG.rb +89 -89
  26. data/lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_MEM_AP.rb +61 -61
  27. data/lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_STM32.rb +121 -121
  28. data/lib/HardsploitAPI/Modules/TEST/HardsploitAPI_TEST_INTERACT.rb +98 -98
  29. data/lib/HardsploitAPI/Modules/UART/HardsploitAPI_UART.rb +196 -196
  30. data/lib/Hardsploit_gui.rb +96 -96
  31. data/lib/LICENSE.txt +674 -674
  32. data/lib/README.md +22 -22
  33. data/lib/TRADEMARK +2 -2
  34. data/lib/class/Chip_editor.rb +304 -304
  35. data/lib/class/Chip_management.rb +496 -496
  36. data/lib/class/Command_editor.rb +216 -216
  37. data/lib/class/Command_table.rb +233 -233
  38. data/lib/class/Console.rb +26 -26
  39. data/lib/class/ErrorMsg.rb +312 -312
  40. data/lib/class/Export.rb +140 -140
  41. data/lib/class/Export_manager.rb +124 -124
  42. data/lib/class/Firmware.rb +70 -70
  43. data/lib/class/Generic_commands.rb +260 -260
  44. data/lib/class/{i2c → I2C}/I2c_command.rb +51 -51
  45. data/lib/class/{i2c → I2C}/I2c_export.rb +95 -95
  46. data/lib/class/{i2c → I2C}/I2c_import.rb +117 -117
  47. data/lib/class/{i2c → I2C}/I2c_scanner.rb +114 -114
  48. data/lib/class/{i2c → I2C}/I2c_settings.rb +148 -148
  49. data/lib/class/Import.rb +193 -193
  50. data/lib/class/{parallel → PARALLEL}/Parallel_export.rb +118 -118
  51. data/lib/class/{parallel → PARALLEL}/Parallel_import.rb +113 -113
  52. data/lib/class/{parallel → PARALLEL}/Parallel_settings.rb +81 -81
  53. data/lib/class/Progress_bar.rb +32 -32
  54. data/lib/class/{spi → SPI}/Spi_export.rb +108 -108
  55. data/lib/class/{spi → SPI}/Spi_import.rb +159 -159
  56. data/lib/class/{spi → SPI}/Spi_settings.rb +108 -108
  57. data/lib/class/{spi → SPI}/Spi_sniffer.rb +101 -101
  58. data/lib/class/Signal_mapper.rb +120 -120
  59. data/lib/class/Wire_helper.rb +230 -230
  60. data/lib/class/swd/Swd.rb +125 -125
  61. data/lib/class/swd/Swd_scanner.rb +121 -121
  62. data/lib/class/swd/Swd_settings.rb +76 -76
  63. data/lib/class/uart/Uart_baudrate.rb +62 -62
  64. data/lib/class/uart/Uart_console.rb +115 -115
  65. data/lib/class/uart/Uart_settings.rb +102 -102
  66. data/lib/db/associations.rb +138 -138
  67. data/lib/db/database.rb +4 -4
  68. data/lib/db/development.sqlite3 +0 -0
  69. data/lib/db/migrate/004_create_manufacturers.rb +13 -13
  70. data/lib/db/migrate/005_create_packages.rb +13 -13
  71. data/lib/db/migrate/006_create_chip_types.rb +11 -11
  72. data/lib/db/migrate/007_create_buses.rb +11 -11
  73. data/lib/db/migrate/008_create_signals.rb +14 -14
  74. data/lib/db/migrate/009_create_chips.rb +25 -25
  75. data/lib/db/migrate/010_create_commands.rb +21 -21
  76. data/lib/db/migrate/011_create_bytes.rb +19 -19
  77. data/lib/db/migrate/012_create_i2c_settings.rb +21 -21
  78. data/lib/db/migrate/013_create_spi_settings.rb +26 -26
  79. data/lib/db/migrate/014_create_parallel_settings.rb +21 -21
  80. data/lib/db/migrate/015_create_pins.rb +19 -19
  81. data/lib/db/migrate/016_create_uses.rb +17 -17
  82. data/lib/db/migrate/017_create_swd_settings.rb +19 -19
  83. data/lib/db/migrate/018_create_uart_settings.rb +22 -22
  84. data/lib/db/schema.rb +157 -157
  85. data/lib/db/seeds.rb +161 -161
  86. data/lib/gui/gui_chip_editor.rb +349 -349
  87. data/lib/gui/gui_chip_management.rb +377 -377
  88. data/lib/gui/gui_command_editor.rb +219 -219
  89. data/lib/gui/gui_export.rb +132 -132
  90. data/lib/gui/gui_export_manager.rb +93 -93
  91. data/lib/gui/gui_generic_commands.rb +202 -202
  92. data/lib/gui/gui_generic_export.rb +164 -164
  93. data/lib/gui/gui_generic_import.rb +142 -142
  94. data/lib/gui/gui_i2c_command.rb +116 -116
  95. data/lib/gui/gui_i2c_settings.rb +230 -230
  96. data/lib/gui/gui_import.rb +131 -131
  97. data/lib/gui/gui_parallel_settings.rb +195 -195
  98. data/lib/gui/gui_progress_bar.rb +85 -85
  99. data/lib/gui/gui_signal_mapper.rb +121 -121
  100. data/lib/gui/gui_signal_scanner.rb +146 -146
  101. data/lib/gui/gui_spi_import.rb +126 -126
  102. data/lib/gui/gui_spi_settings.rb +313 -313
  103. data/lib/gui/gui_spi_sniffer.rb +112 -112
  104. data/lib/gui/gui_swd_settings.rb +166 -166
  105. data/lib/gui/gui_uart_baudrate.rb +114 -114
  106. data/lib/gui/gui_uart_console.rb +164 -164
  107. data/lib/gui/gui_uart_settings.rb +243 -243
  108. data/lib/gui/gui_wire_helper.rb +99 -99
  109. data/lib/gui_designer/gui_chip_editor.ui +549 -549
  110. data/lib/gui_designer/gui_chip_management.ui +886 -886
  111. data/lib/gui_designer/gui_command_editor.ui +350 -350
  112. data/lib/gui_designer/gui_export.ui +171 -171
  113. data/lib/gui_designer/gui_export_manager.ui +115 -115
  114. data/lib/gui_designer/gui_generic_commands.ui +342 -342
  115. data/lib/gui_designer/gui_generic_export.ui +202 -202
  116. data/lib/gui_designer/gui_generic_import.ui +165 -165
  117. data/lib/gui_designer/gui_i2c_command.ui +148 -148
  118. data/lib/gui_designer/gui_i2c_settings.ui +292 -292
  119. data/lib/gui_designer/gui_import.ui +168 -168
  120. data/lib/gui_designer/gui_parallel_settings.ui +247 -247
  121. data/lib/gui_designer/gui_progress_bar.ui +86 -86
  122. data/lib/gui_designer/gui_signal_mapper.ui +179 -179
  123. data/lib/gui_designer/gui_signal_scanner.ui +261 -261
  124. data/lib/gui_designer/gui_spi_settings.ui +446 -446
  125. data/lib/gui_designer/gui_spi_sniffer.ui +156 -156
  126. data/lib/gui_designer/gui_swd_settings.ui +189 -189
  127. data/lib/gui_designer/gui_uart_baudrate.ui +161 -161
  128. data/lib/gui_designer/gui_uart_console.ui +284 -284
  129. data/lib/gui_designer/gui_uart_settings.ui +280 -280
  130. data/lib/gui_designer/gui_wire_helper.ui +117 -117
  131. data/lib/images/search.png +0 -0
  132. data/lib/logs/error.log +0 -63
  133. data/lib/models/bus.rb +19 -19
  134. data/lib/models/byte.rb +29 -29
  135. data/lib/models/chip.rb +41 -41
  136. data/lib/models/chip_type.rb +14 -14
  137. data/lib/models/command.rb +20 -20
  138. data/lib/models/i2c_setting.rb +41 -41
  139. data/lib/models/manufacturer.rb +14 -14
  140. data/lib/models/package.rb +26 -26
  141. data/lib/models/parallel_setting.rb +37 -37
  142. data/lib/models/pin.rb +14 -14
  143. data/lib/models/signall.rb +20 -20
  144. data/lib/models/spi_setting.rb +67 -67
  145. data/lib/models/swd_setting.rb +25 -25
  146. data/lib/models/uart_setting.rb +52 -52
  147. data/lib/models/use.rb +6 -6
  148. data/lib/startHardsploit.rb +10 -10
  149. metadata +14 -14
@@ -1,70 +1,70 @@
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
- class Firmware
9
- def initialize(firmware)
10
- unless $currentFirmware == firmware
11
- unless $currentFirmware == 'uC'
12
- $pgb = Progress_bar.new("Upload firmware :")
13
- $pgb.show
14
- end
15
- base_path = File.expand_path(File.dirname(__FILE__)) + '/../Firmwares/FPGA/'
16
- case firmware
17
- when 'I2C'
18
- firmware_path = base_path + 'I2C/I2C_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_I2C_INTERACT.rpd'
19
- HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
20
- when 'SPI'
21
- firmware_path = base_path + 'SPI/SPI_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SPI_INTERACT.rpd'
22
- HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
23
- when 'SPI_SNIFFER'
24
- firmware_path = base_path + 'SPI/SPI_SNIFFER/HARDSPLOIT_FIRMWARE_FPGA_SPI_SNIFFER.rpd'
25
- HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
26
- when 'PARALLEL'
27
- firmware_path = base_path + 'PARALLEL/NO_MUX_PARALLEL_MEMORY/HARDSPLOIT_FIRMWARE_FPGA_NO_MUX_PARALLEL_MEMORY.rpd'
28
- HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
29
- when 'SWD'
30
- firmware_path = base_path + 'SWD/SWD_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SWD_INTERACT.rpd'
31
- HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
32
- when 'UART'
33
- firmware_path = base_path + 'UART/UART_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_UART_INTERACT.rpd'
34
- HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
35
- when 'uC'
36
- msg = Qt::MessageBox.new
37
- msg.setWindowTitle("Microcontroller update")
38
- msg.setText("Hardsploit must be in bootloader mode and dfu-util package must be installed in order to continue. Proceed ?")
39
- msg.setIcon(Qt::MessageBox::Question)
40
- msg.setStandardButtons(Qt::MessageBox::Cancel | Qt::MessageBox::Ok)
41
- msg.setDefaultButton(Qt::MessageBox::Cancel)
42
- if msg.exec == Qt::MessageBox::Ok
43
- system("dfu-util -D 0483:df11 -a 0 -s 0x08000000 -R --download #{File.expand_path(File.dirname(__FILE__))}'/../Firmware/UC/HARDSPLOIT_FIRMWARE_UC.bin'")
44
- end
45
- end
46
- $currentFirmware = firmware unless firmware == 'uC'
47
- firmware = "SPI" if firmware == "SPI_SNIFFER"
48
- $pgb.close
49
- sleep(2)
50
- end
51
-
52
- case firmware
53
- when 'PARALLEL', 'SWD', 'UART', 'I2C', 'SPI'
54
- # CrossWiring
55
- crossvalue = []
56
- for i in 0..63
57
- crossvalue.push i
58
- end
59
- pin_group = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
60
- Bus.find_by(name: firmware).signalls.each do |s|
61
- hardsploit_pin_number = pin_group.index(s.pin[0]) * 8 + s.pin[1].to_i
62
- crossvalue[hardsploit_pin_number] = HardsploitAPI.getSignalId(signal: s.name)
63
- crossvalue[HardsploitAPI.getSignalId(signal: s.name)] = hardsploit_pin_number
64
- end
65
- HardsploitAPI.instance.setCrossWiring(value: crossvalue)
66
- end
67
- rescue Exception => msg
68
- ErrorMsg.new.unknown(msg)
69
- end
70
- end
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
+ class Firmware
9
+ def initialize(firmware)
10
+ unless $currentFirmware == firmware
11
+ unless $currentFirmware == 'uC'
12
+ $pgb = Progress_bar.new("Upload firmware :")
13
+ $pgb.show
14
+ end
15
+ base_path = File.expand_path(File.dirname(__FILE__)) + '/../Firmwares/FPGA/'
16
+ case firmware
17
+ when 'I2C'
18
+ firmware_path = base_path + 'I2C/I2C_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_I2C_INTERACT.rpd'
19
+ HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
20
+ when 'SPI'
21
+ firmware_path = base_path + 'SPI/SPI_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SPI_INTERACT.rpd'
22
+ HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
23
+ when 'SPI_SNIFFER'
24
+ firmware_path = base_path + 'SPI/SPI_SNIFFER/HARDSPLOIT_FIRMWARE_FPGA_SPI_SNIFFER.rpd'
25
+ HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
26
+ when 'PARALLEL'
27
+ firmware_path = base_path + 'PARALLEL/NO_MUX_PARALLEL_MEMORY/HARDSPLOIT_FIRMWARE_FPGA_NO_MUX_PARALLEL_MEMORY.rpd'
28
+ HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
29
+ when 'SWD'
30
+ firmware_path = base_path + 'SWD/SWD_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SWD_INTERACT.rpd'
31
+ HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
32
+ when 'UART'
33
+ firmware_path = base_path + 'UART/UART_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_UART_INTERACT.rpd'
34
+ HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
35
+ when 'uC'
36
+ msg = Qt::MessageBox.new
37
+ msg.setWindowTitle("Microcontroller update")
38
+ msg.setText("Hardsploit must be in bootloader mode and dfu-util package must be installed in order to continue. Proceed ?")
39
+ msg.setIcon(Qt::MessageBox::Question)
40
+ msg.setStandardButtons(Qt::MessageBox::Cancel | Qt::MessageBox::Ok)
41
+ msg.setDefaultButton(Qt::MessageBox::Cancel)
42
+ if msg.exec == Qt::MessageBox::Ok
43
+ system("dfu-util -D 0483:df11 -a 0 -s 0x08000000 -R --download #{File.expand_path(File.dirname(__FILE__))}'/../Firmwares/UC/HARDSPLOIT_FIRMWARE_UC.bin'")
44
+ end
45
+ end
46
+ $currentFirmware = firmware unless firmware == 'uC'
47
+ firmware = "SPI" if firmware == "SPI_SNIFFER"
48
+ $pgb.close
49
+ sleep(2)
50
+ end
51
+
52
+ case firmware
53
+ when 'PARALLEL', 'SWD', 'UART', 'I2C', 'SPI'
54
+ # CrossWiring
55
+ crossvalue = []
56
+ for i in 0..63
57
+ crossvalue.push i
58
+ end
59
+ pin_group = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
60
+ Bus.find_by(name: firmware).signalls.each do |s|
61
+ hardsploit_pin_number = pin_group.index(s.pin[0]) * 8 + s.pin[1].to_i
62
+ crossvalue[hardsploit_pin_number] = HardsploitAPI.getSignalId(signal: s.name)
63
+ crossvalue[HardsploitAPI.getSignalId(signal: s.name)] = hardsploit_pin_number
64
+ end
65
+ HardsploitAPI.instance.setCrossWiring(value: crossvalue)
66
+ end
67
+ rescue Exception => msg
68
+ ErrorMsg.new.unknown(msg)
69
+ end
70
+ end
@@ -1,260 +1,260 @@
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_generic_commands'
9
- require_relative '../gui/gui_export_manager'
10
-
11
- class Generic_commands < Qt::MainWindow
12
- slots 'feed_cmd_array()'
13
- slots 'execute()'
14
- slots 'create()'
15
- slots 'edit()'
16
- slots 'delete()'
17
- slots 'template()'
18
- slots 'concatenate()'
19
-
20
- def initialize(chip, bus_name)
21
- super()
22
- @view = Ui_Generic_commands.new
23
- centerWindow(self)
24
- @view.setupUi(self)
25
- @view.lbl_chip.setText(chip.reference)
26
- @view.lbl_search.setPixmap(Qt::Pixmap.new('images/search.png'))
27
- inputRestrict(@view.lie_search, 2)
28
- @chip = chip
29
- @bus_name = bus_name
30
- @bus_id = Bus.find_by(name: bus_name).id
31
- select_chip_settings(bus_name)
32
- feed_cmd_array
33
- end
34
-
35
- def contextMenuEvent(event)
36
- if @view.tbl_cmd.currentItem.nil?
37
- return false
38
- else
39
- return false if @view.tbl_cmd.currentItem.column == 1
40
- menu = Qt::Menu.new(self)
41
- menu.addAction(@view.actionExecute)
42
- menu.addAction(@view.actionEdit)
43
- menu.addAction(@view.actionTemplate)
44
- menu.addAction(@view.actionDelete)
45
- menu.addAction(@view.actionConcatenate)
46
- menu.exec(event.globalPos())
47
- end
48
- end
49
-
50
- def execute
51
- return ErrorMsg.new.hardsploit_not_found unless HardsploitAPI.getNumberOfBoardAvailable > 0
52
- return ErrorMsg.new.no_cmd_selected if @view.tbl_cmd.currentItem.nil?
53
- cmd_array = prepare_cmd
54
- result = exec_cmd(@bus_name, cmd_array)
55
- if @view.check_result.isChecked && result != false
56
- export_manager = Export_manager.new(@bus_name, result, cmd_array)
57
- export_manager.setWindowModality(Qt::ApplicationModal)
58
- export_manager.show
59
- end
60
- end
61
-
62
- def create
63
- if @bus_name == 'I2C'
64
- cmdBase = I2c_command.new(@chip, @bus_id, self)
65
- else
66
- cmdBase = Command_editor.new(0, nil, @chip, @bus_id, self)
67
- end
68
- cmdBase.show
69
- end
70
-
71
- def edit
72
- return ErrorMsg.new.no_cmd_selected if @view.tbl_cmd.currentItem.nil?
73
- cmdBase = Command_editor.new(2, @view.tbl_cmd.currentItem.text, @chip, @bus_id, self)
74
- cmdBase.show
75
- end
76
-
77
- def template
78
- return ErrorMsg.new.no_cmd_selected if @view.tbl_cmd.currentItem.nil?
79
- cmdBase = Command_editor.new(1, @view.tbl_cmd.currentItem.text, @chip, @bus_id, self)
80
- cmdBase.show
81
- end
82
-
83
- def delete
84
- return ErrorMsg.new.no_cmd_selected if @view.tbl_cmd.currentItem.nil?
85
- msg = Qt::MessageBox.new
86
- msg.setWindowTitle('Delete command')
87
- msg.setText('Confirm the delete command action ?')
88
- msg.setIcon(Qt::MessageBox::Question)
89
- msg.setStandardButtons(Qt::MessageBox::Cancel | Qt::MessageBox::Ok)
90
- msg.setDefaultButton(Qt::MessageBox::Cancel)
91
- if msg.exec == Qt::MessageBox::Ok
92
- @chip.commands.find_by(name: @view.tbl_cmd.currentItem.text).destroy
93
- feed_cmd_array
94
- end
95
- end
96
-
97
- def concatenate
98
- return ErrorMsg.new.concat_disallow unless @bus_name == "I2C"
99
- return ErrorMsg.new.concat_nbr unless @view.tbl_cmd.selectedItems.count == 2
100
- cmd1 = Command.find_by(name: @view.tbl_cmd.selectedItems[0].text)
101
- cmd2 = Command.find_by(name: @view.tbl_cmd.selectedItems[1].text)
102
- return false unless check_concatenation_size(cmd1.bytes, cmd2.bytes)
103
-
104
- cmd_1 = @view.tbl_cmd.selectedItems[0].text
105
- cmd_2 = @view.tbl_cmd.selectedItems[1].text
106
- cmd = Command.create(
107
- name: 'New concatenation',
108
- description: "Concatenation of #{cmd1.name} and #{cmd2.name} commands",
109
- bus_id: @bus_id,
110
- chip_id: @chip.id
111
- )
112
- unless check_for_errors(cmd)
113
- cmd1.bytes.each do |b1|
114
- byte1 = Byte.create(
115
- index: b1.index,
116
- value: b1.value,
117
- description: b1.description,
118
- iteration: b1.iteration,
119
- command_id: Command.last.id
120
- )
121
- check_for_errors(byte1)
122
- end
123
- cmd2.bytes.each do |b2|
124
- byte2 = Byte.create(
125
- index: Byte.last.index + 1,
126
- value: b2.value,
127
- description: b2.description,
128
- iteration: b2.iteration,
129
- command_id: Command.last.id
130
- )
131
- check_for_errors(byte2)
132
- end
133
- feed_cmd_array
134
- end
135
- end
136
-
137
- def feed_cmd_array
138
- @view.tbl_cmd.clearContents
139
- cmd = @chip.commands.where(bus_id: @bus_id)
140
- unless @view.lie_search.text.empty?
141
- cmd = cmd.where('name LIKE ?', "%#{@view.lie_search.text}%")
142
- end
143
- @view.tbl_cmd.setRowCount(cmd.count);
144
- cmd.to_enum.with_index(0).each do |c, i|
145
- it1 = Qt::TableWidgetItem.new(c.name)
146
- it1.setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled)
147
- it2 = Qt::TableWidgetItem.new(c.description)
148
- it2.setFlags(Qt::ItemIsEnabled)
149
- @view.tbl_cmd.setItem(i, 0, it1);
150
- @view.tbl_cmd.setItem(i, 1, it2);
151
- end
152
- @view.tbl_cmd.resizeColumnsToContents
153
- @view.tbl_cmd.resizeRowsToContents
154
- @view.tbl_cmd.horizontalHeader.stretchLastSection = true
155
- rescue Exception => msg
156
- ErrorMsg.new.unknown(msg)
157
- end
158
-
159
- def select_chip_settings(bus)
160
- case bus
161
- when 'SPI'
162
- @chip_settings = SpiSetting.find_by(chip_id: @chip.id)
163
- @speeds = {
164
- '25.00' => 3,
165
- '18.75' => 4,
166
- '15.00' => 5,
167
- '12.50' => 6,
168
- '10.71' => 7,
169
- '9.38' => 8,
170
- '7.50' => 10,
171
- '5.00' => 15,
172
- '3.95' => 19,
173
- '3.00' => 25,
174
- '2.03' => 37,
175
- '1.00' => 75,
176
- '0.50' => 150,
177
- '0.29' => 255
178
- }
179
- when 'I2C'
180
- @chip_settings = @chip.i2c_setting
181
- end
182
- end
183
-
184
- def prepare_cmd
185
- byte_list = Byte.where(command_id: Command.find_by(name: @view.tbl_cmd.currentItem.text))
186
- packet = []
187
- byte_list.each do |bl|
188
- unless bl.iteration == 0 && bl.iteration.nil?
189
- packet.push(bl.value.to_i(16))
190
- else
191
- for i in 1..bl.iteration.to_i do
192
- packet.push(bl.value.to_i(16))
193
- end
194
- end
195
- end
196
- return packet
197
- end
198
-
199
- def exec_cmd(bus, array_sent)
200
- Firmware.new(bus)
201
- case bus
202
- when 'SPI'
203
- spi = HardsploitAPI_SPI.new(
204
- speed: @speeds[@chip.spi_setting.frequency],
205
- mode: @chip.spi_setting.mode
206
- )
207
- return spi.spi_Interact(payload: array_sent)
208
- when 'I2C'
209
- if [40, 100, 400, 1000].include?(@chip.i2c_setting.frequency)
210
- speed = 0 if @chip.i2c_setting.frequency == 100
211
- speed = 1 if @chip.i2c_setting.frequency == 400
212
- speed = 2 if @chip.i2c_setting.frequency == 1000
213
- speed = 3 if @chip.i2c_setting.frequency == 40
214
- i2c = HardsploitAPI_I2C.new(speed: speed)
215
- end
216
- return i2c.i2c_Interact(payload: array_sent)
217
- end
218
- rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
219
- ErrorMsg.new.hardsploit_not_found
220
- return false
221
- rescue HardsploitAPI::ERROR::USB_ERROR
222
- ErrorMsg.new.usb_error
223
- return false
224
- rescue Exception => msg
225
- ErrorMsg.new.unknown(msg)
226
- return false
227
- end
228
-
229
- def check_concatenation_size(bytes_cmd_1, bytes_cmd_2)
230
- check_size = []
231
- bytes_cmd_1.each do |b1|
232
- check_size.push(b1.value)
233
- end
234
- bytes_cmd_2.each do |b2|
235
- check_size.push(b2.value)
236
- end
237
- count = 0
238
- i = 0
239
- while i <= (check_size.size) - 1 do
240
- lowByte = check_size[i]
241
- highByte = check_size[i + 1]
242
- commandType = check_size[i + 2]
243
- count += (lowByte.to_i(16) + (highByte.to_i(16) << 8))
244
- if commandType.to_i(16) % 2 == 0 #WRITE
245
- i += ((lowByte.to_i(16) + (highByte.to_i(16) << 8)) + 3)
246
- else #READ
247
- i = (i + 3)
248
- end
249
- end
250
- if count > 2000
251
- Qt::MessageBox.new(
252
- Qt::MessageBox::Critical,
253
- 'Critical error',
254
- 'Command too big: unable to concatenate'
255
- ).exec
256
- return false
257
- end
258
- return true
259
- end
260
- end
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_generic_commands'
9
+ require_relative '../gui/gui_export_manager'
10
+
11
+ class Generic_commands < Qt::MainWindow
12
+ slots 'feed_cmd_array()'
13
+ slots 'execute()'
14
+ slots 'create()'
15
+ slots 'edit()'
16
+ slots 'delete()'
17
+ slots 'template()'
18
+ slots 'concatenate()'
19
+
20
+ def initialize(chip, bus_name)
21
+ super()
22
+ @view = Ui_Generic_commands.new
23
+ centerWindow(self)
24
+ @view.setupUi(self)
25
+ @view.lbl_chip.setText(chip.reference)
26
+ @view.lbl_search.setPixmap(Qt::Pixmap.new('images/search.png'))
27
+ inputRestrict(@view.lie_search, 2)
28
+ @chip = chip
29
+ @bus_name = bus_name
30
+ @bus_id = Bus.find_by(name: bus_name).id
31
+ select_chip_settings(bus_name)
32
+ feed_cmd_array
33
+ end
34
+
35
+ def contextMenuEvent(event)
36
+ if @view.tbl_cmd.currentItem.nil?
37
+ return false
38
+ else
39
+ return false if @view.tbl_cmd.currentItem.column == 1
40
+ menu = Qt::Menu.new(self)
41
+ menu.addAction(@view.actionExecute)
42
+ menu.addAction(@view.actionEdit)
43
+ menu.addAction(@view.actionTemplate)
44
+ menu.addAction(@view.actionDelete)
45
+ menu.addAction(@view.actionConcatenate)
46
+ menu.exec(event.globalPos())
47
+ end
48
+ end
49
+
50
+ def execute
51
+ return ErrorMsg.new.hardsploit_not_found unless HardsploitAPI.getNumberOfBoardAvailable > 0
52
+ return ErrorMsg.new.no_cmd_selected if @view.tbl_cmd.currentItem.nil?
53
+ cmd_array = prepare_cmd
54
+ result = exec_cmd(@bus_name, cmd_array)
55
+ if @view.check_result.isChecked && result != false
56
+ export_manager = Export_manager.new(@bus_name, result, cmd_array)
57
+ export_manager.setWindowModality(Qt::ApplicationModal)
58
+ export_manager.show
59
+ end
60
+ end
61
+
62
+ def create
63
+ if @bus_name == 'I2C'
64
+ cmdBase = I2c_command.new(@chip, @bus_id, self)
65
+ else
66
+ cmdBase = Command_editor.new(0, nil, @chip, @bus_id, self)
67
+ end
68
+ cmdBase.show
69
+ end
70
+
71
+ def edit
72
+ return ErrorMsg.new.no_cmd_selected if @view.tbl_cmd.currentItem.nil?
73
+ cmdBase = Command_editor.new(2, @view.tbl_cmd.currentItem.text, @chip, @bus_id, self)
74
+ cmdBase.show
75
+ end
76
+
77
+ def template
78
+ return ErrorMsg.new.no_cmd_selected if @view.tbl_cmd.currentItem.nil?
79
+ cmdBase = Command_editor.new(1, @view.tbl_cmd.currentItem.text, @chip, @bus_id, self)
80
+ cmdBase.show
81
+ end
82
+
83
+ def delete
84
+ return ErrorMsg.new.no_cmd_selected if @view.tbl_cmd.currentItem.nil?
85
+ msg = Qt::MessageBox.new
86
+ msg.setWindowTitle('Delete command')
87
+ msg.setText('Confirm the delete command action ?')
88
+ msg.setIcon(Qt::MessageBox::Question)
89
+ msg.setStandardButtons(Qt::MessageBox::Cancel | Qt::MessageBox::Ok)
90
+ msg.setDefaultButton(Qt::MessageBox::Cancel)
91
+ if msg.exec == Qt::MessageBox::Ok
92
+ @chip.commands.find_by(name: @view.tbl_cmd.currentItem.text).destroy
93
+ feed_cmd_array
94
+ end
95
+ end
96
+
97
+ def concatenate
98
+ return ErrorMsg.new.concat_disallow unless @bus_name == "I2C"
99
+ return ErrorMsg.new.concat_nbr unless @view.tbl_cmd.selectedItems.count == 2
100
+ cmd1 = Command.find_by(name: @view.tbl_cmd.selectedItems[0].text)
101
+ cmd2 = Command.find_by(name: @view.tbl_cmd.selectedItems[1].text)
102
+ return false unless check_concatenation_size(cmd1.bytes, cmd2.bytes)
103
+
104
+ cmd_1 = @view.tbl_cmd.selectedItems[0].text
105
+ cmd_2 = @view.tbl_cmd.selectedItems[1].text
106
+ cmd = Command.create(
107
+ name: 'New concatenation',
108
+ description: "Concatenation of #{cmd1.name} and #{cmd2.name} commands",
109
+ bus_id: @bus_id,
110
+ chip_id: @chip.id
111
+ )
112
+ unless check_for_errors(cmd)
113
+ cmd1.bytes.each do |b1|
114
+ byte1 = Byte.create(
115
+ index: b1.index,
116
+ value: b1.value,
117
+ description: b1.description,
118
+ iteration: b1.iteration,
119
+ command_id: Command.last.id
120
+ )
121
+ check_for_errors(byte1)
122
+ end
123
+ cmd2.bytes.each do |b2|
124
+ byte2 = Byte.create(
125
+ index: Byte.last.index + 1,
126
+ value: b2.value,
127
+ description: b2.description,
128
+ iteration: b2.iteration,
129
+ command_id: Command.last.id
130
+ )
131
+ check_for_errors(byte2)
132
+ end
133
+ feed_cmd_array
134
+ end
135
+ end
136
+
137
+ def feed_cmd_array
138
+ @view.tbl_cmd.clearContents
139
+ cmd = @chip.commands.where(bus_id: @bus_id)
140
+ unless @view.lie_search.text.empty?
141
+ cmd = cmd.where('name LIKE ?', "%#{@view.lie_search.text}%")
142
+ end
143
+ @view.tbl_cmd.setRowCount(cmd.count);
144
+ cmd.to_enum.with_index(0).each do |c, i|
145
+ it1 = Qt::TableWidgetItem.new(c.name)
146
+ it1.setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled)
147
+ it2 = Qt::TableWidgetItem.new(c.description)
148
+ it2.setFlags(Qt::ItemIsEnabled)
149
+ @view.tbl_cmd.setItem(i, 0, it1);
150
+ @view.tbl_cmd.setItem(i, 1, it2);
151
+ end
152
+ @view.tbl_cmd.resizeColumnsToContents
153
+ @view.tbl_cmd.resizeRowsToContents
154
+ @view.tbl_cmd.horizontalHeader.stretchLastSection = true
155
+ rescue Exception => msg
156
+ ErrorMsg.new.unknown(msg)
157
+ end
158
+
159
+ def select_chip_settings(bus)
160
+ case bus
161
+ when 'SPI'
162
+ @chip_settings = SpiSetting.find_by(chip_id: @chip.id)
163
+ @speeds = {
164
+ '25.00' => 3,
165
+ '18.75' => 4,
166
+ '15.00' => 5,
167
+ '12.50' => 6,
168
+ '10.71' => 7,
169
+ '9.38' => 8,
170
+ '7.50' => 10,
171
+ '5.00' => 15,
172
+ '3.95' => 19,
173
+ '3.00' => 25,
174
+ '2.03' => 37,
175
+ '1.00' => 75,
176
+ '0.50' => 150,
177
+ '0.29' => 255
178
+ }
179
+ when 'I2C'
180
+ @chip_settings = @chip.i2c_setting
181
+ end
182
+ end
183
+
184
+ def prepare_cmd
185
+ byte_list = Byte.where(command_id: Command.find_by(name: @view.tbl_cmd.currentItem.text))
186
+ packet = []
187
+ byte_list.each do |bl|
188
+ unless bl.iteration == 0 && bl.iteration.nil?
189
+ packet.push(bl.value.to_i(16))
190
+ else
191
+ for i in 1..bl.iteration.to_i do
192
+ packet.push(bl.value.to_i(16))
193
+ end
194
+ end
195
+ end
196
+ return packet
197
+ end
198
+
199
+ def exec_cmd(bus, array_sent)
200
+ Firmware.new(bus)
201
+ case bus
202
+ when 'SPI'
203
+ spi = HardsploitAPI_SPI.new(
204
+ speed: @speeds[@chip.spi_setting.frequency],
205
+ mode: @chip.spi_setting.mode
206
+ )
207
+ return spi.spi_Interact(payload: array_sent)
208
+ when 'I2C'
209
+ if [40, 100, 400, 1000].include?(@chip.i2c_setting.frequency)
210
+ speed = 0 if @chip.i2c_setting.frequency == 100
211
+ speed = 1 if @chip.i2c_setting.frequency == 400
212
+ speed = 2 if @chip.i2c_setting.frequency == 1000
213
+ speed = 3 if @chip.i2c_setting.frequency == 40
214
+ i2c = HardsploitAPI_I2C.new(speed: speed)
215
+ end
216
+ return i2c.i2c_Interact(payload: array_sent)
217
+ end
218
+ rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
219
+ ErrorMsg.new.hardsploit_not_found
220
+ return false
221
+ rescue HardsploitAPI::ERROR::USB_ERROR
222
+ ErrorMsg.new.usb_error
223
+ return false
224
+ rescue Exception => msg
225
+ ErrorMsg.new.unknown(msg)
226
+ return false
227
+ end
228
+
229
+ def check_concatenation_size(bytes_cmd_1, bytes_cmd_2)
230
+ check_size = []
231
+ bytes_cmd_1.each do |b1|
232
+ check_size.push(b1.value)
233
+ end
234
+ bytes_cmd_2.each do |b2|
235
+ check_size.push(b2.value)
236
+ end
237
+ count = 0
238
+ i = 0
239
+ while i <= (check_size.size) - 1 do
240
+ lowByte = check_size[i]
241
+ highByte = check_size[i + 1]
242
+ commandType = check_size[i + 2]
243
+ count += (lowByte.to_i(16) + (highByte.to_i(16) << 8))
244
+ if commandType.to_i(16) % 2 == 0 #WRITE
245
+ i += ((lowByte.to_i(16) + (highByte.to_i(16) << 8)) + 3)
246
+ else #READ
247
+ i = (i + 3)
248
+ end
249
+ end
250
+ if count > 2000
251
+ Qt::MessageBox.new(
252
+ Qt::MessageBox::Critical,
253
+ 'Critical error',
254
+ 'Command too big: unable to concatenate'
255
+ ).exec
256
+ return false
257
+ end
258
+ return true
259
+ end
260
+ end