开启辅助访问 切换到宽版

精易论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

用微信号发送消息登录论坛

新人指南 邀请好友注册 - 我关注人的新帖 教你赚取精币 - 每日签到


求职/招聘- 论坛接单- 开发者大厅

论坛版规 总版规 - 建议/投诉 - 应聘版主 - 精华帖总集 积分说明 - 禁言标准 - 有奖举报

查看: 274|回复: 4
收起左侧

[求助] python转易语言

[复制链接]
结帖率:100% (1/1)
发表于 2024-3-28 15:08:29 | 显示全部楼层 |阅读模式   湖南省娄底市
[Python] 纯文本查看 复制代码
from ctypes import 
import win32api
import psutil
import win32gui
import win32process
import re

FAGE_READWRITE = 0x04
PROCESS_ALL_ACCESS = 0x001F0FFF
VIRTUAL_MEN = (0x1000  0x2000)

kernel32 = windll.kernel32
user32 = windll.user32


# 获取所有窗口句柄+窗口标题 存入字典中
def get_all_ths_windows()
    ths_windows = []

    def enum_windows_proc(hwnd, lParam)
        windows = lParam
        tdx_temp = dict()
        if (re.match(AAA, win32gui.GetWindowText(hwnd))) and (
                win32gui.GetClassName(hwnd) == 'T_MainFrame_Class')
            hread_id, p_id = win32process.GetWindowThreadProcessId(
                hwnd)  # 通过句柄获取【线程ID 进程ID】
            tdx_temp.update({pid p_id, hwnd hwnd, title win32gui.GetWindowText(
                hwnd), clsname win32gui.GetClassName(hwnd)})
            windows.append(tdx_temp)
        if (re.match(BBB, win32gui.GetWindowText(hwnd))) and (re.match(Afx00, win32gui.GetClassName(hwnd)))
            hread_id, p_id = win32process.GetWindowThreadProcessId(
                hwnd)  # 通过句柄获取【线程ID 进程ID】
            tdx_temp.update({pid p_id, hwnd hwnd, title win32gui.GetWindowText(
                hwnd), clsname win32gui.GetClassName(hwnd)})
            windows.append(tdx_temp)

    win32gui.EnumWindows(enum_windows_proc, ths_windows)
    return ths_windows


# 取一个BBB顶层窗口句柄
def ths_top_hwnd()
    process_lists = get_all_ths_windows()  # 返回进程字典
    # keys = dict_ths.keys()  # 返回字典中所有键
    # items = dict_tdx.items()  # 返回键值对
    for process in process_lists
        pid = process[pid]  # 当前进程id
        hwnd = process[hwnd]  # 当前进程句柄
        # print(
        #     f当前进程id{pid} 当前句柄:{hwnd}===窗口标题:{win32gui.GetWindowText(hwnd)}===类名:{win32gui.GetClassName(hwnd)})
        if re.match(BBB, win32gui.GetWindowText(hwnd))
            return hwnd
    return 0


def ths_prc_hwnd()
    pl = psutil.pids()
    for pid in pl
        if psutil.Process(pid).name().lower() == h.exe
            if isinstance(pid, int)
                ths_process_hwnd = kernel32.OpenProcess(PROCESS_ALL_ACCESS, False,
                                                        int(pid))  # 申请内存所在的进程句柄
                return ths_process_hwnd

def bytes_16(dec_num, Code)
    ascii_char = chr(dec_num)  # 将整数转换为对应的ASCII字符
    codex = ascii_char + str(Code)
    # 将Python字符串转换为bytes类型
    bytes_codex = codex.encode('ascii', 'ignore')
    return bytes_codex


def ths_convert_code(Code)

    if str(Code)[0] == '6'
        dec_num = int(11, 16)  # 将16进制数转换为整数      
        bytes_codex = bytes_16(dec_num,Code)
    elif str(Code).startswith(11)  # 11开头的可转债
        dec_num = int(13, 16)  # 将16进制数转换为整数
        bytes_codex = bytes_16(dec_num,Code)
    elif str(Code).startswith(12)  # 12开头的可转债
        dec_num = int(23, 16)  # 将16进制数转换为整数
        bytes_codex = bytes_16(dec_num,Code)
    else
        dec_num = int(21, 16)  # 将16进制数转换为整数
        bytes_codex = bytes_16(dec_num,Code)
    return bytes_codex

def send_code_message(code)
    ths_process_hwnd = ths_prc_hwnd()
    # 用kerne132.VirtualAllocEx在目标进程开辟内存空间(用于存放数据)
    argv_address = kernel32.VirtualAllocEx(ths_process_hwnd, 0, 8, VIRTUAL_MEN, FAGE_READWRITE)
    bytes_str = ths_convert_code(code)
    # 步用kerne132.WriteProcessMemory在目标进程内存空间写入数据
    kernel32.WriteProcessMemory(ths_process_hwnd, argv_address, bytes_str, 7, None)
    ths_top_hwnd1 = ths_top_hwnd()  # BBB顶层窗口句柄
    win32api.SendMessage(ths_top_hwnd1, int(1168), 0, argv_address)


if __name__ == '__main__'
        send_code_message(688168)



结帖率:100% (25/25)

签到天数: 27 天

发表于 2024-3-28 15:32:54 | 显示全部楼层   山东省泰安市
太长了 不看
回复 支持 反对

使用道具 举报

结帖率:89% (24/27)

签到天数: 18 天

发表于 2024-3-28 17:05:24 | 显示全部楼层   广东省广州市
这个很简单都是API实现的精益模块就能翻译
回复 支持 反对

使用道具 举报

结帖率:100% (9/9)
发表于 2024-3-29 14:02:40 | 显示全部楼层   山西省太原市
向一个窗口发送消息,精易的窗口投递 不能用?
回复 支持 反对

使用道具 举报

结帖率:100% (1/1)

签到天数: 5 天

 楼主| 发表于 2024-3-30 10:15:07 | 显示全部楼层   湖南省娄底市
辛苦老师们帮帮忙改成例程,万分感谢
回复 支持 反对

使用道具 举报

  高级模式
B Color Image Link Quote Code Smilies |上传

本版积分规则 致发广告者

发布主题 收藏帖子 返回列表

sitemap| 易语言源码| 易语言教程| 易语言论坛| 诚聘英才| 易语言模块| 手机版| 广告投放| 精易论坛
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
论坛帖子内容仅用于技术交流学习和研究的目的,严禁用于非法目的,否则造成一切后果自负!如帖子内容侵害到你的权益,请联系我们!
防范网络诈骗,远离网络犯罪 违法和不良信息举报电话0663-3422125,QQ: 800073686,邮箱:800073686@b.qq.com
Powered by Discuz! X3.4 揭阳市揭东区精易科技有限公司 ( 粤ICP备12094385号-1) 粤公网安备 44522102000125 增值电信业务经营许可证 粤B2-20192173

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