MCPcopy
hub / github.com/RUB-NDS/PRET / do_nvram

Method do_nvram

pjl.py:698–784  ·  view source on GitHub ↗
(self, arg)

Source from the content-addressed store, hash-verified

696 # ------------------------[ nvram <operation> ]-----------------------
697 # nvram operations (brother-specific)
698 def do_nvram(self, arg):
699 # dump nvram
700 if arg.startswith("dump"):
701 bs = 2**9 # memory block size used for sampling
702 max = 2**18 # maximum memory address for sampling
703 steps = (
704 2**9
705 ) # number of bytes to dump at once (feedback-performance trade-off)
706 lpath = os.path.join(
707 "nvram", self.basename(self.target)
708 ) # local copy of nvram
709 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
710 # ******* sampling: populate memspace with valid addresses ******
711 if len(re.split("\s+", arg, 1)) > 1:
712 memspace = []
713 commands = ["@PJL RNVRAM ADDRESS=" +
714 str(n) for n in range(0, max, bs)]
715 self.chitchat(
716 "Sampling memory space (bs=" +
717 str(bs) + ", max=" + str(max) + ")"
718 )
719 for chunk in list(chunks(commands, steps)):
720 str_recv = self.cmd(c.EOL.join(chunk))
721 # break on unsupported printers
722 if not str_recv:
723 return
724 # collect valid memory addresses
725 blocks = re.findall("ADDRESS\s*=\s*(\d+)", str_recv)
726 for addr in blocks:
727 memspace += list(range(conv().int(addr),
728 conv().int(addr) + bs))
729 self.chitchat(str(len(blocks)) + " blocks found. ", "")
730 else: # use fixed memspace (quick & dirty but might cover interesting stuff)
731 memspace = (
732 list(range(0, 8192))
733 + list(range(32768, 33792))
734 + list(range(53248, 59648))
735 )
736 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
737 # ******* dumping: read nvram and write copy to local file ******
738 commands = ["@PJL RNVRAM ADDRESS=" + str(n) for n in memspace]
739 self.chitchat("Writing copy to " + lpath)
740 if os.path.isfile(lpath):
741 file().write(lpath, "") # empty file
742 for chunk in list(chunks(commands, steps)):
743 str_recv = self.cmd(c.EOL.join(chunk))
744 if not str_recv:
745 return # break on unsupported printers
746 else:
747 self.makedirs("nvram") # create nvram directory
748 data = "".join(
749 [conv().chr(n)
750 for n in re.findall("DATA\s*=\s*(\d+)", str_recv)]
751 )
752 file().append(lpath, data) # write copy of nvram to disk
753 output().dump(data) # print asciified output to screen
754 print()
755 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Callers

nothing calls this directly

Calls 15

cmdMethod · 0.95
help_nvramMethod · 0.95
chunksFunction · 0.90
convClass · 0.90
fileClass · 0.90
outputClass · 0.90
basenameMethod · 0.80
intMethod · 0.80
makedirsMethod · 0.80
chrMethod · 0.80
dumpMethod · 0.80
infoMethod · 0.80

Tested by

no test coverage detected