Commit 750a90ee by 1256748979@qq.com

Merge remote-tracking branch 'origin/master'

parents e714b640 deefe57d
......@@ -3,6 +3,14 @@ plugins {
}
android {
signingConfigs {
release {
storeFile file('reyun.keystore')
storePassword 'reyun12345'
keyAlias 'reyun.keystore'
keyPassword 'reyun12345'
}
}
compileSdkVersion 30
buildToolsVersion "30.0.3"
......@@ -24,13 +32,10 @@ android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
......
......@@ -19,7 +19,6 @@
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
......
......@@ -14,14 +14,19 @@ import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.Signature;
import android.hardware.Camera;
import android.hardware.Sensor;
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.LocationListener;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
......@@ -29,6 +34,7 @@ import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Looper;
import android.provider.Settings;
import android.provider.Telephony;
import android.telephony.CellInfo;
......@@ -44,18 +50,28 @@ import android.widget.TextView;
import com.reyun.wandun.WdCallback;
import com.reyun.wandun.WdMain;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
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.List;
import java.util.Properties;
public class MainActivity extends AppCompatActivity {
private TextView mText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mText = findViewById(R.id.data);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{
Manifest.permission.READ_PHONE_STATE,
......@@ -66,68 +82,53 @@ public class MainActivity extends AppCompatActivity {
}, 100);
}
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Service.WIFI_SERVICE);
WifiInfo wi = wm.getConnectionInfo();
String ssid = wi.getSSID();
String bssid = wi.getBSSID();
int ip = wi.getIpAddress();
PackageManager pm =getPackageManager();
int uid = getApplicationInfo().uid;
Intent intent = new Intent("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
ResolveInfo ri = pm.resolveActivity(intent, 0);
String ss = ri.activityInfo.packageName;
try {
getFilesDir().getCanonicalPath();
} catch (IOException e) {
e.printStackTrace();
}
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));
} catch (PackageManager.NameNotFoundException | CertificateException e) {
e.printStackTrace();
}
// Example of a call to a native method
TextView tv = findViewById(R.id.sample_text);
tv.setText("hello world!");
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if(requestCode == 100) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
Location bestLocation = null;
LocationManager lm = (LocationManager) getApplicationContext().getSystemService(Service.LOCATION_SERVICE);
Log.d("testdemo-1", "ha ha ha...");
List<String> list = lm.getAllProviders();
for (String provider : list) {
Location l = lm.getLastKnownLocation(provider);
if (l == null) {
continue;
}
if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) {
// Found best last known location: %s", l);
Log.d("testdemo-1", "provider: " + provider);
bestLocation = l;
}
}
if(bestLocation != null) {
double lat = bestLocation.getLatitude();
double lon = bestLocation.getLongitude();
Log.d("testdemo-1", lat + ", " + lon);
}
TelephonyManager tm = (TelephonyManager) getApplicationContext().getSystemService(Service.TELEPHONY_SERVICE);
List<CellInfo> cellInfos = tm.getAllCellInfo();
CellLocation cl = tm.getCellLocation();
String aa = System.getProperty("http.agent");
//初始化sdk环境
WdMain wm = WdMain.getInstance();
wm.init(getApplicationContext(), "test-a341fsfr3123ddadfs");
//同步获取唯一id
wm.getWdId(new WdCallback() {
@Override
public void onWdId(String wdId) {
public void onWdId(final String wdId) {
Log.d("demo", "onWdId: " + wdId);
mText.postDelayed(new Runnable() {
@Override
public void run() {
mText.setText(wdId);
}
}, 0);
}
/*
@Override
......@@ -136,7 +137,28 @@ public class MainActivity extends AppCompatActivity {
}*/
});
}
}
public String getDns() {
String result = "";
ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
for (Network network : cm.getAllNetworks()) {
NetworkInfo networkInfo = cm.getNetworkInfo(network);
if (networkInfo.getType() == activeNetworkInfo.getType()) {
LinkProperties lp = cm.getLinkProperties(network);
for (InetAddress addr : lp.getDnsServers()) {
// Get DNS IP address here:
result += addr.getHostAddress() + ",";
}
}
}
if(result.contains(",")){
result=result.substring(0, result.length() - 1);
}
result="[" + result + "]";
return result;
}
}
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/sample_text"
android:id="@+id/data"
android:layout_margin="7dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:singleLine="false"
android:layout_height="wrap_content" />
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
</LinearLayout>
\ No newline at end of file
......@@ -7,7 +7,7 @@ android {
buildToolsVersion "30.0.3"
defaultConfig {
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
......@@ -26,10 +26,7 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
......
......@@ -6,11 +6,15 @@ include_directories(${CMAKE_SOURCE_DIR}/include)
if(${CMAKE_ANDROID_ARCH_ABI} STREQUAL "arm64-v8a")
set(ARCH_DEPENDED_SRC
wd_syscall64.s)
wd_syscall_aarch64.s)
elseif (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "armeabi-v7a")
set(ARCH_DEPENDED_SRC
wd_syscall32.s)
wd_syscall_arm.s)
elseif (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "x86")
set(ARCH_DEPENDED_SRC
wd_syscall_x86.s)
endif()
add_library(
......
......@@ -24,8 +24,7 @@ jobject g_app_context = NULL;
struct wd_funcs g_funcs;
JNIEXPORT jstring jni_get_wdid(JNIEnv* env, jobject thiz) {
do_collect(env);
return NULL;
return do_collect(env);
}
JNIEXPORT void jni_init(JNIEnv* env, jobject thiz, jobject context) {
......@@ -35,7 +34,7 @@ JNIEXPORT void jni_init(JNIEnv* env, jobject thiz, jobject context) {
}
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
int pid = WDSYSCALL(SYS_getpid);
logd("wdun_core", "%s", "enter jni_onload...");
JNIEnv* env = NULL;
if((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) == JNI_OK) {
jclass cls = (*env)->FindClass(env, WDMAIN_CLASS_NAME);
......@@ -45,12 +44,20 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
(*env)->DeleteLocalRef(env, cls);
}
//find lic needed symbol
logd("wdun_core", "%s", "find libc symbol...");
//find libc needed symbol
struct so_info* si = fake_dlopen("libc.so", 0);
if(si != NULL) {
g_funcs.wd_popen = fake_dlsym(si, "popen");
g_funcs.wd_pclose = fake_dlsym(si, "pclose");
g_funcs.wd_system_property_get = fake_dlsym(si, "__system_property_get");
fake_dlclose(si);
}
if(!g_funcs.wd_popen) g_funcs.wd_popen = popen;
if(!g_funcs.wd_pclose) g_funcs.wd_pclose = pclose;
if(!g_funcs.wd_system_property_get) g_funcs.wd_system_property_get = __system_property_get;
logd("wdun_core", "%s", "leave jni_onload...");
return JNI_VERSION_1_6;
}
......@@ -8,7 +8,7 @@
#include <jni.h>
#include "cJSON.h"
void do_collect(JNIEnv* env);
jstring do_collect(JNIEnv* env);
cJSON* collect_init();
void collect_app_info(JNIEnv* env, cJSON* json);
int collect_permissions(JNIEnv* env, cJSON* json);
......@@ -31,6 +31,10 @@ void collect_network_info(JNIEnv* env, cJSON* json);
void collect_user_agent(JNIEnv* env, cJSON* json);
void collect_location_info(JNIEnv* env, cJSON* json);
void collect_cell_info(JNIEnv* env, cJSON* json);
void collect_system_id(JNIEnv* env, cJSON* json);
void collect_time_info(JNIEnv* env, cJSON* json);
void collect_common_app(JNIEnv* env, cJSON* json);
void collect_risk_info(JNIEnv* env, cJSON* json);
/** Network type is unknown */
#define NETWORK_TYPE_UNKNOWN 0
......
......@@ -9,10 +9,14 @@
#include <jni.h>
void addJniStringToJson(JNIEnv* env, cJSON* json, const char* key, jobject jstr);
void addJniStringToArray(JNIEnv* env, cJSON* json, jobject jstr);
void getJniStringSha256(JNIEnv* env, jobject jstr, char* sha256);
void bytes2Hex(const unsigned char* source, char* dest, int sourceLen, int mac_format);
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);
#endif //REYUNSDK_UTILS_H
......@@ -10,18 +10,32 @@
#ifdef __arm__
#define WDSYSCALL(cmd, args...) wd_syscall32(WDNUM(cmd), ##args)
#define WDSYSCALL(cmd, args...) wd_syscall_arm(WDNUM(cmd), ##args)
#define WD_SYS_mmap SYS_mmap2
#define WD_SYS_fstatat SYS_fstatat64
#endif
#ifdef __aarch64__
#define WDSYSCALL(cmd, args...) wd_syscall64(WDNUM(cmd), ##args)
#define WDSYSCALL(cmd, args...) wd_syscall_aarch64(WDNUM(cmd), ##args)
#define WD_SYS_mmap SYS_mmap
#define WD_SYS_fstatat SYS_newfstatat
#endif
#ifdef x86
#define WDSYSCALL(cmd, args...) wd_syscall_x86(WDNUM(cmd), ##args)
#define WD_SYS_mmap SYS_mmap
#endif
#ifdef x86_64
#define WDSYSCALL(cmd, args...) wd_syscall_x64(WDNUM(cmd), ##args)
#define WD_SYS_mmap SYS_mmap
#endif
#define IMPORTWDSYSCALL \
__attribute__((visibility("hidden"))) extern long wd_syscall32(int cmd, ...);\
__attribute__((visibility("hidden"))) extern long wd_syscall64(int cmd, ...);
__attribute__((visibility("hidden"))) extern long wd_syscall_arm(int cmd, ...);\
__attribute__((visibility("hidden"))) extern long wd_syscall_aarch64(int cmd, ...);\
__attribute__((visibility("hidden"))) extern long wd_syscall_x86(int cmd, ...);\
__attribute__((visibility("hidden"))) extern long wd_syscall_x64(int cmd, ...);
long wd_set_errno(int n);
......
......@@ -10,6 +10,13 @@
#include <string.h>
#include <ctype.h>
#include "wd_result.h"
#include "wd_syscall.h"
#include "syscall.h"
#include "fcntl.h"
#include "errno.h"
#include "unistd.h"
IMPORTWDSYSCALL
//字节流转换为十六进制字符串
void bytes2Hex(const unsigned char *source, char *dest, int sourceLen, int mac_format) {
......@@ -69,13 +76,19 @@ void hex2Bytes(const char* source, unsigned char* dest, int sourceLen)
return;
}
void addJniStringToArray(JNIEnv* env, cJSON* json, jobject jstr) {
addJniStringToJson(env, json, NULL, jstr);
}
void addJniStringToJson(JNIEnv *env, cJSON *json, const char *key, jobject jstr) {
if(jstr == NULL) {
cJSON_AddStringToObject(json, key, "");
if(key) cJSON_AddStringToObject(json, key, "");
else cJSON_AddItemToArray(json, cJSON_CreateString(""));
}else{
jboolean bl = 0;
const char* value= (*env)->GetStringUTFChars(env, jstr, &bl);
cJSON_AddStringToObject(json, key, value);
if(key) cJSON_AddStringToObject(json, key, value);
else cJSON_AddItemToArray(json, cJSON_CreateString(value));
(*env)->ReleaseStringUTFChars(env, jstr, value);
}
}
......@@ -90,11 +103,12 @@ void getJniStringSha256(JNIEnv* env, jobject jstr, char* sha256) {
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);
int res;
if(!fp) res = WD_ERROR;
int read_size = fread(r_buf, r_len, 1, fp);
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;
pclose(fp);
......@@ -118,3 +132,33 @@ char *wd_util_trim(char *start)
*end = '\0';
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 = WDSYSCALL(SYS_faccessat, AT_FDCWD, file_path, F_OK, 0);
int err = errno;
if(res == -1) return 0;
return 1;
}
......@@ -240,6 +240,7 @@ jvalue wdCallStaticMethod(JNIEnv* env, const char* clsName, const char* methodNa
break;
default: break;
}
wdCheckException(env);
return_label:
......@@ -250,6 +251,10 @@ jvalue wdCallStaticMethod(JNIEnv* env, const char* clsName, const char* methodNa
jvalue wdCallMethod(JNIEnv* env, jobject obj, const char* methodName, const char* methodSig, va_list args) {
jclass cls = (*env)->GetObjectClass(env, obj);
jmethodID methodId = (*env)->GetMethodID(env, cls, methodName, methodSig);
if(methodId == NULL) {
logd(WD_JNI, "not find method %s%s", methodName, methodSig);
goto return_label;
}
jvalue value = {0};
switch(wdGetMethodRetType(methodSig)) {
case 'V':
......@@ -286,6 +291,7 @@ jvalue wdCallMethod(JNIEnv* env, jobject obj, const char* methodName, const char
default: break;
}
wdCheckException(env);
return_label:
(*env)->DeleteLocalRef(env, cls);
return value;
}
......
......@@ -2,12 +2,12 @@
// Created by Fear1ess on 2021/3/31.
//
.global wd_syscall64
.global wd_syscall_aarch64
.extern wd_set_errno
.type wd_syscall64, %function
.type wd_syscall_aarch64, %function
wd_syscall64:
wd_syscall_aarch64:
/* Move syscall No. from x0 to x8 */
sub x0, x0, #0xcd
mov x8, x0
......
......@@ -2,12 +2,12 @@
// Created by Fear1ess on 2021/3/31.
//
.global wd_syscall32
.global wd_syscall_arm
.extern wd_set_errno
.type wd_syscall32, %function
.type wd_syscall_arm, %function
wd_syscall32:
wd_syscall_arm:
mov ip, sp
stmfd sp!, {r4, r5, r6, r7}
sub r0, r0, #0xcd
......
.global wd_syscall_x86
.extern wd_set_errno
.type wd_syscall_x86, %function
wd_syscall_x86:
# Push the callee save registers.
push %ebx
push %esi
push %edi
push %ebp
# Get and save the system call entry address.
int $80
push %eax
# Load all the arguments from the calling frame.
# (Not all will be valid, depending on the syscall.)
mov 24(%esp),%eax
mov 28(%esp),%ebx
mov 32(%esp),%ecx
mov 36(%esp),%edx
mov 40(%esp),%esi
mov 44(%esp),%edi
mov 48(%esp),%ebp
# Make the system call.
call *(%esp)
addl $4, %esp
# Error?
cmpl $-4096, %eax
jb 1f
# Yes, so set errno.
negl %eax
pushl %eax
call wd_set_errno
addl $4, %esp
1:
# Restore the callee save registers.
pop %ebp
pop %edi
pop %esi
pop %ebx
ret
\ No newline at end of file
......@@ -41,7 +41,7 @@ public class WdMain {
}
//获取wdId
public void getWdId(WdCallback cb) {
public void getWdId(final WdCallback cb) {
ExecutorService es = Executors.newSingleThreadExecutor();
es.execute(new Runnable() {
@Override
......
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