Class: SWD_DEBUG_PORT

Inherits:
Object
  • Object
show all
Defined in:
lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_DEBUG.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

Instance Method Summary collapse

Constructor Details

#initialize(swdAPI) ⇒ SWD_DEBUG_PORT

Returns a new instance of SWD_DEBUG_PORT.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_DEBUG.rb', line 10

def initialize(swdAPI)
	@swdAPI = swdAPI
	sleep(0.5)
	@swdAPI.resetSWD

	@curAP = -1
	@curBank = -1
	abort(1,1,1,1,1)
	select(0,0) 
	
	# power shit up
	HardsploitAPI.instance.consoleInfo "Power shit up"
	
	@swdAPI.writeSWD(FALSE, 1, 0x54000000)
	if (status() >> 24) != 0xF4 then
		raise "error powering up system"
		exit(0)
	else
		HardsploitAPI.instance.consoleInfo "POWERING UP SYTEM OK"
	end
end

Instance Method Details

#abort(orunerr, wdataerr, stickyerr, stickycmp, dap) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_DEBUG.rb', line 40

def abort (orunerr, wdataerr, stickyerr, stickycmp, dap)
	value = 0x00000000
	(orunerr ? value |= 0x10 : value |= 0x00)
	(wdataerr ? value |= 0x08 : value |= 0x00)
	(stickyerr ? value |= 0x04 : value |= 0x00)
	(stickycmp ? value |= 0x02 : value |= 0x00)
	(dap ? value |= 0x01 : value |= 0x00)
	@swdAPI.writeSWD(FALSE, 0, value)
end

#control(trnCount = 0, trnMode = 0, maskLane = 0, orunDetect = 0) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_DEBUG.rb', line 55

def control (trnCount = 0, trnMode = 0, maskLane = 0, orunDetect = 0)
	value = 0x54000000
	value = value | ((trnCount & 0xFFF) << 12)
	value = value | ((maskLane & 0x00F) << 8)
	value = value | ((trnMode  & 0x003) << 2)
	(orunDetect ? value |= 0x01 : value |= 0x00)
	@swdAPI.writeSWD(False, 1, value)
end

#getAPIObject



32
33
34
# File 'lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_DEBUG.rb', line 32

def getAPI
	return @swdAPI
end

#idcodeObject



36
37
38
# File 'lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_DEBUG.rb', line 36

def idcode
	return @swdAPI.readSWD(FALSE, 0)
end

#readAP(apsel, address) ⇒ Object



76
77
78
79
80
81
# File 'lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_DEBUG.rb', line 76

def readAP ( apsel, address)
	adrBank = (address >> 4) & 0xF
	adrReg  = (address >> 2) & 0x3
	select(apsel, adrBank)
	return @swdAPI.readSWD(TRUE, adrReg)
end

#readRBObject



73
74
75
# File 'lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_DEBUG.rb', line 73

def readRB
	return @swdAPI.readSWD(FALSE, 3)
end

#select(apsel, apbank) ⇒ Object



64
65
66
67
68
69
70
71
# File 'lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_DEBUG.rb', line 64

def select (apsel, apbank)
	if apsel != @curAP or apbank != @curBank then
		@curAP = apsel
		@curBank = apbank
		value = 0 | ((apsel  & 0xFF) << 24) | ((apbank & 0x0F) <<  4)
		@swdAPI.writeSWD(FALSE, 2, value)
	end
end

#statusObject



50
51
52
53
# File 'lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_DEBUG.rb', line 50

def status
	val= @swdAPI.readSWD(FALSE,1)
	return val
end

#writeAP(apsel, address, data) ⇒ Object



83
84
85
86
87
88
# File 'lib/HardsploitAPI/Modules/SWD/HardsploitAPI_SWD_DEBUG.rb', line 83

def writeAP (apsel, address, data)
adrBank = (address >> 4) & 0xF
adrReg  = (address >> 2) & 0x3
select(apsel, adrBank)
@swdAPI.writeSWD(TRUE, adrReg, data)
end