-
Notifications
You must be signed in to change notification settings - Fork 0
/
asardll.c
73 lines (69 loc) · 1.68 KB
/
asardll.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
#define NULL 0
#ifdef _WIN32
#include <windows.h>
#define getlib() LoadLibraryA("asar.dll")
#define loadraw(name, target) *((int(**)())&target)=(int(*)())GetProcAddress((HINSTANCE)asardll, name); require(target)
#define closelib(var) FreeLibrary((HINSTANCE)var)
#else
#include <dlfcn.h>
#include <stdio.h>
#ifdef __APPLE__
#define EXTENSION ".dylib"
#else
#define EXTENSION ".so"
#endif
inline void * getlib()
{
char libname[256];
const char * names[]={"./libasar"EXTENSION, "libasar", NULL};
for (int i=0;names[i];i++)
{
void * rval=dlopen(names[i], RTLD_LAZY);
const char*e=dlerror();if(e)puts(e);
if (rval) return rval;
}
return NULL;
}
#define loadraw(name, target) *(void **)(&target)=dlsym(asardll, name); require(target)
#define closelib(var) dlclose(var)
#endif
#define asarfunc
#include "asardll.h"
static void * asardll=NULL;
static bool (*asar_i_init)();
static void (*asar_i_close)();
bool asar_init()
{
#define require(b) if (!(b)) { asardll=NULL; return false; }
if (asardll) return true;
asardll=getlib();
require(asardll);
//void * tmp;
#define loadi(name) loadraw("asar_"#name, asar_i_##name)
#define load(name) loadraw("asar_"#name, asar_##name)
loadi(init);
loadi(close);
load(version);
load(apiversion);
load(reset);
load(patch);
load(maxromsize);
load(geterrors);
load(getwarnings);
load(getprints);
load(getalllabels);
load(getlabelval);
load(getdefine);
load(getalldefines);
load(math);
if (asar_apiversion()<expectedapiversion || (asar_apiversion()/100)>(expectedapiversion/100)) return false;
require(asar_i_init());
return true;
}
void asar_close()
{
if (!asardll) return;
asar_i_close();
closelib(asardll);
asardll=NULL;
}