Skip to content

Commit

Permalink
sepinf-inc#2286: use item children property instead of extraAttribute…
Browse files Browse the repository at this point in the history
… map to store messages in chat evidence
  • Loading branch information
aberenguel committed Oct 8, 2024
1 parent a10f091 commit 23e0e55
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
3 changes: 3 additions & 0 deletions iped-api/src/main/java/iped/data/IItemReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.io.IOException;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import javax.imageio.stream.ImageInputStream;
Expand Down Expand Up @@ -154,6 +155,8 @@ public interface IItemReader extends IStreamSource {

public IDataSource getDataSource();

public List<IItemReader> getChildren();

/**
* @return Object containing the metadata of the item
*/
Expand Down
22 changes: 22 additions & 0 deletions iped-engine/src/main/java/iped/engine/data/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import iped.data.IHashValue;
import iped.data.IItem;
import iped.data.IItemReader;
import iped.datasource.IDataSource;
import iped.engine.core.Statistics;
import iped.engine.io.ReferencedFile;
Expand Down Expand Up @@ -207,6 +208,8 @@ public static void setStartID(int start) {

private ISeekableInputStreamFactory inputStreamFactory;

private List<IItemReader> children;

private static final int BUF_LEN = 8 * 1024 * 1024;

private static final int maxImageLength = 128 << 20;
Expand Down Expand Up @@ -1316,4 +1319,23 @@ public Object getTempAttribute(String key) {
public void setTempAttribute(String key, Object value) {
tempAttributes.put(key, value);
}

public void addChild(IItemReader child) {
if (children == null) {
children = new ArrayList<>();
}
children.add(child);
}

@Override
public List<IItemReader> getChildren() {
if (children == null) {
return null;
}
try {
return new ArrayList<>(children);
} finally {
children.clear();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1153,11 +1153,9 @@ else if ("Participants".equalsIgnoreCase(role)) {
processItem(item);
} else {
// add chat subitems in the chat via UFED_CHILDREN_ATTR extraAttribute
IItem parent = itemSeq.get(itemSeq.size() - 1);
List<IItem> children = (List<IItem>) parent.getExtraAttributeMap().computeIfAbsent(
UFEDChatParser.UFED_CHILDREN_ATTR, (key) -> new ArrayList<IItem>());
Item parent = itemSeq.get(itemSeq.size() - 1);
Util.calctrackIDAndUpdateID((CaseData) caseData, item);
children.add(item);
parent.addChild(item);
caseData.incDiscoveredEvidences(-1);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public class UFEDChatParser extends AbstractParser {

public static final MediaType UFED_CHAT_PREVIEW_MIME = MediaType.application("x-ufed-chat-preview");

public static final String UFED_CHILDREN_ATTR = "ufedChildren";

public static final String UFED_REPLIED_MESSAGE_ATTR = "ufedOriginalMessage";

public static final Map<String, MediaType> appToMime = ImmutableMap.of( //
Expand Down Expand Up @@ -154,9 +152,11 @@ public void parse(InputStream inputStream, ContentHandler handler, Metadata meta
if (chat == null || searcher == null)
return;

List<Message> messages = new ArrayList<>();
List<IItemReader> chatChildren = (List<IItemReader>) chat.getExtraAttributeMap().remove(UFED_CHILDREN_ATTR);
updateChatMetadata(chatMeta, searcher);
Chat chat = createChat(chatItem, searcher);

List<Message> messages = new ArrayList<>();
List<IItemReader> chatChildren = chatItem.getChildren();
if (chatChildren != null) {
for (IItemReader chatChild : chatChildren) {

Expand All @@ -177,6 +177,7 @@ public void parse(InputStream inputStream, ContentHandler handler, Metadata meta
if (messagesCount == 0 && ignoreEmptyChats) {
return;
}
chatMeta.set(ExtraProperties.CONVERSATION_MESSAGES_COUNT, messagesCount);

Collections.sort(messages);

Expand Down Expand Up @@ -340,6 +341,7 @@ private IItemReader lookupAccount(IItemSearcher searcher, Metadata chatMetadata)

private void fillAccountInfo(IItemSearcher searcher, Metadata chatMetadata) {
String name, id, phone = null, username = null;
String source = readUfedMetadata(chatMetadata, "Source");
IItemReader account = lookupAccount(searcher, chatMetadata);
if (account != null) {
name = readUfedMetadata(account, "name");
Expand Down Expand Up @@ -396,6 +398,7 @@ private IItemReader lookupParticipant(IItemSearcher searcher, Metadata chatMetad

private void fillParticipantInfo(IItemSearcher searcher, Metadata chatMetadata, Metadata targetMetadata,
String ufedProperty, String conversationProperty) {
String source = readUfedMetadata(chatMetadata, "Source");
List<String> partyIDs = readUfedMetadataArray(targetMetadata, ufedProperty + ":ID");
List<String> partyNames = readUfedMetadataArray(targetMetadata, ufedProperty + ":Name");
for (int i = 0; i < partyIDs.size(); i++) {
Expand Down Expand Up @@ -524,8 +527,7 @@ private Message createMessage(IItemReader messageItem, IItemSearcher searcher) {
Message message = new Message(messageItem);
handleMessagePosition(message, searcher);

List<IItemReader> msgChildren = (List<IItemReader>) messageItem.getExtraAttributeMap()
.remove(UFED_CHILDREN_ATTR);
List<IItemReader> msgChildren = messageItem.getChildren();
if (msgChildren != null) {
for (IItemReader msgChild : msgChildren) {
if (msgChild.getMediaType().equals(MediaTypes.UFED_CHATACTIVITY_MIME)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,11 @@ public void setChangeDate(Date changeDate) {
// TODO Auto-generated method stub

}

@Override
public List<IItemReader> getChildren() {
return null;
}
};

ItemInfo itemInfo = new ItemInfo(0, item.getHash(), Collections.emptySet(), Collections.emptySet(),
Expand Down

0 comments on commit 23e0e55

Please sign in to comment.