js逆向 - pyexecjs 执行js编码异常
2020-10-30 本文已影响0人
木语沉心
pyexecjs执行js代码中含有中文会出现编码异常
File "C:\python3\lib\subprocess.py", line 1238, in _readerthread
buffer.append(fh.read())
UnicodeDecodeError: 'gbk' codec can't decode byte 0xbd in position 38: illegal multibyte sequence
解决办法:
法1. 将中文部分取出 单独编码后替换
法2. 根据异常定位可知 File "C:\python3\lib\subprocess.py", line 1238, in _readerthread
buffer.append(fh.read())
是subprocess包内的编码问题, 修改内置 subprocess 文件的编码类型为 encoding='utf-8'
法3. 使用 js2py 第三方包执行js代码 示例如下:
# -*- coding: utf-8 -*-
import execjs
import js2py
jscode = '''function getnames(){
window = {}
name_list = [];
let name = ['极镀ギ紬荕', '爷灬霸气傀儡', '梦战苍穹', '傲世哥', 'мaη肆風聲', '一刀メ隔世', '横刀メ绝杀', 'Q不死你R死你', '魔帝殤邪', '封刀不再战', '倾城孤狼', '戎马江湖', '狂得像风', '影之哀伤', '謸氕づ独尊', '傲视狂杀', '追风之梦', '枭雄在世', '傲视之巅', '黑夜刺客', '占你心为王', '爷来取你狗命', '御风踏血', '凫矢暮城', '孤影メ残刀', '野区霸王', '噬血啸月', '风逝无迹', '帅的睡不着', '血色杀戮者', '冷视天下', '帅出新高度', '風狆瑬蒗', '灵魂禁锢', 'ヤ地狱篮枫ゞ', '溅血メ破天', '剑尊メ杀戮', '塞外う飛龍', '哥‘K纯帅', '逆風祈雨', '恣意踏江山', '望断、天涯路', '地獄惡灵', '疯狂メ孽杀', '寂月灭影', '骚年霸称帝王', '狂杀メ无赦', '死灵的哀伤', '撩妹界扛把子', '霸刀☆藐视天下', '潇洒又能打', '狂卩龙灬巅丷峰', '羁旅天涯.', '南宫沐风', '风恋绝尘', '剑下孤魂', '一蓑烟雨', '领域★倾战', '威龙丶断魂神狙', '辉煌战绩', '屎来运赚', '伱、Bu够档次', '九音引魂箫', '骨子里的傲气', '霸海断长空', '没枪也很狂', '死魂★之灵'];
let data = [{"value": "    "}, {"value": "쑱 ꑨ  놕 "}, {"value": " ꙁ 쑱 뤸 "}, {"value": "뤸 쑱 쑱 ꑨ "}, {"value": "쉉 ꑨ  쉉 "}, {"value": "뤸 뤸 ꙁ 뤸 "}, {"value": " 놕 ꙁ ꑨ "}, {"value": "뤸  ꑨ ꑨ "}, {"value": " 쑱 ꑨ ꑨ "}, {"value": "쉉  쉉 뤸 "}];
i = 0;
for (i; i<5; i++){
window.page = i + 1;
j = 0;
let yyq = 1;
page_names = [];
for (j; j < data.length; j++){
page_names.push(name[yyq + (window.page - 1) * 10]);
yyq += 1;
};
name_list.push(page_names)
};
return name_list;
}'''
name_list = js2py.eval_js(jscode)()
print(name_list)
ctx = execjs.compile(jscode)
name_list = ctx.call('getnames')
ERROR:
>>> File "C:\python3\lib\subprocess.py", line 1238, in _readerthread
buffer.append(fh.read())
UnicodeDecodeError: 'gbk' codec can't decode byte 0xbd in position 38: illegal multibyte sequence
>>> File "C:\python3\lib\subprocess.py", line 1288, in _communicate
stdout = stdout[0]
IndexError: list index out of range