Skip to content

Instantly share code, notes, and snippets.

@Mothblocks
Created August 20, 2023 01:38
Show Gist options
  • Select an option

  • Save Mothblocks/06b415afd75672fb03637804435350d2 to your computer and use it in GitHub Desktop.

Select an option

Save Mothblocks/06b415afd75672fb03637804435350d2 to your computer and use it in GitHub Desktop.
Library to get sleeping procs on Linux
g++ -nostdlib -m32 -shared -fPIC -o libbyond_sleeping_procs.so main.cpp
#include <link.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
struct DungServer {
void* vtable = 0;
char* sleepingProcs = 0;
DungServer(void* vtable): vtable(vtable) {}
};
void receivedStatus(DungServer* server, char* message) {
server->sleepingProcs = new char[strlen(message) + 1];
strcpy(server->sleepingProcs, message);
}
typedef void (__attribute__((cdecl)) *DungServer_RequestStatus)(DungServer*);
extern "C" const char* get_status(int argc, char* argv[]) {
void* handle = dlopen("libbyond.so", RTLD_NOW);
if (!handle) {
printf("error: could not open libbyond.so\n");
return nullptr;
}
DungServer_RequestStatus requestStatus = reinterpret_cast<DungServer_RequestStatus>(dlsym(handle, "_ZN10DungServer13RequestStatusEv"));
if (!requestStatus) {
printf("error: could not find DungServer::RequestStatus\n");
return nullptr;
}
void* vtable[26] = { 0 };
vtable[25] = (void*)&receivedStatus;
DungServer* dungServer = new DungServer(vtable);
requestStatus(dungServer);
return dungServer->sleepingProcs;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment