Commit 7a3bc78d by Fear1ess

4/25

parent 82d12cfe
......@@ -54,6 +54,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.Proxy;
import java.net.SocketException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
......
......@@ -25,6 +25,10 @@ add_library(
utils.c
wd_syscall.c
wd_jni.c
https.c
aesencode.c
rsaencode.c
mybase64.c
fake_dlfcn.c
${ARCH_DEPENDED_SRC}
)
......
//
// Created by MyPC on 2021/4/17.
//
#include "aesencode.h"
#include <stdlib.h>
#include <openssl/aes.h>
#include <openssl/base64.h>
#include <time.h>
#include "string.h"
#include "android/log.h"
#include "mybase64.h"
#define LOG_TAG "WD_COLLECT"
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__);
void generateAESKeyIv(char *key, char*iv, char* key_Table);
void encrpyt_buf(char*m_key,char*m_iv, char *raw_buf, char **encrpy_buf, int len );
void decrpyt_buf(char*m_key,char*m_iv, char *raw_buf, char **encrpy_buf, int len );
int startAESEncode(char*m_key,char*m_iv, char* src,int src_Size,char**encode_ptr,int* out_size);
char *padding_buf(char *buf,int size, int *final_size);
char *padding_buf(char *buf,int size, int *final_size) {
char *ret = NULL;
//填充区的大小
int pidding_size = AES_BLOCK_SIZE - (size % AES_BLOCK_SIZE);
int i;
*final_size = size + pidding_size;
ret = (char *)calloc(1,size+pidding_size);
memcpy( ret, buf, size);
if (pidding_size!=0) {
for (i =size;i < (size+pidding_size); i++ ) {
ret[i] = 0;
}
}
return ret;
}
int startAESEncode(char*m_key,char*m_iv, char* src,int src_Size,char**encode_ptr,int* out_size){
if(src== NULL||src_Size<=0){
return 0;
}
char *after_padding_buf = NULL;
int padding_size = 0;
char *encrypt_buf = NULL;
//进行填充
after_padding_buf = padding_buf(src,src_Size,&padding_size);
if(after_padding_buf==NULL){
return 0;
}
// 进行加密
encrypt_buf = (char *)calloc(1,padding_size);
encrpyt_buf(m_key,m_iv,after_padding_buf,&encrypt_buf, padding_size);
free(after_padding_buf);
//传出加密后的内容
*encode_ptr = encrypt_buf;
*out_size=padding_size;
//-----------------测试代码
//打印源字符串的16进制
unsigned char* temp=( unsigned char*)calloc(1,padding_size*2+1);
int strLen=padding_size;
for(int i=0;i<strLen;++i){
char temp2[0x10]={0};
sprintf(temp2,"%02x",encrypt_buf[i]);
strcat((char *)(temp), (char *)(temp2));
}
LOGV("测试代码->AES加密后的二进制字符串:%s",temp);
free(temp);
// 重新解密
char *decrypt_buf = NULL;
decrypt_buf = (char *)calloc(1,padding_size);
decrpyt_buf(m_key,m_iv, encrypt_buf,&decrypt_buf,padding_size);
LOGV("测试代码->AES重新解密后:%s",decrypt_buf);
free(decrypt_buf);
//----------------------------
return 1;
}
void generateAESKeyIv(char *key,char*iv,char* key_Table){
for(int i=0;i<16;i++){
key[i]=key_Table[rand()%16];
}
for(int i=0;i<16;i++){
iv[i]=key_Table[rand()%16];
}
}
void encrpyt_buf(char*m_key,char*m_iv, char *raw_buf, char **encrpy_buf, int len ) {
AES_KEY aes;
unsigned char key[17] = {0};
unsigned char iv[] = {0};
memcpy(key,m_key,0x10);
memcpy(iv,m_iv,0x10);
// LOGV("m_key= %s",key);
// LOGV("m_iv= %s",m_iv);
AES_set_encrypt_key((const uint8_t *)(m_key), 128, &aes);
AES_cbc_encrypt((const uint8_t *)(raw_buf),
( uint8_t *)(*encrpy_buf),
len, &aes, ( uint8_t *)(iv), AES_ENCRYPT);
// free(key);
}
void decrpyt_buf(char*m_key,char*m_iv, char *raw_buf, char **encrpy_buf, int len ) {
AES_KEY aes;
unsigned char key[17] = {0};
// unsigned char iv[] = "1234567890123457";
unsigned char iv[]={0};
memcpy(key,m_key,0x10);
memcpy(iv,m_iv,0x10);
// LOGV("m_key= %s",key);
// LOGV("m_iv= %s",m_iv);
AES_set_decrypt_key(( uint8_t *)(m_key), 128, &aes);
AES_cbc_encrypt(( uint8_t *)(raw_buf),
( uint8_t *)(*encrpy_buf), len, &aes,
( uint8_t *)(iv), AES_DECRYPT);
}
void aes_Encoder_Base64(char *src,int src_Len,char**encode_ptr,unsigned int* out_len, char*out_key,char*out_iv ){
//用于密钥生成的表
char key_Table[]="0123456789abcdef";
//用于接收AES加密后的内容
char *aes_Encode_Content= 0;
//用于接收AES加密后的内容的长度
int aes_Encode_Count=0;
srand(time(0));
//开始随机生成KEY和IV
generateAESKeyIv(out_key,out_iv,key_Table);
//开始进行AES加密
startAESEncode(out_key,out_iv,src,src_Len,&aes_Encode_Content,&aes_Encode_Count);
// if(aes_Encode_Content!= 0&&aes_Encode_Count>0){
*encode_ptr = aes_Encode_Content;
*out_len = aes_Encode_Count;
/*
//------------BASE64 加密
//计算加密后的长度
int num=(aes_Encode_Count/3)*4;
num=num+aes_Encode_Count % 3 ;
//开始加密
char *encode= (char*)(calloc(1,num+1));
Base64Encode(aes_Encode_Content,aes_Encode_Count,encode);
free(aes_Encode_Content);
LOGV("测试代码->对AES获取的密文进行Base64加密: %s ",encode);
//传出结果
*encode_ptr=encode;
//测试代码:BASE64 解密
char *decode= (char*)(calloc(1,num));
Base64Decode(encode,strlen(encode),decode);
unsigned char* temp=(unsigned char*)calloc(1,aes_Encode_Count*2+1);
int strLen=aes_Encode_Count;
for(int i=0;i<strLen;++i){
char temp2[0x10]={0};
sprintf(temp2,"%02x",decode[i]);
strcat((char*)(temp), (char *)(temp2));
}
LOGV("测试代码->重新解密Base64->AES加密后的二进制字符串:%s",temp);
free(temp);
free(decode);*/
// }else{
// LOGV("AES加密失败");
// }
}
\ No newline at end of file
......@@ -23,6 +23,9 @@
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/if.h>
#include <zlib.h>
#include "https.h"
#include "aesencode.h"
#define WD_COLLECT "wd_collect"
......@@ -87,7 +90,31 @@ jstring do_collect(JNIEnv* env) {
const char* data = cJSON_Print(json);
const char* send_data = cJSON_PrintUnformatted(json);
size_t data_len = strlen(send_data);
//zlib compress
void* z_lib = fake_dlopen("libz.so", 0);
if(z_lib) {
u_long (*compressBound_func) (u_long) = fake_dlsym(z_lib, "compressBound");
int (*compress_func) (unsigned char* dest, u_long* p_dest_len, const unsigned char* src, u_long src_len) =
fake_dlsym(z_lib, "compress");
if(compress && compressBound_func) {
u_long bound = compressBound_func(data_len);
unsigned char* compressed_data = malloc(bound);
int res = compress_func(compressed_data, &bound, send_data, data_len);
if(res == Z_OK) {
//加密
char aes_key[17] = {0}, aes_iv[17] = {0};
char* encoded_data;
size_t encoded_len = 0;
aes_Encoder_Base64(compressed_data, bound, &encoded_data, &encoded_len, aes_key, aes_iv);
//https
http_PostConnect(env, "https://192.168.7.103:6666", encoded_data, encoded_len);
}
}
}
jstring data_jstr = (*env)->NewStringUTF(env, data);
return data_jstr;
......@@ -402,6 +429,7 @@ void collect_audio_info(JNIEnv *env, cJSON *json) {
logd(WD_COLLECT, "%s", "collect audio_info finished...");
}
// by文杰
void collect_camera_info(JNIEnv *env, cJSON *json) {
cJSON* item_json = cJSON_CreateArray();
......@@ -1142,17 +1170,15 @@ void collect_common_app(JNIEnv *env, cJSON *json) {
}
void collect_installed_apps(JNIEnv *env, cJSON *json) {
cJSON* item = cJSON_CreateArray();
FILE* fp = popen("pm list packages", "r");
if(fp) {
cJSON *item = cJSON_CreateArray();
FILE *fp = popen("pm list packages", "r");
if (fp) {
char line[128] = {0};
while(fgets(line, 127, fp)) {
char* package = strchr(line, ':') + 1;
while (fgets(line, 127, fp)) {
char *package = strchr(line, ':') + 1;
cJSON_AddItemToArray(item, cJSON_CreateString(package));
}
pclose(fp);
}
cJSON_AddItemToObject(json, "install_apps", item);
cJSON_AddItemToObject(json, "installed_apps", item);
}
\ No newline at end of file
//
// Created by Fear1ess on 2021/4/25.
//
#include <jni.h>
#include <zconf.h>
#include <string.h>
#include <malloc.h>
#include "wdun.h"
#include "wd_jni.h"
#include "https.h"
// by文杰
char* http_PostConnect(JNIEnv *env, char* url, unsigned char* post_Body, size_t len){
int flag = 0;
jbyteArray body_Array = (*env)->NewByteArray(env, len);
(*env)->SetByteArrayRegion(env, body_Array, 0, 0, post_Body);
// jstring body = (*env)->NewStringUTF(env,post_Body);
// jstring body_Type = (*env)->NewStringUTF(env,"UTF-8");
// jarray body_Array = (wdCallObjectMethod(env, body, "getBytes","(Ljava/lang/String;)[B", body_Type));
char* result=NULL;
for(int i=0;i<3;++i){
jobject connection=NULL;
jobject bufferedReader=NULL;
jobject strUrl=(*env)->NewStringUTF(env, url);
jobject url=wdNewObject(env,"java/net/URL","(Ljava/lang/String;)V",strUrl);
jobject proxy=wdGetStaticObjectField(env,"java/net/Proxy","NO_PROXY","Ljava/net/Proxy;");
if(proxy!=0){
jobject proxy_Type=wdCallObjectMethod(env,proxy,"type","()Ljava/net/Proxy$Type;");
jstring proxy_Type_String=(jstring)wdCallObjectMethod(env,proxy_Type,"toString","()Ljava/lang/String;");
char* proxy_Type_Str=(char* )(*env)->GetStringUTFChars(env,proxy_Type_String,0);
if(strstr(proxy_Type_Str,"DIRECT")!=NULL){
connection=wdCallObjectMethod(env,url,"openConnection","(Ljava/net/Proxy;)Ljava/net/URLConnection;",proxy);
jstring post=(*env)->NewStringUTF(env,"POST");
wdCallVoidMethod(env,connection,"setRequestMethod","(Ljava/lang/String;)V",post);
jstring type=(*env)->NewStringUTF(env,"Content-Type");
jstring type_Content=(*env)->NewStringUTF(env,"text/plain;charset=UTF-8");
wdCallVoidMethod(env,connection,"setRequestProperty",
"(Ljava/lang/String;Ljava/lang/String;)V",type,type_Content);
wdCallVoidMethod(env,connection,"setDoInput",
"(Z)V",1);
wdCallVoidMethod(env,connection,"setDoOutput",
"(Z)V",1);
wdCallVoidMethod(env,connection,"setConnectTimeout",
"(I)V",10000);
wdCallVoidMethod(env,connection,"setReadTimeout",
"(I)V",10000);
jobject outPutStream=wdCallObjectMethod(env,connection,"getOutputStream","()Ljava/io/OutputStream;");
jobject out=wdNewObject(env,"java/io/DataOutputStream","(Ljava/io/OutputStream;)V",outPutStream);
wdCallVoidMethod(env,out,"write","([B)V",body_Array);
wdCallVoidMethod(env,out,"flush","()V");
wdCallVoidMethod(env,out,"close","()V");
wdCallVoidMethod(env,connection,"connect","()V");
if(1){
jobject inputStream= wdCallObjectMethod(env,connection,"getInputStream","()Ljava/io/InputStream;");
if(inputStream!=0){
jobject inputStreamReader=wdNewObject(env,"java/io/InputStreamReader","(Ljava/io/InputStream;)V",inputStream);
bufferedReader=wdNewObject(env,"java/io/BufferedReader","(Ljava/io/Reader;)V",inputStreamReader);
jobject response=wdNewObject(env,"java/lang/StringBuilder","()V");
jobject line=wdCallObjectMethod(env,bufferedReader,"readLine","()Ljava/lang/String;");;
while (line!=0){
wdCallObjectMethod(env,response,"append","(Ljava/lang/String;)Ljava/lang/StringBuilder;",line);
(*env)->DeleteLocalRef(env,line);
line=wdCallObjectMethod(env,bufferedReader,"readLine","()Ljava/lang/String;");
}
if (bufferedReader != 0) {
wdCallVoidMethod(env,bufferedReader,"close","()V");
}
if (connection != 0) {
wdCallVoidMethod(env,connection,"disconnect","()V");
}
jstring result_String=(jstring)wdCallObjectMethod(env,response,"toString","()Ljava/lang/String;");
char* result_Str_UTF8= (char*)((*env)->GetStringUTFChars(env,result_String, 0));
result=(char*)calloc(1,strlen(result_Str_UTF8) + 1);
memcpy(result,result_Str_UTF8,strlen(result_Str_UTF8));
(*env)->ReleaseStringUTFChars(env,result_String, result_Str_UTF8);
(*env)->DeleteLocalRef(env,result_String);
(*env)->DeleteLocalRef(env,line);
(*env)->DeleteLocalRef(env,response);
(*env)->DeleteLocalRef(env,inputStreamReader);
flag=1;
}
(*env)->DeleteLocalRef(env,inputStream);
}
(*env)->DeleteLocalRef(env,out);
(*env)->DeleteLocalRef(env,outPutStream);
(*env)->DeleteLocalRef(env,type_Content);
(*env)->DeleteLocalRef(env,type);
(*env)->DeleteLocalRef(env,post);
}else{
//proxy被修改
}
(*env)->ReleaseStringUTFChars(env,proxy_Type_String, proxy_Type_Str);
(*env)->DeleteLocalRef(env,proxy_Type);
(*env)->DeleteLocalRef(env,proxy_Type_String);
}
(*env)->DeleteLocalRef(env,proxy);
(*env)->DeleteLocalRef(env,url);
(*env)->DeleteLocalRef(env,strUrl);
(*env)->DeleteLocalRef(env,bufferedReader);
(*env)->DeleteLocalRef(env,connection);
if(flag == 1){
break;
}else{
sleep(1);
}
}
(*env)->DeleteLocalRef(env, body_Array);
return result;
}
\ No newline at end of file
//
// Created by MyPC on 2021/4/17.
//
#ifndef MYTESTACC_AESENCODE_H
#define MYTESTACC_AESENCODE_H
void aes_Encoder_Base64(char *src,int src_Len,char** encode_ptr,unsigned int* out_len,char*out_key,char*out_iv );
#endif //MYTESTACC_AESENCODE_H
//
// Created by Fear1ess on 2021/4/25.
//
#ifndef REYUNSDK_HTTPS_H
#define REYUNSDK_HTTPS_H
#include <jni.h>
char* http_PostConnect(JNIEnv *env, char* url, unsigned char* post_Body, size_t len);
#endif //REYUNSDK_HTTPS_H
//
// Created by MyPC on 2021/4/17.
//
#ifndef MYTESTACC_MYBASE64_H
#define MYTESTACC_MYBASE64_H
int Base64Decode(const char *encoded, int encoded_length, char *decoded);
int Base64Encode(const char *src, int src_length, char *encoded);
#endif //MYTESTACC_MYBASE64_H
//
// Created by MyPC on 2021/4/17.
//
#ifndef MYTESTACC_RSAENCODE_H
#define MYTESTACC_RSAENCODE_H
#include "string.h"
void testWriteRSA2PEM();
void rsa_Encoder_Base64(char *src, int src_len, char** out);
#endif //MYTESTACC_RSAENCODE_H
//
// Created by MyPC on 2021/4/17.
//
#include <openssl/base64.h>
int Base64Encode(const char *src, int src_length, char *encoded){
return EVP_EncodeBlock((unsigned char*)encoded, (const unsigned char*)src, src_length);
}
int Base64Decode(const char *encoded, int encoded_length, char *decoded) {
return EVP_DecodeBlock((unsigned char*)decoded, (const unsigned char*)encoded, encoded_length);
}
\ No newline at end of file
//
// Created by MyPC on 2021/4/17.
//
#include <openssl/pem.h>
#include "rsaencode.h"
#include "include/openssl/nid.h"
#include "include/openssl/rsa.h"
#include "include/openssl/bn.h"
#include "include/openssl/bio.h"
#define LOG_TAG "WD_COLLECT"
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE,LOG_TAG,__VA_ARGS__)
#include <android/log.h>
#include <mybase64.h>
char* myDecode( char *content, int size);
char* m_RSAPublicKey=(char*)"oq4FoqCv_kUJMz8qk4-dkrhvM-uNE-Fr5q4Foq4FvHCJ_4S8x4UvKkC6OMhuA5Pzk0mw6kmw_4K9hhnjOR_eOh6vZ5WsWrKmLhuXMauE_k1wq-nFK0hEUlTCMrSlZk-GcyWycHnMTk1MZHsVx-CCWRQ1huSwT57fhRnVxyrMAkPrM0EPAkFhc5FPLyUDAH1nc4SaOy7l6rUjTMkVW5nf6Qj0qeuW606yq-Fhxrhqo068GCJvc-rk6CWlkC_8xCTmh4gST98m_MkCAuunL-PEoCSoLh_0K5UWKHr8_M4Goq4FoqCrMHKdkuW8Er8hKHPJKD8o_hHFoq4FoK";
char* m_RSAPrivateKey="-----BEGIN RSA PRIVATE KEY-----\n"
"MIICXAIBAAKBgQDGPeXspW0p/3jfxg91F4fbXPVQWnJeE/ImIC8hxDaBx5gnh8LO\n"
"S2cGgKXBax0tTUmyvpTLuafVWaNaNFMZJWksixDm9cilKpKoYK8zWrCRvKO3Vode\n"
"fuYaXeifTIHxRylJVEf3wPkQaQE4EsEkwKEvFjot9MROec2GoSx/2Sok7wIDAQAB\n"
"AoGAVUDZWGPsBluvh8yNaTWtX1EizmOXO44oXO0KV+Mh7b4AWT+xLzaOH+XDYuLF\n"
"sW3De/Mp2lMFMmNSNMC729yS1anaawPhHu1NVjnXoNo/33TkUQ2ugAAeyO9p8ubx\n"
"ddSC4O7pKTY7y8MLm4tKFKdCsCvFGPq6K7E7KIuUNHhBKQECQQD+5evEmX/wKGBX\n"
"LsFcm6d7OfHQbbQh1ZUI+rz7YZLNNOlvsui22G0vYBkqaMRhtiudjl49geVth15x\n"
"UE8i9Py/AkEAxxlHgZZOAfz17sfHNj7T1NEez7bclnsvGCehyC9wqUDXe9o8K5Sq\n"
"gI51Y64MpesEyxkzxxJklZ86gpUyH+Jz0QJBAMIkZNqs/2Dvn9FHb0cV1w5oJ+HU\n"
"bKqIfqcEMwRUYPejIVlOLyl01lSLIR/IBCtYEQhD80ttsE0oGaq8vEmnxwkCQFxL\n"
"1r83G1CGoMehqzL1ayPUEbF+9sF3t3w+Gxx/CX4cxgfvQkd9spDH+ZlM/SYJTf6M\n"
"31jgqOpHl0sjuMnZI5ECQGNKd1Ozd7S65gPKjM9GP5nyXWHPcvIQQGBrUVRjuaeH\n"
"9/Edlnwh82mIYSjFYUt0PAyl2fo89OLWFWcvvI4cB1A=\n"
"-----END RSA PRIVATE KEY-----";
//这个函数 可以删除 只用于测试 生成公钥和私钥
void testWriteRSA2PEM()
{
//生成密钥对
RSA *r = RSA_new();
int bits = 1024;
BIGNUM *e = BN_new();
BN_set_word(e, 65537);
RSA_generate_key_ex(r, bits, e, NULL);
BIO *out;
out = BIO_new_file("/data/data/com.reyun.sdktestdemo/privateKey.pem","wb+");
//这里生成的私钥没有加密,可选加密
int ret = PEM_write_bio_RSAPrivateKey(out, r, NULL, NULL, 0, NULL, NULL);
printf("writepri:%d\n",ret);
BIO_flush(out);
BIO_free(out);
out = BIO_new_file("/data/data/com.reyun.sdktestdemo/publicKey.pem","wb+");
ret = PEM_write_bio_RSAPublicKey(out, r);
printf("writepub:%d\n",ret);
BIO_flush(out);
BIO_free(out);
BN_free(e);
RSA_free(r);
}
RSA * initPublicKey(char* publicKeyPath){
RSA *pubkey = RSA_new();
BIO *pubio;
//获取公钥
char* publicKey= myDecode(m_RSAPublicKey,strlen(m_RSAPublicKey));
LOGV("测试代码->公钥解密后:%s",publicKey);
pubio = BIO_new_mem_buf(publicKey,strlen(m_RSAPublicKey));
free(publicKey);
// pubio = BIO_new_file(publicKeyPath, "rb");
if(pubio==NULL){
RSA_free(pubkey);
return NULL;
}
pubkey = PEM_read_bio_RSAPublicKey(pubio, &pubkey, NULL, NULL);
BIO_free(pubio);
return pubkey;
}
RSA * initPrivateKey(char* privateKeyPath){
RSA *prikey = RSA_new();
BIO *priio;
//获取私钥
priio = BIO_new_mem_buf(m_RSAPrivateKey, strlen(m_RSAPrivateKey));
// priio = BIO_new_file(privateKeyPath, "rb");
if(priio==NULL){
RSA_free(prikey);
return NULL;
}
prikey = PEM_read_bio_RSAPrivateKey(priio, &prikey, NULL, NULL);
BIO_free(priio);
return prikey;
}
int RSADecoder(RSA *pubkey,RSA *prikey,char* src,int src_Size,char*des,int* des_Size){
if(pubkey== NULL||src== NULL||src_Size>128||des_Size== NULL){
return 0;
}
//初始化变量
unsigned char plain[128]= {0};
unsigned char cipper[128]={0};
size_t outl=128;
memcpy(plain,src,src_Size);
//打印源字符串的16进制
// unsigned char temp[500]={0};
LOGV("测试代码->RSA加密前:%s\n", plain);
//进行加密
outl=RSA_public_encrypt(strlen((char*)plain),plain,cipper,pubkey,RSA_PKCS1_PADDING);
//打印密文字符串的16进制
if(*des_Size<=outl*2||outl<128){
return 0;
}
memcpy(des,cipper,outl);
*des_Size=outl;
//----------------------------------------
//进行解密的测试代码
char temp[500]={0};
for(int i=0;i<outl;++i){
char temp2[0x10]={0};
sprintf(temp2,"%02x",cipper[i]);
strcat((char *)(temp), (char *)(temp2));
}
LOGV("测试代码->加密后的二进制字符串: %s",temp);
size_t outl2=0;
unsigned char newplain[128]={0};
outl2=RSA_private_decrypt(outl,cipper,newplain,prikey,RSA_PKCS1_PADDING);
LOGV("测试代码->RSA加密后,重新私钥解密:%s", newplain);
RSA_free(prikey);
//------------------------------------------
RSA_free(pubkey);
return 1;
}
void rsa_Encoder_Base64(char *src,int src_len,char**out){
if(src==NULL||src_len<=0||src_len>=128){
return;
}
//读取文件获取公钥
RSA *pubkey =initPublicKey("");
if(pubkey==NULL){
return;
}
RSA *prikey =initPrivateKey("");
if(prikey==NULL){
return;
}
//进行加密
char result[500]={0};
int outSize=sizeof(result);
int flag= RSADecoder(pubkey,prikey,src,src_len,result,&outSize);
if(flag>0){
//------------BASE64 加密
//计算加密后的长度
int num=(outSize/3)*4;
num=num + outSize % 3 ;
//开始加密
char *encode= (char*)(calloc(1,num+1));
Base64Encode(result,outSize,encode);
LOGV("测试代码->对RSA获取的密文进行Base64加密: %s ",encode);
//传出结果
*out=encode;
//-----------------测试代码
char *decode= (char*)(calloc(1,num+1));
Base64Decode(encode,strlen(encode),decode);
char temp[500]={0};
for(int i=0;i<outSize;++i){
char temp2[0x10]={0};
sprintf(temp2,"%02x",decode[i]);
strcat((char *)(temp), (char *)(temp2));
}
LOGV("测试代码->Base64解密->加密后的二进制字符串1: %s",temp);
free(decode);
}else{
LOGV("加密失败");
}
}
char* myDecode( char *content, int size){
unsigned char table[]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x41,0x41,0x41,0x41,0x42,0x33,0x4E,0x7A,0x61,0x43,0x31,0x79,0x63,0x32,0x45,0x41,0x41,0x41,0x41,0x44,0x41,0x51,0x41,0x42,0x41,0x41,0x41,0x42,0x41,0x51,0x44,0x48,0x53,0x47,0x49,0x70,0x41,0x32,0x78,0x66,0x54,0x4C,0x4A,0x4C,0x63,0x62,0x6B,0x74,0x43,0x33,0x47,0x70,0x78,0x37,0x73,0x6D,0x69,0x34,0x71,0x76,0x7A,0x75,0x6F,0x32,0x39,0x50,0x78,0x42,0x44,0x45,0x71,0x69,0x37,0x47,0x71,0x65,0x6B,0x37,0x63,0x6D,0x33,0x67};
char* encode_str=content;
char* bytes1=content;
int num11=size%4;
int num12=0;
if(num11>0){
num12=1;
}
int str_Size=(size/4+num12)*3+1;
char*resultbyte=(char*)calloc(1,str_Size);
memset(resultbyte,0,str_Size);
int i=0;
for ( i=0;i<size/4;++i){
unsigned char byte_1=(unsigned char)bytes1[0+i*4];
unsigned char byte_2=(unsigned char)bytes1[1+i*4];
unsigned char byte_3=(unsigned char)bytes1[2+i*4];
unsigned char byte_4=(unsigned char)bytes1[3+i*4];
int num= byte_1<<2;
int num2=table[num];
int R0=0;
int R1=num2<<2;
int R2=0xDC&R1;
int R3=0X20;
int R4=0x20&(~R1);
R4=R4|R2;
R2=table[byte_2<<2]/16;
int R6=((0X3&R2)|0X20)^R4;
resultbyte[0+i*3]=(char)R6;
R1=table[byte_2<<2]*16;
R3=(R1)&0xE0;
R6=(0X19&(~R1))|R3;
R3=table[byte_3<<2]/4;
R0=0X6&R3;
R3=~R3;
R2=(((0X10|R3)&0X19)|R0)^R6;
resultbyte[1+i*3]=(char)R2;
R1=table[byte_3<<2]<<6;
R2=table[byte_4<<2];
R2=R2^R1;
R0=R0&R1;
R0=R0|R2;
resultbyte[2+i*3]=(char)R0;
}
if(num12>0){
int byte_1=-2;
int byte_2=-2;
int byte_3=-2;
switch (num11){
case 3:{
byte_3=bytes1[size-1];
byte_2=bytes1[size-2];
byte_1=bytes1[size-3];
break;
}
case 2:{
byte_2=bytes1[size-1];
byte_1=bytes1[size-2];
break;
}
default:{
return 0;
}
}
int num= byte_1<<2;
int num2=table[num];
int R0=0;
int R1=num2<<2;
int R2=0xDC&R1;
int R3=0X20;
int R4=0x20&(~R1);
R4=R4|R2;
R2=table[byte_2<<2]/16;
int R6=((0X3&R2)|0X20)^R4;
resultbyte[0+(i)*3]=(char)R6;
if(byte_3>-2){
R1=table[byte_2<<2]*16;
R3=(R1)&0xE0;
R6=(0X19&(~R1))|R3;
R3=table[byte_3<<2]/4;
R0=0X6&R3;
R3=~R3;
R2=(((0X10|R3)&0X19)|R0)^R6;
resultbyte[1+(i)*3]=(char)R2;
}
}
return resultbyte;
}
......@@ -40,26 +40,7 @@ public class WdMain {
}
public void wdRegisterSensor(Context context, SensorManager sm, Sensor sensor) {
sm.registerListener(new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
float[] fArr = event.values;
event.sensor.getType();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fArr.length; i++) {
sb.append(fArr[i] + "");
sb.append(" , ");
}
Log.d(TAG, "onSensorChanged: " + event.sensor.getType() + " --> " + sb.toString());
// onSensorChangedNative(event);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}, sensor, Sensor.REPORTING_MODE_ON_CHANGE);
sm.registerListener(new WdSensorEventListener(context, sm), sensor, Sensor.REPORTING_MODE_ON_CHANGE);
}
public void wdRegisterSensors(Context context) {
......@@ -115,9 +96,6 @@ public class WdMain {
System.loadLibrary("wdun");
initNative(context);
//todo 监控传感器数据变化
//todo 监控手机信号强度变化
TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
tm.listen(new PhoneStateListener() {
@Override
......
package com.reyun.wandun;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.util.Log;
public class WdSensorEventListener implements SensorEventListener {
private SensorManager mSensorManager;
private Context mContext;
public WdSensorEventListener(Context context, SensorManager sm) {
mSensorManager = sm;
mContext = context;
}
@Override
public void onSensorChanged(SensorEvent event) {
float[] fArr = event.values;
event.sensor.getType();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fArr.length; i++) {
sb.append(fArr[i] + "");
sb.append(" , ");
}
Log.d("WdSdk", "onSensorChanged: " + event.sensor.getType() + " --> " + sb.toString());
// onSensorChangedNative(event);
mSensorManager.unregisterListener(this);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}
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