Class: HardsploitAPI

Inherits:
Object
  • Object
show all
Includes:
ERROR, USB, USB_COMMAND, VERSION, Singleton
Defined in:
lib/HardsploitAPI/Core/HardsploitAPI_ERROR.rb,
lib/HardsploitAPI/Core/HardsploitAPI.rb,
lib/HardsploitAPI/Core/HardsploitAPI_CONSTANT.rb,
lib/HardsploitAPI/Core/HardsploitAPI_FIRMWARE.rb,
lib/HardsploitAPI/Core/HardsploitAPI_PROGRESS.rb,
lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb

Overview

Hardsploit API - By Opale Security
www.opale-security.com || www.hardsploit.io
License: GNU General Public License v3
License URI: http://www.gnu.org/licenses/gpl.txt

Defined Under Namespace

Modules: ERROR, I2C, SPISniffer, USB, USB_COMMAND, VERSION Classes: HardsploitProgress

Constant Summary collapse

@@callbackData =
nil
@@callbackInfo =
nil
@@callbackProgress =
nil
@@callbackSpeedOfTransfert =
nil
@@id =
0
@@crossWiringValue =
Array.new

Constants included from VERSION

VERSION::API

Constants included from USB

USB::IN_ENDPOINT, USB::OUT_ENDPOINT, USB::USB_TRAME_SIZE

Constants included from USB_COMMAND

USB_COMMAND::ERASE_FIRMWARE, USB_COMMAND::FPGA_COMMAND, USB_COMMAND::FPGA_DATA, USB_COMMAND::GET_SERIAL_NUMBER, USB_COMMAND::GET_VERSION_NUMBER, USB_COMMAND::GREEN_LED, USB_COMMAND::LOOPBACK, USB_COMMAND::READ_ID_FLASH, USB_COMMAND::READ_PAGE_FIRMWARE, USB_COMMAND::RED_LED, USB_COMMAND::START_FPGA, USB_COMMAND::START_FPGA_DATA, USB_COMMAND::STOP_FPGA, USB_COMMAND::STOP_FPGA_DATA, USB_COMMAND::VCP_ERROR, USB_COMMAND::WRITE_PAGE_FIRMWARE

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHardsploitAPI

Returns a new instance of HardsploitAPI.



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 75

def initialize
     if @@callbackData == nil or @@callbackInfo == nil or @@callbackProgress == nil or @@callbackSpeedOfTransfert == nil then
       raise "Error you need to specify callbackData callbackInfo callbackProgress callbackSpeedOfTransfert first"
     else
       #Default wiring
       for i in 0..63
       	@@crossWiringValue.push i
       end
       self.connect
       puts "Hardsploit is connected".green.bold
     end
end

Class Method Details

.allPosibility(numberOfConnectedPinFromA0:, numberOfSignalsForBus:) ⇒ Object



175
176
177
178
179
180
181
182
183
184
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 175

def self.allPosibility(numberOfConnectedPinFromA0:,numberOfSignalsForBus:)
    if numberOfConnectedPinFromA0 < numberOfSignalsForBus then
      raise HardsploitAPI::ERROR::API_SCANNER_WRONG_PIN_NUMBER
    end
    a =	  Array.new
    for i in 0..numberOfConnectedPinFromA0-1
      a.push i
    end
   return a.permutation.to_a
end

.BytesToInt(lByte:, hByte:) ⇒ Object

Obtain high byte of a word

  • lByte

    low byte

  • hByte

    high byte

Return 16 bits integer concatenate with low and high bytes



93
94
95
# File 'lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb', line 93

def self.BytesToInt(lByte:,hByte:)
	return (lByte + (hByte<<8))
end

.callbackData=(fn) ⇒ Object



50
51
52
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 50

def self.callbackData= fn
      @@callbackData = fn
end

.callbackInfo=(fn) ⇒ Object



53
54
55
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 53

