PDB Extractor

2:48 pm Java, Programação

Ainda em relação ao post anterior, tive que extrair o conteúdo de um arquivo PDB (um formato de arquivo usado nos Palm’s).

Encontrei a solução parcial neste post:http://www.neowin.net/forum/index.php?s=d21af43a292e783de98d0644c0824b70&showtopic=689476&pid=590047756&st=0&#entry590047756

A solução descrita não funcionou, mas após algumas alterações na solução, serviu para o que eu precisava:

/***
* T3_allfiles
* based upon T3_APR.java from Shadowmite's forum
*
* This file will extract a binary file from it's
* Palm PDB prison. Just drop this in the directory
* that contains the *.pdb files, and run it. It'll
* get them all. Well, mostly. See next.
*
* This file is NOT made to extract the rom image.
* Use Grack's RomTool for that.
*/

import java.io.*;

public class T3_allfiles {

public static void main(String[] args) throws Exception {
File directory = new File(“/home/fabio/Desktop/pdb/”);
String[] files = directory.list(new PDBfilter());

for (String individualFile : files) {
pdb2(“/home/fabio/Desktop/pdb/” + individualFile);
}
}

static void pdb2(String file) throws Exception {
System.out.println(file);
RandomAccessFile in = new RandomAccessFile(file, “r”);
in.skipBytes(76);
int numRec = in.readShort();
int[] toc = new int[numRec];
for (int i = 0; i < numRec; ++i) {
toc[i] = in.readInt();
in.readInt();
}
for (int i = 0; i < numRec; ++i) {
in.seek(toc[i]);
short fileNameSize = in.readShort();
byte[] fn = new byte[fileNameSize];
in.read(fn);

String fileName = new String(fn);
System.out.println(“\t” + fileName);

String[] directories = fileName.split(“\\/”);
String directory = “.”;
for (int j = 0; j < directories.length – 1; j++) {
directory += File.separator + directories[j];
}
new File(directory).mkdirs();

BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fileName));

if (i < toc.length – 2) {
int bytesToRead = toc[i + 1] – toc[i] – fileNameSize – 2;
while (bytesToRead > 0) {
out.write(in.read());
bytesToRead–;
}
} else {
int b;
while ((b = in.read()) > -1) {
out.write(b);
}
}

out.close();
}
}
}

class PDBfilter implements FilenameFilter {
public boolean accept(File dir, String name) {
if (new File(dir, name).isDirectory()) {
return false;
}

name = name.toLowerCase();
return name.endsWith(“.pdb”);
}
}

One Response

  1. Jackalo Says:

    I’m glad to see that you were able to reuse the code. PDB is the most annoying format to extract files from, and it took me days to finally find that T3_APR.java file to build off of.

    Again, thanks for sharing your modifications. 🙂

Leave a Comment

Your comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

css.php