Class: HardsploitAPI_PARALLEL
- Inherits:
-
Object
- Object
- HardsploitAPI_PARALLEL
- Defined in:
- lib/HardsploitAPI/Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.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
- #clearStatusRegisterOfMemory ⇒ Object
- #eraseBlockMemory(blockAddress) ⇒ Object
-
#initialize ⇒ HardsploitAPI_PARALLEL
constructor
A new instance of HardsploitAPI_PARALLEL.
-
#read_Memory_WithoutMultiplexing(path:, addressStart:, addressStop:, bits8_or_bits16_DataSize:, latency:) ⇒ Object
- Read parallele memory in asynchronous mode (blocking function) but callBack data is used to receive packet *
addressStart
- 32 bits address *
addressStop
- 32 bits address *
bits8_or_bits16_DataSize
- 0 for 8 bits operation & 1 for 16 bits operation *
latency
-
latency in ns range 7ns to 1600ns=1,6ms Return USB_STATE End with TIMEOUT_RECEIVE but need to check if received the right number of bytes to ensure all is correct.
- 0 for 8 bits operation & 1 for 16 bits operation *
- 32 bits address *
- 32 bits address *
- Read parallele memory in asynchronous mode (blocking function) but callBack data is used to receive packet *
- #readByteFromMemory(address) ⇒ Object
- #readDeviceIdMemory ⇒ Object
- #readManufactuerCodeMemory ⇒ Object
- #readMode ⇒ Object
- #unlockBlock(blockAddress) ⇒ Object
- #write_command_Memory_WithoutMultiplexing(address, data) ⇒ Object
- #writeByteToMemory(address, value) ⇒ Object
Constructor Details
#initialize ⇒ HardsploitAPI_PARALLEL
Returns a new instance of HardsploitAPI_PARALLEL.
11 12 13 14 |
# File 'lib/HardsploitAPI/Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.rb', line 11 def initialize #to be sure the singleton was initialize HardsploitAPI.instance.connect end |
Instance Method Details
#clearStatusRegisterOfMemory ⇒ Object
63 64 65 66 |
# File 'lib/HardsploitAPI/Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.rb', line 63 def clearStatusRegisterOfMemory #Clear Statut register write_command_Memory_WithoutMultiplexing(0x000000,0x50) end |
#eraseBlockMemory(blockAddress) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/HardsploitAPI/Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.rb', line 38 def eraseBlockMemory(blockAddress) #Read Five Word write_command_Memory_WithoutMultiplexing(blockAddress,0x0020) #Block erase command statut = write_command_Memory_WithoutMultiplexing(blockAddress,0x00D0) #Confirm Block erase command timeout = 10 # while (statut != 128 ) && (timeout >= 0) # # puts "#{statut} #{timeout}" # statut = readByteFromMemory(0) #read statut register # sleep(100) # if timeout == 0 then # return statut # else # timeout = timeout-1 # end # end for ty in 0..4 puts readByteFromMemory(0) end puts "Return timeout" return statut end |
#read_Memory_WithoutMultiplexing(path:, addressStart:, addressStop:, bits8_or_bits16_DataSize:, latency:) ⇒ Object
Read parallele memory in asynchronous mode (blocking function) but callBack data is used to receive packet
addressStart
-
32 bits address
addressStop
-
32 bits address
bits8_or_bits16_DataSize
-
0 for 8 bits operation & 1 for 16 bits operation
latency
-
latency in ns range 7ns to 1600ns=1,6ms
Return USB_STATE End with TIMEOUT_RECEIVE but need to check if received the right number of bytes to ensure all is correct
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/HardsploitAPI/Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.rb', line 148 def read_Memory_WithoutMultiplexing(path:,addressStart: , addressStop:, bits8_or_bits16_DataSize:, latency:) numberOfByteReaded = 0 packet = HardsploitAPI.prepare_packet #Chek if 8bits or 16 bits if bits8_or_bits16_DataSize == true then packet.push 1 else packet.push 0 end #Check latency value if ((latency >= 7) and (latency <= 1600)) then packet.push (latency/6.66).floor else raise TypeError, 'Latency value must be from 7 to 1695' end #Check address if (addressStop <= addressStart ) then raise TypeError, 'Stop address is less than start address' end packet.push ((addressStart & 0xFF000000) >> 24 ) #AddStart3 packet.push ((addressStart & 0x00FF0000) >> 16 ) #AddStart2 packet.push ((addressStart & 0x0000FF00) >> 8 ) #AddStart1 packet.push ((addressStart & 0x000000FF) >> 0) #AddStart0 packet.push 0x10 #Memory read command packet.push ((addressStop & 0xFF000000) >> 24 ) #AddStart3 packet.push ((addressStop & 0x00FF0000) >> 16 ) #AddStop2 packet.push ((addressStop & 0x0000FF00) >> 8 ) #AddStop1 packet.push ((addressStop & 0x000000FF) >> 0) #AddStop0 HardsploitAPI.instance.sendPacket(packet) if bits8_or_bits16_DataSize then sizeCalculated = (addressStop-addressStart+1) else sizeCalculated = (addressStop-addressStart+1)*2 end file = File.open(path,"wb") numberOfByteReaded = 0 while true tmp= HardsploitAPI.instance.receiveDATA(2000) #remove header (4 bytes 2 for size 2 for type of command) tmp = tmp.bytes.drop(4) file.write tmp.pack('C*') numberOfByteReaded = numberOfByteReaded + tmp.size HardsploitAPI.instance.consoleInfo "Receive #{numberOfByteReaded} of #{sizeCalculated}" if numberOfByteReaded >= sizeCalculated then file.close #Exit because we received all data return end end end |
#readByteFromMemory(address) ⇒ Object
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/HardsploitAPI/Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.rb', line 99 def readByteFromMemory(address) 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(HardsploitAPI::USB_COMMAND::FPGA_COMMAND) packet.push HardsploitAPI.highByte(HardsploitAPI::USB_COMMAND::FPGA_COMMAND) packet.push 0x50 #Command RAW COMMUNICATION TO FPGA FIFO #16 bits packet.push 0 packet.push (1500/6.66).floor packet.push ((address & 0xFF000000) >> 24 ) #AddStart3 packet.push ((address & 0x00FF0000) >> 16 ) #AddStart2 packet.push ((address & 0x0000FF00) >> 8 ) #AddStart1 packet.push ((address & 0x000000FF) >> 0) #AddStart0 packet.push 0x10 #Memory read command packet.push ((address & 0xFF000000) >> 24 ) #AddStart3 packet.push ((address & 0x00FF0000) >> 16 ) #AddStop2 packet.push ((address & 0x0000FF00) >> 8 ) #AddStop1 packet.push ((address & 0x000000FF) >> 0) #AddStop0 result = sendAndReceiveDATA(packet,1000) if result == USB_STATE::TIMEOUT_RECEIVE then return "TIMEOUT" else if result.size == 6 then return HardsploitAPI.BytesToInt(result[4] , result[5]) else raise "BAD RESPONSE" end end end |
#readDeviceIdMemory ⇒ Object
21 22 23 24 |
# File 'lib/HardsploitAPI/Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.rb', line 21 def readDeviceIdMemory write_command_Memory_WithoutMultiplexing(0x00000000,0x90) #ReadDeviceIdentifierCommand return readByteFromMemory(0)#Read 0 end |
#readManufactuerCodeMemory ⇒ Object
16 17 18 19 |
# File 'lib/HardsploitAPI/Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.rb', line 16 def readManufactuerCodeMemory write_command_Memory_WithoutMultiplexing(0x00000000,0x90) #ReadDeviceIdentifierCommand return readByteFromMemory(1) #Read from 1 to 1 = read 1 byte at 1 end |
#readMode ⇒ Object
33 34 35 36 |
# File 'lib/HardsploitAPI/Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.rb', line 33 def readMode #go in read mode write_command_Memory_WithoutMultiplexing(0x000000,0x00FF) end |
#unlockBlock(blockAddress) ⇒ Object
68 69 70 71 72 |
# File 'lib/HardsploitAPI/Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.rb', line 68 def unlockBlock (blockAddress) write_command_Memory_WithoutMultiplexing(blockAddress,0x0060) #Lock Block Command write_command_Memory_WithoutMultiplexing(blockAddress,0x00D0) #UnLock Command return readByteFromMemory(0x000000) #read statut register end |
#write_command_Memory_WithoutMultiplexing(address, data) ⇒ Object
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/Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.rb', line 74 def write_command_Memory_WithoutMultiplexing(address,data) packet = HardsploitAPI.prepare_packet packet.push 0 #16 bits packet.push (1500/6.66).floor #latency at 1500ns packet.push ((address & 0xFF000000) >> 24 ) #AddStart3 packet.push ((address & 0x00FF0000) >> 16 ) #AddStart2 packet.push ((address & 0x0000FF00) >> 8 ) #AddStart1 packet.push ((address & 0x000000FF) >> 0) #AddStart0 packet.push 0x20 #Memory write command packet.push ((data & 0xFF00) >> 8 ) #Data HIGHT BYTE packet.push ((data & 0xFF) >> 0) #Data LOW BYTE result = HardsploitAPI.instance.sendAndReceiveDATA(packet,1000) if result == USB_STATE::TIMEOUT_RECEIVE then raise "TIMEOUT" elsif result[4] == (data & 0xFF) return readByteFromMemory(0) else raise "ERROR BAD RESPONSE" end end |
#writeByteToMemory(address, value) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/HardsploitAPI/Modules/NO_MUX_PARALLEL_MEMORY/HardsploitAPI_NO_MUX_PARALLEL_MEMORY.rb', line 26 def writeByteToMemory(address,value) #Write data in word mode and read Five status register write_command_Memory_WithoutMultiplexing(address,0x0040) write_command_Memory_WithoutMultiplexing(address,value) return readByteFromMemory(0) end |