Sitemap

My joy of modifying a SIP application with Visual Studio 2022

3 min readAug 29, 2024

--

More recently, I was tasked with modifying Microsip application to automatically open a website link on an incoming call.

You can watch this video to get an idea about the project- https://www.youtube.com/watch?v=74viGbjTpmQ

For those of you who aren’t familiar with Microsip, it’s a softphone much like 3cx or phone.

My initial approach was not to modify it’s source code, instead utilize frida to hook my custom functionality at specified function calls. But upon inspection, it turns out hard. Frida is basically a reverse engineering tool but who cares if it does my job? Then, I stumbled upon modifying its source code.

After a bit of hit and trial with ripgrep and Microsip source code, I get to know where we needed to hook our new functionality.

So, at first glance, I thought I needed to hook the functionality on “CallAccept” function of RingDlg.cpp file.

Press enter or click to view image in full size

But even after it’s integration, I hadn’t been getting the expected outcome. “local_contact” is not yielding us the result. We needed to capture the incoming caller ID number.

After digging through the source code for some hours, I discovered Microsip is already doing all these parsing to call_info and give us sip_uri to keep all these details. We just need to grab our variables from it, sip_uri->user.

At this moment, even the client changed his requirement, instead of firing this “open link” command on call answer, he wanted to open it directly oncoming call.

Again, I needed to play with its source code, but luckily, I discovered another function called “onIncomingCall” in mainDlg.cpp within next 10 minutes.

Get Bhuwan Mishra’s stories in your inbox

Join Medium for free to get updates from this writer.

Now, the hard work is done. We just need to place the code, build and show it to the client.

Press enter or click to view image in full size

Now, the whole idea of opening the custom link is execute this system command:

// Grab BASE_URI from a txt file
// Execute this system command
// start BASE_URI + sipuri.user

To execute the system command, we need to include this directive

#include <cstdlib>

This is the custom code I added:

 // // File containing the URL
const std::string filename = "C:\\MICROSIP_BASE_URL.txt";


// Read the URL from the file
std::ifstream file;
file.open(filename);
std::string baseurl;


if (!file.is_open()) {
std::cerr << "Error: Could not open file " << filename << std::endl;
}

while (getline(file, baseurl)) {
if (baseurl.empty()) {
std::cerr << "Error: URL is empty" << std::endl;
}


std::string user(CW2A(sip_uri->user.GetString()));

std::string command = "start \"\" \"" + baseurl + user + "\"";

std::cout << "command is " << command << std::endl;

// Execute the command
int result = system(command.c_str());
}

Finally, I hit Ctrl+B to build the whole application in Debug, and it worked as expected. Suddenly, I hop on Zoom call to show this awesome demo to my client. He was also happy.

The key takeaways from this project:

Microsip is using PJSIP library for all of its sip-related functionalities. Knowing this, I did some more research and came to know another contender to PJSIP which is baresip. The real reason, I had been looking for some alternative, the first is the frustration in testing sip-related functionalities under my Linux environment and the second one, PJSIP source code doesn’t seem appealing to me to learn more on SIP.

The second takeaway is PJSIP is dependent on OpenSSL. Luckily, you don’t need to compile OpenSSL from source. You can get its binaries from here- https://wiki.openssl.org/index.php/Binaries

Also, you need SDL libraries- https://github.com/libsdl-org/SDL/releases/latest. It contains both .lib and dll files. DLL files should be place next to your microsip release/debug exe.

If you need to support video calls, you need openh64 for video encoding and decoding functionalities. You can download it from here.

Even there’s a Softphone client built with baresip for windows- http://tomeko.net/software/SIPclient/.

Another frustration was setting up and using Visual Studio. To start even working with hello world cpp program, you need to download Microsoft 10–15 GB of its c++ workload.

--

--

Bhuwan Mishra
Bhuwan Mishra

Written by Bhuwan Mishra

A freelance writer specializing in DevOps and Cybersecurity who turns technical jargon into accessible, actionable content. Email: mishrabhuban4@gmail.com