def self.callbackInfo= fn
      @@callbackInfo = fn
end

.callbackProgress=(fn) ⇒ Object



56
57
58
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 56

def self.callbackProgress= fn
      @@callbackProgress = fn
end

.callbackSpeedOfTransfert=(fn) ⇒ Object



59
60
61
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 59

def self.callbackSpeedOfTransfert= fn
      @@callbackSpeedOfTransfert = fn
end

.crossWiringValueObject



63
64
65
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 63

def self.crossWiringValue
  return @@crossWiringValue
end

.getNumberOfBoardAvailableObject

Obtain the number of hardsploit connected to PC Return number



15
16
17
# File 'lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb', line 15

def self.getNumberOfBoardAvailable
  return LIBUSB::Context.new.devices(:idVendor => 0x0483, :idProduct => 0xFFFF).size
end

.getSignalId(signal:) ⇒ Object

Obtain signal Id Params:

signal

Name of signal you want obtain ud



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/HardsploitAPI/Core/HardsploitAPI_CONSTANT.rb', line 15

def self.getSignalId(signal:)
	wires = Hash.new

	#Parallel module
	wires["A0"]				 = 0
	wires["A1"]				 = 1
	wires["A2"]				 = 2
	wires["A3"]				 = 3
	wires["A4"]				 = 4
	wires["A5"]				 = 5
	wires["A6"]				 = 6
	wires["A7"]				 = 7
	wires["A8"]				 = 8
	wires["A9"]				 = 9
	wires["A10"]			 = 10
	wires["A11"]			 = 11
	wires["A12"]			 = 12
	wires["A13"]			 = 13
	wires["A14"]			 = 14
	wires["A15"]			 = 15
	wires["A16"]			 = 16
	wires["A17"]			 = 17
	wires["A18"]			 = 18
	wires["A19"]			 = 19
	wires["A20"]			 = 20
	wires["A21"]			 = 21
	wires["A22"]			 = 22
	wires["A23"]			 = 23
	wires["A24"]			 = 24
	wires["A25"]			 = 25
	wires["A26"]			 = 26
	wires["A27"]			 = 27
	wires["A28"]			 = 28
	wires["A29"]			 = 29
	wires["A30"]			 = 30
	wires["A31"]			 = 31

	wires["D0"] 			 = 32
	wires["D1"]				 = 33
	wires["D2"]				 = 34
	wires["D3"] 			 = 35
	wires["D4"]				 = 36
	wires["D5"] 			 = 37
	wires["D6"] 			 = 38
	wires["D7"] 			 = 39
	wires["D8"] 			 = 40
	wires["D9"] 			 = 41
	wires["D10"] 			 = 42
	wires["D11"] 			 = 43
	wires["D12"] 			 = 44
	wires["D13"]			 = 45
	wires["D14"]			 = 46
	wires["D15"] 			 = 47

	wires["RST"]			 = 48
	wires["CE"] 			 = 49
	wires["OE"] 			 = 50
	wires["WE"] 			 = 51
	wires["PARA_CLK"]	 = 52
	wires["WP"] 			 = 53
	wires["ADV"] 			 = 54

	#SPI module
	wires["SPI_CLK"]	 = 0
	wires["CS"] 	 		 = 1
	wires["MOSI"]	 		 = 2
	wires["MISO"]  		 = 3
	wires["PULSE"] 		 = 4

	#I2C module
	wires["I2C_CLK"] 	 = 0
	wires["SDA"] 	 		 = 1

	#UART module
	wires["TX"] 	 		 = 0
	wires["RX"] 	 		 = 1

	#SWD module
	wires["SWD_CLK"] 	 = 0
	wires["SWD_IO"] 	 = 1

	return wires[signal]
end

.highByte(word:) ⇒ Object

Obtain high byte of a word

  • word

    16 bit word

Return high byte of the word



85
86
87
# File 'lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb', line 85

