Android逆向之路---让我们试试另一种方法看漫画-(2)

前言

上次我们分析到了快看漫画的协议部分,这次我们根据他的协议来手动写个脚本,然后执行以后,可以把他的漫画自动下载到电脑上面,
然后自动拼接图片,这样就可以实现在电脑上当成一个长图来看漫画了,没有广告,没有app的一些限制,先上图,一起看看成果

本文分析基于:快看漫画5.2.0(52000)
事先说明,这是一个系列,关于快看漫画的系列,不过在今天写看漫画这个系列的时候,博主后面的工作也还没有做呢,也希望在大家的监督之下一点一点的全部完成吧。
ps:避免广告嫌疑,以下统称kk漫画了。

为什么选择这个app?
排名靠前啊,反正就选到了,
有对别的感兴趣的同学也欢迎投稿,博主会尽自己所能,给大家带来点好玩的。

觉得看好多地方比较突然的,可以先转到上一篇,然后再来看这篇文章。
传送门:Android逆向之路—让我们试试另一种方法看漫画-(1)

找到正确的协议

上次我们找到了了协议的大概位置,这次我们要针对整个请求的过程进行精准的分析。包括每个接口的作用。
首先把log清空,然后点击他的开始阅读,我抓到了以下log
我以漫画:《李泰和方小甜的平行世界》为例子

经过我的分析,先和大家说结果:
1,4主要就是请求漫画的接口了
3,6主要是请求了一些广告信息
7可以理解为上传一些打点数据
2主要是获取了一些评论回复信息
5可能是和一些社交相关的,这个是我猜的

首先根据Log信息,我们能发现这些接口的作用,当然了,博主还有另一种办法,我们根据这些接口信息,依次的去找源码

源码分析

先分析

https://api.kkmh.com/v2/comic/22535?is_preview=0

我在源码里面搜v2/comic/,为什么这么搜,因为真正有开发经验的人是知道的,后面的一般开发的时候会写成可变的参数,
前面的url一般也是,我们开发的时候会有测试服务器和正式服务器,前面的是会变的,
搜索结果如下:

.method public abstract getComicDetail(JI)Lretrofit2/Call;
    .param p1    # J
        .annotation runtime Lretrofit2/http/Path;
            value = "comic_id"
        .end annotation
    .end param
    .param p3    # I
        .annotation runtime Lretrofit2/http/Query;
            value = "is_preview"
        .end annotation
    .end param
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(JI)",
            "Lretrofit2/Call",
            "<",
            "Lcom/kuaikan/comic/rest/model/API/ComicDetailResponse;",
            ">;"
        }
    .end annotation

    .annotation runtime Lretrofit2/http/GET;
        value = "/v2/comic/{comic_id}"
    .end annotation
.end method

怎么样,这个看着太费劲了,我还是手动转成java来看

@GET("/v2/comic/{comic_id}")
@Query("is_preview")
@Path("comic_id")
public abstract Call.retrofit2 getComicDetail();

根据方法名字其实就已经可以猜的可以了,然后利用动态调试,我们可以在APIRestClient.smali里面调用的地方打好断点,
(具体的动态调试方法,以前也说过,不熟悉的同学可以去翻我以前的文章)

    const/4 v0, 0x1

    :goto_0
    invoke-interface {v1, p1, p2, v0}, Lcom/kuaikan/comic/rest/SignInterface;->getComicDetail(JI)Lretrofit2/Call;

    move-result-object v0

    invoke-interface {v0, p4}, Lretrofit2/Call;->enqueue(Lretrofit2/Callback;)V

    .line 202
    return-void

然后我们能够看出来,这个主要就是利用retrofit框架,来进行网络请求。

开始分析协议

首先通过log,或者动态调试我们已经拿到他请求回来的json数据了

