diff --git a/core/interception.js b/core/interception.js index f05b502..088e7f7 100644 --- a/core/interception.js +++ b/core/interception.js @@ -50,15 +50,8 @@ wsHook.before = function (originalData, url) var counter = decryptedFrameInfo.counter; var realNode = await nodeReaderWriter.decodeStanza(decryptedFrameOriginal, gzipInflate); - - var isAllowed = NodeHandler.isSentNodeAllowed(realNode); - var manipulatedNode = deepClone(realNode); - if (!isAllowed) - { - manipulatedNode.tag = "blocked_node"; - } - - manipulatedNode = await NodeHandler.onSentNode(manipulatedNode); + + var [isAllowed, manipulatedNode] = await NodeHandler.interceptOutgoingNode(realNode); decryptedFrames[i] = {node: manipulatedNode, counter: counter}; if (WAdebugMode || WAPassthroughWithDebug) diff --git a/core/node_handler.js b/core/node_handler.js index 713758e..3c06054 100644 --- a/core/node_handler.js +++ b/core/node_handler.js @@ -83,63 +83,78 @@ NodeHandler.isSentNodeAllowed = function (node) return true; } -NodeHandler.onSentNode = async function (node) +NodeHandler.interceptOutgoingNode = async function (node) { - try + var isAllowed = NodeHandler.isSentNodeAllowed(node); + if (!isAllowed) { - // - // Check for message nodes - // - if (node.tag == "message") - { - // manipulating a message node + var manipulatedNode = deepClone(node); + manipulatedNode.tag = "blocked_node"; + return [isAllowed, manipulatedNode]; + } - var childNodes = node.content; - for (var i = 0; i < childNodes.length; i++) - { - var childNode = childNodes[i]; + // + // Check for message nodes + // + if (node.tag == "message") + { + // manipulating a message node + node = await NodeHandler.onOutgoingMessageNode(node); + } - if (childNode.tag == "enc") - { - childNodes[i] = await this.onSentMessageNode(childNode, node.attrs["to"].toString()); - } + return [true, node]; +} + +NodeHandler.onOutgoingMessageNode = async function (messageNode) +{ + var childNodes = messageNode.content; + for (var i = 0; i < childNodes.length; i++) + { + var childNode = childNodes[i]; - // list of devices to which a copy of the message is sent - if (childNode.tag == "participants") + try + { + if (childNode.tag == "enc") + { + childNodes[i] = await this.onSentEncNode(childNode, messageNode.attrs["to"].toString()); + } + + // list of devices to which a copy of the message is sent + // say, in a message to a group, will contain copies of the message for each group participant. + // in a private chat, will contain copies for the recipient and for the sender's real device + if (childNode.tag == "participants") + { + var participants = childNode.content; + for (var j = 0; j < participants.length; j++) { - var participants = childNode.content; - for (var j = 0; j < participants.length; j++) + var participant = participants[j]; + if (participant.tag != "to") continue; + + var encNode = participant.content[0]; + if (encNode.tag == "enc") { - var participant = participants[j]; - if (participant.tag != "to") continue; - - var messageNode = participant.content[0]; - if (messageNode.tag == "enc") - { - var toJID = participant.attrs["jid"] ? participant.attrs["jid"]: participant.attrs["from"]; + var toJID = participant.attrs["jid"] ? participant.attrs["jid"]: participant.attrs["from"]; - participant = await this.onSentMessageNode(participant, toJID.toString()); - participants[j] = participant; - } + encNode = await this.onSentEncNode(encNode, toJID.toString()); + participant.content[0] = encNode; + participants[j] = participant; } } } - } - - } - catch (exception) - { - console.error("WhatsIncognito: Allowing WA packet due to exception:"); - console.error(exception); - console.error(exception.stack); - return node; + catch (exception) + { + console.error("WhatsIncognito: Allowing WA packet due to exception:"); + console.error(exception); + console.error(exception.stack); + return [true, messageNode] + } } - return node; + return messageNode; } -NodeHandler.onSentMessageNode = async function (messageNode, remoteJid) +NodeHandler.onSentEncNode = async function (encNode, remoteJid) { if (remoteJid && isChatBlocked(remoteJid) && autoReceiptOnReplay) { @@ -159,7 +174,7 @@ NodeHandler.onSentMessageNode = async function (messageNode, remoteJid) // ... var putBreakpointHere = 1; - return messageNode; + return encNode; } NodeHandler.onReceivedNode = async function (node) diff --git a/old/legacy_single_device.js b/old/legacy_single_device.js index 71d9fd1..f2ede67 100644 --- a/old/legacy_single_device.js +++ b/old/legacy_single_device.js @@ -156,7 +156,7 @@ WACrypto.encryptWithWebCrypto = function(nodeBuffer, isMultiDevice = false, isIn } } -NodeHandler.onSentNode = async function (node, isMultiDevice) +NodeHandler.interceptOutgoingNode = async function (node, isMultiDevice) { try { @@ -177,7 +177,7 @@ NodeHandler.onSentNode = async function (node, isMultiDevice) var child = participants[j]; if (child.tag == "message") { - var messageNode = await this.onSentMessageNode(child, isMultiDevice); + var messageNode = await this.onSentEncNode(child, isMultiDevice); participants[j] = messageNode; } } @@ -196,7 +196,7 @@ NodeHandler.onSentNode = async function (node, isMultiDevice) return node; } -NodeHandler.onSentMessageNode = async function (messageNode, remoteJid, isMultiDevice) +NodeHandler.onSentEncNode = async function (messageNode, remoteJid, isMultiDevice) { if (!isMultiDevice) {