-
Notifications
You must be signed in to change notification settings - Fork 3
/
uFileReader.pas
122 lines (103 loc) · 2.42 KB
/
uFileReader.pas
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
{
******************************************************
Monkey Island Explorer
Copyright (c) 2010 - 2011 Bgbennyboy
Http://quick.mixnmojo.com
******************************************************
}
unit uFileReader;
interface
uses
Classes, SysUtils;
type
TExplorerFileStream = class (TFileStream)
private
fBigEndian: boolean;
procedure setBigEndian(const Value: boolean);
public
function ReadByte: byte; inline;
function ReadWord: word; inline;
function ReadWordBE: word; inline;
function ReadDWord: longword; inline;
function ReadDWordBE: longword; inline;
function ReadBlockName: string; inline;
function ReadString(Length: integer): string;
function ReadStringAlt(Length: integer): string;
constructor Create(FileName: string);
destructor Destroy; override;
property BigEndian: boolean read fBigEndian write setBigEndian;
end;
implementation
function TExplorerFileStream.ReadByte: byte;
begin
Read(result,1);
end;
function TExplorerFileStream.ReadWord: word;
begin
if fBigEndian then
result :=ReadWordBE
else
Read(result,2);
end;
function TExplorerFileStream.ReadWordBE: word;
begin
result:=ReadByte shl 8
+ReadByte;
end;
function TExplorerFileStream.ReadDWord: longword;
begin
if fBigEndian then
result :=ReadDWordBE
else
Read(result,4);
end;
function TExplorerFileStream.ReadDWordBE: longword;
begin
result:=ReadByte shl 24
+ReadByte shl 16
+ReadByte shl 8
+ReadByte;
end;
function TExplorerFileStream.ReadBlockName: string;
begin
result:=chr(ReadByte)+chr(ReadByte)+chr(ReadByte)+chr(ReadByte);
end;
function TExplorerFileStream.ReadString(Length: integer): string;
var
n: longword;
begin
SetLength(result,length);
for n:=1 to length do
begin
result[n]:=Chr(ReadByte);
end;
end;
function TExplorerFileStream.ReadStringAlt(Length: integer): string;
var //Replaces #0 chars with character
n: longword;
Rchar: char;
begin
SetLength(result,length);
for n:=0 to length -1 do
begin
RChar:=Chr(ReadByte);
if RChar=#0 then
result[n]:='x'
else
result[n]:=rchar;
end;
end;
procedure TExplorerFileStream.setBigEndian(const Value: boolean);
begin
fBigEndian := Value;
end;
constructor TExplorerFileStream.Create(FileName: string);
begin
inherited Create(Filename, fmopenread);
fBigEndian := false;
end;
destructor TExplorerFileStream.Destroy;
begin
inherited;
end;
end.