Skip to content

Commit 45ad47a

Browse files
author
eggizhang
committed
work around x86 crash see issue
1 parent 9208f0d commit 45ad47a

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

Android/liteapp/src/main/java/com/iqiyi/halberd/liteapp/export/DefaultFunctionProvider.java

+16
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.iqiyi.halberd.liteapp.event.IBridgeEventListener;
3333
import com.iqiyi.halberd.liteapp.event.impl.EventBridgeImpl;
3434
import com.iqiyi.halberd.liteapp.plugin.network.impl.LiteAppNetworkRequest;
35+
import com.iqiyi.halberd.liteapp.utils.MD5Utils;
3536
import com.iqiyi.halberd.liteapp.view.LiteAppBaseActivity;
3637

3738
import org.json.JSONException;
@@ -282,5 +283,20 @@ protected long onCalled(NativeObjectRef[] callbackHandles, String[] parameters){
282283
};
283284
ExecutorManager.addObjectToObject(context, base, "start", pageRouter);
284285

286+
//using this md5 utils will work around x86 crash on javascript md5
287+
final JsObject md5 = new JsObject() {
288+
protected long onCalled(NativeObjectRef[] callbackHandles, String[] parameters) {
289+
if(TextUtils.isEmpty(parameters[0])) {
290+
return 0;
291+
} else if(callbackHandles.length < 2) {
292+
return 0;
293+
} else {
294+
String mdResult = MD5Utils.md5(parameters[0]);
295+
ExecutorManager.callNativeRefFunction(context, callbackHandles[1], mdResult);
296+
}
297+
return 0;
298+
}
299+
};
300+
ExecutorManager.addObjectToGlobal(context, "mi_pad__md5__", md5);
285301
}
286302
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.iqiyi.halberd.liteapp.utils;
2+
3+
import java.security.MessageDigest;
4+
import java.security.NoSuchAlgorithmException;
5+
6+
/**
7+
* Created by eggizhang on 18-6-19.
8+
* using this utils to make md5 string for x86 crash bugs
9+
*/
10+
11+
public class MD5Utils {
12+
public static String md5(final String s) {
13+
final String MD5 = "MD5";
14+
try {
15+
// Create MD5 Hash
16+
MessageDigest digest = java.security.MessageDigest
17+
.getInstance(MD5);
18+
digest.update(s.getBytes());
19+
byte messageDigest[] = digest.digest();
20+
21+
// Create Hex String
22+
StringBuilder hexString = new StringBuilder();
23+
for (byte aMessageDigest : messageDigest) {
24+
StringBuilder h = new StringBuilder(Integer.toHexString(0xFF & aMessageDigest));
25+
while (h.length() < 2)
26+
h.insert(0, "0");
27+
hexString.append(h);
28+
}
29+
return hexString.toString();
30+
31+
} catch (NoSuchAlgorithmException e) {
32+
e.printStackTrace();
33+
}
34+
return "";
35+
}
36+
}

0 commit comments

Comments
 (0)