吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2967|回复: 16
收起左侧

[Python 转载] 刚学js逆向解析,写了个有道翻译,发出来跟大佬们讨论学习下

  [复制链接]
XiaoZouYu 发表于 2022-4-30 13:19
[Python] 纯文本查看 复制代码
import time
import jsonpath
import requests
import execjs

if __name__ == '__main__':
    while True:

        url_ = "https://fanyi.baidu.com/v2transapi?from=zh&to=en"

        headers_ = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36",
            "Referer": "https://fanyi.baidu.com/?aldtype=16047",
            "Cookie": "BIDUPSID=7BB299F19EEE94EB61DB1E77675F0AF0; PSTM=1645516720; BAIDUID=7BB299F19EEE94EB3646FAA407A7C2D5:FG=1; __yjs_duid=1_3535544102b84d8bf040bef421074ee11645517686759; BDUSS=XBNVjB1NUhrYjNPRzV-aFpOMndsMnhTSWdkVlp3Y3Fqa0tRc0ZoTkZhckYzajVpRVFBQUFBJCQAAAAAAAAAAAEAAAAcu96U19~X37XEzfjFzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMVRF2LFURdiV; BDUSS_BFESS=XBNVjB1NUhrYjNPRzV-aFpOMndsMnhTSWdkVlp3Y3Fqa0tRc0ZoTkZhckYzajVpRVFBQUFBJCQAAAAAAAAAAAEAAAAcu96U19~X37XEzfjFzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMVRF2LFURdiV; H_PS_PSSID=36183_36309_36165_34584_36338_35979_35863_36225_26350_36312_36061; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; BAIDUID_BFESS=7BB299F19EEE94EB3646FAA407A7C2D5:FG=1; delPer=0; PSINO=6; BA_HECTOR=04208k2ka0al05a5ms1h6fb0g0r; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1650961489; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1650961737; ab_sr=1.0.1_ZmQyNDQ0ZTY1OGQxMjA2NmJhYzU2NTRjNTY3ZWUzZWNmMTRjMWY0OTExYWVlZWExZDA5MjA5OTYzMTgxMDFkOTZmYmY0NjUwZjhkYjBhMjI0NjlhOGExYTQ3MjBkOTJjNTAzYWM3NTBhN2RiZTZlODE2MDg5ZDNjNzI0ODhiMjMwZmRlMTFmNDM5YTRkYjJiMDM0YjdiOThjMzAxNjlkMDEyNGYxNjA5YjExYWVmMmIzZjcxMjQ5MGIzOTRkYmQz"
        }

        # 构造表单数据
        # 1.要被翻译的数据
        data_ = input("请输入要翻译的中文:")

        # 打开js文件,得到里面的js代码
        with open('baidu_.js','r') as f:
            js_data = f.read()
        # 实例化对象
        js_obj = execjs.compile(js_data)
        # 执行js代码,得到返回数据
        sign_data = js_obj.call('e',data_)
        # sign
        sign_ = sign_data
        # print(sign_data)

        form_data = {
            "from": "zh",
            "to": "en",
            "query": data_,
            "transtype": "translang",
            "simple_means_flag": "3",
            "sign": sign_,
            "token": "ee1b85eec316788c858665fdb0fbdb4f",
            "domain": "common"
        }

        response_ = requests.post(url_,headers=headers_,data=form_data)
        py_data = response_.json()
        # print(py_data)

        res_ = jsonpath.jsonpath(py_data,'$..dst')[0]
        print(f"翻译结果为:{res_}")

        time.sleep(1)

免费评分

参与人数 1吾爱币 +1 收起 理由
doublee + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| XiaoZouYu 发表于 2022-4-30 14:23
[JavaScript] 纯文本查看 复制代码
function n(r, o) {
        for (var t = 0; t < o.length - 2; t += 3) {
            var a = o.charAt(t + 2);
            a = a >= "a" ? a.charCodeAt(0) - 87 : Number(a),
            a = "+" === o.charAt(t + 1) ? r >>> a : r << a,
            r = "+" === o.charAt(t) ? r + a & 4294967295 : r ^ a
        }
        return r
    }
