hardsploit_gui 2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,88 @@
|
|
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 Parallel_import < Qt::Widget
|
12
|
+
slots 'import()'
|
13
|
+
slots 'select_import_file()'
|
14
|
+
|
15
|
+
def initialize(api, chip)
|
16
|
+
super()
|
17
|
+
@parallel_import_gui = Ui_Generic_import.new
|
18
|
+
centerWindow(self)
|
19
|
+
@parallel_import_gui.setupUi(self)
|
20
|
+
@parallel_import_gui.lbl_chip.setText(chip.chip_reference)
|
21
|
+
inputRestrict(@parallel_import_gui.lie_start, 0)
|
22
|
+
@api = api
|
23
|
+
@chip_settings = Parallel.find_by(parallel_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
|
+
@parallel_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 = @parallel_import_gui.lie_start.text.to_i
|
51
|
+
Firmware.new(@api, 'PARALLEL')
|
52
|
+
time = Time.new
|
53
|
+
# API 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 parallel settings', 'No settings saved for this chip').exec
|
64
|
+
return 0
|
65
|
+
end
|
66
|
+
if @chip_settings.parallel_total_size.nil? || @chip_settings.parallel_word_size.nil?
|
67
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing parallel settings', 'Total size or word size settings missing').exec
|
68
|
+
return 0
|
69
|
+
end
|
70
|
+
if @chip_settings.parallel_page_size.nil? || @chip_settings.parallel_write_latency.nil?
|
71
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing parallel settings', 'Page size or write latency settings missing').exec
|
72
|
+
return 0
|
73
|
+
end
|
74
|
+
if @parallel_import_gui.lie_start.text.empty?
|
75
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing start address', 'Please fill the start address field').exec
|
76
|
+
return 0
|
77
|
+
end
|
78
|
+
if file_size > @chip_settings.parallel_total_size
|
79
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Incorrect file size', 'The file size is superior to the chip capacity').exec
|
80
|
+
return 0
|
81
|
+
end
|
82
|
+
if file_size > (@chip_settings.parallel_total_size - @parallel_import_gui.lie_start)
|
83
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Incorrect file size', 'Starting at this address, the file size is superior to the chip capacity').exec
|
84
|
+
return 0
|
85
|
+
end
|
86
|
+
return 1
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,102 @@
|
|
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_parallel_settings'
|
9
|
+
class Parallel_settings < Qt::Widget
|
10
|
+
slots 'save_settings()'
|
11
|
+
|
12
|
+
def initialize(chip)
|
13
|
+
super()
|
14
|
+
@parallel_settings_gui = Ui_Parallel_settings.new
|
15
|
+
centerWindow(self)
|
16
|
+
@parallel_settings_gui.setupUi(self)
|
17
|
+
@parallel_settings_gui.lbl_chip.setText(chip.chip_reference)
|
18
|
+
inputRestrict(@parallel_settings_gui.lie_total_size, 0)
|
19
|
+
inputRestrict(@parallel_settings_gui.lie_write_latency, 0)
|
20
|
+
inputRestrict(@parallel_settings_gui.lie_read_latency, 0)
|
21
|
+
inputRestrict(@parallel_settings_gui.lie_page_size, 0)
|
22
|
+
@chip_settings = Parallel.find_by(parallel_chip: chip.chip_id)
|
23
|
+
@chip = chip
|
24
|
+
feed_settings_form
|
25
|
+
end
|
26
|
+
|
27
|
+
def save_settings
|
28
|
+
if @chip_settings.nil?
|
29
|
+
create
|
30
|
+
else
|
31
|
+
@chip_settings = Parallel.find_by(parallel_chip: @chip.chip_id)
|
32
|
+
update
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def feed_settings_form
|
37
|
+
unless @chip_settings.nil?
|
38
|
+
@parallel_settings_gui.lie_read_latency.setText(@chip_settings.parallel_read_latency.to_s)
|
39
|
+
@parallel_settings_gui.lie_write_latency.setText(@chip_settings.parallel_write_latency.to_s)
|
40
|
+
@parallel_settings_gui.lie_page_size.setText(@chip_settings.parallel_page_size.to_s)
|
41
|
+
@parallel_settings_gui.lie_total_size.setText(@chip_settings.parallel_total_size.to_s)
|
42
|
+
if @chip_settings.parallel_word_size.zero?
|
43
|
+
@parallel_settings_gui.rbn_8b.setChecked(true)
|
44
|
+
else
|
45
|
+
@parallel_settings_gui.rbn_16b.setChecked(true)
|
46
|
+
end
|
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
|
+
if @parallel_settings_gui.rbn_8b.isChecked
|
56
|
+
word_size = 0
|
57
|
+
else
|
58
|
+
word_size = 1
|
59
|
+
end
|
60
|
+
@chip_settings = Parallel.create(
|
61
|
+
parallel_word_size: word_size,
|
62
|
+
parallel_write_latency: @parallel_settings_gui.lie_write_latency,
|
63
|
+
parallel_read_latency: @parallel_settings_gui.lie_read_latency.text,
|
64
|
+
parallel_page_size: @parallel_settings_gui.lie_page_size.text,
|
65
|
+
parallel_total_size: @parallel_settings_gui.lie_total_size.text,
|
66
|
+
parallel_chip: @chip.chip_id
|
67
|
+
)
|
68
|
+
Qt::MessageBox.new(Qt::MessageBox::Information, 'Succes', 'Parallel parameters created successfully').exec
|
69
|
+
rescue Exception => msg
|
70
|
+
logger = Logger.new($logFilePath)
|
71
|
+
logger.error msg
|
72
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured when saving the parallel parameters. Consult the log for more details').exec
|
73
|
+
end
|
74
|
+
|
75
|
+
def update
|
76
|
+
if @parallel_settings_gui.rbn_8b.isChecked
|
77
|
+
word_size = 0
|
78
|
+
else
|
79
|
+
word_size = 1
|
80
|
+
end
|
81
|
+
if @chip_settings.parallel_page_size != @parallel_settings_gui.lie_page_size
|
82
|
+
@chip_settings.update(parallel_page_size: @parallel_settings_gui.lie_page_size.text)
|
83
|
+
end
|
84
|
+
if @chip_settings.parallel_total_size != @parallel_settings_gui.lie_total_size
|
85
|
+
@chip_settings.update(parallel_total_size: @parallel_settings_gui.lie_total_size.text)
|
86
|
+
end
|
87
|
+
if @chip_settings.parallel_read_latency != @parallel_settings_gui.lie_read_latency
|
88
|
+
@chip_settings.update(parallel_read_latency: @parallel_settings_gui.lie_read_latency.text)
|
89
|
+
end
|
90
|
+
if @chip_settings.parallel_write_latency != @parallel_settings_gui.lie_write_latency
|
91
|
+
@chip_settings.update(parallel_write_latency: @parallel_settings_gui.lie_write_latency.text)
|
92
|
+
end
|
93
|
+
if @chip_settings.parallel_word_size != word_size
|
94
|
+
@chip_settings.update(parallel_word_size: word_size)
|
95
|
+
end
|
96
|
+
Qt::MessageBox.new(Qt::MessageBox::Information, 'Succes', 'Parallel parameters saved successfully').exec
|
97
|
+
rescue Exception => msg
|
98
|
+
logger = Logger.new($logFilePath)
|
99
|
+
logger.error msg
|
100
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured when saving the parallel parameters. Consult the log for more details').exec
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,141 @@
|
|
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 Spi_export < Qt::Widget
|
12
|
+
slots 'export()'
|
13
|
+
slots 'select_export_file()'
|
14
|
+
|
15
|
+
def initialize(api, chip)
|
16
|
+
super()
|
17
|
+
@spi_export_gui = Ui_Generic_export.new
|
18
|
+
centerWindow(self)
|
19
|
+
@spi_export_gui.setupUi(self)
|
20
|
+
@spi_export_gui.lbl_chip.setText(chip.chip_reference)
|
21
|
+
inputRestrict(@spi_export_gui.lie_start, 0)
|
22
|
+
inputRestrict(@spi_export_gui.lie_stop, 0)
|
23
|
+
@api = api
|
24
|
+
@chip_settings = Spi.find_by(spi_chip: chip.chip_id)
|
25
|
+
@speeds = {
|
26
|
+
'25.00' => 3,
|
27
|
+
'18.75' => 4,
|
28
|
+
'15.00' => 5,
|
29
|
+
'12.50' => 6,
|
30
|
+
'10.71' => 7,
|
31
|
+
'9.38' => 8,
|
32
|
+
'7.50' => 10,
|
33
|
+
'5.00' => 15,
|
34
|
+
'3.95' => 19,
|
35
|
+
'3.00' => 25,
|
36
|
+
'2.03' => 37,
|
37
|
+
'1.00' => 75,
|
38
|
+
'0.50' => 150,
|
39
|
+
'0.29' => 255
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def select_export_file
|
44
|
+
@filepath = Qt::FileDialog.getSaveFileName(self, tr('Select a file'), '/', tr('Bin file (*.bin)'))
|
45
|
+
unless @filepath.nil?
|
46
|
+
$file = File.open("#{@filepath}", 'w')
|
47
|
+
@spi_export_gui.btn_export.setEnabled(true)
|
48
|
+
@spi_export_gui.btn_full_export.setEnabled(true)
|
49
|
+
end
|
50
|
+
rescue Exception => msg
|
51
|
+
logger = Logger.new($logFilePath)
|
52
|
+
logger.error msg
|
53
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while openning the export file. Consult the logs for more details').exec
|
54
|
+
end
|
55
|
+
|
56
|
+
def close_file
|
57
|
+
unless $file.nil?
|
58
|
+
$file.close
|
59
|
+
end
|
60
|
+
rescue Exception => msg
|
61
|
+
logger = Logger.new($logFilePath)
|
62
|
+
logger.error msg
|
63
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while closing the export file. Consult the logs for more details').exec
|
64
|
+
end
|
65
|
+
|
66
|
+
def export
|
67
|
+
if sender.objectName == 'btn_full_export'
|
68
|
+
return 0 if control_export_settings('full').zero?
|
69
|
+
else
|
70
|
+
return 0 if control_export_settings('partial').zero?
|
71
|
+
end
|
72
|
+
Firmware.new(@api, 'SPI')
|
73
|
+
time = Time.new
|
74
|
+
if sender.objectName == 'btn_full_export'
|
75
|
+
@api.spi_Generic_Dump(@chip_settings.spi_mode, @speeds[@chip_settings.spi_frequency], @chip_settings.spi_command_read, 0, @chip_settings.spi_total_size - 1, @chip_settings.spi_total_size.to_i)
|
76
|
+
close_file
|
77
|
+
control_export_result('full', @chip_settings.spi_total_size - 1, time)
|
78
|
+
else
|
79
|
+
@api.spi_Generic_Dump(@chip_settings.spi_mode, @speeds[@chip_settings.spi_frequency], @chip_settings.spi_command_read, @spi_export_gui.lie_start.text.to_i, @spi_export_gui.lie_stop.text.to_i, @chip_settings.spi_total_size.to_i)
|
80
|
+
close_file
|
81
|
+
control_export_result('partial', @spi_export_gui.lie_stop.text.to_i, time)
|
82
|
+
end
|
83
|
+
@spi_export_gui.btn_export.setEnabled(false)
|
84
|
+
@spi_export_gui.btn_full_export.setEnabled(false)
|
85
|
+
rescue Exception => msg
|
86
|
+
logger = Logger.new($logFilePath)
|
87
|
+
logger.error msg
|
88
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while full export operation. Consult the logs for more details').exec
|
89
|
+
end
|
90
|
+
|
91
|
+
def control_export_result(type, stop, time)
|
92
|
+
time = Time.new - time
|
93
|
+
if type == 'partial'
|
94
|
+
toCompare = ((stop - @spi_export_gui.lie_start.text.to_i) + 1)
|
95
|
+
else
|
96
|
+
toCompare = @chip_settings.spi_total_size
|
97
|
+
end
|
98
|
+
file_size = File.size(@filepath)
|
99
|
+
if toCompare == file_size
|
100
|
+
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
|
101
|
+
else
|
102
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Error', 'Dump error: Size does not match').exec
|
103
|
+
end
|
104
|
+
p "DUMP #{((file_size / time)).round(2)}Bytes/s (#{(file_size)}Bytes in #{time.round(4)} s)"
|
105
|
+
end
|
106
|
+
|
107
|
+
def control_export_settings(type)
|
108
|
+
if @chip_settings.nil?
|
109
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI settings', 'No settings saved for this chip').exec
|
110
|
+
return 0
|
111
|
+
end
|
112
|
+
if @chip_settings.spi_command_read.nil? || @chip_settings.spi_frequency.nil?
|
113
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI settings', 'Read command or frequency settings missing').exec
|
114
|
+
return 0
|
115
|
+
end
|
116
|
+
if @chip_settings.spi_mode.nil?
|
117
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI setting', 'Mode setting missing').exec
|
118
|
+
return 0
|
119
|
+
end
|
120
|
+
if type == 'full'
|
121
|
+
if @chip_settings.spi_total_size.zero? || @chip_settings.spi_total_size.nil?
|
122
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Empty field', 'Full size setting missing or equal 0').exec
|
123
|
+
return 0
|
124
|
+
end
|
125
|
+
else
|
126
|
+
if @spi_export_gui.lie_start.text.empty? || @spi_export_gui.lie_stop.text.empty?
|
127
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Empty field', 'Start and stop address must be filled').exec
|
128
|
+
return 0
|
129
|
+
end
|
130
|
+
if @spi_export_gui.lie_start.text.to_i > @spi_export_gui.lie_stop.text.to_i
|
131
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Wrong value', 'Start address must be inforior to the stop address').exec
|
132
|
+
return 0
|
133
|
+
end
|
134
|
+
if @spi_export_gui.lie_start.text.to_i > (@chip_settings.spi_total_size - 1) || @spi_export_gui.lie_stop.text.to_i > (@chip_settings.spi_total_size - 1)
|
135
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Wrong value', 'Start and stop address must be inforior to the chip total size').exec
|
136
|
+
return 0
|
137
|
+
end
|
138
|
+
end
|
139
|
+
return 1
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,112 @@
|
|
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 Spi_import < Qt::Widget
|
12
|
+
slots 'import()'
|
13
|
+
slots 'select_import_file()'
|
14
|
+
|
15
|
+
def initialize(api, chip)
|
16
|
+
super()
|
17
|
+
@spi_import_gui = Ui_Generic_import.new
|
18
|
+
centerWindow(self)
|
19
|
+
@spi_import_gui.setupUi(self)
|
20
|
+
@spi_import_gui.lbl_chip.setText(chip.chip_reference)
|
21
|
+
inputRestrict(@spi_import_gui.lie_start, 0)
|
22
|
+
@api = api
|
23
|
+
@chip_settings = Spi.find_by(spi_chip: chip.chip_id)
|
24
|
+
@speeds = {
|
25
|
+
'25.00' => 3,
|
26
|
+
'18.75' => 4,
|
27
|
+
'15.00' => 5,
|
28
|
+
'12.50' => 6,
|
29
|
+
'10.71' => 7,
|
30
|
+
'9.38' => 8,
|
31
|
+
'7.50' => 10,
|
32
|
+
'5.00' => 15,
|
33
|
+
'3.95' => 19,
|
34
|
+
'3.00' => 25,
|
35
|
+
'2.03' => 37,
|
36
|
+
'1.00' => 75,
|
37
|
+
'0.50' => 150,
|
38
|
+
'0.29' => 255
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def select_import_file
|
43
|
+
@filepath = Qt::FileDialog.getOpenFileName(self, tr('Select a file'), '/', tr('Bin file (*.bin)'))
|
44
|
+
unless @filepath.nil?
|
45
|
+
$file = File.open("#{@filepath}", 'w')
|
46
|
+
@spi_import_gui.btn_import.setEnabled(true)
|
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 occured while openning the export file. Consult the logs for more details').exec
|
52
|
+
end
|
53
|
+
|
54
|
+
def close_file
|
55
|
+
unless $file.nil?
|
56
|
+
$file.close
|
57
|
+
end
|
58
|
+
rescue Exception => msg
|
59
|
+
logger = Logger.new($logFilePath)
|
60
|
+
logger.error msg
|
61
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while closing the export file. Consult the logs for more details').exec
|
62
|
+
end
|
63
|
+
|
64
|
+
def import
|
65
|
+
return 0 if control_import_settings.zero?
|
66
|
+
start = @spi_import_gui.lie_start.text.to_i
|
67
|
+
Firmware.new(@api, 'SPI')
|
68
|
+
time = Time.new
|
69
|
+
@api.spi_Generic_Dump(@chip_settings.spi_mode, @speeds[@chip_settings.spi_frequency], @chip_settings.spi_command_read, @spi_import_gui.lie_start.text.to_i, @chip_settings.spi_total_size.to_i)
|
70
|
+
rescue Exception => msg
|
71
|
+
logger = Logger.new($logFilePath)
|
72
|
+
logger.error msg
|
73
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured while partial import operation. Consult the logs for more details').exec
|
74
|
+
end
|
75
|
+
|
76
|
+
def control_import_result(type, stop, pathfile, time)
|
77
|
+
# TO COME
|
78
|
+
end
|
79
|
+
|
80
|
+
def control_import_settings
|
81
|
+
file_size = File.size("#{@filepath}")
|
82
|
+
if @chip_settings.nil?
|
83
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI settings', 'No settings saved for this chip').exec
|
84
|
+
return 0
|
85
|
+
end
|
86
|
+
if @chip_settings.spi_total_size.nil? || @chip_settings.spi_page_size.nil?
|
87
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI settings', 'Total size or page size settings missing').exec
|
88
|
+
return 0
|
89
|
+
end
|
90
|
+
if @chip_settings.spi_read_command.nil? || @chip_settings.spi_frequency.nil?
|
91
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI settings', 'Read command or frequency settings missing').exec
|
92
|
+
return 0
|
93
|
+
end
|
94
|
+
if @chip_settings.spi_mode.nil?
|
95
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing SPI setting', 'Mode setting missing').exec
|
96
|
+
return 0
|
97
|
+
end
|
98
|
+
if @spi_import_gui.lie_start.text.empty?
|
99
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Missing start address', 'Please fill the Start address field').exec
|
100
|
+
return 0
|
101
|
+
end
|
102
|
+
if file_size > @chip_settings.spi_total_size
|
103
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Incorrect file size', 'The file size is superior to the chip capacity').exec
|
104
|
+
return 0
|
105
|
+
end
|
106
|
+
if file_size > (@chip_settings.spi_total_size - @spi_import_gui.lie_start)
|
107
|
+
Qt::MessageBox.new(Qt::MessageBox::Warning, 'Incorrect file size', 'Starting at this address, the file size is superior to the chip capacity').exec
|
108
|
+
return 0
|
109
|
+
end
|
110
|
+
return 1
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,90 @@
|
|
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_spi_settings'
|
9
|
+
class Spi_settings < Qt::Widget
|
10
|
+
slots 'save_settings()'
|
11
|
+
|
12
|
+
def initialize(chip)
|
13
|
+
super()
|
14
|
+
@spi_settings_gui = Ui_Spi_settings.new
|
15
|
+
centerWindow(self)
|
16
|
+
@spi_settings_gui.setupUi(self)
|
17
|
+
@spi_settings_gui.lbl_chip.setText(chip.chip_reference)
|
18
|
+
inputRestrict(@spi_settings_gui.lie_total_size, 0)
|
19
|
+
inputRestrict(@spi_settings_gui.lie_cmd_read, 0)
|
20
|
+
inputRestrict(@spi_settings_gui.lie_page_size, 0)
|
21
|
+
@chip_settings = Spi.find_by(spi_chip: chip.chip_id)
|
22
|
+
@chip = chip
|
23
|
+
feed_settings_form
|
24
|
+
end
|
25
|
+
|
26
|
+
def save_settings
|
27
|
+
if @chip_settings.nil?
|
28
|
+
create
|
29
|
+
else
|
30
|
+
@chip_settings = Spi.find_by(spi_chip: @chip.chip_id)
|
31
|
+
update
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def feed_settings_form
|
36
|
+
unless @chip_settings.nil?
|
37
|
+
@spi_settings_gui.cbx_mode.setCurrentIndex(@spi_settings_gui.cbx_mode.findText(@chip_settings.spi_mode.to_s))
|
38
|
+
@spi_settings_gui.cbx_frequency.setCurrentIndex(@spi_settings_gui.cbx_frequency.findText(@chip_settings.spi_frequency))
|
39
|
+
@spi_settings_gui.lie_cmd_read.setText(@chip_settings.spi_command_read.to_s)
|
40
|
+
@spi_settings_gui.lie_page_size.setText(@chip_settings.spi_page_size.to_s)
|
41
|
+
@spi_settings_gui.lie_total_size.setText(@chip_settings.spi_total_size.to_s)
|
42
|
+
end
|
43
|
+
rescue Exception => msg
|
44
|
+
logger = Logger.new($logFilePath)
|
45
|
+
logger.error msg
|
46
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error while loading the form. Consult the log for more details').exec
|
47
|
+
end
|
48
|
+
|
49
|
+
def create
|
50
|
+
@chip_settings = Spi.create(
|
51
|
+
spi_mode: @spi_settings_gui.cbx_mode.currentText,
|
52
|
+
spi_frequency: @spi_settings_gui.cbx_frequency.currentText,
|
53
|
+
spi_command_read: @spi_settings_gui.lie_cmd_read.text,
|
54
|
+
spi_page_size: @spi_settings_gui.lie_page_size.text,
|
55
|
+
spi_total_size: @spi_settings_gui.lie_total_size.text,
|
56
|
+
spi_chip: @chip.chip_id
|
57
|
+
)
|
58
|
+
Qt::MessageBox.new(Qt::MessageBox::Information, 'Succes', 'SPI parameters created successfully').exec
|
59
|
+
rescue Exception => msg
|
60
|
+
logger = Logger.new($logFilePath)
|
61
|
+
logger.error msg
|
62
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured when saving the SPI parameters. Consult the log for more details').exec
|
63
|
+
end
|
64
|
+
|
65
|
+
def update
|
66
|
+
if @chip_settings.spi_mode != @spi_settings_gui.cbx_mode.currentText.to_i
|
67
|
+
@chip_settings.update(spi_mode: @spi_settings_gui.cbx_mode.currentText.to_i)
|
68
|
+
end
|
69
|
+
if @chip_settings.spi_frequency != @spi_settings_gui.cbx_frequency.currentText
|
70
|
+
@chip_settings.update(spi_frequency: @spi_settings_gui.cbx_frequency.currentText)
|
71
|
+
end
|
72
|
+
if @chip_settings.spi_command_read != @spi_settings_gui.lie_cmd_read.text
|
73
|
+
if @spi_settings_gui.lie_cmd_read.text.empty?
|
74
|
+
@spi_settings_gui.lie_cmd_read.setText('3')
|
75
|
+
end
|
76
|
+
@chip_settings.update(spi_command_read: @spi_settings_gui.lie_cmd_read.text)
|
77
|
+
end
|
78
|
+
if @chip_settings.spi_page_size != @spi_settings_gui.lie_page_size.text
|
79
|
+
@chip_settings.update(spi_page_size: @spi_settings_gui.lie_page_size.text)
|
80
|
+
end
|
81
|
+
if @chip_settings.spi_total_size != @spi_settings_gui.lie_total_size.text
|
82
|
+
@chip_settings.update(spi_total_size: @spi_settings_gui.lie_total_size.text)
|
83
|
+
end
|
84
|
+
Qt::MessageBox.new(Qt::MessageBox::Information, 'Succes', 'SPI parameters saved successfully').exec
|
85
|
+
rescue Exception => msg
|
86
|
+
logger = Logger.new($logFilePath)
|
87
|
+
logger.error msg
|
88
|
+
Qt::MessageBox.new(Qt::MessageBox::Critical, 'Critical error', 'Error occured when saving the SPI parameters. Consult the log for more details').exec
|
89
|
+
end
|
90
|
+
end
|