-
Notifications
You must be signed in to change notification settings - Fork 12
/
tenda_hooks.c
113 lines (93 loc) · 1.97 KB
/
tenda_hooks.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* tenda_hooks.c
*
* Fakes some functions from libcfm.so
* for the Tenda AC15/ACx line of routers otherwise the
* webserver doesn't start
*
* by Saumil Shah
* @therealsaumil
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <dlfcn.h>
#include <sys/types.h>
#include <sys/stat.h>
int nvram_set(char *uParm1, char *pcParm2); // set
char *nvram_get(char *uParm1); // get
int nvram_unset(char *uParm1); // unset
//static int (*real_get_flash_type)() = NULL;
// function declarations
extern int print_caller_and_address();
/*
// hook GetCfmValue()
int GetCfmValue(char *name, char *value)
{
int r;
print_caller_and_address();
if(!real_GetCfmValue)
real_GetCfmValue = dlsym(RTLD_NEXT, "GetCfmValue");
r = real_GetCfmValue(name, value);
printf("GetCfmValue('%s' -> %s) =%d\n", name, value, r);
return(r);
}
*/
// Hook just to inspect what get_flash_type() returns
/*
int get_flash_type()
{
int r;
if(!real_get_flash_type) {
real_get_flash_type = dlsym(RTLD_NEXT, "get_flash_type");
}
r = real_get_flash_type();
#ifdef VERBOSE
print_caller_and_address();
printf("get_flash_type() = %d\n", r);
#endif
return(r);
}
*/
// bcm_nvram_get --> nvram_get
char *bcm_nvram_get(char *k)
{
char *v = "";
#ifdef VERBOSE
print_caller_and_address();
#endif
v = nvram_get(k);
if(v == 0)
v = "";
#ifdef VERBOSE
printf("bcm_nvram_get('%s') = '%s'\n", k, v);
#endif
return(v);
}
// bcm_nvram_set --> nvram_set
int bcm_nvram_set(char *k, char *v)
{
int i;
#ifdef VERBOSE
print_caller_and_address();
#endif
i = nvram_set(k, v);
#ifdef VERBOSE
printf("[nvram %d] bcm_nvram_set('%s', '%s')\n", i, k, v);
#endif
return(0);
}
// bcm_nvram_unset --> nvram_unset
int bcm_nvram_unset(char *k)
{
int i;
#ifdef VERBOSE
print_caller_and_address();
#endif
i = nvram_unset(k);
#ifdef VERBOSE
printf("[nvram %d] bcm_nvram_unset('%s')\n", i, k);
#endif
return(i);
}