trunk contents moved to root

This commit is contained in:
Jindra Petřík
2014-05-10 20:50:57 +02:00
parent 1b851e66a8
commit 199a4d0c2b
2296 changed files with 0 additions and 0 deletions
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* 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/>.
*/
package com.jpexs.browsers.cache.chrome;
import java.io.IOException;
import java.io.InputStream;
/**
*
* @author JPEXS
*/
public class BlockFileHeader {
static final int kBlockHeaderSize = 8192; // Two pages: almost 64k entries
static final int kMaxBlocks = (kBlockHeaderSize - 80) * 8;
long magic; // c3 ca 04 c1
long version; // 00 00 02 00
int this_file;
int next_file;
int entry_size;
int num_entries;
int max_entries;
int empty[] = new int[4];
int hints[] = new int[4];
int updating;
int user[] = new int[5];
long allocation_map[] = new long[kMaxBlocks / 32];
public BlockFileHeader(InputStream is) throws IOException {
IndexInputStream iis = new IndexInputStream(is);
magic = iis.readUInt32();
version = iis.readUInt32();
this_file = iis.readInt16();
next_file = iis.readInt16();
entry_size = iis.readInt32();
num_entries = iis.readInt32();
max_entries = iis.readInt32();
empty = new int[4];
for (int i = 0; i < 4; i++) {
empty[i] = iis.readInt32();
}
hints = new int[4];
for (int i = 0; i < 4; i++) {
hints[i] = iis.readInt32();
}
updating = iis.readInt32();
user = new int[5];
for (int i = 0; i < 5; i++) {
user[i] = iis.readInt32();
}
for (int i = 0; i < allocation_map.length; i++) {
allocation_map[i] = iis.readUInt32();
}
}
}
+122
View File
@@ -0,0 +1,122 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* 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/>.
*/
package com.jpexs.browsers.cache.chrome;
import com.jpexs.browsers.cache.RafInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.util.Map;
/**
*
* @author JPEXS
*/
public class CacheAddr {
public static final int EXTERNAL = 0;
public static final int RANKINGS = 1;
public static final int BLOCK_256 = 2;
public static final int BLOCK_1K = 3;
public static final int BLOCK_4K = 4;
public static final int BLOCK_FILES = 5;
public static final int BLOCK_ENTRIES = 6;
public static final int BLOCK_EVICTED = 7;
public static final String blockNames[] = new String[]{"EXTERNAL", "RANKINGS", "BLOCK_256", "BLOCK_1K", "BLOCK_4K", "BLOCK_FILES", "BLOCK_ENTRIES", "BLOCK_EVICTED"};
public static final int blockSizes[] = new int[]{0, 36, 256, 1024, 4096, 8, 104, 48};
public static final long kInitializedMask = 0x80000000L;
public static final long kFileTypeMask = 0x70000000L;
public static final int kFileTypeOffset = 28;
public static final long kReservedBitsMask = 0x0c000000L;
public static final long kNumBlocksMask = 0x03000000L;
public static final int kNumBlocksOffset = 24;
public static final long kFileSelectorMask = 0x00ff0000L;
public static final int FileSelectorOffset = 16;
public static final long kStartBlockMask = 0x0000FFFFL;
public static final long kFileNameMask = 0x0FFFFFFFL;
public boolean initialized;
public int fileType;
public int numBlocks;
public int fileSelector;
public int startBlock;
public int fileName;
public long val;
public File rootPath;
private final Map<Integer, RandomAccessFile> dataFiles;
private final File externalFilesDir;
public CacheAddr(InputStream is, File rootPath, Map<Integer, RandomAccessFile> dataFiles, File externalFilesDir) throws IOException {
this.dataFiles = dataFiles;
this.rootPath = rootPath;
this.externalFilesDir = externalFilesDir;
IndexInputStream iis = new IndexInputStream(is);
val = iis.readUInt32();
initialized = (val & kInitializedMask) == kInitializedMask;
fileType = (int) ((val & kFileTypeMask) >> kFileTypeOffset);
if (fileType == EXTERNAL) {
fileName = (int) (val & kFileNameMask);
} else {
numBlocks = (int) ((val & kNumBlocksMask) >> kNumBlocksOffset);
fileSelector = (int) ((val & kFileSelectorMask) >> FileSelectorOffset);
startBlock = (int) (val & kStartBlockMask);
}
}
@Override
public String toString() {
String ft = blockNames[fileType];
if (fileType == EXTERNAL) {
return ft + ":" + fileName;
}
if (!initialized) {
return "uninitialized";
}
return ft + ": numBlocks " + numBlocks + " fileSelector " + fileSelector + " startBlock " + startBlock;
}
public InputStream getInputStream() throws IOException {
if (!initialized) {
return null;
}
switch (fileType) {
case EXTERNAL:
String fileNameStr = Long.toHexString(fileName);
while (fileNameStr.length() < 6) {
fileNameStr = "0" + fileNameStr;
}
fileNameStr = "f_" + fileNameStr;
return new RafInputStream(new RandomAccessFile(new File(externalFilesDir, fileNameStr), "r"));
case BLOCK_1K:
case BLOCK_256:
case BLOCK_4K:
RandomAccessFile raf;
if (dataFiles.containsKey(fileSelector)) {
raf = dataFiles.get(fileSelector);
} else {
raf = new RandomAccessFile(rootPath + "\\data_" + fileSelector, "r");
dataFiles.put(fileSelector, raf);
}
raf.seek(BlockFileHeader.kBlockHeaderSize + startBlock * blockSizes[fileType]);
return new RafInputStream(raf);
}
return null;
}
}
+194
View File
@@ -0,0 +1,194 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* 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/>.
*/
package com.jpexs.browsers.cache.chrome;
import com.jpexs.browsers.cache.CacheEntry;
import com.jpexs.browsers.cache.CacheImplementation;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public class ChromeCache implements CacheImplementation {
private static ChromeCache instance;
private File tempDir;
private List<File> dataFiles;
private File indexFile;
private ChromeCache() {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
free();
}
});
}
public static ChromeCache getInstance() {
if (instance == null) {
instance = new ChromeCache();
}
return instance;
}
private boolean loaded = false;
private Index index;
@Override
public List<CacheEntry> getEntries() {
if (!loaded) {
refresh();
}
if (!loaded) {
return null;
}
List<CacheEntry> ret = new ArrayList<>();
try {
List<EntryStore> entries = index.getEntries();
for (EntryStore en : entries) {
if (en.state == EntryStore.ENTRY_NORMAL) {
String key = en.getKey();
if (key != null && !key.trim().isEmpty()) {
ret.add(en);
}
}
}
} catch (IOException ex) {
Logger.getLogger(ChromeCache.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
return ret;
}
@Override
public void refresh() {
free();
File cacheDir = null;
try {
cacheDir = getCacheDirectory();
} catch (IOException ex) {
Logger.getLogger(ChromeCache.class.getName()).log(Level.SEVERE, null, ex);
}
if (cacheDir == null) {
return;
}
File systemTempDir = new File(System.getProperty("java.io.tmpdir"));
File originalIndexFile = new File(cacheDir + File.separator + "index");
tempDir = new File(systemTempDir, "cacheView" + System.identityHashCode(this));
tempDir.mkdir();
indexFile = new File(tempDir, "index");
try {
Files.copy(originalIndexFile.toPath(), indexFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException ex) {
Logger.getLogger(ChromeCache.class.getName()).log(Level.SEVERE, null, ex);
return;
}
File originalDataFile;
dataFiles = new ArrayList<>();
for (int i = 0; (originalDataFile = new File(cacheDir, "data_" + i)).exists(); i++) {
File dataFile = new File(tempDir, "data_" + i);
dataFiles.add(dataFile);
try {
Files.copy(originalDataFile.toPath(), dataFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException ex) {
Logger.getLogger(ChromeCache.class.getName()).log(Level.SEVERE, null, ex);
return;
}
}
try {
index = new Index(indexFile, cacheDir);
} catch (IOException ex) {
Logger.getLogger(ChromeCache.class.getName()).log(Level.SEVERE, null, ex);
}
loaded = true;
}
private enum OSId {
WINDOWS, OSX, UNIX
}
private static OSId getOSId() {
PrivilegedAction<String> doGetOSName = new PrivilegedAction<String>() {
@Override
public String run() {
return System.getProperty("os.name");
}
};
OSId id = OSId.UNIX;
String osName = AccessController.doPrivileged(doGetOSName);
if (osName != null) {
if (osName.toLowerCase().startsWith("mac os x")) {
id = OSId.OSX;
} else if (osName.contains("Windows")) {
id = OSId.WINDOWS;
}
}
return id;
}
public static File getCacheDirectory() throws IOException {
String userHome = null;
File ret = null;
try {
userHome = System.getProperty("user.home");
} catch (SecurityException ignore) {
}
if (userHome != null) {
OSId osId = getOSId();
if (osId == OSId.WINDOWS) {
ret = new File(userHome + "\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Cache\\");
if (!ret.exists()) {
ret = new File(userHome + "\\Local Settings\\Application Data\\Google\\Chrome\\User Data\\Default\\Cache");
}
} else if (osId == OSId.OSX) {
ret = new File(userHome + "/Library/Caches/Google/Chrome/Default/Cache");
} else {
ret = new File(userHome + "/.config/google-chrome/Default/Application Cache/Cache/");
if (!ret.exists()) {
ret = new File(userHome + "/.cache/chromium/Default/Cache");
}
}
}
if ((ret != null) && !ret.exists()) {
return null;
}
return ret;
}
private void free() {
if (loaded) {
index.free();
indexFile.delete();
for (File d : dataFiles) {
d.delete();
}
tempDir.delete();
}
}
}
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* 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/>.
*/
package com.jpexs.browsers.cache.chrome;
/**
*
* @author JPEXS
*/
public class EntryFlags {
public static final int PARENT_ENTRY = 1;
public static final int CHILD_ENTRY = 1 << 1;
}
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* 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/>.
*/
package com.jpexs.browsers.cache.chrome;
/**
*
* @author JPEXS
*/
public class EntryState {
public static final int ENTRY_NORMAL = 0;
public static final int ENTRY_EVICTED = 1;
public static final int ENTRY_DOOMED = 2;
}
+153
View File
@@ -0,0 +1,153 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* 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/>.
*/
package com.jpexs.browsers.cache.chrome;
import com.jpexs.browsers.cache.CacheEntry;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public class EntryStore extends CacheEntry {
public static final int ENTRY_NORMAL = 0;
public static final int ENTRY_EVICTED = 1; // The entry was recently evicted from the cache.
public static final int ENTRY_DOOMED = 2; // The entry was doomed
public static final int PARENT_ENTRY = 1; // This entry has children (sparse) entries.
public static final int CHILD_ENTRY = 1 << 1;
public long hash; // Full hash of the key.
public CacheAddr next; // Next entry with the same hash or bucket.
public CacheAddr rankings_node; // Rankings node for this entry.
public int reuse_count; // How often is this entry used.
public int refetch_count; // How often is this fetched from the net.
public int state; // Current state.
public long creation_time;
public int key_len;
public CacheAddr long_key; // Optional address of a long key.
public int data_size[] = new int[4]; // We can store up to 4 data streams for each
public CacheAddr data_addr[] = new CacheAddr[4]; // entry.
public long flags; // Any combination of EntryFlags.
public int pad[] = new int[4];
public long self_hash; // The hash of EntryStore up to this point.
public byte key[] = new byte[256 - 24 * 4]; // null terminated
public EntryStore(InputStream is, File rootDir, Map<Integer, RandomAccessFile> dataFiles, File externalFilesDir) throws IOException {
IndexInputStream iis = new IndexInputStream(is);
hash = iis.readUInt32();
next = new CacheAddr(is, rootDir, dataFiles, externalFilesDir);
rankings_node = new CacheAddr(is, rootDir, dataFiles, externalFilesDir);
reuse_count = iis.readInt32();
refetch_count = iis.readInt32();
state = iis.readInt32();
creation_time = iis.readUInt64();
key_len = iis.readInt32();
long_key = new CacheAddr(is, rootDir, dataFiles, externalFilesDir);
data_size = new int[4];
for (int i = 0; i < 4; i++) {
data_size[i] = iis.readInt32();
}
data_addr = new CacheAddr[4];
for (int i = 0; i < 4; i++) {
data_addr[i] = new CacheAddr(is, rootDir, dataFiles, externalFilesDir);
}
flags = iis.readUInt32();
pad = new int[4];
for (int i = 0; i < 4; i++) {
pad[i] = iis.readInt32();
}
self_hash = iis.readUInt32();
key = new byte[256 - 24 * 4];
iis.read(key);
}
public HttpResponseInfo getResponseInfo() {
try {
InputStream is = data_addr[0].getInputStream();
if (is == null) {
return null;
}
return new HttpResponseInfo(is);
} catch (IOException ex) {
Logger.getLogger(EntryStore.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}
public int getResponseDataSize() {
return data_size[1];
}
@Override
public InputStream getResponseRawDataStream() {
try {
return data_addr[1].getInputStream();
} catch (IOException ex) {
Logger.getLogger(EntryStore.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public String getKey() {
if (key_len < 0) {
return null;
}
return new String(key, 0, key_len > key.length || key_len < 0 ? key.length : key_len);
}
@Override
public String getRequestURL() {
return getKey();
}
@Override
public Map<String, String> getResponseHeaders() {
HttpResponseInfo ri = getResponseInfo();
if (ri == null) {
return new HashMap<>();
}
List<String> headers = ri.headers;
Map<String, String> ret = new HashMap<>();
for (int h = 1; h < headers.size(); h++) {
String hs = headers.get(h);
if (hs.contains(":")) {
String hp[] = hs.split(":");
ret.put(hp[0].trim(), hp[1].trim());
}
}
return ret;
}
@Override
public String getStatusLine() {
HttpResponseInfo ri = getResponseInfo();
return ri.headers.get(0);
}
@Override
public String getRequestMethod() {
return "GET";
}
}
@@ -0,0 +1,107 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* 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/>.
*/
package com.jpexs.browsers.cache.chrome;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author JPEXS
*/
public class HttpResponseInfo {
public long flags;
public int version;
public long request_time;
public long response_time;
public long payload_size;
public List<String> headers;
// The version of the response info used when persisting response info.
public static final int RESPONSE_INFO_VERSION = 3;
// The minimum version supported for deserializing response info.
public static final int RESPONSE_INFO_MINIMUM_VERSION = 1;
// We reserve up to 8 bits for the version number.
public static final int RESPONSE_INFO_VERSION_MASK = 0xFF;
// This bit is set if the response info has a cert at the end.
// Version 1 serialized only the end-entity certificate, while subsequent
// versions include the available certificate chain.
public static final int RESPONSE_INFO_HAS_CERT = 1 << 8;
// This bit is set if the response info has a security-bits field (security
// strength, in bits, of the SSL connection) at the end.
public static final int RESPONSE_INFO_HAS_SECURITY_BITS = 1 << 9;
// This bit is set if the response info has a cert status at the end.
public static final int RESPONSE_INFO_HAS_CERT_STATUS = 1 << 10;
// This bit is set if the response info has vary header data.
public static final int RESPONSE_INFO_HAS_VARY_DATA = 1 << 11;
// This bit is set if the request was cancelled before completion.
public static final int RESPONSE_INFO_TRUNCATED = 1 << 12;
// This bit is set if the response was received via SPDY.
public static final int RESPONSE_INFO_WAS_SPDY = 1 << 13;
// This bit is set if the request has NPN negotiated.
public static final int RESPONSE_INFO_WAS_NPN = 1 << 14;
// This bit is set if the request was fetched via an explicit proxy.
public static final int RESPONSE_INFO_WAS_PROXY = 1 << 15;
// This bit is set if the response info has an SSL connection status field.
// This contains the ciphersuite used to fetch the resource as well as the
// protocol version, compression method and whether SSLv3 fallback was used.
public static final int RESPONSE_INFO_HAS_SSL_CONNECTION_STATUS = 1 << 16;
// This bit is set if the response info has protocol version.
public static final int RESPONSE_INFO_HAS_NPN_NEGOTIATED_PROTOCOL = 1 << 17;
// This bit is set if the response info has connection info.
public static final int RESPONSE_INFO_HAS_CONNECTION_INFO = 1 << 18;
// This bit is set if the request has http authentication.
public static final int RESPONSE_INFO_USE_HTTP_AUTHENTICATION = 1 << 19;
public String getHeaderValue(String header) {
for (String h : headers) {
if (h.contains(":")) {
String keyval[] = h.split(":");
String key = keyval[0].trim().toLowerCase();
String val = keyval[1].trim();
if (header.toLowerCase().equals(key)) {
return val;
}
}
}
return null;
}
public HttpResponseInfo(InputStream is) throws IOException {
IndexInputStream iis = new IndexInputStream(is);
payload_size = iis.readUInt32();
flags = iis.readInt();
version = (int) (flags & RESPONSE_INFO_VERSION_MASK);
if (version < RESPONSE_INFO_MINIMUM_VERSION || version > RESPONSE_INFO_VERSION) {
throw new RuntimeException("unexpected response info version: " + version);
}
request_time = iis.readInt64();
response_time = iis.readInt64();
String headersStr = iis.readString();
headers = new ArrayList<>();
int nulpos;
while ((nulpos = headersStr.indexOf(0)) > 0) {
String h = headersStr.substring(0, nulpos);
headersStr = headersStr.substring(nulpos + 1);
headers.add(h);
}
//TODO: Read SSL info
}
}
+79
View File
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* 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/>.
*/
package com.jpexs.browsers.cache.chrome;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author JPEXS
*/
public class Index {
IndexHeader header;
CacheAddr table[];
public static final int kIndexTablesize = 0x10000;
public File rootDir;
private final Map<Integer, RandomAccessFile> dataFiles;
private final File externalFilesDir;
public void free() {
for (RandomAccessFile r : dataFiles.values()) {
try {
r.close();
} catch (IOException ex) {
}
}
}
public List<EntryStore> getEntries() throws IOException {
List<EntryStore> ret = new ArrayList<>();
for (CacheAddr ca : table) {
InputStream is = ca.getInputStream();
if (is != null) {
EntryStore es = new EntryStore(is, rootDir, dataFiles, externalFilesDir);
ret.add(es);
}
}
return ret;
}
public Index(File file, File externalFilesDir) throws IOException {
dataFiles = new HashMap<>();
this.externalFilesDir = externalFilesDir;
try (FileInputStream is = new FileInputStream(file)) {
rootDir = file.getParentFile();
header = new IndexHeader(is, rootDir, dataFiles, externalFilesDir);
int tsize = kIndexTablesize;
if (header.table_len > 0) {
tsize = header.table_len;
}
table = new CacheAddr[tsize];
for (int i = 0; i < tsize; i++) {
table[i] = new CacheAddr(is, rootDir, dataFiles, externalFilesDir);
}
}
}
}
+64
View File
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* 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/>.
*/
package com.jpexs.browsers.cache.chrome;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.util.Map;
/**
*
* @author JPEXS
*/
public class IndexHeader {
long magic; //c3 ca 03 c1
long version; //01 00 02 00
int num_entries;
int num_bytes;
int last_file;
int this_id;
CacheAddr stats;
int table_len;
int crash;
int experiment;
long create_time;
int pad[] = new int[52];
LruData lru;
public IndexHeader(InputStream is, File rootDir, Map<Integer, RandomAccessFile> dataFiles, File externalFilesDir) throws IOException {
IndexInputStream iis = new IndexInputStream(is);
magic = iis.readUInt32();
version = iis.readUInt32();
num_entries = iis.readInt32();
num_bytes = iis.readInt32();
last_file = iis.readInt32();
this_id = iis.readInt32();
stats = new CacheAddr(iis, rootDir, dataFiles, externalFilesDir);
table_len = iis.readInt32();
crash = iis.readInt32();
experiment = iis.readInt32();
create_time = iis.readUInt64();
pad = new int[52];
for (int i = 0; i < 52; i++) {
pad[i] = iis.readInt32();
}
lru = new LruData(is, rootDir, dataFiles, externalFilesDir);
}
}
@@ -0,0 +1,79 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* 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/>.
*/
package com.jpexs.browsers.cache.chrome;
import java.io.IOException;
import java.io.InputStream;
/**
*
* @author JPEXS
*/
public class IndexInputStream extends InputStream {
private final InputStream is;
public long pos = 0;
public long getPos() {
return pos;
}
public IndexInputStream(InputStream is) {
this.is = is;
}
@Override
public int read() throws IOException {
int r = is.read();
//System.out.print("$"+Integer.toHexString(r));
pos++;
return r;
}
public long readUInt32() throws IOException {
long r = (((long) read()) + ((long) (read() << 8)) + ((long) (read() << 16)) + ((long) (read() << 24))) & 0xffffffffL;
//System.out.println("");
return r;
}
public long readUInt64() throws IOException {
return readUInt32() + (readUInt32() << 32);
}
public long readInt64() throws IOException {
return readUInt64(); //FIXME
}
public int readInt32() throws IOException {
return (int) readUInt32();
}
public int readInt16() throws IOException {
return (short) ((int) read() + (int) (read() << 8));
}
public long readInt() throws IOException {
return readInt32();
}
public String readString() throws IOException {
int len = (int) readInt();
byte data[] = new byte[len];
read(data);
return new String(data);
}
}
+71
View File
@@ -0,0 +1,71 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* 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/>.
*/
package com.jpexs.browsers.cache.chrome;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.util.Map;
/**
*
* @author JPEXS
*/
public class LruData {
int pad1[] = new int[2];
int filled;
int sizes[] = new int[5];
CacheAddr heads[] = new CacheAddr[5];
CacheAddr tails[] = new CacheAddr[5];
CacheAddr transaction;
int operation;
int operation_list;
int pad2[] = new int[7];
public LruData(InputStream is, File rootDir, Map<Integer, RandomAccessFile> dataFiles, File externalFilesDir) throws IOException {
IndexInputStream iis = new IndexInputStream(is);
pad1 = new int[2];
pad1[0] = iis.readInt32();
pad1[1] = iis.readInt32();
filled = iis.readInt32();
sizes = new int[5];
for (int i = 0; i < 5; i++) {
sizes[i] = iis.readInt32();
}
sizes = new int[5];
for (int i = 0; i < 5; i++) {
sizes[i] = iis.readInt32();
}
heads = new CacheAddr[5];
for (int i = 0; i < 5; i++) {
heads[i] = new CacheAddr(is, rootDir, dataFiles, externalFilesDir);
}
tails = new CacheAddr[5];
for (int i = 0; i < 5; i++) {
tails[i] = new CacheAddr(is, rootDir, dataFiles, externalFilesDir);
}
transaction = new CacheAddr(is, rootDir, dataFiles, externalFilesDir);
operation = iis.readInt32();
operation_list = iis.readInt32();
pad2 = new int[7];
for (int i = 0; i < 7; i++) {
pad2[i] = iis.readInt32();
}
}
}
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2010-2014 JPEXS
*
* 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/>.
*/
package com.jpexs.browsers.cache.chrome;
/**
*
* @author JPEXS
*/
public class RankingsNode {
public long last_used;
public long last_modified;
CacheAddr next;
CacheAddr prev;
CacheAddr contents;
int dirty;
long self_hash;
}