Advertisement
Guest User

whatsapp reverse eng js version

a guest
Apr 7th, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const randomBytes = require('randombytes');
  2. const WebSocket = require('ws');
  3. const QrCode = require('qrcode');
  4.  
  5. const createCounter = start => {
  6.   let count = start || 0;
  7.   return () => {
  8.     return count++;
  9.   }
  10. }
  11.  
  12. const incrementCount = createCounter(1);
  13.  
  14. const createMessageTag = () => {
  15.   const date = new Date();
  16.   const dateTime = date.getTime();
  17.   const textTime = dateTime.toString().substring(0, 10);
  18.   const count = incrementCount();
  19.   const messageTag = `${textTime}.--${count}`;
  20.   return messageTag;
  21. }
  22.  
  23. const msgTag = createMessageTag();
  24. const clientId = randomBytes(16);
  25.  
  26. const WHATSAPP_WEB_VERSION = '0,4,2088';
  27. let msg = `${msgTag},[\"admin\",\"init\",[${WHATSAPP_WEB_VERSION}],[\"Windows\",\"Chrome\",\"10\"],\"${clientId}\",true]`;
  28.  
  29. const getJsonText = (text) => {
  30.  const indexOfFirstComma = text.indexOf(',');
  31.  const newText = text.substring(indexOfFirstComma + 1, text.length);
  32.  const jsonText = JSON.parse(newText);
  33.  return jsonText;
  34. }
  35.  
  36. const isStatusOk = text => {
  37.  const jsonText = getJsonText(text);
  38.  const { status } = jsonText;
  39.  return status === 200
  40. }
  41.  
  42. const isConnected = text => {
  43.  const jsonText = getJsonText(text);
  44.  const { connected } = jsonText;
  45.  return connected || false;
  46. }
  47.  
  48. const whatsappHost = 'wss://web.whatsapp.com/ws';
  49. const ws = new WebSocket(whatsappHost, {
  50.  origin: 'https://web.whatsapp.com'
  51. });
  52.  
  53. ws.on('open', () => {
  54.  ws.send(`web socket connected on ${whatsappHost}`);
  55.  console.log('connected websocket');
  56.  ws.send(msg);
  57. });
  58.  
  59. ws.on('message', (data) => {
  60.  console.log('ws data: ', data);
  61.  const statusConnection = isStatusOk(data);
  62.  console.log('Connection status:', statusConnection);
  63.  
  64.  if(statusConnection) {
  65.    const connectionInfo = getJsonText(data);
  66.    console.log('connection info:', connectionInfo);
  67.  
  68.    const qrCodeOptions =  { type: 'terminal', errorCorrectionLevel: 'Q' };
  69.    const { ref, } = connectionInfo;
  70.    const codeToGenerate = ``;
  71.    QrCode.toString(codeToGenerate, qrCodeOptions, (err, url) => {
  72.      if(err) {
  73.        console.log('error:', err);
  74.        return;
  75.      }
  76.      console.log('QRCODE:');
  77.      console.log(url);
  78.    })
  79.  }
  80. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement