hardsploit_gui 2.0 → 2.1
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 +4 -4
- data/lib/Firmware/FPGA/I2C/I2C_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_I2C_INTERACT.rpd +0 -0
- data/lib/HardsploitAPI/HardsploitAPI.rb +5 -6
- data/lib/HardsploitAPI/HardsploitAPI_CONSTANT.rb +1 -1
- data/lib/HardsploitAPI/HardsploitAPI_ERROR.rb +38 -0
- data/lib/HardsploitAPI/HardsploitAPI_FIRMWARE.rb +3 -3
- data/lib/HardsploitAPI/HardsploitAPI_I2C.rb +145 -3
- data/lib/HardsploitAPI/HardsploitAPI_PROGRESS.rb +28 -0
- data/lib/HardsploitAPI/HardsploitAPI_SPI.rb +195 -5
- data/lib/HardsploitAPI/HardsploitAPI_USB_COMMUNICATION.rb +0 -1
- data/lib/HardsploitAPI/SWD/HardsploitAPI_SWD.rb +1 -1
- data/lib/class/Generic_commands.rb +31 -36
- data/lib/class/HardsploitGUI.rb +5 -4
- data/lib/class/I2C/I2c_export.rb +6 -9
- data/lib/class/I2C/I2c_import.rb +15 -28
- data/lib/class/I2C/I2c_settings.rb +20 -8
- data/lib/class/Progress_bar.rb +31 -0
- data/lib/class/SPI/Spi_export.rb +6 -9
- data/lib/class/SPI/Spi_import.rb +33 -32
- data/lib/class/SPI/Spi_settings.rb +50 -4
- data/lib/db/hs.db +0 -0
- data/lib/gui/gui_chip_editor.rb +120 -127
- data/lib/gui/gui_i2c_settings.rb +34 -5
- data/lib/gui/gui_progress_bar.rb +84 -0
- data/lib/gui/gui_spi_settings.rb +175 -49
- data/lib/gui_designer/gui_chip_editor.ui +134 -141
- data/lib/gui_designer/gui_i2c_settings.ui +35 -4
- data/lib/gui_designer/gui_progress_bar.ui +83 -0
- data/lib/gui_designer/gui_spi_settings.ui +159 -34
- data/lib/hardsploit.rb +12 -3
- data/lib/logs/error.log +1 -0
- data/lib/startHardsploit.rb +10 -0
- metadata +8 -3
- data/lib/gui_designer/gui_processing.ui +0 -81
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b79bd73280ea7c66e0edaf61103cb36b18db5a96
|
4
|
+
data.tar.gz: ebf960a577ff3f24cdaec29553c1255ceb6fc93d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07f8c87b9042222abe141b2db89ae4719f4c2a2776b0a0599ad39f401ad60c51eb6de16415bc1304ca5d1b499d6aa44912f6af98757c7a8a44a13fa18c5a9d35
|
7
|
+
data.tar.gz: ba298ca43356b5939f485b206223bc9699875edc447f3d5db902cdfd5a457874bc4735f95e404d2ff3f3c75931d16b9b2425c8cefb96c32a0b238afbfb8cb677
|
Binary file
|
@@ -15,6 +15,7 @@ require_relative 'HardsploitAPI_I2C'
|
|
15
15
|
require_relative 'HardsploitAPI_SPI'
|
16
16
|
require_relative 'HardsploitAPI_TEST_INTERACT'
|
17
17
|
require_relative 'SWD/HardsploitAPI_SWD'
|
18
|
+
require_relative 'HardsploitAPI_ERROR'
|
18
19
|
|
19
20
|
require 'thread'
|
20
21
|
|
@@ -33,10 +34,10 @@ public
|
|
33
34
|
# * +callbackError+:: callback not used for the moment and transform into progressCallback soon
|
34
35
|
# * +callbackSpeedOfTransfert+:: callback to get back +information about speed+
|
35
36
|
def initialize(*args)
|
36
|
-
parametters = HardsploitAPI.checkParametters(["callbackData","callbackInfo","
|
37
|
+
parametters = HardsploitAPI.checkParametters(["callbackData","callbackInfo","callbackProgress","callbackSpeedOfTransfert"],args)
|
37
38
|
@callbackData = parametters[:callbackData]
|
38
39
|
@callbackInfo = parametters[:callbackInfo]
|
39
|
-
@
|
40
|
+
@callbackProgress = parametters[:callbackProgress]
|
40
41
|
@callbackSpeedOfTransfert = parametters[:callbackSpeedOfTransfert]
|
41
42
|
|
42
43
|
@packet_send = Array.new
|
@@ -88,8 +89,6 @@ public
|
|
88
89
|
|
89
90
|
end
|
90
91
|
|
91
|
-
|
92
|
-
|
93
92
|
def self.reverseBit(byte)
|
94
93
|
return byte.to_s(2).rjust(8, "0").reverse.to_i(2)
|
95
94
|
end
|
@@ -117,8 +116,8 @@ public
|
|
117
116
|
return params
|
118
117
|
end
|
119
118
|
|
120
|
-
def
|
121
|
-
@
|
119
|
+
def consoleProgress(percent:,startTime:,endTime:)
|
120
|
+
@callbackProgress.call(percent:percent,startTime:startTime,endTime:endTime)
|
122
121
|
end
|
123
122
|
def consoleData(value)
|
124
123
|
@callbackData.call(value)
|
@@ -0,0 +1,38 @@
|
|
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
|
+
module Error
|
11
|
+
class Standard < StandardError; end
|
12
|
+
|
13
|
+
class FileIssue < Standard
|
14
|
+
def initialize(msg="Issue with file")
|
15
|
+
super(msg)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
class I2CWrongSpeed < Standard
|
21
|
+
def initialize(msg="Uknown speed")
|
22
|
+
super(msg)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class WrongStartAddress < Standard
|
27
|
+
def initialize(msg="Start address can't be negative and not more than size max - 1")
|
28
|
+
super(msg)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class SpiError < Standard
|
33
|
+
def initialize(msg="Error during SPI processing")
|
34
|
+
super(msg)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -72,7 +72,7 @@ protected
|
|
72
72
|
p "TIMEOUT_RECEIVE"
|
73
73
|
return HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
|
74
74
|
else
|
75
|
-
t2 = Time.now
|
75
|
+
t2 = Time.now
|
76
76
|
delta = t2 - t1
|
77
77
|
consoleSpeed "Firmware erased in #{delta.round(4)} sec\n\n"
|
78
78
|
end
|
@@ -244,7 +244,7 @@ protected
|
|
244
244
|
received_data = received_data.drop(7)
|
245
245
|
|
246
246
|
#reverse byte
|
247
|
-
received_data = received_data.collect {|x|
|
247
|
+
received_data = received_data.collect {|x| HardsploitAPI.reverseBit(x) }
|
248
248
|
|
249
249
|
readFirmware.push *received_data
|
250
250
|
|
@@ -293,7 +293,7 @@ protected
|
|
293
293
|
received_data = received_data.drop(7)
|
294
294
|
|
295
295
|
#reverse byte
|
296
|
-
received_data = received_data.collect {|x|
|
296
|
+
received_data = received_data.collect {|x| HardsploitAPI.reverseBit(x) }
|
297
297
|
readFirmware.push *received_data
|
298
298
|
|
299
299
|
consoleSpeed "READ AT 100%\n"
|
@@ -122,7 +122,7 @@ public
|
|
122
122
|
if numberOfByteAddress <= 0 then
|
123
123
|
raise TypeError, "There is an issue with calculating of number of byte needed"
|
124
124
|
end
|
125
|
-
|
125
|
+
startTime = Time.now
|
126
126
|
packet_size = 2000 - numberOfByteAddress - 1
|
127
127
|
number_complet_packet = ( (stopAddress-startAddress+1) / packet_size).floor
|
128
128
|
size_last_packet = (stopAddress-startAddress+1) % packet_size
|
@@ -130,7 +130,6 @@ public
|
|
130
130
|
#SEND the first complete trame
|
131
131
|
for i in 0..number_complet_packet-1 do
|
132
132
|
packet = generate_i2c_read_command i2cBaseAddress,numberOfByteAddress+startAddress,i*packet_size,packet_size
|
133
|
-
|
134
133
|
temp = i2c_Interact(speed,packet)
|
135
134
|
case temp
|
136
135
|
when HardsploitAPI::USB_STATE::PACKET_IS_TOO_LARGE
|
@@ -145,8 +144,11 @@ public
|
|
145
144
|
#Remove header, result of read command and numberOfByte Address too
|
146
145
|
consoleData ( process_dump_i2c_result( temp ) )
|
147
146
|
end
|
147
|
+
|
148
|
+
consoleProgress(percent:100*(i+1)/(number_complet_packet+ (size_last_packet.zero? ? 0 : 1)),startTime:startTime,endTime:Time.new)
|
148
149
|
end
|
149
150
|
|
151
|
+
if(size_last_packet > 0 )then
|
150
152
|
packet = generate_i2c_read_command i2cBaseAddress,numberOfByteAddress,number_complet_packet*packet_size+startAddress,size_last_packet
|
151
153
|
temp = i2c_Interact(speed,packet)
|
152
154
|
case temp
|
@@ -161,10 +163,117 @@ public
|
|
161
163
|
else
|
162
164
|
#Remove header, result of read command and numberOfByte Address too
|
163
165
|
consoleData ( process_dump_i2c_result ( temp ) )
|
166
|
+
end
|
167
|
+
consoleProgress(percent:100,startTime:startTime,endTime:Time.new)
|
168
|
+
end
|
169
|
+
|
170
|
+
delta = Time.now - startTime
|
171
|
+
consoleSpeed "Write in #{delta.round(4)} sec"
|
172
|
+
end
|
173
|
+
|
174
|
+
#For the moment only with EEPROM (not need to erase or activate write)
|
175
|
+
def i2c_Generic_Import (*args)
|
176
|
+
parametters = HardsploitAPI.checkParametters(["speed","i2cBaseAddress","startAddress","pageSize","memorySize","dataFile","writePageLatency"],args)
|
177
|
+
speed = parametters[:speed]
|
178
|
+
i2cBaseAddress = parametters[:i2cBaseAddress]
|
179
|
+
startAddress = parametters[:startAddress]
|
180
|
+
pageSize = parametters[:pageSize]
|
181
|
+
memorySize = parametters[:memorySize]
|
182
|
+
dataFile = parametters[:dataFile]
|
183
|
+
writePageLatency = parametters[:writePageLatency]
|
184
|
+
|
185
|
+
startTime = Time.now
|
186
|
+
begin
|
187
|
+
file = File.open(dataFile, 'rb')
|
188
|
+
sizeFile = file.size
|
189
|
+
rescue Exception => e
|
190
|
+
raise Error::FileIssue, e.message
|
191
|
+
end
|
192
|
+
|
193
|
+
if ((startAddress < 0) or (startAddress > memorySize-1)) then
|
194
|
+
raise Error::WrongStartAddress
|
195
|
+
end
|
196
|
+
|
197
|
+
if ((pageSize <= 0) and (pageSize >1024)) then
|
198
|
+
raise TypeError, "pageSize need to be greater than 0 and less than 1024"
|
199
|
+
end
|
200
|
+
|
201
|
+
numberOfByteAddress = (((Math.log(memorySize-1,2)).floor + 1) / 8.0).ceil
|
202
|
+
if numberOfByteAddress > 4 then
|
203
|
+
raise TypeError, "Size max must be less than 2^32 about 4Gb"
|
204
|
+
end
|
205
|
+
|
206
|
+
if numberOfByteAddress <= 0 then
|
207
|
+
raise TypeError, "There is an issue with calculating of number of byte needed"
|
164
208
|
end
|
209
|
+
|
210
|
+
packet_size = pageSize
|
211
|
+
number_complet_packet = (sizeFile / packet_size).floor
|
212
|
+
size_last_packet = sizeFile % packet_size
|
213
|
+
|
214
|
+
#SEND the first complete trame
|
215
|
+
for i in 0..number_complet_packet-1 do
|
216
|
+
packet = generate_i2c_write_command i2cBaseAddress,numberOfByteAddress,i*packet_size,file.read(packet_size).unpack("C*")
|
217
|
+
temp = i2c_Interact(speed,packet)
|
218
|
+
case temp
|
219
|
+
when HardsploitAPI::USB_STATE::PACKET_IS_TOO_LARGE
|
220
|
+
puts "PACKET_IS_TOO_LARGE max: #{HardsploitAPI::USB::USB_TRAME_SIZE}"
|
221
|
+
when HardsploitAPI::USB_STATE::ERROR_SEND
|
222
|
+
puts "ERROR_SEND\n"
|
223
|
+
when HardsploitAPI::USB_STATE::BUSY
|
224
|
+
puts "BUSY"
|
225
|
+
when HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
|
226
|
+
puts "TIMEOUT_RECEIVE\n"
|
227
|
+
else
|
228
|
+
#Remove header, result of read command and numberOfByte Address too
|
229
|
+
process_import_i2c_result( temp )
|
230
|
+
end
|
231
|
+
|
232
|
+
consoleProgress(percent:100*(i+1)/(number_complet_packet+ (size_last_packet.zero? ? 0 : 1)),startTime:startTime,endTime:Time.new)
|
233
|
+
|
234
|
+
#if too many error when write increase because we need to wait to write a full page
|
235
|
+
sleep(writePageLatency)
|
236
|
+
end
|
237
|
+
|
238
|
+
if(size_last_packet > 0 )then
|
239
|
+
packet = generate_i2c_write_command(i2cBaseAddress,numberOfByteAddress,number_complet_packet*packet_size+startAddress,file.read(size_last_packet).unpack("C*"))
|
240
|
+
temp = i2c_Interact(speed,packet)
|
241
|
+
case temp
|
242
|
+
when HardsploitAPI::USB_STATE::PACKET_IS_TOO_LARGE
|
243
|
+
puts "PACKET_IS_TOO_LARGE max: #{HardsploitAPI::USB::USB_TRAME_SIZE}"
|
244
|
+
when HardsploitAPI::USB_STATE::ERROR_SEND
|
245
|
+
puts "ERROR_SEND\n"
|
246
|
+
when HardsploitAPI::USB_STATE::BUSY
|
247
|
+
puts "BUSY"
|
248
|
+
when HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
|
249
|
+
puts "TIMEOUT_RECEIVE\n"
|
250
|
+
else
|
251
|
+
#Remove header, result of read command and numberOfByte Address too
|
252
|
+
process_import_i2c_result ( temp )
|
253
|
+
end
|
254
|
+
consoleProgress(percent:100,startTime:startTime,endTime:Time.new)
|
255
|
+
end
|
256
|
+
|
257
|
+
delta = Time.now - startTime
|
258
|
+
consoleSpeed "Write in #{delta.round(4)} sec"
|
165
259
|
end
|
166
260
|
|
167
261
|
private
|
262
|
+
|
263
|
+
def process_import_i2c_result (packet)
|
264
|
+
result = Array.new
|
265
|
+
for i in (0..packet.size-1).step(2) do
|
266
|
+
case packet[i]
|
267
|
+
when 0 #Write ACK
|
268
|
+
#Do nothing,don't save write ack
|
269
|
+
else
|
270
|
+
raise TypeError, "Error in I2C transaction (NACK), write failed "
|
271
|
+
end
|
272
|
+
end
|
273
|
+
return result
|
274
|
+
end
|
275
|
+
|
276
|
+
|
168
277
|
def process_dump_i2c_result (packet)
|
169
278
|
result = Array.new
|
170
279
|
for i in (0..packet.size-1).step(2) do
|
@@ -175,12 +284,44 @@ private
|
|
175
284
|
when 0 #Write ACK
|
176
285
|
#Do nothing,don't save write ack
|
177
286
|
else
|
178
|
-
raise TypeError, "Error in I2C transaction, I2C
|
287
|
+
raise TypeError, "Error in I2C transaction, I2C export seems to be wrong"
|
179
288
|
end
|
180
289
|
end
|
181
290
|
return result
|
182
291
|
end
|
183
292
|
|
293
|
+
def generate_i2c_write_command ( i2cBaseAddress, numberOfByteAddress,startAddress,data)
|
294
|
+
packet = Array.new
|
295
|
+
#Push write command
|
296
|
+
packet.push HardsploitAPI.lowByte(numberOfByteAddress+data.size) #size of write command
|
297
|
+
packet.push HardsploitAPI.highByte(numberOfByteAddress+data.size) #size of write command
|
298
|
+
|
299
|
+
packet.push i2cBaseAddress #push Write address
|
300
|
+
|
301
|
+
case numberOfByteAddress
|
302
|
+
when 1
|
303
|
+
packet.push ((startAddress & 0x000000FF) >> 0) #AddStart0
|
304
|
+
when 2
|
305
|
+
packet.push ((startAddress & 0x0000FF00) >> 8 ) #AddStart1
|
306
|
+
packet.push ((startAddress & 0x000000FF) >> 0) #AddStart
|
307
|
+
when 3
|
308
|
+
packet.push ((startAddress & 0x00FF0000) >> 16 ) #AddStart2
|
309
|
+
packet.push ((startAddress & 0x0000FF00) >> 8 ) #AddStart1
|
310
|
+
packet.push ((startAddress & 0x000000FF) >> 0) #AddStart0
|
311
|
+
when 4
|
312
|
+
packet.push ((startAddress & 0xFF000000) >> 24 ) #AddStart3
|
313
|
+
packet.push ((startAddress & 0x00FF0000) >> 16 ) #AddStart2
|
314
|
+
packet.push ((startAddress & 0x0000FF00) >> 8 ) #AddStart1
|
315
|
+
packet.push ((startAddress & 0x000000FF) >> 0) #AddStart0
|
316
|
+
else
|
317
|
+
raise TypeError, "Issue in generate_i2c_write_command function when parse number of byte address"
|
318
|
+
end
|
319
|
+
|
320
|
+
#Push data to write
|
321
|
+
packet.push *data
|
322
|
+
return packet
|
323
|
+
end
|
324
|
+
|
184
325
|
def generate_i2c_read_command ( i2cBaseAddress, numberOfByteAddress,startAddress,size)
|
185
326
|
packet = Array.new
|
186
327
|
#Push write command for start address
|
@@ -215,4 +356,5 @@ private
|
|
215
356
|
|
216
357
|
return packet
|
217
358
|
end
|
359
|
+
|
218
360
|
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
class HardsploitProgress
|
11
|
+
def initialize(percent,timeElasped)
|
12
|
+
@Percent = percent
|
13
|
+
@TimeElasped = timeElasped
|
14
|
+
end
|
15
|
+
def getPercent
|
16
|
+
return @Percent
|
17
|
+
end
|
18
|
+
def setPercent(percent)
|
19
|
+
@Percent = percent
|
20
|
+
end
|
21
|
+
def getTimeElasped
|
22
|
+
return @TimeElasped
|
23
|
+
end
|
24
|
+
def setTimeElasped(timeElasped)
|
25
|
+
@TimeElasped = timeElasped
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -57,6 +57,147 @@ def spi_Interact(*args)
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
|
61
|
+
# Spi generic Import
|
62
|
+
# * +mode+:: SPI mode 0,1,2,3
|
63
|
+
# * +speed+:: Range 1-255 SPI clock = 150Mhz / (2*speed) tested from 3 to 255 (25Mhz to about 0.3Khz)
|
64
|
+
# * +writeSpiCommand+:: The write command
|
65
|
+
# * +startAddress+:: Start address (included)
|
66
|
+
# * +pageSize+:: Size of page
|
67
|
+
# * +memorySize+:: Size max of memory in byte (important, to calculate automatically the number of byte to set address)
|
68
|
+
# * +saveFile+:: File contain data
|
69
|
+
# * +writePageLatency+:: Time to wait after each pages written
|
70
|
+
# * +enableWriteSpiCommand+:: Enable write commad
|
71
|
+
# * +clearSpiCommand+:: Bulk erase command
|
72
|
+
# * +clearChipTime+:: Time to erase entire the memory (bulk erase) in case of flash memory, 240 seconds for a 512Mb spansion memory and 13 seconds for a 16Mb Micron memory, see the datasheet
|
73
|
+
# * +isFLASH+:: True if it is a Flash memory (add clear content)
|
74
|
+
def spi_Generic_Import (*args)
|
75
|
+
parametters = HardsploitAPI.checkParametters(["mode","speed","startAddress","pageSize","memorySize","dataFile","writeSpiCommand","writePageLatency","enableWriteSpiCommand","clearSpiCommand","clearChipTime","isFLASH"],args)
|
76
|
+
mode = parametters[:mode]
|
77
|
+
speed = parametters[:speed]
|
78
|
+
startAddress = parametters[:startAddress]
|
79
|
+
pageSize = parametters[:pageSize]
|
80
|
+
memorySize = parametters[:memorySize]
|
81
|
+
dataFile = parametters[:dataFile]
|
82
|
+
writePageLatency = parametters[:writePageLatency]
|
83
|
+
|
84
|
+
#most of the time 0x02
|
85
|
+
writeSpiCommand = parametters[:writeSpiCommand]
|
86
|
+
writeSpiCommand
|
87
|
+
#most of the time 0x06
|
88
|
+
enableWriteSpiCommand = parametters[:enableWriteSpiCommand]
|
89
|
+
|
90
|
+
#most of the time 0x60 chip eraseTime
|
91
|
+
clearSpiCommand = parametters[:clearWriteSpiCommand]
|
92
|
+
|
93
|
+
# in second
|
94
|
+
clearChipTime = parametters[:clearChipTime]
|
95
|
+
|
96
|
+
#if flash memory
|
97
|
+
isFLASH = parametters[:isEEPROM]
|
98
|
+
|
99
|
+
#Start time
|
100
|
+
startTime = Time.now
|
101
|
+
begin
|
102
|
+
file = File.open(dataFile, 'rb')
|
103
|
+
sizeFile = file.size
|
104
|
+
rescue Exception => e
|
105
|
+
raise Error::FileIssue, e.message
|
106
|
+
end
|
107
|
+
|
108
|
+
if (mode < 0) and (mode >3) then
|
109
|
+
raise TypeError, 'Mode must be between 0 and 3'
|
110
|
+
end
|
111
|
+
if (speed <= 2) and (speed >256) then
|
112
|
+
raise TypeError, 'Speed must be between 3 and 255'
|
113
|
+
end
|
114
|
+
|
115
|
+
if ((startAddress < 0) or (startAddress > memorySize-1)) then
|
116
|
+
raise Error::WrongStartAddress
|
117
|
+
end
|
118
|
+
|
119
|
+
if ((pageSize <= 0) and (pageSize >2048)) then
|
120
|
+
raise TypeError, "pageSize need to be greater than 0 and less than 2048"
|
121
|
+
end
|
122
|
+
|
123
|
+
numberOfByteAddress = (((Math.log(memorySize-1,2)).floor + 1) / 8.0).ceil
|
124
|
+
if numberOfByteAddress > 4 then
|
125
|
+
raise TypeError, "Size max must be less than 2^32 about 4Gb"
|
126
|
+
end
|
127
|
+
|
128
|
+
if numberOfByteAddress <= 0 then
|
129
|
+
raise TypeError, "There is an issue with calculating of number of byte needed"
|
130
|
+
end
|
131
|
+
|
132
|
+
#if flash memory we need to erase it before and wait enought
|
133
|
+
#time (erase cycle time in datasheet) or polling status register
|
134
|
+
if isFLASH then
|
135
|
+
spi_Interact(mode:mode,speed:speed,payload:[clearSpiCommand])
|
136
|
+
sleep(clearChipTime)
|
137
|
+
end
|
138
|
+
|
139
|
+
startTime = Time.now
|
140
|
+
packet_size = pageSize
|
141
|
+
number_complet_packet = (sizeFile / packet_size).floor
|
142
|
+
size_last_packet = sizeFile % packet_size
|
143
|
+
|
144
|
+
#SEND the first complete trame
|
145
|
+
for i in 0..number_complet_packet-1 do
|
146
|
+
#Enable write latch
|
147
|
+
spi_Interact(mode:mode,speed:speed,payload:[enableWriteSpiCommand])
|
148
|
+
packet = generate_spi_write_command numberOfByteAddress,writeSpiCommand,i*packet_size+startAddress,file.read(packet_size).unpack("C*")
|
149
|
+
temp = spi_Interact(mode,speed,packet)
|
150
|
+
case temp
|
151
|
+
when HardsploitAPI::USB_STATE::PACKET_IS_TOO_LARGE
|
152
|
+
puts "PACKET_IS_TOO_LARGE max: #{HardsploitAPI::USB::USB_TRAME_SIZE}"
|
153
|
+
when HardsploitAPI::USB_STATE::ERROR_SEND
|
154
|
+
puts "ERROR_SEND\n"
|
155
|
+
when HardsploitAPI::USB_STATE::BUSY
|
156
|
+
puts "BUSY"
|
157
|
+
when HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
|
158
|
+
puts "TIMEOUT_RECEIVE\n"
|
159
|
+
else
|
160
|
+
#Remove header, result of read command and numberOfByte Address too
|
161
|
+
#consoleData temp.drop(numberOfByteAddress+1)
|
162
|
+
if packet.size != packet.size then
|
163
|
+
raise HardsploitAPI::SpiError
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
consoleProgress(percent:100*(i+1)/(number_complet_packet+ (size_last_packet.zero? ? 0 : 1)),startTime:startTime,endTime:Time.new)
|
168
|
+
#if too many error when write increase because we need to wait to write a full page
|
169
|
+
sleep(writePageLatency)
|
170
|
+
end
|
171
|
+
|
172
|
+
if(size_last_packet > 0 )then
|
173
|
+
#Enable write latch
|
174
|
+
spi_Interact(mode:mode,speed:speed,payload:[enableWriteSpiCommand])
|
175
|
+
packet = generate_spi_write_command numberOfByteAddress,writeSpiCommand,number_complet_packet*packet_size+startAddress,file.read(size_last_packet).unpack("C*")
|
176
|
+
temp = spi_Interact(mode,speed,packet)
|
177
|
+
case temp
|
178
|
+
when HardsploitAPI::USB_STATE::PACKET_IS_TOO_LARGE
|
179
|
+
puts "PACKET_IS_TOO_LARGE max: #{HardsploitAPI::USB::USB_TRAME_SIZE}"
|
180
|
+
when HardsploitAPI::USB_STATE::ERROR_SEND
|
181
|
+
puts "ERROR_SEND\n"
|
182
|
+
when HardsploitAPI::USB_STATE::BUSY
|
183
|
+
puts "BUSY"
|
184
|
+
when HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
|
185
|
+
puts "TIMEOUT_RECEIVE\n"
|
186
|
+
else
|
187
|
+
#Remove header, result of write command and numberOfByte Address too
|
188
|
+
#consoleData temp.drop(numberOfByteAddress+1)
|
189
|
+
if packet.size != packet.size then
|
190
|
+
raise HardsploitAPI::SpiError
|
191
|
+
end
|
192
|
+
end
|
193
|
+
#Send 100% in case of last packet
|
194
|
+
consoleProgress(percent:100,startTime:startTime,endTime:Time.now)
|
195
|
+
end
|
196
|
+
delta = Time.now - startTime
|
197
|
+
consoleSpeed "Write in #{delta.round(4)} sec"
|
198
|
+
end
|
199
|
+
|
200
|
+
|
60
201
|
# Spi generic dump
|
61
202
|
# * +mode+:: SPI mode 0,1,2,3
|
62
203
|
# * +speed+:: Range 1-255 SPI clock = 150Mhz / (2*speed) tested from 3 to 255 (25Mhz to about 0.3Khz)
|
@@ -73,6 +214,14 @@ end
|
|
73
214
|
stopAddress = parametters[:stopAddress]
|
74
215
|
sizeMax = parametters[:sizeMax]
|
75
216
|
|
217
|
+
|
218
|
+
if (mode < 0) and (mode >3) then
|
219
|
+
raise TypeError, 'Mode must be between 0 and 3'
|
220
|
+
end
|
221
|
+
if (speed <= 2) and (speed >256) then
|
222
|
+
raise TypeError, 'Speed must be between 3 and 255'
|
223
|
+
end
|
224
|
+
|
76
225
|
if ((startAddress < 0) or (startAddress > sizeMax-1)) then
|
77
226
|
raise TypeError, "Start address can't be negative and not more than size max - 1"
|
78
227
|
end
|
@@ -93,6 +242,8 @@ end
|
|
93
242
|
raise TypeError, "There is an issue with calculating of number of byte needed"
|
94
243
|
end
|
95
244
|
|
245
|
+
#Start time
|
246
|
+
startTime = Time.now
|
96
247
|
packet_size = 4000 - numberOfByteAddress - 1
|
97
248
|
number_complet_packet = ( (stopAddress-startAddress+1) / packet_size).floor
|
98
249
|
size_last_packet = (stopAddress-startAddress+1) % packet_size
|
@@ -100,7 +251,6 @@ end
|
|
100
251
|
#SEND the first complete trame
|
101
252
|
for i in 0..number_complet_packet-1 do
|
102
253
|
packet = generate_spi_read_command numberOfByteAddress,readSpiCommand,i*packet_size+startAddress,packet_size
|
103
|
-
|
104
254
|
temp = spi_Interact(mode,speed,packet)
|
105
255
|
case temp
|
106
256
|
when HardsploitAPI::USB_STATE::PACKET_IS_TOO_LARGE
|
@@ -113,11 +263,13 @@ end
|
|
113
263
|
puts "TIMEOUT_RECEIVE\n"
|
114
264
|
else
|
115
265
|
#Remove header, result of read command and numberOfByte Address too
|
116
|
-
puts "receive real size #{temp.size}"
|
266
|
+
#puts "receive real size #{temp.size}"
|
117
267
|
consoleData temp.drop(numberOfByteAddress+1)
|
118
268
|
end
|
269
|
+
consoleProgress(percent:100*(i+1)/(number_complet_packet+ (size_last_packet.zero? ? 0 : 1)),startTime:startTime,endTime:Time.new)
|
119
270
|
end
|
120
271
|
|
272
|
+
if(size_last_packet > 0 )then
|
121
273
|
packet = generate_spi_read_command numberOfByteAddress,readSpiCommand,number_complet_packet*packet_size+startAddress,size_last_packet
|
122
274
|
temp = spi_Interact(mode,speed,packet)
|
123
275
|
case temp
|
@@ -131,10 +283,14 @@ end
|
|
131
283
|
puts "TIMEOUT_RECEIVE\n"
|
132
284
|
else
|
133
285
|
#Remove header, result of read command and numberOfByte Address too
|
134
|
-
puts "receive real size #{temp.size}"
|
286
|
+
#puts "receive real size #{temp.size}"
|
135
287
|
consoleData temp.drop(numberOfByteAddress+1)
|
136
|
-
|
288
|
+
consoleProgress(percent:100,startTime:startTime,endTime:Time.now)
|
289
|
+
end
|
137
290
|
end
|
291
|
+
delta = Time.now - startTime
|
292
|
+
consoleSpeed "Write in #{delta.round(4)} sec"
|
293
|
+
end
|
138
294
|
|
139
295
|
protected
|
140
296
|
def generate_spi_read_command ( numberOfByteAddress,readSpiCommand,startAddress,size)
|
@@ -168,8 +324,42 @@ protected
|
|
168
324
|
|
169
325
|
#put N dummy byte to read size data
|
170
326
|
packet.push *Array.new(size, 0)
|
327
|
+
if packet.size > 4000 then
|
328
|
+
raise TypeError, "Too many byte to send in spi mode not more than 4000 is needed"
|
329
|
+
end
|
330
|
+
|
331
|
+
return packet
|
332
|
+
end
|
333
|
+
|
334
|
+
def generate_spi_write_command ( numberOfByteAddress,writeSpiCommand,startAddress,data)
|
335
|
+
packet = Array.new
|
336
|
+
#Push write command
|
337
|
+
packet.push writeSpiCommand
|
338
|
+
|
339
|
+
case numberOfByteAddress
|
340
|
+
when 1
|
341
|
+
packet.push ((startAddress & 0x000000FF) >> 0) #AddStart0
|
342
|
+
|
343
|
+
when 2
|
344
|
+
packet.push ((startAddress & 0x0000FF00) >> 8 ) #AddStart1
|
345
|
+
packet.push ((startAddress & 0x000000FF) >> 0) #AddStart0
|
346
|
+
|
347
|
+
when 3
|
348
|
+
packet.push ((startAddress & 0x00FF0000) >> 16 ) #AddStart2
|
349
|
+
packet.push ((startAddress & 0x0000FF00) >> 8 ) #AddStart1
|
350
|
+
packet.push ((startAddress & 0x000000FF) >> 0) #AddStart0
|
351
|
+
|
352
|
+
when 4
|
353
|
+
packet.push ((startAddress & 0xFF000000) >> 24 ) #AddStart3
|
354
|
+
packet.push ((startAddress & 0x00FF0000) >> 16 ) #AddStart2
|
355
|
+
packet.push ((startAddress & 0x0000FF00) >> 8 ) #AddStart1
|
356
|
+
packet.push ((startAddress & 0x000000FF) >> 0) #AddStart0
|
357
|
+
else
|
358
|
+
raise TypeError, "Issue in generate_spi_write_command function when parse number of byte address"
|
359
|
+
end
|
171
360
|
|
172
|
-
|
361
|
+
#Push data to write
|
362
|
+
packet.push *data
|
173
363
|
if packet.size > 4000 then
|
174
364
|
raise TypeError, "Too many byte to send in spi mode not more than 4000 is needed"
|
175
365
|
end
|