Commit 0edb5722 authored by nanahira's avatar nanahira

better matching

parent 192c5e9a
......@@ -28,9 +28,9 @@ declare module 'koishi' {
}
const matcherGlobal =
/(0*[^\d]*)*([1-2]?[^\d]?\d{0,2})(([^\d]+[1-2]?\d{1,2}){3,}?).+?([1-6]([^\d]*\d){4})/g;
/(0*[^\d]*)*([1-2]?[^\d\.]?\d{0,2})(([^\d]+[1-2]?\d{1,2}){3,}?).+?([1-6]([^\d]*\d){4})(.*[\+\-]\d{1,5})*/g;
const matcherSingle =
/(0*[^\d]*)*([1-2]?[^\d]?\d{0,2})(([^\d]+[1-2]?\d{1,2}){3,}?).+?([1-6]([^\d]*\d){4})/;
/(0*[^\d]*)*([1-2]?[^\d\.]?\d{0,2})(([^\d]+[1-2]?\d{1,2}){3,}?).+?([1-6]([^\d]*\d){4})(.*[\+\-]\d{1,5})*/;
const PROTOCOL_BASE64 = 'base64://';
......@@ -125,7 +125,7 @@ export default class HisoutensokuJammerPlugin implements OnApply {
return this.handleMessage(text, sender, false);
}
private async handleMessage(
private async getTargetsFromMessage(
message: string,
sender: string,
useCache = true,
......@@ -155,7 +155,8 @@ export default class HisoutensokuJammerPlugin implements OnApply {
} else if (!messageMatch) {
return;
}
const attackPromises = messageMatch.map((pattern) => {
const results: { address: string; port: number }[] = [];
for (const pattern of messageMatch) {
const patternMatch = pattern.match(matcherSingle);
const firstDigit = patternMatch[2].replace(/[^\d]+/g, '');
const address = `${firstDigit}.${patternMatch[3]
......@@ -163,9 +164,34 @@ export default class HisoutensokuJammerPlugin implements OnApply {
.filter((s) => s.length)
.join('.')}`;
const port = parseInt(patternMatch[5].replace(/[^\d]+/g, ''));
return this.startAttack(address, port);
});
const results: boolean[] = await Promise.all(attackPromises);
results.push({ address, port });
const suffixPattern = patternMatch[7]?.replace(/[^\+\-\d]/g, '');
if (suffixPattern) {
const suffixMatch = suffixPattern.match(/[\+\-]\d+/g);
if (suffixMatch) {
let mutatedPort = port;
for (const numberPattern of suffixMatch) {
const portOffset = parseInt(numberPattern);
mutatedPort += portOffset;
}
results.push({ address, port: mutatedPort });
}
}
}
return results;
}
private async handleMessage(
message: string,
sender: string,
useCache = true,
) {
const targets = await this.getTargetsFromMessage(message, sender, useCache);
const results: boolean[] = await Promise.all(
targets.map((target) => {
return this.startAttack(target.address, target.port);
}),
);
}
private async startAttack(address: string, port: number): Promise<boolean> {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment