Skip to content

Commit

Permalink
sepinf-inc#2304: adjust timeout for UFED chats
Browse files Browse the repository at this point in the history
  • Loading branch information
aberenguel committed Aug 22, 2024
1 parent 69089c1 commit b964f8b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
8 changes: 7 additions & 1 deletion iped-app/resources/config/conf/ParsingTaskConfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ parseUnknownFiles = true
# For example, deleted and partially overwritten images could have searchable plain text into them.
parseCorruptedFiles = true

# Minimum timeout (seconds) while parsing files. To this baseline will be added the result of timeOutPerMB * file size in MB (see next parameter).
# Minimum timeout (seconds) while parsing files.
# To this baseline will be added the result of timeOutPerMB * file size in MB
# or timeOutPerHundredMessages * messages_count / 100 (see next parameters).
# After the timeout, the file's raw strings will be indexed.
timeOut = 180

# Timeout (seconds) for each Megabyte of the file being parsed.
# Total_Timeout = timeOut + timeOutPerMB * <file_size_in_MB>
timeOutPerMB = 2

# Timeout (seconds) for each 100 messages in UFED Chat
# Total_Timeout = timeOut + timeOutPerHundredMessages * <messages_count> / 100
timeOutPerHundredMessages = 2

# Minimum size of raw strings extracted from unknown files for indexing.
minRawStringSize = 4

