hardsploit_gui 2.2 → 2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/bin/hardsploit_gui +2 -2
  3. data/lib/{Firmware → Firmwares}/FPGA/I2C/I2C_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_I2C_INTERACT.rpd +0 -0
  4. data/lib/{Firmware/FPGA/SWD/SWD_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SWD_INTERACT.rpd → Firmwares/FPGA/PARALLEL/NO_MUX_PARALLEL_MEMORY/HARDSPLOIT_FIRMWARE_FPGA_NO_MUX_PARALLEL_MEMORY.rpd} +0 -0
  5. data/lib/Firmwares/FPGA/SPI/SPI_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SPI_INTERACT.rpd +0 -0
  6. data/lib/{Firmware/FPGA/SPI/SPI_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SPI_INTERACT.rpd → Firmwares/FPGA/SPI/SPI_SNIFFER/HARDSPLOIT_FIRMWARE_FPGA_SPI_SNIFFER.rpd} +0 -0
  7. data/lib/Firmwares/FPGA/SWD/SWD_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SWD_INTERACT.rpd +0 -0
  8. data/lib/{Firmware → Firmwares}/FPGA/TEST/TEST_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_TEST_INTERACT.rpd +0 -0
  9. data/lib/Firmwares/FPGA/UART/UART_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_UART_INTERACT.rpd +0 -0
  10. data/lib/{Firmware → Firmwares}/FPGA/VersionFPGA.rb +1 -1
  11. data/lib/{Firmware → Firmwares}/UC/HARDSPLOIT_FIRMWARE_UC.bin +0 -0
  12. data/lib/{Firmware → Firmwares}/UC/VersionUC.rb +1 -1
  13. data/lib/HardsploitAPI/Core/HardsploitAPI.rb +210 -0
  14. data/lib/HardsploitAPI/Core/HardsploitAPI_CONSTANT.rb +150 -0
  15. data/lib/HardsploitAPI/Core/HardsploitAPI_ERROR.rb +109 -0
  16. data/lib/HardsploitAPI/Core/HardsploitAPI_FIRMWARE.rb +305 -0
  17. data/lib/HardsploitAPI/{HardsploitAPI_PROGRESS.rb → Core/HardsploitAPI_PROGRESS.rb} +0 -0
  18. data/lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb +166 -0
  19. data/lib/HardsploitAPI/Modules/I2C/HardsploitAPI_I2C.rb +356 -0
  20. data/lib/HardsploitAPI/{HardsploitAPI_NO_MUX_PARALLELE_MEMORY.rb → Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.rb} +26 -49
  21. data/lib/HardsploitAPI/Modules/NRF24L01/HardsploitAPI_NRF24L01.rb +306 -0
  22. data/lib/HardsploitAPI/Modules/SPI/HardsploitAPI_SPI.rb +340 -0
  23. data/lib/HardsploitAPI/Modules/SPI_SNIFFER/HardsploitAPI_SPI_SNIFFER.rb +83 -0
  24. data/lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD.rb +367 -0
  25. data/lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_DEBUG.rb +89 -0
  26. data/lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_MEM_AP.rb +61 -0
  27. data/lib/HardsploitAPI/{SWD → Modules/SWD}/HardsploitAPI_SWD_STM32.rb +32 -15
  28. data/lib/HardsploitAPI/{HardsploitAPI_TEST_INTERACT.rb → Modules/TEST/HardsploitAPI_TEST_INTERACT.rb} +1 -1
  29. data/lib/HardsploitAPI/Modules/UART/HardsploitAPI_UART.rb +196 -0
  30. data/lib/Hardsploit_gui.rb +96 -0
  31. data/lib/class/Chip_editor.rb +186 -330
  32. data/lib/class/Chip_management.rb +496 -0
  33. data/lib/class/Command_editor.rb +130 -182
  34. data/lib/class/Command_table.rb +16 -22
  35. data/lib/class/Console.rb +0 -2
  36. data/lib/class/ErrorMsg.rb +312 -0
  37. data/lib/class/Export.rb +140 -0
  38. data/lib/class/Export_manager.rb +43 -43
  39. data/lib/class/Firmware.rb +52 -11
  40. data/lib/class/Generic_commands.rb +180 -190
  41. data/lib/class/Import.rb +193 -0
  42. data/lib/class/Progress_bar.rb +1 -0
  43. data/lib/class/Signal_mapper.rb +120 -0
  44. data/lib/class/Wire_helper.rb +132 -148
  45. data/lib/class/{I2C → i2c}/I2c_command.rb +16 -13
  46. data/lib/class/i2c/I2c_export.rb +95 -0
  47. data/lib/class/i2c/I2c_import.rb +117 -0
  48. data/lib/class/i2c/I2c_scanner.rb +114 -0
  49. data/lib/class/i2c/I2c_settings.rb +148 -0
  50. data/lib/class/parallel/Parallel_export.rb +118 -0
  51. data/lib/class/parallel/Parallel_import.rb +113 -0
  52. data/lib/class/parallel/Parallel_settings.rb +81 -0
  53. data/lib/class/spi/Spi_export.rb +108 -0
  54. data/lib/class/spi/Spi_import.rb +159 -0
  55. data/lib/class/spi/Spi_settings.rb +108 -0
  56. data/lib/class/spi/Spi_sniffer.rb +101 -0
  57. data/lib/class/swd/Swd.rb +125 -0
  58. data/lib/class/swd/Swd_scanner.rb +121 -0
  59. data/lib/class/swd/Swd_settings.rb +76 -0
  60. data/lib/class/uart/Uart_baudrate.rb +62 -0
  61. data/lib/class/uart/Uart_console.rb +115 -0
  62. data/lib/class/uart/Uart_settings.rb +102 -0
  63. data/lib/db/associations.rb +42 -29
  64. data/lib/db/database.rb +4 -0
  65. data/lib/db/development.sqlite3 +0 -0
  66. data/lib/db/migrate/004_create_manufacturers.rb +13 -0
  67. data/lib/db/migrate/005_create_packages.rb +13 -0
  68. data/lib/db/migrate/006_create_chip_types.rb +11 -0
  69. data/lib/db/migrate/007_create_buses.rb +11 -0
  70. data/lib/db/migrate/008_create_signals.rb +14 -0
  71. data/lib/db/migrate/009_create_chips.rb +25 -0
  72. data/lib/db/migrate/010_create_commands.rb +21 -0
  73. data/lib/db/migrate/011_create_bytes.rb +19 -0
  74. data/lib/db/migrate/012_create_i2c_settings.rb +21 -0
  75. data/lib/db/migrate/013_create_spi_settings.rb +26 -0
  76. data/lib/db/migrate/014_create_parallel_settings.rb +21 -0
  77. data/lib/db/migrate/015_create_pins.rb +19 -0
  78. data/lib/db/migrate/016_create_uses.rb +17 -0
  79. data/lib/db/migrate/017_create_swd_settings.rb +19 -0
  80. data/lib/db/migrate/018_create_uart_settings.rb +22 -0
  81. data/lib/db/schema.rb +157 -0
  82. data/lib/db/seeds.rb +161 -0
  83. data/lib/gui/gui_chip_editor.rb +23 -22
  84. data/lib/gui/gui_chip_management.rb +43 -38
  85. data/lib/gui/gui_command_editor.rb +2 -1
  86. data/lib/gui/gui_export.rb +132 -0
  87. data/lib/gui/gui_generic_commands.rb +69 -31
  88. data/lib/gui/gui_generic_export.rb +18 -2
  89. data/lib/gui/gui_generic_import.rb +18 -2
  90. data/lib/gui/gui_i2c_command.rb +2 -1
  91. data/lib/gui/gui_i2c_settings.rb +2 -2
  92. data/lib/gui/gui_import.rb +131 -0
  93. data/lib/gui/gui_parallel_settings.rb +2 -1
  94. data/lib/gui/gui_progress_bar.rb +2 -1
  95. data/lib/gui/gui_signal_mapper.rb +121 -0
  96. data/lib/gui/gui_signal_scanner.rb +146 -0
  97. data/lib/gui/gui_spi_settings.rb +6 -2
  98. data/lib/gui/gui_spi_sniffer.rb +112 -0
  99. data/lib/gui/gui_swd_settings.rb +166 -0
  100. data/lib/gui/gui_uart_baudrate.rb +114 -0
  101. data/lib/gui/gui_uart_console.rb +164 -0
  102. data/lib/gui/gui_uart_settings.rb +243 -0
  103. data/lib/gui_designer/gui_chip_editor.ui +9 -6
  104. data/lib/gui_designer/gui_chip_management.ui +79 -35
  105. data/lib/gui_designer/gui_command_editor.ui +3 -0
  106. data/lib/gui_designer/gui_export.ui +171 -0
  107. data/lib/gui_designer/gui_generic_commands.ui +274 -190
  108. data/lib/gui_designer/gui_generic_export.ui +24 -1
  109. data/lib/gui_designer/gui_generic_import.ui +25 -2
  110. data/lib/gui_designer/gui_i2c_command.ui +3 -0
  111. data/lib/gui_designer/gui_i2c_settings.ui +2 -2
  112. data/lib/gui_designer/gui_import.ui +168 -0
  113. data/lib/gui_designer/gui_parallel_settings.ui +4 -1
  114. data/lib/gui_designer/gui_progress_bar.ui +3 -0
  115. data/lib/gui_designer/gui_signal_mapper.ui +179 -0
  116. data/lib/gui_designer/gui_signal_scanner.ui +261 -0
  117. data/lib/gui_designer/gui_spi_settings.ui +15 -2
  118. data/lib/gui_designer/gui_spi_sniffer.ui +156 -0
  119. data/lib/gui_designer/gui_swd_settings.ui +189 -0
  120. data/lib/gui_designer/gui_uart_baudrate.ui +161 -0
  121. data/lib/gui_designer/gui_uart_console.ui +284 -0
  122. data/lib/gui_designer/gui_uart_settings.ui +280 -0
  123. data/lib/logs/error.log +63 -0
  124. data/lib/models/bus.rb +19 -0
  125. data/lib/models/byte.rb +29 -0
  126. data/lib/models/chip.rb +41 -0
  127. data/lib/models/chip_type.rb +14 -0
  128. data/lib/models/command.rb +20 -0
  129. data/lib/models/i2c_setting.rb +41 -0
  130. data/lib/models/manufacturer.rb +14 -0
  131. data/lib/models/package.rb +26 -0
  132. data/lib/models/parallel_setting.rb +37 -0
  133. data/lib/models/pin.rb +14 -0
  134. data/lib/models/signall.rb +20 -0
  135. data/lib/models/spi_setting.rb +67 -0
  136. data/lib/models/swd_setting.rb +25 -0
  137. data/lib/models/uart_setting.rb +52 -0
  138. data/lib/models/use.rb +6 -0
  139. data/lib/startHardsploit.rb +2 -2
  140. metadata +106 -41
  141. data/lib/Firmware/FPGA/PARALLEL/NO_MUX_PARALLEL_MEMORY/HARDSPLOIT_FIRMWARE_FPGA_NO_MUX_PARALLEL_MEMORY.rpd +0 -0
  142. data/lib/HardsploitAPI/HardsploitAPI.rb +0 -133
  143. data/lib/HardsploitAPI/HardsploitAPI_CONSTANT.rb +0 -145
  144. data/lib/HardsploitAPI/HardsploitAPI_ERROR.rb +0 -38
  145. data/lib/HardsploitAPI/HardsploitAPI_FIRMWARE.rb +0 -311
  146. data/lib/HardsploitAPI/HardsploitAPI_I2C.rb +0 -360
  147. data/lib/HardsploitAPI/HardsploitAPI_SPI.rb +0 -369
  148. data/lib/HardsploitAPI/HardsploitAPI_USB_COMMUNICATION.rb +0 -148
  149. data/lib/HardsploitAPI/LICENSE.txt +0 -674
  150. data/lib/HardsploitAPI/README.md +0 -22
  151. data/lib/HardsploitAPI/SWD/HardsploitAPI_SWD.rb +0 -249
  152. data/lib/HardsploitAPI/SWD/HardsploitAPI_SWD_DEBUG.rb +0 -102
  153. data/lib/HardsploitAPI/SWD/HardsploitAPI_SWD_MEM_AP.rb +0 -78
  154. data/lib/HardsploitAPI/TRADEMARK +0 -3
  155. data/lib/class/HardsploitGUI.rb +0 -463
  156. data/lib/class/I2C/I2c_export.rb +0 -118
  157. data/lib/class/I2C/I2c_import.rb +0 -79
  158. data/lib/class/I2C/I2c_settings.rb +0 -129
  159. data/lib/class/PARALLEL/Parallel_export.rb +0 -146
  160. data/lib/class/PARALLEL/Parallel_import.rb +0 -88
  161. data/lib/class/PARALLEL/Parallel_settings.rb +0 -102
  162. data/lib/class/SPI/Spi_export.rb +0 -138
  163. data/lib/class/SPI/Spi_import.rb +0 -113
  164. data/lib/class/SPI/Spi_settings.rb +0 -134
  165. data/lib/db/hs.db +0 -0
  166. data/lib/hardsploit.rb +0 -131
