Skip to content

Commit

Permalink
Read Xposed version from xposed.prop instead of constant
Browse files Browse the repository at this point in the history
The Xposed framework consists of several parts: app_process, XposedBridge.jar
and the modified ART runtime. Let's use a single version number for the whole
package, defined in /system/xposed.prop, instead of having different version
numbers for the individual parts. It's not supported to mix parts from
different packages anyway.
  • Loading branch information
rovo89 committed Jun 20, 2015
1 parent ca2ddf3 commit bccac73
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void app_usage()
{
fprintf(stderr,
"Usage: app_process [java-options] cmd-dir start-class-name [options]\n");
fprintf(stderr, " with Xposed support (version " XPOSED_VERSION ")\n");
fprintf(stderr, " with Xposed support\n");
}

void _atrace_set_tracing_enabled(bool enabled)
Expand Down
2 changes: 1 addition & 1 deletion app_main2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void app_usage()
{
fprintf(stderr,
"Usage: app_process [java-options] cmd-dir start-class-name [options]\n");
fprintf(stderr, " with Xposed support (version " XPOSED_VERSION ")\n");
fprintf(stderr, " with Xposed support\n");
}

class AppRuntime : public AndroidRuntime
Expand Down
65 changes: 61 additions & 4 deletions xposed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
#include "xposed_safemode.h"
#include "xposed_service.h"

#include <stdlib.h>
#include <ctype.h>
#include <cutils/process_name.h>
#include <cutils/properties.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>

#if PLATFORM_SDK_VERSION >= 18
#include <sys/capability.h>
Expand All @@ -33,15 +34,19 @@ static int sdkVersion = -1;
static char* argBlockStart;
static size_t argBlockLength;

const char* xposedVersion = "unknown (invalid " XPOSED_PROP_FILE ")";
uint32_t xposedVersionInt = 0;

////////////////////////////////////////////////////////////
// Functions
////////////////////////////////////////////////////////////

/** Handle special command line options. */
bool handleOptions(int argc, char* const argv[]) {
parseXposedProp();

if (argc == 2 && strcmp(argv[1], "--xposedversion") == 0) {
printf("Xposed version: " XPOSED_VERSION "\n");
printf("Xposed version: %s\n", xposedVersion);
return true;
}

Expand Down Expand Up @@ -140,7 +145,7 @@ void printRomInfo() {
property_get("ro.product.cpu.abi", platform, "n/a");

ALOGI("-----------------");
ALOGI("Starting Xposed binary version %s, compiled for SDK %d", XPOSED_VERSION, PLATFORM_SDK_VERSION);
ALOGI("Starting Xposed version %s, compiled for SDK %d", xposedVersion, PLATFORM_SDK_VERSION);
ALOGI("Device: %s (%s), Android version %s (SDK %s)", model, manufacturer, release, sdk);
ALOGI("ROM: %s", rom);
ALOGI("Build fingerprint: %s", fingerprint);
Expand All @@ -153,6 +158,58 @@ void printRomInfo() {
xposed->isSELinuxEnforcing ? "yes" : "no");
}

/** Parses /system/xposed.prop and stores selected values in variables */
void parseXposedProp() {
FILE *fp = fopen(XPOSED_PROP_FILE, "r");
if (fp == NULL) {
ALOGE("Could not read %s: %s", XPOSED_PROP_FILE, strerror(errno));
return;
}

char buf[512];
while (fgets(buf, sizeof(buf), fp) != NULL) {
char* key = buf;
// Ignore leading spaces for the key
while (isspace(*key)) key++;

// Skip comments
if (*key == '#')
continue;

// Find the key/value separator
char* value = strchr(buf, '=');
if (value == NULL)
continue;

// Ignore trailing spaces for the key
char* tmp = value;
do { *tmp = 0; tmp--; } while (isspace(*tmp));

// Ignore leading spaces for the value
do { value++; } while (isspace(*value));

// Remove trailing newline
tmp = strpbrk(value, "\n\r");
if (tmp != NULL)
*tmp = 0;

// Handle this entry
if (!strcmp("version", key)) {
int len = strlen(value);
if (len == 0)
continue;
tmp = (char*) malloc(len + 1);
strlcpy(tmp, value, len + 1);
xposedVersion = tmp;
xposedVersionInt = atoi(xposedVersion);
}
}
fclose(fp);

return;
}

/** Returns the SDK version of the system */
int getSdkVersion() {
if (sdkVersion < 0) {
char sdkString[PROPERTY_VALUE_MAX];
Expand Down
3 changes: 3 additions & 0 deletions xposed.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "xposed_shared.h"

#define XPOSED_PROP_FILE "/system/xposed.prop"

#if defined(__LP64__)
#define XPOSED_LIB_DIR "/system/lib64/"
#else
Expand Down Expand Up @@ -30,6 +32,7 @@ namespace xposed {
bool handleOptions(int argc, char* const argv[]);
bool initialize(bool zygote, bool startSystemServer, const char* className, int argc, char* const argv[]);
void printRomInfo();
void parseXposedProp();
int getSdkVersion();
bool isDisabled();
void disableXposed();
Expand Down
1 change: 0 additions & 1 deletion xposed_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#define ALOGV LOGV
#endif

#define XPOSED_VERSION "61"
#define XPOSED_DIR "/data/data/de.robv.android.xposed.installer/"

namespace xposed {
Expand Down

0 comments on commit bccac73

Please sign in to comment.