text
stringlengths 0
93.6k
|
---|
# The first write into the bootROM touches the lowbuffer.
|
self.current_buffer = 0
|
# Keep track of the total amount written.
|
self.total_written = 0
|
# Create a vulnerability backend for the given device.
|
try:
|
self.backend = HaxBackend.create_appropriate_backend(system_override=os_override, skip_checks=override_checks)
|
except IOError:
|
print("It doesn't look like we support your OS, currently. Sorry about that!\n")
|
sys.exit(-1)
|
# Grab a connection to the USB device itself.
|
self.dev = self._find_device(vid, pid)
|
# If we don't have a device...
|
if self.dev is None:
|
# ... and we're allowed to wait for one, wait indefinitely for one to appear...
|
if wait_for_device:
|
print("Waiting for a TegraRCM device to come online...")
|
while self.dev is None:
|
self.dev = self._find_device(vid, pid)
|
# ... or bail out.
|
else:
|
raise IOError("No TegraRCM device found?")
|
# Print any use-related warnings.
|
self.backend.print_warnings()
|
# Notify the user of which backend we're using.
|
print("Identified a {} system; setting up the appropriate backend.".format(self.backend.BACKEND_NAME))
|
def _find_device(self, vid=None, pid=None):
|
""" Attempts to get a connection to the RCM device with the given VID and PID. """
|
# Apply our default VID and PID if neither are provided...
|
vid = vid if vid else self.DEFAULT_VID
|
pid = pid if pid else self.DEFAULT_PID
|
# ... and use them to find a USB device.
|
return self.backend.find_device(vid, pid)
|
def read(self, length):
|
""" Reads data from the RCM protocol endpoint. """
|
return self.backend.read(length)
|
def write(self, data):
|
""" Writes data to the main RCM protocol endpoint. """
|
length = len(data)
|
packet_size = 0x1000
|
while length:
|
data_to_transmit = min(length, packet_size)
|
length -= data_to_transmit
|
chunk = data[:data_to_transmit]
|
data = data[data_to_transmit:]
|
self.write_single_buffer(chunk)
|
def write_single_buffer(self, data):
|
"""
|
Writes a single RCM buffer, which should be 0x1000 long.
|
The last packet may be shorter, and should trigger a ZLP (e.g. not divisible by 512).
|
If it's not, send a ZLP.
|
"""
|
self._toggle_buffer()
|
return self.backend.write_single_buffer(data)
|
def _toggle_buffer(self):
|
"""
|
Toggles the active target buffer, paralleling the operation happening in
|
RCM on the X1 device.
|
"""
|
self.current_buffer = 1 - self.current_buffer
|
def get_current_buffer_address(self):
|
""" Returns the base address for the current copy. """
|
return self.COPY_BUFFER_ADDRESSES[self.current_buffer]
|
def read_device_id(self):
|
""" Reads the Device ID via RCM. Only valid at the start of the communication. """
|
return self.read(16)
|
def switch_to_highbuf(self):
|
""" Switches to the higher RCM buffer, reducing the amount that needs to be copied. """
|
if self.get_current_buffer_address() != self.COPY_BUFFER_ADDRESSES[1]:
|
self.write(b'\0' * 0x1000)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.