hardsploit_gui 2.3 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
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,230 +1,230 @@
1
- #===================================================
2
- # Hardsploit GUI - By Opale Security
3
- # www.opale-security.com || www.hardsploit.io
4
- # License: GNU General Public License v3
5
- # License URI: http://www.gnu.org/licenses/gpl.txt
6
- #===================================================
7
-
8
- require_relative '../gui/gui_wire_helper'
9
- require_relative '../HardsploitAPI/Core/HardsploitAPI'
10
-
11
- class Wire_helper < Qt::Widget
12
- slots 'rotate_scene()'
13
-
14
- def initialize(chip)
15
- super()
16
- @wire_helper_gui = Ui_Wire_helper.new
17
- centerWindow(self)
18
- @wire_helper_gui.setupUi(self)
19
- @chip = chip
20
- HardsploitAPI.instance.setWiringLeds(value: 0x0000000000000000)
21
- @scene = Qt::GraphicsScene.new
22
- @wire_helper_gui.lbl_chip.setText("Your chip (#{chip.reference}):")
23
- Package.find_by(id: chip.package_id).shape.zero? ? draw_square : draw_rect
24
- @wire_helper_gui.gView.setScene(@scene)
25
- rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
26
- ErrorMsg.new.hardsploit_not_found
27
- rescue HardsploitAPI::ERROR::USB_ERROR
28
- ErrorMsg.new.usb_error
29
- rescue Exception => msg
30
- ErrorMsg.new.unknown(msg)
31
- end
32
-
33
- def closeEvent(event)
34
- HardsploitAPI.instance.setWiringLeds(value: 0xFF00FF00FF00FF00)
35
- rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
36
- ErrorMsg.new.hardsploit_not_found
37
- rescue HardsploitAPI::ERROR::USB_ERROR
38
- ErrorMsg.new.usb_error
39
- rescue Exception => msg
40
- ErrorMsg.new.unknown(msg)
41
- end
42
-
43
- def rotate_scene
44
- @wire_helper_gui.gView.rotate(90)
45
- end
46
- end
47
-
48
- def draw_square
49
- total_pin_nbr = Pin.where(chip_id: @chip.id).count
50
- pin_by_side = total_pin_nbr / 4
51
- cHeight = 14*(pin_by_side + 4) # Chip's height (+4 because we add a space equal to one pin for each corner)
52
- @scene.addRect(Qt::RectF.new(0, 0, cHeight, cHeight))
53
- y = 32
54
- y2 = cHeight - 38
55
- x = 32
56
- x2 = cHeight - 38
57
- (1..total_pin_nbr).each do |i|
58
- # Face 1
59
- if i <= pin_by_side
60
- ySig = y
61
- yNum = y
62
- UniqPin.new(@scene, i, @chip.id, -70, ySig - 12, 0, yNum - 12, 0, y, -20, 6, false)
63
- y = y + 14 # Space between each pin
64
- elsif i > pin_by_side && i <= total_pin_nbr / 2
65
- # Face 2
66
- xSig2 = x
67
- xNum2 = x
68
- UniqPin.new(@scene, i, @chip.id, xSig2 - 12, cHeight + 55, xNum2 - 12, cHeight, x, cHeight, 6, 20, true)
69
- x = x + 14
70
- elsif i > total_pin_nbr / 2 && i <= (total_pin_nbr - (pin_by_side))
71
- # Face 3
72
- xSig = cHeight + 24
73
- ySig = y2
74
- yNum = y2
75
-
76
- if i < 10
77
- xNum = cHeight - 20
78
- elsif i >= 10 && i < 100
79
- xNum = cHeight - 25
80
- else
81
- xNum = cHeight - 35
82
- end
83
- UniqPin.new(@scene, i, @chip.id, xSig, ySig - 12, xNum, yNum - 12, cHeight, y2, 20, 6, false)
84
- y2 = y2 - 14
85
- else
86
- # Face 4
87
- xSig2 = x2
88
- xNum2 = x2
89
-
90
- if i < 10
91
- yNum2 = 20
92
- elsif i >= 10 && i < 100
93
- yNum2 = 30
94
- else
95
- yNum2 = 40
96
- end
97
- UniqPin.new(@scene, i, @chip.id, xSig2 - 12, -20, xNum2 - 12, yNum2, x2, 0, 6, -20, true)
98
- x2 = x2 - 14
99
- end
100
- end
101
- end
102
-
103
- def draw_rect
104
- total_pin_nbr = Pin.where(chip_id: @chip.id).count
105
- pin_by_side = total_pin_nbr / 2
106
- cHeight = 14 * (pin_by_side + 2) # +2 because we add a space equal to one pin for each corner
107
- @scene.addRect(Qt::RectF.new(0, 0, cHeight, cHeight))
108
- # Add the pins + text
109
- y = 18
110
- y2 = cHeight - 24
111
- (1..total_pin_nbr).each do |i|
112
- # Face 1
113
- if i <= total_pin_nbr / 2
114
- ySig = y
115
- yNum = y
116
- UniqPin.new(@scene, i, @chip.id, -70, ySig - 12, 0, yNum - 12, 0, y, -20, 6, false)
117
- y = y + 14
118
- # Face 2
119
- else
120
- xSig = cHeight + 24
121
- ySig = y2
122
- yNum = y2
123
-
124
- if i < 10
125
- xNum = cHeight - 20
126
- elsif i >= 10 && i < 100
127
- xNum = cHeight - 25
128
- else
129
- xNum = cHeight - 35
130
- end
131
- UniqPin.new(@scene, i, @chip.id, xSig, ySig - 12, xNum, yNum - 12, cHeight, y2, 20, 6, false)
132
- y2 = y2 - 14
133
- end
134
- end
135
- end
136
-
137
-
138
- #
139
- # Custom Item - To trigger events on the graphics text items
140
- #
141
- class CustomItem < Qt::GraphicsTextItem
142
-
143
- def setPin(upin, api_value)
144
- @UPin = upin
145
- @api_value = api_value
146
- end
147
-
148
- def boundingRect
149
- rect = Qt::RectF.new
150
- rect.setHeight(20)
151
- rect.setWidth(65)
152
- rect.setTop(5)
153
- return rect
154
- end
155
-
156
- def mousePressEvent(event)
157
- pin = self.instance_variable_get('@UPin')
158
- pin.setColor
159
- pin.instance_variable_get('@signalTxt').clearFocus
160
- pin.instance_variable_get('@nbrTxt').clearFocus
161
- return false if @api_value == 'NA'
162
- pin_group = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
163
- hardsploit_pin_number = pin_group.index(@api_value.pin[0]) * 8 + @api_value.pin[1].to_i
164
- HardsploitAPI.instance.setWiringLeds(value: 2**hardsploit_pin_number)
165
- rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
166
- ErrorMsg.new.hardsploit_not_found
167
- rescue HardsploitAPI::ERROR::USB_ERROR
168
- ErrorMsg.new.usb_error
169
- rescue Exception => msg
170
- HardsploitAPI.instance.setWiringLeds(value: 0x0000000000000000)
171
- pin.instance_variable_get('@signalTxt').clearFocus
172
- pin.instance_variable_get('@nbrTxt').clearFocus
173
- end
174
-
175
- def mouseDoubleClickEvent(event)
176
- pin = self.instance_variable_get('@UPin')
177
- pin.instance_variable_get('@signalTxt').clearFocus
178
- pin.instance_variable_get('@nbrTxt').clearFocus
179
- end
180
- end
181
-
182
- #
183
- # UniqPin - Contain all data linked to one pin on the graphic
184
- #
185
- class UniqPin
186
- def initialize(scene, pinNum, pinChip, xSig, ySig, xNum, yNum, xRect, yRect, wRect, hRect, rotation)
187
- signal_name = Pin.find_by(number: pinNum, chip_id: pinChip).signall
188
- @signalTxt = CustomItem.new(signal_name.name)
189
- @signalTxt.cursor = Qt::Cursor.new(Qt::PointingHandCursor)
190
- @signalTxt.setPin(self, signal_name)
191
- @signalTxt.setTextInteractionFlags(Qt::TextSelectableByMouse)
192
- @signalTxt.setX(xSig)
193
- @signalTxt.setY(ySig)
194
- @signalTxt.rotation = 270.00 if rotation
195
- scene.addItem(@signalTxt)
196
-
197
- @nbrTxt = CustomItem.new(pinNum.to_s)
198
- @nbrTxt.cursor = Qt::Cursor.new(Qt::PointingHandCursor)
199
- @nbrTxt.setPin(self, pinNum.to_s)
200
- @nbrTxt.setTextInteractionFlags(Qt::TextSelectableByMouse)
201
- @nbrTxt.setX(xNum)
202
- @nbrTxt.setY(yNum)
203
- @nbrTxt.rotation = 270.00 if rotation
204
- scene.addItem(@nbrTxt)
205
- @pinGraphItem = scene.addRect(xRect, yRect, wRect, hRect)
206
- end
207
-
208
- def setColor
209
- # Colors
210
- @on = Qt::Color.new(0, 0, 255)
211
- @off = Qt::Color.new(0, 0, 0)
212
- # Disable the pin if another pin is already enabled
213
- $pinEnabled.unsetColor unless $pinEnabled.nil?
214
- # Light the new pin
215
- @nbrTxt.setDefaultTextColor(@on)
216
- @signalTxt.setDefaultTextColor(@on)
217
- @bold = Qt::Font.new
218
- @bold.setBold(true)
219
- @signalTxt.setFont(@bold)
220
- $pinEnabled = self
221
- end
222
-
223
- def unsetColor
224
- @nbrTxt.setDefaultTextColor(@off)
225
- @signalTxt.setDefaultTextColor(@off)
226
- @bold.setBold(false)
227
- @signalTxt.setFont(@bold)
228
- end
229
-
230
- end
1
+ #===================================================
2
+ # Hardsploit GUI - By Opale Security
3
+ # www.opale-security.com || www.hardsploit.io
4
+ # License: GNU General Public License v3
5
+ # License URI: http://www.gnu.org/licenses/gpl.txt
6
+ #===================================================
7
+
8
+ require_relative '../gui/gui_wire_helper'
9
+ require_relative '../HardsploitAPI/Core/HardsploitAPI'
10
+
11
+ class Wire_helper < Qt::Widget
12
+ slots 'rotate_scene()'
13
+
14
+ def initialize(chip)
15
+ super()
16
+ @wire_helper_gui = Ui_Wire_helper.new
17
+ centerWindow(self)
18
+ @wire_helper_gui.setupUi(self)
19
+ @chip = chip
20
+ HardsploitAPI.instance.setWiringLeds(value: 0x0000000000000000)
21
+ @scene = Qt::GraphicsScene.new
22
+ @wire_helper_gui.lbl_chip.setText("Your chip (#{chip.reference}):")
23
+ Package.find_by(id: chip.package_id).shape.zero? ? draw_square : draw_rect
24
+ @wire_helper_gui.gView.setScene(@scene)
25
+ rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
26
+ ErrorMsg.new.hardsploit_not_found
27
+ rescue HardsploitAPI::ERROR::USB_ERROR
28
+ ErrorMsg.new.usb_error
29
+ rescue Exception => msg
30
+ ErrorMsg.new.unknown(msg)
31
+ end
32
+
33
+ def closeEvent(event)
34
+ HardsploitAPI.instance.setWiringLeds(value: 0xFF00FF00FF00FF00)
35
+ rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
36
+ ErrorMsg.new.hardsploit_not_found
37
+ rescue HardsploitAPI::ERROR::USB_ERROR
38
+ ErrorMsg.new.usb_error
39
+ rescue Exception => msg
40
+ ErrorMsg.new.unknown(msg)
41
+ end
42
+
43
+ def rotate_scene
44
+ @wire_helper_gui.gView.rotate(90)
45
+ end
46
+ end
47
+
48
+ def draw_square
49
+ total_pin_nbr = Pin.where(chip_id: @chip.id).count
50
+ pin_by_side = total_pin_nbr / 4
51
+ cHeight = 14*(pin_by_side + 4) # Chip's height (+4 because we add a space equal to one pin for each corner)
52
+ @scene.addRect(Qt::RectF.new(0, 0, cHeight, cHeight))
53
+ y = 32
54
+ y2 = cHeight - 38
55
+ x = 32
56
+ x2 = cHeight - 38
57
+ (1..total_pin_nbr).each do |i|
58
+ # Face 1
59
+ if i <= pin_by_side
60
+ ySig = y
61
+ yNum = y
62
+ UniqPin.new(@scene, i, @chip.id, -70, ySig - 12, 0, yNum - 12, 0, y, -20, 6, false)
63
+ y = y + 14 # Space between each pin
64
+ elsif i > pin_by_side && i <= total_pin_nbr / 2
65
+ # Face 2
66
+ xSig2 = x
67
+ xNum2 = x
68
+ UniqPin.new(@scene, i, @chip.id, xSig2 - 12, cHeight + 55, xNum2 - 12, cHeight, x, cHeight, 6, 20, true)
69
+ x = x + 14
70
+ elsif i > total_pin_nbr / 2 && i <= (total_pin_nbr - (pin_by_side))
71
+ # Face 3
72
+ xSig = cHeight + 24
73
+ ySig = y2
74
+ yNum = y2
75
+
76
+ if i < 10
77
+ xNum = cHeight - 20
78
+ elsif i >= 10 && i < 100
79
+ xNum = cHeight - 25
80
+ else
81
+ xNum = cHeight - 35
82
+ end
83
+ UniqPin.new(@scene, i, @chip.id, xSig, ySig - 12, xNum, yNum - 12, cHeight, y2, 20, 6, false)
84
+ y2 = y2 - 14
85
+ else
86
+ # Face 4
87
+ xSig2 = x2
88
+ xNum2 = x2
89
+
90
+ if i < 10
91
+ yNum2 = 20
92
+ elsif i >= 10 && i < 100
93
+ yNum2 = 30
94
+ else
95
+ yNum2 = 40
96
+ end
97
+ UniqPin.new(@scene, i, @chip.id, xSig2 - 12, -20, xNum2 - 12, yNum2, x2, 0, 6, -20, true)
98
+ x2 = x2 - 14
99
+ end
100
+ end
101
+ end
102
+
103
+ def draw_rect
104
+ total_pin_nbr = Pin.where(chip_id: @chip.id).count
105
+ pin_by_side = total_pin_nbr / 2
106
+ cHeight = 14 * (pin_by_side + 2) # +2 because we add a space equal to one pin for each corner
107
+ @scene.addRect(Qt::RectF.new(0, 0, cHeight, cHeight))
108
+ # Add the pins + text
109
+ y = 18
110
+ y2 = cHeight - 24
111
+ (1..total_pin_nbr).each do |i|
112
+ # Face 1
113
+ if i <= total_pin_nbr / 2
114
+ ySig = y
115
+ yNum = y
116
+ UniqPin.new(@scene, i, @chip.id, -70, ySig - 12, 0, yNum - 12, 0, y, -20, 6, false)
117
+ y = y + 14
118
+ # Face 2
119
+ else
120
+ xSig = cHeight + 24
121
+ ySig = y2
122
+ yNum = y2
123
+
124
+ if i < 10
125
+ xNum = cHeight - 20
126
+ elsif i >= 10 && i < 100
127
+ xNum = cHeight - 25
128
+ else
129
+ xNum = cHeight - 35
130
+ end
131
+ UniqPin.new(@scene, i, @chip.id, xSig, ySig - 12, xNum, yNum - 12, cHeight, y2, 20, 6, false)
132
+ y2 = y2 - 14
133
+ end
134
+ end
135
+ end
136
+
137
+
138
+ #
139
+ # Custom Item - To trigger events on the graphics text items
140
+ #
141
+ class CustomItem < Qt::GraphicsTextItem
142
+
143
+ def setPin(upin, api_value)
144
+ @UPin = upin
145
+ @api_value = api_value
146
+ end
147
+
148
+ def boundingRect
149
+ rect = Qt::RectF.new
150
+ rect.setHeight(20)
151
+ rect.setWidth(65)
152
+ rect.setTop(5)
153
+ return rect
154
+ end
155
+
156
+ def mousePressEvent(event)
157
+ pin = self.instance_variable_get('@UPin')
158
+ pin.setColor
159
+ pin.instance_variable_get('@signalTxt').clearFocus
160
+ pin.instance_variable_get('@nbrTxt').clearFocus
161
+ return false if @api_value == 'NA'
162
+ pin_group = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
163
+ hardsploit_pin_number = pin_group.index(@api_value.pin[0]) * 8 + @api_value.pin[1].to_i
164
+ HardsploitAPI.instance.setWiringLeds(value: 2**hardsploit_pin_number)
165
+ rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
166
+ ErrorMsg.new.hardsploit_not_found
167
+ rescue HardsploitAPI::ERROR::USB_ERROR
168
+ ErrorMsg.new.usb_error
169
+ rescue Exception => msg
170
+ HardsploitAPI.instance.setWiringLeds(value: 0x0000000000000000)
171
+ pin.instance_variable_get('@signalTxt').clearFocus
172
+ pin.instance_variable_get('@nbrTxt').clearFocus
173
+ end
174
+
175
+ def mouseDoubleClickEvent(event)
176
+ pin = self.instance_variable_get('@UPin')
177
+ pin.instance_variable_get('@signalTxt').clearFocus
178
+ pin.instance_variable_get('@nbrTxt').clearFocus
179
+ end
180
+ end
181
+
182
+ #
183
+ # UniqPin - Contain all data linked to one pin on the graphic
184
+ #
185
+ class UniqPin
186
+ def initialize(scene, pinNum, pinChip, xSig, ySig, xNum, yNum, xRect, yRect, wRect, hRect, rotation)
187
+ signal_name = Pin.find_by(number: pinNum, chip_id: pinChip).signall
188
+ @signalTxt = CustomItem.new(signal_name.name)
189
+ @signalTxt.cursor = Qt::Cursor.new(Qt::PointingHandCursor)
190
+ @signalTxt.setPin(self, signal_name)
191
+ @signalTxt.setTextInteractionFlags(Qt::TextSelectableByMouse)
192
+ @signalTxt.setX(xSig)
193
+ @signalTxt.setY(ySig)
194
+ @signalTxt.rotation = 270.00 if rotation
195
+ scene.addItem(@signalTxt)
196
+
197
+ @nbrTxt = CustomItem.new(pinNum.to_s)
198
+ @nbrTxt.cursor = Qt::Cursor.new(Qt::PointingHandCursor)
199
+ @nbrTxt.setPin(self, pinNum.to_s)
200
+ @nbrTxt.setTextInteractionFlags(Qt::TextSelectableByMouse)
201
+ @nbrTxt.setX(xNum)
202
+ @nbrTxt.setY(yNum)
203
+ @nbrTxt.rotation = 270.00 if rotation
204
+ scene.addItem(@nbrTxt)
205
+ @pinGraphItem = scene.addRect(xRect, yRect, wRect, hRect)
206
+ end
207
+
208
+ def setColor
209
+ # Colors
210
+ @on = Qt::Color.new(0, 0, 255)
211
+ @off = Qt::Color.new(0, 0, 0)
212
+ # Disable the pin if another pin is already enabled
213
+ $pinEnabled.unsetColor unless $pinEnabled.nil?
214
+ # Light the new pin
215
+ @nbrTxt.setDefaultTextColor(@on)
216
+ @signalTxt.setDefaultTextColor(@on)
217
+ @bold = Qt::Font.new
218
+ @bold.setBold(true)
219
+ @signalTxt.setFont(@bold)
220
+ $pinEnabled = self
221
+ end
222
+
223
+ def unsetColor
224
+ @nbrTxt.setDefaultTextColor(@off)
225
+ @signalTxt.setDefaultTextColor(@off)
226
+ @bold.setBold(false)
227
+ @signalTxt.setFont(@bold)
228
+ end
229
+
230
+ end