关于文件保护的
我现在有一个VB做的程序,实现的主要功能是对网络游戏进行自动更新的,
然后再通过这个VB的程序,调用执行一个VC++写的游戏的EXE文件
由于游戏的原代码不在我们这,不可能对这个EXE做什么操作
以上这些都没任何问题,已经全部实现
现在的问题是,这个EXE的游戏文件不能让用户看到,或者可以看到,但是不能直接运行,(本来是想让这个EXE需要个启动参数的,但是EXE不是我们做的,无法改变)
目前这个EXE文件可以直接启动游戏,有什么方法可以让EXE不存放在硬盘上,打到VB写的更新程序的资源文件中,然后直接释放到内存执行?
也想到过把EXE释放到硬盘,然后锁住,等游戏结束后,删除.但是这样有个问题,如果电脑掉电,下次开机后EXE不就暴露出来了吗?
现在想到的效果是,能不在硬盘上生成实体的话,最好不生成实体.如果一定要生成实体,那么有什么有效的保护措施,使玩家不可能COPY走这个EXE程序,而脱离VB的更新程序执行?
我分给的是100,不知道怎么才能给到200 300,下面显示的是(0-100)
[解决办法]
参考:
http://www.vbgood.com/viewthread.php?tid=70045&extra=page%3D1
(从内存启动一个exe)
[解决办法]
将VC的exe文件作为VB程序的资源文件,在运行VB程序时释放VC的exe文件,同时设置文件防防止,文件防防止代码如下。
在窗体代码中写入:
Option Explicit
Private Sub Form_Load()
sFileNameLock = "1.txt"'该文件为要防止复制的文件
Hook Me.hwnd
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
UnHook Me.hwnd
End Sub
在模块文件中写入:
Option Explicit
Public sFileNameLock As String
Public lpPrevWndProc As Long
Public lClipboardChain As Long
Public Const GWL_WNDPROC = -4
Public Const WM_DRAWCLIPBOARD = &H308
Public Const WM_CHANGECBCHAIN = &H30D
Public Declare Function EmptyClipboard Lib "user32" () As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long 'SetWindowLong这个函数有许多用法,这里我只讲SubClass 的用法)可以告诉Windows,当有消息发出时通知我们以及可以在哪里通知到。使用这个API,除了要把我们的程序的句柄(等于程序的标识,以便让Windows知道向谁发消息)传给它外,还需要提供一个函数的地址,这个函数有一定的格式,Windows消息的发出就是对这个函数的参数进行改变,我们根据特定参数的值来判断这个消息是什么消息。函数的格式是:Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByValwParam As Long, ByVal lParam As Long) As Long每当有消息发生时,我们的程序就是在这个函数里得知的。下面我们一边做个示例程序一边讲解吧。新建一个工程,再添加一个标准模块,模块里除了加上SetWindowLong 的声明外,再加上:
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long
Public Declare Function SetClipboardViewer Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function ChangeClipboardChain Lib "user32" (ByVal hwnd As Long, ByVal hWndNext As Long) As Long
Public Const CF_HDROP = 15
Public Type POINT
x As Long
y As Long
End Type
Public Type DROPFILES
pFiles As Long
pt As POINT
fNC As Long
fWide As Long
End Type
Public Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Public Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function CloseClipboard Lib "user32" () As Long
Public Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Sub ShowFilesOnClipboard(sFileNameLock As String)
Dim sFilePath As String
Dim lHandle As Long
Dim lpResults As Long
Dim lRet As Long
Dim df As DROPFILES
Dim strDest As String
Dim lBufferSize As Long
Dim arBuffer() As Byte
Dim vNames As Variant
Dim i As Long
If OpenClipboard(0) Then
lHandle = GetClipboardData(CF_HDROP)
' If you don't find a CF_HDROP, you don't want to process anything
If lHandle > 0 Then
lpResults = GlobalLock(lHandle)
lBufferSize = GlobalSize(lpResults)
ReDim arBuffer(0 To lBufferSize)
CopyMemory df, ByVal lpResults, Len(df)
Call CopyMemory(arBuffer(0), ByVal lpResults + df.pFiles, (lBufferSize - Len(df)))
If df.fWide = 1 Then
' it is wide chars--unicode
strDest = arBuffer
Else
strDest = StrConv(arBuffer, vbUnicode)
End If
GlobalUnlock lHandle
vNames = Split(strDest, vbNullChar)
i = 0
While Len(vNames(i)) > 0
sFilePath = vNames(i)
i = i + 1
Wend
If InStr(UCase(sFilePath), UCase(sFileNameLock)) Then Call EmptyClipboard'清除剪切板
End If
End If
CloseClipboard
End Sub
Public Sub Hook(hwnd As Long)
' 在这里使用了 AddressOf,得到的是WindowProc 函数的地址
'GWL_WNDPROC告诉SetWindowLong 函数将使用SubClass
lpPrevWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
'SubClass需要保存调用时返回的指针以便做其他处理
lClipboardChain = SetClipboardViewer(hwnd)
End Sub
Public Sub UnHook(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, lpPrevWndProc
ChangeClipboardChain hwnd, lClipboardChain
End Sub
'把WindowProc 函数完成:
Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case uMsg
Case WM_DRAWCLIPBOARD
SendMessage lClipboardChain, WM_DRAWCLIPBOARD, 0, 0
'剪贴板改变时你要做什么处理就是写在这里了.这里当复制的文件为你所防止防止的文件则清除剪切板。
Call ShowFilesOnClipboard(sFileNameLock)
Case WM_CHANGECBCHAIN
If lClipboardChain = wParam Then
lClipboardChain = lParam
End If
Case Else
WindowProc = CallWindowProc(lpPrevWndProc, hwnd, uMsg, wParam, lParam)
End Select
End Function