{"code":200,"data":{"comment_view_message":"吐槽神马的尽管来","can_view":true,"cover_image_url":"http://f2.kkmh.com/image/170310/hi585uspn.webp-w640","created_at":1467150603,"recommend":{"recommend_list":[{"male_vertical_image_url":"http://f2.kkmh.com/image/171213/rt79rf2bj.webp-w320.w","vertical_image_url":"http://f2.kkmh.com/image/171213/rt79rf2bj.webp-w320.w","recommend_tag":["奇幻","剧情"],"topic_id":544,"recommend_source":"AI推荐","title":"整容游戏"},{"male_vertical_image_url":"http://f2.kkmh.com/image/171212/rl5z4ftks.webp-w320.w","vertical_image_url":"http://f2.kkmh.com/image/171212/rl5z4ftks.webp-w320.w","recommend_tag":["都市"],"topic_id":782,"recommend_source":"AI推荐","title":"密会"},{"male_vertical_image_url":"http://f2.kkmh.com/image/161220/7tsm5zh6g.webp-w320.w","vertical_image_url":"http://f2.kkmh.com/image/161220/7tsm5zh6g.webp-w320.w","recommend_tag":["灵异"],"topic_id":786,"recommend_source":"AI推荐","title":"百怪夜谭"}],"title":"猜你喜欢"},"is_favourite":false,"title":"第1话 爱的供养","widgets":[],"recommend_count":0,"updated_at":1489143638,"selling_kk_currency":0,"zoomable":1,"push_flag":0,"previous_comic_id":null,"share":{"award":false,"activity_id":null,"show_draw_record":false,"title":""},"customized_share":[{"description":"短篇合集,讲述一场自来水污染导致人类出现的奇奇怪怪的疾病。细思极恐,高能慎入!看作者的脑洞能有多大!【授权/每周五更新 责编:拉面】","share_platform":4,"title":"好看哭!《李泰和方小甜的平行世界》这个漫画太优秀了!","picture":"http://f2.kkmh.com/image/170310/hi585uspn.webp-w640","url":"https://m.kuaikanmanhua.com/comics/22535"},{"description":"短篇合集,讲述一场自来水污染导致人类出现的奇奇怪怪的疾病。细思极恐,高能慎入!看作者的脑洞能有多大!【授权/每周五更新 责编:拉面】","share_platform":3,"title":"好看哭!《李泰和方小甜的平行世界》这个漫画太优秀了!","picture":"http://f2.kkmh.com/image/170310/hi585uspn.webp-w640","url":"https://m.kuaikanmanhua.com/comics/22535"},{"description":"","share_platform":2,"title":"好看哭!《李泰和方小甜的平行世界》这个漫画太优秀了!","picture":"http://f2.kkmh.com/image/170310/hi585uspn.webp-w640","url":"https://m.kuaikanmanhua.com/comics/22535"},{"description":"好看哭!《李泰和方小甜的平行世界》这个漫画太优秀了!传送门:https://m.kuaikanmanhua.com/comics/22535 ","share_platform":5,"title":"","picture":"http://f2.kkmh.com/image/170310/hi585uspn.webp-w640","url":"https://m.kuaikanmanhua.com/comics/22535"},{"description":"短篇合集,讲述一场自来水污染导致人类出现的奇奇怪怪的疾病。细思极恐,高能慎入!看作者的脑洞能有多大!【授权/每周五更新 责编:拉面】","share_platform":1,"title":"好看哭!《李泰和方小甜的平行世界》这个漫画太优秀了!","picture":"http://f2.kkmh.com/image/170310/hi585uspn.webp-w640","url":"https://m.kuaikanmanhua.com/comics/22535"}],"id":22535,"comic_type":0,"is_login":false,"is_liked":false,"images":["http://f2.kkmh.com/image/170310/ni3jq73um.webp-w640","http://f2.kkmh.com/image/170310/dkytvh9tb.webp-w640","http://f2.kkmh.com/image/170310/bnffqu5qj.webp-w640","http://f2.kkmh.com/image/170310/aolh65hqg.webp-w640","http://f2.kkmh.com/image/170310/g7sqrvbcy.webp-w640","http://f2.kkmh.com/image/170310/2m64twttm.webp-w640","http://f2.kkmh.com/image/170310/eaf8vdmeu.webp-w640","http://f2.kkmh.com/image/170310/a3jpxb2xf.webp-w640","http://f2.kkmh.com/image/c22535/171215/Wyu5BaDjG.webp-w640","http://f2.kkmh.com/image/c22535/171215/qgwMVAIvz.webp-w640","http://f2.kkmh.com/image/170310/unl0hyycu.webp-w640","http://f2.kkmh.com/image/170310/zjari95lw.webp-w640","http://f2.kkmh.com/image/170310/nvmdki6lh.webp-w640","http://f2.kkmh.com/image/170310/5s3nddorm.webp-w640","http://f2.kkmh.com/image/170310/c4fpmayxv.webp-w640","http://f2.kkmh.com/image/170310/d7ac181j7.webp-w640","http://f2.kkmh.com/image/170310/g4wehvwku.webp-w640","http://f2.kkmh.com/image/170310/vqa24zdne.webp-w640","http://f2.kkmh.com/image/170310/xq0k49c0b.webp-w640","http://f2.kkmh.com/image/170310/u4exvr3m5.webp-w640","http://f2.kkmh.com/image/170310/ba50c68yu.webp-w640","http://f2.kkmh.com/image/170310/r4ih3xd17.webp-w640","http://f2.kkmh.com/image/170310/2q6rf6te8.webp-w640","http://f2.kkmh.com/image/170310/mmp8h7aj2.webp-w640","http://f2.kkmh.com/image/170310/62rxlx12n.webp-w640","http://f2.kkmh.com/image/170310/k7ht36vn4.webp-w640","http://f2.kkmh.com/image/170310/iylzwx29w.webp-w640","http://f2.kkmh.com/image/170310/y2vqk0mq7.webp-w640","http://f2.kkmh.com/image/170310/8ja8e70cs.webp-w640","http://f2.kkmh.com/image/170310/rpp8t58iq.webp-w640","http://f2.kkmh.com/image/170310/ethht9qmf.webp-w640","http://f2.kkmh.com/image/170310/i2sazavwb.webp-w640","http://f2.kkmh.com/image/170310/435u6zdjf.webp-w640","http://f2.kkmh.com/image/170310/6tv8bqpg9.webp-w640","http://f2.kkmh.com/image/170310/owxw2tmt9.webp-w640","http://f2.kkmh.com/image/170310/ekh44qmx0.webp-w640","http://f2.kkmh.com/image/170310/oo5x5z0m8.webp-w640","http://f2.kkmh.com/image/170310/lqatu6m7r.webp-w640","http://f2.kkmh.com/image/170310/2ydiojudy.webp-w640","http://f2.kkmh.com/image/170310/i55bo2j8x.webp-w640","http://f2.kkmh.com/image/170310/fs2uvkx6r.webp-w640","http://f2.kkmh.com/image/170310/wtzg35e7i.webp-w640","http://f2.kkmh.com/image/170310/lbajscux3.webp-w640","http://f2.kkmh.com/image/170310/9nb3tyagb.webp-w640","http://f2.kkmh.com/image/170310/r6ivjlxhb.webp-w640","http://f2.kkmh.com/image/170310/byzo0k17q.webp-w640","http://f2.kkmh.com/image/170310/yvc0psfj9.webp-w640","http://f2.kkmh.com/image/170310/wfqmv3l2s.webp-w640","http://f2.kkmh.com/image/170310/05dva698t.webp-w640","http://f2.kkmh.com/image/170310/vys1sdghs.webp-w640","http://f2.kkmh.com/image/170310/yzrxwhgkx.webp-w640","http://f2.kkmh.com/image/170310/l373i5iyp.webp-w640","http://f2.kkmh.com/image/170310/q6d2hv0sy.webp-w640","http://f2.kkmh.com/image/170310/4lpxmpwf0.webp-w640","http://f2.kkmh.com/image/170310/7dhye2una.webp-w640","http://f2.kkmh.com/image/170310/xl4wuhcrq.webp-w640"],"tencent_share_title":"最近发现一部超好看的漫画:李泰和方小甜的平行世界","storyboard_cnt":30,"image_infos":[{"width":800,"key":"a5de7dd6bbc497db5ed12f298111c272","height":625},{"width":800,"key":"6b8b3a865a1ddf711ad71452eec1ad30","height":506},{"width":800,"key":"4f4d306a2a102aa989b8c7a3b658431f","height":625},{"width":800,"key":"378bf2c19fdd4a0fd3eb6ee146c7be7f","height":506},{"width":800,"key":"5435475d65f21de30414fa1749b52aa7","height":625},{"width":800,"key":"cf22f5be2e388b61e8b82827895e0bb5","height":506},{"width":800,"key":"4415c68c3b28b6a44b9673f2992b8364","height":625},{"width":800,"key":"c869489f0d0940896eb25c91329dee08","height":506},{"width":800,"key":"5ffa28d7671f97557c77156147939e21","height":625},{"width":800,"key":"8f636aed79bf9ae50f11933c9d4d732b","height":506},{"width":800,"key":"cd7139fe2446d909c7402abcdcc0dd47","height":625},{"width":800,"key":"39c84ab2949cd3b820f09d4692fb2a62","height":506},{"width":800,"key":"af718ad639b59a426cde65271c366e6d","height":625},{"width":800,"key":"5e12172168957b71266a5bfdb8beafec","height":506},{"width":800,"key":"4d92699063b072739dbe782ad7e6ddbf","height":625},{"width":800,"key":"7c714d5713c9b2422ed8dec402b7fd11","height":506},{"width":800,"key":"9d12808cadb037d2685711d71b131450","height":625},{"width":800,"key":"026615ec2f26a04390a7293616d687d4","height":506},{"width":800,"key":"d87475d57208b2dde95253fa81a487ea","height":625},{"width":800,"key":"32318591ebf3417e5f6d4e28c9127fba","height":506},{"width":800,"key":"e52e90c0f2ea49db9984f8523a089665","height":625},{"width":800,"key":"3e89642afb9d3ec69bf18f3ed18b0fdc","height":506},{"width":800,"key":"b7b067915ed2725763f7e5c9c63a48d6","height":625},{"width":800,"key":"b3093850b87fa4a350a4803b62f82fbc","height":506},{"width":800,"key":"a4e02ca44d58f5ebbc7142937f69296e","height":625},{"width":800,"key":"73de978ec21bfca1eb953349341674b3","height":506},{"width":800,"key":"7d54db0da6ed34116f2546f100717dfa","height":625},{"width":800,"key":"6dd19891de33dcd8bf8400d04bca82b9","height":506},{"width":800,"key":"8e27c2b56222f3343fd473d13871a42d","height":625},{"width":800,"key":"90dd36feb5698ecd776d80139d8bc138","height":506},{"width":800,"key":"7844984a79c747c469423060e67bda36","height":625},{"width":800,"key":"4f14da7ffdf1b0d70fe168c3a4ed66a1","height":506},{"width":800,"key":"7fe98dc3ca0cc4d1655485e44a8703b4","height":625},{"width":800,"key":"48bb94fc304ba8d5c906450b028343b3","height":506},{"width":800,"key":"78e4201ed552e6d3f860c9a9887243e1","height":625},{"width":800,"key":"8c4b8ce67f2fe045cb134a30bb393a04","height":506},{"width":800,"key":"07127d72aea50fbcc0a55f4efb5353c2","height":625},{"width":800,"key":"818e2b0bb456b089e685da175eb5735e","height":506},{"width":800,"key":"31670324abe8fef90d9efe65c2b7838e","height":625},{"width":800,"key":"f5e20fedf06f1543e02abfb0c7b9cd73","height":506},{"width":800,"key":"78b5993f46492921873f643efc8590e9","height":625},{"width":800,"key":"dcd6bf9589dcbffb044dc6bf21c68a37","height":506},{"width":800,"key":"247c655ee1b6428a65ac00058771db12","height":625},{"width":800,"key":"ba25ca3e2e325a33433297e1330c9dfe","height":506},{"width":800,"key":"f54893ef269f8e93c5f15463c24ee49f","height":625},{"width":800,"key":"1a504b37b1f0496e1bba6bb430c0a7d5","height":506},{"width":800,"key":"a8360e2fd73b4347a62e7c71b2174c26","height":625},{"width":800,"key":"49aa257f7e56345b1c23c8aee338e146","height":506},{"width":800,"key":"17ad09e8fc85e72e87f3f9522b3cdc42","height":625},{"width":800,"key":"6274771113b60223485615437172734d","height":506},{"width":800,"key":"d118ea13e0e705687434b08e2b79bfeb","height":625},{"width":800,"key":"16d0edfb22f56fefbe4afe982e1a6d98","height":506},{"width":800,"key":"77b835206f8aaa317e7b9bfb1d13731d","height":625},{"width":800,"key":"f626de71fe25ca19cf6dba693d372e39","height":506},{"width":800,"key":"efd890a68fb91b4547366d4cc7cdb8a1","height":625},{"width":800,"key":"a8a7e8c74833d794da68780c518c740a","height":506}],"next_comic_id":15884,"sina_share_title":"最近在@快看漫画 上发现一部超好看的漫画:李泰和方小甜的平行世界,和我一起来看吧~完整内容戳:","url":"https://m.kuaikanmanhua.com/comics/22535","likes_count":529608,"banner_info":{"type":0},"tencent_share_params":"快看!一分钟一个超赞故事!","comments_count":17046,"is_free":true,"topic":{"discover_image_url":"","vertical_image_url":"http://f2.kkmh.com/image/180314/jp128u992.webp-w320","cover_image_url":"http://f2.kkmh.com/image/180314/w9omjgy9w.webp-w640","description":"短篇合集,讲述一场自来水污染导致人类出现的奇奇怪怪的疾病。细思极恐,高能慎入!看作者的脑洞能有多大!【授权/每周五更新 责编:拉面】","created_at":1453890436,"is_favourite":false,"title":"李泰和方小甜的平行世界","male_vertical_image_url":"http://f2.kkmh.com/image/180314/jp128u992.webp-w320","updated_at":1453890436,"special_offer":{},"is_free":true,"id":699,"category":["剧情"],"related_authors":[{"pub_feed":1,"avatar_url":"http://f2.kkmh.com/image/160530/744atwg2u.webp-w180.w","grade":1,"nickname":"潇潇潇潇如","reg_type":"phone","id":6021212}],"user":{"pub_feed":1,"avatar_url":"http://f2.kkmh.com/image/160530/744atwg2u.webp-w180.w","grade":1,"nickname":"潇潇潇潇如","reg_type":"phone","id":6021212},"label_id":17,"male_cover_image_url":"http://f2.kkmh.com/image/180314/w9omjgy9w.webp-w640","order":761,"comics_count":35,"status":"published"},"serial_no":0,"status":"published"},"message":"ok"}

