很多参加计算机职称考试的一些朋友肯定用过无忧考系统,这套系统把所有题库放在一些Access文件里面,直接用access打开看不到明文,似乎加密了,其实仔细分析下,他存储的格式是RTF,只不过去掉了些RTF文件的关键信息.为了方便浏览(因为他有一些表之间的关联),特写了一个Delphi的小工具..下面给出一些关键的代码.
1
unit MainForm;
2![]()
3
interface
4![]()
5
uses
6
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7
Dialogs, StdCtrls, Grids, DBGrids,DB,ADODB, ComCtrls;
8![]()
9
type
10
TForm1 = class(TForm)
11
Button1: TButton;
12
SaveDialog1: TSaveDialog;
13
OpenDialog1: TOpenDialog;
14
Button2: TButton;
15
Button3: TButton;
16
ProgressBar1: TProgressBar;
17
procedure Button1Click(Sender: TObject);
18
procedure Button2Click(Sender: TObject);
19
procedure Button3Click(Sender: TObject);
20
private
21
{ Private declarations }
22
public
23
{ Public declarations }
24
end;
25
function SaveFiledToFile(myfield:TField;FilePath:String;filename:String):Boolean;
26
var
27
Form1: TForm1;
28![]()
29
implementation
30![]()
31
uses DataDM,StrUtils;
32![]()
33
{$R *.dfm}
34
var
35
DataBaseName:string;
36
ResultFileName:string;
37
iCount : Integer;
38
function SaveFiledToFile(myfield:TField;FilePath:String;filename:String):Boolean;
39
var
40
bs:TADOBlobStream;
41
allPath:String;
42
begin
43
bs:=TADOBlobStream.Create(TBlobField(myfield),bmRead);
44
try
45
if RightStr(trim(FilePath),1)<>'\' then
46
allPath:=FilePath+'\'+FileName
47
else
48
allPath:=filePath+FileName;
49
if FileExists(allPath) then
50
DeleteFile(allPath);
51
bs.SaveToFile(allpath);
52
finally
53
bs.Free;
54
end;
55
Result:=True;
56
end;
57![]()
58
procedure TForm1.Button1Click(Sender: TObject);
59
var
60
titleQR : TADOQuery; //题干及答案
61
choiceQR : TADOQuery; //题选项
62
tempFile : TextFile; //临时文件
63
tempString,tsFileName: String;
64
function GetAnswer(encode:Integer):String;
65
begin
66
case encode of
67
1: Result:='A';
68
2: Result:='B';
69
4: Result:='C';
70
8: Result:='D';
71
end;
72
end;
73
begin
74![]()
75
tsFileName := ExtractFileDir(Application.ExeName)+ '\TemplateStart.txt';
76
//ShowMessage(tsfileName);exit;
77
if not FileExists(DataBaseName) then
78
begin
79
ShowMessage('源数据库文件不存在,请重新仔细选择!');
80
exit;
81
end;
82
if FileExists(ResultFileName) then
83
begin
84
if MessageDlg('目标文件已存在,继续的话将被覆盖,是否继续?',
85
mtConfirmation, [mbYes, mbNo],0) = mrNo then
86
begin
87
exit;
88
end;
89
end;
90![]()
91
if Length(ResultFileName)=0 then
92
begin
93
ShowMessage('请返回选择结果文件存放位置');
94
exit;
95
end;
96
// SetLength();
97
SetLength(tsFileName,Length(tsFileName));
98
SetLength(ResultFileName,Length(ResultFileName));
99
CopyFile(PChar(tsFileName),PChar(ResultFileName),False);
100
AssignFile(tempfile,ResultFileName);
101
Append(tempFile);
102
titleQR := TADOQuery.Create(nil);
103
GaoZhiDM.DataConn.Connected := True;
104
titleQR.Connection := GaoZhiDM.DataConn;
105
titleQr.SQL.Text := 'SELECT * FROM tbl_operation where c_recno=''010400362'' ORDER BY C_RECNO ';
106
choiceQR := TADOQuery.Create(nil);
107
choiceQR.Connection := GaoZhiDM.DataConn;
108
choiceQR.SQL.Text := 'SELECT * FROM tbl_choicevice WHERE C_recno= :recordno';
109
iCount:=0;
110
try
111
titleQR.Open;
112
ProgressBar1.Max := titleQR.RecordCount;
113
while not titleQR.Eof do
114
begin
115
{ ProgressBar1.Position := iCount;
116
Application.ProcessMessages;
117
iCount:=iCount+1;
118
tempString := IntToStr(iCount) + ':' ;
119
tempString := tempString + titleQR.FieldValues['M_TITLE'];
120
tempString := tempString+'\par ';
121![]()
122
WriteLn(tempFile,tempString);}
123
SaveFiledToFile(titleQr.FieldByName('o_rudecont'),'g:\temp','a.dat');
124
titleQr.Next;
125
end;
126
WriteLn(tempFile,' \par }}');
127
finally
128
CloseFile(tempFile);
129
if choiceQR.Active then
130
begin
131
choiceQR.Close;
132
end;
133
if titleQR.Active then
134
begin
135
titleQR.Close;
136
end;
137
titleQR.Free;
138
choiceQR.Free;
139
end;
140
ShowMessage('数据已处理完毕!');
141
end;
142![]()
143
procedure TForm1.Button2Click(Sender: TObject);
144
begin
145
if OpenDialog1.Execute then
146
begin
147
DataBaseName := OpenDialog1.FileName;
148
//Showmessage(DataBaseName);
149
if GaoZhiDM.DataConn.Connected then
150
GaoZhiDm.DataConn.Close;
151
GaoZhiDM.DataConn.ConnectionString :=
152
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+DataBaseName+';Persist Security Info=False';
153
end;
154
end;
155![]()
156
procedure TForm1.Button3Click(Sender: TObject);
157
begin
158
if SaveDialog1.Execute then
159
begin
160
ResultFileName := SaveDialog1.FileName;
161
// ShowMessage(ResultFileName);
162
end;
163
end;
164![]()
165
end.
166![]()
unit MainForm;2

