Skip to content

Commit 15df5d1

Browse files
Update to 1.03
1 parent d9ee9b8 commit 15df5d1

14 files changed

+267
-112
lines changed

Lazarus Source/MainUnit.lfm

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ object MainForm: TMainForm
44
Top = 23
55
Width = 754
66
AllowDropFiles = True
7-
Caption = 'UEF Reader 1.02 by Gerald J Holdsworth'
7+
Caption = 'UEF Reader 1.03 by Gerald J Holdsworth'
88
ClientHeight = 855
99
ClientWidth = 754
1010
Color = 14737632
1111
OnDropFiles = FormDropFiles
12-
LCLVersion = '2.0.12.0'
12+
LCLVersion = '2.2.0.4'
1313
object Report: TMemo
1414
Left = 0
1515
Height = 655
@@ -18,7 +18,6 @@ object MainForm: TMainForm
1818
Align = alClient
1919
BorderStyle = bsNone
2020
Font.Name = 'Courier New'
21-
Lines.Strings = ( )
2221
ParentColor = True
2322
ParentFont = False
2423
ReadOnly = True
@@ -66,7 +65,6 @@ object MainForm: TMainForm
6665
Top = 0
6766
Width = 139
6867
Caption = 'File loading progress:'
69-
ParentColor = False
7068
end
7169
object Panel3: TPanel
7270
Left = 0
@@ -85,7 +83,6 @@ object MainForm: TMainForm
8583
Align = alClient
8684
BorderStyle = bsNone
8785
Font.Name = 'Courier New'
88-
Lines.Strings = ( )
8986
ParentColor = True
9087
ParentFont = False
9188
ReadOnly = True
@@ -110,7 +107,6 @@ object MainForm: TMainForm
110107
Alignment = taRightJustify
111108
AutoSize = False
112109
Caption = 'Chunk ID:'
113-
ParentColor = False
114110
end
115111
object Label3: TLabel
116112
Left = 0
@@ -120,7 +116,6 @@ object MainForm: TMainForm
120116
Alignment = taRightJustify
121117
AutoSize = False
122118
Caption = 'Chunk Length:'
123-
ParentColor = False
124119
end
125120
object Label4: TLabel
126121
Left = 0
@@ -130,7 +125,6 @@ object MainForm: TMainForm
130125
Alignment = taRightJustify
131126
AutoSize = False
132127
Caption = 'Chunk Details:'
133-
ParentColor = False
134128
end
135129
object Label5: TLabel
136130
Left = 0
@@ -140,7 +134,6 @@ object MainForm: TMainForm
140134
Alignment = taRightJustify
141135
AutoSize = False
142136
Caption = 'Unknown chunks:'
143-
ParentColor = False
144137
end
145138
object Label6: TLabel
146139
Left = 0
@@ -150,47 +143,41 @@ object MainForm: TMainForm
150143
Alignment = taRightJustify
151144
AutoSize = False
152145
Caption = 'Number of files:'
153-
ParentColor = False
154146
end
155147
object lb_chunkID: TLabel
156148
Left = 136
157149
Height = 16
158150
Top = 0
159151
Width = 200
160152
AutoSize = False
161-
ParentColor = False
162153
end
163154
object lb_chunkLen: TLabel
164155
Left = 136
165156
Height = 16
166157
Top = 16
167158
Width = 200
168159
AutoSize = False
169-
ParentColor = False
170160
end
171161
object lb_chunkDesc: TLabel
172162
Left = 136
173163
Height = 16
174164
Top = 32
175165
Width = 200
176166
AutoSize = False
177-
ParentColor = False
178167
end
179168
object lb_chunkUnk: TLabel
180169
Left = 136
181170
Height = 16
182171
Top = 48
183172
Width = 200
184173
AutoSize = False
185-
ParentColor = False
186174
end
187175
object lb_files: TLabel
188176
Left = 136
189177
Height = 16
190178
Top = 64
191179
Width = 200
192180
AutoSize = False
193-
ParentColor = False
194181
end
195182
object UEFProgress: TProgressBar
196183
Left = 0

