百姓网字体解密

https://maanshan.baixing.com/chuguolaowu/a2636030753.html?from=regular

字体文件

原始代码

import io
import re
import requests
from lxml import etree
from fontTools.ttLib import TTFont


def decrypt_font(encrypted_str, font_data):
    """解密字体"""
    # font = TTFont(font_path)
    font = TTFont(io.BytesIO(font_data))
    # font.saveXML(f"{font_path}.xml")

    font_cmap = font.getBestCmap()
    # print(font_cmap)

    decrypt_str = ""
    for char in encrypted_str:
        value = font_cmap.get(ord(char))
        new_value = chr(int(value[3:], 16)) if value else char
        print(f"char: {char}, value: {value}, new_value: {new_value}")
        decrypt_str += new_value

    print(decrypt_str)
    return decrypt_str


def ferch_data():
    headers = {
        "accept": "*/*",
        "accept-language": "zh-CN,zh;q=0.9",
        "referer": "https://www.baixing.com/",
        "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36",
    }
    url = "https://maanshan.baixing.com/chuguolaowu/a2636030753.html?from=regular"
    response = requests.get(url, headers=headers)
    cookies = response.cookies.get_dict()
    print(cookies)
    response = requests.get(url, headers=headers, cookies=cookies)

    print(response.text)
    print(response)

    tree = etree.HTML(response.text)
    phone_1 = "".join(tree.xpath('//li[@class="contact-btn-box"]/a[@class="contact-no bx-shield-font"]/text()'))
    print(phone_1)
    phone_2 = "".join(tree.xpath('//li[@class="contact-btn-box"]/a[@class="show-contact"]/@data-contact'))
    print(phone_2)

    phone_str = phone_1.replace("*", "") + phone_2
    print(phone_str)

    font_url = "https:" + "".join(re.findall(r'font-family:"bx-shield-font";src:url\("(.*?)"\)', response.text))
    print(font_url)

    font_response = requests.get(font_url, headers=headers, cookies=cookies)
    # print(font_response)
    # with open("font.woff", "wb") as fw:
    #     fw.write(font_response.content)
    return phone_str, font_response.content


def main():
    phone_str, font_data = ferch_data()
    new_phone = decrypt_font(phone_str, font_data)
    print(f"phone_str: {phone_str}, new_phone: {new_phone}")


if __name__ == "__main__":
    main()

结果展示

posted @ 2025-04-25 11:32  二二二狗子  阅读(13)  评论(0)    收藏  举报