3
interface4

5
uses6
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,7
Dialogs, StdCtrls, Grids, DBGrids,DB,ADODB, ComCtrls;8

9
type10
TForm1 = class(TForm)11
Button1: TButton;12
SaveDialog1: TSaveDialog;13
OpenDialog1: TOpenDialog;14
Button2: TButton;15
Button3: TButton;16
ProgressBar1: TProgressBar;17
procedure Button1Click(Sender: TObject);18
procedure Button2Click(Sender: TObject);19
procedure Button3Click(Sender: TObject);20
private21
{ Private declarations }22
public23
{ Public declarations }24
end;25
function SaveFiledToFile(myfield:TField;FilePath:String;filename:String):Boolean;26
var27
Form1: TForm1;28

29
implementation30

31
uses DataDM,StrUtils;32

33
{$R *.dfm}34
var35
DataBaseName:string;36
ResultFileName:string;37
iCount : Integer;38
function SaveFiledToFile(myfield:TField;FilePath:String;filename:String):Boolean;39
var40
bs:TADOBlobStream;41
allPath:String;42
begin43
bs:=TADOBlobStream.Create(TBlobField(myfield),bmRead);44
try45
if RightStr(trim(FilePath),1)<>'\' then46
allPath:=FilePath+'\'+FileName47
else48
allPath:=filePath+FileName;49
if FileExists(allPath) then50
DeleteFile(allPath);51
bs.SaveToFile(allpath);52
finally53
bs.Free;54
end;55
Result:=True;56
end;57

58
procedure TForm1.Button1Click(Sender: TObject);59
var60
titleQR : TADOQuery; //题干及答案61
choiceQR : TADOQuery; //题选项62
tempFile : TextFile; //临时文件63
tempString,tsFileName: String;64
function GetAnswer(encode:Integer):String;65
begin66
case encode of67
1: Result:='A';68
2: Result:='B';69
4: Result:='C';70
8: Result:='D';71
end;72
end;73
begin74

75
tsFileName := ExtractFileDir(Application.ExeName)+ '\TemplateStart.txt';76
//ShowMessage(tsfileName);exit;77
if not FileExists(DataBaseName) then78
begin79
ShowMessage('源数据库文件不存在,请重新仔细选择!');80
exit;81
end;82
if FileExists(ResultFileName) then83
begin84
if MessageDlg('目标文件已存在,继续的话将被覆盖,是否继续?',85
mtConfirmation, [mbYes, mbNo],0) = mrNo then86
begin87
exit;88
end;89
end;90

91
if Length(ResultFileName)=0 then92
begin93
ShowMessage('请返回选择结果文件存放位置');94
exit;95
end;96
// SetLength();97
SetLength(tsFileName,Length(tsFileName));98
SetLength(ResultFileName,Length(ResultFileName));99
CopyFile(PChar(tsFileName),PChar(ResultFileName),False);100
AssignFile(tempfile,ResultFileName);101
Append(tempFile);102
titleQR := TADOQuery.Create(nil);103
GaoZhiDM.DataConn.Connected := True;104
titleQR.Connection := GaoZhiDM.DataConn;105
titleQr.SQL.Text := 'SELECT * FROM tbl_operation where c_recno=''010400362'' ORDER BY C_RECNO ';106
choiceQR := TADOQuery.Create(nil);107
choiceQR.Connection := GaoZhiDM.DataConn;108
choiceQR.SQL.Text := 'SELECT * FROM tbl_choicevice WHERE C_recno= :recordno';109
iCount:=0;110
try111
titleQR.Open;112
ProgressBar1.Max := titleQR.RecordCount;113
while not titleQR.Eof do114
begin115
{ ProgressBar1.Position := iCount;116
Application.ProcessMessages;117
iCount:=iCount+1;118
tempString := IntToStr(iCount) + ':' ;119
tempString := tempString + titleQR.FieldValues['M_TITLE'];120
tempString := tempString+'\par ';121

122
WriteLn(tempFile,tempString);}123
SaveFiledToFile(titleQr.FieldByName('o_rudecont'),'g:\temp','a.dat');124
titleQr.Next;125
end;126
WriteLn(tempFile,' \par }}');127
finally128
CloseFile(tempFile);129
if choiceQR.Active then130
begin131
choiceQR.Close;132
end;133
if titleQR.Active then134
begin135
titleQR.Close;136
end;137
titleQR.Free;138
choiceQR.Free;139
end;140
ShowMessage('数据已处理完毕!');141
end;142

143
procedure TForm1.Button2Click(Sender: TObject);144
begin145
if OpenDialog1.Execute then146
begin147
DataBaseName := OpenDialog1.FileName;148
//Showmessage(DataBaseName);149
if GaoZhiDM.DataConn.Connected then150
GaoZhiDm.DataConn.Close;151
GaoZhiDM.DataConn.ConnectionString :=152
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+DataBaseName+';Persist Security Info=False';153
end;154
end;155

156
procedure TForm1.Button3Click(Sender: TObject);157
begin158
if SaveDialog1.Execute then159
begin160
ResultFileName := SaveDialog1.FileName;161
// ShowMessage(ResultFileName);162
end;163
end;164

165
end.166


浙公网安备 33010602011771号