Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
ReyunSecureSdk
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhanglei
ReyunSecureSdk
Commits
a907e0e0
Commit
a907e0e0
authored
Apr 16, 2021
by
Fear1ess
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
4/8
parent
cc0ff7e9
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
173 additions
and
41 deletions
+173
-41
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+0
-1
MainActivity.java
app/src/main/java/com/reyun/sdktestdemo/MainActivity.java
+39
-6
activity_main.xml
app/src/main/res/layout/activity_main.xml
+13
-11
collect.c
wandun/src/main/cpp/collect.c
+71
-15
core.c
wandun/src/main/cpp/core.c
+1
-3
collect.h
wandun/src/main/cpp/include/collect.h
+2
-1
utils.h
wandun/src/main/cpp/include/utils.h
+4
-1
utils.c
wandun/src/main/cpp/utils.c
+43
-3
No files found.
app/src/main/AndroidManifest.xml
View file @
a907e0e0
...
...
@@ -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>
...
...
app/src/main/java/com/reyun/sdktestdemo/MainActivity.java
View file @
a907e0e0
...
...
@@ -19,6 +19,9 @@ 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
;
...
...
@@ -30,6 +33,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
;
...
...
@@ -45,18 +49,25 @@ import android.widget.TextView;
import
com.reyun.wandun.WdCallback
;
import
com.reyun.wandun.WdMain
;
import
java.io.ByteArrayInputStream
;
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
;
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
,
...
...
@@ -67,7 +78,6 @@ public class MainActivity extends AppCompatActivity {
},
100
);
}
WifiManager
wm
=
(
WifiManager
)
getApplicationContext
().
getSystemService
(
Service
.
WIFI_SERVICE
);
WifiInfo
wi
=
wm
.
getConnectionInfo
();
String
ssid
=
wi
.
getSSID
();
...
...
@@ -80,11 +90,28 @@ public class MainActivity extends AppCompatActivity {
ResolveInfo
ri
=
pm
.
resolveActivity
(
intent
,
0
);
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
...
...
@@ -96,8 +123,14 @@ public class MainActivity extends AppCompatActivity {
//同步获取唯一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
...
...
@@ -105,8 +138,8 @@ public class MainActivity extends AppCompatActivity {
Log.d(TAG, "onError: " + errorMsg);
}*/
});
}
}
}
}
app/src/main/res/layout/activity_main.xml
View file @
a907e0e0
<?xml version="1.0" encoding="utf-8"?>
<
androidx.constraintlayout.widget.Constraint
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<
Linear
Layout
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"
>
<TextView
android:id=
"@+id/sample_text"
<ScrollView
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:layout_height=
"wrap_content"
>
<TextView
android:id=
"@+id/data"
android:layout_margin=
"7dp"
android:layout_width=
"wrap_content"
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
wandun/src/main/cpp/collect.c
View file @
a907e0e0
...
...
@@ -18,10 +18,12 @@
#include "openssl/md5.h"
#include <arpa/inet.h>
#include <sys/syscall.h>
#include <linux/prctl.h>
#include <errno.h>
#include <zlib.h>
#define WD_COLLECT "wd_collect"
extern
jobject
g_app_context
;
extern
struct
wd_funcs
g_funcs
;
...
...
@@ -31,7 +33,7 @@ cJSON *collect_init() {
return
cJSON_CreateObject
();
}
void
do_collect
(
JNIEnv
*
env
)
{
jstring
do_collect
(
JNIEnv
*
env
)
{
cJSON
*
json
=
collect_init
();
struct
timespec
ts
=
{
0
};
double
start_time
=
0
,
end_time
=
0
;
...
...
@@ -67,6 +69,7 @@ void do_collect(JNIEnv* env) {
}
collect_system_id
(
env
,
json
);
collect_time_info
(
env
,
json
);
collect_risk_info
(
env
,
json
);
if
(
WDSYSCALL
(
SYS_clock_gettime
,
CLOCK_REALTIME
,
&
ts
)
==
0
)
{
...
...
@@ -79,10 +82,15 @@ void do_collect(JNIEnv* env) {
const
char
*
data
=
cJSON_Print
(
json
);
jstring
data_jstr
=
(
*
env
)
->
NewStringUTF
(
env
,
data
);
return
data_jstr
;
/*
size_t len = strlen(data);
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_close
,
fd
);
WDSYSCALL(SYS_close, fd);
*/
}
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_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..."
);
(
*
env
)
->
PopLocalFrame
(
env
,
NULL
);
...
...
@@ -192,6 +214,9 @@ void collect_mac_addr(JNIEnv *env, cJSON *json) {
// //above android 11.0+ can't get mac by this method
jstring
name_str
=
(
*
env
)
->
NewStringUTF
(
env
,
"wlan0"
);
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"
);
if
(
mac_byteArr
==
NULL
)
{
cJSON_AddStringToObject
(
json
,
"mac_addr"
,
""
);
...
...
@@ -207,6 +232,7 @@ void collect_mac_addr(JNIEnv *env, cJSON *json) {
(
*
env
)
->
DeleteLocalRef
(
env
,
mac_byteArr
);
return_label:
(
*
env
)
->
DeleteLocalRef
(
env
,
ni
);
return_label2:
(
*
env
)
->
DeleteLocalRef
(
env
,
name_str
);
char
*
mac_addr2
=
""
;
...
...
@@ -393,7 +419,24 @@ void collect_libs_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
)
{
...
...
@@ -616,18 +659,10 @@ void collect_cell_info(JNIEnv *env, cJSON *json) {
void
collect_system_id
(
JNIEnv
*
env
,
cJSON
*
json
)
{
char
buf1
[
40
]
=
{
0
},
buf2
[
40
]
=
{
0
};
FILE
*
fp
=
fopen
(
"/proc/sys/kernel/random/boot_id"
,
"r"
);
if
(
fp
)
{
fscanf
(
fp
,
"%s"
,
buf1
);
}
fclose
(
fp
);
int
res
=
read_file
(
"/proc/sys/kernel/random/boot_id"
,
"r"
,
buf1
,
39
);
cJSON_AddStringToObject
(
json
,
"sys_boot_id"
,
buf1
);
fp
=
fopen
(
"/proc/sys/kernel/random/uuid"
,
"r"
);
if
(
fp
)
{
fscanf
(
fp
,
"%s"
,
buf2
);
}
fclose
(
fp
);
res
=
read_file
(
"/proc/sys/kernel/random/uuid"
,
"r"
,
buf2
,
39
);
cJSON_AddStringToObject
(
json
,
"sys_uuid"
,
buf2
);
logd
(
WD_COLLECT
,
"%s"
,
"collect system id finished..."
);
...
...
@@ -643,7 +678,28 @@ void collect_time_info(JNIEnv *env, cJSON *json) {
}
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
);
}
wandun/src/main/cpp/core.c
View file @
a907e0e0
...
...
@@ -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,6 @@ JNIEXPORT void jni_init(JNIEnv* env, jobject thiz, jobject context) {
}
JNIEXPORT
jint
JNI_OnLoad
(
JavaVM
*
vm
,
void
*
reserved
)
{
int
pid
=
WDSYSCALL
(
SYS_getpid
);
JNIEnv
*
env
=
NULL
;
if
((
*
vm
)
->
GetEnv
(
vm
,
(
void
**
)
&
env
,
JNI_VERSION_1_6
)
==
JNI_OK
)
{
jclass
cls
=
(
*
env
)
->
FindClass
(
env
,
WDMAIN_CLASS_NAME
);
...
...
wandun/src/main/cpp/include/collect.h
View file @
a907e0e0
...
...
@@ -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
);
...
...
@@ -33,6 +33,7 @@ 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_risk_info
(
JNIEnv
*
env
,
cJSON
*
json
);
/** Network type is unknown */
#define NETWORK_TYPE_UNKNOWN 0
...
...
wandun/src/main/cpp/include/utils.h
View file @
a907e0e0
...
...
@@ -12,7 +12,10 @@ void addJniStringToJson(JNIEnv* env, cJSON* json, const char* key, 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
wandun/src/main/cpp/utils.c
View file @
a907e0e0
...
...
@@ -10,6 +10,11 @@
#include <string.h>
#include <ctype.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
)
{
...
...
@@ -90,11 +95,12 @@ void getJniStringSha256(JNIEnv* env, jobject jstr, char* sha256) {
sha256
[
64
]
=
0
;
}
int
read
C
md
(
const
char
*
cmd
,
const
char
*
mode
,
char
*
r_buf
,
size_t
r_len
)
{
int
read
_c
md
(
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 +124,37 @@ 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
;
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
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment