Fix inconsistent whitespace
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1688031 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cc909dfa75
commit
7c00beb63e
@ -43,138 +43,138 @@ import org.apache.poi.util.IntList;
|
|||||||
* down the source of corruption in a file.
|
* down the source of corruption in a file.
|
||||||
*/
|
*/
|
||||||
public class POIFSHeaderDumper {
|
public class POIFSHeaderDumper {
|
||||||
/**
|
/**
|
||||||
* Display the entries of multiple POIFS files
|
* Display the entries of multiple POIFS files
|
||||||
*
|
*
|
||||||
* @param args the names of the files to be displayed
|
* @param args the names of the files to be displayed
|
||||||
*/
|
*/
|
||||||
public static void main(final String args[]) throws Exception {
|
public static void main(final String args[]) throws Exception {
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
System.err.println("Must specify at least one file to view");
|
System.err.println("Must specify at least one file to view");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < args.length; j++) {
|
for (int j = 0; j < args.length; j++) {
|
||||||
viewFile(args[j]);
|
viewFile(args[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void viewFile(final String filename) throws Exception {
|
public static void viewFile(final String filename) throws Exception {
|
||||||
System.out.println("Dumping headers from: " + filename);
|
System.out.println("Dumping headers from: " + filename);
|
||||||
InputStream inp = new FileInputStream(filename);
|
InputStream inp = new FileInputStream(filename);
|
||||||
|
|
||||||
// Header
|
|
||||||
HeaderBlock header_block = new HeaderBlock(inp);
|
|
||||||
displayHeader(header_block);
|
|
||||||
|
|
||||||
// Raw blocks
|
|
||||||
POIFSBigBlockSize bigBlockSize = header_block.getBigBlockSize();
|
|
||||||
RawDataBlockList data_blocks = new RawDataBlockList(inp, bigBlockSize);
|
|
||||||
displayRawBlocksSummary(data_blocks);
|
|
||||||
|
|
||||||
// Main FAT Table
|
|
||||||
BlockAllocationTableReader batReader =
|
|
||||||
new BlockAllocationTableReader(
|
|
||||||
header_block.getBigBlockSize(),
|
|
||||||
header_block.getBATCount(),
|
|
||||||
header_block.getBATArray(),
|
|
||||||
header_block.getXBATCount(),
|
|
||||||
header_block.getXBATIndex(),
|
|
||||||
data_blocks);
|
|
||||||
displayBATReader("Big Blocks", batReader);
|
|
||||||
|
|
||||||
// Properties Table
|
// Header
|
||||||
PropertyTable properties =
|
HeaderBlock header_block = new HeaderBlock(inp);
|
||||||
new PropertyTable(header_block, data_blocks);
|
displayHeader(header_block);
|
||||||
|
|
||||||
// Mini Fat
|
|
||||||
BlockAllocationTableReader sbatReader =
|
|
||||||
SmallBlockTableReader._getSmallDocumentBlockReader(
|
|
||||||
bigBlockSize, data_blocks, properties.getRoot(),
|
|
||||||
header_block.getSBATStart()
|
|
||||||
);
|
|
||||||
displayBATReader("Small Blocks", sbatReader);
|
|
||||||
|
|
||||||
// Summary of the properties
|
|
||||||
displayPropertiesSummary(properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void displayHeader(HeaderBlock header_block) throws Exception {
|
// Raw blocks
|
||||||
System.out.println("Header Details:");
|
POIFSBigBlockSize bigBlockSize = header_block.getBigBlockSize();
|
||||||
System.out.println(" Block size: " + header_block.getBigBlockSize().getBigBlockSize());
|
RawDataBlockList data_blocks = new RawDataBlockList(inp, bigBlockSize);
|
||||||
System.out.println(" BAT (FAT) header blocks: " + header_block.getBATArray().length);
|
displayRawBlocksSummary(data_blocks);
|
||||||
System.out.println(" BAT (FAT) block count: " + header_block.getBATCount());
|
|
||||||
if (header_block.getBATCount() > 0)
|
|
||||||
System.out.println(" BAT (FAT) block 1 at: " + header_block.getBATArray()[0]);
|
|
||||||
System.out.println(" XBAT (FAT) block count: " + header_block.getXBATCount());
|
|
||||||
System.out.println(" XBAT (FAT) block 1 at: " + header_block.getXBATIndex());
|
|
||||||
System.out.println(" SBAT (MiniFAT) block count: " + header_block.getSBATCount());
|
|
||||||
System.out.println(" SBAT (MiniFAT) block 1 at: " + header_block.getSBATStart());
|
|
||||||
System.out.println(" Property table at: " + header_block.getPropertyStart());
|
|
||||||
System.out.println("");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void displayRawBlocksSummary(RawDataBlockList data_blocks) throws Exception {
|
// Main FAT Table
|
||||||
System.out.println("Raw Blocks Details:");
|
BlockAllocationTableReader batReader =
|
||||||
System.out.println(" Number of blocks: " + data_blocks.blockCount());
|
new BlockAllocationTableReader(
|
||||||
|
header_block.getBigBlockSize(),
|
||||||
Method gbm = data_blocks.getClass().getSuperclass().getDeclaredMethod("get", int.class);
|
header_block.getBATCount(),
|
||||||
gbm.setAccessible(true);
|
header_block.getBATArray(),
|
||||||
|
header_block.getXBATCount(),
|
||||||
for(int i=0; i<Math.min(16, data_blocks.blockCount()); i++) {
|
header_block.getXBATIndex(),
|
||||||
ListManagedBlock block = (ListManagedBlock)gbm.invoke(data_blocks, Integer.valueOf(i));
|
data_blocks);
|
||||||
byte[] data = new byte[Math.min(48, block.getData().length)];
|
displayBATReader("Big Blocks", batReader);
|
||||||
System.arraycopy(block.getData(), 0, data, 0, data.length);
|
|
||||||
|
// Properties Table
|
||||||
System.out.println(" Block #" + i + ":");
|
PropertyTable properties =
|
||||||
System.out.println(HexDump.dump(data, 0, 0));
|
new PropertyTable(header_block, data_blocks);
|
||||||
}
|
|
||||||
|
// Mini Fat
|
||||||
System.out.println("");
|
BlockAllocationTableReader sbatReader =
|
||||||
}
|
SmallBlockTableReader._getSmallDocumentBlockReader(
|
||||||
|
bigBlockSize, data_blocks, properties.getRoot(),
|
||||||
public static void displayBATReader(String type, BlockAllocationTableReader batReader) throws Exception {
|
header_block.getSBATStart()
|
||||||
System.out.println("Sectors, as referenced from the "+type+" FAT:");
|
);
|
||||||
Field entriesF = batReader.getClass().getDeclaredField("_entries");
|
displayBATReader("Small Blocks", sbatReader);
|
||||||
entriesF.setAccessible(true);
|
|
||||||
IntList entries = (IntList)entriesF.get(batReader);
|
// Summary of the properties
|
||||||
|
displayPropertiesSummary(properties);
|
||||||
for(int i=0; i<entries.size(); i++) {
|
}
|
||||||
int bn = entries.get(i);
|
|
||||||
String bnS = Integer.toString(bn);
|
public static void displayHeader(HeaderBlock header_block) throws Exception {
|
||||||
if(bn == POIFSConstants.END_OF_CHAIN) {
|
System.out.println("Header Details:");
|
||||||
bnS = "End Of Chain";
|
System.out.println(" Block size: " + header_block.getBigBlockSize().getBigBlockSize());
|
||||||
} else if(bn == POIFSConstants.DIFAT_SECTOR_BLOCK) {
|
System.out.println(" BAT (FAT) header blocks: " + header_block.getBATArray().length);
|
||||||
bnS = "DI Fat Block";
|
System.out.println(" BAT (FAT) block count: " + header_block.getBATCount());
|
||||||
} else if(bn == POIFSConstants.FAT_SECTOR_BLOCK) {
|
if (header_block.getBATCount() > 0)
|
||||||
bnS = "Normal Fat Block";
|
System.out.println(" BAT (FAT) block 1 at: " + header_block.getBATArray()[0]);
|
||||||
} else if(bn == POIFSConstants.UNUSED_BLOCK) {
|
System.out.println(" XBAT (FAT) block count: " + header_block.getXBATCount());
|
||||||
bnS = "Block Not Used (Free)";
|
System.out.println(" XBAT (FAT) block 1 at: " + header_block.getXBATIndex());
|
||||||
}
|
System.out.println(" SBAT (MiniFAT) block count: " + header_block.getSBATCount());
|
||||||
|
System.out.println(" SBAT (MiniFAT) block 1 at: " + header_block.getSBATStart());
|
||||||
System.out.println(" Block # " + i + " -> " + bnS);
|
System.out.println(" Property table at: " + header_block.getPropertyStart());
|
||||||
}
|
System.out.println("");
|
||||||
|
}
|
||||||
System.out.println("");
|
|
||||||
}
|
public static void displayRawBlocksSummary(RawDataBlockList data_blocks) throws Exception {
|
||||||
|
System.out.println("Raw Blocks Details:");
|
||||||
public static void displayPropertiesSummary(PropertyTable properties) {
|
System.out.println(" Number of blocks: " + data_blocks.blockCount());
|
||||||
System.out.println("Properties and their block start:");
|
|
||||||
displayProperties(properties.getRoot(), "");
|
Method gbm = data_blocks.getClass().getSuperclass().getDeclaredMethod("get", int.class);
|
||||||
System.out.println("");
|
gbm.setAccessible(true);
|
||||||
}
|
|
||||||
public static void displayProperties(DirectoryProperty prop, String indent) {
|
for(int i=0; i<Math.min(16, data_blocks.blockCount()); i++) {
|
||||||
indent = indent + " ";
|
ListManagedBlock block = (ListManagedBlock)gbm.invoke(data_blocks, Integer.valueOf(i));
|
||||||
System.out.println(prop.getName());
|
byte[] data = new byte[Math.min(48, block.getData().length)];
|
||||||
for (Property cp : prop) {
|
System.arraycopy(block.getData(), 0, data, 0, data.length);
|
||||||
if (cp instanceof DirectoryProperty) {
|
|
||||||
displayProperties((DirectoryProperty)cp, indent);
|
System.out.println(" Block #" + i + ":");
|
||||||
} else {
|
System.out.println(HexDump.dump(data, 0, 0));
|
||||||
// TODO
|
}
|
||||||
if (cp.shouldUseSmallBlocks()) {
|
|
||||||
|
System.out.println("");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
public static void displayBATReader(String type, BlockAllocationTableReader batReader) throws Exception {
|
||||||
}
|
System.out.println("Sectors, as referenced from the "+type+" FAT:");
|
||||||
|
Field entriesF = batReader.getClass().getDeclaredField("_entries");
|
||||||
|
entriesF.setAccessible(true);
|
||||||
|
IntList entries = (IntList)entriesF.get(batReader);
|
||||||
|
|
||||||
|
for(int i=0; i<entries.size(); i++) {
|
||||||
|
int bn = entries.get(i);
|
||||||
|
String bnS = Integer.toString(bn);
|
||||||
|
if(bn == POIFSConstants.END_OF_CHAIN) {
|
||||||
|
bnS = "End Of Chain";
|
||||||
|
} else if(bn == POIFSConstants.DIFAT_SECTOR_BLOCK) {
|
||||||
|
bnS = "DI Fat Block";
|
||||||
|
} else if(bn == POIFSConstants.FAT_SECTOR_BLOCK) {
|
||||||
|
bnS = "Normal Fat Block";
|
||||||
|
} else if(bn == POIFSConstants.UNUSED_BLOCK) {
|
||||||
|
bnS = "Block Not Used (Free)";
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(" Block # " + i + " -> " + bnS);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void displayPropertiesSummary(PropertyTable properties) {
|
||||||
|
System.out.println("Properties and their block start:");
|
||||||
|
displayProperties(properties.getRoot(), "");
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
|
public static void displayProperties(DirectoryProperty prop, String indent) {
|
||||||
|
indent = indent + " ";
|
||||||
|
System.out.println(prop.getName());
|
||||||
|
for (Property cp : prop) {
|
||||||
|
if (cp instanceof DirectoryProperty) {
|
||||||
|
displayProperties((DirectoryProperty)cp, indent);
|
||||||
|
} else {
|
||||||
|
// TODO
|
||||||
|
if (cp.shouldUseSmallBlocks()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user