Skip to content

Commit

Permalink
Merge pull request #109 from DeNA/fix_binary_auto_modify
Browse files Browse the repository at this point in the history
バイナリデータに対してREGEXでAuto Modificationsするとマッチしなくてもデータが壊れるのを修正
  • Loading branch information
funa-tk authored Jun 15, 2021
2 parents 65bbc66 + 8a52ad1 commit 7efd562
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/core/packetproxy/model/Modification.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,16 @@ private byte[] replaceRegex(byte[] data, Packet packet) {
Pattern pattern = Pattern.compile(this.pattern, Pattern.MULTILINE);
Matcher matcher = pattern.matcher(new String(data));
String result = new String(data);
boolean matched = false;
while (matcher.find()) {
matched = true;
result = matcher.replaceAll(this.replaced);
packet.setModified();
}
if (!matched) {
// バイナリデータが壊れる可能性があるので、マッチしなかった場合はそのまま返す
return data;
}
return result.getBytes();
}
private byte[] replaceBinary(byte[] data, Packet packet) throws Exception {
Expand Down

0 comments on commit 7efd562

Please sign in to comment.