forked from thp/apkenv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapkenv.h
263 lines (216 loc) · 8.45 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#ifndef APKENV_H
#define APKENV_H
/**
* apkenv
* Copyright (c) 2012, Thomas Perl <[email protected]>
* 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"
#include "imagelib/imagelib.h"
#define APKENV_NAME "apkenv"
#define APKENV_VERSION "42.24.7"
#define APKENV_WEBSITE "http://thp.io/2012/apkenv/"
#define APKENV_HEADLINE APKENV_NAME " " APKENV_VERSION " - " APKENV_WEBSITE
#define APKENV_COPYRIGHT "Copyright (c) 2012, 2013, 2014, 2015, 2016 Thomas Perl <[email protected]>"
/* these are used to determine if the screen content has to be rotated for the current platform */
#define ORIENTATION_LANDSCAPE 0
#define ORIENTATION_PORTRAIT 1
struct GlobalState;
struct SupportModule;
struct SupportModulePriv;
struct ConfigOption {
char *key;
char *value;
};
struct ModuleHacks {
int current_orientation;
int gles_downscale_images;
int gles_no_readpixels;
int gles_viewport_hack;
int gles_scale;
int glOrthof_rotation_hack;
int glDrawArrays_rotation_hack;
};
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 (*key_input)(struct SupportModule *self, int event, int keycode, int unicode);
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 *(*read_file_to_jni_array_t)(const char *filename);
typedef void (*recursive_mkdir_t)(const char *path);
typedef const char *(*lookup_resource_t)(const char *key);
typedef void (*patch_symbol_t)(const char *symbol, void *function);
struct JniLibrary {
struct JniLibrary *next;
char *name;
void *lib;
char **method_table;
};
enum PlatformPath {
/* Path to where .apk files should be installed, or NULL if unsupported */
PLATFORM_PATH_INSTALL_DIRECTORY = 1,
/* Path to where application data should be stored */
PLATFORM_PATH_DATA_DIRECTORY = 2,
/* Path from where support modules should be loaded */
PLATFORM_PATH_MODULE_DIRECTORY = 3,
};
/**
* Callback for a request_text_input request
* text ........ User-entered text, or NULL if the user canceled text input
* user_data ... The pointer passed to request_text_input() for the request
**/
typedef void (*text_callback_t)(const char *text, void *user_data);
struct PlatformSupport {
/* Initialize the video mode, return nonzero on success, zero on error */
int (*init)(int gles_version);
/* Get a device path (see enum PlatformPath), don't free() the result */
const char *(*get_path)(enum PlatformPath which);
/* Get the size of the device screen */
void (*get_size)(int *width, int *height);
/* Process input events and forward to "module", return nonzero to exit */
int (*input_update)(struct SupportModule *module);
/* this returns the platforms default orientation for rotating the app content properly */
int (*get_orientation)(void);
/**
* Asynchronously request text input from the native platform
* is_password ... If non-zero, text input will be hidden while typing
* text .......... Text to pre-fill into the entry (or NULL for none)
* callback ...... Callback for the result
* user_data ..... Pointer that will be passed to callback
* This function returns right away, when the text input is completed,
* callback will be called with user_data (see text_callback_t for details).
**/
void (*request_text_input)(int is_password, const char *text,
text_callback_t callback, void *user_data);
/* Called once per rendering frame to swap buffers, etc... */
void (*update)();
/* Called when apkenv shuts down (for platform-specific cleanups) */
void (*exit)();
};
struct trace_list {
char *name;
struct trace_list *next;
};
struct GlobalState {
const char *apkenv_executable;
const char *apkenv_headline;
const char *apkenv_copyright;
struct PlatformSupport *platform;
struct JNINativeInterface fake_env;
JNIEnv env;
struct JNIInvokeInterface fake_vm;
JavaVM vm;
// dalvikvm
struct _JavaVM *_vm;
struct _JNIEnv *_env;
struct JNINativeInterface dalvik_copy_env;
struct ConfigOption *config;
int config_count;
int config_size;
const char *apk_filename;
AndroidApk *apklib_handle;
const void *apk_in_mem; /* can be NULL if APK is too large */
size_t apk_size;
int apk_fd;
struct JniLibrary *libraries;
struct SupportModule *support_modules;
struct SupportModule *active_module;
struct ModuleHacks *module_hacks;
struct ResourceStrings resource_strings;
/* tracing/debugging */
int trace_latehooked;
int trace_unhooked;
int trace_dynhooked;
int trace_arm_injection;
int trace_thumb_injection;
struct trace_list *functions_to_trace;
int trace_all;
int use_dvm;
char *android_path;
int loader_seen_glesv1;
int loader_seen_glesv2;
lookup_symbol_t lookup_symbol;
lookup_lib_symbol_t lookup_lib_symbol;
foreach_file_t foreach_file;
read_file_t read_file;
read_file_to_jni_array_t read_file_to_jni_array;
recursive_mkdir_t recursive_mkdir;
lookup_resource_t lookup_resource;
image_loader_t image_loader;
int use_gles_serialize;
};
#define VM(global_ptr) ((global_ptr)->_vm ? (JavaVM*)((global_ptr)->_vm) : &((global_ptr->vm)))
#define ENV(global_ptr) ((global_ptr)->_env ? (JNIEnv*)((global_ptr)->_env) : &((global_ptr->env)))
/* Android MotionEvent/KeyEvent */
#define ACTION_DOWN 0
#define ACTION_UP 1
#define ACTION_MOVE 2
#define ACTION_MULTIPLE 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
/* multitouch support definitions */
#if defined(FREMANTLE) || defined(PANDORA)
# define HAVE_MULTITOUCH 0
#else
# define HAVE_MULTITOUCH 1
#endif
/* Forward-declarations for the Bionic linker */
void *apkenv_android_dlopen(const char *filename, int flag);
void *apkenv_android_dlsym(void *handle, const char *symbol);
/* apkenv configuration helper */
char *get_config(char *name);
int get_config_int(char *name, int fallback);
/* 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 0x010002
#endif /* APKENV_H */