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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 030b1c7ca30ebc3603c750b93147ad1a7b2d407f
|
4
|
+
data.tar.gz: 7595d0cc31b7a3fab274252985577064e581ebb6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 058934a2bef35c81153d96ce0b21d12069c6abe32cbb5f32166f9a3777d865b5761cea0dcaaca56bc0477bba4fb047875d3f2929fe7b23388e247c7fa427f2ea
|
7
|
+
data.tar.gz: 9586a89c0be2be5df3e39754711563c3885e4506c7bf8d7f4f68ed2005988fe42c511555c73c4aa7842ff2ee4b68a98fe01569cebd317b613255d814dbf27530
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Hardsploit
|
2
|
+
|
3
|
+
The essential security auditing tool for Internet of Things devices you'll need in your toolbox
|
4
|
+
|
5
|
+
### [GO TO HARDSPLOIT](http://www.hardsploit.io)
|
6
|
+
|
7
|
+
TO LEARN ABOUT IT
|
8
|
+
|
9
|
+
### [GO TO SHOP](https://www.shop-hardsploit.com)
|
10
|
+
TO BUY
|
11
|
+
|
12
|
+
### [GO TO WIKI](http://wiki.hardsploit.io)
|
13
|
+
|
14
|
+
TO UNDERSTAND HOW USE IT
|
15
|
+
|
16
|
+
### [GO TO FORUM](http://forum.hardsploit.io)
|
17
|
+
|
18
|
+
FOR SUPPORT / HELP
|
19
|
+
|
20
|
+
### [GO TO BUG TRACKER] (http://issues.hardsploit.io)
|
21
|
+
|
22
|
+
FOR BUGS OR IMPROVEMENTS
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/hardsploit_gui
ADDED
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#===================================================
|
2
|
+
# Hardsploit UC - 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 VersionUC
|
9
|
+
module VERSION_UC
|
10
|
+
UC = "V1.0.2"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#===================================================
|
3
|
+
# Hardsploit API - By Opale Security
|
4
|
+
# www.opale-security.com || www.hardsploit.io
|
5
|
+
# License: GNU General Public License v3
|
6
|
+
# License URI: http://www.gnu.org/licenses/gpl.txt
|
7
|
+
#===================================================
|
8
|
+
|
9
|
+
require 'libusb'
|
10
|
+
require_relative 'HardsploitAPI_CONSTANT'
|
11
|
+
require_relative 'HardsploitAPI_USB_COMMUNICATION'
|
12
|
+
require_relative 'HardsploitAPI_FIRMWARE'
|
13
|
+
require_relative 'HardsploitAPI_NO_MUX_PARALLELE_MEMORY'
|
14
|
+
require_relative 'HardsploitAPI_I2C'
|
15
|
+
require_relative 'HardsploitAPI_SPI'
|
16
|
+
require_relative 'HardsploitAPI_TEST_INTERACT'
|
17
|
+
require_relative 'SWD/HardsploitAPI_SWD'
|
18
|
+
|
19
|
+
require 'thread'
|
20
|
+
|
21
|
+
class HardsploitAPI
|
22
|
+
public
|
23
|
+
|
24
|
+
attr_accessor :dev
|
25
|
+
|
26
|
+
include USB
|
27
|
+
include USB_STATE
|
28
|
+
include USB_COMMAND
|
29
|
+
|
30
|
+
# Initialize the HARDSPLOIT API
|
31
|
+
# * +callbackData+:: callback to return data for dump function
|
32
|
+
# * +callbackInfo+:: callback to get back general information
|
33
|
+
# * +callbackError+:: callback not used for the moment and transform into progressCallback soon
|
34
|
+
# * +callbackSpeedOfTransfert+:: callback to get back +information about speed+
|
35
|
+
def initialize(*args)
|
36
|
+
parametters = HardsploitAPI.checkParametters(["callbackData","callbackInfo","callbackError","callbackSpeedOfTransfert"],args)
|
37
|
+
@callbackData = parametters[:callbackData]
|
38
|
+
@callbackInfo = parametters[:callbackInfo]
|
39
|
+
@callbackError = parametters[:callbackError]
|
40
|
+
@callbackSpeedOfTransfert = parametters[:callbackSpeedOfTransfert]
|
41
|
+
|
42
|
+
@packet_send = Array.new
|
43
|
+
@usb = LIBUSB::Context.new
|
44
|
+
@device = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
# Set custom value to wiring led
|
48
|
+
# * +value+:: 64 bits (8x8 Bytes) values to represent led (PortH PortG PortF PortE PortD PortC PortB PortA)
|
49
|
+
def setWiringLeds(*args)
|
50
|
+
parametters = HardsploitAPI.checkParametters(["value"],args)
|
51
|
+
val = parametters[:value]
|
52
|
+
|
53
|
+
packet = Array.new
|
54
|
+
packet.push 0 #low byte of lenght of trame refresh automaticly before send by usb
|
55
|
+
packet.push 0 #high byte of lenght of trame refresh automaticly before send by usb
|
56
|
+
packet.push HardsploitAPI.lowByte(USB_COMMAND::FPGA_COMMAND)
|
57
|
+
packet.push HardsploitAPI.highByte(USB_COMMAND::FPGA_COMMAND)
|
58
|
+
|
59
|
+
packet.push 0x23 #Command SPI write wiring led
|
60
|
+
|
61
|
+
packet.push HardsploitAPI.reverseBit((val & 0x00000000000000FF) >> 0)
|
62
|
+
packet.push HardsploitAPI.reverseBit((val & 0x000000000000FF00) >> 8 )
|
63
|
+
packet.push HardsploitAPI.reverseBit((val & 0x0000000000FF0000) >> 16 )
|
64
|
+
packet.push HardsploitAPI.reverseBit((val & 0x00000000FF000000) >> 24 )
|
65
|
+
packet.push HardsploitAPI.reverseBit((val & 0x000000FF00000000) >> 32 )
|
66
|
+
packet.push HardsploitAPI.reverseBit((val & 0x0000FF0000000000) >> 40 )
|
67
|
+
packet.push HardsploitAPI.reverseBit((val & 0x00FF000000000000) >> 48 )
|
68
|
+
packet.push HardsploitAPI.reverseBit((val & 0xFF00000000000000) >> 56 )
|
69
|
+
|
70
|
+
return self.sendPacket(packet)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Obtaint the version number of the board
|
74
|
+
def getVersionNumber
|
75
|
+
packet = Array.new
|
76
|
+
packet.push 0 #low byte of lenght of trame refresh automaticly before send by usb
|
77
|
+
packet.push 0 #high byte of lenght of trame refresh automaticly before send by usb
|
78
|
+
packet.push HardsploitAPI.lowByte(USB_COMMAND::GET_VERSION_NUMBER)
|
79
|
+
packet.push HardsploitAPI.highByte(USB_COMMAND::GET_VERSION_NUMBER)
|
80
|
+
|
81
|
+
#remove header
|
82
|
+
version_number = sendAndReceiveDATA(packet,1000).drop(4)
|
83
|
+
if version_number.size < 20 then #if size more thant 20 char error when reading version number
|
84
|
+
return version_number.pack('U*')
|
85
|
+
else
|
86
|
+
return "BAD VERSION NUMBER"
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
def self.reverseBit(byte)
|
94
|
+
return byte.to_s(2).rjust(8, "0").reverse.to_i(2)
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.checkParametters(arr_parametters,*args)
|
98
|
+
params = Hash.new
|
99
|
+
if args[0][0].class == Hash then
|
100
|
+
hash_args = args[0][0]
|
101
|
+
arr_parametters.each do |param|
|
102
|
+
if hash_args[param.to_sym] == nil then
|
103
|
+
raise "Wrong parametters, you need to specify #{param.to_sym}"
|
104
|
+
else
|
105
|
+
params[param.to_sym] = hash_args[param.to_sym]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
else
|
109
|
+
if args[0].length == arr_parametters.size then
|
110
|
+
args[0].each_with_index do |value,key|
|
111
|
+
params[arr_parametters[key].to_sym] = value
|
112
|
+
end
|
113
|
+
else
|
114
|
+
raise "Error : method need #{arr_parametters.size} parametters"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
return params
|
118
|
+
end
|
119
|
+
|
120
|
+
def consoleError(value)
|
121
|
+
@callbackError.call(value)
|
122
|
+
end
|
123
|
+
def consoleData(value)
|
124
|
+
@callbackData.call(value)
|
125
|
+
end
|
126
|
+
def consoleSpeed(value)
|
127
|
+
@callbackSpeedOfTransfert.call(value)
|
128
|
+
end
|
129
|
+
def consoleInfo(value)
|
130
|
+
@callbackInfo.call(value)
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#===================================================
|
3
|
+
# Hardsploit API - By Opale Security
|
4
|
+
# www.opale-security.com || www.hardsploit.io
|
5
|
+
# License: GNU General Public License v3
|
6
|
+
# License URI: http://www.gnu.org/licenses/gpl.txt
|
7
|
+
#===================================================
|
8
|
+
|
9
|
+
class HardsploitAPI
|
10
|
+
public
|
11
|
+
|
12
|
+
# Power on the led for each signal specified
|
13
|
+
# Params:
|
14
|
+
# +signal+:: Name of signal you want visual help (set the led)
|
15
|
+
def signalHelpingWiring(*args)
|
16
|
+
parametters = HardsploitAPI.checkParametters(["signal"],args)
|
17
|
+
signal = parametters[:signal]
|
18
|
+
|
19
|
+
wires = Hash.new
|
20
|
+
|
21
|
+
#Parallel module
|
22
|
+
wires["A0"] = 0
|
23
|
+
wires["A1"] = 1
|
24
|
+
wires["A2"] = 2
|
25
|
+
wires["A3"] = 3
|
26
|
+
wires["A4"] = 4
|
27
|
+
wires["A5"] = 5
|
28
|
+
wires["A6"] = 6
|
29
|
+
wires["A7"] = 7
|
30
|
+
wires["A8"] = 8
|
31
|
+
wires["A9"] = 9
|
32
|
+
wires["A10"] = 10
|
33
|
+
wires["A11"] = 11
|
34
|
+
wires["A12"] = 12
|
35
|
+
wires["A13"] = 13
|
36
|
+
wires["A14"] = 14
|
37
|
+
wires["A15"] = 15
|
38
|
+
wires["A16"] = 16
|
39
|
+
wires["A17"] = 17
|
40
|
+
wires["A18"] = 18
|
41
|
+
wires["A19"] = 19
|
42
|
+
wires["A20"] = 20
|
43
|
+
wires["A21"] = 21
|
44
|
+
wires["A22"] = 22
|
45
|
+
wires["A23"] = 23
|
46
|
+
wires["A24"] = 24
|
47
|
+
wires["A25"] = 25
|
48
|
+
wires["A26"] = 26
|
49
|
+
wires["A27"] = 27
|
50
|
+
wires["A28"] = 28
|
51
|
+
wires["A29"] = 29
|
52
|
+
wires["A30"] = 30
|
53
|
+
wires["A31"] = 31
|
54
|
+
|
55
|
+
wires["D0"] = 32
|
56
|
+
wires["D1"] = 33
|
57
|
+
wires["D2"] = 34
|
58
|
+
wires["D3"] = 35
|
59
|
+
wires["D4"] = 36
|
60
|
+
wires["D5"] = 37
|
61
|
+
wires["D6"] = 38
|
62
|
+
wires["D7"] = 39
|
63
|
+
wires["D8"] = 40
|
64
|
+
wires["D9"] = 41
|
65
|
+
wires["D10"] = 42
|
66
|
+
wires["D11"] = 43
|
67
|
+
wires["D12"] = 44
|
68
|
+
wires["D13"] = 45
|
69
|
+
wires["D14"] = 46
|
70
|
+
wires["D15"] = 47
|
71
|
+
|
72
|
+
wires["RST"] = 48
|
73
|
+
wires["CE"] = 49
|
74
|
+
wires["OE"] = 50
|
75
|
+
wires["WE"] = 51
|
76
|
+
wires["CLK"] = 52
|
77
|
+
wires["WP"] = 53
|
78
|
+
wires["ADV"] = 54
|
79
|
+
|
80
|
+
|
81
|
+
#SPI module
|
82
|
+
wires["CS"] = 0
|
83
|
+
wires["SPI_CLK"] = 1
|
84
|
+
wires["MOSI"] = 2
|
85
|
+
wires["MISO"] = 3
|
86
|
+
|
87
|
+
#I2C module
|
88
|
+
wires["I2C_CLK"] = 0
|
89
|
+
wires["SDA"] = 1
|
90
|
+
|
91
|
+
begin
|
92
|
+
setWiringLeds(2**wires[signal])
|
93
|
+
rescue Exception => e
|
94
|
+
raise 'UNKNOWN SIGNAL'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
module USB_COMMAND
|
99
|
+
GREEN_LED = 0
|
100
|
+
RED_LED = 1
|
101
|
+
LOOPBACK = 2
|
102
|
+
ERASE_FIRMWARE = 3
|
103
|
+
WRITE_PAGE_FIRMWARE = 4
|
104
|
+
READ_PAGE_FIRMWARE = 5
|
105
|
+
READ_ID_FLASH = 6
|
106
|
+
START_FPGA = 7
|
107
|
+
STOP_FPGA = 8
|
108
|
+
FPGA_COMMAND = 9
|
109
|
+
FPGA_DATA = 10
|
110
|
+
STOP_FPGA_DATA = 11
|
111
|
+
START_FPGA_DATA = 12
|
112
|
+
GET_SERIAL_NUMBER = 13
|
113
|
+
GET_VERSION_NUMBER = 14
|
114
|
+
VCP_ERROR = 0xFFFF
|
115
|
+
end
|
116
|
+
|
117
|
+
module I2C
|
118
|
+
KHZ_100 = 0
|
119
|
+
KHZ_400 = 1
|
120
|
+
KHZ_1000 = 2
|
121
|
+
end
|
122
|
+
|
123
|
+
module USB
|
124
|
+
OUT_ENDPOINT = 0X02
|
125
|
+
IN_ENDPOINT = 0X81
|
126
|
+
USB_TRAME_SIZE = 8191
|
127
|
+
end
|
128
|
+
module VERSION
|
129
|
+
API = "1.1.0"
|
130
|
+
end
|
131
|
+
module USB_STATE
|
132
|
+
public
|
133
|
+
UNKNOWN_STATE = -2
|
134
|
+
BUSY = -1
|
135
|
+
NOT_CONNECTED = 0
|
136
|
+
CONNECTED = 1
|
137
|
+
UNKNOWN_CONNECTED = 2
|
138
|
+
SUCCESSFUL_SEND = 3
|
139
|
+
PACKET_IS_TOO_LARGE = 4
|
140
|
+
ERROR_SEND = 5
|
141
|
+
SUCCESSFUL_RECEIVE = 6
|
142
|
+
TIMEOUT_RECEIVE = 7
|
143
|
+
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,311 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
#===================================================
|
3
|
+
# Hardsploit API - By Opale Security
|
4
|
+
# www.opale-security.com || www.hardsploit.io
|
5
|
+
# License: GNU General Public License v3
|
6
|
+
# License URI: http://www.gnu.org/licenses/gpl.txt
|
7
|
+
#===================================================
|
8
|
+
|
9
|
+
class HardsploitAPI
|
10
|
+
public
|
11
|
+
|
12
|
+
# Wait to receive data
|
13
|
+
# * +pathFirmware+:: path of rpd file (vhdl)
|
14
|
+
# * +checkFirmware+:: boolean if check is needed (recommended false, in case issue true to check)
|
15
|
+
# Return true if firmware write == firmware read (slow because read the firmware for check)
|
16
|
+
def uploadFirmware(*args)
|
17
|
+
parametters = HardsploitAPI.checkParametters(["pathFirmware","checkFirmware"],args)
|
18
|
+
pathFirmware = parametters[:pathFirmware]
|
19
|
+
checkFirmware = parametters[:checkFirmware]
|
20
|
+
|
21
|
+
stopFPGA
|
22
|
+
eraseFirmware
|
23
|
+
firmwarewrite = self.writeFirmware(pathFirmware)#return array of bytes write
|
24
|
+
if checkFirmware == true then
|
25
|
+
firmwareRead = self.readFirmware(firmwarewrite.length) #return array of bytes read
|
26
|
+
startFPGA
|
27
|
+
return (firmwarewrite == firmwareRead)
|
28
|
+
else
|
29
|
+
startFPGA
|
30
|
+
return true
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def startFPGA
|
35
|
+
packet = Array.new
|
36
|
+
packet.push HardsploitAPI.lowByte(4)
|
37
|
+
packet.push HardsploitAPI.highByte(4)
|
38
|
+
packet.push HardsploitAPI.lowByte(USB_COMMAND::START_FPGA)
|
39
|
+
packet.push HardsploitAPI.highByte(USB_COMMAND::START_FPGA)
|
40
|
+
self.sendPacket(packet)
|
41
|
+
end
|
42
|
+
def stopFPGA
|
43
|
+
packet = Array.new
|
44
|
+
packet.push HardsploitAPI.lowByte(4)
|
45
|
+
packet.push HardsploitAPI.highByte(4)
|
46
|
+
packet.push HardsploitAPI.lowByte(USB_COMMAND::STOP_FPGA)
|
47
|
+
packet.push HardsploitAPI.highByte(USB_COMMAND::STOP_FPGA)
|
48
|
+
self.sendPacket(packet)
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
protected
|
53
|
+
def eraseFirmware
|
54
|
+
usbPacket = Array.new
|
55
|
+
usbPacket.push HardsploitAPI.lowByte(4) #length of trame
|
56
|
+
usbPacket.push HardsploitAPI.highByte(4)
|
57
|
+
usbPacket.push HardsploitAPI.lowByte(USB_COMMAND::ERASE_FIRMWARE)
|
58
|
+
usbPacket.push HardsploitAPI.highByte(USB_COMMAND::ERASE_FIRMWARE)
|
59
|
+
|
60
|
+
consoleInfo "Start to erase Firmware\n"
|
61
|
+
t1 = Time.now
|
62
|
+
received_data = sendAndReceiveDATA(usbPacket,15000)
|
63
|
+
|
64
|
+
case received_data
|
65
|
+
when HardsploitAPI::USB_STATE::PACKET_IS_TOO_LARGE
|
66
|
+
return HardsploitAPI::USB_STATE::ERROR_SEND
|
67
|
+
when HardsploitAPI::USB_STATE::ERROR_SEND
|
68
|
+
return HardsploitAPI::USB_STATE::ERROR_SEND
|
69
|
+
when HardsploitAPI::USB_STATE::BUSY
|
70
|
+
return HardsploitAPI::USB_STATE::ERROR_SEND
|
71
|
+
when HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
|
72
|
+
p "TIMEOUT_RECEIVE"
|
73
|
+
return HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
|
74
|
+
else
|
75
|
+
t2 = Time.now
|
76
|
+
delta = t2 - t1
|
77
|
+
consoleSpeed "Firmware erased in #{delta.round(4)} sec\n\n"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
#Just path of file and wait. is a blocking function until firmware has been uploaded
|
82
|
+
def writeFirmware (file_path)
|
83
|
+
t1 = Time.now
|
84
|
+
consoleInfo "Upload firmware in progress\n"
|
85
|
+
|
86
|
+
usbPacket= Array.new
|
87
|
+
file = File.read(file_path,:encoding => 'iso-8859-1').unpack('C*') #string to array byte
|
88
|
+
#file = file.drop(168) #remove header of pof file
|
89
|
+
#file.pop(52+355000) #remove footer of pof file + about 355k of unused memory
|
90
|
+
|
91
|
+
consoleInfo "FIRMARE Write #{file.size} bytes\n"
|
92
|
+
|
93
|
+
#firmwareFile = file.clone #copy the file in other variable to return it not just egal because copy pointer and after is the same array we want a copy -> clone
|
94
|
+
|
95
|
+
nbFullPage = file.size/256
|
96
|
+
nbLastByte = file.size%256
|
97
|
+
|
98
|
+
nbFullPacket = nbFullPage/31
|
99
|
+
nbLastPagePacket = nbFullPage%31
|
100
|
+
|
101
|
+
#complete last page with the last alone byte ( without full page)
|
102
|
+
if nbLastByte > 0 then
|
103
|
+
for i in 0.. (256-nbLastByte)
|
104
|
+
file.push 0xFF
|
105
|
+
end
|
106
|
+
nbFullPage = nbFullPage+1
|
107
|
+
nbLastByte = 0
|
108
|
+
|
109
|
+
#recalculating packet after complete half page to a full page
|
110
|
+
nbFullPacket = nbFullPage/31
|
111
|
+
nbLastPagePacket = nbFullPage%31
|
112
|
+
end
|
113
|
+
|
114
|
+
consoleInfo "REAL Write #{file.size} bytes\n"
|
115
|
+
|
116
|
+
#Now only full page but maybe a half packet
|
117
|
+
#Prepare the full packet (31 pages of 256 byte each)
|
118
|
+
for ipacket in 0..nbFullPacket-1
|
119
|
+
usbPacket= Array.new
|
120
|
+
usbPacket.push 0 #lenght of trame modify by sendUSBPacket
|
121
|
+
usbPacket.push 0
|
122
|
+
usbPacket.push HardsploitAPI.lowByte(USB_COMMAND::WRITE_PAGE_FIRMWARE)
|
123
|
+
usbPacket.push HardsploitAPI.highByte(USB_COMMAND::WRITE_PAGE_FIRMWARE)
|
124
|
+
usbPacket.push HardsploitAPI.lowByte((ipacket)*31) # low byte Nb of the first page
|
125
|
+
usbPacket.push HardsploitAPI.highByte((ipacket)*31) # high byte Nb of the first page
|
126
|
+
usbPacket.push 31 #Nb of pages sent
|
127
|
+
|
128
|
+
start = (ipacket)*31*256
|
129
|
+
stop = (ipacket+1)*31*256 -1 #array start at index = 0
|
130
|
+
|
131
|
+
for iFile in start..stop
|
132
|
+
usbPacket.push HardsploitAPI.reverseBit(file[iFile])
|
133
|
+
#usbPacket.push file[iFile]
|
134
|
+
end
|
135
|
+
|
136
|
+
percent = ipacket *100 / (nbFullPacket-1)
|
137
|
+
|
138
|
+
case self.sendPacket(usbPacket)
|
139
|
+
when USB_STATE::SUCCESSFUL_SEND
|
140
|
+
consoleSpeed "UPLOAD AT : #{ipacket} / #{(nbFullPacket-1)} (#{percent}) %\n"
|
141
|
+
when USB_STATE::PACKET_IS_TOO_LARGE
|
142
|
+
return USB_STATE::PACKET_IS_TOO_LARGE
|
143
|
+
when USB_STATE::ERROR_SEND
|
144
|
+
return USB_STATE::ERROR_SEND
|
145
|
+
else
|
146
|
+
return USB_STATE::ERROR_SEND
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
#Prepare the last packet with the rest of data
|
151
|
+
if nbLastPagePacket >0 then
|
152
|
+
usbPacket= Array.new
|
153
|
+
usbPacket.push 0 #lenght of trame modify by sendUSBPacket
|
154
|
+
usbPacket.push 0
|
155
|
+
usbPacket.push HardsploitAPI.lowByte(USB_COMMAND::WRITE_PAGE_FIRMWARE)
|
156
|
+
usbPacket.push HardsploitAPI.highByte(USB_COMMAND::WRITE_PAGE_FIRMWARE)
|
157
|
+
|
158
|
+
if nbFullPacket == 0 then
|
159
|
+
usbPacket.push HardsploitAPI.lowByte((nbFullPacket)*31) # low byte Nb of the first page
|
160
|
+
usbPacket.push HardsploitAPI.highByte((nbFullPacket)*31) # high byte Nb of the first page
|
161
|
+
else
|
162
|
+
usbPacket.push HardsploitAPI.lowByte((nbFullPacket)*31 + 1 ) # low byte Nb of the first page
|
163
|
+
usbPacket.push HardsploitAPI.highByte((nbFullPacket)*31+ 1 ) # high byte Nb of the first page
|
164
|
+
end
|
165
|
+
|
166
|
+
usbPacket.push nbLastPagePacket # nb of page < 31
|
167
|
+
|
168
|
+
start = (nbFullPacket)*31*256
|
169
|
+
stop = (nbFullPacket)*31*256 + nbLastPagePacket*256 -1
|
170
|
+
|
171
|
+
for iFile in start..stop
|
172
|
+
#inverted LSB MSB
|
173
|
+
usbPacket.push HardsploitAPI.reverseBit(file[iFile])
|
174
|
+
end
|
175
|
+
|
176
|
+
case self.sendPacket(usbPacket)
|
177
|
+
when USB_STATE::SUCCESSFUL_SEND
|
178
|
+
consoleSpeed "UPLOAD AT : 100 %\n"
|
179
|
+
when USB_STATE::PACKET_IS_TOO_LARGE
|
180
|
+
return USB_STATE::PACKET_IS_TOO_LARGE
|
181
|
+
when USB_STATE::ERROR_SEND
|
182
|
+
return USB_STATE::ERROR_SEND
|
183
|
+
else
|
184
|
+
return USB_STATE::ERROR_SEND
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
t2 = Time.now
|
189
|
+
delta = t2 - t1
|
190
|
+
consoleSpeed "FIRMWARE WAS WRITTEN in #{delta.round(4)} sec\n"
|
191
|
+
return file
|
192
|
+
end
|
193
|
+
|
194
|
+
|
195
|
+
#Read firmware
|
196
|
+
def readFirmware(size)
|
197
|
+
consoleSpeed "START READ FIRMWARE \n"
|
198
|
+
readFirmware = Array.new
|
199
|
+
t1 = Time.now
|
200
|
+
|
201
|
+
nbFullPage = size/256
|
202
|
+
nbLastByte = size%256
|
203
|
+
|
204
|
+
|
205
|
+
nbFullPacket = nbFullPage/31
|
206
|
+
nbLastPagePacket = nbFullPage%31
|
207
|
+
|
208
|
+
if nbLastByte > 0 then
|
209
|
+
nbSuppressBytesAtLast = 256-nbLastByte
|
210
|
+
|
211
|
+
nbFullPage = nbFullPage+1
|
212
|
+
nbLastByte = 0
|
213
|
+
|
214
|
+
nbFullPacket = nbFullPage/31
|
215
|
+
nbLastPagePacket = nbFullPage%31
|
216
|
+
else
|
217
|
+
nbSuppressBytesAtLast = 0
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
for ipacket in 0..nbFullPacket-1
|
222
|
+
usbPacket= Array.new
|
223
|
+
usbPacket.push 7
|
224
|
+
usbPacket.push 0
|
225
|
+
usbPacket.push HardsploitAPI.lowByte(USB_COMMAND::READ_PAGE_FIRMWARE)
|
226
|
+
usbPacket.push HardsploitAPI.highByte(USB_COMMAND::READ_PAGE_FIRMWARE)
|
227
|
+
usbPacket.push HardsploitAPI.lowByte((ipacket)*31) # low byte Nb of the first page
|
228
|
+
usbPacket.push HardsploitAPI.highByte((ipacket)*31) # high byte Nb of the first page
|
229
|
+
usbPacket.push 31 # nb of page max 31 per packet
|
230
|
+
|
231
|
+
received_data = sendAndReceiveDATA(usbPacket,3000)
|
232
|
+
#p received_data
|
233
|
+
case received_data
|
234
|
+
when HardsploitAPI::USB_STATE::PACKET_IS_TOO_LARGE
|
235
|
+
return HardsploitAPI::USB_STATE::ERROR_SEND
|
236
|
+
when HardsploitAPI::USB_STATE::ERROR_SEND
|
237
|
+
return HardsploitAPI::USB_STATE::ERROR_SEND
|
238
|
+
when HardsploitAPI::USB_STATE::BUSY
|
239
|
+
return HardsploitAPI::USB_STATE::ERROR_SEND
|
240
|
+
when HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
|
241
|
+
return HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
|
242
|
+
else
|
243
|
+
#remove header
|
244
|
+
received_data = received_data.drop(7)
|
245
|
+
|
246
|
+
#reverse byte
|
247
|
+
received_data = received_data.collect {|x| self.reverseBit(x) }
|
248
|
+
|
249
|
+
readFirmware.push *received_data
|
250
|
+
|
251
|
+
if nbFullPacket == 1 then
|
252
|
+
consoleSpeed "READ AT : 1 / 2 50 %\n"
|
253
|
+
else
|
254
|
+
percent = ipacket *100 / (nbFullPacket-1)
|
255
|
+
consoleSpeed "READ AT : #{ipacket} / #{(nbFullPacket-1)} (#{percent} %) \n"
|
256
|
+
end
|
257
|
+
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
#Prepare the last packet with the rest of data
|
264
|
+
if nbLastPagePacket >0 then
|
265
|
+
usbPacket= Array.new
|
266
|
+
usbPacket.push 7
|
267
|
+
usbPacket.push 0
|
268
|
+
usbPacket.push HardsploitAPI.lowByte(USB_COMMAND::READ_PAGE_FIRMWARE)
|
269
|
+
usbPacket.push HardsploitAPI.highByte(USB_COMMAND::READ_PAGE_FIRMWARE)
|
270
|
+
|
271
|
+
#Increase nb of page to add the last byte
|
272
|
+
if nbFullPacket == 0 then
|
273
|
+
usbPacket.push HardsploitAPI.lowByte((nbFullPacket)*31) # low byte Nb of the first page
|
274
|
+
usbPacket.push HardsploitAPI.highByte((nbFullPacket)*31) # high byte Nb of the first page
|
275
|
+
else
|
276
|
+
usbPacket.push HardsploitAPI.lowByte((nbFullPacket)*31 + 1 ) # low byte Nb of the first page
|
277
|
+
usbPacket.push HardsploitAPI.highByte((nbFullPacket)*31+ 1 ) # high byte Nb of the first page
|
278
|
+
end
|
279
|
+
|
280
|
+
usbPacket.push nbLastPagePacket
|
281
|
+
received_data = sendAndReceiveDATA(usbPacket,15000)
|
282
|
+
case received_data
|
283
|
+
when HardsploitAPI::USB_STATE::PACKET_IS_TOO_LARGE
|
284
|
+
return HardsploitAPI::USB_STATE::ERROR_SEND
|
285
|
+
when HardsploitAPI::USB_STATE::ERROR_SEND
|
286
|
+
return HardsploitAPI::USB_STATE::ERROR_SEND
|
287
|
+
when HardsploitAPI::USB_STATE::BUSY
|
288
|
+
return HardsploitAPI::USB_STATE::ERROR_SEND
|
289
|
+
when HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
|
290
|
+
return HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
|
291
|
+
else
|
292
|
+
#remove header
|
293
|
+
received_data = received_data.drop(7)
|
294
|
+
|
295
|
+
#reverse byte
|
296
|
+
received_data = received_data.collect {|x| self.reverseBit(x) }
|
297
|
+
readFirmware.push *received_data
|
298
|
+
|
299
|
+
consoleSpeed "READ AT 100%\n"
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
#remove a fake byte at last of reading just for transmiting
|
304
|
+
readFirmware.pop(nbSuppressBytesAtLast)
|
305
|
+
|
306
|
+
t2 = Time.now
|
307
|
+
delta = t2 - t1
|
308
|
+
consoleSpeed "READ FIRMWARE FINISH in #{delta.round(4)} sec\n"
|
309
|
+
return readFirmware
|
310
|
+
end
|
311
|
+
end
|