Wednesday, November 5, 2014

Using Yowsup to get groups and group information

Took me a while to figure this out.

I had a particularly annoying problem with Python: it thinks that I'm giving it 14 parameters when I'm giving it 2. In particular, I had to add dummy parameters to sendGetGroups and sendGetGroupInfo inside connectionmanager.py so that I can pass arguments to them correctly.

Using Yowsup to get information about a group

Using Yowsup to get the list of all groups the user is participating in

Files:
Yowsup\connectionmanager.py
Examples\GroupInfoClient.py
Examples\GetAllGroupsClient.py
yowsup-cli

Tuesday, November 4, 2014

Using Yowsup to send contacts

Contacts are referred to as Vcards inside the library, so I'll refer them as Vcards from the next sentence on. Vcards work in the same way as location, as both of them do not need the media request, media upload, send media chain. A call to message_vcardSend will do. message_vcardSend accepts 3 parameters: JID of person to send to, data, and name. I had no idea what data is, so I started off writing a listener for Vcards instead, to learn the format of the data parameter.


I've included the files for the listener below.

Following the format as shown above, I wrote the code for sending Vcards. It generally works, but occasionally, the send doesn't get through and the receiver will receive nothing. If anyone can pinpoint why this happens please enlighten me.




Files:





Monday, November 3, 2014

Using Yowsup to send location

Previously when sending images, video and audio, the flow goes like this:

Request media upload -> request success -> upload -> upload success -> send url of uploaded media to other people

I realised that sending location does not follow this pattern. All it requires is calling message_locationSend with the correct parameters and it'll work.

Nevertheless, I had to fix up connectionmanager.py a bit as it does not include the "name" attribute, and it crashes my Whatsapp on iOS everytime the location is sent (as of 4 Nov 2014)...the updated connectionmanager.py is posted below. The line that is changed is marked with #sirpoot

If you send with a name, longitude and latitude you'll get this:





If you send with an empty name, you'll replicate the same thing as what Whatsapp on iOS does:






 Files:
Examples\LocationUploaderClient.py
Yowsup\connectionmanager.py
yowsup-cli





Sunday, November 2, 2014

Using Yowsup to send audio and video

It works.

Sending audio and video files work in the same way as sending images. It begins with a call to media_requestUpload with the hash, a string of the type of file to upload, and the filesize as arguments, and once the request succeeds, the client has to use MediaUploader to upload the local file, and finally when the upload completes the client can then send the URL to friends using the method message_imageSend, message_audioSend, and message_videoSend for images, audio files and video files respectively. The only difference in the API for these 3 methods are: message_audioSend does not have a preview as argument, while message_videoSend and message_imageSend both have a argument for the preview (which can be None).

Please note that most of the audio and video uploader code is copy-pasted from the image uploader, and I haven't wrote in preview code for the video uploader due to the infinite variety of video formats out there. This code is more for people to look at and see how it works than to be used in production.

Examples\VideoUploaderClient.py
yowsup-cli

Tested with .mp3 and .wav for audio, and .mp4 for video.

Using Yowsup to send audio and video files

Saturday, August 16, 2014

Multi-monitor gaming

Managed to dig out spare monitors from the storehouse, now I can finally play games on 3 monitors!

My graphics card is the Chinese Colorful GTX 750. It has 3 ports at the back, 1 VGA, 1 DVI, and 1 HDMI. I used 1 HDMI to DVI cable for the first monitor, 1 DVI to DVI for the 2nd, and 1 VGA to VGA for the third monitor.

Here's the outcome:

I now have one super wide desktop. Panorama wallpapers look absolutely awesome!

3-monitor Payday 2. All 3 monitors have 4:3 aspect ratio

3-monitor Payday 2



In this experiment, I tried to determine if the same monitors (the same aspect ratio) is needed for 3-monitor gaming to work. For this and the following photo I replaced the center monitor with a widescreen one (16:9 aspect ratio). To my surprise, the center monitor isn't skewed or stretched; it worked perfectly!

Aspect ratios of monitors from left to right: 4:3, 16:9, 4:3. No problems with the graphics!

After playing several rounds of Payday 2 I discovered that the side monitors really help in spatial awareness. I can remember map layouts much better with the side monitors around!

Tuesday, August 12, 2014

Using Yowsup to send pictures to a group

So, I intended to send pictures to my whatsapp group...these are the steps I took.

1. Buy a cheap SIM card, take note of that number
2. Edit the config file, use yowsup-cli to register using that phone number and input the subsequent verification code

Register a Whatsapp account using phone number


3. Extend the ListenerClient to listen for group messages, ask one of my groupmates to send the group a test message. This allows me to obtain the JID of the group.

Listen for group messages to obtain JID of the group

4. Extend CmdClient.py and fix it, and add in my own additions to yowsup-cli to be able to send

Sending images to group chat


Here are all my files at the end:

Examples\GroupListenerClient.py
Examples\UploaderClient.py
Examples\CmdClient.py
yowsup-cli


References:

Using the yowsup-cli, registering a new account
http://hacktracking.blogspot.sg/2013/02/yowsup-cli-send-whatsapp-messages-from.html

Getting JID of the group
https://github.com/tgalal/yowsup/issues/162

Sending images by SamsonBox
https://github.com/tgalal/yowsup/issues/178

Creating preview images
https://github.com/tgalal/yowsup/issues/35#issuecomment-41364453



Tuesday, July 8, 2014

Wierd VM behavior

My Windows 7 virtual machine, which has 2GB of RAM allocated to it, is extremely laggy, to the point that opening a folder will take minutes. Surprisingly, it became all smooth and quick when I decreased its RAM allocation to 1GB. Intrigued, I used Process Explorer to look at some of its stats.

Win7 VM with 2GB of RAM

When the VM had 2 GB of RAM, its CPU usage is mostly zero. In addition, even when idle, it's performing about 200 Page faults per second.

Win7 VM with 1GB of RAM
When the VM had 1 GB of RAM, it used 1.2GB for its working set, the CPU is hard at work, and page faults are close to non.

Wierd... I have no idea why.

Monday, May 26, 2014

timeBeginPeriod

Was reading how the use of timeBeginPeriod to increase system tick frequency could lead to a shorter battery life (read here) ...decided to investigate how timeBeginPeriod function interacts with Windows 8, since Windows 8 uses tickless kernel and theoretically has no relations with system timer ticks. From MSDN, timeBeginPeriod resides in winmm.dll. There are 2 versions on winmm.dll on my Win 8 machine, one under c:\Windows\SysWow64 and one under c:\Windows\system32.

timeBeginPeriod in c:\Windows\SysWow64\winmm.dll:

timeBeginPeriod calls an imported function, timeBeginPeriod@4

timeBeginPeriod@4 belongs to api-ms-win-mm-time-l1-1-0.dll

timeBeginPeriod@4 in api-ms-win-mm-time-l1-1-0.dll is an empty function
timeBeginPeriod in c:\Windows\system32\winmm.dll uses the same flow, importing the function timeBeginPeriod@4 from api-ms-win-mm-time-l1-1-0.dll:

x64 api-ms-win-mm-time-l1-1-0.dll uses the same function for multiple exports

And that one function is empty

Hence, I've verified that timeBeginPeriod does not work in Win 8...so why is Win 8 battery life still so weak?!




Monday, May 19, 2014

How Procmon works




Out of curiosity I looked under the hood of the tool that lets you look under the hood of other programs.

To be able to monitor so many system functions at once, Procmon probably uses a driver to do that. So I went looking for Procmon's driver using GMER, and found PROCMON23.SYS.




I didn't see PROCMON23.SYS inside the Sysinternals directory, so I guess it'll be inside the PE structure. Sure enough, when I use PE Explorer to open up Procmon, I found it inside the BINRES directory in the RESOURCE section.



Extracted out the driver, and analysed using NikPEViewer. It's a 32 bit driver.


Then proceeded to analysis using IDA. It registers itself as a filter driver...



Creates a filter communication port at \ProcessMonitor23Port and starts the filter.



Procmon 64 bit

When running Procmon in 64-bit systems, another process called Procmon64.exe is created. This isn't found anywhere in the Sysinternals folder.

Procmon in 64-bit Windows
This implies that its 64-bit image is being stored in its 32-bit executable. Hence, I looked up the second entry under the BINRES section, and sure enough, it's a PE file:

Location of Procmon 64 bit image

Procmon's 64 bit image

Initially I thought it was the 64-bit Procmon driver...turned out that it is the 64-bit Procmon executable. And of course, the 64-bit driver is hidden inside the 64 bit executable's resource section.

Procmon 64 bit driver





Friday, May 16, 2014

How to turn off monitor screen

Found a small program called Turn Off Monitor, decided to investigate how it works.

 Used IDA to open it, turned out to be a .NET exe. Opened it using Dotnet IL Editor instead.

Main code:


Seems like the only API call needed is SendMessage. ldc.i4.m1 means push -1 to stack, so the API call is SendMessage(-1,a,b,2).

SendMessage belongs to user32.dll:


Second argument, a is 0x04000003:


Third argument, b is 0x04000004:


So the only API call needed turned out to be user32!SendMessage(-1,0x04000003,0x04000004,2).