Example #1
0
  /**
   * Perform the 'alias' command.
   *
   * @param session JSwat session on which to operate.
   * @param args Tokenized string of command arguments.
   * @param out Output to write messages to.
   */
  public void perform(Session session, CommandArguments args, Log out) {
    CommandManager cmdman = (CommandManager) session.getManager(CommandManager.class);
    if (args.hasMoreTokens()) {
      String aliasName = args.nextToken();
      if (args.hasMoreTokens()) {
        // Grab rest of string as alias value.
        // Be sure to preserve the quotes and escapes.
        args.returnAsIs(true);
        String alias = args.rest().trim();
        if (alias.charAt(0) == '"' && alias.charAt(alias.length() - 1) == '"') {
          // Must remove the enclosing quotes because the
          // command parser doesn't handle that.
          alias = alias.substring(1, alias.length() - 1);
        }

        // Add the command alias to the list.
        cmdman.createAlias(aliasName, alias);
        out.writeln(Bundle.getString("alias.defined") + ' ' + aliasName);
      } else {
        // One argument, show the alias definition.
        String alias = cmdman.getAlias(aliasName);
        if (alias == null) {
          throw new CommandException(Bundle.getString("alias.undefined") + ' ' + aliasName);
        } else {
          out.writeln("alias " + aliasName + ' ' + alias);
        }
      }
    } else {
      // No arguments, show the defined aliases.
      cmdman.listAliases();
    }
  } // perform
Example #2
0
  /**
   * Perform the 'history' command.
   *
   * @param session JSwat session on which to operate.
   * @param args Tokenized string of command arguments.
   * @param out Output to write messages to.
   */
  public void perform(Session session, CommandArguments args, Log out) {
    CommandManager cmdman = (CommandManager) session.getManager(CommandManager.class);

    if (args.hasMoreTokens()) {
      String arg = args.nextToken();
      try {
        int size = Integer.parseInt(arg);
        cmdman.setHistorySize(size);
        out.writeln(Bundle.getString("history.sizeSet"));
      } catch (NumberFormatException nfe) {
        throw new CommandException(Bundle.getString("history.invalidSize"));
      } catch (IllegalArgumentException iae) {
        throw new CommandException(Bundle.getString("history.invalidRange"));
      }
    } else {
      cmdman.displayHistory();
    }
  } // perform
  /**
   * Returns the value of this node.
   *
   * @param context evaluation context.
   * @return a Number.
   * @throws EvaluationException if an error occurred during evaluation.
   */
  protected Object eval(EvaluationContext context) throws EvaluationException {

    Object o1 = getChild(0).evaluate(context);

    if (isLong(o1)) {
      return new Long(~getLongValue(o1));
    } else if (isNumber(o1) && !isFloating(o1)) {
      return new Integer(~getIntValue(o1));
    } else {
      throw new EvaluationException(Bundle.getString("error.oper.int"), getToken());
    }
  } // eval
Example #4
0
 /**
  * Returns a String representation of this.
  *
  * @param terse true to keep the description terse.
  * @return string of this.
  */
 public String toString(boolean terse) {
   StringBuffer buf = new StringBuffer(80);
   if (referenceSpec == null) {
     return "<not initialized>";
   }
   String cname = referenceSpec.toString();
   if (terse) {
     cname = Names.justTheName(cname);
   }
   buf.append(cname);
   buf.append(':');
   buf.append(lineNumber);
   if (!terse) {
     buf.append(' ');
     if (suspendPolicy == EventRequest.SUSPEND_ALL) {
       buf.append(Bundle.getString("suspendAll"));
     } else if (suspendPolicy == EventRequest.SUSPEND_EVENT_THREAD) {
       buf.append(Bundle.getString("suspendThread"));
     } else if (suspendPolicy == EventRequest.SUSPEND_NONE) {
       buf.append(Bundle.getString("suspendNone"));
     }
   }
   return buf.toString();
 }
  /**
   * Returns the value of this node.
   *
   * @param context evaluation context.
   * @return a Number.
   * @throws EvaluationException if an error occurred during evaluation.
   */
  protected Object eval(EvaluationContext context) throws EvaluationException {

    Object o1 = getChild(0).evaluate(context);
    Object o2 = getChild(1).evaluate(context);
    if (isNumber(o1) && isNumber(o2)) {
      if (isFloating(o1) || isFloating(o2)) {
        if (isDouble(o1) || isDouble(o2)) {
          double d1 = getDoubleValue(o1);
          double d2 = getDoubleValue(o2);
          return new Double(d1 / d2);
        } else {
          float f1 = getFloatValue(o1);
          float f2 = getFloatValue(o2);
          return new Float(f1 / f2);
        }
      } else {
        if (isLong(o1) || isLong(o2)) {
          long l1 = getLongValue(o1);
          long l2 = getLongValue(o2);
          if (l2 == 0L) {
            throw new EvaluationException(Bundle.getString("error.oper.div.zero"), getToken());
          }
          return new Long(l1 / l2);
        } else {
          int i1 = getIntValue(o1);
          int i2 = getIntValue(o2);
          if (i2 == 0) {
            throw new EvaluationException(Bundle.getString("error.oper.div.zero"), getToken());
          }
          return new Integer(i1 / i2);
        }
      }
    } else {
      throw new EvaluationException(Bundle.getString("error.oper.num"), getToken());
    }
  } // eval
