hardsploit_gui 2.3 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -22
  3. data/Rakefile +1 -1
  4. data/bin/hardsploit_gui +3 -3
  5. data/lib/Firmwares/FPGA/I2C/I2C_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_I2C_INTERACT.rpd +0 -0
  6. data/lib/Firmwares/FPGA/PARALLEL/NO_MUX_PARALLEL_MEMORY/HARDSPLOIT_FIRMWARE_FPGA_NO_MUX_PARALLEL_MEMORY.rpd +0 -0
  7. data/lib/Firmwares/FPGA/SPI/SPI_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SPI_INTERACT.rpd +0 -0
  8. data/lib/Firmwares/FPGA/SPI/SPI_SNIFFER/HARDSPLOIT_FIRMWARE_FPGA_SPI_SNIFFER.rpd +0 -0
  9. data/lib/Firmwares/FPGA/SWD/SWD_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SWD_INTERACT.rpd +0 -0
  10. data/lib/Firmwares/FPGA/UART/UART_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_UART_INTERACT.rpd +0 -0
  11. data/lib/Firmwares/FPGA/VersionFPGA.rb +5 -5
  12. data/lib/Firmwares/UC/VersionUC.rb +12 -12
  13. data/lib/HardsploitAPI/Core/HardsploitAPI.rb +210 -210
  14. data/lib/HardsploitAPI/Core/HardsploitAPI_CONSTANT.rb +150 -150
  15. data/lib/HardsploitAPI/Core/HardsploitAPI_ERROR.rb +109 -109
  16. data/lib/HardsploitAPI/Core/HardsploitAPI_FIRMWARE.rb +305 -305
  17. data/lib/HardsploitAPI/Core/HardsploitAPI_PROGRESS.rb +28 -28
  18. data/lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb +166 -166
  19. data/lib/HardsploitAPI/Modules/I2C/HardsploitAPI_I2C.rb +356 -356
  20. data/lib/HardsploitAPI/Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.rb +206 -206
  21. data/lib/HardsploitAPI/Modules/NRF24L01/HardsploitAPI_NRF24L01.rb +306 -306
  22. data/lib/HardsploitAPI/Modules/SPI/HardsploitAPI_SPI.rb +340 -340
  23. data/lib/HardsploitAPI/Modules/SPI_SNIFFER/HardsploitAPI_SPI_SNIFFER.rb +83 -83
  24. data/lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD.rb +367 -367
  25. data/lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_DEBUG.rb +89 -89
  26. data/lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_MEM_AP.rb +61 -61
  27. data/lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_STM32.rb +121 -121
  28. data/lib/HardsploitAPI/Modules/TEST/HardsploitAPI_TEST_INTERACT.rb +98 -98
  29. data/lib/HardsploitAPI/Modules/UART/HardsploitAPI_UART.rb +196 -196
  30. data/lib/Hardsploit_gui.rb +96 -96
  31. data/lib/LICENSE.txt +674 -674
  32. data/lib/README.md +22 -22
  33. data/lib/TRADEMARK +2 -2
  34. data/lib/class/Chip_editor.rb +304 -304
  35. data/lib/class/Chip_management.rb +496 -496
  36. data/lib/class/Command_editor.rb +216 -216
  37. data/lib/class/Command_table.rb +233 -233
  38. data/lib/class/Console.rb +26 -26
  39. data/lib/class/ErrorMsg.rb +312 -312
  40. data/lib/class/Export.rb +140 -140
  41. data/lib/class/Export_manager.rb +124 -124
  42. data/lib/class/Firmware.rb +70 -70
  43. data/lib/class/Generic_commands.rb +260 -260
  44. data/lib/class/{i2c → I2C}/I2c_command.rb +51 -51
  45. data/lib/class/{i2c → I2C}/I2c_export.rb +95 -95
  46. data/lib/class/{i2c → I2C}/I2c_import.rb +117 -117
  47. data/lib/class/{i2c → I2C}/I2c_scanner.rb +114 -114
  48. data/lib/class/{i2c → I2C}/I2c_settings.rb +148 -148
  49. data/lib/class/Import.rb +193 -193
  50. data/lib/class/{parallel → PARALLEL}/Parallel_export.rb +118 -118
  51. data/lib/class/{parallel → PARALLEL}/Parallel_import.rb +113 -113
  52. data/lib/class/{parallel → PARALLEL}/Parallel_settings.rb +81 -81
  53. data/lib/class/Progress_bar.rb +32 -32
  54. data/lib/class/{spi → SPI}/Spi_export.rb +108 -108
  55. data/lib/class/{spi → SPI}/Spi_import.rb +159 -159
  56. data/lib/class/{spi → SPI}/Spi_settings.rb +108 -108
  57. data/lib/class/{spi → SPI}/Spi_sniffer.rb +101 -101
  58. data/lib/class/Signal_mapper.rb +120 -120
  59. data/lib/class/Wire_helper.rb +230 -230
  60. data/lib/class/swd/Swd.rb +125 -125
  61. data/lib/class/swd/Swd_scanner.rb +121 -121
  62. data/lib/class/swd/Swd_settings.rb +76 -76
  63. data/lib/class/uart/Uart_baudrate.rb +62 -62
  64. data/lib/class/uart/Uart_console.rb +115 -115
  65. data/lib/class/uart/Uart_settings.rb +102 -102
  66. data/lib/db/associations.rb +138 -138
  67. data/lib/db/database.rb +4 -4
  68. data/lib/db/development.sqlite3 +0 -0
  69. data/lib/db/migrate/004_create_manufacturers.rb +13 -13
  70. data/lib/db/migrate/005_create_packages.rb +13 -13
  71. data/lib/db/migrate/006_create_chip_types.rb +11 -11
  72. data/lib/db/migrate/007_create_buses.rb +11 -11
  73. data/lib/db/migrate/008_create_signals.rb +14 -14
  74. data/lib/db/migrate/009_create_chips.rb +25 -25
  75. data/lib/db/migrate/010_create_commands.rb +21 -21
  76. data/lib/db/migrate/011_create_bytes.rb +19 -19
  77. data/lib/db/migrate/012_create_i2c_settings.rb +21 -21
  78. data/lib/db/migrate/013_create_spi_settings.rb +26 -26
  79. data/lib/db/migrate/014_create_parallel_settings.rb +21 -21
  80. data/lib/db/migrate/015_create_pins.rb +19 -19
  81. data/lib/db/migrate/016_create_uses.rb +17 -17
  82. data/lib/db/migrate/017_create_swd_settings.rb +19 -19
  83. data/lib/db/migrate/018_create_uart_settings.rb +22 -22
  84. data/lib/db/schema.rb +157 -157
  85. data/lib/db/seeds.rb +161 -161
  86. data/lib/gui/gui_chip_editor.rb +349 -349
  87. data/lib/gui/gui_chip_management.rb +377 -377
  88. data/lib/gui/gui_command_editor.rb +219 -219
  89. data/lib/gui/gui_export.rb +132 -132
  90. data/lib/gui/gui_export_manager.rb +93 -93
  91. data/lib/gui/gui_generic_commands.rb +202 -202
  92. data/lib/gui/gui_generic_export.rb +164 -164
  93. data/lib/gui/gui_generic_import.rb +142 -142
  94. data/lib/gui/gui_i2c_command.rb +116 -116
  95. data/lib/gui/gui_i2c_settings.rb +230 -230
  96. data/lib/gui/gui_import.rb +131 -131
  97. data/lib/gui/gui_parallel_settings.rb +195 -195
  98. data/lib/gui/gui_progress_bar.rb +85 -85
  99. data/lib/gui/gui_signal_mapper.rb +121 -121
  100. data/lib/gui/gui_signal_scanner.rb +146 -146
  101. data/lib/gui/gui_spi_import.rb +126 -126
  102. data/lib/gui/gui_spi_settings.rb +313 -313
  103. data/lib/gui/gui_spi_sniffer.rb +112 -112
  104. data/lib/gui/gui_swd_settings.rb +166 -166
  105. data/lib/gui/gui_uart_baudrate.rb +114 -114
  106. data/lib/gui/gui_uart_console.rb +164 -164
  107. data/lib/gui/gui_uart_settings.rb +243 -243
  108. data/lib/gui/gui_wire_helper.rb +99 -99
  109. data/lib/gui_designer/gui_chip_editor.ui +549 -549
  110. data/lib/gui_designer/gui_chip_management.ui +886 -886
  111. data/lib/gui_designer/gui_command_editor.ui +350 -350
  112. data/lib/gui_designer/gui_export.ui +171 -171
  113. data/lib/gui_designer/gui_export_manager.ui +115 -115
  114. data/lib/gui_designer/gui_generic_commands.ui +342 -342
  115. data/lib/gui_designer/gui_generic_export.ui +202 -202
  116. data/lib/gui_designer/gui_generic_import.ui +165 -165
  117. data/lib/gui_designer/gui_i2c_command.ui +148 -148
  118. data/lib/gui_designer/gui_i2c_settings.ui +292 -292
  119. data/lib/gui_designer/gui_import.ui +168 -168
  120. data/lib/gui_designer/gui_parallel_settings.ui +247 -247
  121. data/lib/gui_designer/gui_progress_bar.ui +86 -86
  122. data/lib/gui_designer/gui_signal_mapper.ui +179 -179
  123. data/lib/gui_designer/gui_signal_scanner.ui +261 -261
  124. data/lib/gui_designer/gui_spi_settings.ui +446 -446
  125. data/lib/gui_designer/gui_spi_sniffer.ui +156 -156
  126. data/lib/gui_designer/gui_swd_settings.ui +189 -189
  127. data/lib/gui_designer/gui_uart_baudrate.ui +161 -161
  128. data/lib/gui_designer/gui_uart_console.ui +284 -284
  129. data/lib/gui_designer/gui_uart_settings.ui +280 -280
  130. data/lib/gui_designer/gui_wire_helper.ui +117 -117
  131. data/lib/images/search.png +0 -0
  132. data/lib/logs/error.log +0 -63
  133. data/lib/models/bus.rb +19 -19
  134. data/lib/models/byte.rb +29 -29
  135. data/lib/models/chip.rb +41 -41
  136. data/lib/models/chip_type.rb +14 -14
  137. data/lib/models/command.rb +20 -20
  138. data/lib/models/i2c_setting.rb +41 -41
  139. data/lib/models/manufacturer.rb +14 -14
  140. data/lib/models/package.rb +26 -26
  141. data/lib/models/parallel_setting.rb +37 -37
  142. data/lib/models/pin.rb +14 -14
  143. data/lib/models/signall.rb +20 -20
  144. data/lib/models/spi_setting.rb +67 -67
  145. data/lib/models/swd_setting.rb +25 -25
  146. data/lib/models/uart_setting.rb +52 -52
  147. data/lib/models/use.rb +6 -6
  148. data/lib/startHardsploit.rb +10 -10
  149. metadata +14 -14