def self.highByte(word:)
	return  (word & 0xFF00) >> 8
end

.id=(id) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 67

def self.id=id
  if (id < 0) then
    raise ERROR::HARDSPLOIT_NOT_FOUND
  else
    @@id = id
  end
end

.lowByte(word:) ⇒ Object

Obtain low byte of a word

  • word

    16 bit word

Return low byte of the word



78
79
80
# File 'lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb', line 78

def self.lowByte(word:)
	return  word & 0xFF
end

.prepare_packetObject



186
187
188
189
190
191
192
193
194
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 186

def self.prepare_packet
	packet = []
	packet.push 0  #low byte of lenght of trame refresh automaticly before send by usb
	packet.push 0  #high byte of lenght of trame refresh automaticly before send by usb
	packet.push HardsploitAPI.lowByte(word:HardsploitAPI::USB_COMMAND::FPGA_COMMAND)
	packet.push HardsploitAPI.highByte(word:HardsploitAPI::USB_COMMAND::FPGA_COMMAND)
	packet.push 0x50 #Command RAW COMMUNICATION TO FPGA FIFO
	return packet
end

.reverseBit(byte) ⇒ Object



152
153
154
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 152

def self.reverseBit(byte)
  return byte.to_s(2).rjust(8, "0").reverse.to_i(2)
end

Instance Method Details

#connectObject

Connect board and get an instance to work with Return USB_STATE



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb', line 21

def connect
	@usb = LIBUSB::Context.new
	@devices = @usb.devices(:idVendor => 0x0483, :idProduct => 0xFFFF)

	if @devices.size == 0 then
		@device = nil
		@dev = nil
		raise ERROR::HARDSPLOIT_NOT_FOUND
	else
		if @@id >= @devices.size then
			raise ERROR::HARDSPLOIT_NOT_FOUND
		else
			begin
				if @dev == nil then
					@dev = @devices[@@id].open
					 if RUBY_PLATFORM=~/linux/i && @dev.kernel_driver_active?(0)
						@dev.detach_kernel_driver(0)
					 end
					@dev.claim_interface(0)
				end
				self.startFPGA
				sleep(0.1)
				self.setStatutLed(led:USB_COMMAND::GREEN_LED,state:true);
			rescue
				raise ERROR::USB_ERROR
				end
		end
	end
end

#consoleData(value) ⇒ Object



200
201
202
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 200

def consoleData(value)
  @@callbackData.call(value)
end

#consoleInfo(value) ⇒ Object



206
207
208
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 206

def consoleInfo(value)
  @@callbackInfo.call(value)
end

#consoleProgress(percent:, startTime:, endTime:) ⇒ Object

call back



197
198
199
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 197

def consoleProgress(percent:,startTime:,endTime:)
  @@callbackProgress.call(percent:percent,startTime:startTime,endTime:endTime)
end

#consoleSpeed(value) ⇒ Object



203
204
205
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 203

def consoleSpeed(value)
  @@callbackSpeedOfTransfert.call(value)
end

#getAllVersionsObject



145
146
147
148
149
150
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 145

def getAllVersions
  puts "API             : #{VERSION::API}".blue.bold
  puts "Board           : #{getVersionNumber}".blue.bold
  puts "FPGA            : #{VersionFPGA::VERSION_FPGA::FPGA}".blue.bold
  puts "Microcontroller : #{VersionUC::VERSION_UC::UC}".blue.bold
end

#getVersionNumberObject

Obtaint the version number of the board



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 129

def getVersionNumber
  packet = Array.new
  packet.push 0  #low byte of lenght of trame refresh automaticly before send by usb
  packet.push 0  #high byte of lenght of trame refresh automaticly before send by usb
  packet.push HardsploitAPI.lowByte(word:USB_COMMAND::GET_VERSION_NUMBER)
  packet.push HardsploitAPI.highByte(word:USB_COMMAND::GET_VERSION_NUMBER)

  #remove header
  version_number = self.sendAndReceiveDATA(packet,1000).drop(4)
  if version_number.size < 20 then #if size more thant 20 char error when reading version number
      return version_number.pack('U*')
  else
    return "BAD VERSION NUMBER"
  end
