很多参加计算机职称考试的一些朋友肯定用过无忧考系统,这套系统把所有题库放在一些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![]()

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