Expand Down
1 change: 1 addition & 0 deletions iped-app/resources/config/conf/metadataTypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4202,6 +4202,7 @@ ufed:GlobalNumberOfFiles = java.lang.Integer
ufed:Header offset = java.lang.String
ufed:Height = java.lang.Integer
ufed:Identifier = java.lang.String
ufed:InstantMessagesCount = java.lang.Integer
ufed:IsEmulatable = java.lang.String
ufed:Label = java.lang.String
ufed:LastAccessTime = java.util.Date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ParsingTaskConfig extends AbstractTaskPropertiesConfig {
private boolean parseUnknownFiles = true;
private int timeOut = 180;
private int timeOutPerMB = 2;
private int timeOutPerHundredMessages = 2;
private int minRawStringSize = 4;
private boolean storeTextCacheOnDisk = true;
private boolean sortPDFChars;
Expand Down Expand Up @@ -85,6 +86,11 @@ public void processProperties(UTF8Properties properties) {
timeOutPerMB = Integer.valueOf(value.trim());
}

value = properties.getProperty("timeOutPerHundredMessages"); //$NON-NLS-1$
if (value != null) {
timeOutPerHundredMessages = Integer.valueOf(value.trim());
}

value = properties.getProperty("minRawStringSize"); //$NON-NLS-1$
if (value != null) {
minRawStringSize = Integer.valueOf(value.trim());
Expand Down Expand Up @@ -145,6 +151,10 @@ public int getTimeOutPerMB() {
return timeOutPerMB;
}

public int getTimeOutPerHundredMessages() {
return timeOutPerHundredMessages;
}

public boolean isStoreTextCacheOnDisk() {
return storeTextCacheOnDisk;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public class UfedXmlReader extends DataSourceReader {
private Set<String> supportedApps = new HashSet<String>(Arrays.asList(WhatsAppParser.WHATSAPP,
TelegramParser.TELEGRAM, WhatsAppParser.WHATSAPP + " Business", WhatsAppParser.WHATSAPP + " (Dual App)"));

public static final Property UFED_IM_COUNT = Property.internalInteger(ExtraProperties.UFED_META_PREFIX + "InstantMessagesCount");

private static Random random = new Random();

private static HashMap<File, UFDRInputStreamFactory> uisfMap = new HashMap<>();
Expand Down Expand Up @@ -392,6 +394,7 @@ private class XMLContentHandler implements ContentHandler {
Object ignoreItemTree = null;
boolean inChat = false;
int numAttachments = 0;
int numInstantMessages = 0;
String prevUfedId = null;

private class XmlNode {
Expand Down Expand Up @@ -580,8 +583,10 @@ public void startElement(String uri, String localName, String qName, Attributes
Item item = new Item();
item.setExtraAttribute(ExtraProperties.DATASOURCE_READER, UfedXmlReader.class.getSimpleName());
String type = atts.getValue("type"); //$NON-NLS-1$
if (type.equals("Chat"))
if (type.equals("Chat")) {
inChat = true;
numInstantMessages = 0;
}
String name = type + "_" + atts.getValue("id"); //$NON-NLS-1$ //$NON-NLS-2$
item.setName(name);
String path = decodedFolder.getPath() + "/" + type + "/" + name; //$NON-NLS-1$ //$NON-NLS-2$
Expand Down Expand Up @@ -874,6 +879,7 @@ else if (parentItem.getMediaType().equals(MediaTypes.UFED_MESSAGE_MIME)) {
if (TelegramParser.TELEGRAM.equalsIgnoreCase(source)) // $NON-NLS-1$
item.setMediaType(UFEDChatParser.UFED_CHAT_TELEGRAM);

item.getMetadata().set(UFED_IM_COUNT, numInstantMessages);
item.setExtraAttribute(IndexItem.TREENODE, "true"); //$NON-NLS-1$
}
if ("InstantMessage".equals(type) || "Email".equals(type) || "Call".equals(type) || "SMS".equals(type) //$NON-NLS-4$
Expand Down Expand Up @@ -911,6 +917,9 @@ else if (parentItem.getMediaType().equals(MediaTypes.UFED_MESSAGE_MIME)) {
ignoreItemLocal = true;
}
}
if (!ignoreItemLocal) {
numInstantMessages++;
}
}
if (mergeInParentNode.contains(type) && itemSeq.size() > 0) {
IItem parentItem = itemSeq.get(itemSeq.size() - 1);
Expand Down Expand Up @@ -1125,6 +1134,7 @@ else if ("Bcc".equalsIgnoreCase(role)) //$NON-NLS-1$
if (MediaTypes.isInstanceOf(item.getMediaType(), UFEDChatParser.UFED_CHAT_MIME)) {
inChat = false;
ignoreItems = false;
numInstantMessages = 0;
}
}

Expand Down
10 changes: 4 additions & 6 deletions iped-engine/src/main/java/iped/engine/io/FastPipedReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public class FastPipedReader extends Reader {

// utilizado para verificar se há comunicação entre reader e writer
private int timer = 0;
private int timeOutBySize = 0;
private int minTimeout = 60;
private int totalTimeout = 60;
private boolean timeoutPaused = false, timedOut = false;

boolean closedByWriter = false;
Expand Down Expand Up @@ -123,10 +122,9 @@ public FastPipedReader() {
* if <code>pipeSize less than 1</code>.
* @since 1.6
*/
public FastPipedReader(int pipeSize, int minTimeout, int timeOutBySize) {
public FastPipedReader(int pipeSize, int totalTimeout) {
initPipe(pipeSize);
this.minTimeout = minTimeout;
this.timeOutBySize = timeOutBySize;
this.totalTimeout = totalTimeout;
}

public synchronized boolean setTimeoutPaused(boolean paused) {
Expand All @@ -135,7 +133,7 @@ public synchronized boolean setTimeoutPaused(boolean paused) {
}

public int getTotalTimeout() {
return minTimeout + timeOutBySize;
return totalTimeout;
}

private void initPipe(int pipeSize) {
Expand Down
9 changes: 8 additions & 1 deletion iped-engine/src/main/java/iped/engine/io/ParsingReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import iped.engine.config.ConfigurationManager;
import iped.engine.config.ParsingTaskConfig;
import iped.engine.core.QueuesProcessingOrder;
import iped.engine.datasource.UfedXmlReader;
import iped.parsers.fork.ParsingTimeout;
import iped.parsers.standard.StandardParser;
import iped.parsers.util.CorruptedCarvedException;
Expand Down Expand Up @@ -144,7 +145,13 @@ public ParsingReader(Parser parser, InputStream stream, Metadata metadata, Parse
ParsingTaskConfig parsingConfig = ConfigurationManager.get().findObject(ParsingTaskConfig.class);
timeOutBySize = (int) (length / 1000000) * parsingConfig.getTimeOutPerMB();

pipedReader = new FastPipedReader(128 * 1024, parsingConfig.getTimeOut(), timeOutBySize);
int timeOutByMessages = 0;
Integer messagesCount = metadata.getInt(UfedXmlReader.UFED_IM_COUNT);
if (messagesCount != null) {
timeOutByMessages = messagesCount * parsingConfig.getTimeOutPerHundredMessages() / 100;
}

pipedReader = new FastPipedReader(128 * 1024, parsingConfig.getTimeOut() + timeOutBySize + timeOutByMessages);
this.reader = new BufferedReader(pipedReader);
this.writer = new FastPipedWriter(pipedReader);

Expand Down

0 comments on commit b964f8b

Please sign in to comment.