-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
22 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
# analyzer.py | ||
import time, gc | ||
|
||
def analyze_payload(payload): | ||
tokens = [] | ||
i = 0 | ||
while i < len(payload): | ||
if payload[i] == "<": | ||
end_index = payload.find(">", i) | ||
if end_index != -1 and ' ' not in payload[i+1:end_index]: | ||
tokens.append(payload[i:end_index+1]) | ||
i = end_index + 1 | ||
continue | ||
tokens.append(payload[i]) | ||
i += 1 | ||
return tokens | ||
token_start = 0 | ||
in_token = False | ||
|
||
for i, char in enumerate(payload): | ||
if char == "<": | ||
if in_token: | ||
tokens.append(payload[token_start:i]) | ||
token_start = i | ||
in_token = True | ||
elif char == ">" and in_token: | ||
tokens.append(payload[token_start:i+1]) | ||
in_token = False | ||
token_start = i + 1 | ||
elif not in_token and (i == len(payload) - 1 or payload[i+1] == "<"): | ||
tokens.append(payload[token_start:i+1]) | ||
token_start = i + 1 | ||
|
||
if not in_token and token_start < len(payload): | ||
tokens.append(payload[token_start:]) | ||
|
||
return tokens |