Rev 281 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Copyright (C) 2009.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*/
package test.display;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Standalone program to display an MDR file. There is no freely available
* knowledge of the file format.
*
* Can produce a massive file, so may take some time to write.
*
* @author Steve Ratcliffe
*/
public class MdrSummary
extends CommonDisplay
{
private static final int NSECT =
41;
private final Section
[] sections =
new Section
[NSECT
];
// Sections to be displayed
private final boolean[] wanted =
new boolean[NSECT
];
protected void print
() {
reader.
position(21);
readHeader
();
Section end =
new Section
("END OF FILE", filelen,
0);
sections
[sections.
length -
1] = end
;
printDetails
();
printReverseDetails
();
}
private void printReverseDetails
() {
Section section = sections
[1];
if (section.
getRecordSize() ==
4)
return;
reader.
position(section.
getStart());
long end = section.
getEnd();
List<Integer> offsets =
new ArrayList<Integer>();
while ((reader.
position() < end
)) {
reader.
getInt();
int offset = reader.
getInt();
offsets.
add(offset
);
}
Integer[] subtotals =
new Integer[20];
for (int off : offsets
) {
reader.
position(off
);
int len = reader.
getChar();
int sub =
0;
int lastLen =
0;
while (reader.
position() < off + len
) {
sub++
;
reader.
getInt();
int sublen
;
if (sub ==
2)
sublen = lastLen
;
else
sublen = reader.
getInt();
lastLen = sublen
;
if (sublen
> 0) {
if (subtotals
[sub
] ==
null)
subtotals
[sub
] =
0;
subtotals
[sub
] += sublen
;
}
}
}
int sub =
0;
for (Integer tot : subtotals
) {
if (tot
!=
null)
System.
out.
printf("Sub%-2d %-5s total %d\n", sub, Mdr1SubFileDisplay.
subToMdr(sub
), tot
);
sub++
;
}
}
private void printDetails
() {
int number =
0;
for (Section s : sections
) {
if (s
!=
null && s.
getLen() > 0) {
System.
out.
printf("MDR %-2d ", number
);
if (s.
getRecordSize() > 0)
System.
out.
printf("NR=%-6d(%06x) RS=%-2d ",
s.
getNumberOfRecords(),
s.
getNumberOfRecords(),
s.
getRecordSize());
else
System.
out.
printf("DataSize=%-9d(%08x) ", s.
getLen(), s.
getLen());
System.
out.
printf("magic=0x%x\n", s.
getMagic());
}
number++
;
}
}
private void readHeader
() {
reader.
getChar();
int unk1 = reader.
getChar();
int unk2 = reader.
getChar();
int unk3 = reader.
getChar();
System.
out.
printf("initial values %4x %4x %4x\n", unk1, unk2, unk3
);
addSection
(1,
true,
true);
addSection
(2,
true,
true);
addSection
(3,
true,
true);
addSection
(4,
true,
true);
addSection
(5,
true,
true);
addSection
(6,
true,
true);
addSection
(7,
true,
true);
addSection
(8,
true,
true);
addSection
(9,
true,
true);
addSection
(10,
false,
true);
addSection
(11,
true,
true);
addSection
(12,
true,
true);
addSection
(13,
true,
true);
addSection
(14,
true,
true);
addSection
(15,
false,
false);
reader.
get();
addSection
(16,
true,
true);
addSection
(17,
false,
true);
addSection
(18,
true,
true);
addSection
(19,
true,
true);
addSection
(20,
true,
true);
addSection
(21,
true,
true);
addSection
(22,
true,
true);
addSection
(23,
true,
true);
addSection
(24,
true,
true);
addSection
(25,
true,
true);
addSection
(26,
true,
true);
addSection
(27,
true,
true);
addSection
(28,
true,
true);
addSection
(29,
true,
true);
addSection
(30,
true,
true);
}
private Section addSection
(int n,
boolean withReclen,
boolean withMagic
) {
long start = reader.
getInt();
int len = reader.
getInt();
Section section =
new Section
("MDR " + n, start, len
);
if (withReclen
) {
int reclen = reader.
getChar();
section.
setRecordSize(reclen
);
}
if (withMagic
) {
int magic = reader.
getInt();
section.
setMagic(magic
);
}
sections
[n
] = section
;
return section
;
}
/**
* Print a summary of an mdr file.
*/
public static void main
(String[] args
) {
if (args.
length < 1) {
System.
err.
println("Usage: mdrsummary <filename>");
System.
exit(1);
}
MdrSummary md =
new MdrSummary
();
String name = args
[0];
if (args.
length > 1) {
if (args
[1].
equals("!")) {
Arrays.
fill(md.
wanted,
true);
for (String a :
Arrays.
asList(args
).
subList(2, args.
length))
md.
wanted[Integer.
parseInt(a
)] =
false;
} else {
for (String a :
Arrays.
asList(args
).
subList(1, args.
length))
md.
wanted[Integer.
parseInt(a
)] =
true;
}
} else {
Arrays.
fill(md.
wanted,
true);
}
md.
display(name,
"MDR");
}
}