From bfb09976167060c811834a1a9b299bd6aad761e9 Mon Sep 17 00:00:00 2001 From: tc-wleite Date: Wed, 4 Oct 2023 17:32:51 -0300 Subject: [PATCH] '#1880: Use a single constant for WA "@s.whatsapp.net" suffix. --- .../java/iped/parsers/whatsapp/ExtractorAndroid.java | 4 ++-- .../java/iped/parsers/whatsapp/ReportGenerator.java | 7 +++---- .../src/main/java/iped/parsers/whatsapp/WAAccount.java | 10 ++++------ .../src/main/java/iped/parsers/whatsapp/WAContact.java | 2 ++ .../iped/parsers/whatsapp/WAContactsExtractorIOS.java | 8 ++++---- 5 files changed, 15 insertions(+), 16 deletions(-) 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 d681ea148d..1a11c761cc 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 @@ -200,7 +200,7 @@ protected List extractChatList() throws WAExtractorException { for (Chat c : undeletedChats) { String remoteId = c.getRemote().getId(); - remoteId += c.isGroupChat() ? "@g.us" : "@s.whatsapp.net"; //$NON-NLS-1$ //$NON-NLS-2$ + remoteId += c.isGroupChat() ? "@g.us" : WAContact.waSuffix; if (!activeChats.contains(remoteId)) { list.add(c); if (firstTry && c.isDeleted()) { @@ -337,7 +337,7 @@ private List extractMessages(Connection conn, WAContact remote, boolean boolean recoverDeleted = undeleteTable != null && !undeletedMessages.isEmpty(); String id = remote.getId(); - id += isGroupChat ? "@g.us" : "@s.whatsapp.net"; //$NON-NLS-1$ //$NON-NLS-2$ + id += isGroupChat ? "@g.us" : WAContact.waSuffix; Set activeMessages = new HashSet<>(); Map activeMessageIds = new HashMap<>(); 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 69a78e04be..b8cba4de19 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 @@ -44,7 +44,6 @@ public class ReportGenerator { private static final String lockedIcon = ""; private static final String locationIcon = ""; private static final String forwardedIcon = ""; - private static final String waSuffix = "@s.whatsapp.net"; public ReportGenerator() { } @@ -427,7 +426,7 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean if (!number.isEmpty()) { if (name.isEmpty()) { name = number; - } else if (!number.equals(name) && !number.equals(name + waSuffix)) { + } else if (!number.equals(name) && !number.equals(name + WAContact.waSuffix)) { name += " (" + number + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } } @@ -675,8 +674,8 @@ private synchronized void printMessage(PrintWriter out, Message message, boolean if (contact != null) { name = contact.getName(); } - if (number.endsWith(waSuffix)) { - number = number.substring(0, number.length() - waSuffix.length()); + if (number.endsWith(WAContact.waSuffix)) { + number = number.substring(0, number.length() - WAContact.waSuffix.length()); } } } diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/WAAccount.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/WAAccount.java index 8c4fe11662..6cd2b9b51a 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/WAAccount.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/WAAccount.java @@ -20,8 +20,6 @@ public class WAAccount extends WAContact { - private static final String idSuffix = "@s.whatsapp.net"; //$NON-NLS-1$ - private boolean isUnknown = false; public WAAccount(String id) { @@ -47,8 +45,8 @@ public static WAAccount getFromAndroidXml(InputStream is) { if (value == null || value.isBlank()) return null; } - if (!value.endsWith(idSuffix)) - value += idSuffix; + if (!value.endsWith(waSuffix)) + value += waSuffix; WAAccount account = new WAAccount(value); @@ -80,8 +78,8 @@ public static WAAccount getFromIOSPlist(InputStream is) { return null; } String strVal = value.toString(); - if (!strVal.endsWith(idSuffix)) - strVal += idSuffix; + if (!strVal.endsWith(waSuffix)) + strVal += waSuffix; WAAccount account = new WAAccount(strVal); diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/WAContact.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/WAContact.java index 6e10ff873f..a086eeca19 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/WAContact.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/WAContact.java @@ -2,6 +2,8 @@ public class WAContact { + protected static final String waSuffix = "@s.whatsapp.net"; + private final String id; private final String suffix; diff --git a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/WAContactsExtractorIOS.java b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/WAContactsExtractorIOS.java index 85afec7301..61334a17b2 100644 --- a/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/WAContactsExtractorIOS.java +++ b/iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/WAContactsExtractorIOS.java @@ -58,8 +58,8 @@ public void extractContactList() throws WAExtractorException { while (rs.next()) { String id = getString(rs, "ZWHATSAPPID"); - if (!id.endsWith("@s.whatsapp.net")) { - id += "@s.whatsapp.net"; + if (!id.endsWith(WAContact.waSuffix)) { + id += WAContact.waSuffix; } WAContact c = directory.getContact(id); c.setDisplayName(getString(rs, "ZHIGHLIGHTEDNAME")); //$NON-NLS-1$ @@ -82,8 +82,8 @@ public void extractContactList() throws WAExtractorException { if (undeletedContactsTable != null) { for (var row : undeletedContactsTable.getTableRows()) { var id = row.getTextValue("ZWHATSAPPID"); - if (!id.endsWith("@s.whatsapp.net")) { - id += "@s.whatsapp.net"; + if (!id.endsWith(WAContact.waSuffix)) { + id += WAContact.waSuffix; } if (! directory.hasContact(id)) { // only recover contact if it does not exist already WAContact c = directory.getContact(id);