/** * Tells the Byteman agent to list all deployed rules. * * @return all the rules deployed in the Byteman agent * * @throws Exception * if the request failed */ public String listAllRules() throws Exception { return submitRequest("LIST\n"); }
/** * Tells the Byteman agent to delete all rules. This will effectively revert * the Byteman's VM to its original state; that is, no Byteman injected * byte-code will be invoked. * * @return the results of the delete-all request to the Byteman agent * * @throws Exception * if the request failed */ public String deleteAllRules() throws Exception { return submitRequest("DELETEALL\n"); }
/** * Returns the version of the remote Byteman agent. * * @return the version of the remote Byteman agent * * @throws Exception * if the request failed */ public String getAgentVersion() throws Exception { String version = submitRequest("VERSION\n"); return (version != null) ? version.trim() : "0"; }
/** * Returns a list of jars that were added to the Byteman agent's boot classloader. * * @return list of jars that were added to the boot classloader * * @throws Exception * if the request failed */ public List<String> getLoadedBootClassloaderJars() throws Exception { String results = submitRequest("LISTBOOT\n"); List<String> jars = new ArrayList<String>(); BufferedReader reader = new BufferedReader(new StringReader(results)); String line = reader.readLine(); while (line != null) { jars.add(line); line = reader.readLine(); } return jars; }
/** * Returns a list of jars that were added to the Byteman agent's system classloader. * * @return list of jars that were added to the system classloader * * @throws Exception * if the request failed */ public List<String> getLoadedSystemClassloaderJars() throws Exception { String results = submitRequest("LISTSYS\n"); List<String> jars = new ArrayList<String>(); BufferedReader reader = new BufferedReader(new StringReader(results)); String line = reader.readLine(); while (line != null) { jars.add(line); line = reader.readLine(); } return jars; }
/** * old version which uses a Map * @param rules the rules to be added * @return the results of the deployment * @throws Exception * if the request failed */ @Deprecated public String addRules(Map<String,String> rules) throws Exception { if (rules == null || rules.size() == 0) { return ""; } StringBuilder str = new StringBuilder("LOAD\n"); for (Map.Entry<String, String> entry : rules.entrySet()) { str.append("SCRIPT " + entry.getKey() + '\n'); str.append(entry.getValue()).append('\n'); str.append("ENDSCRIPT\n"); } str.append("ENDLOAD\n"); return submitRequest(str.toString()); }
/** * Sets system properties in the Byteman agent VM. * If Byteman was configured for strict mode, only Byteman related * system properties will be allowed to be set. * * @param propsToSet * system properties to set in the Byteman agent VM * * @return response from the Byteman agent * * @throws Exception * if the request failed */ public String setSystemProperties(Properties propsToSet) throws Exception { if (propsToSet == null || propsToSet.size() == 0) { return ""; } StringBuilder str = new StringBuilder("SETSYSPROPS\n"); for (Map.Entry<Object, Object> entry : propsToSet.entrySet()) { str.append(entry.getKey()).append('=').append(entry.getValue()).append('\n'); } str.append("ENDSETSYSPROPS\n"); return submitRequest(str.toString()); }
/** * This adds the given list of files to the Byteman agent's <em>system</em> * classloader. Note that if the Byteman agent is running on a remote * machine, the paths must resolve on that remote host (i.e. the file must * exist on the remote machine at the paths given to this method). * * @param jarPaths * the paths to the library .jar files that will be loaded * * @return the result of the load as reported by Byteman * * @throws Exception * if the request failed */ public String addJarsToSystemClassloader(List<String> jarPaths) throws Exception { if (jarPaths == null || jarPaths.size() == 0) { return ""; } StringBuilder str = new StringBuilder("SYS\n"); for (String jarPath : jarPaths) { str.append(jarPath).append("\n"); } str.append("ENDSYS\n"); return submitRequest(str.toString()); }
/** * This adds the given list of files to the Byteman agent's <em>boot</em> * classloader. Note that if the Byteman agent is running on a remote * machine, the paths must resolve on that remote host (i.e. the file must * exist on the remote machine at the paths given to this method). * * @param jarPaths * the paths to the library .jar files that will be loaded * * @return the result of the load as reported by Byteman * * @throws Exception * if the request failed */ public String addJarsToBootClassloader(List<String> jarPaths) throws Exception { if (jarPaths == null || jarPaths.size() == 0) { return ""; } StringBuilder str = new StringBuilder("BOOT\n"); for (String jarPath : jarPaths) { str.append(jarPath).append("\n"); } str.append("ENDBOOT\n"); return submitRequest(str.toString()); }
/** * old version which uses a Map * @param rules the rules to be deleted * @return the results of the deletion * @throws Exception * if the request failed */ @Deprecated public String deleteRules(Map<String,String> rules) throws Exception { if (rules == null || rules.size() == 0) { return ""; } StringBuilder str = new StringBuilder("DELETE\n"); for (Map.Entry<String, String> entry : rules.entrySet()) { str.append("SCRIPT " + entry.getKey() + '\n'); str.append(entry.getValue()).append('\n'); str.append("ENDSCRIPT\n"); } str.append("ENDDELETE\n"); return submitRequest(str.toString()); } /**
/** * Returns the system properties set in the Byteman agent VM. * If Byteman was configured for strict mode, only Byteman related * system properties will be returned. * * @return system properties defined in the Byteman agent VM * * @throws Exception * if the request failed */ public Properties listSystemProperties() throws Exception { String results = submitRequest("LISTSYSPROPS\n"); Properties props = new Properties(); BufferedReader reader = new BufferedReader(new StringReader(results)); String line = reader.readLine(); while (line != null) { String[] nameValuePair = line.split("=", 2); if (nameValuePair.length != 2) { throw new Exception("Invalid name/value pair in line [" + line + "]. Full response below:\n" + results); } props.setProperty(nameValuePair[0], nameValuePair[1].replace("\\n", "\n").replace("\\r", "\r")); line = reader.readLine(); } return props; }
/** * Deletes rules from Byteman. * * @param scripts * rule scripts to be deleted from Byteman * * @return the results of the deletion * * @throws Exception * if the request failed */ public String deleteScripts(List<ScriptText> scripts) throws Exception { if (scripts == null || scripts.size() == 0) { return ""; } StringBuilder str = new StringBuilder("DELETE\n"); for (ScriptText scriptText : scripts) { str.append("SCRIPT " + scriptText.getFileName() + '\n'); str.append(scriptText.getText()).append('\n'); str.append("ENDSCRIPT\n"); } str.append("ENDDELETE\n"); return submitRequest(str.toString()); }
/** * Deploys rule scripts into Byteman * * @param scripts * scripts to be deployed to Byteman * * @return the results of the deployment * * @throws Exception * if the request failed */ public String addScripts(List<ScriptText> scripts) throws Exception { if (scripts == null || scripts.size() == 0) { return ""; } StringBuilder str = new StringBuilder("LOAD\n"); for (ScriptText scriptText : scripts) { str.append("SCRIPT " + scriptText.getFileName() + '\n'); str.append(scriptText.getText()).append('\n'); str.append("ENDSCRIPT\n"); } str.append("ENDLOAD\n"); return submitRequest(str.toString()); }