Class: SWD_MEM_AP

Inherits:
Object
  • Object
show all
Defined in:
lib/HardsploitAPI/SWD/HardsploitAPI_SWD_MEM_AP.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(dp, apsel) ⇒ SWD_MEM_AP

Returns a new instance of SWD_MEM_AP.


11
12
13
14
15
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_MEM_AP.rb', line 11

def initialize( dp, apsel)
	@dp = dp
	@apsel = apsel
	csw(1,2) # 32-bit auto-incrementing addressing
end

Instance Method Details

#csw(addrInc, size) ⇒ Object


17
18
19
20
21
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_MEM_AP.rb', line 17

def csw ( addrInc, size)
     @dp.readAP(@apsel, 0x00)
     val = @dp.readRB() & 0xFFFFFF00
		@dp.writeAP(@apsel, 0x00, val + (addrInc << 4) + size)
end

#idcodeObject


22
23
24
25
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_MEM_AP.rb', line 22

def idcode
     @dp.readAP(@apsel, 0xFC)
     return @dp.readRB()
end

#readBlock(adr, count) ⇒ Object

1K boundaries and return 4K of data word alignement


36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_MEM_AP.rb', line 36

def readBlock ( adr, count)#1K boundaries and return 4K of data word alignement
		if count < 1 then
			raise "readBlock error : count must be >= 1"
		end
		if count > 1024 then
			raise "readBlock error : count must be <= 1024 "
		end
		csw(1, 2) # 32-bit single-incrementing addressing
		@dp.writeAP(@apsel, 0x04, adr)
		vals = Array.new
		@dp.readAP(@apsel, 0x0C) #For the first byte
		vals.push(*@dp.getAPI.readBlockAP(count-1))  #Hardcoded function to increase speed of read block
     return vals
end

#readWord(adr) ⇒ Object


26
27
28
29
30
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_MEM_AP.rb', line 26

def readWord (adr)
     @dp.writeAP(@apsel, 0x04, adr)
     @dp.readAP(@apsel, 0x0C)
     return @dp.readRB()
end

#writeBlock(adr, data) ⇒ Object

def writeBlockNonInc (adr, data)

		self.csw(0, 2) # 32-bit non-incrementing addressing
		for val in data

@dp.writeAP(@apsel, 0x04, adr) @dp.writeAP(@apsel, 0x0C, val) end self.csw(1, 2) # 32-bit auto-incrementing addressing end


60
61
62
63
64
65
66
67
68
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_MEM_AP.rb', line 60

def writeBlock (adr, data) #1K boundaries
   @dp.writeAP(@apsel, 0x04, adr)
	puts "writeBlock #{adr.to_s(16)}"

	@dp.getAPI.writeBlockAP(data)
	# for i in (0..data.size-1).step(4)
	# 		@dp.writeAP(@apsel, 0x0C, data[i].to_i + (data[i+1].to_i << 8) + (data[i+2].to_i << 16)+ (data[i+3].to_i << 24))
	# end
end

#writeHalfs(adr, data) ⇒ Object


70
71
72
73
74
75
76
77
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_MEM_AP.rb', line 70

def writeHalfs (adr, data)
     self.csw(2, 1) # 16-bit packed-incrementing addressing
     @dp.writeAP(@apsel, 0x04, adr)
     for val in data
         sleep(0.001)
         @dp.writeAP(@apsel, 0x0C, val)
		end
end

#writeWord(adr, data) ⇒ Object


31
32
33
34
35
# File 'lib/HardsploitAPI/SWD/HardsploitAPI_SWD_MEM_AP.rb', line 31

def writeWord (adr, data)
     @dp.writeAP(@apsel, 0x04, adr)
     @dp.writeAP(@apsel, 0x0C, data)
     return @dp.readRB()
end