Skip to content

Commit a81646c

Browse files
committedAug 9, 2024
sepinf-inc#2286: support for group admins in WhatsAppParser
1 parent da35073 commit a81646c

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed
 

‎iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Chat.java

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class Chat {
2323
private String recoveredFrom;
2424

2525
private Set<WAContact> groupMembers = new HashSet<>();
26+
private Set<WAContact> groupAdmins = new HashSet<>();
2627

2728
public Chat(WAContact remote) {
2829
this.remote = remote;
@@ -143,6 +144,10 @@ public Set<WAContact> getGroupMembers() {
143144
return groupMembers;
144145
}
145146

147+
public Set<WAContact> getGroupAdmins() {
148+
return groupAdmins;
149+
}
150+
146151
public void setGroupMembers(Set<WAContact> groupmembers) {
147152
this.groupMembers = groupmembers;
148153
}

‎iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/Extractor.java

+3
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ protected void setGroupMembers(Chat c, Connection conn, String SELECT_GROUP_MEMB
6464
String memberId = rs.getString("member");
6565
if (memberId != null && !memberId.trim().isEmpty()) {
6666
c.getGroupMembers().add(contacts.getContact(memberId));
67+
if (rs.getBoolean("admin")) {
68+
c.getGroupAdmins().add(contacts.getContact(memberId));
69+
}
6770
}
6871
}
6972
}

‎iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ExtractorAndroid.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ public class ExtractorAndroid extends Extractor {
7777
private boolean hasMediaCaptionCol = false;
7878
private boolean hasSubjectCol = false;
7979
private boolean hasMediaDurationCol = false;
80-
private boolean hasGroupParticiantsTable = true;
80+
private boolean hasGroupParticipantsTable = true;
81+
private boolean hasGroupParticipantUserTable = true;
8182
private boolean hasForwardedCol = false;
8283
private boolean hasQuoteCol = false;
8384
private SQLException parsingException = null;
@@ -147,7 +148,8 @@ protected List<Chat> extractChatList() throws WAExtractorException {
147148
hasSortTimestamp = databaseHasSortTimestamp(conn);
148149
hasChatView = databaseHasChatView(conn);
149150
hasThumbTable = SQLite3DBParser.containsTable("message_thumbnails", conn); //$NON-NLS-1$
150-
hasGroupParticiantsTable = SQLite3DBParser.containsTable("group_participants", conn); //$NON-NLS-1$
151+
hasGroupParticipantsTable = SQLite3DBParser.containsTable("group_participants", conn); //$NON-NLS-1$
152+
hasGroupParticipantUserTable = SQLite3DBParser.containsTable("group_participant_user", conn); //$NON-NLS-1$
151153
hasEditVersionCol = SQLite3DBParser.checkIfColumnExists(conn, "messages", "edit_version"); //$NON-NLS-1$ //$NON-NLS-2$
152154
hasMediaCaptionCol = SQLite3DBParser.checkIfColumnExists(conn, "messages", "media_caption"); //$NON-NLS-1$ //$NON-NLS-2$
153155
hasMediaDurationCol = SQLite3DBParser.checkIfColumnExists(conn, "messages", "media_duration"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -217,7 +219,9 @@ protected List<Chat> extractChatList() throws WAExtractorException {
217219
undeletedMessagesTable, hasThumbTable, hasEditVersionCol, firstTry));
218220
if (c.isGroupChat()) {
219221
try {
220-
setGroupMembers(c, conn, hasGroupParticiantsTable ? SELECT_GROUP_MEMBERS : null);
222+
String query = hasGroupParticipantUserTable ? SELECT_GROUP_MEMBERS_2
223+
: hasGroupParticipantsTable ? SELECT_GROUP_MEMBERS : null;
224+
setGroupMembers(c, conn, query);
221225
} catch (SQLException ex) {
222226
if (firstTry || !isSqliteCorruptException(ex)) {
223227
throw ex;
@@ -781,7 +785,10 @@ private static String getMessagesQueryQuote(boolean hasThumbTable, boolean hasEd
781785
+ "WHERE remoteId=? and status!=-1 ORDER BY timestamp"; //$NON-NLS-1$
782786

783787
// to address a field must use ` instead of '
784-
private static final String SELECT_GROUP_MEMBERS = "select gjid as 'group', jid as member FROM group_participants where `group`=?"; //$NON-NLS-1$
788+
private static final String SELECT_GROUP_MEMBERS = "select gjid as 'group', jid as member, admin FROM group_participants where `group`=?"; //$NON-NLS-1$
789+
790+
static final String SELECT_GROUP_MEMBERS_2 = "select g._id as group_id, g.raw_string as group_name, u._id as user_id, u.raw_string as member, gp.rank > 0 as admin "
791+
+ "FROM group_participant_user gp inner join jid g on g._id=gp.group_jid_row_id inner join jid u on u._id=gp.user_jid_row_id where u.server='s.whatsapp.net' and u.type=0 and group_name=?"; //$NON-NLS-1$
785792

786793
private static final String SELECT_QUOTES_NO_THUMBS_TABLE = "SELECT mq._id AS id, mq.key_remote_jid "
787794
+ "as remoteId, mq.remote_resource AS remoteResource, mq.status, mq.data, "

‎iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ExtractorAndroidNew.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ protected List<Chat> extractChatList() throws WAExtractorException {
145145
for (Chat c : list) {
146146
Collections.sort(c.getMessages());
147147
if (c.isGroupChat()) {
148-
setGroupMembers(c, conn, SELECT_GROUP_MEMBERS);
148+
setGroupMembers(c, conn, ExtractorAndroid.SELECT_GROUP_MEMBERS_2);
149149
}
150150
}
151151

@@ -1093,7 +1093,4 @@ private static String getSelectBlockedQuery(Connection conn) throws SQLException
10931093
+ " left join chat chat1 on chat1.jid_row_id = log.jid_row_id"
10941094
+ " left join chat chat2 on chat2.jid_row_id = log.group_jid_row_id";
10951095

1096-
private static final String SELECT_GROUP_MEMBERS = "select g._id as group_id, g.raw_string as group_name, u._id as user_id, u.raw_string as member "
1097-
+ "FROM group_participant_user gp inner join jid g on g._id=gp.group_jid_row_id inner join jid u on u._id=gp.user_jid_row_id where u.server='s.whatsapp.net' and u.type=0 and group_name=?"; //$NON-NLS-1$
1098-
10991096
}

‎iped-parsers/iped-parsers-impl/src/main/java/iped/parsers/whatsapp/ExtractorIOS.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ public void extractPushNames() {
16421642

16431643
private static final String SELECT_PUSH_NAMES = "select ZJID as jid, ZPUSHNAME as pushname from ZWAPROFILEPUSHNAME";
16441644

1645-
private static final String SELECT_GROUP_MEMBERS = "select CS.ZCONTACTJID as `group`, ZMEMBERJID as member from ZWAGROUPMEMBER GM "
1645+
private static final String SELECT_GROUP_MEMBERS = "select CS.ZCONTACTJID as `group`, ZMEMBERJID as member, ZISADMIN as admin from ZWAGROUPMEMBER GM "
16461646
+ "inner join ZWACHATSESSION CS on GM.ZCHATSESSION=CS.Z_PK where `group`=?";
16471647

16481648
private static final String SELECT_MESSAGES_USER = "SELECT ZWAMESSAGE.Z_PK AS id, ZCHATSESSION " //$NON-NLS-1$

0 commit comments

Comments
 (0)
Please sign in to comment.