Top Level Namespace

Defined Under Namespace

Modules: Ui Classes: Bus, Byte, CType, Chip, ChipType, Chip_clone, Chip_editor, Chip_management, Cmd, Command, Command_editor, Command_table, Console, CreateBuses, CreateBytes, CreateChipTypes, CreateChips, CreateCommands, CreateI2cSettings, CreateManufacturers, CreatePackages, CreateParallelSettings, CreatePins, CreateSignals, CreateSpiSettings, CreateSwdSettings, CreateUartSettings, CreateUses, CustomItem, ErrorMsg, Export, Export_manager, Firmware, Generic_commands, HardsploitAPI, HardsploitAPI_I2C, HardsploitAPI_NRF24L01, HardsploitAPI_PARALLEL, HardsploitAPI_SPI, HardsploitAPI_SPI_SNIFFER, HardsploitAPI_SWD, HardsploitAPI_TEST, HardsploitAPI_UART, Hardsploit_gui, I2C, I2cSetting, I2c_command, I2c_read, I2c_scanner, I2c_settings, I2c_write, Import, Manufacturer, Package, Parallel, ParallelSetting, Parallel_read, Parallel_settings, Parallel_write, Pin, Progress_bar, SWD_DEBUG_PORT, SWD_MEM_AP, SWD_STM32, Signal_mapper, Signall, Spi, SpiSetting, Spi_read, Spi_settings, Spi_sniffer, Spi_write, String, Swd, SwdSetting, Swd_scanner, Swd_settings, UartSetting, Uart_baudrate, Uart_console, Uart_settings, Ui_Chip_clone, Ui_Chip_editor, Ui_Chip_management, Ui_Command_editor, Ui_Export, Ui_Export_manager, Ui_Generic_commands, Ui_Generic_read, Ui_Generic_write, Ui_I2c_command, Ui_I2c_settings, Ui_Import, Ui_Parallel_settings, Ui_Progress_bar, Ui_Signal_mapper, Ui_Signal_scanner, Ui_Spi_settings, Ui_Spi_sniffer, Ui_Swd_settings, Ui_Uart_baudrate, Ui_Uart_console, Ui_Uart_settings, Ui_Wire_helper, UniqPin, Use, VersionFPGA, VersionUC, Wire_helper

Constant Summary collapse

ABSOLUTE_PATH =
Hardsploit GUI - 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
File.expand_path(File.dirname(__FILE__)) + "/"

Constants included from VersionUC::VERSION_UC

VersionUC::VERSION_UC::UC

Constants included from VersionFPGA::VERSION_FPGA

VersionFPGA::VERSION_FPGA::FPGA

Instance Method Summary collapse

Instance Method Details

#callbackData(receiveData) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/hardsploit-api/Examples/testI2C.rb', line 16

def callbackData(receiveData)
	if receiveData != nil then
			puts "received #{receiveData.size}"
	  	p receiveData
	else
			puts "ISSUE BECAUSE DATA IS NIL"
	end
end

#callbackInfo(receiveData) ⇒ Object



12
13
14
# File 'lib/hardsploit-api/Examples/testI2C.rb', line 12

def callbackInfo(receiveData)
	#print receiveData  + "\n"
end

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

puts “Speed : #receiveData”



28
29
30
31
32
# File 'lib/hardsploit-api/Examples/testSPI.rb', line 28

def callbackProgress(percent:,startTime:,endTime:)
	print "\r\e[#{31}mUpload of FPGA firmware in progress : #{percent}%\e[0m"
	#puts "Progress : #{percent}%  Start@ #{startTime}  Stop@ #{endTime}"
	#puts "Elasped time #{(endTime-startTime).round(4)} sec"
end

#callbackSpeedOfTransfert(receiveData) ⇒ Object



25
26
27
# File 'lib/hardsploit-api/Examples/testI2C.rb', line 25

def callbackSpeedOfTransfert(receiveData)
	#puts "Speed : #{receiveData}"
end

#centerWindow(win) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/Hardsploit_gui.rb', line 89

def centerWindow(win)
  desktop = Qt::DesktopWidget.new
  rect  = desktop.screenGeometry(desktop.primaryScreen)
  centerX = (rect.width - win.width ) / 2
  centerY = (rect.height - win.height)  / 2
  win.move(centerX,centerY)
end

#check_for_errors(result) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/Hardsploit_gui.rb', line 67

def check_for_errors(result)
  return false if result.errors.messages.empty?
  error_message = ""
  result.errors.messages.each do |msg|
    error_message << "Error: #{msg[0]} #{msg[1][0]}\n"
  end
  Qt::MessageBox.new(Qt::MessageBox::Warning, 'Warning', error_message).exec
  return true
end

#draw_rectObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/class/Wire_helper.rb', line 103

def draw_rect
  total_pin_nbr = Pin.where(chip_id: @chip.id).count
  pin_by_side = total_pin_nbr / 2
  cHeight = 14 * (pin_by_side + 2) # +2 because we add a space equal to one pin for each corner
  @scene.addRect(Qt::RectF.new(0, 0, cHeight, cHeight))
  # Add the pins + text
  y = 18
  y2 = cHeight - 24
  (1..total_pin_nbr).each do |i|
    # Face 1
    if i <= total_pin_nbr / 2
      ySig = y
      yNum = y
      UniqPin.new(@scene, i, @chip.id, -70, ySig - 12, 0, yNum - 12, 0, y, -20, 6, false)
      y = y + 14
    # Face 2
    else
      xSig = cHeight + 24
      ySig = y2
      yNum = y2

      if i < 10
        xNum = cHeight - 20
      elsif i >= 10 && i < 100
        xNum = cHeight - 25
      else
        xNum = cHeight - 35
      end
      UniqPin.new(@scene, i, @chip.id, xSig, ySig - 12, xNum, yNum - 12, cHeight, y2, 20, 6, false)
      y2 = y2 - 14
    end
  end
end

#draw_squareObject



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
98
99
100
101
# File 'lib/class/Wire_helper.rb', line 48

def draw_square
  total_pin_nbr = Pin.where(chip_id: @chip.id).count
  pin_by_side = total_pin_nbr / 4
  cHeight = 14*(pin_by_side + 4)  # Chip's height (+4 because we add a space equal to one pin for each corner)
  @scene.addRect(Qt::RectF.new(0, 0, cHeight, cHeight))
  y = 32
  y2 = cHeight - 38
  x = 32
  x2 = cHeight - 38
  (1..total_pin_nbr).each do |i|
    # Face 1
    if i <= pin_by_side
      ySig = y
      yNum = y
      UniqPin.new(@scene, i, @chip.id, -70, ySig - 12, 0, yNum - 12, 0, y, -20, 6, false)
      y = y + 14 # Space between each pin
    elsif i > pin_by_side && i <= total_pin_nbr / 2
    # Face 2
      xSig2 = x
      xNum2 = x
      UniqPin.new(@scene, i, @chip.id, xSig2 - 12, cHeight + 55, xNum2 - 12, cHeight, x, cHeight, 6, 20, true)
      x = x + 14
    elsif i > total_pin_nbr / 2 && i <= (total_pin_nbr - (pin_by_side))
    # Face 3
      xSig = cHeight + 24
      ySig = y2
      yNum = y2

      if i < 10
        xNum = cHeight - 20
      elsif i >= 10 && i < 100
        xNum = cHeight - 25
      else
        xNum = cHeight - 35
      end
      UniqPin.new(@scene, i, @chip.id, xSig, ySig - 12, xNum, yNum - 12, cHeight, y2, 20, 6, false)
      y2 = y2 - 14
    else
    # Face 4
      xSig2 = x2
      xNum2 = x2

      if i < 10
        yNum2 = 20
      elsif i >= 10 && i < 100
        yNum2 = 30
      else
        yNum2 = 40
      end
      UniqPin.new(@scene, i, @chip.id, xSig2 - 12, -20, xNum2 - 12, yNum2, x2, 0, 6, -20, true)
      x2 = x2 - 14
    end
  end
end

#i2cCustomInteractObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/hardsploit-api/Examples/testI2C.rb', line 83

def i2cCustomInteract
	begin
		#Create an instance of I2C
		i2c = HardsploitAPI_I2C.new(speed:HardsploitAPI::I2C::KHZ_100)

		testpack = Array.new

		#interact I2C
		# write with even address
		# read with odd address

		#Write 4 bytes at 0x00 0x00
		# testpack.push HardAPI.lowByte(4)  #Count Low  Byte
		# testpack.push HardAPI.highByte(4)   #Count High Byte
		# testpack.push 0xA0
		# testpack.push 41  #First data byte
		# testpack.push 42  #Second data byte
		# testpack.push 43
		# testpack.push 44


		#Write pointer of I2C memorie at 0x00 0x00
		# testpack.push HardsploitAPI.lowByte(word:2)  #Count Low  Byte
		# testpack.push HardsploitAPI.highByte(word:2)   #Count High Byte
		# testpack.push 0xA0
		# testpack.push 0x00
		# testpack.push 0x00

		testpack.push HardsploitAPI.lowByte(word:2)  #Count Low  Byte
		testpack.push HardsploitAPI.highByte(word:2)   #Count High Byte
		testpack.push 0xA0
		testpack.push 0x00
		testpack.push 0x00

		testpack.push HardsploitAPI.lowByte(word:4)  #Count Low  Byte
		testpack.push HardsploitAPI.highByte(word:4)   #Count High Byte
		testpack.push 0xA1




		begin
			#result contient les ACK NACK ou les data si dispo cf wiki
			# https://github.com/OPALESECURITY/hardsploit-api/wiki#i2c-interact
			result = i2c.i2c_Interact(payload:testpack)
			p result
		rescue HardsploitAPI::ERROR::USB_ERROR
			puts "Error during USB communication, please retry"
		end

	rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
		puts "Hardsploit not found"
	end
end

#i2cCustomScanObject



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
# File 'lib/hardsploit-api/Examples/testI2C.rb', line 49

def i2cCustomScan
	begin
		#Create an instance of I2C
		i2c = HardsploitAPI_I2C.new(speed:HardsploitAPI::I2C::KHZ_100)

		#Change the speed
		i2c.speed = HardsploitAPI::I2C::KHZ_100

		#scan I2C
		puts "I2C SCAN :"
		scan_result = i2c.i2c_Scan
		#check parity of array index to know if a Read or Write address
		# Index 0 is write address because is is even
		# Index 1 is read address because it is  odd

		# Index 160 (0xA0) is write address because is is even
		# Index 161 (0xA1) is read address because is is odd

		#If value is 0 slave address is not available
		#If valude is 1 slave address is available

		for i in (0..scan_result.size-1) do
			if scan_result[i] == 1 then
				puts " #{(i).to_s(16)} #{scan_result[i]}"
			end
		end

	rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
		puts "Hardsploit not found"
	rescue HardsploitAPI::ERROR::USB_ERROR
		puts "USB ERRROR"
  end
end

#inputRestrict(lineEdit, type) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/Hardsploit_gui.rb', line 77

def inputRestrict(lineEdit, type)
  case type
  when 0 ; reg = Qt::RegExp.new("[0-9]+")
  when 1 ; reg = Qt::RegExp.new("^[a-zA-Z_@-]+( [a-zA-Z_@-]+)*$")
  when 2 ; reg = Qt::RegExp.new("^[a-zA-Z0-9_@-]+( [a-zA-Z0-9_@-]+)*$")
  when 3 ; reg = Qt::RegExp.new("^[A-Fa-f0-9]{2}")
  when 4 ; reg = Qt::RegExp.new("^[A-Fa-f0-9]{8}")
  end
  regVal = Qt::RegExpValidator.new(reg, self)
  lineEdit.setValidator(regVal)
end

#spiCustomCommandObject

p HardsploitAPI::VERSION::API



51
52
53
54
55
56
57
58
59
60
# File 'lib/hardsploit-api/Examples/testSPI.rb', line 51

def spiCustomCommand
	#Speed Range 1-255  SPI clock =  150Mhz / (2*speed) tested from 3 to 255 (25Mhz to about 0.3Khz)

	testpack = Array.new
	for i in (0..10) do
		testpack.push i
	end
	result = @spi.spi_Interact(payload:testpack)
	p result
end

#swdCustomReadObject

The current API version p HardsploitAPI::VERSION::API



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
# File 'lib/hardsploit-api/Examples/testSWD.rb', line 48

def swdCustomRead
	begin
		swd = HardsploitAPI_SWD.new(
			memory_start_address: "0x08000000",
			memory_size_address:   "0x1FFFF7E0",
			cpu_id_address:		   "0xE000ED00",
			device_id_address:	   "0x1FFFF7E8"
		)
		#TO OBTAIN ID CODE
		code = swd.obtainCodes
		puts "DP.IDCODE: 	#{code[:DebugPortId].to_s(16)} "
		#puts "AP.IDCODE: 	#{code[:AccessPortId].to_s(16)} "
		#puts "CPU ID : 		#{code[:CpuId].to_s(16)} "
		#	puts "DEVICE ID : #{code[:DeviceId].to_s(16)}"
	rescue
		puts "MCU NOT FOUND"
		#puts "Read ARM Register"
		#swd.readRegs

		#puts "stop"
		#swd.stop

		#TO DUMP FLASH
		#swd.dumpFlash('dumdp.bin')
		#swd.erase
		# ERASE FLASH !!!!!!!!!!  AND WRITE THE CONTENT OF THE FILE ON THE FLASH
		#swd.writeFlash('dumdp2.bin')

	rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
		puts "Hardsploit not found"
	rescue HardsploitAPI::ERROR::USB_ERROR
		puts "USB ERRROR"
	end
end

#swdCustomWriteObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/hardsploit-api/Examples/testSWD.rb', line 82

def swdCustomWrite
	begin

		swd = HardsploitAPI_SWD.new(
			memory_start_address: "0x08000000",
			memory_size_address:  "0x1FFFF7E0",
			cpu_id_address:		  	"0xE000ED00",
			device_id_address:	  "0x1FFFF7E8"
		)
		#TO OBTAIN ID CODE
		code = swd.obtainCodes
		puts "DP.IDCODE: 	#{code[:DebugPortId].to_s(16)} "
		puts "AP.IDCODE: 	#{code[:AccessPortId].to_s(16)} "
		puts "CPU ID : 		#{code[:CpuId].to_s(16)} "

	#TO DUMP FLASH
	#swd.dumpFlash('dumdp.bin')
	#swd.erase
	# ERASE FLASH !!!!!!!!!!  AND WRITE THE CONTENT OF THE FILE ON THE FLASH
	swd.writeFlash('dumdp2.bin')
	#unhalt
	#swd.stop

	rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
		puts "Hardsploit not found"
	rescue HardsploitAPI::ERROR::USB_ERROR
		puts "USB ERRROR"
	end
end

#uartCustomReadObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/hardsploit-api/Examples/testUARTFuzzer.rb', line 68

def uartCustomRead
	while 1
		begin
			tab = @uart.sendAndReceived
			print tab.pack('c*')
			rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
				puts "Hardsploit not found"
		  rescue HardsploitAPI::ERROR::USB_ERROR
			  puts "USB ERRROR"
		end
		sleep(0.2)
	end
end

#uartCustomSendObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/hardsploit-api/Examples/testUARTFuzzer.rb', line 51

def uartCustomSend
	begin
		payload = Array.new
		for i in 0..23
			payload.push 0x40
		end
		payload.push 13 #Carriage return

		@uart.write(payload:payload)
		puts payload.pack("C*")
		rescue HardsploitAPI::ERROR::HARDSPLOIT_NOT_FOUND
			puts "Hardsploit not found"
		rescue HardsploitAPI::ERROR::USB_ERROR
		  puts "USB ERRROR"
	end
end