end

#loadFirmware(firmware) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/HardsploitAPI/Core/HardsploitAPI_FIRMWARE.rb', line 11

def loadFirmware(firmware)
	base_path = File.expand_path(File.dirname(__FILE__)) + '/../../Firmwares/FPGA/'
	case firmware
	when 'I2C'
		firmware_path = base_path + 'I2C/I2C_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_I2C_INTERACT.rpd'
		HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
	when 'SPI'
		firmware_path = base_path + 'SPI/SPI_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SPI_INTERACT.rpd'
		HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
	when 'SPI_SNIFFER'
		firmware_path = base_path + 'SPI/SPI_SNIFFER/HARDSPLOIT_FIRMWARE_FPGA_SPI_SNIFFER.rpd'
		HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
	when 'PARALLEL'
		firmware_path = base_path + 'PARALLEL/NO_MUX_PARALLEL_MEMORY/HARDSPLOIT_FIRMWARE_FPGA_NO_MUX_PARALLEL_MEMORY.rpd'
		HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
	when 'SWD'
		firmware_path = base_path + 'SWD/SWD_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_SWD_INTERACT.rpd'
		HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
	when 'UART'
		firmware_path = base_path + 'UART/UART_INTERACT/HARDSPLOIT_FIRMWARE_FPGA_UART_INTERACT.rpd'
		HardsploitAPI.instance.uploadFirmware(pathFirmware: firmware_path, checkFirmware: false)
	when 'uC'
			system("dfu-util -D 0483:df11 -a 0 -s 0x08000000 -R --download #{File.expand_path(File.dirname(__FILE__))}'/../Firmwares/UC/HARDSPLOIT_FIRMWARE_UC.bin'")
	end
end

#receiveDATA(timeout) ⇒ Object

Wait to receive data

  • timeout

    timeout to read response (ms)

Return USB_STATE or array with response (improve soon with exception)



119
120
121
122
123
124
125
126
127
128
# File 'lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb', line 119

def receiveDATA(timeout)
	begin
		received_data =  @dev.bulk_transfer(:endpoint=>IN_ENDPOINT, :dataIn=>USB::USB_TRAME_SIZE, :timeout=>timeout)
		return received_data
	rescue LIBUSB::ERROR_NO_DEVICE
		raise ERROR::USB_ERROR
	rescue LIBUSB::ERROR_NO_DEVICE
		raise ERROR::HARDSPLOIT_NOT_FOUND
	end
end

#reconncetObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb', line 51

def reconncet
	@usb = LIBUSB::Context.new
	@devices = @usb.devices(:idVendor => 0x0483, :idProduct => 0xFFFF)
	if @devices.size == 0 then
		@device = nil
		@dev = nil
		raise ERROR::HARDSPLOIT_NOT_FOUND
	else
		begin
			@dev = @devices[@@id].open
			 if RUBY_PLATFORM=~/linux/i && @dev.kernel_driver_active?(0)
				@dev.detach_kernel_driver(0)
			 end
			@dev.claim_interface(0)
			self.startFPGA
			sleep(0.1)
			self.setStatutLed(led:USB_COMMAND::GREEN_LED,state:true);

		rescue
			raise ERROR::USB_ERROR
		end
	end
end

#sendAndReceiveDATA(packet_send, timeout) ⇒ Object

Send data and wait to receive response

  • packet_send

    array of byte

  • timeout

    timeout to read response (ms)

Return USB_STATE or array with response (improve soon with exception)



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb', line 102

def sendAndReceiveDATA(packet_send,timeout)
	time = Time.new
	begin
		sendPacket(packet_send)
		received_data =  @dev.bulk_transfer(:endpoint=>IN_ENDPOINT, :dataIn=>USB::USB_TRAME_SIZE, :timeout=>timeout)
		consoleSpeed "RECEIVE #{((received_data.bytes.to_a.size/(Time.new-time))).round(2)}Bytes/s  #{(received_data.bytes.to_a.size)}Bytes in  #{(Time.new-time).round(4)} s"
		return received_data.bytes.to_a
	rescue LIBUSB::ERROR_NO_DEVICE
		raise ERROR::HARDSPLOIT_NOT_FOUND
	rescue
		raise ERROR::USB_ERROR
	end
end

#sendPacket(packet_send) ⇒ Object

Send USB packet

  • packet

    array with bytes

Return number of byte sent



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb', line 133

def sendPacket(packet_send)

	begin
		if packet_send.size <= 8191 then

			packet_send[0] = HardsploitAPI.lowByte(word:packet_send.size)
			packet_send[1] = HardsploitAPI.highByte(word:packet_send.size)

			#if a multiple of packet size add a value to explicit the end of trame
			if packet_send.size % 64 ==0 then
				packet_send.push 0
			end

			number_of_data_send = 0
			time = Benchmark.realtime  do
				number_of_data_send =  @dev.bulk_transfer(:endpoint=>OUT_ENDPOINT, :dataOut=>packet_send.pack('c*'),:timeout=>3000)
			end
			consoleSpeed "SEND #{((number_of_data_send/time)).round(2)}Bytes/s  SEND #{(number_of_data_send)}Bytes in  #{time.round(4)} s"
			if number_of_data_send ==  packet_send.size then
				return number_of_data_send
			 else
				raise ERROR::USB_ERROR
			 end
		else
			raise ERROR::USB_ERROR
		end
	rescue LIBUSB::ERROR_NO_DEVICE
		#TRY TO RECONNECT maybe error due to disconnecting and reconnecting board
		reconncet
	rescue
		raise ERROR::USB_ERROR
	end
end

#setCrossWiring(value:) ⇒ Object

Set cross wiring

  • value

    64*8 bits to represent wiring



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 158

def setCrossWiring(value:)
  if not value.size == 64 then
    raise HardsploitAPI::ERROR::API_CROSS_WIRING
  end

  packet = Array.new
  packet.push 0  #low byte of lenght of trame refresh automaticly before send by usb
  packet.push 0  #high byte of lenght of trame refresh automaticly before send by usb
  packet.push HardsploitAPI.lowByte(word:USB_COMMAND::FPGA_COMMAND)
  packet.push HardsploitAPI.highByte(word:USB_COMMAND::FPGA_COMMAND)

  packet.push 0x75 #Cross wiring command
  packet.push *value
  @@crossWiringValue = value
  return self.sendPacket(packet)
end

#setStatutLed(led:, state:) ⇒ Object

  • led

    USB_COMMAND::GREEN_LED or USB_COMMAND::RED_LED

  • state

    callback to return data for dump function



91
92
93
94
95
96
97
98
99
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 91

def setStatutLed(led:,state:)
	packet_send = Array.new
	packet_send.push 0 #size set before send automatic
	packet_send.push 0	#size set before send automatic
	packet_send.push HardsploitAPI.lowByte(word:led)
	packet_send.push HardsploitAPI.highByte(word:led)
	packet_send.push (state ? 1 : 0)
	return sendPacket(packet_send)
end

#setWiringLeds(value:) ⇒ Object

Set custom value to wiring led

  • value

    64 bits (8x8 Bytes) values to represent led (PortH PortG PortF PortE PortD PortC PortB PortA)



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/HardsploitAPI/Core/HardsploitAPI.rb', line 104

