网站首页 > 教程文章 正文
今天成功把易语言调用验证码通杀的DLL在Python中成功调用了
特此共享出来,下面是识别截图:
识别方法1:
私信小编01即可获取大量Python学习资源
# 来源:http://www.sanye.cx/?id=12022
# 优点:载入快、识别速度高、识别精度较高
# 缺点:仅在32位Python环境中成功运行
# 获取上级目录
path = os.path.abspath(os.path.dirname(os.getcwd()))
# 获取验证码文件夹
img_list = os.listdir(path + r"\captcha")
# 载入识别库
dll = cdll.LoadLibrary(path + r"\ocr1\ocr.dll")
# 初始化识别库
dll.init()
# 遍历图片并识别
for i in img_list:
# 读入图片
with open(path + r"\captcha\{0}".format(i), "rb") as file:
# 读入图片
image = file.read()
# 利用dll中的ocr函数进行识别
Str = dll.ocr(image, len(image))
# 返回的是指针,所以此处将指针转换为字符串,然后再编码即可得到字符串类型
text = string_at(Str).decode("utf-8")
print(f"识别返回:{text},类型:{type(text)},ID地址:{id(text)}")
识别方法2:
# 来源:[url=https://www.52pojie.cn/thread-1072587-1-1.html]https://www.52pojie.cn/thread-1072587-1-1.html[/url]
# 优点:识别速度高、识别精度高
# 缺点:仅在32位Python环境中成功运行、载入时间较长
# 获取上级目录
path = os.path.abspath(os.path.dirname(os.getcwd()))
# 载入识别库
dll = cdll.LoadLibrary(path + r"\ocr2\OCRS.dll")
# 载入字库与建立字库索引
with open(path + r"\ocr2\通杀英文数字库.cnn", "rb") as file:
# 载入字库
word_bank = file.read()
# 建立字库索引
work_index = dll.INIT(path, word_bank, len(word_bank), -1, 1)
# 读入待识别图片列表
img_list = os.listdir(path + "\captcha")
# 循环识别图片并输出
for i in img_list:
# 打开指定图片
with open(path + "\captcha\{0}".format(i), "rb") as file_img:
# 读入图片
image = file_img.read()
Str = create_string_buffer(100) # 创建文本缓冲区
dll.OCR(work_index, image, len(image), Str) # 利用DLL中的识别函数进行识别
text = Str.raw.decode("utf-8") # 对识别的返回值进行编码
print(f"识别返回:{text},类型:{type(text)},ID地址:{id(text)}")
1.自己弄了一个类,下载下来直接使用,调用方法:
dll = Ver_code_1(DLL文件所在的文件夹目录)
#或者
dll = Ver_code_2(DLL文件所在的文件夹目录)
#识别图片:
dll.ocr(图片)
2.修正了识别库2空白字符未消除,无法正确判断长度的问题(可以利用固定长度判断是否符合,进行初步筛选,避免提交后网页返回验证码错误)
import os
from ctypes import *
class Ver_code_1:
# 启动时需要传入ocr.dll
def __init__(self, path):
# 载入识别库
self.dll = cdll.LoadLibrary(path + r"\ocr.dll")
# 初始化识别库
self.dll.init()
def ocr(self, image):
Str = self.dll.ocr(image, len(image))
# 返回的是指针,所以此处将指针转换为字符串,然后再编码即可得到字符串类型
return string_at(Str).decode("utf-8")
class Ver_code_2:
def __init__(self, path):
# 载入识别库
self.dll = cdll.LoadLibrary(path + r"\OCRS.dll")
# 载入字库与建立字库索引
with open(path + r"\通杀英文数字库.cnn", "rb") as file:
# 载入字库
self.word_bank = file.read()
# 建立字库索引
self.word_index = self.dll.INIT(path, self.word_bank, len(self.word_bank), -1, 1)
def ocr(self, image):
Str = create_string_buffer(100) # 创建文本缓冲区
self.dll.OCR(self.word_index, image, len(image), Str) # 利用DLL中的识别函数进行识别
return Str.raw.decode("utf-8").rstrip('\x00') # 对识别的返回值进行编码后返回,这里的\x00是删除缓冲区的空白符
注意!测试环境为:
Python 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:30:23) [MSC v.1928 32 bit (Intel)] on win32
经测试,无法在64位环境下调用,如有大佬能实现,烦请告知一下
关于DLL改64位的思路:
我找到了论坛中的IDA pro,成功将DLL进行了反编译,如图:
其实最关键的就是以上的init以及ocr两个函数,但是后续如何将IDA pro项目转换为64位,然后进行编译,目前没有找到合适的方法,如果有大佬麻烦告知一下。
- 上一篇: Python语言入门源代码
- 下一篇: Lua实现文件I/O操作,你会吗?
猜你喜欢
- 2025-01-21 Python中的“锁”艺术:解锁Lock与RLock的秘密
- 2025-01-21 Python格式化字符串
- 2025-01-21 Lua实现文件I/O操作,你会吗?
- 2025-01-21 Python语言入门源代码
- 2025-01-21 R 语言 + aardio 快速开发图形界面、生成独立 EXE
- 2025-01-21 Python中定义函数
- 2025-01-21 Python基础语法之print和变量赋值
- 2025-01-21 java程序设计练习题(二)附答案
- 2025-01-21 c#中使用miniExcel和fastreport实现付款审批单的批量打印
- 2025-01-21 R语言实战—自学笔记—向量
- 最近发表
- 标签列表
-
- location.href (44)
- document.ready (36)
- git checkout -b (34)
- 跃点数 (35)
- 阿里云镜像地址 (33)
- qt qmessagebox (36)
- md5 sha1 (32)
- mybatis plus page (35)
- semaphore 使用详解 (32)
- update from 语句 (32)
- vue @scroll (38)
- 堆栈区别 (33)
- 在线子域名爆破 (32)
- 什么是容器 (33)
- sha1 md5 (33)
- navicat导出数据 (34)
- 阿里云acp考试 (33)
- 阿里云 nacos (34)
- redhat官网下载镜像 (36)
- srs服务器 (33)
- pico开发者 (33)
- https的端口号 (34)
- vscode更改主题 (35)
- 阿里云资源池 (34)
- os.path.join (33)