今天成功把易語(yǔ)言調(diào)用驗(yàn)證碼通殺的dll在python中成功調(diào)用了
特此共享出來(lái),下面是識(shí)別截圖:
識(shí)別方法1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
"""當(dāng)然在學(xué)習(xí)python的道路上肯定會(huì)困難,沒(méi)有好的學(xué)習(xí)資料,怎么去學(xué)習(xí)呢? 學(xué)習(xí)python中有不明白推薦加入交流群號(hào):928946953 群里有志同道合的小伙伴,互幫互助, 群里有不錯(cuò)的視頻學(xué)習(xí)教程和pdf!還有大牛解答!""" # 來(lái)源:http://www.sanye.cx/?id=12022 # 優(yōu)點(diǎn):載入快、識(shí)別速度高、識(shí)別精度較高 # 缺點(diǎn):僅在32位python環(huán)境中成功運(yùn)行 # 獲取上級(jí)目錄 path = os.path.abspath(os.path.dirname(os.getcwd())) # 獲取驗(yàn)證碼文件夾 img_list = os.listdir(path + r "\captcha" ) # 載入識(shí)別庫(kù) dll = cdll.loadlibrary(path + r "\ocr1\ocr.dll" ) # 初始化識(shí)別庫(kù) dll.init() # 遍歷圖片并識(shí)別 for i in img_list: # 讀入圖片 with open (path + r "\captcha\{0}" . format (i), "rb" ) as file : # 讀入圖片 image = file .read() # 利用dll中的ocr函數(shù)進(jìn)行識(shí)別 str = dll.ocr(image, len (image)) # 返回的是指針,所以此處將指針轉(zhuǎn)換為字符串,然后再編碼即可得到字符串類型 text = string_at( str ).decode( "utf-8" ) print (f "識(shí)別返回:{text},類型:{type(text)},id地址:{id(text)}" ) 識(shí)別方法 2 : # 來(lái)源:[url=https://www.52pojie.cn/thread-1072587-1-1.html]https://www.52pojie.cn/thread-1072587-1-1.html[/url] # 優(yōu)點(diǎn):識(shí)別速度高、識(shí)別精度高 # 缺點(diǎn):僅在32位python環(huán)境中成功運(yùn)行、載入時(shí)間較長(zhǎng) # 獲取上級(jí)目錄 path = os.path.abspath(os.path.dirname(os.getcwd())) # 載入識(shí)別庫(kù) dll = cdll.loadlibrary(path + r "\ocr2\ocrs.dll" ) # 載入字庫(kù)與建立字庫(kù)索引 with open (path + r "\ocr2\通殺英文數(shù)字庫(kù).cnn" , "rb" ) as file : # 載入字庫(kù) word_bank = file .read() # 建立字庫(kù)索引 work_index = dll.init(path, word_bank, len (word_bank), - 1 , 1 ) # 讀入待識(shí)別圖片列表 img_list = os.listdir(path + "\captcha" ) # 循環(huán)識(shí)別圖片并輸出 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 ) # 創(chuàng)建文本緩沖區(qū) dll.ocr(work_index, image, len (image), str ) # 利用dll中的識(shí)別函數(shù)進(jìn)行識(shí)別 text = str .raw.decode( "utf-8" ) # 對(duì)識(shí)別的返回值進(jìn)行編碼 print (f "識(shí)別返回:{text},類型:{type(text)},id地址:{id(text)}" ) |
1.自己弄了一個(gè)類,下載下來(lái)直接使用,調(diào)用方法:
1
2
3
4
5
|
dll = ver_code_1(dll文件所在的文件夾目錄) #或者 dll = ver_code_2(dll文件所在的文件夾目錄) #識(shí)別圖片: dll.ocr(圖片) |
2.修正了識(shí)別庫(kù)2空白字符未消除,無(wú)法正確判斷長(zhǎng)度的問(wèn)題(可以利用固定長(zhǎng)度判斷是否符合,進(jìn)行初步篩選,避免提交后網(wǎng)頁(yè)返回驗(yàn)證碼錯(cuò)誤)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
import os from ctypes import * class ver_code_1: # 啟動(dòng)時(shí)需要傳入ocr.dll def __init__( self , path): # 載入識(shí)別庫(kù) self .dll = cdll.loadlibrary(path + r "\ocr.dll" ) # 初始化識(shí)別庫(kù) self .dll.init() def ocr( self , image): str = self .dll.ocr(image, len (image)) # 返回的是指針,所以此處將指針轉(zhuǎn)換為字符串,然后再編碼即可得到字符串類型 return string_at( str ).decode( "utf-8" ) class ver_code_2: def __init__( self , path): # 載入識(shí)別庫(kù) self .dll = cdll.loadlibrary(path + r "\ocrs.dll" ) # 載入字庫(kù)與建立字庫(kù)索引 with open (path + r "\通殺英文數(shù)字庫(kù).cnn" , "rb" ) as file : # 載入字庫(kù) self .word_bank = file .read() # 建立字庫(kù)索引 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 ) # 創(chuàng)建文本緩沖區(qū) self .dll.ocr( self .word_index, image, len (image), str ) # 利用dll中的識(shí)別函數(shù)進(jìn)行識(shí)別 return str .raw.decode( "utf-8" ).rstrip( '\x00' ) # 對(duì)識(shí)別的返回值進(jìn)行編碼后返回,這里的\x00是刪除緩沖區(qū)的空白符 |
注意!測(cè)試環(huán)境為:
python 3.9.2 (tags/v3.9.2:1a79785, feb 19 2021, 13:30:23) [msc v.1928 32 bit (intel)] on win32
經(jīng)測(cè)試,無(wú)法在64位環(huán)境下調(diào)用,如有大佬能實(shí)現(xiàn),煩請(qǐng)告知一下
關(guān)于dll改64位的思路:
我找到了論壇中的ida pro,成功將dll進(jìn)行了反編譯,如圖:
其實(shí)最關(guān)鍵的就是以上的init以及ocr兩個(gè)函數(shù),但是后續(xù)如何將ida pro項(xiàng)目轉(zhuǎn)換為64位,然后進(jìn)行編譯,目前沒(méi)有找到合適的方法,如果有大佬麻煩告知一下。
到此這篇關(guān)于python調(diào)用易語(yǔ)言動(dòng)態(tài)鏈接庫(kù),實(shí)現(xiàn)驗(yàn)證碼通殺例子的文章就介紹到這了,更多相關(guān)python易語(yǔ)言驗(yàn)證碼內(nèi)容請(qǐng)搜索服務(wù)器之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持服務(wù)器之家!
原文鏈接:https://www.cnblogs.com/pythonQqun200160592/p/15152466.html