package ole;
import pptViewer.PptException;
/**
* Die DIF zum Auffinden von FAT-Sektoren, die nicht mehr im Header gespeichert sind
* @author Michael Roth <michi.ro@gmx.de>
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
public class DIF {
private int[] data;
private OleFile file;
public DIF(OleFile oleFile) throws PptException {
System.out.println("Initialising DIF:");
this.file = oleFile;
if (oleFile.getHeader().getCountDif()>0)
data = new int[oleFile.getHeader().getCountDif()];
int DifPointer = oleFile.getHeader().getSecDifStart();
int n=0;
while (DifPointer != OleFile.ENDOFCHAIN) {
System.out.println(" "+n+": "+DifPointer);
this.data[n++]=DifPointer;
byte[] dataArray = oleFile.getBlock(oleFile.getHeader().getSecDifStart());
DifPointer = dataArray[oleFile.getHeader().getSecSize()-4]|(dataArray[oleFile.getHeader().getSecSize()-3]<<8)|(dataArray[oleFile.getHeader().getSecSize()-2]<<16)|(dataArray[oleFile.getHeader().getSecSize()-1]<<24);
}
System.out.println(" CountDif: "+oleFile.getHeader().getCountDif());
}
/**
* Liefert die Position des gesuchten DIF-Sektors in der Datei
* @param n gesuchter Sektor in der DIF-Sektorkette
* @return Die Sektornummer in der Datei
*/
public int getDifBlockSec(int n) {
if (this.data != null) return this.data[n];
else return OleFile.ENDOFCHAIN;
}
/**
* Liefert den Inhalt des gesuchten DIf-Sektors
* @param n gesuchter Sektor in der DIF-Sektorkette
* @return Der Inhalt des Sektors
* @throws PptException
*/
public byte[] getDifBlock(int n) throws PptException {
if (this.data != null) return this.file.getBlock(this.data[n]);
else throw new PptException("unknown block "+n);
}
}