Rev 531 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* Copyright (C) 2018 Steve Ratcliffe
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 or
* version 2 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.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import uk.me.parabola.imgfmt.Utils;
import static uk.me.parabola.imgfmt.fs.DirectoryEntry.SLOTS_PER_ENTRY;
/**
* Display high level details of an img file such as block size.
*/
public class ImgDisplay
extends CommonDisplay
{
private int dirStart
;
protected void print
() {
Displayer d =
new Displayer
(reader
);
printHeader
(d
);
reader.
position(0x1be
);
printPartition
(d
);
printFat
(d
);
}
private void printFat
(Displayer d
) {
d.
setTitle("FAT");
reader.
position(512 * dirStart
);
int size = printOneFat
(d,
0);
for (int i =
1; dirStart + i
< size /
512; i++
)
printOneFat
(d, i
);
d.
print(outStream
);
}
private int printOneFat
(Displayer d,
int n
) {
reader.
position((dirStart + n
) * 512);
DisplayItem item = d.
byteItem();
int fl = item.
getValue();
if (fl ==
0) {
item.
addText("Empty block");
item.
addText("...");
return 0;
} else {
item.
addText("Directory block");
}
d.
stringValue(8,
"Filename: '%s'");
d.
stringValue(3,
"Ext: '%s'");
int size = d.
intValue("Size %d bytes");
d.
byteValue("Flags");
d.
charValue("Part %d");
d.
rawValue(13,
"");
char bl = d.
charValue("First block %d");
char last =
0;
for (int count =
0; bl
!= 0xffff
&& count
< SLOTS_PER_ENTRY
; bl =
(char)reader.
get2u(), count++
) {
last = bl
;
}
// Rewind before 0xffff end marker
reader.
position(reader.
position() -
4);
d.
item().
addText("...");
item = d.
item();
item.
setBytes2(last
);
item.
addText("Last block %d", item.
getValue());
d.
gap();
return size
;
}
private void printPartition
(Displayer d
) {
d.
setTitle("Partition 1");
d.
byteValue("boot %d");
d.
int3Value("first CHS sector 0x%x");
d.
byteValue("partition type %d");
d.
int3Value("last CHS sector 0x%x");
d.
intValue("First sector LBA x%x");
d.
intValue("Number of sectors %d");
// Ignore further partitions
d.
item().
addText("...");
d.
print(outStream
);
}
private void printHeader
(Displayer d
) {
d.
setTitle("Header");
d.
byteValue("XOR value %x");
d.
rawValue(9,
"");
d.
byteValue("Update Month %d");
DisplayItem item = d.
byteItem();
item.
addText("Update year %d", item.
getValue() +
1900);
d.
int3Value("");
d.
byteValue("Checksum %d");
d.
zstringValue("%s");
d.
byteValue("");
d.
charValue("%d sectors");
d.
charValue("%d heads");
d.
charValue("%d cyls");
d.
charValue("");
d.
rawValue(25,
"");
item = d.
rawItem(7);
Date date = Utils.
makeCreationTime(item.
getBytes());
DateFormat df =
new SimpleDateFormat("d MMM yyyy HH:mm:ss");
item.
addText("created %s", df.
format(date
));
dirStart = d.
byteValue("Directory start block");
d.
stringValue(8,
"%s");
d.
stringValue(20,
"Description: %s");
d.
charValue("%d heads");
d.
charValue("%d sectors");
int e1 = d.
byteValue("E1=%d");
item = d.
byteItem();
int e2 = item.
getValue();
item.
addText("E2=%d", e2
);
item.
addText("Block size=%d",
1<<(e1+e2
));
d.
charValue("Number of blocks %d");
d.
stringValue(31,
"Description (cont): %s");
d.
print(outStream
);
}
public static void main
(String[] args
) {
if (args.
length < 1) {
System.
err.
println("Usage: imgdisplay <filename>");
System.
exit(1);
}
String name = args
[0];
CommonDisplay id =
new ImgDisplay
();
id.
display(name
);
}
}