[C] 纯文本查看 复制代码
JNIEXPORT jstring JNICALL Java_net_iaround_utils_NativeLibUtil_aaa
(JNIEnv *env, jobject ob, jobject paramContext, jobject paramPackageInfo, jstring paramString1, jstring paramString2)
{
SHA1Context context;
jstring ret=0;
JNIEnv* p_env=env;
char cifferbuf[128]={0};
char buf[64]={0};
jclass obClass=env->GetObjectClass(ob);
char *pString="()Ljava/lang/String;";
jmethodID reusltID=p_env->GetMethodID(obClass,"getPackageName","()Ljava/lang/String;");
jobject retObject=p_env->CallObjectMethod(paramContext,reusltID);
jboolean boolean=0;
const char *str=p_env->GetStringUTFChars((jstring)retObject,&boolean);
bool cmpResult=strcmp("net.iaround",str);
if(cmpResult==0)
{
ret=p_env->NewStringUTF("123456");
}
else
{
char destBuffer[128]={0};
const char* s1=p_env->GetStringUTFChars(paramString1,&boolean);
const char *s2=p_env->GetStringUTFChars(paramString2,&boolean);
__android_log_print(4, "logfromc", "%s",s1);
__android_log_print(4, "logfromc", "%s",s2);
int len1=strlen(s1);
int len2=strlen(s2);
memcpy(destBuffer,s1,len1);
memcpy(destBuffer+len1,s2,len2);
jclass packageInfo= p_env->GetObjectClass(paramPackageInfo);
ret=(jstring)packageInfo;
if(packageInfo)
{
jfieldID signatures=p_env->GetFieldID(packageInfo,"signatures","[Landroid/content/pm/Signature;");
ret=(jstring)signatures;
if(signatures)
{
jobjectArray sigarray=(jobjectArray)p_env->GetObjectField(paramPackageInfo,signatures);
if(sigarray)
{
jsize sigLength=p_env->GetArrayLength(sigarray);
if(sigLength>0)
{
jobject ob=p_env->GetObjectArrayElement(sigarray,0);
if(ob)
{
jclass jc=p_env->GetObjectClass(ob);
if(jc)
{
jmethodID id=p_env->GetMethodID(jc,"toCharsString","()Ljava/lang/String;");
if(id)
{
jstring sigString =(jstring)p_env->CallObjectMethod(ob,id);
const char* sigStr=p_env->GetStringUTFChars(sigString,&boolean);
int passLen=strlen(destBuffer);
memcpy(cifferbuf,sigStr+16,32);
//__android_log_print(4, "logfromc", "%s",sigStr+16);
//memcpy(cifferbuf,"a00302010202044e549d3a300d06092a",32);
memcpy(cifferbuf+32,destBuffer,passLen);
__android_log_print(4, "logfromc", "cifferString:%s",cifferbuf);
SHA1Reset(&context);
int cifferlen=strlen(cifferbuf);
SHA1Input(&context,cifferbuf,cifferlen);
//memset(&v51, 48, 0x29u);
memset(buf,0,sizeof(buf));
if(SHA1Result(&context))
{
sprintf(buf, "%08X%08X%08X%08X%08X", context.Message_Digest[0],context.Message_Digest[1],
context.Message_Digest[2],context.Message_Digest[3],context.Message_Digest[4]);
}
else
{
__android_log_print(4, "logfromc", "ERROR-- could not compute message digest\n");
}
ret=p_env->NewStringUTF(buf);
}
}
}
}
}
}
}
}
return ret;
}