yeah, the trick does work, i tried out on some sample codes.. At first I tried to do something like this.. (the code for the library is below, compiled using:
g++ -Wall -shared -fPIC -o libdynamic.so dynamic.cpp
and the main is compiled using:
g++ main.cpp -o go -L. -ldynamic -ldl
Code:
for void dynamic::dynamicClass::method01()
#include <dlfcn.h>
handle = dlopen("/usr/local/lib/libdynamic.so",RTLD_LAZY);
void (* functionpointer_method01)(void*);
functionpointer_method01 = (void (*)()) dlsym(handle, "_ZN7dynamic12dynamicClass8method01Ev");
which works but the object wasn't created, so this might be good for static methods only. Also i had to insert an extra argument for my function pointers and I have no idea why.
e.g
Code:
void method02(int a)
becomes
Code:
void method02(int X,int a);
and i dont know what X is for. Passing 0 to it causes segmentation fault and passing an address to it does not change the address' value. Any idea on why this happens, I'll be happy to hear.
this approach seems to work, but as you mentioned it, will need some labor:
Code:
/* 23 October 2014: The Lost Header Exploit */
/*
~/projects/dynamictest$ objdump -T /usr/local/lib/libdynamic.so
/usr/local/lib/libdynamic.so: file format elf32-i386
DYNAMIC SYMBOL TABLE:
00000000 DF *UND* 00000000 GLIBCXX_3.4 _ZNSolsEi
00000000 DF *UND* 00000000 GLIBC_2.1.3 __cxa_atexit
00000000 w D *UND* 00000000 __gmon_start__
00000000 w D *UND* 00000000 _Jv_RegisterClasses
00000000 DF *UND* 00000000 GLIBCXX_3.4 _ZNSt8ios_base4InitC1Ev
00000000 DF *UND* 00000000 GLIBCXX_3.4 _ZNSt8ios_base4InitD1Ev
00000000 w D *UND* 00000000 _ITM_deregisterTMCloneTable
00000000 DF *UND* 00000000 GLIBCXX_3.4 _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc
00000000 w D *UND* 00000000 _ITM_registerTMCloneTable
00000000 DO *UND* 00000000 GLIBCXX_3.4 _ZSt4cout
00000000 DF *UND* 00000000 GLIBCXX_3.4 _ZNSolsEPFRSoS_E
00000000 DF *UND* 00000000 GLIBCXX_3.4 _ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
00000000 w DF *UND* 00000000 GLIBC_2.1.3 __cxa_finalize
00000962 g DF .text 00000047 Base _ZN7dynamic12dynamicClass8method02Ev
0000090c g DF .text 0000000d Base _ZN7dynamic12dynamicClassC2Ei
0000090c g DF .text 0000000d Base _ZN7dynamic12dynamicClassC1Ei
00002030 g D .bss 00000000 Base _end
0000202c g D .data 00000000 Base _edata
00000920 g DF .text 00000042 Base _ZN7dynamic12dynamicClass8method01Ev
0000091a g DF .text 00000005 Base _ZN7dynamic12dynamicClassD1Ev
0000202c g D .bss 00000000 Baseg++ main2.cpp -o go -L. -ldynamic -ldl __bss_start
0000091a g DF .text 00000005 Base _ZN7dynamic12dynamicClassD2Ev
00000a76 g DF .text 00000089 Base _ZN7dynamic12dynamicClass8method05Eii
00000734 g DF .init 00000000 Base _init
00000b74 g DF .fini 00000000 Base _fini
00000a0e g DF .text 00000068 Base _ZN7dynamic12dynamicClass8method04Ei
000009aa g DF .text 00000063 Base _ZN7dynamic12dynamicClass8method03Ei
*/
// rearranging base based on address and demangling, i get:
// -----------------------------------------
// dynamic::dynamicClass::dynamicClass(int)
// dynamic::dynamicClass::~dynamicClass()
// dynamic::dynamicClass::~dynamicClass()
// dynamic::dynamicClass::method01()
// dynamic::dynamicClass::method02()
// dynamic::dynamicClass::method03(int)
// dynamic::dynamicClass::method04(int)
// dynamic::dynamicClass::method05(int, int)
// -----------------------------------------
/* note: why dont i get the return value? */
#include <iostream>
namespace dynamic
{
class dynamicClass
{
public:
dynamicClass(int);
~dynamicClass();
void method01();
void method02();
void method03(int);
void method04(int);
void method05(int,int);
};
}
using namespace std;
int main ()
{
dynamic::dynamicClass oDynamicClass(1);
oDynamicClass.method01();
oDynamicClass.method02();
oDynamicClass.method03(1);
oDynamicClass.method04(1);
oDynamicClass.method05(1,2);
return (0);
}
/* outputs:
method01
method02
method03(1)
method04(1)
method05(1,2)
*/
I think being able to call libNickel subroutines would be a great help in Kobo development, not just for KoReader.
Complete source:
https://www.dropbox.com/s/1idg3q2gql...er.tar.gz?dl=0