def setWiringLeds(value:)
#  parametters = HardsploitAPI.checkParametters(["value"],args)
#  val = parametters[:value]

  packet = Array.new
  packet.push 0  #low byte of lenght of trame refresh automaticly before send by usb
  packet.push 0  #high byte of lenght of trame refresh automaticly before send by usb
  packet.push HardsploitAPI.lowByte(word:USB_COMMAND::FPGA_COMMAND)
  packet.push HardsploitAPI.highByte(word:USB_COMMAND::FPGA_COMMAND)

  packet.push 0x23 #Command SPI write wiring led

  packet.push  HardsploitAPI.reverseBit((value & 0x00000000000000FF) >> 0)
  packet.push  HardsploitAPI.reverseBit((value & 0x000000000000FF00) >> 8 )
  packet.push  HardsploitAPI.reverseBit((value & 0x0000000000FF0000) >> 16 )
  packet.push  HardsploitAPI.reverseBit((value & 0x00000000FF000000) >> 24 )
  packet.push  HardsploitAPI.reverseBit((value & 0x000000FF00000000) >> 32 )
  packet.push  HardsploitAPI.reverseBit((value & 0x0000FF0000000000) >> 40 )
  packet.push  HardsploitAPI.reverseBit((value & 0x00FF000000000000) >> 48 )
  packet.push  HardsploitAPI.reverseBit((value & 0xFF00000000000000) >> 56 )

  return  HardsploitAPI.instance.sendPacket(packet)
end

#signalHelpingWiring(signal:) ⇒ Object

Power on the led for each signal specified Params:

signal

Name of signal you want visual help (set the led)



102
103
104
105
106
107
108
# File 'lib/HardsploitAPI/Core/HardsploitAPI_CONSTANT.rb', line 102

def signalHelpingWiring(signal:)
	begin
		HardsploitAPI.instance.setWiringLeds(value:2**HardsploitAPI.crossWiringValue.index(HardsploitAPI.getSignalId(signal:signal)))
	rescue
	   raise 'UNKNOWN SIGNAL'
	end
end

#startFPGAObject



57
58
59
60
61
62
63
64
# File 'lib/HardsploitAPI/Core/HardsploitAPI_FIRMWARE.rb', line 57

def startFPGA
	packet = Array.new
	packet.push HardsploitAPI.lowByte(word:4)
	packet.push HardsploitAPI.highByte(word:4)
	packet.push HardsploitAPI.lowByte(word:USB_COMMAND::START_FPGA)
	packet.push HardsploitAPI.highByte(word:USB_COMMAND::START_FPGA)
	self.sendPacket(packet)
end

#stopFPGAObject



65
66
67
68
69
70
71
72
# File 'lib/HardsploitAPI/Core/HardsploitAPI_FIRMWARE.rb', line 65

def stopFPGA
	packet = Array.new
	packet.push HardsploitAPI.lowByte(word:4)
	packet.push HardsploitAPI.highByte(word:4)
	packet.push HardsploitAPI.lowByte(word:USB_COMMAND::STOP_FPGA)
	packet.push HardsploitAPI.highByte(word:USB_COMMAND::STOP_FPGA)
	self.sendPacket(packet)
end

#uploadFirmware(pathFirmware:, checkFirmware:) ⇒ Object

Wait to receive data

  • pathFirmware

    path of rpd file (vhdl)

  • checkFirmware

    boolean if check is needed (recommended false, in case issue true to check)

Return true if firmware write == firmware read (slow because read the firmware for check)



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/HardsploitAPI/Core/HardsploitAPI_FIRMWARE.rb', line 41

def uploadFirmware(pathFirmware:,checkFirmware:)
	stopFPGA
	eraseFirmware
	firmwarewrite = self.writeFirmware(pathFirmware)#return array of bytes write
	if checkFirmware == true then
		firmwareRead = self.readFirmware(firmwarewrite.length) #return array of bytes read
		startFPGA
		sleep(1)
		return (firmwarewrite == firmwareRead)
	else
		startFPGA
		sleep(1)
		return true
	end
end