第一次发帖.
首先我知道如何使用Pattern Matcher和String Split.我的问题最适合我在我的例子中使用,为什么?或建议更好的替代品.
任务:我需要在未知字符串中的两个已知正则表达式之间提取未知的NOUN.
我的解决方案:获取名词的开头和结尾(来自Regexp 1和2)和子串来提取名词.
String line = "unknownXoooXNOUNXccccccXunknown";
int goal = 12 ;
String regexp1 = "Xo+X";
String regexp2 = "Xc+X";
Run Code Online (Sandbox Code Playgroud)
A)我可以使用模式匹配器
Pattern p = Pattern.compile(regexp1);
Matcher m = p.matcher(line);
if (m.find()) {
int afterRegex1 = m.end();
} else {
throw new IllegalArgumentException();
//TODO Exception Management;
}
Run Code Online (Sandbox Code Playgroud)
B)我可以使用String Split
String[] split = line.split(regex1,2);
if (split.length != 2) {
throw new UnsupportedOperationException();
//TODO Exception Management;
}
int afterRegex1 = line.indexOf(split[1]);
Run Code Online (Sandbox Code Playgroud)
我应该使用哪种方法?为什么?我不知道哪个在时间和记忆上更有效率.两者都足够接近我自己的可读性.
我可以获取受保护字段的值,但私有字段会抛出java.lang.IllegalAccessException
.我想我知道为什么我会得到这个例外,但是如何使用反射来利用私有字段的内容,我该如何解决这个问题呢?
程序员帽是在
我已经在netbeans项目中创建了以下弱势类.我已经制作了一个Jar文件来分发它.
public class Vulnerable {
private int privateSecret;
protected int protectedSecret;
int secret;
public Vulnerable() {
this.protectedSecret = 11;
this.privateSecret = 22;
this.secret = 33;
}
}
Run Code Online (Sandbox Code Playgroud)
恶意黑客帽子现在开启
我想知道私人隐藏的领域,我想知道它们包含什么.
我有Jar文件,我已将其导入我的Exploit项目.
以下类扩展了Vulnerable并使用反射列出字段并尝试访问这些值.
public class ExpliotSubClass extends VulnerableCode.Vulnerable {
public List<Field> protectedList = new LinkedList<Field>();
public List<Field> privateList = new LinkedList<Field>();
public void lists() {
Field[] declaredFields = this.getClass().getSuperclass().getDeclaredFields();
for (Field field : declaredFields) {
int modifiers = field.getModifiers();
if (Modifier.isPrivate(modifiers)) {
privateList.add(field);
System.out.println("Private = " + field.getName()); …
Run Code Online (Sandbox Code Playgroud)