以上的这些是完整的json数据,我们当然只说重点了。
加载机制:
关于kk漫画的加载机制,假如你现在在看第2章的漫画,当你看到一半多的时候,他就会请求这个接口,提前把第3章漫画的图片的url地址都拿下来。
依此类推。
我们需要关注的是,他如何找到下一个漫画的id,然后又如何判断下一个漫画的标题等等。

我们可以通过在程序里打断点,动态调试,或者看静态源码,或者Log信息,最终发现返回的数据如下,
关于重点的一些信息,我做了标记

制作我们自己的脚本的思路

思路:我们首先请求第一章的id,我们现在的id是22535,根据刚刚的Log分析可知。
然后我们请求回来之后,把images里面的图片都保存到指定的文件夹,准备合并。
然后请求下一章节,继续,直到所有漫画都下载到本地。
合并每个文件夹里面的图片,最后这些长图就是我们想看的漫画了。

我用的python写的这个脚本,因为个人平时都是用java,有些地方写的不好,也欢迎大家指正

我的脚本

github地址
运行环境:
python3.6+
Pillow库,
具体的可以查看ReadME,也可以联系本人

运行方法:
python .\app.py ${id}

python .\app.py 22535

22535只是一个章节的id,

我就以《漫画A作为例子》
然后脚本就会自动的在当前文件夹下面生成两个文件夹
漫画A和漫画A-result

