Loading remote-droid-guard-lib/src/main/java/org/microg/gms/droidguard/Constants.javadeleted 100644 → 0 +0 −23 Original line number Diff line number Diff line /* * Copyright (C) 2013-2017 microG Project Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.microg.gms.droidguard; public class Constants { public static final String GMS_PACKAGE_NAME = "com.google.android.gms"; public static final int GMS_VERSION_CODE = 10084430; public static final String GMS_VERSION_NAME_PREFIX = "10.0.84 (430-"; } remote-droid-guard/src/main/java/org/microg/gms/droidguard/DroidguardHelper.java +47 −5 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.os.Build; import android.os.Bundle; import android.util.Base64; import android.util.Log; import android.text.TextUtils; import com.squareup.wire.Wire; Loading Loading @@ -58,16 +59,19 @@ public class DroidguardHelper { private static Map<String, Class<?>> loadedClass = new HashMap<>(); public static byte[] guard(Context context, RemoteDroidGuardRequest request) throws Exception { int versionCode = context.getPackageManager().getPackageInfo("com.google.android.gms", 0).versionCode; SignedDGResponse signedResponse = request(new DGRequest.Builder() .usage(new DGUsage(request.reason, request.packageName)) .info(getSystemInfo(null)) .isGoogleCn(false) .enableInlineVm(true) .currentVersion(3) .versionNamePrefix(Constants.GMS_VERSION_NAME_PREFIX) .versionNamePrefix(gmsVersionNamePrefix(versionCode, Build.CPU_ABI)) .cached(getCached(context)) .arch(getArch()) .build()); .build(), versionCode); DGResponse response = new Wire().parseFrom(signedResponse.data.toByteArray(), DGResponse.class); String checksum = response.vmChecksum.hex(); File dgCacheDir = context.getDir("dg_cache", 0); Loading @@ -89,6 +93,39 @@ public class DroidguardHelper { return invoke(context, clazz, request.packageName, request.reason, response.byteCode.toByteArray(), request.androidIdLong, request.extras); } public static int gmsVersionCode(int versionCode, String arch) { versionCode -= versionCode % 1000; switch (arch) { case "arm64-v8a": return versionCode + 23; case "x86": return versionCode + 26; case "x86_64": return versionCode + 27; default: return versionCode + 19; } } public static String gmsVersionNamePrefix(int versionCode, String arch) { int minor, patch; versionCode /= 1000; patch = versionCode % 100; versionCode /= 100; minor = versionCode % 10; versionCode /= 10; String versionPrefix = versionCode + "." + minor + "." + patch; switch (arch) { case "arm64-v8a": return versionPrefix + " (040400-{{cl}})"; case "x86": case "x86_64": return versionPrefix + " (040700-{{cl}})"; default: return versionPrefix + " (040300-{{cl}})"; } } public static byte[] invoke(Context context, Class<?> clazz, String packageName, String type, byte[] byteCode, String androidIdLong, Bundle extras) throws InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException, NoSuchMethodException { Object instance = clazz .getDeclaredConstructor(Context.class, String.class, byte[].class, Object.class) Loading @@ -111,6 +148,7 @@ public class DroidguardHelper { createSystemInfoPair("BRAND", clazz, build), createSystemInfoPair("CPU_ABI", clazz, build), createSystemInfoPair("CPU_ABI2", clazz, build), createSystemInfoPair("SUPPORTED_ABIS", clazz, build), createSystemInfoPair("DEVICE", clazz, build), createSystemInfoPair("DISPLAY", clazz, build), createSystemInfoPair("FINGERPRINT", clazz, build), Loading Loading @@ -157,7 +195,11 @@ public class DroidguardHelper { } } String nuKey = tr[tr.length - 1]; return new KeyValuePair(nuKey, String.valueOf(nuClass.getField(nuKey).get(nuObj))); Object val = nuClass.getField(nuKey).get(nuObj); if (val instanceof String[]) return new KeyValuePair(nuKey, TextUtils.join(",", (String[]) val)); else return new KeyValuePair(nuKey, String.valueOf(val)); } catch (Exception e) { if (obj != null) { // fallback to real system info Loading Loading @@ -240,14 +282,14 @@ public class DroidguardHelper { } } private static SignedDGResponse request(DGRequest request) throws IOException { private static SignedDGResponse request(DGRequest request, int versionCode) throws IOException { HttpURLConnection connection = (HttpURLConnection) new URL(DG_URL).openConnection(); connection.setRequestMethod("POST"); connection.setDoInput(true); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "application/x-protobuf"); connection.setRequestProperty("Accept-Encoding", "gzip"); connection.setRequestProperty("User-Agent", "DroidGuard/" + Constants.GMS_VERSION_CODE); connection.setRequestProperty("User-Agent", "DroidGuard/" + gmsVersionCode(versionCode, Build.CPU_ABI)); Log.d(TAG, "-- Request --\n" + request); OutputStream os = connection.getOutputStream(); Loading Loading
remote-droid-guard-lib/src/main/java/org/microg/gms/droidguard/Constants.javadeleted 100644 → 0 +0 −23 Original line number Diff line number Diff line /* * Copyright (C) 2013-2017 microG Project Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.microg.gms.droidguard; public class Constants { public static final String GMS_PACKAGE_NAME = "com.google.android.gms"; public static final int GMS_VERSION_CODE = 10084430; public static final String GMS_VERSION_NAME_PREFIX = "10.0.84 (430-"; }
remote-droid-guard/src/main/java/org/microg/gms/droidguard/DroidguardHelper.java +47 −5 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.os.Build; import android.os.Bundle; import android.util.Base64; import android.util.Log; import android.text.TextUtils; import com.squareup.wire.Wire; Loading Loading @@ -58,16 +59,19 @@ public class DroidguardHelper { private static Map<String, Class<?>> loadedClass = new HashMap<>(); public static byte[] guard(Context context, RemoteDroidGuardRequest request) throws Exception { int versionCode = context.getPackageManager().getPackageInfo("com.google.android.gms", 0).versionCode; SignedDGResponse signedResponse = request(new DGRequest.Builder() .usage(new DGUsage(request.reason, request.packageName)) .info(getSystemInfo(null)) .isGoogleCn(false) .enableInlineVm(true) .currentVersion(3) .versionNamePrefix(Constants.GMS_VERSION_NAME_PREFIX) .versionNamePrefix(gmsVersionNamePrefix(versionCode, Build.CPU_ABI)) .cached(getCached(context)) .arch(getArch()) .build()); .build(), versionCode); DGResponse response = new Wire().parseFrom(signedResponse.data.toByteArray(), DGResponse.class); String checksum = response.vmChecksum.hex(); File dgCacheDir = context.getDir("dg_cache", 0); Loading @@ -89,6 +93,39 @@ public class DroidguardHelper { return invoke(context, clazz, request.packageName, request.reason, response.byteCode.toByteArray(), request.androidIdLong, request.extras); } public static int gmsVersionCode(int versionCode, String arch) { versionCode -= versionCode % 1000; switch (arch) { case "arm64-v8a": return versionCode + 23; case "x86": return versionCode + 26; case "x86_64": return versionCode + 27; default: return versionCode + 19; } } public static String gmsVersionNamePrefix(int versionCode, String arch) { int minor, patch; versionCode /= 1000; patch = versionCode % 100; versionCode /= 100; minor = versionCode % 10; versionCode /= 10; String versionPrefix = versionCode + "." + minor + "." + patch; switch (arch) { case "arm64-v8a": return versionPrefix + " (040400-{{cl}})"; case "x86": case "x86_64": return versionPrefix + " (040700-{{cl}})"; default: return versionPrefix + " (040300-{{cl}})"; } } public static byte[] invoke(Context context, Class<?> clazz, String packageName, String type, byte[] byteCode, String androidIdLong, Bundle extras) throws InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException, NoSuchMethodException { Object instance = clazz .getDeclaredConstructor(Context.class, String.class, byte[].class, Object.class) Loading @@ -111,6 +148,7 @@ public class DroidguardHelper { createSystemInfoPair("BRAND", clazz, build), createSystemInfoPair("CPU_ABI", clazz, build), createSystemInfoPair("CPU_ABI2", clazz, build), createSystemInfoPair("SUPPORTED_ABIS", clazz, build), createSystemInfoPair("DEVICE", clazz, build), createSystemInfoPair("DISPLAY", clazz, build), createSystemInfoPair("FINGERPRINT", clazz, build), Loading Loading @@ -157,7 +195,11 @@ public class DroidguardHelper { } } String nuKey = tr[tr.length - 1]; return new KeyValuePair(nuKey, String.valueOf(nuClass.getField(nuKey).get(nuObj))); Object val = nuClass.getField(nuKey).get(nuObj); if (val instanceof String[]) return new KeyValuePair(nuKey, TextUtils.join(",", (String[]) val)); else return new KeyValuePair(nuKey, String.valueOf(val)); } catch (Exception e) { if (obj != null) { // fallback to real system info Loading Loading @@ -240,14 +282,14 @@ public class DroidguardHelper { } } private static SignedDGResponse request(DGRequest request) throws IOException { private static SignedDGResponse request(DGRequest request, int versionCode) throws IOException { HttpURLConnection connection = (HttpURLConnection) new URL(DG_URL).openConnection(); connection.setRequestMethod("POST"); connection.setDoInput(true); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "application/x-protobuf"); connection.setRequestProperty("Accept-Encoding", "gzip"); connection.setRequestProperty("User-Agent", "DroidGuard/" + Constants.GMS_VERSION_CODE); connection.setRequestProperty("User-Agent", "DroidGuard/" + gmsVersionCode(versionCode, Build.CPU_ABI)); Log.d(TAG, "-- Request --\n" + request); OutputStream os = connection.getOutputStream(); Loading