Add raw map dumper, and support for xtea encryption. Split datafile reading from deccryption/decompressing, allow cache client to simply save the encrypted+compressed data, too.
This commit is contained in:
79
cache/src/test/java/net/runelite/cache/MapDumperTest.java
vendored
Normal file
79
cache/src/test/java/net/runelite/cache/MapDumperTest.java
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
package net.runelite.cache;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import net.runelite.cache.fs.Archive;
|
||||
import net.runelite.cache.fs.Index;
|
||||
import net.runelite.cache.fs.Store;
|
||||
import net.runelite.cache.util.XteaKeyManager;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class MapDumperTest
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(MapDumperTest.class);
|
||||
|
||||
private static final int MAX_REGIONS = 32768;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = StoreLocation.getTemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void dump() throws IOException
|
||||
{
|
||||
File base = StoreLocation.LOCATION,
|
||||
outDir = new java.io.File("d:/rs/07/cache/maps");//folder.newFolder();
|
||||
|
||||
try (Store store = new Store(base))
|
||||
{
|
||||
store.load();
|
||||
|
||||
Index index = store.getIndex(IndexType.MAPS);
|
||||
XteaKeyManager keyManager = index.getXteaManager();
|
||||
|
||||
for (int i = 0; i < MAX_REGIONS; i++)
|
||||
{
|
||||
int[] keys = keyManager.getKeys(i);
|
||||
|
||||
int x = i >> 8;
|
||||
int y = i & 0xFF;
|
||||
|
||||
Archive map = index.findArchiveByName("m" + x + "_" + y);
|
||||
Archive land = index.findArchiveByName("l" + x + "_" + y);
|
||||
|
||||
assert (map == null) == (land == null);
|
||||
|
||||
if (map == null || land == null)
|
||||
continue;
|
||||
|
||||
assert map.getFiles().size() == 1;
|
||||
assert land.getFiles().size() == 1;
|
||||
|
||||
// maps aren't encrypted, but we don't load archive data of any archive in
|
||||
// the maps index, so load it
|
||||
map.decompressAndLoad(null);
|
||||
|
||||
byte[] data = map.getFiles().get(0).getContents();
|
||||
|
||||
Files.write(data, new File(outDir, "m" + x + "_" + y + ".dat"));
|
||||
|
||||
if (keys != null)
|
||||
{
|
||||
land.decompressAndLoad(keys);
|
||||
|
||||
data = land.getFiles().get(0).getContents();
|
||||
|
||||
if (data == null)
|
||||
continue; // key is probably wrong
|
||||
|
||||
Files.write(data, new File(outDir, "l" + x + "_" + y + ".dat"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class ModelDumperTest
|
||||
@Test
|
||||
public void test() throws IOException
|
||||
{
|
||||
java.io.File modelDir = folder.newFolder("models");
|
||||
java.io.File modelDir = new java.io.File("d:/rs/07/cache/models");//folder.newFolder("models");
|
||||
int count = 0;
|
||||
|
||||
try (Store store = new Store(StoreLocation.LOCATION))
|
||||
|
||||
@@ -42,7 +42,7 @@ public class CacheClientTest
|
||||
@Before
|
||||
public void before()
|
||||
{
|
||||
System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE");
|
||||
System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "TRACE");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package net.runelite.cache.fs;
|
||||
|
||||
import java.io.File;
|
||||
@@ -43,60 +42,86 @@ public class DataFileTest
|
||||
{
|
||||
@Rule
|
||||
public TemporaryFolder folder = StoreLocation.getTemporaryFolder();
|
||||
|
||||
|
||||
@Test
|
||||
public void test1() throws IOException
|
||||
{
|
||||
File file = folder.newFile();
|
||||
Store store = new Store(folder.getRoot());
|
||||
DataFile df = new DataFile(store, file);
|
||||
DataFileWriteResult res = df.write(42, 3, ByteBuffer.wrap("test".getBytes()), CompressionType.NONE, 0);
|
||||
DataFileReadResult res2 = df.read(42, 3, res.sector, res.compressedLength);
|
||||
byte[] buf = res2.data;
|
||||
String str = new String(buf);
|
||||
Assert.assertEquals("test", str);
|
||||
file.delete();
|
||||
|
||||
try (Store store = new Store(folder.getRoot()))
|
||||
{
|
||||
DataFile df = new DataFile(store, file);
|
||||
|
||||
byte[] compressedData = DataFile.compress("test".getBytes(), CompressionType.NONE, 0, null);
|
||||
DataFileWriteResult res = df.write(42, 3, compressedData, 0);
|
||||
|
||||
compressedData = df.read(42, 3, res.sector, res.compressedLength);
|
||||
DataFileReadResult res2 = DataFile.decompress(compressedData, null);
|
||||
|
||||
byte[] buf = res2.data;
|
||||
String str = new String(buf);
|
||||
Assert.assertEquals("test", str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test2() throws IOException
|
||||
{
|
||||
byte[] b = new byte[1024];
|
||||
for (int i = 0; i < 1024; ++i)
|
||||
{
|
||||
b[i] = (byte) i;
|
||||
|
||||
}
|
||||
|
||||
File file = folder.newFile();
|
||||
Store store = new Store(folder.getRoot());
|
||||
DataFile df = new DataFile(store, file);
|
||||
DataFileWriteResult res = df.write(42, 0x1FFFF, ByteBuffer.wrap(b), CompressionType.BZ2, 42);
|
||||
DataFileReadResult res2 = df.read(42, 0x1FFFF, res.sector, res.compressedLength);
|
||||
byte[] buf = res2.data;
|
||||
Assert.assertArrayEquals(b, buf);
|
||||
file.delete();
|
||||
|
||||
try (Store store = new Store(folder.getRoot()))
|
||||
{
|
||||
DataFile df = new DataFile(store, file);
|
||||
|
||||
byte[] compressedData = DataFile.compress(b, CompressionType.BZ2, 42, null);
|
||||
DataFileWriteResult res = df.write(42, 0x1FFFF, compressedData, 42);
|
||||
|
||||
compressedData = df.read(42, 0x1FFFF, res.sector, res.compressedLength);
|
||||
DataFileReadResult res2 = DataFile.decompress(compressedData, null);
|
||||
|
||||
byte[] buf = res2.data;
|
||||
Assert.assertArrayEquals(b, buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGZipCompression() throws IOException
|
||||
{
|
||||
try (Store store = new Store(folder.getRoot()))
|
||||
{
|
||||
DataFile df = new DataFile(store, folder.newFile());
|
||||
DataFileWriteResult res = df.write(41, 4, ByteBuffer.wrap("test".getBytes()), CompressionType.GZ, 0);
|
||||
DataFileReadResult res2 = df.read(41, 4, res.sector, res.compressedLength);
|
||||
|
||||
byte[] compressedData = DataFile.compress("test".getBytes(), CompressionType.GZ, 0, null);
|
||||
DataFileWriteResult res = df.write(41, 4, compressedData, 0);
|
||||
|
||||
compressedData = df.read(41, 4, res.sector, res.compressedLength);
|
||||
DataFileReadResult res2 = DataFile.decompress(compressedData, null);
|
||||
|
||||
byte[] buf = res2.data;
|
||||
String str = new String(buf);
|
||||
Assert.assertEquals("test", str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBZip2Compression() throws IOException
|
||||
{
|
||||
try (Store store = new Store(folder.getRoot()))
|
||||
{
|
||||
DataFile df = new DataFile(store, folder.newFile());
|
||||
DataFileWriteResult res = df.write(41, 4, ByteBuffer.wrap("test".getBytes()), CompressionType.BZ2, 5);
|
||||
DataFileReadResult res2 = df.read(41, 4, res.sector, res.compressedLength);
|
||||
|
||||
byte[] compressedData = DataFile.compress("test".getBytes(), CompressionType.BZ2, 5, null);
|
||||
DataFileWriteResult res = df.write(41, 4, compressedData, 0);
|
||||
|
||||
compressedData = df.read(41, 4, res.sector, res.compressedLength);
|
||||
DataFileReadResult res2 = DataFile.decompress(compressedData, null);
|
||||
|
||||
byte[] buf = res2.data;
|
||||
String str = new String(buf);
|
||||
Assert.assertEquals("test", str);
|
||||
@@ -107,15 +132,22 @@ public class DataFileTest
|
||||
public void testCrc() throws IOException
|
||||
{
|
||||
File file = folder.newFile();
|
||||
Store store = new Store(folder.getRoot());
|
||||
DataFile df = new DataFile(store, file);
|
||||
DataFileWriteResult res = df.write(42, 3, ByteBuffer.wrap("test".getBytes()), CompressionType.NONE, 42);
|
||||
DataFileReadResult res2 = df.read(42, 3, res.sector, res.compressedLength);
|
||||
byte[] buf = res2.data;
|
||||
String str = new String(buf);
|
||||
Assert.assertEquals("test", str);
|
||||
Assert.assertEquals(res.crc, res2.crc);
|
||||
Assert.assertEquals(42, res2.revision);
|
||||
file.delete();
|
||||
|
||||
try (Store store = new Store(folder.getRoot()))
|
||||
{
|
||||
DataFile df = new DataFile(store, file);
|
||||
|
||||
byte[] compressedData = DataFile.compress("test".getBytes(), CompressionType.NONE, 42, null);
|
||||
DataFileWriteResult res = df.write(42, 3, compressedData, 0);
|
||||
|
||||
compressedData = df.read(42, 3, res.sector, res.compressedLength);
|
||||
DataFileReadResult res2 = DataFile.decompress(compressedData, null);
|
||||
|
||||
byte[] buf = res2.data;
|
||||
String str = new String(buf);
|
||||
Assert.assertEquals("test", str);
|
||||
Assert.assertEquals(res.crc, res2.crc);
|
||||
Assert.assertEquals(42, res2.revision);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user