/
apkenv.h
134 lines (110 loc) · 4.29 KB
/
apkenv.h
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef APKENV_H
#define APKENV_H
/**
* apkenv
* Copyright (c) 2012, Thomas Perl <m@thp.io>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/
#include "apklib/apklib.h"
#include "jni/jni.h"
#define APKENV_NAME "apkenv"
#define APKENV_VERSION "42.3.14"
#define APKENV_WEBSITE "http://thp.io/2012/apkenv/"
#define APKENV_HEADLINE APKENV_NAME " " APKENV_VERSION " - " APKENV_WEBSITE
#define APKENV_COPYRIGHT "Copyright (c) 2012 Thomas Perl <m@thp.io>"
struct GlobalState;
struct SupportModulePriv;
struct SupportModule {
struct GlobalState *global;
struct SupportModulePriv *priv;
char *filename;
int priority;
struct JNINativeInterface override_env;
struct JNIInvokeInterface override_vm;
int (*try_init)(struct SupportModule *self);
void (*init)(struct SupportModule *self, int width, int height, const char *home);
void (*input)(struct SupportModule *self, int event, int x, int y, int finger);
void (*update)(struct SupportModule *self);
void (*deinit)(struct SupportModule *self);
void (*pause)(struct SupportModule *self);
void (*resume)(struct SupportModule *self);
int (*requests_exit)(struct SupportModule *self);
struct SupportModule *next;
};
typedef void *(*lookup_symbol_t)(const char *method);
typedef void *(*lookup_lib_symbol_t)(const char *lib, const char *method);
typedef void (*foreach_file_t)(const char *prefix, apk_for_each_file_callback callback);
typedef int (*read_file_t)(const char *filename, char **buffer, size_t *size);
typedef void (*recursive_mkdir_t)(const char* path);
struct JniLibrary {
struct JniLibrary *next;
char *name;
void *lib;
char **method_table;
};
struct GlobalState {
const char *apkenv_executable;
const char *apkenv_headline;
const char *apkenv_copyright;
struct JNINativeInterface fake_env;
JNIEnv env;
struct JNIInvokeInterface fake_vm;
JavaVM vm;
const char *apk_filename;
AndroidApk *apklib_handle;
struct JniLibrary *libraries;
struct SupportModule *support_modules;
struct SupportModule *active_module;
lookup_symbol_t lookup_symbol;
lookup_lib_symbol_t lookup_lib_symbol;
foreach_file_t foreach_file;
read_file_t read_file;
recursive_mkdir_t recursive_mkdir;
};
#define VM(global_ptr) (&((global_ptr)->vm))
#define ENV(global_ptr) (&((global_ptr)->env))
/* Android MotionEvent */
#define ACTION_DOWN 0
#define ACTION_UP 1
#define ACTION_MOVE 2
/**
* Attribute for softfp-calling-style functions
* (only on Harmattan - Fremantle *is* softfp)
**/
#if defined(FREMANTLE) || defined(PANDORA)
# define SOFTFP
#else
# define SOFTFP __attribute__((pcs("aapcs")))
#endif
/* Forward-declarations for the Bionic linker */
void *android_dlopen(const char *filename, int flag);
void *android_dlsym(void *handle, const char *symbol);
/* Module support */
typedef int (*apkenv_module_init_t)(int version, struct SupportModule *module);
#define APKENV_MODULE_INIT "apkenv_module_init"
#define APKENV_MODULE_SUFFIX ".apkenv.so"
#define APKENV_MODULE_VERSION 0x010000
#endif /* APKENV_H */