Skip to content

Commit

Permalink
Move dynamic loading to separate c file for modular design
Browse files Browse the repository at this point in the history
  • Loading branch information
harlequin committed Jun 6, 2016
1 parent b565360 commit f306939
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 60 deletions.
2 changes: 1 addition & 1 deletion dvbapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

#include "hook.h"
#include "common.h"
#include "C_support.h"
//#include "C_support.h"
#include "tv_info.h"
#include "utlist.h"
#include "types.h"
Expand Down
63 changes: 63 additions & 0 deletions hook.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "hook.h"
#include "log.h"
#include <dlfcn.h>
#include <string.h>

#define cacheflush(from, size) __clear_cache((void*)from, (void*)((unsigned long)from+size))
Expand All @@ -7,6 +9,67 @@
#define LUI_T9_0 0x3C190000
#define ORI_T9_0 0x37390000

typedef union
{
const void *procs[100];
const char *names[100];
} samyGO_CTX_t;


int dyn_sym_tab_init(void *h, dyn_fn_t *fn_tab, uint32_t cnt) {
void *sdal=dlopen("libSDAL.so",RTLD_LAZY);
for(int i = 0; i < cnt; i++) {
void *fn=0;
if(sdal)
fn = dlsym(sdal, fn_tab[i].name);
if(!fn)
fn = dlsym(h, fn_tab[i].name);
if(!fn)
{
log("dlsym '%s' failed.\n", fn_tab[i].name);
continue;
//return -1;
}

log("%s [%p].\n", fn_tab[i].name, fn);

fn_tab[i].fn = fn;
}
return 0;
}



int samyGO_whacky_t_init(void *h, void *paramCTX, uint32_t cnt) {
samyGO_CTX_t *ctx;
ctx=paramCTX;
void *fn;
void *sdal=dlopen("libSDAL.so",RTLD_LAZY);
for(int i = 0; i < cnt ; i++) {
if(!ctx->procs[i])
continue;
fn=0;
if(sdal)
fn = dlsym(sdal, ctx->procs[i]);
if(!fn)
fn = dlsym(h, ctx->procs[i]);

if(!fn && !(fn=C_find(h,ctx->procs[i]))) {
log("dlsym '%s' failed.\n", ctx->procs[i]);
} else {
log("%s [%p].\n", ctx->procs[i], fn);
}
ctx->procs[i] = fn;
}
return 0;
}







void hijack_start(
sym_hook_t *sa, void *target, void *_new)
{
Expand Down
13 changes: 13 additions & 0 deletions hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


#include "common.h"
#include "C_support.h"


//#define HIJACK_SIZE 12
Expand All @@ -16,8 +17,16 @@ typedef struct
} sym_hook_t;




EXTERN_C_BEGIN

typedef struct
{
void *fn;
const char *name;
} dyn_fn_t;

void hijack_start(
sym_hook_t *sa, void *target, void *_new);

Expand All @@ -30,6 +39,10 @@ void hijack_resume(
void hijack_stop(
sym_hook_t *sa);


EXTERN_C_END

int dyn_sym_tab_init(void *h, dyn_fn_t *fn_tab, uint32_t cnt);
int samyGO_whacky_t_init(void *h, void *paramCTX, uint32_t cnt);

#endif //__HOOK_H__
14 changes: 14 additions & 0 deletions types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
#define NULL (void *)0
#endif

#define STATIC static

#define _FILE_OFFSET_BITS 64

#ifndef _LARGEFILE64_H
#define _LARGEFILE64_H
#endif

#ifndef _LARGEFILE64_SOURCE
#define _LARGEFILE64_SOURCE 1
#endif


typedef unsigned char u8;
Expand Down Expand Up @@ -135,3 +146,6 @@ typedef struct ca_descr_mode {
enum ca_descr_algo algo;
enum ca_descr_cipher_mode cipher_mode;
} ca_descr_mode_t;



83 changes: 24 additions & 59 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,38 +88,34 @@ char* getOptArg(char **argv, int argc, char *option)

#define cacheflush(from, size) __clear_cache((void*)from, (void*)((unsigned long)from+size))

typedef struct
{
void *fn;
const char *name;
} dyn_fn_t;



STATIC int dyn_sym_tab_init(
void *h, dyn_fn_t *fn_tab, uint32_t cnt)
{
void *sdal=dlopen("libSDAL.so",RTLD_LAZY);
for(int i = 0; i < cnt; i++)
{
void *fn=0;
if(sdal)
fn = dlsym(sdal, fn_tab[i].name);
if(!fn)
fn = dlsym(h, fn_tab[i].name);
if(!fn)
{
log("dlsym '%s' failed.\n", fn_tab[i].name);
continue;
//return -1;
}

log("%s [%p].\n", fn_tab[i].name, fn);

fn_tab[i].fn = fn;
}
return 0;
}
//STATIC int dyn_sym_tab_init(
// void *h, dyn_fn_t *fn_tab, uint32_t cnt)
//{
// void *sdal=dlopen("libSDAL.so",RTLD_LAZY);
// for(int i = 0; i < cnt; i++)
// {
// void *fn=0;
// if(sdal)
// fn = dlsym(sdal, fn_tab[i].name);
// if(!fn)
// fn = dlsym(h, fn_tab[i].name);
// if(!fn)
// {
// log("dlsym '%s' failed.\n", fn_tab[i].name);
// continue;
// //return -1;
// }
//
// log("%s [%p].\n", fn_tab[i].name, fn);
//
// fn_tab[i].fn = fn;
// }
// return 0;
//}

void log_buf(char *name, unsigned char *buf)
{
Expand Down Expand Up @@ -166,38 +162,7 @@ STATIC int remove_hooks(
}
}

typedef union
{
const void *procs[100];
const char *names[100];
} samyGO_CTX_t;

//STATIC int samyGO_whacky_t_init(void *h, samyGO_whacky_t *ctx, uint32_t cnt)
STATIC int samyGO_whacky_t_init(void *h, void *paramCTX, uint32_t cnt)
{
samyGO_CTX_t *ctx;
ctx=paramCTX;
void *fn;
void *sdal=dlopen("libSDAL.so",RTLD_LAZY);
for(int i = 0; i < cnt ; i++)
{
if(!ctx->procs[i])
continue;
fn=0;
if(sdal)
fn = dlsym(sdal, ctx->procs[i]);
if(!fn)
fn = dlsym(h, ctx->procs[i]);

if(!fn && !(fn=C_find(h,ctx->procs[i]))) {
log("dlsym '%s' failed.\n", ctx->procs[i]);
} else {
log("%s [%p].\n", ctx->procs[i], fn);
}
ctx->procs[i] = fn;
}
return 0;
}
#include <errno.h>

void *sgo_shmem_open(
Expand Down

0 comments on commit f306939

Please sign in to comment.