@@ -0,0 +1,356 @@
1
+ #===================================================
2
+ # Hardsploit API - 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_relative '../../Core/HardsploitAPI'
8
+ class HardsploitAPI_I2C
9
+
10
+ public
11
+
12
+ #attr_accessor :speed
13
+ #attr_reader :device_version
14
+
15
+ # * +speed+:: I2C::KHZ_40 , I2C::KHZ_100 , I2C::KHZ_400 , I2C::KHZ_1000
16
+ def initialize(speed:)
17
+ #to be sure the singleton was initialize
18
+ HardsploitAPI.instance.connect
19
+ self.speed=speed
20
+ end
21
+
22
+ def speed
23
+ return @speed
24
+ end
25
+
26
+ def speed=(speed)
27
+ unless [HardsploitAPI::I2C::KHZ_40, HardsploitAPI::I2C::KHZ_100, HardsploitAPI::I2C::KHZ_400,HardsploitAPI::I2C::KHZ_1000].include?(speed) then
28
+ raise HardsploitAPI::ERROR::I2CWrongSpeed
29
+ end
30
+ @speed = speed
31
+ end
32
+
33
+ # Interact with I2C bus
34
+ # * +payload+:: payload to send
35
+ def i2c_Interact(payload:)
36
+ if (payload.size > 4000) then
37
+ raise TypeError, 'Size of the data need to be less than 4000'
38
+ end
39
+
40
+ packet = Array.new
41
+ packet.push 0 #low byte of lenght of trame refresh automaticly before send by usb
42
+ packet.push 0 #high byte of lenght of trame refresh automaticly before send by usb
43
+ packet.push HardsploitAPI.lowByte(word:HardsploitAPI::USB_COMMAND::FPGA_COMMAND)
44
+ packet.push HardsploitAPI.highByte(word:HardsploitAPI::USB_COMMAND::FPGA_COMMAND)
45
+
46
+ packet.push 0x50 #Command RAW COMMUNICATION TO FPGA FIFO
47
+
48
+ packet.push @speed #Add speed
49
+ packet.concat payload #Add data
50
+
51
+ #remove header (4 bytes 2 for size 2 for type of command)
52
+ return HardsploitAPI.instance.sendAndReceiveDATA(packet,2000).drop(4)
53
+ end
54
+
55
+ # Start I2C scan to find addresses
56
+ # * +speed+:: I2C::KHZ_100 , I2C::KHZ_400 , I2C::KHZ_1000
57
+ # * Return An array 256 value for each addresse if 0 not present if 1 present
58
+ def i2c_Scan
59
+ if (@speed < 0) and (@speed >3) then
60
+ I2CWrongSpeed
61
+ end
62
+
63
+ array_i2c_scan = Array.new
64
+ result_scan = Array.new
65
+ return_scan = Array.new
66
+
67
+ #we want scan just read address it is a partial scan (fastest)
68
+ for i in (1..255).step(2) do
69
+ array_i2c_scan.push HardsploitAPI.lowByte(word:1) #Count Low Byte
70
+ array_i2c_scan.push HardsploitAPI.highByte(word:1) #Count High Byte
71
+ array_i2c_scan.push i
72
+ end
73
+
74
+ result_scan = i2c_Interact(payload:array_i2c_scan)
75
+ if result_scan.size != 256 then
76
+ result_scan.clear
77
+ end
78
+
79
+ for i in (0..result_scan.size-1).step(2) do
80
+ #Check if ACK_ERROR
81
+ if result_scan[i] == 1 then
82
+ return_scan.push 1 #For write
83
+ return_scan.push 1 #For read
84
+ else
85
+ return_scan.push 0 #For write
86
+ return_scan.push 0 #For read
87
+ end
88
+ end
89
+ return return_scan
90
+ end
91
+
92
+ # Interact with I2C bus
93
+ # * +speed+:: I2C::KHZ_100 , I2C::KHZ_400 , I2C::KHZ_1000
94
+ # * +i2cBaseAddress+:: I2C base address / Write address (8bits)
95
+ # * +startAddress+:: Start address (included)
96
+ # * +stopAddress+:: Stop address (included)
97
+ # * +sizeMax+:: Size max of memory (important to calculate automaticly the number of byte to set address)
98
+ def i2c_Generic_Dump (i2cBaseAddress:,startAddress:,stopAddress:,sizeMax:)
99
+ if ((startAddress < 0) or (startAddress > sizeMax-1)) then
100
+ raise TypeError, "Start address can't be negative and not more than size max - 1"
101
+ end
102
+
103
+ if ((stopAddress < 0) or (stopAddress > (sizeMax-1))) then
104
+ raise TypeError, "Stop address can't be negative and not more than size max-1 because start at 0"
105
+ end
106
+
107
+ if (stopAddress <= startAddress) then
108
+ raise TypeError, "Stop address need to be greater than start address"
109
+ end
110
+
111
+ numberOfByteAddress = (((Math.log(sizeMax-1,2)).floor + 1) / 8.0).ceil
112
+ if numberOfByteAddress > 4 then
113
+ raise TypeError, "Size max must be less than 2^32 about 4Gb"
114
+ end
115
+
116
+ if numberOfByteAddress <= 0 then
117
+ raise TypeError, "There is an issue with calculating of number of byte needed"
118
+ end
119
+ startTime = Time.now
120
+ packet_size = 2000 - numberOfByteAddress - 1
121
+ number_complet_packet = ( (stopAddress-startAddress+1) / packet_size).floor
122
+ size_last_packet = (stopAddress-startAddress+1) % packet_size
123
+
124
+ #SEND the first complete trame
125
+ for i in 0..number_complet_packet - 1 do
126
+ packet = generate_i2c_read_command(
127
+ i2cBaseAddress: i2cBaseAddress,
128
+ numberOfByteAddress: numberOfByteAddress + startAddress,
129
+ startAddress: i * packet_size,
130
+ size: packet_size
131
+ )
132
+ #Remove header, result of read command and numberOfByte Address too
133
+ HardsploitAPI.instance.consoleData ( process_dump_i2c_result( i2c_Interact( payload: packet )))
134
+ HardsploitAPI.instance.consoleProgress(
135
+ percent: 100 * ( i + 1 ) / ( number_complet_packet + ( size_last_packet.zero? ? 0 : 1 )),
136
+ startTime: startTime,
137
+ endTime: Time.new
138
+ )
139
+ end
140
+
141
+ if(size_last_packet > 0 ) then
142
+ packet = generate_i2c_read_command(
143
+ i2cBaseAddress: i2cBaseAddress,
144
+ numberOfByteAddress: numberOfByteAddress,
145
+ startAddress: number_complet_packet * packet_size + startAddress,
146
+ size: size_last_packet
147
+ )
148
+ #Remove header, result of read command and numberOfByte Address too
149
+ HardsploitAPI.instance.consoleData( process_dump_i2c_result( i2c_Interact( payload:packet )))
150
+ HardsploitAPI.instance.consoleProgress(
151
+ percent: 100,
152
+ startTime: startTime,
153
+ endTime: Time.new
154
+ )
155
+ end
156
+
157
+ delta = Time.now - startTime
158
+ HardsploitAPI.instance.consoleSpeed "Write in #{delta.round(4)} sec"
159
+ end
160
+
161
+ #For the moment only with EEPROM (not need to erase or activate write)
162
+ def i2c_Generic_Import (i2cBaseAddress:,startAddress:,pageSize:,memorySize:,dataFile:,writePageLatency:)
163
+ startTime = Time.now
164
+ begin
165
+ file = File.open(dataFile, 'rb')
166
+ sizeFile = file.size
167
+ rescue Exception => e
168
+ raise Error::FileIssue, e.message
169
+ end
170
+
171
+ if ((startAddress < 0) or (startAddress > memorySize - 1)) then
172
+ raise Error::WrongStartAddress
173
+ end
174
+
175
+ if ((pageSize <= 0) and (pageSize > 1024)) then
176
+ raise TypeError, "pageSize need to be greater than 0 and less than 1024"
177
+ end
178
+
179
+ numberOfByteAddress = (((Math.log(memorySize - 1, 2)).floor + 1) / 8.0).ceil
180
+ if numberOfByteAddress > 4 then
181
+ raise TypeError, "Size max must be less than 2^32 about 4Gb"
182
+ end
183
+
184
+ if numberOfByteAddress <= 0 then
185
+ raise TypeError, "There is an issue with calculating of number of byte needed"
186
+ end
187
+
188
+ packet_size = pageSize
189
+ number_complet_packet = (sizeFile / packet_size).floor
190
+ size_last_packet = sizeFile % packet_size
191
+
192
+ #SEND the first complete trame
193
+ for i in 0..number_complet_packet-1 do
194
+ packet = generate_i2c_write_command(
195
+ i2cBaseAddress: i2cBaseAddress,
196
+ numberOfByteAddress: numberOfByteAddress,
197
+ startAddress: i * packet_size,
198
+ data: file.read( packet_size ).unpack( "C*" )
199
+ )
200
+
201
+ #Remove header, result of read command and numberOfByte Address too
202
+ process_import_i2c_result( i2c_Interact( payload: packet ))
203
+
204
+ HardsploitAPI.instance.consoleProgress(
205
+ percent: 100 * ( i + 1 ) / ( number_complet_packet + ( size_last_packet.zero? ? 0 : 1 )),
206
+ startTime: startTime,
207
+ endTime: Time.new
208
+ )
209
+ #if too many error when write increase because we need to wait to write a full page
210
+ sleep(writePageLatency)
211
+ end
212
+
213
+ if(size_last_packet > 0 ) then
214
+ packet = generate_i2c_write_command(
215
+ i2cBaseAddress: i2cBaseAddress,
216
+ numberOfByteAddress: numberOfByteAddress,
217
+ startAddress: number_complet_packet * packet_size + startAddress,
218
+ data: file.read( size_last_packet ).unpack( "C*" )
219
+ )
220
+
221
+ #Remove header, result of read command and numberOfByte Address too
222
+ process_import_i2c_result ( i2c_Interact(payload: packet) )
223
+ HardsploitAPI.instance.consoleProgress(
224
+ percent: 100,
225
+ startTime: startTime,
226
+ endTime: Time.new
227
+ )
228
+ end
229
+
230
+ delta = Time.now - startTime
231
+ HardsploitAPI.instance.consoleSpeed "Write in #{delta.round(4)} sec"
232
+ end
233
+
234
+ def find(numberOfConnectedPinFromA0:)
235
+ posibility = HardsploitAPI.allPosibility(
236
+ numberOfConnectedPinFromA0: numberOfConnectedPinFromA0,
237
+ numberOfSignalsForBus: 2
238
+ )
239
+ compare_tab = Array.new(256, 1)
240
+ for item in posibility
241
+ currentWiring = 0
242
+ for value in item
243
+ currentWiring += 2 ** value
244
+ end
245
+ HardsploitAPI.instance.setWiringLeds(value: currentWiring)
246
+ for i in 0..(63 - item.size)
247
+ item.push i + numberOfConnectedPinFromA0
248
+ end
249
+ HardsploitAPI.instance.setCrossWiring(value: item)
250
+ begin
251
+ tab = i2c_Scan
252
+ return item if tab.include?(1) and tab != compare_tab
253
+ rescue Exception => msg
254
+ puts msg
255
+ end
256
+ end
257
+ end
258
+
259
+ private
260
+
261
+ def process_import_i2c_result (packet)
262
+ result = Array.new
263
+ for i in (0..packet.size - 1).step(2) do
264
+ case packet[i]
265
+ when 0 #Write ACK
266
+ #Do nothing,don't save write ack
267
+ else
268
+ raise TypeError, "Error in I2C transaction (NACK), write failed "
269
+ end
270
+ end
271
+ return result
272
+ end
273
+
274
+ def process_dump_i2c_result (packet)
275
+ result = Array.new
276
+ for i in (0..packet.size - 1).step(2) do
277
+ case packet[i]
278
+ when 1 #Read ACK
279
+ #Save read data
280
+ result.push packet[i + 1]
281
+ when 0 #Write ACK
282
+ #Do nothing,don't save write ack
283
+ else
284
+ raise TypeError, "Error in I2C transaction, I2C export seems to be wrong"
285
+ end
286
+ end
287
+ return result
288
+ end
289
+
290
+ def generate_i2c_write_command (i2cBaseAddress:, numberOfByteAddress:, startAddress:, data:)
291
+ packet = Array.new
292
+ #Push write command
293
+ packet.push HardsploitAPI.lowByte(word:numberOfByteAddress+data.size) #size of write command
294
+ packet.push HardsploitAPI.highByte(word:numberOfByteAddress+data.size) #size of write command
295
+
296
+ packet.push i2cBaseAddress #push Write address
297
+
298
+ case numberOfByteAddress
299
+ when 1
300
+ packet.push ((startAddress & 0x000000FF) >> 0) #AddStart0
301
+ when 2
302
+ packet.push ((startAddress & 0x0000FF00) >> 8 ) #AddStart1
303
+ packet.push ((startAddress & 0x000000FF) >> 0) #AddStart
304
+ when 3
305
+ packet.push ((startAddress & 0x00FF0000) >> 16 ) #AddStart2
306
+ packet.push ((startAddress & 0x0000FF00) >> 8 ) #AddStart1
307
+ packet.push ((startAddress & 0x000000FF) >> 0) #AddStart0
308
+ when 4
309
+ packet.push ((startAddress & 0xFF000000) >> 24 ) #AddStart3
310
+ packet.push ((startAddress & 0x00FF0000) >> 16 ) #AddStart2
311
+ packet.push ((startAddress & 0x0000FF00) >> 8 ) #AddStart1
312
+ packet.push ((startAddress & 0x000000FF) >> 0) #AddStart0
313
+ else
314
+ raise TypeError, "Issue in generate_i2c_write_command function when parse number of byte address"
315
+ end
316
+
317
+ #Push data to write
318
+ packet.push *data
319
+ return packet
320
+ end
321
+
322
+ def generate_i2c_read_command (i2cBaseAddress:, numberOfByteAddress:, startAddress:, size:)
323
+ packet = Array.new
324
+ #Push write command for start address
325
+ packet.push HardsploitAPI.lowByte(word: numberOfByteAddress) #size of write command
326
+ packet.push HardsploitAPI.highByte(word: numberOfByteAddress) #size of write command
327
+
328
+ packet.push i2cBaseAddress #push Write address
329
+
330
+ case numberOfByteAddress
331
+ when 1
332
+ packet.push ((startAddress & 0x000000FF) >> 0) #AddStart0
333
+ when 2
334
+ packet.push ((startAddress & 0x0000FF00) >> 8 ) #AddStart1
335
+ packet.push ((startAddress & 0x000000FF) >> 0) #AddStart
336
+ when 3
337
+ packet.push ((startAddress & 0x00FF0000) >> 16 ) #AddStart2
338
+ packet.push ((startAddress & 0x0000FF00) >> 8 ) #AddStart1
339
+ packet.push ((startAddress & 0x000000FF) >> 0) #AddStart0
340
+ when 4
341
+ packet.push ((startAddress & 0xFF000000) >> 24 ) #AddStart3
342
+ packet.push ((startAddress & 0x00FF0000) >> 16 ) #AddStart2
343
+ packet.push ((startAddress & 0x0000FF00) >> 8 ) #AddStart1
344
+ packet.push ((startAddress & 0x000000FF) >> 0) #AddStart0
345
+ else
346
+ raise TypeError, "Issue in generate_spi_read_command function when parse number of byte address"
347
+ end
348
+
349
+ #Push read command to read size data
350
+ packet.push HardsploitAPI.lowByte(word:size) #size of read command
351
+ packet.push HardsploitAPI.highByte(word:size) #size of read command
352
+ packet.push i2cBaseAddress+1 #push read address
353
+
354
+ return packet
355
+ end
356
+ end
@@ -6,9 +6,12 @@
6
6
  # License URI: http://www.gnu.org/licenses/gpl.txt
7
7
  #===================================================
8
8
 
9
- class HardsploitAPI
9
+ class HardsploitAPI_PARALLEL
10
10
  public
11
-
11
+ def initialize
12
+ #to be sure the singleton was initialize
13
+ HardsploitAPI.instance.connect
14
+ end
12
15
 
13
16
  def readManufactuerCodeMemory
14
17
  write_command_Memory_WithoutMultiplexing(0x00000000,0x90) #ReadDeviceIdentifierCommand
@@ -41,7 +44,7 @@ public
41
44
  # while (statut != 128 ) && (timeout >= 0)
42
45
  #
43
46
  # puts "#{statut} #{timeout}"
44
- # statut = readByteFromMemory(0) #read statut register
47
+ # statut = readByteFromMemory(0) #read statut register
45
48
  # sleep(100)
46
49
  # if timeout == 0 then
47
50
  # return statut
@@ -69,14 +72,7 @@ public
69
72
  end
70
73
 
71
74
  def write_command_Memory_WithoutMultiplexing(address,data)
72
- packet = Array.new
73
- packet.push 0 #low byte of lenght of trame refresh automaticly before send by usb
74
- packet.push 0 #high byte of lenght of trame refresh automaticly before send by usb
75
- packet.push HardsploitAPI.lowByte(USB_COMMAND::FPGA_COMMAND)
76
- packet.push HardsploitAPI.highByte(USB_COMMAND::FPGA_COMMAND)
77
-
78
- packet.push 0x50 #Command RAW COMMUNICATION TO FPGA FIFO
79
-
75
+ packet = HardsploitAPI.prepare_packet
80
76
  packet.push 0 #16 bits
81
77
  packet.push (1500/6.66).floor #latency at 1500ns
82
78
 
@@ -89,7 +85,7 @@ def write_command_Memory_WithoutMultiplexing(address,data)
89
85
  packet.push ((data & 0xFF) >> 0) #Data LOW BYTE
90
86
 
91
87
 
92
- result = sendAndReceiveDATA(packet,1000)
88
+ result = HardsploitAPI.instance.sendAndReceiveDATA(packet,1000)
93
89
  if result == USB_STATE::TIMEOUT_RECEIVE then
94
90
  raise "TIMEOUT"
95
91
  elsif result[4] == (data & 0xFF)
@@ -104,8 +100,8 @@ def write_command_Memory_WithoutMultiplexing(address,data)
104
100
  packet = Array.new
105
101
  packet.push 0 #low byte of lenght of trame refresh automaticly before send by usb
106
102
  packet.push 0 #high byte of lenght of trame refresh automaticly before send by usb
107
- packet.push HardsploitAPI.lowByte(USB_COMMAND::FPGA_COMMAND)
108
- packet.push HardsploitAPI.highByte(USB_COMMAND::FPGA_COMMAND)
103
+ packet.push HardsploitAPI.lowByte(HardsploitAPI::USB_COMMAND::FPGA_COMMAND)
104
+ packet.push HardsploitAPI.highByte(HardsploitAPI::USB_COMMAND::FPGA_COMMAND)
109
105
 
110
106
  packet.push 0x50 #Command RAW COMMUNICATION TO FPGA FIFO
111
107
 
@@ -149,22 +145,9 @@ def write_command_Memory_WithoutMultiplexing(address,data)
149
145
  # * +bits8_or_bits16_DataSize+:: 0 for 8 bits operation & 1 for 16 bits operation
150
146
  # * +latency+:: latency in ns range 7ns to 1600ns=1,6ms
151
147
  # Return USB_STATE End with TIMEOUT_RECEIVE but need to check if received the right number of bytes to ensure all is correct
152
- def read_Memory_WithoutMultiplexing(*args)
153
- parametters = HardsploitAPI.checkParametters(["addressStart","addressStop","bits8_or_bits16_DataSize","latency"],args)
154
- addressStart = parametters[:addressStart]
155
- addressStop = parametters[:addressStop]
156
- bits8_or_bits16_DataSize = parametters[:bits8_or_bits16_DataSize]
157
- latency = parametters[:latency]
158
-
159
-
148
+ def read_Memory_WithoutMultiplexing(path:,addressStart: , addressStop:, bits8_or_bits16_DataSize:, latency:)
160
149
  numberOfByteReaded = 0
161
- packet = Array.new
162
- packet.push 0 #low byte of lenght of trame refresh automaticly before send by usb
163
- packet.push 0 #high byte of lenght of trame refresh automaticly before send by usb
164
- packet.push HardsploitAPI.lowByte(USB_COMMAND::FPGA_COMMAND)
165
- packet.push HardsploitAPI.highByte(USB_COMMAND::FPGA_COMMAND)
166
-
167
- packet.push 0x50 #Command RAW COMMUNICATION TO FPGA FIFO
150
+ packet = HardsploitAPI.prepare_packet
168
151
 
169
152
  #Chek if 8bits or 16 bits
170
153
  if bits8_or_bits16_DataSize == true then
@@ -196,34 +179,28 @@ def write_command_Memory_WithoutMultiplexing(address,data)
196
179
  packet.push ((addressStop & 0x0000FF00) >> 8 ) #AddStop1
197
180
  packet.push ((addressStop & 0x000000FF) >> 0) #AddStop0
198
181
 
199
- sendPacket(packet)
182
+ HardsploitAPI.instance.sendPacket(packet)
200
183
 
201
184
  if bits8_or_bits16_DataSize then
202
185
  sizeCalculated = (addressStop-addressStart+1)
203
186
  else
204
187
  sizeCalculated = (addressStop-addressStart+1)*2
205
188
  end
206
-
189
+ file = File.open(path,"wb")
207
190
  numberOfByteReaded = 0
208
191
  while true
209
- tmp= receiveDATA(2000)
210
- case tmp
211
- when HardsploitAPI::USB_STATE::BUSY
212
- raise "USB_STATE::BUSY"
213
- when HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
214
- raise "Timeout"
215
- else
216
- #remove header (4 bytes 2 for size 2 for type of command)
217
- tmp = tmp.bytes.drop(4)
218
- numberOfByteReaded = numberOfByteReaded + tmp.size
219
- consoleData(tmp)
220
-
221
- puts "Receive #{numberOfByteReaded} of #{sizeCalculated}"
222
- if numberOfByteReaded >= sizeCalculated then
223
- #Exit because we received all data
224
- return
225
- end
226
- end
192
+ tmp= HardsploitAPI.instance.receiveDATA(2000)
193
+ #remove header (4 bytes 2 for size 2 for type of command)
194
+ tmp = tmp.bytes.drop(4)
195
+ file.write tmp.pack('C*')
196
+
197
+ numberOfByteReaded = numberOfByteReaded + tmp.size
198
+ HardsploitAPI.instance.consoleInfo "Receive #{numberOfByteReaded} of #{sizeCalculated}"
199
+ if numberOfByteReaded >= sizeCalculated then
200
+ file.close
201
+ #Exit because we received all data
202
+ return
227
203
  end
228
204
  end
205
+ end
229
206
  end