最近有朋友问到如何防止pbd文件被替换。
其实还有类似问题,比如防止dll被替换,防止其他文件被替换。
可以采用三个方法
- 取文件md5作为特征码,在程序的open里面校验,文件编译后生成的md5放入一个ini中(经过变化或者杂糅成多个文件的长串)。特点任何字节改变都会被判定,缺点,计算比较慢,影响启动。
- 取文件某个字节或者多个字节即可。比计算md5有效率。因为修改后的文件多半是经过重新编译的。所以文件体积会变化。一般取前中后的某个位置的字节,比如前面第250-253三个字节,中间的三个,末尾倒数255的三个字节来对比即可。这是一个比较快的方法。
3.每个文件做一个对象,专门作为编译日期校验的作用,我这里设计一个用户对象。
forward
global type uo_filename_date from nonvisualobject
end type
end forward
global type uo_filename_date from nonvisualobject autoinstantiate
end type
type variables
date filedate = today() //这里会静态编译成当时的日期
end variables
on uo_dwhttp_date.create
call super::create
TriggerEvent( this, “constructor” )
end on
on uo_dwhttp_date.destroy
TriggerEvent( this, “destructor” )
call super::destroy
end on
在启动时进行判断。
date thisdate = today()
uo_dwhttp_date uo_dwhttp_date
if uo_dwhttp_date.filedate < thisdate then
messagebox(“提示”,”文件日期是旧的,不能运行!”)
halt
end if