Example #6
0
  /**
   * Perform the 'capture' command.
   *
   * @param session debugging session on which to operate.
   * @param args Tokenized string of command arguments.
   * @param out Output to write messages to.
   */
  public void perform(Session session, CommandArguments args, Log out) {
    // Get the current capture settings.
    boolean captureStdout = Capture.isOutputEnabled(session);
    boolean captureFile = Capture.isFileEnabled(session);
    String filename = Capture.getFilename(session);

    if (args.hasMoreTokens()) {
      // Modify the capture settings.

      while (args.hasMoreTokens()) {
        String token = args.nextToken();
        boolean enable = false;
        boolean disable = false;
        if (token.startsWith("+")) {
          enable = true;
          token = token.substring(1);
        } else if (token.startsWith("-")) {
          disable = true;
          token = token.substring(1);
        }
        if (token.equals("stdout")) {
          captureStdout = enable || !disable && !captureStdout;
        } else if (token.equals("file")) {
          captureFile = enable || !disable && !captureFile;
          if (captureFile) {
            if (args.hasMoreTokens()) {
              filename = args.nextToken();
            } else {
              throw new MissingArgumentsException(Bundle.getString("capture.missingFilename"));
            }
          }
        } else {
          throw new CommandException(Bundle.getString("capture.unknownType") + ' ' + token);
        }
      }

      Capture.setOutputEnabled(captureStdout, session);

      File file = null;
      if (captureFile) {
        // Create the file and check that it exists.
        file = new File(filename);
        if (file.exists() && !file.canWrite()) {
          throw new CommandException(Bundle.getString("capture.readOnlyFile"));
        }
      }

      // Enable or disable the file capture.
      try {
        Capture.setFileEnabled(captureFile, file, session);
      } catch (FileNotFoundException fnfe) {
        throw new CommandException(Bundle.getString("capture.fileNotFound"));
      } catch (IOException ioe) {
        throw new CommandException(ioe);
      }
    } else {
      // Display the capture settings.
      StringBuffer buf = new StringBuffer();
      if (captureStdout) {
        buf.append(Bundle.getString("capture.stdout"));
        buf.append('\n');
      }
      if (captureFile) {
        buf.append(Bundle.getString("capture.file") + ' ' + filename);
        buf.append('\n');
      }
      if (buf.length() > 0) {
        out.write(buf.toString());
      } else {
        out.writeln(Bundle.getString("capture.none"));
      }
    }
  } // perform
Example #7
0
    int queryPurchases(Inventory inv, String itemType) throws JSONException, RemoteException {
        // Query purchases
        logDebug("Querying owned items, item type: " + itemType);
        logDebug("Package name: " + mContext.getPackageName());
        boolean verificationFailed = false;
        String continueToken = null;

        do {
            logDebug("Calling getPurchases with continuation token: " + continueToken);
            Bundle ownedItems = mService.getPurchases(3, mContext.getPackageName(),
                    itemType, continueToken);

            int response = getResponseCodeFromBundle(ownedItems);
            logDebug("Owned items response: " + String.valueOf(response));
            if (response != BILLING_RESPONSE_RESULT_OK) {
                logDebug("getPurchases() failed: " + getResponseDesc(response));
                return response;
            }
            if (!ownedItems.containsKey(RESPONSE_INAPP_ITEM_LIST)
                    || !ownedItems.containsKey(RESPONSE_INAPP_PURCHASE_DATA_LIST)
                    || !ownedItems.containsKey(RESPONSE_INAPP_SIGNATURE_LIST)) {
                logError("Bundle returned from getPurchases() doesn't contain required fields.");
                return IABHELPER_BAD_RESPONSE;
            }

            ArrayList<String> ownedSkus = ownedItems.getStringArrayList(
                        RESPONSE_INAPP_ITEM_LIST);
            ArrayList<String> purchaseDataList = ownedItems.getStringArrayList(
                        RESPONSE_INAPP_PURCHASE_DATA_LIST);
            ArrayList<String> signatureList = ownedItems.getStringArrayList(
                        RESPONSE_INAPP_SIGNATURE_LIST);

            for (int i = 0; i < purchaseDataList.size(); ++i) {
                String purchaseData = purchaseDataList.get(i);
                String signature = signatureList.get(i);
                String sku = ownedSkus.get(i);
                if (Security.verifyPurchase(mSignatureBase64, purchaseData, signature)) {
                    logDebug("Sku is owned: " + sku);
                    Purchase purchase = new Purchase(itemType, purchaseData, signature);

                    if (TextUtils.isEmpty(purchase.getToken())) {
                        logWarn("BUG: empty/null token!");
                        logDebug("Purchase data: " + purchaseData);
                    }

                    // Record ownership and token
                    inv.addPurchase(purchase);
                }
                else {
                    logWarn("Purchase signature verification **FAILED**. Not adding item.");
                    logDebug("   Purchase data: " + purchaseData);
                    logDebug("   Signature: " + signature);
                    verificationFailed = true;
                }
            }

            continueToken = ownedItems.getString(INAPP_CONTINUATION_TOKEN);
            logDebug("Continuation token: " + continueToken);
        } while (!TextUtils.isEmpty(continueToken));

        return verificationFailed ? IABHELPER_VERIFICATION_FAILED : BILLING_RESPONSE_RESULT_OK;
    }
Example #8
0
  /**
   * Perform the 'hotswap' command.
   *
   * @param session JSwat session on which to operate.
   * @param args Tokenized string of command arguments.
   * @param out Output to write messages to.
   */
  public void perform(Session session, CommandArguments args, Log out) {
    if (!session.isActive()) {
      throw new CommandException(Bundle.getString("noActiveSession"));
    }

    if (!args.hasMoreTokens()) {
      throw new MissingArgumentsException();
    }

    // Name of class is required; name of .class file is optional.
    String cname = args.nextToken();
    String cfile = null;
    if (args.hasMoreTokens()) {
      cfile = args.nextToken();
    }

    // Find the ReferenceType for this class.
    VirtualMachine vm = session.getConnection().getVM();
    List classes = vm.classesByName(cname);
    if (classes.size() == 0) {
      throw new CommandException(Bundle.getString("hotswap.noSuchClass"));
    }
    ReferenceType clazz = (ReferenceType) classes.get(0);

    // Did the user give us a .class file?
    InputStream is = null;
    if (cfile == null) {
      // Try to find the .class file.
      PathManager pathman = (PathManager) session.getManager(PathManager.class);
      SourceSource src = pathman.mapClass(clazz);
      if (src == null) {
        throw new CommandException(Bundle.getString("hotswap.fileNotFound"));
      }
      is = src.getInputStream();
    } else {
      // A filename was given, just open it.
      try {
        is = new FileInputStream(cfile);
      } catch (FileNotFoundException fnfe) {
        throw new CommandException(Bundle.getString("hotswap.fileNotFound"));
      }
    }

    // Do the actual hotswap operation.
    try {
      Classes.hotswap(clazz, is, vm);
      out.writeln(Bundle.getString("hotswap.success"));
    } catch (UnsupportedOperationException uoe) {
      if (!vm.canRedefineClasses()) {
        throw new CommandException(Bundle.getString("hotswap.noHotSwap"));
      } else if (!vm.canAddMethod()) {
        throw new CommandException(Bundle.getString("hotswap.noAddMethod"));
      } else if (!vm.canUnrestrictedlyRedefineClasses()) {
        throw new CommandException(Bundle.getString("hotswap.noUnrestricted"));
      } else {
        throw new CommandException(Bundle.getString("hotswap.unsupported"));
      }
    } catch (IOException ioe) {
      throw new CommandException(Bundle.getString("hotswap.errorReadingFile") + ' ' + ioe);
    } catch (NoClassDefFoundError ncdfe) {
      throw new CommandException(Bundle.getString("hotswap.wrongClass"));
    } catch (VerifyError ve) {
      throw new CommandException(Bundle.getString("hotswap.verifyError") + ' ' + ve);
    } catch (UnsupportedClassVersionError ucve) {
      throw new CommandException(Bundle.getString("hotswap.versionError") + ' ' + ucve);
    } catch (ClassFormatError cfe) {
      throw new CommandException(Bundle.getString("hotswap.formatError") + ' ' + cfe);
    } catch (ClassCircularityError cce) {
      throw new CommandException(Bundle.getString("hotswap.circularity") + ' ' + cce);
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException ioe) {
        }
      }
    }
  } // perform