Skip to content

Instantly share code, notes, and snippets.

@Asmageddon
Created Sep 4, 2011
Embed
What would you like to do?
Intercept and modify messages sent by libpurple(fails)
#include <glib.h>
#include <glib-object.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include "marshal.h" /* The file generated from marshal.list via tool glib-genmarshal */
//VOID:INT,STRING,STRING - put into marshal.list
//glib-genmarshal --header --prefix=marshal marshal.list > marshal.h
//glib-genmarshal --body --prefix=marshal marshal.list > marshal.c
//Compile with: "gcc -MMD -Wall -ggdb -O -pthread -I/usr/include/dbus-1.0 -I/usr/lib/i386-linux-gnu/dbus-1.0/include -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -pthread -L/usr/lib/i386-linux-gnu -ldbus-glib-1 -ldbus-1 -lpthread -lgobject-2.0 -lgthread-2.0 -lrt -lglib-2.0 marshal.c main.c -o main"
/* pidgin dbus station name */
#define DBUS_SERVICE_PURPLE "im.pidgin.purple.PurpleService"
#define DBUS_PATH_PURPLE "/im/pidgin/purple/PurpleObject"
#define DBUS_INTERFACE_PURPLE "im.pidgin.purple.PurpleInterface"
/* global dbus instance */
DBusGConnection *bus;
DBusGProxy *purple_proxy;
/* Main event loop */
GMainLoop *loop = NULL;
/* Signal callback handling routing */
void sending_im_msg_cb (DBusGProxy *purple_proxy,
int account_id, const char *receiver, char **message,
gpointer user_data)
{
*message = "DEATH";
g_print("Account %d sends msg \"%s\" to %s\n", account_id, *message, receiver);
}
//signal sender=:1.19 -> dest=(null destination) serial=3113 path=/im/pidgin/purple/PurpleObject; interface=im.pidgin.purple.PurpleInterface; member=SendingImMsg
//int32 5479
//string "Asmageddon@gmail.com"
//string "a"
/*
* The main process, loop waiting for any signals
*/
int main (int argc, char **argv)
{
GError *error = NULL;
g_type_init ();
/* Get the bus */
bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
if (bus == NULL) {
g_printerr("Failed to open connection to bus: %s", error->message);
g_error_free(error);
return -1;
}
/* Create a proxy object for the bus driver */
purple_proxy = dbus_g_proxy_new_for_name (bus,
DBUS_SERVICE_PURPLE,
DBUS_PATH_PURPLE,
DBUS_INTERFACE_PURPLE);
if (!purple_proxy) {
g_printerr("Couldn't connect to the Purple Service: %s", error->message);
g_error_free(error);
return -1;
}
/* Create the main loop instance */
loop = g_main_loop_new (NULL, FALSE);
/* Register dbus signal marshaller */
dbus_g_object_register_marshaller(marshal_VOID__INT_STRING_STRING,
G_TYPE_NONE, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
/* Add the signal to the proxy */
dbus_g_proxy_add_signal(purple_proxy, "SendingImMsg",
G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
/* Connect the signal handler to the proxy */
dbus_g_proxy_connect_signal(purple_proxy, "SendingImMsg",
G_CALLBACK(sending_im_msg_cb), bus, NULL);
/* Main loop */
g_main_loop_run (loop);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment