Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5936 | pavelyakov | 1 | /* |
2 | 2015 |
||
3 | Author: Pavel Yakovlev. |
||
4 | */ |
||
5 | |||
6 | #define LIB_NAME "library" |
||
7 | #define NO_LIBIMPORT_FUNC |
||
8 | |||
9 | #include "coff.h" |
||
10 | |||
11 | #include |
||
12 | #include |
||
13 | |||
14 | struct_import *array_list_func; |
||
15 | dword ADR_FUNC_LIST=0; |
||
16 | dword ADR_LIB_LIST=0; |
||
17 | |||
18 | dword init_list_function_adr(); |
||
19 | |||
20 | typedef struct |
||
21 | { |
||
22 | dword key; |
||
23 | dword value; |
||
24 | } array; |
||
25 | |||
26 | void strtolower(char *text) |
||
27 | { |
||
28 | --text; |
||
29 | while(*++text)if((*text>='A')&&(*text<='Z'))*text+='a'-'A'; |
||
30 | } |
||
31 | |||
32 | static array*(* _stdcall array_set_key_string)(array *ary,char *key,void *data); |
||
33 | static void*(* _stdcall array_get_key_string)(array *ary,char *key); |
||
34 | |||
35 | static char*(* _stdcall get_full_path)(char *path); |
||
36 | byte init_check_fs = 0; |
||
37 | byte init_fs() |
||
38 | { |
||
39 | if(init_check_fs)return 1; |
||
40 | char *name = "/sys/lib/fs.obj"; |
||
41 | array_list_func = cofflib_load(name); |
||
42 | if (!array_list_func) exit(); |
||
43 | |||
44 | get_full_path = (void *)cofflib_procload (array_list_func, "fs.get_full_path"); |
||
45 | if (!get_full_path) exit(); |
||
46 | |||
47 | init_check_fs = 1; |
||
48 | |||
49 | array_set_key_string(&ADR_LIB_LIST,name,array_list_func); |
||
50 | return init_list_function_adr(); |
||
51 | } |
||
52 | |||
53 | byte init_check_array = 0; |
||
54 | byte init_array() |
||
55 | { |
||
56 | if(init_check_array)return 1; |
||
57 | |||
58 | char *name = "/sys/lib/array.obj"; |
||
59 | array_list_func = cofflib_load(name); |
||
60 | if (!array_list_func) exit(); |
||
61 | |||
62 | array_set_key_string = (void *)cofflib_procload (array_list_func, "array.key_string_set"); |
||
63 | if (!array_set_key_string) exit(); |
||
64 | |||
65 | array_get_key_string = (void *)cofflib_procload (array_list_func, "array.key_string_get"); |
||
66 | if (!array_get_key_string) exit(); |
||
67 | |||
68 | init_check_array = 1; |
||
69 | |||
70 | array_set_key_string(&ADR_LIB_LIST,name,array_list_func); |
||
71 | init_list_function_adr(); |
||
72 | return init_fs(); |
||
73 | } |
||
74 | |||
75 | int load_dll2(dword dllname,struct_import* import_table, byte need_init) |
||
76 | { |
||
77 | struct_import* import_table1 = cofflib_load(dllname); |
||
78 | if(import_table1)return -1; |
||
79 | |||
80 | dword i=0,ii=0; |
||
81 | dword name = import_table1[i].name; |
||
82 | dword name1 = import_table[ii].name; |
||
83 | while(name) |
||
84 | { |
||
85 | if(!strcmp(name,name1)) |
||
86 | { |
||
87 | import_table[ii].data=import_table1[i].data; |
||
88 | name1 = import_table[++ii].name; |
||
89 | } |
||
90 | name = import_table1[++i].name; |
||
91 | } |
||
92 | if(need_init) dll_init(import_table1[0].data); |
||
93 | return 0; |
||
94 | } |
||
95 | |||
96 | static void (* lib_init_eval)(dword,dword,dword,dword); |
||
97 | |||
98 | void dll_init(dword data) |
||
99 | { |
||
100 | lib_init_eval = data; |
||
101 | lib_init_eval(&malloc,&free,&realloc,&load_dll2); |
||
102 | } |
||
103 | |||
104 | byte first_load = 0; |
||
105 | |||
106 | dword load(char *name) |
||
107 | { |
||
108 | init_array(); |
||
109 | name = get_full_path(name); |
||
110 | strtolower(name); |
||
111 | if(array_get_key_string(&ADR_LIB_LIST,name))return 1; |
||
112 | array_list_func = cofflib_load(name); |
||
113 | if(!array_list_func) return 0; |
||
114 | array_set_key_string(&ADR_LIB_LIST,name,array_list_func); |
||
115 | return init_list_function_adr(); |
||
116 | } |
||
117 | |||
118 | dword get(char *name) |
||
119 | { |
||
120 | return (dword)array_get_key_string(&ADR_FUNC_LIST,name); |
||
121 | } |
||
122 | |||
123 | static void (* _stdcall eval_set_pointer)(dword,dword); |
||
124 | |||
125 | dword init_list_function_adr() |
||
126 | { |
||
127 | dword i=0,data; |
||
128 | char *name = 0; |
||
129 | LOOP: |
||
130 | name = array_list_func[i].name; |
||
131 | if(!name) return 1; |
||
132 | data = array_list_func[i++].data; |
||
133 | if(!strcmp("lib_init",name)) |
||
134 | { |
||
135 | dll_init(data); |
||
136 | goto LOOP; |
||
137 | } |
||
138 | if(!strcmp("lib_pointer_library",name)) |
||
139 | { |
||
140 | eval_set_pointer = data; |
||
141 | eval_set_pointer(&load,&get); |
||
142 | goto LOOP; |
||
143 | } |
||
144 | array_set_key_string(&ADR_FUNC_LIST,name,data); |
||
145 | goto LOOP; |
||
146 | } |
||
147 | |||
148 | EXPORT_ |
||
149 | export(load) |
||
150 | export(get) |
||
151 | _EXPORT='Z'))*text+='a'-'A'; |