Method: HardsploitAPI#sendPacket

Defined in:
lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb

#sendPacket(packet_send) ⇒ Object

Send USB packet

  • packet

    array with bytes

Return number of byte sent



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/HardsploitAPI/Core/HardsploitAPI_USB_COMMUNICATION.rb', line 133

def sendPacket(packet_send)

  begin
    if packet_send.size <= 8191 then

      packet_send[0] = HardsploitAPI.lowByte(word:packet_send.size)
      packet_send[1] = HardsploitAPI.highByte(word:packet_send.size)

      #if a multiple of packet size add a value to explicit the end of trame

      if packet_send.size % 64 ==0 then
        packet_send.push 0
      end

      number_of_data_send = 0
      time = Benchmark.realtime  do
        number_of_data_send =  @dev.bulk_transfer(:endpoint=>OUT_ENDPOINT, :dataOut=>packet_send.pack('c*'),:timeout=>3000)
      end
      consoleSpeed "SEND #{((number_of_data_send/time)).round(2)}Bytes/s  SEND #{(number_of_data_send)}Bytes in  #{time.round(4)} s"
      if number_of_data_send ==  packet_send.size then
        return number_of_data_send
       else
        raise ERROR::USB_ERROR
       end
    else
      raise ERROR::USB_ERROR
    end
  rescue LIBUSB::ERROR_NO_DEVICE
    #TRY TO RECONNECT maybe error due to disconnecting and reconnecting board

    reconncet
  rescue
    raise ERROR::USB_ERROR
  end
end