Class: HardsploitAPI_SPI_SNIFFER

Inherits:
Object
  • Object
show all
Defined in:
lib/HardsploitAPI/Modules/SPI_SNIFFER/HardsploitAPI_SPI_SNIFFER.rb

Instance Method Summary collapse

Constructor Details

#initialize(mode:, sniff:) ⇒ HardsploitAPI_SPI_SNIFFER

Returns a new instance of HardsploitAPI_SPI_SNIFFER.



13
14
15
16
17
18
19
# File 'lib/HardsploitAPI/Modules/SPI_SNIFFER/HardsploitAPI_SPI_SNIFFER.rb', line 13

def initialize(mode:,sniff:)
	#to be sure the singleton was initialize
	HardsploitAPI.instance.connect
	self.mode=mode
	self.sniff=sniff
	spi_SetSettings
end

Instance Method Details

#modeObject



21
22
23
# File 'lib/HardsploitAPI/Modules/SPI_SNIFFER/HardsploitAPI_SPI_SNIFFER.rb', line 21

def mode
	return @mode
end

#mode=(mode) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/HardsploitAPI/Modules/SPI_SNIFFER/HardsploitAPI_SPI_SNIFFER.rb', line 27

def mode=(mode)
	if ( mode < 0 ) or ( mode > 3 ) then
		raise HardsploitAPI::ERROR::SPIWrongMode
	else
		@mode = mode
	end
end

#odds_and_evens(tab, return_odds) ⇒ Object



54
55
56
# File 'lib/HardsploitAPI/Modules/SPI_SNIFFER/HardsploitAPI_SPI_SNIFFER.rb', line 54

def odds_and_evens(tab, return_odds)
	tab.select.with_index{|_, i| return_odds ? i.odd? : i.even?}
end

#sniffObject



24
25
26
# File 'lib/HardsploitAPI/Modules/SPI_SNIFFER/HardsploitAPI_SPI_SNIFFER.rb', line 24

def sniff
	return @sniff
end

#sniff=(sniff) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/HardsploitAPI/Modules/SPI_SNIFFER/HardsploitAPI_SPI_SNIFFER.rb', line 34

def sniff=(sniff)
	case sniff
	when HardsploitAPI::SPISniffer::MISO;			 @sniff = sniff
	when HardsploitAPI::SPISniffer::MOSI; 		 @sniff = sniff
	when HardsploitAPI::SPISniffer::MISO_MOSI; @sniff = sniff
	else
		raise HardsploitAPI::ERROR::SPIWrongMode
	end
end

#spi_receive_available_dataObject

  • Return data received



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/HardsploitAPI/Modules/SPI_SNIFFER/HardsploitAPI_SPI_SNIFFER.rb', line 59

def spi_receive_available_data
	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:HardsploitAPI::USB_COMMAND::FPGA_COMMAND)
	packet.push HardsploitAPI.highByte(word:HardsploitAPI::USB_COMMAND::FPGA_COMMAND)

	packet.push 0x50 #Command RAW COMMUNICATION TO FPGA FIFO
	packet.push 0x20 #Command receive available data

	#remove header (4 bytes   2 for size 2 for type of command)
	result = HardsploitAPI.instance.sendAndReceiveDATA(packet, 200).drop(4)

	#if half a simple array, if fullduplex  first item -> an array of MISO  and second array -> an array of MOSI
	case @sniff
	when HardsploitAPI::SPISniffer::MISO,HardsploitAPI::SPISniffer::MOSI
		return result
	else
		myresult = Array.new
		myresult.push odds_and_evens(result,true)
		myresult.push odds_and_evens(result,false)
		return myresult
	end
end

#spi_SetSettingsObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/HardsploitAPI/Modules/SPI_SNIFFER/HardsploitAPI_SPI_SNIFFER.rb', line 43

def spi_SetSettings
	packet = HardsploitAPI.prepare_packet
	packet.push 0x10 #Command change mode
	packet.push @mode + (@sniff<<6)  #Add mode
	begin
		HardsploitAPI.instance.sendPacket packet
		rescue
		raise HardsploitAPI::ERROR::USB_ERROR
	end
end