function e(r) {
        var o = r.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g);
        if (null === o) {
            var t = r.length;
            t > 30 && (r = "" + r.substr(0, 10) + r.substr(Math.floor(t / 2) - 5, 10) + r.substr(-10, 10))
        } else {
            for (var e = r.split(/[\uD800-\uDBFF][\uDC00-\uDFFF]/), C = 0, h = e.length, f = []; h > C; C++)
                "" !== e[C] && f.push.apply(f, a(e[C].split(""))),
                C !== h - 1 && f.push(o[C]);
            var g = f.length;
            g > 30 && (r = f.slice(0, 10).join("") + f.slice(Math.floor(g / 2) - 5, Math.floor(g / 2) + 5).join("") + f.slice(-10).join(""))
        }
        var i = "320305.131321201"
        var u = void 0
          , l = "" + String.fromCharCode(103) + String.fromCharCode(116) + String.fromCharCode(107);
        u = null !== i ? i : (i = window[l] || "") || "";
        for (var d = u.split("."), m = Number(d[0]) || 0, s = Number(d[1]) || 0, S = [], c = 0, v = 0; v < r.length; v++) {
            var A = r.charCodeAt(v);
            128 > A ? S[c++] = A : (2048 > A ? S[c++] = A >> 6 | 192 : (55296 === (64512 & A) && v + 1 < r.length && 56320 === (64512 & r.charCodeAt(v + 1)) ? (A = 65536 + ((1023 & A) << 10) + (1023 & r.charCodeAt(++v)),
            S[c++] = A >> 18 | 240,
            S[c++] = A >> 12 & 63 | 128) : S[c++] = A >> 12 | 224,
            S[c++] = A >> 6 & 63 | 128),
            S[c++] = 63 & A | 128)
        }
        for (var p = m, F = "" + String.fromCharCode(43) + String.fromCharCode(45) + String.fromCharCode(97) + ("" + String.fromCharCode(94) + String.fromCharCode(43) + String.fromCharCode(54)), D = "" + String.fromCharCode(43) + String.fromCharCode(45) + String.fromCharCode(51) + ("" + String.fromCharCode(94) + String.fromCharCode(43) + String.fromCharCode(98)) + ("" + String.fromCharCode(43) + String.fromCharCode(45) + String.fromCharCode(102)), b = 0; b < S.length; b++)
            p += S[b],
            p = n(p, F);
        return p = n(p, D),
        p ^= s,
        0 > p && (p = (2147483647 & p) + 2147483648),
        p %= 1e6,
        p.toString() + "." + (p ^ m)
    }
太阳学 发表于 2022-5-31 00:08
我实验后结果
请输入要翻译的中文:机器人
Traceback (most recent call last):
  File PycharmProjects\pythonProject2\python入门1.py", line 21, in <module>
    with open('baidu_.js', 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'baidu_.js'
doublee 发表于 2022-4-30 13:41
楼主可以把逆向的思路过程发出来嘛,只有代码怎么互相学习讨论
cdsgg 发表于 2022-4-30 13:55
你只发这个是运行不了的  还要逆向的js 文件发出来 才能用的
 楼主| XiaoZouYu 发表于 2022-4-30 14:29
cdsgg 发表于 2022-4-30 13:55
你只发这个是运行不了的  还要逆向的js 文件发出来 才能用的

js文件已发在品论区,谢谢提醒
话痨司机啊 发表于 2022-4-30 14:41
用hook把cookie取到放里更好一点,也是js文件生成的cookie,
document.cookie='OUTFOX_SEARCH_USER_ID=-1525129329@10.110.96.154; JSESSIONID=aaa5PaROESrJk-cH_l5by; ___rl__test__cookies=1651300625407; OUTFOX_SEARCH_USER_ID_NCOO=1655402317.885046'
叫我小王叔叔 发表于 2022-4-30 15:47
XiaoZouYu 发表于 2022-4-30 14:29
js文件已发在品论区,谢谢提醒

大佬,讲一讲如何逆向的吧,你怎么知道上面那段js有用呢?
知心 发表于 2022-4-30 17:55
楼主代码用的是百度翻译的接口把
 楼主| XiaoZouYu 发表于 2022-4-30 18:24
叫我小王叔叔 发表于 2022-4-30 15:47
大佬,讲一讲如何逆向的吧,你怎么知道上面那段js有用呢?

这个不好讲,得操作,要去抓包,看前端代码运行,然后使用断点去慢慢测试
deepgo 发表于 2022-5-2 00:08
虽然看不懂 还是顶一下
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-25 05:29

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表