L2ClientDat decoder.
This commit is contained in:
90
L2ClientDat/java/com/l2jmobius/actions/MassRecryptor.java
Normal file
90
L2ClientDat/java/com/l2jmobius/actions/MassRecryptor.java
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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.l2jmobius.actions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import com.l2jmobius.L2ClientDat;
|
||||
import com.l2jmobius.clientcryptor.DatFile;
|
||||
import com.l2jmobius.clientcryptor.crypt.DatCrypter;
|
||||
|
||||
public class MassRecryptor
|
||||
{
|
||||
private static final MassRecryptor _instance = new MassRecryptor();
|
||||
|
||||
public static MassRecryptor getInstance()
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public void recrypt(String chronicle, String path, DatCrypter decCrypter, DatCrypter enCrypter)
|
||||
{
|
||||
L2ClientDat.addLogConsole("Mass recrypt with using " + chronicle + " chronicles by path [" + path + "]", true);
|
||||
File baseDir = new File(path);
|
||||
if (!baseDir.exists())
|
||||
{
|
||||
L2ClientDat.addLogConsole("Directory [" + path + "] does not exists.", true);
|
||||
return;
|
||||
}
|
||||
String recryptDirPath = path + "/" + "!recrypted";
|
||||
File recryptDir = new File(recryptDirPath);
|
||||
if (!recryptDir.exists() && !recryptDir.mkdir())
|
||||
{
|
||||
L2ClientDat.addLogConsole("Cannot create recrypt directory [" + recryptDirPath + "].", true);
|
||||
return;
|
||||
}
|
||||
long startTime = System.currentTimeMillis();
|
||||
for (File file : baseDir.listFiles(pathname -> pathname.getName().endsWith(".dat") || pathname.getName().endsWith(".ini") || pathname.getName().endsWith(".htm")))
|
||||
{
|
||||
try
|
||||
{
|
||||
try (FileInputStream fis = new FileInputStream(file);)
|
||||
{
|
||||
if (fis.available() < 28)
|
||||
{
|
||||
L2ClientDat.addLogConsole(file.getName() + " The file is too small.", true);
|
||||
return;
|
||||
}
|
||||
byte[] head = new byte[28];
|
||||
fis.read(head);
|
||||
String header = new String(head, "UTF-16LE");
|
||||
if (!header.startsWith("Lineage2Ver"))
|
||||
{
|
||||
L2ClientDat.addLogConsole("File " + file.getName() + " not encrypted. Skip decrypt.", true);
|
||||
continue;
|
||||
}
|
||||
if (Integer.valueOf(header.substring(11)).intValue() != decCrypter.getCode())
|
||||
{
|
||||
L2ClientDat.addLogConsole("File " + file.getName() + " encrypted code: " + header + ". Skip decrypt.", true);
|
||||
continue;
|
||||
}
|
||||
L2ClientDat.addLogConsole("Recrypting [" + file.getName() + "]", true);
|
||||
DatFile dat = new DatFile(file.getAbsolutePath());
|
||||
dat.decrypt(decCrypter);
|
||||
DatFile.encrypt(dat.getBuff().array(), recryptDirPath + "/" + file.getName(), enCrypter);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
L2ClientDat.addLogConsole(file.getName() + " Decrypt failed.", true);
|
||||
}
|
||||
}
|
||||
long diffTime = (System.currentTimeMillis() - startTime) / 1000L;
|
||||
L2ClientDat.addLogConsole("Completed. Elapsed ".concat(String.valueOf(diffTime)).concat(" sec"), true);
|
||||
}
|
||||
}
|
134
L2ClientDat/java/com/l2jmobius/actions/MassTxtPacker.java
Normal file
134
L2ClientDat/java/com/l2jmobius/actions/MassTxtPacker.java
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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.l2jmobius.actions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import com.l2jmobius.L2ClientDat;
|
||||
import com.l2jmobius.clientcryptor.DatFile;
|
||||
import com.l2jmobius.clientcryptor.crypt.DatCrypter;
|
||||
import com.l2jmobius.config.ConfigDebug;
|
||||
import com.l2jmobius.data.GameDataName;
|
||||
import com.l2jmobius.util.DebugUtil;
|
||||
import com.l2jmobius.xml.Descriptor;
|
||||
import com.l2jmobius.xml.DescriptorParser;
|
||||
import com.l2jmobius.xml.DescriptorWriter;
|
||||
import com.l2jmobius.xml.exceptions.PackDataException;
|
||||
|
||||
public class MassTxtPacker
|
||||
{
|
||||
private static final MassTxtPacker _instance = new MassTxtPacker();
|
||||
|
||||
public static MassTxtPacker getInstance()
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public void pack(String chronicle, String path, DatCrypter crypter) throws Exception
|
||||
{
|
||||
L2ClientDat.addLogConsole("Mass packer with using " + chronicle + " chronicles by path [" + path + "]", true);
|
||||
File baseDir = new File(path);
|
||||
if (!baseDir.exists())
|
||||
{
|
||||
L2ClientDat.addLogConsole("Directory [" + path + "] does not exists.", true);
|
||||
return;
|
||||
}
|
||||
String packDirPath = path + "/" + "!packed";
|
||||
File packDir = new File(packDirPath);
|
||||
if (!packDir.exists() && !packDir.mkdir())
|
||||
{
|
||||
L2ClientDat.addLogConsole("Cannot create directory [" + packDir + "].", true);
|
||||
return;
|
||||
}
|
||||
File[] fList = baseDir.listFiles(pathname -> crypter.checkFileExtension(pathname.getName()));
|
||||
GameDataName.getInstance().clear();
|
||||
long startTime = System.currentTimeMillis();
|
||||
CountDownLatch doneSignal = new CountDownLatch(fList.length);
|
||||
Semaphore semaphore = new Semaphore(Runtime.getRuntime().availableProcessors());
|
||||
for (File file : fList)
|
||||
{
|
||||
new Thread(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
semaphore.acquire();
|
||||
L2ClientDat.addLogConsole("Packing [" + file.getName() + "]", true);
|
||||
try
|
||||
{
|
||||
byte[] buff = null;
|
||||
String name = file.getName();
|
||||
if (crypter.isUseStructure())
|
||||
{
|
||||
name = name.replace(".txt", ".dat");
|
||||
byte[] array = Files.readAllBytes(file.toPath());
|
||||
String joined = new String(array, 0, array.length, "UTF-8");
|
||||
Descriptor desc = DescriptorParser.getInstance().findDescriptorForFile(chronicle, name);
|
||||
if (desc != null)
|
||||
{
|
||||
buff = DescriptorWriter.parseData(file, crypter, desc, joined);
|
||||
}
|
||||
else
|
||||
{
|
||||
L2ClientDat.addLogConsole("Not found the structure of the file: " + file.getName(), true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
buff = Files.readAllBytes(file.toPath());
|
||||
}
|
||||
String fResult = packDir + "/" + name;
|
||||
if (buff != null)
|
||||
{
|
||||
if (ConfigDebug.ENCRYPT)
|
||||
{
|
||||
DatFile.encrypt(buff, fResult, crypter);
|
||||
}
|
||||
else
|
||||
{
|
||||
FileOutputStream os = new FileOutputStream(fResult, false);
|
||||
os.write(buff);
|
||||
os.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (PackDataException e)
|
||||
{
|
||||
DebugUtil.getLogger().error(e);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugUtil.getLogger().error(e.getMessage(), e);
|
||||
}
|
||||
doneSignal.countDown();
|
||||
semaphore.release();
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
DebugUtil.getLogger().error(e.getMessage(), e);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
doneSignal.await();
|
||||
GameDataName.getInstance().checkAndUpdate(packDir.getPath(), crypter);
|
||||
long diffTime = (System.currentTimeMillis() - startTime) / 1000L;
|
||||
L2ClientDat.addLogConsole("Completed. Elapsed ".concat(String.valueOf(diffTime)).concat(" sec"), true);
|
||||
}
|
||||
}
|
165
L2ClientDat/java/com/l2jmobius/actions/MassTxtUnpacker.java
Normal file
165
L2ClientDat/java/com/l2jmobius/actions/MassTxtUnpacker.java
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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.l2jmobius.actions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import com.l2jmobius.L2ClientDat;
|
||||
import com.l2jmobius.clientcryptor.DatFile;
|
||||
import com.l2jmobius.clientcryptor.crypt.DatCrypter;
|
||||
import com.l2jmobius.data.GameDataName;
|
||||
import com.l2jmobius.util.DebugUtil;
|
||||
import com.l2jmobius.xml.Descriptor;
|
||||
import com.l2jmobius.xml.DescriptorParser;
|
||||
import com.l2jmobius.xml.DescriptorReader;
|
||||
|
||||
public class MassTxtUnpacker
|
||||
{
|
||||
private static final MassTxtUnpacker _instance = new MassTxtUnpacker();
|
||||
|
||||
public static MassTxtUnpacker getInstance()
|
||||
{
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public void unpack(String chronicle, String path, DatCrypter decCrypter)
|
||||
{
|
||||
L2ClientDat.addLogConsole("Mass unpacker with using " + chronicle + " chronicles by path [" + path + "]", true);
|
||||
File baseDir = new File(path);
|
||||
if (!baseDir.exists())
|
||||
{
|
||||
L2ClientDat.addLogConsole("Directory [" + path + "] does not exists.", true);
|
||||
return;
|
||||
}
|
||||
String unpackDirPath = path + "/" + "!unpacked";
|
||||
File unpackDir = new File(unpackDirPath);
|
||||
if (!unpackDir.exists() && !unpackDir.mkdir())
|
||||
{
|
||||
L2ClientDat.addLogConsole("Cannot create recrypt directory [" + unpackDirPath + "].", true);
|
||||
return;
|
||||
}
|
||||
GameDataName.getInstance().clear();
|
||||
long startTime = System.currentTimeMillis();
|
||||
for (File file : baseDir.listFiles(pathname -> decCrypter.checkFileExtension(pathname.getName())))
|
||||
{
|
||||
try
|
||||
{
|
||||
try (FileInputStream fis = new FileInputStream(file);)
|
||||
{
|
||||
String name;
|
||||
String res;
|
||||
String charset;
|
||||
if (fis.available() < 28)
|
||||
{
|
||||
L2ClientDat.addLogConsole(file.getName() + " The file is too small.", true);
|
||||
continue;
|
||||
}
|
||||
byte[] head = new byte[28];
|
||||
fis.read(head);
|
||||
fis.close();
|
||||
String header = new String(head, "UTF-16LE");
|
||||
if (!header.startsWith("Lineage2Ver"))
|
||||
{
|
||||
L2ClientDat.addLogConsole("File " + file.getName() + " not encrypted. Skip decrypt.", true);
|
||||
continue;
|
||||
}
|
||||
if (Integer.valueOf(header.substring(11)).intValue() != decCrypter.getCode())
|
||||
{
|
||||
L2ClientDat.addLogConsole("File " + file.getName() + " encrypted code: " + header + ". Skip decrypt.", true);
|
||||
continue;
|
||||
}
|
||||
L2ClientDat.addLogConsole("Unpacking [" + file.getName() + "]", true);
|
||||
DatFile dat = new DatFile(file.getAbsolutePath());
|
||||
dat.decrypt(decCrypter);
|
||||
DebugUtil.save(dat.getBuff(), file);
|
||||
res = null;
|
||||
charset = "UTF-8";
|
||||
if (decCrypter.isUseStructure() && file.getName().endsWith(".dat"))
|
||||
{
|
||||
Descriptor desc = DescriptorParser.getInstance().findDescriptorForFile(chronicle, file.getName());
|
||||
try
|
||||
{
|
||||
res = DescriptorReader.getInstance().parseData(file, decCrypter, desc, dat.getBuff());
|
||||
}
|
||||
catch (Exception e23)
|
||||
{
|
||||
L2ClientDat.addLogConsole("Cannot parse [" + file.getName() + "]", true);
|
||||
}
|
||||
name = file.getName().replace(".dat", ".txt");
|
||||
}
|
||||
else
|
||||
{
|
||||
name = file.getName();
|
||||
if (file.getName().endsWith(".unr"))
|
||||
{
|
||||
name = "dec-" + name;
|
||||
}
|
||||
if (file.getName().endsWith(".htm"))
|
||||
{
|
||||
charset = "UTF-16";
|
||||
}
|
||||
try
|
||||
{
|
||||
try (FileOutputStream fos = new FileOutputStream(unpackDirPath + "/" + name);)
|
||||
{
|
||||
fos.write(dat.getBuff().array());
|
||||
}
|
||||
catch (Throwable throwable)
|
||||
{
|
||||
throw throwable;
|
||||
}
|
||||
}
|
||||
catch (UnsupportedEncodingException e3)
|
||||
{
|
||||
e3.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (res == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
try
|
||||
{
|
||||
try (PrintWriter fos = new PrintWriter(new OutputStreamWriter(new FileOutputStream(unpackDirPath + "/" + name), charset));)
|
||||
{
|
||||
fos.write(res);
|
||||
}
|
||||
catch (Throwable throwable)
|
||||
{
|
||||
throw throwable;
|
||||
}
|
||||
}
|
||||
catch (Exception e4)
|
||||
{
|
||||
DebugUtil.getLogger().error("Cannot write file.", e4);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugUtil.getLogger().error(file.getName() + " Decrypt failed.", e);
|
||||
}
|
||||
}
|
||||
long diffTime = (System.currentTimeMillis() - startTime) / 1000L;
|
||||
L2ClientDat.addLogConsole("Completed. Elapsed ".concat(String.valueOf(diffTime)).concat(" sec"), true);
|
||||
}
|
||||
}
|
143
L2ClientDat/java/com/l2jmobius/actions/OpenDat.java
Normal file
143
L2ClientDat/java/com/l2jmobius/actions/OpenDat.java
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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.l2jmobius.actions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
import com.l2jmobius.L2ClientDat;
|
||||
import com.l2jmobius.clientcryptor.DatFile;
|
||||
import com.l2jmobius.clientcryptor.crypt.DatCrypter;
|
||||
import com.l2jmobius.data.GameDataName;
|
||||
import com.l2jmobius.util.DebugUtil;
|
||||
import com.l2jmobius.xml.Descriptor;
|
||||
import com.l2jmobius.xml.DescriptorParser;
|
||||
import com.l2jmobius.xml.DescriptorReader;
|
||||
|
||||
public class OpenDat
|
||||
{
|
||||
public static void start(String dir, File path, String name, DatCrypter crypter) throws Exception
|
||||
{
|
||||
ByteBuffer buffer;
|
||||
boolean crypt = true;
|
||||
if (!path.exists())
|
||||
{
|
||||
L2ClientDat.addLogConsole("File does not exist.", true);
|
||||
return;
|
||||
}
|
||||
if (!path.canRead())
|
||||
{
|
||||
L2ClientDat.addLogConsole("Unable to read file.", true);
|
||||
return;
|
||||
}
|
||||
FileInputStream fis = new FileInputStream(path);
|
||||
if (fis.available() < 28)
|
||||
{
|
||||
L2ClientDat.addLogConsole("The file is too small.", true);
|
||||
fis.close();
|
||||
return;
|
||||
}
|
||||
byte[] head = new byte[28];
|
||||
fis.read(head);
|
||||
String header = new String(head, "UTF-16LE");
|
||||
if (!header.startsWith("Lineage2Ver"))
|
||||
{
|
||||
L2ClientDat.addLogConsole("File " + name + " not encrypted. Skip decrypt.", true);
|
||||
crypt = false;
|
||||
}
|
||||
fis.close();
|
||||
buffer = null;
|
||||
if (crypt)
|
||||
{
|
||||
L2ClientDat.addLogConsole("File " + name + " encrypted. " + header + " decrypt ...", true);
|
||||
try
|
||||
{
|
||||
DatFile dat = new DatFile(path.getPath());
|
||||
dat.decrypt(crypter);
|
||||
buffer = dat.getBuff();
|
||||
if (buffer == null)
|
||||
{
|
||||
L2ClientDat.addLogConsole("Error decrypt file. Empty buffer.", true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
L2ClientDat.addLogConsole("Error decrypt file.", true);
|
||||
return;
|
||||
}
|
||||
DebugUtil.save(buffer, path);
|
||||
L2ClientDat.addLogConsole("Decrypt successfully.", true);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
try (FileInputStream fIn = new FileInputStream(path);)
|
||||
{
|
||||
FileChannel fChan = fIn.getChannel();
|
||||
ByteBuffer mBuf = ByteBuffer.allocate((int) fChan.size());
|
||||
fChan.read(mBuf);
|
||||
buffer = mBuf;
|
||||
fChan.close();
|
||||
fIn.close();
|
||||
}
|
||||
}
|
||||
catch (IOException exc)
|
||||
{
|
||||
L2ClientDat.addLogConsole("Error reading.", true);
|
||||
}
|
||||
}
|
||||
if (name.contains(".ini") || name.contains(".txt"))
|
||||
{
|
||||
if ((buffer != null) && buffer.hasArray())
|
||||
{
|
||||
L2ClientDat.addText(new String(buffer.array(), 0, buffer.array().length, "UTF-8"));
|
||||
}
|
||||
}
|
||||
else if (name.contains(".htm"))
|
||||
{
|
||||
if ((buffer != null) && buffer.hasArray())
|
||||
{
|
||||
L2ClientDat.addText(new String(buffer.array(), 0, buffer.array().length, "UTF-16"));
|
||||
}
|
||||
}
|
||||
else if (crypter.isUseStructure())
|
||||
{
|
||||
L2ClientDat.addLogConsole("Read the file structure ...", true);
|
||||
String data = null;
|
||||
Descriptor desc = DescriptorParser.getInstance().findDescriptorForFile(dir, name);
|
||||
if ((desc != null) && (buffer != null))
|
||||
{
|
||||
buffer.position(0);
|
||||
DebugUtil.debug("Buffer size: " + buffer.limit());
|
||||
GameDataName.getInstance().clear();
|
||||
data = DescriptorReader.getInstance().parseData(path, crypter, desc, buffer);
|
||||
}
|
||||
if (data == null)
|
||||
{
|
||||
L2ClientDat.addLogConsole("Structure is not found in the directory: " + dir + " file: " + name, true);
|
||||
return;
|
||||
}
|
||||
L2ClientDat.addText(data);
|
||||
}
|
||||
L2ClientDat.addLogConsole("Completed.", true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user