injector capture resource register
This commit is contained in:
parent
8b2cb8fc5a
commit
2405fa9bc1
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
struct RegisteredResource {
|
||||
RegisteredResource(int i, const unsigned char* resourceStruct, const unsigned char* resourceName, const unsigned char* resourceData);
|
||||
|
||||
int i; // what is this? version? type? (always just 2?)
|
||||
const unsigned char* resourceStruct;
|
||||
const unsigned char* resourceName;
|
||||
const unsigned char* resourceData;
|
||||
};
|
||||
|
||||
std::map<uint64_t, std::shared_ptr<RegisteredResource>>* registeredResources = nullptr;
|
|
@ -1,22 +1,24 @@
|
|||
|
||||
// this file injects the debugger into the QApplication
|
||||
|
||||
#include "injector.h"
|
||||
#include "qtdebugger.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <QApplication>
|
||||
|
||||
class QApplication;
|
||||
using registerFunc = bool (*) (int, const unsigned char*, const unsigned char*, const unsigned char*);
|
||||
|
||||
RegisteredResource::RegisteredResource(int i, const unsigned char* resourceStruct, const unsigned char* resourceName, const unsigned char* resourceData) :
|
||||
i( i ), resourceStruct( resourceStruct ), resourceName( resourceName ), resourceData( resourceData ) { }
|
||||
|
||||
int QApplication::exec() {
|
||||
// init debugger
|
||||
QtDebugger debugger;
|
||||
|
||||
// get real exec call
|
||||
static int (*real_exec)() = (int (*)())dlsym(RTLD_NEXT, "_ZN12QApplication4execEv");
|
||||
static int (*real_exec)() = (int (*)()) dlsym(RTLD_NEXT, "_ZN12QApplication4execEv");
|
||||
if ( !real_exec ) {
|
||||
// failed to init real exec
|
||||
return -1;
|
||||
|
@ -30,3 +32,40 @@ int QApplication::exec() {
|
|||
return returnVal;
|
||||
}
|
||||
|
||||
bool qRegisterResourceData(int i, const unsigned char* resourceStruct, const unsigned char* resourceName, const unsigned char* resourceData) {
|
||||
static registerFunc real_register = (registerFunc) dlsym(RTLD_NEXT, "_Z21qRegisterResourceDataiPKhS0_S0_");
|
||||
|
||||
printf("registerResourceData: %i struct: %p name: %p data: %p\n", i, resourceStruct, resourceName, resourceData);
|
||||
|
||||
bool res = real_register(i, resourceStruct, resourceName, resourceData);
|
||||
|
||||
if ( res ) {
|
||||
if ( !registeredResources ) {
|
||||
registeredResources = new std::map<uint64_t, std::shared_ptr<RegisteredResource>>();
|
||||
}
|
||||
(*registeredResources)[(uint64_t) resourceStruct] = std::make_shared<RegisteredResource>(i, resourceStruct, resourceName, resourceData);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
bool qUnregisterResourceData(int i, const unsigned char* resourceStruct, const unsigned char* resourceName, const unsigned char* resourceData) {
|
||||
static registerFunc real_unregister = (registerFunc) dlsym(RTLD_NEXT, "_Z23qUnregisterResourceDataiPKhS0_S0_");
|
||||
|
||||
printf("unregisterResourceData: %i struct: %p name: %p data: %p\n", i, resourceStruct, resourceName, resourceData);
|
||||
|
||||
bool res = real_unregister(i, resourceStruct, resourceName, resourceData);
|
||||
|
||||
if ( res && registeredResources ) {
|
||||
auto it = registeredResources->find( (uint64_t) resourceStruct );
|
||||
if ( it != registeredResources->end() ) {
|
||||
registeredResources->erase( it );
|
||||
if ( registeredResources->empty() ) {
|
||||
delete registeredResources;
|
||||
registeredResources = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue