示例#1
0
    def prompt(self):
        """Generates the injector util prompt"""
        while True:
            try:
                if self.rf4ce_frame.frame_ciphered:
                    ciphered_status = "ciphered"
                else:
                    ciphered_status = "plain"
                a = hue.lightblue("{}".format(self.rf4ce_frame.frame_counter))
                b = hue.lightblue("0x{:02x}".format(
                    self.rf4ce_frame.profile_indentifier))
                c = hue.lightblue(ciphered_status)
                cmd = raw_input("({} - {} - {})>>> ".format(a, b, c))
            except KeyboardInterrupt:
                raise StopIteration

            if cmd.startswith("profile"):
                try:
                    yield InjectorCmd(InjectorCmd.PROFILE, cmd.split()[1])
                except:
                    self.log("Malformed command", hue.bad)
                    continue

            elif cmd.startswith("counter"):
                try:
                    yield InjectorCmd(InjectorCmd.COUNTER, cmd.split()[1])
                except:
                    self.log("Malformed command", hue.bad)
                    continue

            elif cmd.startswith("delay"):
                try:
                    yield InjectorCmd(InjectorCmd.DELAY, cmd.split()[1])
                except:
                    self.log("Malformed command", hue.bad)
                    continue

            elif cmd.startswith("ciphered"):
                try:
                    yield InjectorCmd(InjectorCmd.CIPHERED, cmd.split()[1])
                except:
                    self.log("Malformed command", hue.bad)
                    continue

            elif cmd.startswith("help"):
                yield InjectorCmd(InjectorCmd.HELP, None)

            elif cmd.startswith("exit"):
                raise StopIteration

            else:
                for packet in cmd.split():
                    try:
                        data = binascii.unhexlify(packet)
                    except:
                        self.log("Malformed command", hue.bad)
                        continue
                    yield InjectorCmd(InjectorCmd.PACKET, data)
示例#2
0
	def __repr__(self):
		if self.frame_type == Rf4ceConstants.FRAME_TYPE_DATA:
			type = hue.lightblue("DATA") + " - "
			type += "profile:" + hue.lightblue("0x{:x}".format(self.profile_indentifier))
		elif self.frame_type == Rf4ceConstants.FRAME_TYPE_COMMAND:
			type = hue.lightblue("COMMAND") + " - "
			type += "cmd:" + hue.lightblue("0x{:x}".format(self.command))
		elif self.frame_type == Rf4ceConstants.FRAME_TYPE_VENDOR:
			type = hue.lightblue("VENDOR") + " - "
			type += "profile:" + hue.lightblue("0x{:x}").format(self.profile_indentifier)
			type += " - vendor:" + hue.lightblue("0x{:x}".format(self.vendor_indentifier))

		data = hue.bold(binascii.hexlify(self.payload).decode())
		counter = hue.lightblue("0x{:x}".format(self.frame_counter))

		result = "({}) -> ({}) : ".format(self.source, self.destination)
		result += "[{} - counter:{}] : {}".format(type, counter, data)

		return result
示例#3
0
文件: train.py 项目: darglein/npbg
def print_args(args, default_args):
    from huepy import bold, lightblue, orange, lightred, green, red

    args_v = vars(args)
    default_args_v = vars(default_args)
    
    print(bold(lightblue(' - ARGV: ')), '\n', ' '.join(sys.argv), '\n')
    # Get list of default params and changed ones    
    s_default = ''     
    s_changed = ''
    for arg in sorted(args_v.keys()):
        value = args_v[arg]
        if default_args_v[arg] == value:
            s_default += f"{lightblue(arg):>50}  :  {orange(value if value != '' else '<empty>')}\n"
        else:
            s_changed += f"{lightred(arg):>50}  :  {green(value)} (default {orange(default_args_v[arg] if default_args_v[arg] != '' else '<empty>')})\n"

    print(f'{bold(lightblue("Unchanged args")):>69}\n\n'
          f'{s_default[:-1]}\n\n'
          f'{bold(red("Changed args")):>68}\n\n'
          f'{s_changed[:-1]}\n')