@@ -1,98 +1,98 @@
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_TEST
10
- public
11
- # Write value of 64 IO for testing purpose
12
- # * +value+:: 64bits to write on all ports
13
- # return [Integer] Return the value sent (lookback) (64bits)
14
-
15
- def test_InteractWrite(*args)
16
- parametters = HardsploitAPI.checkParametters(["value"],args)
17
- val = parametters[:value]
18
-
19
- packet = Array.new
20
- packet.push 0 #low byte of lenght of trame refresh automaticly before send by usb
21
- packet.push 0 #high byte of lenght of trame refresh automaticly before send by usb
22
- packet.push HardsploitAPI.lowByte(USB_COMMAND::FPGA_COMMAND)
23
- packet.push HardsploitAPI.highByte(USB_COMMAND::FPGA_COMMAND)
24
-
25
- #Command RAW COMMUNICATION TO FPGA FIFO
26
- packet.push 0x50
27
-
28
- #Write mode
29
- packet.push 0xEF
30
-
31
- packet.push ((val & 0x00000000000000FF) >> 0)
32
- packet.push ((val & 0x000000000000FF00) >> 8 )
33
- packet.push ((val & 0x0000000000FF0000) >> 16 )
34
- packet.push ((val & 0x00000000FF000000) >> 24 )
35
- packet.push ((val & 0x000000FF00000000) >> 32 )
36
- packet.push ((val & 0x0000FF0000000000) >> 40 )
37
- packet.push ((val & 0x00FF000000000000) >> 48 )
38
- packet.push ((val & 0xFF00000000000000) >> 56 )
39
-
40
- sendPacket packet
41
-
42
- tmp= receiveDATA(1000)
43
- case tmp
44
- when HardsploitAPI::USB_STATE::BUSY
45
- return USB_STATE::BUSY
46
- when HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
47
- return USB_STATE::TIMEOUT_RECEIVE
48
- else
49
- #remove header (4 bytes 2 for size 2 for type of command)
50
- tmp = tmp.bytes.drop(4)
51
-
52
- return 0 | (tmp[0] << 0) | (tmp[1] << 8) | (tmp[2] << 16) | (tmp[3] << 24) | (tmp[4] << 32) | (tmp[5] << 40) | (tmp[6] << 48) | (tmp[7] << 56)
53
- end
54
- end
55
-
56
- # Read value of 64 IO for testing purpose
57
- #
58
- # return [Integer] 64bits
59
-
60
- def test_InteractRead
61
- packet = Array.new
62
- packet.push 0 #low byte of lenght of trame refresh automaticly before send by usb
63
- packet.push 0 #high byte of lenght of trame refresh automaticly before send by usb
64
- packet.push HardsploitAPI.lowByte(USB_COMMAND::FPGA_COMMAND)
65
- packet.push HardsploitAPI.highByte(USB_COMMAND::FPGA_COMMAND)
66
-
67
- ##packet.push 0x50 #Command RAW COMMUNICATION TO FPGA FIFO
68
- packet.push 0x50
69
-
70
- #Read mode
71
- packet.push 0xCD
72
-
73
- packet.push 0xA1
74
- packet.push 0xA2
75
- packet.push 0xA3
76
- packet.push 0xA4
77
- packet.push 0xA5
78
- packet.push 0xA6
79
- packet.push 0xA7
80
- packet.push 0xA8
81
-
82
-
83
- sendPacket packet
84
-
85
- tmp= receiveDATA(1000)
86
- case tmp
87
- when HardsploitAPI::USB_STATE::BUSY
88
- return USB_STATE::BUSY
89
- when HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
90
- puts "TIMEOUT"
91
- # raise "test_InteractRead Timeout"
92
- else
93
- #remove header (4 bytes 2 for size 2 for type of command)
94
- tmp = tmp.bytes.drop(4)
95
- return 0 | (tmp[0] << 0) | (tmp[1] << 8) | (tmp[2] << 16) | (tmp[3] << 24) | (tmp[4] << 32) | (tmp[5] << 40) | (tmp[6] << 48) | (tmp[7] << 56)
96
- end
97
- end
98
- end
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_TEST
10
+ public
11
+ # Write value of 64 IO for testing purpose
12
+ # * +value+:: 64bits to write on all ports
13
+ # return [Integer] Return the value sent (lookback) (64bits)
14
+
15
+ def test_InteractWrite(*args)
16
+ parametters = HardsploitAPI.checkParametters(["value"],args)
17
+ val = parametters[:value]
18
+
19
+ packet = Array.new
20
+ packet.push 0 #low byte of lenght of trame refresh automaticly before send by usb
21
+ packet.push 0 #high byte of lenght of trame refresh automaticly before send by usb
22
+ packet.push HardsploitAPI.lowByte(USB_COMMAND::FPGA_COMMAND)
23
+ packet.push HardsploitAPI.highByte(USB_COMMAND::FPGA_COMMAND)
24
+
25
+ #Command RAW COMMUNICATION TO FPGA FIFO
26
+ packet.push 0x50
27
+
28
+ #Write mode
29
+ packet.push 0xEF
30
+
31
+ packet.push ((val & 0x00000000000000FF) >> 0)
32
+ packet.push ((val & 0x000000000000FF00) >> 8 )
33
+ packet.push ((val & 0x0000000000FF0000) >> 16 )
34
+ packet.push ((val & 0x00000000FF000000) >> 24 )
35
+ packet.push ((val & 0x000000FF00000000) >> 32 )
36
+ packet.push ((val & 0x0000FF0000000000) >> 40 )
37
+ packet.push ((val & 0x00FF000000000000) >> 48 )
38
+ packet.push ((val & 0xFF00000000000000) >> 56 )
39
+
40
+ sendPacket packet
41
+
42
+ tmp= receiveDATA(1000)
43
+ case tmp
44
+ when HardsploitAPI::USB_STATE::BUSY
45
+ return USB_STATE::BUSY
46
+ when HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
47
+ return USB_STATE::TIMEOUT_RECEIVE
48
+ else
49
+ #remove header (4 bytes 2 for size 2 for type of command)
50
+ tmp = tmp.bytes.drop(4)
51
+
52
+ return 0 | (tmp[0] << 0) | (tmp[1] << 8) | (tmp[2] << 16) | (tmp[3] << 24) | (tmp[4] << 32) | (tmp[5] << 40) | (tmp[6] << 48) | (tmp[7] << 56)
53
+ end
54
+ end
55
+
56
+ # Read value of 64 IO for testing purpose
57
+ #
58
+ # return [Integer] 64bits
59
+
60
+ def test_InteractRead
61
+ packet = Array.new
62
+ packet.push 0 #low byte of lenght of trame refresh automaticly before send by usb
63
+ packet.push 0 #high byte of lenght of trame refresh automaticly before send by usb
64
+ packet.push HardsploitAPI.lowByte(USB_COMMAND::FPGA_COMMAND)
65
+ packet.push HardsploitAPI.highByte(USB_COMMAND::FPGA_COMMAND)
66
+
67
+ ##packet.push 0x50 #Command RAW COMMUNICATION TO FPGA FIFO
68
+ packet.push 0x50
69
+
70
+ #Read mode
71
+ packet.push 0xCD
72
+
73
+ packet.push 0xA1
74
+ packet.push 0xA2
75
+ packet.push 0xA3
76
+ packet.push 0xA4
77
+ packet.push 0xA5
78
+ packet.push 0xA6
79
+ packet.push 0xA7
80
+ packet.push 0xA8
81
+
82
+
83
+ sendPacket packet
84
+
85
+ tmp= receiveDATA(1000)
86
+ case tmp
87
+ when HardsploitAPI::USB_STATE::BUSY
88
+ return USB_STATE::BUSY
89
+ when HardsploitAPI::USB_STATE::TIMEOUT_RECEIVE
90
+ puts "TIMEOUT"
91
+ # raise "test_InteractRead Timeout"
92
+ else
93
+ #remove header (4 bytes 2 for size 2 for type of command)
94
+ tmp = tmp.bytes.drop(4)
95
+ return 0 | (tmp[0] << 0) | (tmp[1] << 8) | (tmp[2] << 16) | (tmp[3] << 24) | (tmp[4] << 32) | (tmp[5] << 40) | (tmp[6] << 48) | (tmp[7] << 56)
96
+ end
97
+ end
98
+ end
@@ -1,196 +1,196 @@
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_relative '../../Core/HardsploitAPI'
10
- class HardsploitAPI_UART
11
- public
12
- def initialize(baud_rate:,word_width:,use_parity_bit:,parity_type:,nb_stop_bits:,idle_line_level:)
13
- #to be sure the singleton was initialize
14
- HardsploitAPI.instance
15
- self.baud_rate = baud_rate
16
- self.word_width = word_width
17
- self.use_parity_bit = use_parity_bit
18
- self.parity_type = parity_type
19
- self.nb_stop_bits = nb_stop_bits
20
- self.idle_line_level = idle_line_level
21
- setSettings
22
-
23
- @payload_TX = Array.new
24
- end
25
-
26
- def baud_rate
27
- return 150000000 / @baud_rate
28
- end
29
-
30
- def baud_rate=(baud_rate)
31
- if (baud_rate >= 2400) and (baud_rate <= 1036800) then
32
- @baud_rate = 150000000 / baud_rate
33
- else
34
- raise HardsploitAPI::ERROR::UART_WrongSettings
35
- end
36
- end
37
-
38
- def word_width
39
- return @word_width
40
- end
41
-
42
- def word_width=(word_width)
43
- if (word_width >= 5) and (word_width <= 8) then
44
- @word_width = word_width
45
- else
46
- raise HardsploitAPI::ERROR::UART_WrongSettings
47
- end
48
- end
49
-
50
- def use_parity_bit
51
- return @use_parity_bit
52
- end
53
-
54
- def use_parity_bit=(use_parity_bit)
55
- if (use_parity_bit >= 0) and (use_parity_bit <= 1) then
56
- @use_parity_bit = use_parity_bit
57
- else
58
- raise HardsploitAPI::ERROR::UART_WrongSettings
59
- end
60
- end
61
-
62
- def parity_type
63
- return @parity_type
64
- end
65
-
66
- def parity_type=(parity_type)
67
- if (parity_type >= 0) and (parity_type <= 1) then
68
- @parity_type = parity_type
69
- else
70
- raise HardsploitAPI::ERROR::UART_WrongSettings
71
- end
72
- end
73
-
74
- def nb_stop_bits
75
- return @nb_stop_bits
76
- end
77
-
78
- def nb_stop_bits=(nb_stop_bits)
79
- if (nb_stop_bits >= 1) and (nb_stop_bits <= 2) then
80
- @nb_stop_bits = nb_stop_bits
81
- else
82
- raise HardsploitAPI::ERROR::UART_WrongSettings
83
- end
84
- end
85
-
86
- def idle_line_level
87
- return @idle_line_level
88
- end
89
-
90
- def idle_line_level=(idle_line_level)
91
- if (idle_line_level >= 0) and (idle_line_level <= 1) then
92
- @idle_line_level = idle_line_level
93
- else
94
- raise HardsploitAPI::ERROR::UART_WrongSettings
95
- end
96
- end
97
-
98
- # write
99
- # * +payload+:: Byte array want to send
100
- # * Return nothing
101
- def write(payload:)
102
- if ( (@payload_TX.size + payload.size) > 4000) then
103
- raise HardsploitAPI::ERROR::UART_WrongTxPayloadSize
104
- end
105
- @payload_TX.concat payload #Add data
106
- end
107
-
108
- # sendAndReceived ( send and receive)
109
- # First write data if needed and refresh (data are sent and reveived data if needed) and you obtain available data
110
- # * Return nothing
111
- def sendAndReceived
112
- packet = HardsploitAPI.prepare_packet
113
- packet.push 0x20 #Send command
114
- packet.concat @payload_TX
115
-
116
- begin
117
- tmp = HardsploitAPI.instance.sendAndReceiveDATA(packet,1000)
118
- rescue
119
- raise HardsploitAPI::ERROR::USB_ERROR
120
- end
121
-
122
- @payload_TX.clear
123
- #remove header (4 bytes 2 for size 2 for type of command 1 dummy byte)
124
- return tmp.drop(5)
125
- end
126
-
127
- # enableMeasureBaudRate
128
- #
129
- # *
130
- def enableMeasureBaudRate
131
- packet = HardsploitAPI.prepare_packet
132
- packet.push 0x41 # command
133
- begin
134
- tmp = HardsploitAPI.instance.sendAndReceiveDATA(packet,1000)
135
- rescue
136
- raise HardsploitAPI::ERROR::USB_ERROR
137
- end
138
- end
139
-
140
- # disableMeasureBaudRate
141
- #
142
- # *
143
- def disableMeasureBaudRate
144
- packet = HardsploitAPI.prepare_packet
145
- packet.push 0x40 # command
146
- begin
147
- tmp = HardsploitAPI.instance.sendAndReceiveDATA(packet,1000)
148
- rescue
149
- raise HardsploitAPI::ERROR::USB_ERROR
150
- end
151
- end
152
-
153
- # measureBaudRate
154
- #
155
- # * Return 32 bits period
156
- def measureBaudRate
157
- packet = HardsploitAPI.prepare_packet
158
- packet.push 0x30 # command
159
-
160
- begin
161
- tmp = HardsploitAPI.instance.sendAndReceiveDATA(packet,1000)
162
- rescue
163
- raise HardsploitAPI::ERROR::USB_ERROR
164
- end
165
- #remove header (4 bytes 2 for size 2 for type of command)
166
- tmp = tmp.drop(4)
167
- period = tmp[0] + (tmp[1] << 8 ) + (tmp[2] << 16 ) + (tmp[3] << 24 )
168
- period = period * 33.33*(10**-9) #s
169
- if period > 0 then
170
- return (1 / period).to_i
171
- else
172
- return 0
173
- end
174
- end
175
-
176
- # settings
177
- # * Return nothing
178
- def setSettings
179
- packet = HardsploitAPI.prepare_packet
180
- packet.push 0x00 #Settings command
181
- packet.push ((@parity_type & 0b1) << 7) || ((@use_parity_bit & 0b1) << 6) || ((@nb_stop_bits & 0b11) << 4) || (@word_width & 0b1111)
182
- packet.push @idle_line_level & 1
183
- packet.push HardsploitAPI.lowByte(word: @baud_rate)
184
- packet.push HardsploitAPI.highByte(word: @baud_rate)
185
-
186
- begin
187
- HardsploitAPI.instance.sendPacket packet
188
- sleep(1)
189
- # tmp= HardsploitAPI.instance.receiveDATA(1000)
190
- #remove header (4 bytes 2 for size 2 for type of command)
191
- # return tmp.bytes.drop(4)
192
- rescue
193
- raise HardsploitAPI::ERROR::USB_ERROR
194
- end
195
- end
196
- end
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_relative '../../Core/HardsploitAPI'
10
+ class HardsploitAPI_UART
11
+ public
12
+ def initialize(baud_rate:,word_width:,use_parity_bit:,parity_type:,nb_stop_bits:,idle_line_level:)
13
+ #to be sure the singleton was initialize
14
+ HardsploitAPI.instance
15
+ self.baud_rate = baud_rate
16
+ self.word_width = word_width
17
+ self.use_parity_bit = use_parity_bit
18
+ self.parity_type = parity_type
19
+ self.nb_stop_bits = nb_stop_bits
20
+ self.idle_line_level = idle_line_level
21
+ setSettings
22
+
23
+ @payload_TX = Array.new
24
+ end
25
+
26
+ def baud_rate
27
+ return 150000000 / @baud_rate
28
+ end
29
+
30
+ def baud_rate=(baud_rate)
31
+ if (baud_rate >= 2400) and (baud_rate <= 1036800) then
32
+ @baud_rate = 150000000 / baud_rate
33
+ else
34
+ raise HardsploitAPI::ERROR::UART_WrongSettings
35
+ end
36
+ end
37
+
38
+ def word_width
39
+ return @word_width
40
+ end
41
+
42
+ def word_width=(word_width)
43
+ if (word_width >= 5) and (word_width <= 8) then
44
+ @word_width = word_width
45
+ else
46
+ raise HardsploitAPI::ERROR::UART_WrongSettings
47
+ end
48
+ end
49
+
50
+ def use_parity_bit
51
+ return @use_parity_bit
52
+ end
53
+
54
+ def use_parity_bit=(use_parity_bit)
55
+ if (use_parity_bit >= 0) and (use_parity_bit <= 1) then
56
+ @use_parity_bit = use_parity_bit
57
+ else
58
+ raise HardsploitAPI::ERROR::UART_WrongSettings
59
+ end
60
+ end
61
+
62
+ def parity_type
63
+ return @parity_type
64
+ end
65
+
66
+ def parity_type=(parity_type)
67
+ if (parity_type >= 0) and (parity_type <= 1) then
68
+ @parity_type = parity_type
69
+ else
70
+ raise HardsploitAPI::ERROR::UART_WrongSettings
71
+ end
72
+ end
73
+
74
+ def nb_stop_bits
75
+ return @nb_stop_bits
76
+ end
77
+
78
+ def nb_stop_bits=(nb_stop_bits)
79
+ if (nb_stop_bits >= 1) and (nb_stop_bits <= 2) then
80
+ @nb_stop_bits = nb_stop_bits
81
+ else
82
+ raise HardsploitAPI::ERROR::UART_WrongSettings
83
+ end
84
+ end
85
+
86
+ def idle_line_level
87
+ return @idle_line_level
88
+ end
89
+
90
+ def idle_line_level=(idle_line_level)
91
+ if (idle_line_level >= 0) and (idle_line_level <= 1) then
92
+ @idle_line_level = idle_line_level
93
+ else
94
+ raise HardsploitAPI::ERROR::UART_WrongSettings
95
+ end
96
+ end
97
+
98
+ # write
99
+ # * +payload+:: Byte array want to send
100
+ # * Return nothing
101
+ def write(payload:)
102
+ if ( (@payload_TX.size + payload.size) > 4000) then
103
+ raise HardsploitAPI::ERROR::UART_WrongTxPayloadSize
104
+ end
105
+ @payload_TX.concat payload #Add data
106
+ end
107
+
108
+ # sendAndReceived ( send and receive)
109
+ # First write data if needed and refresh (data are sent and reveived data if needed) and you obtain available data
110
+ # * Return nothing
111
+ def sendAndReceived
112
+ packet = HardsploitAPI.prepare_packet
113
+ packet.push 0x20 #Send command
114
+ packet.concat @payload_TX
115
+
116
+ begin
117
+ tmp = HardsploitAPI.instance.sendAndReceiveDATA(packet,1000)
118
+ rescue
119
+ raise HardsploitAPI::ERROR::USB_ERROR
120
+ end
121
+
122
+ @payload_TX.clear
123
+ #remove header (4 bytes 2 for size 2 for type of command 1 dummy byte)
124
+ return tmp.drop(5)
125
+ end
126
+
127
+ # enableMeasureBaudRate
128
+ #
129
+ # *
130
+ def enableMeasureBaudRate
131
+ packet = HardsploitAPI.prepare_packet
132
+ packet.push 0x41 # command
133
+ begin
134
+ tmp = HardsploitAPI.instance.sendAndReceiveDATA(packet,1000)
135
+ rescue
136
+ raise HardsploitAPI::ERROR::USB_ERROR
137
+ end
138
+ end
139
+
140
+ # disableMeasureBaudRate
141
+ #
142
+ # *
143
+ def disableMeasureBaudRate
144
+ packet = HardsploitAPI.prepare_packet
145
+ packet.push 0x40 # command
146
+ begin
147
+ tmp = HardsploitAPI.instance.sendAndReceiveDATA(packet,1000)
148
+ rescue
149
+ raise HardsploitAPI::ERROR::USB_ERROR
150
+ end
151
+ end
152
+
153
+ # measureBaudRate
154
+ #
155
+ # * Return 32 bits period
156
+ def measureBaudRate
157
+ packet = HardsploitAPI.prepare_packet
158
+ packet.push 0x30 # command
159
+
160
+ begin
161
+ tmp = HardsploitAPI.instance.sendAndReceiveDATA(packet,1000)
162
+ rescue
163
+ raise HardsploitAPI::ERROR::USB_ERROR
164
+ end
165
+ #remove header (4 bytes 2 for size 2 for type of command)
166
+ tmp = tmp.drop(4)
167
+ period = tmp[0] + (tmp[1] << 8 ) + (tmp[2] << 16 ) + (tmp[3] << 24 )
168
+ period = period * 33.33*(10**-9) #s
169
+ if period > 0 then
170
+ return (1 / period).to_i
171
+ else
172
+ return 0
173
+ end
174
+ end
175
+
176
+ # settings
177
+ # * Return nothing
178
+ def setSettings
179
+ packet = HardsploitAPI.prepare_packet
180
+ packet.push 0x00 #Settings command
181
+ packet.push ((@parity_type & 0b1) << 7) || ((@use_parity_bit & 0b1) << 6) || ((@nb_stop_bits & 0b11) << 4) || (@word_width & 0b1111)
182
+ packet.push @idle_line_level & 1
183
+ packet.push HardsploitAPI.lowByte(word: @baud_rate)
184
+ packet.push HardsploitAPI.highByte(word: @baud_rate)
185
+
186
+ begin
187
+ HardsploitAPI.instance.sendPacket packet
188
+ sleep(1)
189
+ # tmp= HardsploitAPI.instance.receiveDATA(1000)
190
+ #remove header (4 bytes 2 for size 2 for type of command)
191
+ # return tmp.bytes.drop(4)
192
+ rescue
193
+ raise HardsploitAPI::ERROR::USB_ERROR
194
+ end
195
+ end
196
+ end