首页
社区
课程
招聘
1
[转贴]发一个以前写的模拟dll的代码,保存成.dpr可以直接用delphi编译
发表于: 2004-9-7 13:18 4312

[转贴]发一个以前写的模拟dll的代码,保存成.dpr可以直接用delphi编译

2004-9-7 13:18
4312
原贴地址:
http://www.exetools.com/forum/showthread.php?t=5261

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
{
  Do not modify / remove this copyright notice
 
  Copyright(C) 2004 by parker
 
  Description: Sense KeyPro DLL Emulator
 
  Version: 1.10
 
  Last Update: 2004-2-22
 
}
 
library KeyProEmu;
 
uses
  Windows;
 
const
 
//功能码
  KeyAPIReadMemory   = $00;  //读狗数据
  KeyAPIWriteMemory  = $01;  //写狗数据
  KeyAPISetPassword  = $02;  //设置密码
  KeyAPIRemoveDriver = $03;  //卸载驱动
 
//返回值
  APISuccess         = $00;  //调用成功
  APIAddressOverflow = $01;  //软件狗数据地址越界
  APIInvalidFunction = $02;  //调用功能码非法
  APINoKeyPro        = $03;  //软件狗未找到或密码不对
  APINoKeyDriver     = $0F;  //软件狗驱动未安装
 
//一些常量
  KeyMemFile = '.\KeyData.dat'//记录软件狗数据的文件,128字节
  MemSize    = $40;              //文件长度单位是Word
  KeyMemSize = $3C;              //狗数据长度单位是Word
  Pass0      = $3C;              //密码0在文件中的位置
  Pass1      = $3D;              //密码1在文件中的位置
  Ext0       = $3E;              //扩展数据0文件中的位置
  Ext1       = $3F;              //扩展数据1文件中的位置
   
type
  pKeyproData=^KEYPRODATA;             //指向KEYPRODATA结构体的指针
  KEYPRODATA=record                    //结构体变量
    ReturnFlag: Word;                  //返回值
    FunctionCode: Word;                //功能码
    MemAddress: Word;                  //数据地址
    Password0: Word;                   //密码0
    Password1: Word;                   //密码1
    MemContent: Word;                  //读出的数据或者要写入数据
    Lock0: Word;                       //修改密码时填写,新密码0
    Lock1: Word;                       //修改密码时填写,新密码1
    Reserved: array[$0..$1F] of Word;  //保留
  end;
 
var
  TKeyMem: array [$0..MemSize - 1] of Word;  //存放软件狗数据的数组
 
{载入DLL时做的初始化动作,读取记录软件狗数据的文件,放入数组KeyMem中}
procedure DLLEnter;
var
  hFile,Count: Cardinal;
begin
  hFile:=CreateFile(KeyMemFile,GENERIC_READ,FILE_SHARE_READ,nil,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
  ReadFile(hFile, TKeyMem, SizeOf(TKeyMem), Count,nil);
  CloseHandle(hFile);
end;
 
{卸载DLL时做的收尾动作,把数组KeyMem中的内容,保存到记录软件狗数据的文件}
procedure DLLExit(const Reason:Integer);
var
  hFile,Count:Cardinal;
begin
  if Reason=DLL_PROCESS_DETACH then  //在卸载DLL时才进行保存动作
    begin
      hFile:=CreateFile(KeyMemFile,GENERIC_WRITE,FILE_SHARE_READ,nil,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
      WriteFile(hFile, TKeyMem, SizeOf(TKeyMem), Count,nil);
      CloseHandle(hFile);
    end;
end;
 
{模拟读取软件狗数据的功能}
procedure ReadMemory(const Stru:pKeyproData);
begin
  if Stru.MemAddress<KeyMemSize then  //判断要读取的狗数据的地址是否越界
  begin
    Stru.MemContent:=TKeyMem[Stru.MemAddress];
    Stru.ReturnFlag:=APISuccess;
  end
  else begin
    Stru.ReturnFlag:=APIAddressOverflow;  //地址越界
  end;
end;
 
{模拟写入软件狗数据的功能}
procedure WriteMemory(const Stru:pKeyproData);
begin
  if Stru.MemAddress<KeyMemSize then  //判断要写入的狗数据的地址是否越界
  begin
    TKeyMem[Stru.MemAddress]:=Stru.MemContent;
    Stru.ReturnFlag:=APISuccess;
  end
  else begin
    Stru.ReturnFlag:=APIAddressOverflow;  //地址越界
  end;
end;
 
{模拟设置软件狗密码的功能}
procedure SetPassword(const Stru:pKeyproData);
begin
  TKeyMem[Pass0]:=Stru.Lock0;
  TKeyMem[Pass1]:=Stru.Lock1;
  Stru.ReturnFlag:=APISuccess;
end;
 
{模拟卸载软件狗驱动的功能}
procedure RemoveDriver(const Stru:pKeyproData);
begin
  Stru.ReturnFlag:=APISuccess;
end;
 
{设置KeyproData结构体的元素的数据,主要供FoxPro使用}
procedure PutData(const Data:Word;const Stru:Integer;const Pos:Integer);stdcall;export;
var
  StruData:^Word;
begin
  StruData:=Pointer(Stru+Pos);
  StruData^:=Data;
end;
 
{读取KeyproData结构体的元素的数据,主要供FoxPro使用}
function GetData(const Stru:Integer;const Pos:Integer):Integer;stdcall;export;
var
  StruData:^Word;
begin
  StruData:=Pointer(Stru+Pos);
  Result:=StruData^;
end;
 
{模拟对软件狗的所有操作}
procedure KEYPRO(const Stru:pKeyproData);stdcall;export;
begin
 
  if TKeyMem[Ext0]=0 then  //设置是否模拟软件狗的比较密码功能
  begin                   //扩展数据为0时比较密码,为非0时不比较
    if (Stru.Password0<>TKeyMem[Pass0]) or (Stru.Password1<>TKeyMem[Pass1]) then
    begin
      Stru.ReturnFlag:=APINoKeyPro;  //密码错误
      Exit;
    end;
  end;
 
  case Stru.FunctionCode of  //根据功能码选择模拟的功能
    KeyAPIReadMemory:   ReadMemory(Stru);
    KeyAPIWriteMemory:  WriteMemory(Stru);
    KeyAPISetPassword:  SetPassword(Stru);
    KeyAPIRemoveDriver: RemoveDriver(Stru);
  else
    begin
      Stru.ReturnFlag:=APIInvalidFunction;  //功能码错误
    end;
  end;
 
end;
 
exports
  PutData,
  GetData,
  KEYPRO;
begin
  DLLProc:=@DLLExit;
  DLLEnter;
end.

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 1
支持
分享
赞赏记录
参与人
雪币
留言
时间
PLEBFE
为你点赞~
2024-3-9 00:33
最新回复 (2)
雪    币: 204
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
不错, 收着先。
不过, 因为不知道狗的原理,所以 也看不懂。
2004-9-7 13:37
0
雪    币: 205
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
代码风格不错,学习ing
2004-9-7 17:33
0
游客
登录 | 注册 方可回帖
返回

账号登录
验证码登录

忘记密码?
没有账号?立即免费注册