本文为看雪论坛优秀文章
看雪论坛作者ID:xwtwho
一
软硬件环境
二
坑(时间顺序)
之前就看到有使用Cronet模块,想看下实现过程,下过源码(https://github.com/hanpfei/chromium-net),一个是发现跟app使用的并不完全相同,再一个还要自己编译模块,就想到直接使用抖音的模块。
com.ttnet.org.chromium.net
if (!StringsKt.contains$default((CharSequence) name, (CharSequence) "__MACOSX", false, 2, (Object) null)) {StringsKt.contains((CharSequence) str, (CharSequence) "?", false))
public final class FrontMethodFragment$onCreateFailed$1 extends Lambda implements Function0<Unit> {Lambda要带上Lambda<Unit>// 初始化引擎CronetEngine.Builder myBuilder = new CronetEngine.Builder(getApplicationContext());CronetEngine cronetEngine = myBuilder.build();// 创建请求线程Executor executor = Executors.newSingleThreadExecutor();// 创建UrlRequeststrUrl="http://10.0.0.217/about";UrlRequest.Builder requestBuilder = cronetEngine.newUrlRequestBuilder(strUrl, new MyUrlRequestCallback(), executor);requestBuilder.addHeader("testHeader","testValue");UrlRequest request = requestBuilder.build();// 发起请求request.start();
class MyUrlRequestCallback extends UrlRequest.Callback {private static final String TAG = "ttttt MyUrlRequestCallback";@Overridepublic void onRedirectReceived(UrlRequest request, UrlResponseInfo info, String newLocationUrl) {android.util.Log.i(TAG, "onRedirectReceived method called.");// You should call the request.followRedirect() method to continue// processing the request.request.followRedirect();}@Overridepublic void onResponseStarted(UrlRequest request, UrlResponseInfo info) {//这个函数只会调用一次android.util.Log.i(TAG, "onResponseStarted method called.");// You should call the request.read() method before the request can be// further processed. The following instruction provides a ByteBuffer object// with a capacity of 102400 bytes to the read() method.request.read(ByteBuffer.allocateDirect(102400));}@Overridepublic void onFailed(UrlRequest urlRequest, UrlResponseInfo urlResponseInfo, CronetException cronetException) {}@Overridepublic void onReadCompleted(UrlRequest request, UrlResponseInfo info, ByteBuffer byteBuffer) {//这个会调用多次android.util.Log.i(TAG, "onReadCompleted method called.");// You should keep reading the request until there's no more data.request.read(ByteBuffer.allocateDirect(102400));}@Overridepublic void onSucceeded(UrlRequest request, UrlResponseInfo info, String str) {android.util.Log.i(TAG, "onSucceeded method called.");}}
// Certificate is not trusted due to non-trusted root of the certificate// chain.static int NO_TRUSTED_ROOT = -2;
private <T> T getStaticServiceImplReal(Class<T> cls) {PatchProxyResult proxy = PatchProxy.proxy(new Object[]{cls}, this, changeQuickRedirect, false, 95671);if (proxy.isSupported) {return (T) proxy.result;}int iHashCode=cls.getName().hashCode();switch (iHashCode) {
FeedActionApi.f71204b.diggItem("7018000130007633191", "7018000130007633191", 1, 0).get();if (C9859c.m21219a()) {jSONObject.put("netClientType", "CronetClient");} else {jSONObject.put("netClientType", "TTOkhttp3Client");}
三
学习总结
1、学习了JAV代理类使用,大厂设计模式。
2、熟悉了Cronet模块。
看雪ID:xwtwho
https://bbs.pediy.com/user-home-44250.htm
# 往期推荐
1.Chrom V8分析入门——Google CTF2018 justintime分析
4.人人都可以拯救正版硬件受害者(Jlink提示Clone)
球分享
球点赞
球在看
点击“阅读原文”,了解更多!