漫画A-result里面就是拼接好的漫画了
漫画A-是分批下载的一些临时文件

具体如图:

前面的就是我们下载的一些临时文件
后一张图就是我们做好的了

声明

本文只做技术研究,不做商用,如有同学做商用,恶意攻击服务器,等非法行为,本人概不负责

告一段落

好了好了,其实说到了这里,今天就说到这里吧,这次把一整本书的内容都提取出来了。
可以开开心心的在本地看漫画了。

我希望呢,自己写博客,能够认认真真的写出一点东西分享给大家,而不是网上抄来抄去。希望能做一个踏踏实实做技术的人吧,不敢求太多,能给大家带来点好玩的就挺好。

写在最后

有什么问题欢迎给博主指出。
包括python,程序分析方面的问题,等。

成品就不上传了,希望大家都能跑

忽然想到id获取的问题,其实有几个思路,

  • sd卡的根目录创建/KuaiKan文件夹,然后里面创建了一个空的kkmh_debug文件。使kk漫画处于debug模式下,自己抓Log
  • 博主可以去对app重新打包,然后加上一些个人的代码,二次打包发布出来
  • 写个xposed插件供大家使用

具体的可以下回说,也可以大家自己来发挥想象力啦,有什么问题欢迎联系我

关于我

个人网站:MartinHan的小站

博客:hanhan12312的专栏

知乎:MartinHan01