Commit b888a62d by Fear1ess

3/31

parent aff26ecf
......@@ -19,6 +19,9 @@ android {
cppFlags ""
}
}
ndk {
abiFilters "armeabi-v7a", "arm64-v8a"
}
}
buildTypes {
......
......@@ -3,6 +3,7 @@
package="com.reyun.sdktestdemo">
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
......
......@@ -14,6 +14,10 @@ android {
// testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
buildTypes {
......
......@@ -4,8 +4,22 @@ project(Wandun)
include_directories(${CMAKE_SOURCE_DIR}/include)
if(${CMAKE_ANDROID_ARCH_ABI} STREQUAL "arm64-v8a")
set(OS_DEPENDENDED_SRC
wd_syscall64.s)
elseif (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "armeabi-v7a")
set(OS_DEPENDENDED_SRC
wd_syscall32.s)
endif()
add_library(wdun
SHARED
core.cpp)
core.cpp
wd_syscall.cpp
${OS_DEPENDENDED_SRC}
)
target_link_libraries(wdun log)
enable_language(ASM)
\ No newline at end of file
......@@ -2,3 +2,29 @@
// Created by 12567 on 2021/3/31.
//
#include <jni.h>
#include <syscall.h>
#include "wdun.h"
//import asm symbol
IMPORTWDSYSCALL
#define WDMAIN_CLASS_NAME "com/reyun/wandun/WdMain"
#define WDMAIN_GETWDID_METHOD_NAME "getWdIdNative"
#define WDMAIN_GETWDID_METHOD_SIG "()Ljava/lang/String;"
jstring jni_get_wdid(JNIEnv* env, jobject thiz) {
}
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
int pid = WDSYSCALL(SYS_getpid);
JNIEnv* env = NULL;
if(vm->GetEnv((void**)&env, JNI_VERSION_1_6) == JNI_TRUE) {
jclass cls = env->FindClass(WDMAIN_CLASS_NAME);
JNINativeMethod methods[] = {{WDMAIN_GETWDID_METHOD_NAME, WDMAIN_GETWDID_METHOD_SIG, (void*)jni_get_wdid}};
env->RegisterNatives(cls, methods, sizeof(methods)/sizeof(JNINativeMethod));
}
return JNI_VERSION_1_6;
}
//
// Created by Fear1ess on 2021/3/31.
//
#ifndef REYUNSDK_WD_SYSCALL_H
#define REYUNSDK_WD_SYSCALL_H
#define WD_SYSCALL_BASE 0xcd
#define WDNUM(x) (x + WD_SYSCALL_BASE)
#ifdef __arm__
#define WDSYSCALL(cmd, args...) wd_syscall32(WDNUM(cmd), ##args)
#endif
#ifdef __aarch64__
#define WDSYSCALL(cmd, args...) wd_syscall64(WDNUM(cmd), ##args)
#endif
#define IMPORTWDSYSCALL \
extern "C" int wd_syscall32(int cmd, ...);\
extern "C" int wd_syscall64(int cmd, ...);
extern "C" int wd_set_errno(int n);
#endif //REYUNSDK_WD_SYSCALL_H
//
// Created by Fear1ess on 2021/3/31.
//
#ifndef REYUNSDK_WDUN_H
#define REYUNSDK_WDUN_H
#include <android/log.h>
#include "wd_syscall.h"
#define logd(tag, fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, tag, fmt, ##args)
#endif //REYUNSDK_WDUN_H
//
// Created by Fear1ess on 2021/3/31.
//
#include "wd_syscall.h"
#include <errno.h>
int wd_set_errno(int n) {
errno = n;
return -1;
}
//
// Created by Fear1ess on 2021/3/31.
//
.global wd_syscall32
.extern wd_set_errno
wd_syscall32:
mov ip, sp
stmfd sp!, {r4, r5, r6, r7}
sub r0, r0, #0xcd
mov r7, r0
mov r0, r1
mov r1, r2
mov r2, r3
ldmfd ip, {r3, r4, r5, r6}
swi #0
ldmfd sp!, {r4, r5, r6, r7}
cmn r0, #0x1000
bxls lr
neg r0, r0
b wd_set_errno
.global wd_syscall64
.extern wd_set_errno
wd_syscall64:
/* Move syscall No. from x0 to x8 */
sub x0, x0, #0xcd
mov x8, x0
/* Move syscall parameters from x1 thru x6 to x0 thru x5 */
mov x0, x1
mov x1, x2
mov x2, x3
mov x3, x4
mov x4, x5
mov x5, x6
svc #0
/* check if syscall returned successfully */
cmn x0, #0x1000
cneg x0, x0, hi
b.hi wd_set_errno
ret
\ No newline at end of file
package com.reyun.wandun;
import android.os.Message;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MdUtils {
public static String md5(String data) {
public static String md(String algorithm, String data) {
try {
MessageDigest md = MessageDigest.getInstance("md5");
MessageDigest md = MessageDigest.getInstance(algorithm);
byte[] result = md.digest(data.getBytes());
return bytes2HexString(result);
} catch (NoSuchAlgorithmException e) {
......@@ -17,6 +15,14 @@ public class MdUtils {
return null;
}
public static String md5(String data) {
return md("md5", data);
}
public static String sha1(String data) {
return md("sha-1", data);
}
private static byte charToByte(char c) {
return (byte) "0123456789abcdef".indexOf(c);
}
......
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