欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

VBA工程加密PJ方式(两种)

程序员文章站 2022-07-07 08:37:16
两种方式破解vba加密代码第一种:sub vbapassword1() '你要解保护的excel文件路径 filename = application.getopenfilename("exce...

两种方式破解vba加密代码

第一种:

sub vbapassword1() '你要解保护的excel文件路径
    filename = application.getopenfilename("excel文件(*.xls & *.xla & *.xlt),*.xls;*.xla;*.xlt", , "vba破解")
    if dir(filename) = "" then
        msgbox "没找到相关文件,清重新设置。"
        exit sub
    else
        filecopy filename, filename & ".bak" '备份文件。
    end if
    dim getdata as string * 5
    open filename for binary as #1
    dim cmgs as long
    dim dpbo as long
    for i = 1 to lof(1)
        get #1, i, getdata
        if getdata = "cmg=""" then cmgs = i
        if getdata = "[host" then dpbo = i - 2: exit for
    next
    if cmgs = 0 then
        msgbox "请先对vba编码设置一个保护密码...", 32, "提示"
        exit sub
    end if
    dim st as string * 2
    dim s20 as string * 1
    '取得一个0d0a十六进制字串
    get #1, cmgs - 2, st
    '取得一个20十六制字串
    get #1, dpbo + 16, s20
    '替换加密部份机码
    for i = cmgs to dpbo step 2
        put #1, i, st
    next
    '加入不配对符号
    if (dpbo - cmgs) mod 2 <> 0 then
        put #1, dpbo + 1, s20
    end if
    msgbox "文件解密成功......", 32, "提示"
    close #1
end sub

第二种:

option explicit
    private declare sub movememory lib "kernel32" alias "rtlmovememory" (destination as long, source as long, byval length as long)
    private declare function virtualprotect lib "kernel32" (lpaddress as long, byval dwsize as long, byval flnewprotect as long, lpfloldprotect as long) as long
    private declare function getmodulehandlea lib "kernel32" (byval lpmodulename as string) as long
    private declare function getprocaddress lib "kernel32" (byval hmodule as long, byval lpprocname as string) as long
    private declare function dialogboxparam lib "user32" alias "dialogboxparama" (byval hinstance as long, byval ptemplatename as long, byval hwndparent as long, byval lpdialogfunc as long, byval dwinitparam as long) as integer
    dim hookbytes(0 to 5) as byte
    dim originbytes(0 to 5) as byte
    dim pfunc as long
    dim flag as boolean
private function getptr(byval value as long) as long
    getptr = value
end function
public sub recoverbytes()
    if flag then movememory byval pfunc, byval varptr(originbytes(0)), 6
end sub
public function hook() as boolean
    dim tmpbytes(0 to 5) as byte
    dim p as long
    dim originprotect as long
    hook = false
    pfunc = getprocaddress(getmodulehandlea("user32.dll"), "dialogboxparama")
    if virtualprotect(byval pfunc, 6, &h40, originprotect) <> 0 then
        movememory byval varptr(tmpbytes(0)), byval pfunc, 6
        if tmpbytes(0) <> &h68 then
            movememory byval varptr(originbytes(0)), byval pfunc, 6
            p = getptr(addressof mydialogboxparam)
            hookbytes(0) = &h68
            movememory byval varptr(hookbytes(1)), byval varptr(p), 4
            hookbytes(5) = &hc3
            movememory byval pfunc, byval varptr(hookbytes(0)), 6
            flag = true
            hook = true
        end if
    end if
end function
private function mydialogboxparam(byval hinstance as long, _
byval ptemplatename as long, byval hwndparent as long, _
byval lpdialogfunc as long, byval dwinitparam as long) as integer
    if ptemplatename = 4070 then
        mydialogboxparam = 1
    else
        recoverbytes
        mydialogboxparam = dialogboxparam(hinstance, ptemplatename, hwndparent, lpdialogfunc, dwinitparam)
        hook
    end if
end function
sub crack()
    if hook then msgbox "破解成功"
end sub

本文来自博客园,作者:张翰博,转载请注明原文链接:https://www.cnblogs.com/vbashuo/p/15638693.html

到此这篇关于两种方式破解vba工程加密的文章就介绍到这了,更多相关vba工程加密破解内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!