Commit a907e0e0 by Fear1ess

4/8

parent cc0ff7e9
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
<activity android:name=".MainActivity"> <activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
......
...@@ -19,6 +19,9 @@ import android.content.pm.Signature; ...@@ -19,6 +19,9 @@ import android.content.pm.Signature;
import android.hardware.Camera; import android.hardware.Camera;
import android.hardware.Sensor; import android.hardware.Sensor;
import android.hardware.SensorManager; import android.hardware.SensorManager;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;
import android.location.Location; import android.location.Location;
import android.location.LocationListener; import android.location.LocationListener;
import android.location.LocationManager; import android.location.LocationManager;
...@@ -30,6 +33,7 @@ import android.net.wifi.WifiInfo; ...@@ -30,6 +33,7 @@ import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Looper;
import android.provider.Settings; import android.provider.Settings;
import android.provider.Telephony; import android.provider.Telephony;
import android.telephony.CellInfo; import android.telephony.CellInfo;
...@@ -45,18 +49,25 @@ import android.widget.TextView; ...@@ -45,18 +49,25 @@ import android.widget.TextView;
import com.reyun.wandun.WdCallback; import com.reyun.wandun.WdCallback;
import com.reyun.wandun.WdMain; import com.reyun.wandun.WdMain;
import java.io.ByteArrayInputStream;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.net.SocketException; import java.net.SocketException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
private TextView mText;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
mText = findViewById(R.id.data);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{ requestPermissions(new String[]{
Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_PHONE_STATE,
...@@ -67,7 +78,6 @@ public class MainActivity extends AppCompatActivity { ...@@ -67,7 +78,6 @@ public class MainActivity extends AppCompatActivity {
}, 100); }, 100);
} }
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Service.WIFI_SERVICE); WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Service.WIFI_SERVICE);
WifiInfo wi = wm.getConnectionInfo(); WifiInfo wi = wm.getConnectionInfo();
String ssid = wi.getSSID(); String ssid = wi.getSSID();
...@@ -80,11 +90,28 @@ public class MainActivity extends AppCompatActivity { ...@@ -80,11 +90,28 @@ public class MainActivity extends AppCompatActivity {
ResolveInfo ri = pm.resolveActivity(intent, 0); ResolveInfo ri = pm.resolveActivity(intent, 0);
String ss = ri.activityInfo.packageName; String ss = ri.activityInfo.packageName;
try {
PackageInfo pi = pm.getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
byte[] b = pi.signatures[0].toByteArray();
CertificateFactory cf = CertificateFactory.getInstance("X509");
Certificate ci = cf.generateCertificate(new ByteArrayInputStream(b));
Log.d("ffsfs", "onCreate: zzz");
} catch (PackageManager.NameNotFoundException | CertificateException e) {
e.printStackTrace();
}
CameraManager camera = (CameraManager) getSystemService(Service.CAMERA_SERVICE);
try {
String[] list = camera.getCameraIdList();
CameraCharacteristics cc = camera.getCameraCharacteristics("0");
Log.d("haha", "onCreate: ");
} catch (CameraAccessException e) {
e.printStackTrace();
}
// Example of a call to a native method
TextView tv = findViewById(R.id.sample_text);
tv.setText("hello world!");
} }
@Override @Override
...@@ -96,8 +123,14 @@ public class MainActivity extends AppCompatActivity { ...@@ -96,8 +123,14 @@ public class MainActivity extends AppCompatActivity {
//同步获取唯一id //同步获取唯一id
wm.getWdId(new WdCallback() { wm.getWdId(new WdCallback() {
@Override @Override
public void onWdId(String wdId) { public void onWdId(final String wdId) {
Log.d("demo", "onWdId: " + wdId); Log.d("demo", "onWdId: " + wdId);
mText.postDelayed(new Runnable() {
@Override
public void run() {
mText.setText(wdId);
}
}, 0);
} }
/* /*
@Override @Override
...@@ -105,8 +138,8 @@ public class MainActivity extends AppCompatActivity { ...@@ -105,8 +138,8 @@ public class MainActivity extends AppCompatActivity {
Log.d(TAG, "onError: " + errorMsg); Log.d(TAG, "onError: " + errorMsg);
}*/ }*/
}); });
}
} }
}
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"> tools:context=".MainActivity">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/sample_text" android:id="@+id/data"
android:layout_margin="7dp"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:singleLine="false"
android:text="Hello World!" android:layout_height="wrap_content" />
app:layout_constraintBottom_toBottomOf="parent" </ScrollView>
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout>
\ No newline at end of file \ No newline at end of file
...@@ -18,10 +18,12 @@ ...@@ -18,10 +18,12 @@
#include "openssl/md5.h" #include "openssl/md5.h"
#include <arpa/inet.h> #include <arpa/inet.h>
#include <sys/syscall.h> #include <sys/syscall.h>
#include <linux/prctl.h> #include <errno.h>
#include <zlib.h>
#define WD_COLLECT "wd_collect" #define WD_COLLECT "wd_collect"
extern jobject g_app_context; extern jobject g_app_context;
extern struct wd_funcs g_funcs; extern struct wd_funcs g_funcs;
...@@ -31,7 +33,7 @@ cJSON *collect_init() { ...@@ -31,7 +33,7 @@ cJSON *collect_init() {
return cJSON_CreateObject(); return cJSON_CreateObject();
} }
void do_collect(JNIEnv* env) { jstring do_collect(JNIEnv* env) {
cJSON* json = collect_init(); cJSON* json = collect_init();
struct timespec ts = {0}; struct timespec ts = {0};
double start_time = 0, end_time = 0; double start_time = 0, end_time = 0;
...@@ -67,6 +69,7 @@ void do_collect(JNIEnv* env) { ...@@ -67,6 +69,7 @@ void do_collect(JNIEnv* env) {
} }
collect_system_id(env, json); collect_system_id(env, json);
collect_time_info(env, json); collect_time_info(env, json);
collect_risk_info(env, json);
if(WDSYSCALL(SYS_clock_gettime, CLOCK_REALTIME, &ts) == 0) { if(WDSYSCALL(SYS_clock_gettime, CLOCK_REALTIME, &ts) == 0) {
...@@ -79,10 +82,15 @@ void do_collect(JNIEnv* env) { ...@@ -79,10 +82,15 @@ void do_collect(JNIEnv* env) {
const char* data = cJSON_Print(json); const char* data = cJSON_Print(json);
jstring data_jstr = (*env)->NewStringUTF(env, data);
return data_jstr;
/*
size_t len = strlen(data); size_t len = strlen(data);
int fd = WDSYSCALL(SYS_openat, AT_FDCWD, "/sdcard/wd_data", O_CREAT|O_RDWR|O_TRUNC, S_IRWXU); int fd = WDSYSCALL(SYS_openat, AT_FDCWD, "/sdcard/wd_data", O_CREAT|O_RDWR|O_TRUNC, S_IRWXU);
int err = errno;
WDSYSCALL(SYS_write, fd, data, len); WDSYSCALL(SYS_write, fd, data, len);
WDSYSCALL(SYS_close, fd); WDSYSCALL(SYS_close, fd);*/
} }
void collect_app_info(JNIEnv* env, cJSON *json) { void collect_app_info(JNIEnv* env, cJSON *json) {
...@@ -133,6 +141,20 @@ void collect_app_info(JNIEnv* env, cJSON *json) { ...@@ -133,6 +141,20 @@ void collect_app_info(JNIEnv* env, cJSON *json) {
cJSON_AddNumberToObject(json, "app_debug", (flags & (1 << 1)) ? 1 : 0); cJSON_AddNumberToObject(json, "app_debug", (flags & (1 << 1)) ? 1 : 0);
cJSON_AddNumberToObject(json, "app_backup", (flags & (1 << 15)) ? 1 : 0); cJSON_AddNumberToObject(json, "app_backup", (flags & (1 << 15)) ? 1 : 0);
//launcher
jstring action_jstr = (*env)->NewStringUTF(env, "android.intent.action.MAIN");
jstring category_jstr = (*env)->NewStringUTF(env, "android.intent.category.HOME");
jobject intent = wdNewObject(env, "android/content/Intent", "(Ljava/lang/String;)V", action_jstr);
wdCallObjectMethod(env, intent, "addCategory", "(Ljava/lang/String;)Landroid/content/Intent;", category_jstr);
jobject ri = wdCallObjectMethod(env, pkgManager, "resolveActivity",
"(Landroid/content/Intent;I)Landroid/content/pm/ResolveInfo;", intent, 0);
if(ri != NULL) {
jobject ai = wdGetObjectField(env, ri, "activityInfo", "Landroid/content/pm/ActivityInfo;");
jstring launcher_jstr = wdGetObjectField(env, ai, "packageName", "Ljava/lang/String;");
addJniStringToJson(env, json, "launcher", launcher_jstr);
}
logd(WD_COLLECT, "%s", "collect app info finished..."); logd(WD_COLLECT, "%s", "collect app info finished...");
(*env)->PopLocalFrame(env, NULL); (*env)->PopLocalFrame(env, NULL);
...@@ -192,6 +214,9 @@ void collect_mac_addr(JNIEnv *env, cJSON *json) { ...@@ -192,6 +214,9 @@ void collect_mac_addr(JNIEnv *env, cJSON *json) {
// //above android 11.0+ can't get mac by this method // //above android 11.0+ can't get mac by this method
jstring name_str = (*env)->NewStringUTF(env, "wlan0"); jstring name_str = (*env)->NewStringUTF(env, "wlan0");
jobject ni = wdCallStaticObjectMethod(env, "java/net/NetworkInterface", "getByName", "(Ljava/lang/String;)Ljava/net/NetworkInterface;", name_str); jobject ni = wdCallStaticObjectMethod(env, "java/net/NetworkInterface", "getByName", "(Ljava/lang/String;)Ljava/net/NetworkInterface;", name_str);
if(ni == NULL) {
goto return_label2;
}
jbyteArray mac_byteArr = wdCallObjectMethod(env, ni, "getHardwareAddress", "()[B"); jbyteArray mac_byteArr = wdCallObjectMethod(env, ni, "getHardwareAddress", "()[B");
if(mac_byteArr == NULL) { if(mac_byteArr == NULL) {
cJSON_AddStringToObject(json, "mac_addr", ""); cJSON_AddStringToObject(json, "mac_addr", "");
...@@ -207,6 +232,7 @@ void collect_mac_addr(JNIEnv *env, cJSON *json) { ...@@ -207,6 +232,7 @@ void collect_mac_addr(JNIEnv *env, cJSON *json) {
(*env)->DeleteLocalRef(env, mac_byteArr); (*env)->DeleteLocalRef(env, mac_byteArr);
return_label: return_label:
(*env)->DeleteLocalRef(env, ni); (*env)->DeleteLocalRef(env, ni);
return_label2:
(*env)->DeleteLocalRef(env, name_str); (*env)->DeleteLocalRef(env, name_str);
char* mac_addr2 = ""; char* mac_addr2 = "";
...@@ -393,7 +419,24 @@ void collect_libs_info(JNIEnv *env, cJSON *json) { ...@@ -393,7 +419,24 @@ void collect_libs_info(JNIEnv *env, cJSON *json) {
} }
void collect_cpu_info(JNIEnv *env, cJSON *json) { void collect_cpu_info(JNIEnv *env, cJSON *json) {
//todo cJSON* item = cJSON_CreateObject();
//cpu count
char count[10] = {0}, minfreq[20] = {0}, maxfreq[20] = {0}, features[100] = {0};
int res = read_file("/sys/devices/system/cpu/present", "r", count, 9);
cJSON_AddStringToObject(item, "count", count);
res = read_file("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq", "r", minfreq, 19);
cJSON_AddStringToObject(item, "minfreq", minfreq);
res = read_file("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r", maxfreq, 19);
cJSON_AddStringToObject(item, "maxfreq", maxfreq);
res = read_cmd("cat /proc/cpuinfo | grep Features", "r", features, 99);
char* ft = strchr(features, ' ') + 1;
cJSON_AddStringToObject(item, "features", ft);
cJSON_AddItemToObject(json, "cpu", item);
} }
void collect_sensor_info(JNIEnv *env, cJSON *json) { void collect_sensor_info(JNIEnv *env, cJSON *json) {
...@@ -616,18 +659,10 @@ void collect_cell_info(JNIEnv *env, cJSON *json) { ...@@ -616,18 +659,10 @@ void collect_cell_info(JNIEnv *env, cJSON *json) {
void collect_system_id(JNIEnv *env, cJSON *json) { void collect_system_id(JNIEnv *env, cJSON *json) {
char buf1[40] = {0}, buf2[40] = {0}; char buf1[40] = {0}, buf2[40] = {0};
FILE* fp = fopen("/proc/sys/kernel/random/boot_id", "r"); int res = read_file("/proc/sys/kernel/random/boot_id", "r", buf1, 39);
if(fp) {
fscanf(fp, "%s", buf1);
}
fclose(fp);
cJSON_AddStringToObject(json, "sys_boot_id", buf1); cJSON_AddStringToObject(json, "sys_boot_id", buf1);
fp = fopen("/proc/sys/kernel/random/uuid", "r"); res = read_file("/proc/sys/kernel/random/uuid", "r", buf2, 39);
if(fp) {
fscanf(fp, "%s", buf2);
}
fclose(fp);
cJSON_AddStringToObject(json, "sys_uuid", buf2); cJSON_AddStringToObject(json, "sys_uuid", buf2);
logd(WD_COLLECT, "%s", "collect system id finished..."); logd(WD_COLLECT, "%s", "collect system id finished...");
...@@ -643,7 +678,28 @@ void collect_time_info(JNIEnv *env, cJSON *json) { ...@@ -643,7 +678,28 @@ void collect_time_info(JNIEnv *env, cJSON *json) {
} }
if(WDSYSCALL(SYS_clock_gettime, CLOCK_BOOTTIME, &ts) == 0) { if(WDSYSCALL(SYS_clock_gettime, CLOCK_BOOTTIME, &ts) == 0) {
cJSON_AddNumberToObject(json, "boot_time", ts.tv_sec - cur); cJSON_AddNumberToObject(json, "boot_time", cur - ts.tv_sec);
} }
} }
// 收集风控信息
void collect_risk_info(JNIEnv *env, cJSON *json) {
//root
//su
char su[64] = {0};
int res = read_cmd("which su", "r", su, 63);
cJSON_AddStringToObject(json, "su", su);
//magisk
char magisk[64] = {0};
res = read_cmd("which magisk", "r", magisk, 63);
cJSON_AddStringToObject(json, "magisk", magisk);
//vpn
char* vpn = "/sys/class/net/tun0";
if(!is_file_exists(vpn)) {
vpn = "";
}
cJSON_AddStringToObject(json, "vpn", vpn);
}
...@@ -24,8 +24,7 @@ jobject g_app_context = NULL; ...@@ -24,8 +24,7 @@ jobject g_app_context = NULL;
struct wd_funcs g_funcs; struct wd_funcs g_funcs;
JNIEXPORT jstring jni_get_wdid(JNIEnv* env, jobject thiz) { JNIEXPORT jstring jni_get_wdid(JNIEnv* env, jobject thiz) {
do_collect(env); return do_collect(env);
return NULL;
} }
JNIEXPORT void jni_init(JNIEnv* env, jobject thiz, jobject context) { JNIEXPORT void jni_init(JNIEnv* env, jobject thiz, jobject context) {
...@@ -35,7 +34,6 @@ JNIEXPORT void jni_init(JNIEnv* env, jobject thiz, jobject context) { ...@@ -35,7 +34,6 @@ JNIEXPORT void jni_init(JNIEnv* env, jobject thiz, jobject context) {
} }
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) { JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
int pid = WDSYSCALL(SYS_getpid);
JNIEnv* env = NULL; JNIEnv* env = NULL;
if((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) == JNI_OK) { if((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) == JNI_OK) {
jclass cls = (*env)->FindClass(env, WDMAIN_CLASS_NAME); jclass cls = (*env)->FindClass(env, WDMAIN_CLASS_NAME);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <jni.h> #include <jni.h>
#include "cJSON.h" #include "cJSON.h"
void do_collect(JNIEnv* env); jstring do_collect(JNIEnv* env);
cJSON* collect_init(); cJSON* collect_init();
void collect_app_info(JNIEnv* env, cJSON* json); void collect_app_info(JNIEnv* env, cJSON* json);
int collect_permissions(JNIEnv* env, cJSON* json); int collect_permissions(JNIEnv* env, cJSON* json);
...@@ -33,6 +33,7 @@ void collect_location_info(JNIEnv* env, cJSON* json); ...@@ -33,6 +33,7 @@ void collect_location_info(JNIEnv* env, cJSON* json);
void collect_cell_info(JNIEnv* env, cJSON* json); void collect_cell_info(JNIEnv* env, cJSON* json);
void collect_system_id(JNIEnv* env, cJSON* json); void collect_system_id(JNIEnv* env, cJSON* json);
void collect_time_info(JNIEnv* env, cJSON* json); void collect_time_info(JNIEnv* env, cJSON* json);
void collect_risk_info(JNIEnv* env, cJSON* json);
/** Network type is unknown */ /** Network type is unknown */
#define NETWORK_TYPE_UNKNOWN 0 #define NETWORK_TYPE_UNKNOWN 0
......
...@@ -12,7 +12,10 @@ void addJniStringToJson(JNIEnv* env, cJSON* json, const char* key, jobject jstr) ...@@ -12,7 +12,10 @@ void addJniStringToJson(JNIEnv* env, cJSON* json, const char* key, jobject jstr)
void getJniStringSha256(JNIEnv* env, jobject jstr, char* sha256); void getJniStringSha256(JNIEnv* env, jobject jstr, char* sha256);
void bytes2Hex(const unsigned char* source, char* dest, int sourceLen, int mac_format); void bytes2Hex(const unsigned char* source, char* dest, int sourceLen, int mac_format);
void hex2Bytes(const char* source, unsigned char* dest, int sourceLen); void hex2Bytes(const char* source, unsigned char* dest, int sourceLen);
int readCmd(const char* cmd, const char* mode, char* r_buf, size_t r_len); int read_cmd(const char* cmd, const char* mode, char* r_buf, size_t r_len);
int read_file(const char* file_path, const char* mode, char* r_buf, size_t r_len);
int is_file_exists(const char* file_path);
void delete_enter(char* buf, int len);
char *wd_util_trim(char *start); char *wd_util_trim(char *start);
#endif //REYUNSDK_UTILS_H #endif //REYUNSDK_UTILS_H
...@@ -10,6 +10,11 @@ ...@@ -10,6 +10,11 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include "wd_result.h" #include "wd_result.h"
#include "wd_syscall.h"
#include "syscall.h"
#include "fcntl.h"
IMPORTWDSYSCALL
//字节流转换为十六进制字符串 //字节流转换为十六进制字符串
void bytes2Hex(const unsigned char *source, char *dest, int sourceLen, int mac_format) { void bytes2Hex(const unsigned char *source, char *dest, int sourceLen, int mac_format) {
...@@ -90,11 +95,12 @@ void getJniStringSha256(JNIEnv* env, jobject jstr, char* sha256) { ...@@ -90,11 +95,12 @@ void getJniStringSha256(JNIEnv* env, jobject jstr, char* sha256) {
sha256[64] = 0; sha256[64] = 0;
} }
int readCmd(const char *cmd, const char *mode, char *r_buf, size_t r_len) { int read_cmd(const char *cmd, const char *mode, char *r_buf, size_t r_len) {
FILE* fp = popen(cmd, mode); FILE* fp = popen(cmd, mode);
int res; int res;
if(!fp) res = WD_ERROR; if(!fp) return WD_ERROR;
int read_size = fread(r_buf, r_len, 1, fp); int read_size = fread(r_buf, 1, r_len, fp);
if(read_size > 0) delete_enter(r_buf, read_size);
if(read_size == -1) res = WD_ERROR; if(read_size == -1) res = WD_ERROR;
else res = WD_OK; else res = WD_OK;
pclose(fp); pclose(fp);
...@@ -118,3 +124,37 @@ char *wd_util_trim(char *start) ...@@ -118,3 +124,37 @@ char *wd_util_trim(char *start)
*end = '\0'; *end = '\0';
return start; return start;
} }
void delete_enter(char* buf, int len) {
int i = 0;
while(i < len) {
if (buf[i] == '\n') {
buf[i] = 0;
return;
}
++i;
}
}
int read_file(const char *file_path, const char *mode, char *r_buf, size_t r_len) {
FILE* fp = fopen(file_path, mode);
int res;
if(!fp) return WD_ERROR;
int read_size = fread(r_buf, 1, r_len, fp);
if(read_size > 0) delete_enter(r_buf, read_size);
if(read_size == -1) res = WD_ERROR;
else res = WD_OK;
fclose(fp);
return res;
}
int is_file_exists(const char *file_path) {
int res;
int fd = WDSYSCALL(SYS_openat, AT_FDCWD, file_path, O_RDONLY, 0);
if(fd == -1) res = 0;
else {
WDSYSCALL(SYS_close, fd);
res = 1;
}
return res;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment