Начало декодинга gzip
This commit is contained in:
@@ -26,6 +26,7 @@ dependencies {
|
||||
implementation "org.springframework.boot:spring-boot-starter-websocket"
|
||||
implementation 'org.springframework.session:spring-session-core'
|
||||
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.7'
|
||||
compile group: 'com.google.guava', name: 'guava', version: '11.0.2'
|
||||
compile 'org.pcap4j:pcap4j-core:1.+'
|
||||
compile 'org.pcap4j:pcap4j-packetfactory-static:1.+'
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
|
||||
@@ -150,13 +150,13 @@ public class PcapWorker implements PacketListener {
|
||||
if (unfinishedStreams.containsKey(stream)) {
|
||||
unfinishedStreams.get(stream).add(packet);
|
||||
} else {
|
||||
log.info("Начат новый стрим");
|
||||
log.debug("Начат новый стрим");
|
||||
List<ru.serega6531.packmate.model.Packet> packets = new ArrayList<>();
|
||||
packets.add(packet);
|
||||
unfinishedStreams.put(stream, packets);
|
||||
}
|
||||
|
||||
log.info("{} {} {}:{} -> {}:{}, номер пакета {}",
|
||||
log.debug("{} {} {}:{} -> {}:{}, номер пакета {}",
|
||||
protocol.name().toLowerCase(), serviceOptional.get(), sourceIpString, sourcePort, destIpString, destPort,
|
||||
unfinishedStreams.get(stream).size());
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ public class Packet {
|
||||
|
||||
private boolean incoming; // true если от клиента к серверу, иначе false
|
||||
|
||||
private boolean ungzipped;
|
||||
|
||||
private byte[] content;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package ru.serega6531.packmate.service;
|
||||
|
||||
import com.google.common.primitives.Bytes;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -25,6 +27,8 @@ public class StreamService {
|
||||
private final String localIp;
|
||||
private final boolean ignoreEmptyPackets;
|
||||
|
||||
private final byte[] GZIP_HEADER = {0x1f, (byte) 0x8b, 0x08};
|
||||
|
||||
@Autowired
|
||||
public StreamService(StreamRepository repository,
|
||||
PatternService patternService,
|
||||
@@ -76,6 +80,49 @@ public class StreamService {
|
||||
}
|
||||
}
|
||||
|
||||
boolean gzipStarted = false;
|
||||
byte[] gzipContent = null;
|
||||
int gzipStartPacket = 0;
|
||||
int gzipEndPacket = 0;
|
||||
|
||||
for (int i = 0; i < packets.size(); i++) {
|
||||
Packet packet = packets.get(i);
|
||||
|
||||
if (packet.isIncoming() && gzipStarted) {
|
||||
gzipStarted = false;
|
||||
gzipEndPacket = i - 1;
|
||||
//TODO end and read gzip stream
|
||||
} else if (!packet.isIncoming()) {
|
||||
String content = new String(packet.getContent());
|
||||
|
||||
int contentPos = content.indexOf("\r\n\r\n");
|
||||
boolean http = content.startsWith("HTTP/");
|
||||
|
||||
if(http && gzipStarted) {
|
||||
gzipEndPacket = i - 1;
|
||||
//TODO end and read gzip stream
|
||||
}
|
||||
|
||||
if (contentPos != -1) { // начало body
|
||||
String headers = content.substring(0, contentPos);
|
||||
boolean gziped = headers.contains("Content-Encoding: gzip\r\n");
|
||||
if (gziped) {
|
||||
gzipStarted = true;
|
||||
gzipStartPacket = i;
|
||||
int gzipStart = Bytes.indexOf(packet.getContent(), GZIP_HEADER);
|
||||
gzipContent = Arrays.copyOfRange(packet.getContent(), gzipStart, packet.getContent().length);
|
||||
}
|
||||
} else if (gzipStarted) { // продолжение body
|
||||
gzipContent = ArrayUtils.addAll(gzipContent, packet.getContent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(gzipContent != null) {
|
||||
gzipEndPacket = packets.size() - 1;
|
||||
// TODO end and read gzip stream
|
||||
}
|
||||
|
||||
Stream savedStream = save(stream);
|
||||
|
||||
List<ru.serega6531.packmate.model.Packet> savedPackets = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user