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.
- checksums.yaml +7 -0
- data/README.md +22 -0
- data/Rakefile +1 -0
- data/bin/hardsploit_gui +3 -0
- data/lib/Firmware/FPGA/I2C/I2C_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_I2C_INTERACT.rpd +0 -0
- data/lib/Firmware/FPGA/PARALLEL/NO_MUX_PARALLEL_MEMORY/HARDSPLOIT_FIRMWARE_FPGA_NO_MUX_PARALLEL_MEMORY.rpd +0 -0
- data/lib/Firmware/FPGA/SPI/SPI_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SPI_INTERACT.rpd +0 -0
- data/lib/Firmware/FPGA/SWD/SWD_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SWD_INTERACT.rpd +0 -0
- data/lib/Firmware/FPGA/TEST/TEST_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_TEST_INTERACT.rpd +0 -0
- data/lib/Firmware/FPGA/VersionFPGA.rb +5 -0
- data/lib/Firmware/UC/HARDSPLOIT_FIRMWARE_UC.bin +0 -0
- data/lib/Firmware/UC/VersionUC.rb +12 -0
- data/lib/HardsploitAPI/HardsploitAPI.rb +134 -0
- data/lib/HardsploitAPI/HardsploitAPI_CONSTANT.rb +145 -0
- data/lib/HardsploitAPI/HardsploitAPI_FIRMWARE.rb +311 -0
- data/lib/HardsploitAPI/HardsploitAPI_I2C.rb +218 -0
- data/lib/HardsploitAPI/HardsploitAPI_NO_MUX_PARALLELE_MEMORY.rb +229 -0
- data/lib/HardsploitAPI/HardsploitAPI_SPI.rb +179 -0
- data/lib/HardsploitAPI/HardsploitAPI_TEST_INTERACT.rb +98 -0
- data/lib/HardsploitAPI/HardsploitAPI_USB_COMMUNICATION.rb +149 -0
- data/lib/HardsploitAPI/LICENSE.txt +674 -0
- data/lib/HardsploitAPI/README.md +22 -0
- data/lib/HardsploitAPI/SWD/HardsploitAPI_SWD.rb +249 -0
- data/lib/HardsploitAPI/SWD/HardsploitAPI_SWD_DEBUG.rb +102 -0
- data/lib/HardsploitAPI/SWD/HardsploitAPI_SWD_MEM_AP.rb +78 -0
- data/lib/HardsploitAPI/SWD/HardsploitAPI_SWD_STM32.rb +104 -0
- data/lib/HardsploitAPI/TRADEMARK +3 -0
- data/lib/LICENSE.txt +674 -0
- data/lib/README.md +22 -0
- data/lib/TRADEMARK +3 -0
- data/lib/class/Chip_editor.rb +448 -0
- data/lib/class/Command_editor.rb +268 -0
- data/lib/class/Command_table.rb +239 -0
- data/lib/class/Console.rb +28 -0
- data/lib/class/Export_manager.rb +124 -0
- data/lib/class/Firmware.rb +29 -0
- data/lib/class/Generic_commands.rb +275 -0
- data/lib/class/HardsploitGUI.rb +462 -0
- data/lib/class/I2C/I2c_command.rb +48 -0
- data/lib/class/I2C/I2c_export.rb +121 -0
- data/lib/class/I2C/I2c_import.rb +92 -0
- data/lib/class/I2C/I2c_settings.rb +117 -0
- data/lib/class/PARALLEL/Parallel_export.rb +146 -0
- data/lib/class/PARALLEL/Parallel_import.rb +88 -0
- data/lib/class/PARALLEL/Parallel_settings.rb +102 -0
- data/lib/class/SPI/Spi_export.rb +141 -0
- data/lib/class/SPI/Spi_import.rb +112 -0
- data/lib/class/SPI/Spi_settings.rb +90 -0
- data/lib/class/Wire_helper.rb +246 -0
- data/lib/db/associations.rb +125 -0
- data/lib/db/hs.db +0 -0
- data/lib/gui/gui_chip_editor.rb +355 -0
- data/lib/gui/gui_chip_management.rb +372 -0
- data/lib/gui/gui_command_editor.rb +218 -0
- data/lib/gui/gui_export_manager.rb +93 -0
- data/lib/gui/gui_generic_commands.rb +164 -0
- data/lib/gui/gui_generic_export.rb +148 -0
- data/lib/gui/gui_generic_import.rb +126 -0
- data/lib/gui/gui_i2c_command.rb +115 -0
- data/lib/gui/gui_i2c_settings.rb +201 -0
- data/lib/gui/gui_parallel_settings.rb +194 -0
- data/lib/gui/gui_spi_import.rb +126 -0
- data/lib/gui/gui_spi_settings.rb +187 -0
- data/lib/gui/gui_wire_helper.rb +99 -0
- data/lib/gui_designer/gui_chip_editor.ui +553 -0
- data/lib/gui_designer/gui_chip_management.ui +842 -0
- data/lib/gui_designer/gui_command_editor.ui +347 -0
- data/lib/gui_designer/gui_export_manager.ui +115 -0
- data/lib/gui_designer/gui_generic_commands.ui +258 -0
- data/lib/gui_designer/gui_generic_export.ui +179 -0
- data/lib/gui_designer/gui_generic_import.ui +142 -0
- data/lib/gui_designer/gui_i2c_command.ui +145 -0
- data/lib/gui_designer/gui_i2c_settings.ui +261 -0
- data/lib/gui_designer/gui_parallel_settings.ui +244 -0
- data/lib/gui_designer/gui_processing.ui +81 -0
- data/lib/gui_designer/gui_spi_settings.ui +321 -0
- data/lib/gui_designer/gui_wire_helper.ui +117 -0
- data/lib/hardsploit.rb +122 -0
- data/lib/images/search.png +0 -0
- data/lib/logs/error.log +0 -0
- metadata +236 -0
@@ -0,0 +1,28 @@
|
|
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
|
+
require 'date'
|
8
|
+
require_relative '../HardsploitAPI/HardsploitAPI'
|
9
|
+
require_relative '../class/Command_table'
|
10
|
+
require_relative '../gui/gui_command_editor'
|
11
|
+
class Console < Qt::TableWidget
|
12
|
+
|
13
|
+
def initialize(console)
|
14
|
+
super()
|
15
|
+
@console = console
|
16
|
+
end
|
17
|
+
|
18
|
+
def print(msg)
|
19
|
+
@console.insertRow(@console.rowCount)
|
20
|
+
time = Qt::TableWidgetItem.new("#{Time.now.strftime("%d/%m %H:%M")}")
|
21
|
+
time.setFlags(Qt::ItemIsEnabled)
|
22
|
+
msg = Qt::TableWidgetItem.new(msg)
|
23
|
+
msg.setFlags(Qt::ItemIsEnabled)
|
24
|
+
@console.setItem(@console.rowCount - 1, 0, time)
|
25
|
+
@console.setItem(@console.rowCount - 1, 1, msg)
|
26
|
+
@console.scrollToItem(time, Qt::AbstractItemView::EnsureVisible)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,124 @@
|
|
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 'csv'
|
9
|
+
class Export_manager < Qt::Widget
|
10
|
+
slots 'save_result()'
|
11
|
+
|
12
|
+
def initialize(bus, result, spiDataSended = [])
|
13
|
+
super()
|
14
|
+
@em = Ui_Export_manager.new
|
15
|
+
centerWindow(self)
|
16
|
+
@em.setupUi(self)
|
17
|
+
@bus = bus
|
18
|
+
# Check the bus type to adapt the table column
|
19
|
+
if bus == 'SPI'
|
20
|
+
create_result_table('SPI')
|
21
|
+
@em.cbx_export.hide
|
22
|
+
@em.tbl_result.setRowCount(result.length)
|
23
|
+
result.length.times do |i|
|
24
|
+
@em.tbl_result.setItem(i, 0, Qt::TableWidgetItem.new(spiDataSended[i].to_s))
|
25
|
+
@em.tbl_result.setItem(i, 1, Qt::TableWidgetItem.new(result[i].to_s))
|
26
|
+
end
|
27
|
+
@em.tbl_result.resizeColumnsToContents
|
28
|
+
@em.tbl_result.resizeRowsToContents
|
29
|
+
@em.tbl_result.horizontalHeader.stretchLastSection = true
|
30
|
+
else
|
31
|
+
create_result_table('I2C')
|
32
|
+
@em.tbl_result.setRowCount(result.length / 2)
|
33
|
+
(0..result.length - 1).step(2).each_with_index do |i, v|
|
34
|
+
case result[i]
|
35
|
+
when 0
|
36
|
+
@em.tbl_result.setItem(v, 0, Qt::TableWidgetItem.new('Write'))
|
37
|
+
@em.tbl_result.setItem(v, 1, Qt::TableWidgetItem.new('ACK'))
|
38
|
+
@em.tbl_result.setItem(v, 2, Qt::TableWidgetItem.new(result[i + 1].to_s))
|
39
|
+
when 1
|
40
|
+
@em.tbl_result.setItem(v, 0, Qt::TableWidgetItem.new('Read'))
|
41
|
+
@em.tbl_result.setItem(v, 1, Qt::TableWidgetItem.new('ACK'))
|
42
|
+
@em.tbl_result.setItem(v, 2, Qt::TableWidgetItem.new(result[i + 1].to_s))
|
43
|
+
when 2
|
44
|
+
@em.tbl_result.setItem(v, 0, Qt::TableWidgetItem.new('Write'))
|
45
|
+
@em.tbl_result.setItem(v, 1, Qt::TableWidgetItem.new('NACK'))
|
46
|
+
@em.tbl_result.setItem(v, 2, Qt::TableWidgetItem.new(result[i + 1].to_s))
|
47
|
+
else
|
48
|
+
@em.tbl_result.setItem(v, 0, Qt::TableWidgetItem.new('Write'))
|
49
|
+
@em.tbl_result.setItem(v, 1, Qt::TableWidgetItem.new('NACK'))
|
50
|
+
@em.tbl_result.setItem(v, 2, Qt::TableWidgetItem.new(result[i + 1].to_s))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
@em.tbl_result.resizeColumnsToContents
|
54
|
+
@em.tbl_result.resizeRowsToContents
|
55
|
+
@em.tbl_result.horizontalHeader.stretchLastSection = true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def create_result_table(bus)
|
60
|
+
if bus == 'SPI'
|
61
|
+
@em.tbl_result.insertColumn(0)
|
62
|
+
@em.tbl_result.setHorizontalHeaderItem(0, Qt::TableWidgetItem.new('Data send'))
|
63
|
+
@em.tbl_result.insertColumn(1)
|
64
|
+
@em.tbl_result.setHorizontalHeaderItem(1, Qt::TableWidgetItem.new('Data receive'))
|
65
|
+
else
|
66
|
+
@em.tbl_result.insertColumn(0)
|
67
|
+
@em.tbl_result.setHorizontalHeaderItem(0, Qt::TableWidgetItem.new('R/W'))
|
68
|
+
@em.tbl_result.insertColumn(1)
|
69
|
+
@em.tbl_result.setHorizontalHeaderItem(1, Qt::TableWidgetItem.new('(N)ACK)'))
|
70
|
+
@em.tbl_result.insertColumn(2)
|
71
|
+
@em.tbl_result.setHorizontalHeaderItem(2, Qt::TableWidgetItem.new('DATA'))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def save_result
|
76
|
+
result_file = Qt::FileDialog.getSaveFileName(self, tr('Create a file'), '/', tr('All files (*)'))
|
77
|
+
unless result_file.nil?
|
78
|
+
if @bus == 'I2C'
|
79
|
+
if @em.cbx_export.currentIndex == 0
|
80
|
+
save_i2c_csv(result_file)
|
81
|
+
else
|
82
|
+
save_i2c(result_file)
|
83
|
+
end
|
84
|
+
else
|
85
|
+
save_spi(result_file)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
rescue Exception => msg
|
89
|
+
logger = Logger.new($logFilePath)
|
90
|
+
logger.error msg
|
91
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while saving the results. Consult the logs for more details').exec
|
92
|
+
end
|
93
|
+
|
94
|
+
def save_i2c_csv(result_file)
|
95
|
+
CSV.open("#{result_file}.csv", 'wb', :col_sep => ';') do |csv|
|
96
|
+
csv << ['R/W', '(N)ACK', 'DATA']
|
97
|
+
@em.tbl_result.rowCount.times do |i|
|
98
|
+
csv << [@em.tbl_result.item(i, 0).text, @em.tbl_result.item(i, 1).text, @em.tbl_result.item(i, 2).text]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def save_i2c(result_file)
|
104
|
+
file = File.open("#{result_file}", 'w')
|
105
|
+
result = []
|
106
|
+
@em.tbl_result.rowCount.times do |i|
|
107
|
+
if @em.tbl_result.item(i, 0).text == 'Read' && @em.tbl_result.item(i, 1).text == 'ACK'
|
108
|
+
result.push(@em.tbl_result.item(i, 2).text.to_i)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
file.write(result.pack('C*'))
|
112
|
+
file.close
|
113
|
+
end
|
114
|
+
|
115
|
+
def save_spi(result_file)
|
116
|
+
file = File.open("#{result_file}", 'w')
|
117
|
+
result = []
|
118
|
+
@em.tbl_result.rowCount.times do |i|
|
119
|
+
result.push(@em.tbl_result.item(i, 1).text.to_i)
|
120
|
+
end
|
121
|
+
file.write(result.pack('C*'))
|
122
|
+
file.close
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,29 @@
|
|
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(api, firmware)
|
10
|
+
if $currentFirmware != firmware
|
11
|
+
case firmware
|
12
|
+
when 'I2C'
|
13
|
+
p "Upload Firmware check : #{api.uploadFirmware(File.expand_path(File.dirname(__FILE__)) + "/../Firmware/FPGA/I2C/I2C_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_I2C_INTERACT.rpd", false)}"
|
14
|
+
when 'SPI'
|
15
|
+
p "Upload Firmware check : #{api.uploadFirmware(File.expand_path(File.dirname(__FILE__)) + '/../Firmware/FPGA/SPI/SPI_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SPI_INTERACT.rpd', false)}"
|
16
|
+
when 'Parallel'
|
17
|
+
p "Upload Firmware check : #{api.uploadFirmware(File.expand_path(File.dirname(__FILE__)) + "/../Firmware/FPGA/PARALLEL/NO_MUX_PARALLEL_MEMORY/HARDSPLOIT_FIRMWARE_FPGA_NO_MUX_PARALLEL_MEMORY.rpd", false)}"
|
18
|
+
when 'SWD'
|
19
|
+
p "Upload Firmware check : #{api.uploadFirmware(File.expand_path(File.dirname(__FILE__)) + "/../Firmware/FPGA/SWD/SWD_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SWD_INTERACT.rpd", false)}"
|
20
|
+
end
|
21
|
+
$currentFirmware = firmware
|
22
|
+
sleep(2)
|
23
|
+
end
|
24
|
+
rescue Exception => msg
|
25
|
+
logger = Logger.new($logFilePath)
|
26
|
+
logger.error msg
|
27
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error while loading the firmware. Consult the log for more details').exec
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,275 @@
|
|
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_commands'
|
10
|
+
require_relative '../gui/gui_export_manager'
|
11
|
+
require_relative '../class/I2C/I2c_command'
|
12
|
+
require_relative '../class/Export_manager'
|
13
|
+
require_relative '../class/Command_editor'
|
14
|
+
|
15
|
+
|
16
|
+
class Generic_commands < Qt::Widget
|
17
|
+
slots 'feed_cmd_array()'
|
18
|
+
slots 'exec_action()'
|
19
|
+
slots 'open_cmd_form()'
|
20
|
+
|
21
|
+
def initialize(api, chip, bus_name)
|
22
|
+
super()
|
23
|
+
@generic_command_gui = Ui_Generic_commands.new
|
24
|
+
centerWindow(self)
|
25
|
+
@generic_command_gui.setupUi(self)
|
26
|
+
@generic_command_gui.lbl_chip.setText(chip.chip_reference)
|
27
|
+
@generic_command_gui.lbl_search.setPixmap(Qt::Pixmap.new('images/search.png'))
|
28
|
+
inputRestrict(@generic_command_gui.lie_search, 2)
|
29
|
+
@generic_command_gui.check_result.setChecked(true)
|
30
|
+
@api = api
|
31
|
+
@chip = chip
|
32
|
+
@bus_name = bus_name
|
33
|
+
@bus_id = Bus.find_by(bus_name: bus_name).bus_id
|
34
|
+
select_chip_settings(bus_name)
|
35
|
+
feed_cmd_array
|
36
|
+
end
|
37
|
+
|
38
|
+
def feed_cmd_array
|
39
|
+
@generic_command_gui.tbl_cmd.clearContents
|
40
|
+
cmd = @chip.cmd.where(cmd_bus: @bus_id)
|
41
|
+
unless @generic_command_gui.lie_search.text.empty?
|
42
|
+
cmd = cmd.where('cmd_name LIKE ?', "%#{@generic_command_gui.lie_search.text}%")
|
43
|
+
end
|
44
|
+
@generic_command_gui.tbl_cmd.setRowCount(cmd.count);
|
45
|
+
cmd.to_enum.with_index(0).each do |c, i|
|
46
|
+
it1 = Qt::TableWidgetItem.new(c.cmd_name)
|
47
|
+
it1.setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled)
|
48
|
+
it2 = Qt::TableWidgetItem.new(c.cmd_desc)
|
49
|
+
it2.setFlags(Qt::ItemIsEnabled)
|
50
|
+
@generic_command_gui.tbl_cmd.setItem(i, 0, it1);
|
51
|
+
@generic_command_gui.tbl_cmd.setItem(i, 1, it2);
|
52
|
+
end
|
53
|
+
@generic_command_gui.tbl_cmd.resizeColumnsToContents
|
54
|
+
@generic_command_gui.tbl_cmd.resizeRowsToContents
|
55
|
+
@generic_command_gui.tbl_cmd.horizontalHeader.stretchLastSection = true
|
56
|
+
rescue Exception => msg
|
57
|
+
logger = Logger.new($logFilePath)
|
58
|
+
logger.error msg
|
59
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error while loading the command array. Consult the log for more details').exec
|
60
|
+
end
|
61
|
+
|
62
|
+
def select_chip_settings(bus)
|
63
|
+
case bus
|
64
|
+
when 'SPI'
|
65
|
+
@chip_settings = Spi.find_by(spi_chip: @chip.chip_id)
|
66
|
+
@speeds = {
|
67
|
+
'25.00' => 3,
|
68
|
+
'18.75' => 4,
|
69
|
+
'15.00' => 5,
|
70
|
+
'12.50' => 6,
|
71
|
+
'10.71' => 7,
|
72
|
+
'9.38' => 8,
|
73
|
+
'7.50' => 10,
|
74
|
+
'5.00' => 15,
|
75
|
+
'3.95' => 19,
|
76
|
+
'3.00' => 25,
|
77
|
+
'2.03' => 37,
|
78
|
+
'1.00' => 75,
|
79
|
+
'0.50' => 150,
|
80
|
+
'0.29' => 255
|
81
|
+
}
|
82
|
+
@generic_command_gui.cbx_action.insertItem(3, 'Concatenate')
|
83
|
+
when 'I2C'
|
84
|
+
@chip_settings = I2C.find_by(i2c_chip: @chip.chip_id)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Execute action
|
89
|
+
def exec_action
|
90
|
+
if @generic_command_gui.tbl_cmd.currentItem.nil?
|
91
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Missing command', 'Select a command in the array first').exec
|
92
|
+
return 0
|
93
|
+
end
|
94
|
+
case @generic_command_gui.cbx_action.currentText
|
95
|
+
when 'Execute'
|
96
|
+
cmd_array = prepare_cmd
|
97
|
+
result = exec_cmd(@bus_name, cmd_array)
|
98
|
+
if @generic_command_gui.check_result.isChecked
|
99
|
+
export_manager = Export_manager.new(@bus_name, result, cmd_array)
|
100
|
+
export_manager.setWindowModality(Qt::ApplicationModal)
|
101
|
+
export_manager.show
|
102
|
+
end
|
103
|
+
when 'Template'
|
104
|
+
open_cmd_form(:option_1 => 'temp')
|
105
|
+
when 'Edit'
|
106
|
+
open_cmd_form(:option_1 => 'edit')
|
107
|
+
when 'Concatenate'
|
108
|
+
concatenate_cmds
|
109
|
+
when 'Delete'
|
110
|
+
delete_cmd
|
111
|
+
else
|
112
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Wrong option', 'Please choose a correct action').exec
|
113
|
+
end
|
114
|
+
rescue Exception => msg
|
115
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while executing the action. Consult the logs for more details').exec
|
116
|
+
logger = Logger.new($logFilePath)
|
117
|
+
logger.error msg
|
118
|
+
end
|
119
|
+
|
120
|
+
def prepare_cmd
|
121
|
+
byte_list = Byte.where(byte_cmd: Cmd.find_by(cmd_name: @generic_command_gui.tbl_cmd.currentItem.text))
|
122
|
+
array_sent = Array.new
|
123
|
+
byte_list.each do |bl|
|
124
|
+
if bl.byte_iteration != 0 && !bl.byte_iteration.nil?
|
125
|
+
for i in 1..bl.byte_iteration.to_i do
|
126
|
+
array_sent.push(bl.byte_value.to_i(16))
|
127
|
+
end
|
128
|
+
else
|
129
|
+
array_sent.push(bl.byte_value.to_i(16))
|
130
|
+
end
|
131
|
+
end
|
132
|
+
return array_sent
|
133
|
+
rescue Exception => msg
|
134
|
+
logger = Logger.new($logFilePath)
|
135
|
+
logger.error msg
|
136
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured when preparing the command. Consult the log for more details').exec
|
137
|
+
end
|
138
|
+
|
139
|
+
def exec_cmd(bus, array_sent)
|
140
|
+
Firmware.new(@api, @bus_name)
|
141
|
+
case bus
|
142
|
+
when 'SPI'
|
143
|
+
return check_send_and_received_data(@api.spi_Interact(@chip_settings.spi_mode, @speeds[@chip_settings.spi_frequency], array_sent))
|
144
|
+
when 'I2C'
|
145
|
+
return check_send_and_received_data(@api.i2c_Interact(@chip_settings.i2c_frequency, array_sent))
|
146
|
+
end
|
147
|
+
rescue Exception => msg
|
148
|
+
logger = Logger.new($logFilePath)
|
149
|
+
logger.error msg
|
150
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured when executing the command. Consult the log for more details').exec
|
151
|
+
end
|
152
|
+
|
153
|
+
def delete_cmd
|
154
|
+
msg = Qt::MessageBox.new
|
155
|
+
msg.setWindowTitle('Delete command')
|
156
|
+
msg.setText('Confirm the delete command action ?')
|
157
|
+
msg.setIcon(Qt::MessageBox::Question)
|
158
|
+
msg.setStandardButtons(Qt::MessageBox::Cancel | Qt::MessageBox::Ok)
|
159
|
+
msg.setDefaultButton(Qt::MessageBox::Cancel)
|
160
|
+
if msg.exec == Qt::MessageBox::Ok
|
161
|
+
@chip.cmd.find_by(cmd_name: @generic_command_gui.tbl_cmd.currentItem.text).destroy
|
162
|
+
feed_cmd_array
|
163
|
+
end
|
164
|
+
rescue Exception => msg
|
165
|
+
logger = Logger.new($logFilePath)
|
166
|
+
logger.error msg
|
167
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured when deleting the command. Consult the log for more details').exec
|
168
|
+
end
|
169
|
+
|
170
|
+
def concatenate_cmds
|
171
|
+
if @generic_command_gui.tbl_cmd.selectedItems.count != 2
|
172
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Wrong selection', 'Select two commands in the table to concatenate them').exec
|
173
|
+
return 0
|
174
|
+
end
|
175
|
+
bytesCmd1 = Byte.where(byte_cmd: Cmd.find_by(cmd_name: @generic_command_gui.tbl_cmd.selectedItems[0].text).cmd_id)
|
176
|
+
bytesCmd2 = Byte.where(byte_cmd: Cmd.find_by(cmd_name: @generic_command_gui.tbl_cmd.selectedItems[1].text).cmd_id)
|
177
|
+
if check_concatenation_size(bytesCmd1, bytesCmd2)
|
178
|
+
return 0
|
179
|
+
end
|
180
|
+
# Save cmd
|
181
|
+
cmd = Cmd.new
|
182
|
+
cmd.cmd_name = 'New concatenation'
|
183
|
+
cmd.cmd_desc = "Concatenation of #{@generic_command_gui.tbl_cmd.selectedItems[0].text} and #{@generic_command_gui.tbl_cmd.selectedItems[1].text} commands"
|
184
|
+
cmd.cmd_bus = @bus_id
|
185
|
+
cmd.cmd_chip = @chip.chip_id
|
186
|
+
cmd.save
|
187
|
+
# Save cmd bytes
|
188
|
+
bytesCmd1.each do |b1|
|
189
|
+
byte = Byte.new
|
190
|
+
byte.byte_index = b1.byte_index
|
191
|
+
byte.byte_value = b1.byte_value
|
192
|
+
checkSize.push(b1.byte_value)
|
193
|
+
byte.byte_description = b1.byte_description
|
194
|
+
byte.byte_iteration = b1.byte_iteration
|
195
|
+
byte.byte_cmd = Cmd.ids.last
|
196
|
+
byte.byte_type = 1
|
197
|
+
byte.save
|
198
|
+
end
|
199
|
+
bytesCmd2.each do |b2|
|
200
|
+
byte2 = Byte.new
|
201
|
+
byte2.byte_index = Byte.last.byte_index + 1
|
202
|
+
byte2.byte_value = b2.byte_value
|
203
|
+
checkSize.push(b2.byte_value)
|
204
|
+
byte2.byte_description = b2.byte_description
|
205
|
+
byte2.byte_iteration = b2.byte_iteration
|
206
|
+
byte2.byte_cmd = Cmd.ids.last
|
207
|
+
byte2.byte_type = 1
|
208
|
+
byte2.save
|
209
|
+
end
|
210
|
+
feed_cmd_array
|
211
|
+
rescue Exception => msg
|
212
|
+
logger = Logger.new($logFilePath)
|
213
|
+
logger.error msg
|
214
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured when concatenating the command. Consult the log for more details').exec
|
215
|
+
end
|
216
|
+
|
217
|
+
def check_concatenation_size(bytesCmd1, bytesCmd2)
|
218
|
+
checkSize = Array.new
|
219
|
+
bytesCmd1.each do |b1|
|
220
|
+
checkSize.push(b1.byte_value)
|
221
|
+
end
|
222
|
+
bytesCmd2.each do |b2|
|
223
|
+
checkSize.push(b2.byte_value)
|
224
|
+
end
|
225
|
+
count = 0
|
226
|
+
i = 0
|
227
|
+
while i <= (checkSize.size) - 1 do
|
228
|
+
lowByte = checkSize[i]
|
229
|
+
highByte = checkSize[i + 1]
|
230
|
+
commandType = checkSize[i + 2]
|
231
|
+
count = count + (@api.BytesToInt(lowByte.to_i(16), highByte.to_i(16)))
|
232
|
+
if commandType.to_i(16) % 2 == 0 #WRITE
|
233
|
+
i = (i + ((@api.BytesToInt(lowByte.to_i(16), highByte.to_i(16))) + 3))
|
234
|
+
else #READ
|
235
|
+
i = (i + 3)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
if count > 2000
|
239
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Command too big: unable to concatenate').exec
|
240
|
+
return false
|
241
|
+
end
|
242
|
+
return true
|
243
|
+
end
|
244
|
+
|
245
|
+
def open_cmd_form(options={})
|
246
|
+
if options[:option_1].nil?
|
247
|
+
if @bus_name == 'I2C'
|
248
|
+
cmdBase = I2c_command.new(@api, @chip, @bus_id, self)
|
249
|
+
else
|
250
|
+
cmdBase = Command_editor.new(0, nil, @chip, @bus_id, self, @api)
|
251
|
+
end
|
252
|
+
else
|
253
|
+
if options[:option_1] == 'temp'
|
254
|
+
cmdBase = Command_editor.new(1, @generic_command_gui.tbl_cmd.currentItem.text, @chip, @bus_id, self, @api)
|
255
|
+
else
|
256
|
+
cmdBase = Command_editor.new(2, @generic_command_gui.tbl_cmd.currentItem.text, @chip, @bus_id, self, @api)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
cmdBase.setWindowModality(Qt::ApplicationModal)
|
260
|
+
cmdBase.show
|
261
|
+
end
|
262
|
+
|
263
|
+
def check_send_and_received_data(value)
|
264
|
+
case value
|
265
|
+
when HardsploitAPI::USB_STATE::PACKET_IS_TOO_LARGE
|
266
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', "PACKET_IS_TOO_LARGE max: #{HardsploitAPI::USB::USB_TRAME_SIZE}").exec
|
267
|
+
when HardsploitAPI::USB_STATE::ERROR_SEND
|
268
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'ERROR_SEND').exec
|
269
|
+
when HardsploitAPI::USB_STATE::BUSY
|
270
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'BUSY', 'Device busy').exec
|
271
|
+
else
|
272
|
+
return value
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|