diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/chrome/ChromeSqliteParser.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/chrome/ChromeSqliteParser.java index 6b7ab47273..789d17e9d8 100755 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/chrome/ChromeSqliteParser.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/chrome/ChromeSqliteParser.java @@ -9,7 +9,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -498,7 +498,7 @@ private void parseChromeSearches(ContentHandler handler, Metadata metadata, Pars protected List getResumedHistory(Connection connection, Metadata metadata, ParseContext context) throws SQLException { - List resumedHistory = new LinkedList(); + List resumedHistory = new ArrayList(); Statement st = null; try { @@ -524,7 +524,7 @@ protected List getResumedHistory(Connection connection, Metadata m protected List getHistory(Connection connection, Metadata metadata, ParseContext context) throws SQLException { - List history = new LinkedList(); + List history = new ArrayList(); Statement st = null; try { @@ -549,7 +549,7 @@ protected List getHistory(Connection connection, Metadata metadata, Parse protected List getDownloads(Connection connection, Metadata metadata, ParseContext context) throws SQLException { - List downloads = new LinkedList(); + List downloads = new ArrayList(); Statement st = null; try { @@ -582,7 +582,7 @@ protected List getDownloads(Connection connection, Metadata metadata, protected List getSearchTerms(Connection connection, Metadata metadata, ParseContext context) throws SQLException { - List searches = new LinkedList(); + List searches = new ArrayList(); Statement st = null; try { diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/edge/EdgeWebCacheParser.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/edge/EdgeWebCacheParser.java index 1db90a3744..c68b31e91e 100755 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/edge/EdgeWebCacheParser.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/edge/EdgeWebCacheParser.java @@ -7,9 +7,9 @@ import java.io.InputStream; import java.nio.file.Files; import java.nio.file.StandardCopyOption; +import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -287,7 +287,7 @@ private void parseEdgeHistory(ContentHandler handler, Metadata metadata, ParseCo protected List getHistory(String filePath, PointerByReference filePointerReference, ItemInfo itemInfo) throws EdgeWebCacheException { - List history = new LinkedList(); + List history = new ArrayList(); try { /* diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/firefox/FirefoxSqliteParser.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/firefox/FirefoxSqliteParser.java index 017a1aea20..35b0ee37c6 100755 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/firefox/FirefoxSqliteParser.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/firefox/FirefoxSqliteParser.java @@ -9,7 +9,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -504,7 +504,7 @@ private void parseFirefoxResumedHistory(ContentHandler handler, Metadata metadat protected List getResumedHistory(Connection connection, Metadata metadata, ParseContext context) throws SQLException { - List resumedHistory = new LinkedList(); + List resumedHistory = new ArrayList(); Statement st = null; try { @@ -531,7 +531,7 @@ protected List getResumedHistory(Connection connection, Metadata m protected List getHistory(Connection connection, Metadata metadata, ParseContext context) throws SQLException { - List history = new LinkedList(); + List history = new ArrayList(); Statement st = null; try { @@ -555,7 +555,7 @@ protected List getHistory(Connection connection, Metadata metadata, Parse protected List getBookmarks(Connection connection, Metadata metadata, ParseContext context) throws SQLException { - List bookmarks = new LinkedList(); + List bookmarks = new ArrayList(); Statement st = null; try { @@ -580,7 +580,7 @@ protected List getBookmarks(Connection connection, Metadata private List getDownloads(Connection connection, Metadata metadata, ParseContext context) throws SQLException, JsonParseException, JsonMappingException, IOException { - List downloads = new LinkedList(); + List downloads = new ArrayList(); Statement st = null; try { diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/safari/SafariPlistParser.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/safari/SafariPlistParser.java index 530e0a3566..430751b530 100755 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/safari/SafariPlistParser.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/safari/SafariPlistParser.java @@ -5,7 +5,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -342,7 +342,7 @@ private void parseSafariResumedHistory(InputStream stream, ContentHandler handle } protected List getResumedHistory(InputStream is) throws Exception { - List resumedHistory = new LinkedList(); + List resumedHistory = new ArrayList(); NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(is); NSObject[] parameters = ((NSArray) rootDict.objectForKey("WebHistoryDates")).getArray(); @@ -371,7 +371,7 @@ protected List getResumedHistory(InputStream is) throws Exce } // protected List getHistory(InputStream is) throws Exception { - // List history = new LinkedList(); + // List history = new ArrayList(); // // NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(is); // NSObject[] parameters = ((NSArray) @@ -400,7 +400,7 @@ protected List getResumedHistory(InputStream is) throws Exce // } private List getDownloads(InputStream is) throws Exception { - List downloads = new LinkedList<>(); + List downloads = new ArrayList<>(); NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(is); NSObject[] parameters = ((NSArray) rootDict.objectForKey("DownloadHistory")).getArray(); @@ -555,7 +555,7 @@ private void parseChildren(List bookmarks, NSDictionary dict) { } private List getBookmarks(InputStream is) throws Exception { - List bookmarks = new LinkedList(); + List bookmarks = new ArrayList(); NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(is); diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/safari/SafariSqliteParser.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/safari/SafariSqliteParser.java index 28449a901a..91eb95678f 100755 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/safari/SafariSqliteParser.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/browsers/safari/SafariSqliteParser.java @@ -9,7 +9,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -229,7 +229,7 @@ private void parseSafariResumedHistory(ContentHandler handler, Metadata metadata protected List getResumedHistory(Connection connection, Metadata metadata, ParseContext context) throws SQLException { - List resumedHistory = new LinkedList(); + List resumedHistory = new ArrayList(); Statement st = null; try { @@ -273,7 +273,7 @@ protected List getResumedHistory(Connection connection, Meta protected List getHistory(Connection connection, Metadata metadata, ParseContext context) throws SQLException { - List history = new LinkedList(); + List history = new ArrayList(); Statement st = null; try { diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/discord/json/DiscordAttachment.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/discord/json/DiscordAttachment.java index 4a8ddd35a6..158d9724a3 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/discord/json/DiscordAttachment.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/discord/json/DiscordAttachment.java @@ -1,7 +1,7 @@ package iped.parsers.discord.json; -import java.util.HashSet; -import java.util.Set; +import java.util.Collections; +import java.util.List; import com.fasterxml.jackson.annotation.JsonProperty; @@ -42,7 +42,7 @@ public class DiscordAttachment { private String mediaHash; - private Set childPornSets = new HashSet<>(); + private List childPornSets; public String getId() { return id; @@ -122,15 +122,11 @@ public String getMediaHash() { public void setMediaHash(String mediaHash) { this.mediaHash = mediaHash; - childPornSets.addAll(ChildPornHashLookup.lookupHash(mediaHash)); + childPornSets = ChildPornHashLookup.lookupHashAndMerge(mediaHash, childPornSets); } - public Set getChildPornSets() { - return childPornSets; - } - - public void setChildPornSets(Set childPornSets) { - this.childPornSets = childPornSets; + public List getChildPornSets() { + return childPornSets == null ? Collections.emptyList() : childPornSets; } @Override diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/emule/KnownMetParser.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/emule/KnownMetParser.java index 3dfd0326b5..ebd261d792 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/emule/KnownMetParser.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/emule/KnownMetParser.java @@ -28,7 +28,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.TimeZone; @@ -199,13 +198,12 @@ public void parse(InputStream stream, ContentHandler handler, Metadata metadata, cells.add(e.getName()); String hash = e.getHash(); metadata.add(ExtraProperties.SHARED_HASHES, hash); - HashSet hashSets = new HashSet<>(); - hashSets.addAll(ChildPornHashLookup.lookupHash(EDONKEY, hash)); + List hashSets = ChildPornHashLookup.lookupHash(EDONKEY, hash); item = searchItemInCase(searcher, EDONKEY, e.getHash()); if(item != null) { - hashSets.addAll(ChildPornHashLookup.lookupHash(item.getHash())); + hashSets = ChildPornHashLookup.lookupHashAndMerge(EDONKEY, hash, hashSets); } - if (!hashSets.isEmpty()) { + if (hashSets != null && !hashSets.isEmpty()) { hashDBHits++; trClass = "rr"; //$NON-NLS-1$ } diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/emule/PartMetParser.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/emule/PartMetParser.java index fe3235c715..94b5ed9888 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/emule/PartMetParser.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/emule/PartMetParser.java @@ -8,7 +8,7 @@ import java.text.SimpleDateFormat; import java.util.Collections; import java.util.Date; -import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.TimeZone; @@ -115,12 +115,11 @@ public void parse(InputStream stream, ContentHandler handler, Metadata metadata, xhtml.startElement("table", "class", "d"); int hashDBHits = 0; - HashSet hashSets = new HashSet(); - hashSets.addAll(ChildPornHashLookup.lookupHash(KnownMetParser.EDONKEY, e.getHash())); + List hashSets = ChildPornHashLookup.lookupHash(KnownMetParser.EDONKEY, e.getHash()); IItemReader item = KnownMetParser.searchItemInCase(searcher, KnownMetParser.EDONKEY, e.getHash()); if (item != null) - hashSets.addAll(ChildPornHashLookup.lookupHash(item.getHash())); - if (!hashSets.isEmpty()) + hashSets = ChildPornHashLookup.lookupHashAndMerge(item.getHash(), hashSets); + if (hashSets != null && !hashSets.isEmpty()) hashDBHits++; AttributesImpl attributes = new AttributesImpl(); diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/jdbc/JDBCTableReader.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/jdbc/JDBCTableReader.java index f1d7c677f2..b46605e4ba 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/jdbc/JDBCTableReader.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/jdbc/JDBCTableReader.java @@ -27,7 +27,7 @@ import java.sql.SQLException; import java.sql.Statement; import java.sql.Types; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import javax.swing.text.html.HTMLEditorKit.Parser; @@ -159,7 +159,7 @@ public String handleCell(ResultSet results, ResultSetMetaData rsmd, int i, Conte } public List getHeaders() throws IOException { - List headers = new LinkedList(); + List headers = new ArrayList(); // lazy initialization if (results == null) { results = getTableData(); diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/shareaza/LibraryFile.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/shareaza/LibraryFile.java index 0b4fe46dfe..7bbbb16277 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/shareaza/LibraryFile.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/shareaza/LibraryFile.java @@ -20,7 +20,7 @@ import java.io.IOException; import java.util.ArrayList; -import java.util.HashSet; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -65,7 +65,7 @@ public class LibraryFile extends ShareazaEntity { private boolean cachedPreview; private boolean bogus; private final LibraryFolder parentFolder; - private HashSet hashSetHits = new HashSet<>(); + private List hashSetHits; public LibraryFile(LibraryFolder parentFolder) { super("LIBRARY FILE"); //$NON-NLS-1$ @@ -208,14 +208,14 @@ public boolean isShared() { public void printTableRow(XHTMLContentHandler html, String path, IItemSearcher searcher, Map> albunsForFiles) throws SAXException { - hashSetHits.addAll(ChildPornHashLookup.lookupHash(md5)); - hashSetHits.addAll(ChildPornHashLookup.lookupHash(sha1)); + hashSetHits = ChildPornHashLookup.lookupHashAndMerge(md5, hashSetHits); + hashSetHits = ChildPornHashLookup.lookupHashAndMerge(sha1, hashSetHits); AttributesImpl attributes = new AttributesImpl(); if (md5 != null && !md5.isEmpty()) { attributes.addAttribute("", "name", "name", "CDATA", md5.toUpperCase()); } - if (!hashSetHits.isEmpty()) { + if (hashSetHits != null && !hashSetHits.isEmpty()) { attributes.addAttribute("", "class", "class", "CDATA", "r"); } html.startElement("tr", attributes); @@ -260,7 +260,7 @@ private void printTd(XHTMLContentHandler html, IItemSearcher searcher, Object... col++; } html.startElement("td"); //$NON-NLS-1$ - if (!hashSetHits.isEmpty()) { + if (hashSetHits != null && !hashSetHits.isEmpty()) { html.characters(hashSetHits.toString()); } html.endElement("td"); //$NON-NLS-1$ @@ -270,7 +270,7 @@ private void printTd(XHTMLContentHandler html, IItemSearcher searcher, Object... } public boolean isHashDBHit() { - return !hashSetHits.isEmpty(); + return hashSetHits != null && !hashSetHits.isEmpty(); } public long getSize() { @@ -377,8 +377,8 @@ public LibraryFolder getParentFolder() { return parentFolder; } - public HashSet getHashSetHits() { - return hashSetHits; + public List getHashSetHits() { + return hashSetHits == null ? Collections.emptyList() : hashSetHits; } public void setIndex(int index) { diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/sqlite/SQLite3DBParser.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/sqlite/SQLite3DBParser.java index 965de29471..ffbdc34078 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/sqlite/SQLite3DBParser.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/sqlite/SQLite3DBParser.java @@ -26,7 +26,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -189,7 +189,7 @@ protected String getJDBCClassName() { @Override protected List getTableNames(Connection connection, Metadata metadata, ParseContext context) throws SQLException { - List tableNames = new LinkedList(); + List tableNames = new ArrayList(); Statement st = null; try { diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/telegram/Message.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/telegram/Message.java index eb66fd68c2..894bc86f4a 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/telegram/Message.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/telegram/Message.java @@ -19,10 +19,9 @@ package iped.parsers.telegram; import java.util.Collection; +import java.util.Collections; import java.util.Date; -import java.util.HashSet; import java.util.List; -import java.util.Set; import dpf.ap.gpinf.interfacetelegram.MessageInterface; import dpf.ap.gpinf.interfacetelegram.PhotoData; @@ -52,7 +51,7 @@ public class Message implements MessageInterface { private long toId = 0; private Double latitude = null; private Double longitude = null; - private Set childPornSets = new HashSet<>(); + private List childPornSets; public long getId() { return id; @@ -68,7 +67,7 @@ public String getMediaHash() { public void setMediaHash(String mediaHash) { this.mediaHash = mediaHash; - childPornSets.addAll(ChildPornHashLookup.lookupHash(mediaHash)); + childPornSets = ChildPornHashLookup.lookupHashAndMerge(mediaHash, childPornSets); } public String getMediaFile() { @@ -248,8 +247,8 @@ public void setLongitude(Double longitude) { this.longitude = longitude; } - public Set getChildPornSets() { - return this.childPornSets; + public List getChildPornSets() { + return childPornSets == null ? Collections.emptyList() : childPornSets; } public void addChildPornSets(Collection sets) { diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/util/ChildPornHashLookup.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/util/ChildPornHashLookup.java index 4686e12f12..5e317e6b6f 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/util/ChildPornHashLookup.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/util/ChildPornHashLookup.java @@ -19,8 +19,17 @@ public static void dispose() { } public static List lookupHash(String mediaHash) { + return lookupHashAndMerge(mediaHash, null); + } + + /** + * Lookup a hash in the database and merge the result with a optionally provided + * list (returned from a previous call to hash lookup). The hash algorithm (md5, + * sha-1 or sha-256) is guessed from the hash length. + */ + public static List lookupHashAndMerge(String mediaHash, List prev) { if (mediaHash == null || mediaHash.isEmpty() || lookupProviders.isEmpty()) - return Collections.EMPTY_LIST; + return prev != null ? prev : Collections.emptyList(); String guessedAlgo = ""; if (mediaHash.length() == 32) guessedAlgo = "md5"; @@ -29,19 +38,37 @@ else if (mediaHash.length() == 40) else if (mediaHash.length() == 64) guessedAlgo = "sha-256"; - return lookupHash(guessedAlgo, mediaHash); + return lookupHashAndMerge(guessedAlgo, mediaHash, prev); } public static List lookupHash(String algorithm, String hash) { - Set hashsets = new HashSet(); + return lookupHashAndMerge(algorithm, hash, null); + } + + /** + * Lookup a hash in the database and merge the result with a optionally provided + * list (returned from a previous call to hash lookup), using a defined + * algorithm. + */ + public static List lookupHashAndMerge(String algorithm, String hash, List prev) { + Set hashsets = null; if (hash != null) { for (LookupProvider provider : lookupProviders) { List sets = provider.lookupHash(algorithm, hash); if (sets != null) { + if (hashsets == null) { + hashsets = new HashSet(); + } hashsets.addAll(sets); } } } + if (hashsets == null || hashsets.isEmpty()) { + return prev != null ? prev : Collections.emptyList(); + } + if (prev != null) { + hashsets.addAll(prev); + } List l = new ArrayList(hashsets); Collections.sort(l); return l; diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ExtractorAndroid.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ExtractorAndroid.java index 1a11c761cc..1de572b0d1 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ExtractorAndroid.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ExtractorAndroid.java @@ -47,7 +47,6 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -262,7 +261,7 @@ protected List extractChatList() throws WAExtractorException { private List undeleteChats(SQLiteUndeleteTable undeleteChatListTable, SQLiteUndeleteTable undeleteChatTable, SQLiteUndeleteTable undeleteJIDTable, WAContactsDirectory contacts) { - List result = new LinkedList<>(); + List result = new ArrayList<>(); if (undeleteChatListTable != null && undeleteChatListTable.getTableRows() != null && !undeleteChatListTable.getTableRows().isEmpty()) { // this is the case of a database with the table "chat_list" diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ExtractorIOS.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ExtractorIOS.java index 64411d478f..a236c27c9c 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ExtractorIOS.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ExtractorIOS.java @@ -45,7 +45,6 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -554,7 +553,7 @@ private void decodeReceiptInfo(Message m, byte[] receiptInfo) { } private List undeleteChats(SQLiteUndeleteTable undeleteChatsSessions, WAContactsDirectory contacts) { - List result = new LinkedList<>(); + List result = new ArrayList<>(); if (undeleteChatsSessions != null && !undeleteChatsSessions.getTableRows().isEmpty()) { for (SqliteRow row : undeleteChatsSessions.getTableRows()) { diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java index e357d74293..aeba963210 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Message.java @@ -8,11 +8,9 @@ import java.nio.file.StandardOpenOption; import java.util.ArrayList; import java.util.Base64; -import java.util.Collection; +import java.util.Collections; import java.util.Date; -import java.util.HashSet; import java.util.List; -import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; @@ -63,10 +61,10 @@ public class Message { private int mediaDuration; private MessageStatus messageStatus; private String recoveredFrom = null; - private Set childPornSets = new HashSet<>(); + private List childPornSets; private IItemReader mediaItem = null; private String mediaQuery = null; - private List addOns = new ArrayList<>(); + private List addOns; static { try { @@ -99,7 +97,6 @@ public static synchronized void closeStaticResources() throws IOException { public Message() { messageType = MessageType.TEXT_MESSAGE; - vcards = new ArrayList<>(); } public long getId() { @@ -219,7 +216,7 @@ public void setMediaHash(String mediaHash, boolean encoded) { } else { this.mediaHash = mediaHash; } - childPornSets.addAll(ChildPornHashLookup.lookupHash(this.mediaHash)); + childPornSets = ChildPornHashLookup.lookupHashAndMerge(this.mediaHash, childPornSets); } public byte[] getThumbData() { @@ -320,7 +317,7 @@ public void setMessageType(MessageType messageType) { } public List getVcards() { - return vcards; + return vcards == null ? Collections.emptyList() : vcards; } public void setVcards(List vcards) { @@ -424,12 +421,12 @@ public void setRecoveredFrom(String recoveredFrom) { this.recoveredFrom = recoveredFrom; } - public Set getChildPornSets() { - return childPornSets; + public List getChildPornSets() { + return childPornSets == null ? Collections.emptyList() : childPornSets; } - public void addChildPornSets(Collection sets) { - this.childPornSets.addAll(sets); + public void lookupAndAddChildPornSets(String hash) { + childPornSets = ChildPornHashLookup.lookupHashAndMerge(hash, childPornSets); } public IItemReader getMediaItem() { @@ -449,11 +446,14 @@ public void setMediaQuery(String mediaQuery) { } public boolean addMessageAddOn(MessageAddOn m) { + if (addOns == null) { + addOns = new ArrayList(1); + } return addOns.add(m); } public List getAddOns() { - return addOns; + return addOns == null ? Collections.emptyList() : addOns; } public String getCallId() { diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ReportGenerator.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ReportGenerator.java index b8cba4de19..beb1186063 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ReportGenerator.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ReportGenerator.java @@ -17,7 +17,6 @@ import org.apache.commons.text.lookup.StringLookupFactory; import iped.data.IItemReader; -import iped.parsers.util.ChildPornHashLookup; import iped.parsers.util.Messages; import iped.parsers.vcard.VCardParser; import iped.parsers.whatsapp.Message.MessageType; @@ -641,7 +640,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean break; } if (mediaItem != null) { - message.addChildPornSets(ChildPornHashLookup.lookupHash(mediaItem.getHash())); + message.lookupAndAddChildPornSets(mediaItem.getHash()); } break; }