diff --git a/src/main/java/core/packetproxy/model/Modification.java b/src/main/java/core/packetproxy/model/Modification.java index df90b77..41f39fd 100644 --- a/src/main/java/core/packetproxy/model/Modification.java +++ b/src/main/java/core/packetproxy/model/Modification.java @@ -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 {