Lazarus Source/MainUnit.pas

Lines changed: 51 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
interface
66

77
uses
8-
Classes,SysUtils,Forms,Controls,Graphics,Dialogs,ExtCtrls,StdCtrls,Buttons,
8+
Classes,SysUtils,Forms,Controls,Dialogs,ExtCtrls,StdCtrls,Buttons,
99
ComCtrls,ZStream,crc,Global,StrUtils,Math;
1010

1111
type
@@ -50,7 +50,7 @@ TMainForm = class(TForm)
5050
function TargetMachine(machine: Byte): String;
5151
function GetCRC16(start,length: Cardinal;var buffer: TDynByteArray): Cardinal;
5252
function GetCRC32(var buffer: TDynByteArray): String;
53-
function Inflate(source: String): TDynByteArray;
53+
function Inflate(source: String;var IsInflated: Boolean): TDynByteArray;
5454
function GetIEEEFloat(input: Cardinal): Real;
5555
private
5656

@@ -96,9 +96,12 @@ procedure TMainForm.ReadUEFFile(source: String);
9696
chunklen,
9797
blocklen,
9898
blocknum,
99+
lastblock,
99100
ptr,
100101
headcrc,
101102
datacrc : Cardinal;
103+
firstblock,
104+
IsGZip,
102105
ok : Boolean;
103106
temp,
104107
line : String;
@@ -114,6 +117,7 @@ procedure TMainForm.ReadUEFFile(source: String);
114117
SetLength(files,0);
115118
baud:=1200; //Default baud rate
116119
phase:=180;
120+
IsGZip:=False;
117121
//Reset the controls
118122
Report.Clear; //The reading of the file would actually go quicker without these
119123
FileLoader.Clear; //being updated as it read.
@@ -128,7 +132,8 @@ procedure TMainForm.ReadUEFFile(source: String);
128132
//Begin the report
129133
Report.Lines.Add('File: "'+source+'"'); //Put the filename in as the first line
130134
//Open the file
131-
buffer:=Inflate(source);
135+
buffer:=Inflate(source,IsGzip);
136+
if(IsGZip)then Report.Lines.Add('File is GZipped');
132137
Report.Lines.Add('Total uncompressed file length: '
133138
+IntToStr(Length(buffer))+' bytes (0x'
134139
+IntToHex(Length(buffer),10)+')');
@@ -143,6 +148,9 @@ procedure TMainForm.ReadUEFFile(source: String);
143148
Report.Lines.Add('File is a UEF file');
144149
Report.Lines.Add('UEF version: '+IntToStr(buffer[$0A])+'.'+IntToStr(buffer[$0B]));
145150
Report.Lines.Add('');
151+
//Keep track of the last block's details
152+
lastblock:=0;
153+
firstblock:=True;
146154
//Starting position is after the magic string
147155
pos:=$0C;
148156
//Keep track of which file we are on
@@ -218,21 +226,34 @@ procedure TMainForm.ReadUEFFile(source: String);
218226
files[filenum].Filename:=temp; //Filename
219227
files[filenum].Offset :=pos-6; //Where to find it (first block)
220228
SetLength(files[filenum].Data,0);//Clear the data
221-
FileLoader.Lines.Add(temp);
222-
end;
223-
//Read in the load address
224-
files[filenum].LoadAddr:=buffer[pos+i]
225-
+buffer[pos+i+1]*$100
226-
+buffer[pos+i+2]*$10000
227-
+buffer[pos+i+3]*$1000000;
228-
//Read in the execution address
229-
files[filenum].ExecAddr:=buffer[pos+i+4]
230-
+buffer[pos+i+5]*$100
231-
+buffer[pos+i+6]*$10000
232-
+buffer[pos+i+7]*$1000000;
229+
firstblock:=True;
230+
//Read in the load address
231+
files[filenum].LoadAddr:=buffer[pos+i]
232+
+buffer[pos+i+1]*$100
233+
+buffer[pos+i+2]*$10000
234+
+buffer[pos+i+3]*$1000000;
235+
//Read in the execution address
236+
files[filenum].ExecAddr:=buffer[pos+i+4]
237+
+buffer[pos+i+5]*$100
238+
+buffer[pos+i+6]*$10000
239+
+buffer[pos+i+7]*$1000000;
240+
end else firstblock:=False;
233241
//Read in the block number
234242
blocknum:=buffer[pos+i+8]+buffer[pos+i+9]*$100;
235243
line:=line+' #'+IntToHex(blocknum,4);
244+
//Is it a new block, or copy protection?
245+
if(blocknum>0)and(firstblock)and(Length(files)>1)then
246+
if (lastblock=blocknum-1)
247+
and(files[filenum-1].Filename=files[filenum].Filename)
248+
{and(files[filenum-1].LoadAddr=files[filenum].LoadAddr)
249+
and(files[filenum-1].ExecAddr=files[filenum].ExecAddr)}then
250+
begin
251+
SetLength(files,Length(files)-1);
252+
dec(filenum);
253+
firstblock:=False;
254+
end;
255+
lastblock:=blocknum;
256+
if firstblock then FileLoader.Lines.Add(files[filenum].Filename);
236257
//Take a note of where we are in the file's data, as we build it up
237258
ptr:=files[filenum].Length;
238259
//Get the length of this block
@@ -241,6 +262,7 @@ procedure TMainForm.ReadUEFFile(source: String);
241262
inc(files[filenum].Length,blocklen);
242263
//Get the block status
243264
blockst:=buffer[pos+i+12];
265+
line:=line+' Status: '+IntToHex(blockst,2);
244266
//Get the CRC16 value for the header
245267
headcrc:=buffer[pos+i+17]+buffer[pos+i+18]*$100;
246268
//Check it is valid
@@ -497,7 +519,7 @@ function TMainForm.GetCRC32(var buffer: TDynByteArray): String;
497519
{-------------------------------------------------------------------------------
498520
Load, and inflate if it is GZipped, a UEF file
499521
-------------------------------------------------------------------------------}
500-
function TMainForm.Inflate(Source: String): TDynByteArray;
522+
function TMainForm.Inflate(Source: String;var IsInflated: Boolean): TDynByteArray;
501523
function L_Inflate(Source: String): TDynByteArray;
502524
var
503525
GZ : TGZFileStream;
@@ -554,14 +576,18 @@ function TMainForm.Inflate(Source: String): TDynByteArray;
554576
except
555577
end;
556578
F.Free;
557-
//Count how many blocks and make note of their positions
558-
for ptr:=0 to Length(buffer)-10 do
559-
if(buffer[ptr]=$1F)and(buffer[ptr+1]=$8B)and(buffer[ptr+2]=$08)then
560-
begin
561-
//Make a note of the position
562-
SetLength(blockptrs,Length(blockptrs)+1);
563-
blockptrs[Length(blockptrs)-1]:=ptr;
564-
end;
579+
//First, is it actually a GZip file?
580+
if(buffer[$00]=$1F)and(buffer[$01]=$8B)and(buffer[$02]=$08)then
581+
begin
582+
//Count how many blocks and make note of their positions
583+
for ptr:=0 to Length(buffer)-10 do
584+
if(buffer[ptr]=$1F)and(buffer[ptr+1]=$8B)and(buffer[ptr+2]=$08)then
585+
begin
586+
//Make a note of the position
587+
SetLength(blockptrs,Length(blockptrs)+1);
588+
blockptrs[Length(blockptrs)-1]:=ptr;
589+
end;
590+
end;
565591
//Separate each block, if more than one
566592
if Length(blockptrs)>1 then
567593
begin
@@ -597,6 +623,7 @@ function TMainForm.Inflate(Source: String): TDynByteArray;
597623
if Length(blockptrs)=1 then Result:=L_Inflate(Source);
598624
//If there are no blocks, then just return the entire file
599625
if Length(blockptrs)=0 then Result:=buffer;
626+
IsInflated:=Length(buffer)<>Length(Result);
600627
end;
601628

602629
{-------------------------------------------------------------------------------

0 commit comments

Comments
 (0)