old_contents: import logging
  from rex import Vulnerability
  from rex.exploit import CannotExploit
  from rex.exploit.cgc import CGCType1CircumstantialExploit
  from ..technique import Technique
  
  l = logging.getLogger("rex.exploit.techniques.linux.circumstantial_set_register")
  
  class CircumstantialSetRegister(Technique):
  
      name = "circumstantially_set_register"
  
      applicable_to = ['cgc']
  
      cgc_registers = ["eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi"]
  
      # this technique should create an exploit which is a type1 pov
      pov_type = 1
  
      def set_register(self, register):
          '''
          set a register with shellcode on cgc
          '''
  
          # can only exploit ip overwrites
          ct = self.crash.crash_type
          if ct != Vulnerability.IP_OVERWRITE and ct != Vulnerability.PARTIAL_IP_OVERWRITE:
              raise CannotExploit("[%s] cannot control ip" % self.name)
  
  
          state = self.crash.state
  
          # see if the register value is nearly unconstrained
          reg = getattr(state.regs, register)
  
          size = reg.size()
          test_val_0 = 0x0
          test_val_1 = (1 << size) - 1
          test_val_2 = int("1010"*16, 2) % (1 << size)
          test_val_3 = int("0101"*16, 2) % (1 << size)
  
          if not state.satisfiable(extra_constraints=(reg == test_val_0,)):
              raise CannotExploit("register %s's value does not appear to be unconstrained", register)
          if not state.satisfiable(extra_constraints=(reg == test_val_1,)):
              raise CannotExploit("register %s's value does not appear to be unconstrained", register)
          if not state.satisfiable(extra_constraints=(reg == test_val_2,)):
              raise CannotExploit("register %s's value does not appear to be unconstrained", register)
          if not state.satisfiable(extra_constraints=(reg == test_val_3,)):
              raise CannotExploit("register %s's value does not appear to be unconstrained", register)
  
          l.info("can circumstantially set register %s", register)
  
          return CGCType1CircumstantialExploit(self.crash, register)
  
      def apply(self, **kwargs):
  
          register_setters = [ ]
          for register in CircumstantialSetRegister.cgc_registers:
              try:
                  register_setters.append(self.set_register(register))
              except CannotExploit as e:
                  l.warning("could not set register %s circumstantially (%s)", register, e.message)
  
          return register_setters
  
new_contents: import logging
  from rex import Vulnerability
  from rex.exploit import CannotExploit
  from rex.exploit.cgc import CGCType1CircumstantialExploit
  from ..technique import Technique
  
  l = logging.getLogger("rex.exploit.techniques.linux.circumstantial_set_register")
  
  class CircumstantialSetRegister(Technique):
  
      name = "circumstantially_set_register"
  
      applicable_to = ['cgc']
  
      cgc_registers = ["eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi"]
  
      # this technique should create an exploit which is a type1 pov
      pov_type = 1
  
      def set_register(self, register):
          '''
          set a register with shellcode on cgc
          '''
  
          # can only exploit ip overwrites
          ct = self.crash.crash_type
          if ct != Vulnerability.IP_OVERWRITE and ct != Vulnerability.PARTIAL_IP_OVERWRITE:
              raise CannotExploit("[%s] cannot control ip" % self.name)
  
  
          state = self.crash.state
  
          # see if the register value is nearly unconstrained
          reg = getattr(state.regs, register)
  
          size = reg.size()
          test_val_0 = 0x0
          test_val_1 = (1 << size) - 1
          test_val_2 = int("1010"*16, 2) % (1 << size)
          test_val_3 = int("0101"*16, 2) % (1 << size)
  
          if not state.satisfiable(extra_constraints=(reg == test_val_0,)):
              raise CannotExploit("register %s's value does not appear to be unconstrained" % register)
          if not state.satisfiable(extra_constraints=(reg == test_val_1,)):
              raise CannotExploit("register %s's value does not appear to be unconstrained" % register)
          if not state.satisfiable(extra_constraints=(reg == test_val_2,)):
              raise CannotExploit("register %s's value does not appear to be unconstrained" % register)
          if not state.satisfiable(extra_constraints=(reg == test_val_3,)):
              raise CannotExploit("register %s's value does not appear to be unconstrained" % register)
  
          l.info("can circumstantially set register %s", register)
  
          return CGCType1CircumstantialExploit(self.crash, register)
  
      def apply(self, **kwargs):
  
          register_setters = [ ]
          for register in CircumstantialSetRegister.cgc_registers:
              try:
                  register_setters.append(self.set_register(register))
              except CannotExploit as e:
                  l.warning("could not set register %s circumstantially (%s)", register, e.message)
  
          return register_setters
  
subject: Format message in CannotExploit exception correctly