hi, i was trying to use the databurner, but do not really understand the code. I get out the list of data, but when you create them can not, I just did this:
Code:
string c = "data.000";
DataBurner.ListManager dl = new DataBurner.ListManager();
dl.Load(c);
foreach (DataBurner.ListManager.RAPPELZDATA dato in dl.dataList)
{
Console.Write(dato.fileName + " - ");
Console.Write(dato.size + "\n");
dl.Create(".\\des\\" + dato.fileName);
}
Console.ReadKey();
Please, if anyone can tell me where I am failing would greatly appreciate it, thanks.
below I show the code databurner
FileManager.cs
Code:
using System;
using System.IO;
using System.Text;
using System.Diagnostics;
namespace DataBurner
{
public class FileManager
{
private Encoding encoding = Encoding.Default;
private ListManager listManager;
public FileManager(ListManager listManager)
{
this.listManager = listManager;
}
public byte[] ReadFile(string path, string fileName, int size, int offset, int dataID)
{
try
{
byte[] buffer;
using (FileStream fs = new FileStream(path.Substring(0, path.Length - 1) + dataID, FileMode.Open, FileAccess.Read))
{
using (BinaryReader br = new BinaryReader(fs, encoding))
{
br.BaseStream.Position = offset;
buffer = br.ReadBytes(size);
}
}
XOR xor = new XOR();
if (xor.Encrypted(Path.GetExtension(fileName).Remove(0, 1)))
{
byte index = 0;
xor.Cipher(ref buffer, ref index);
}
return buffer;
}
catch (Exception ex)
{
#if DEBUG
Debug.WriteLine("{0} has thrown {1} with message {2}.", this.GetType().FullName, ex.GetType().FullName, ex.Message);
#endif
return new byte[0];
}
}
public bool UpdateFile(string path, string filePath, bool isEncoded)
{
try
{
return UpdateFile(path, Path.GetFileName(filePath), File.ReadAllBytes(filePath), isEncoded, false);
}
catch (Exception ex)
{
#if DEBUG
Debug.WriteLine("{0} has thrown {1} with message {2}.", this.GetType().FullName, ex.GetType().FullName, ex.Message);
#endif
return false;
}
}
public bool UpdateFile(string path, string fileName, byte[] buffer, bool isEncoded, bool isEncrypted)
{
try
{
ListManager.RAPPELZDATA fileInfo = new ListManager.RAPPELZDATA();
ListManager.RAPPELZDATA oldInfo = listManager.Find(fileName);
int sizeDifference = 0;
if (oldInfo != null) { sizeDifference = buffer.Length - oldInfo.size; }
if (isEncoded)
{
fileInfo.fileHash = fileName;
fileInfo.fileName = StringCipher.Decode(fileName);
}
else
{
fileInfo.fileName = fileName;
fileInfo.fileHash = StringCipher.Encode(fileName);
}
fileInfo.dataID = listManager.getID(fileInfo.fileHash);
if (!File.Exists(path + fileInfo.dataID)) { File.Create(path + fileInfo.dataID).Close(); }
if (oldInfo != null && sizeDifference <= 0) { fileInfo.offset = oldInfo.offset; }
else { fileInfo.offset = (int)new FileInfo(path + fileInfo.dataID).Length; }
fileInfo.size = buffer.Length;
if (oldInfo != null) { listManager.dataList.Remove(oldInfo); }
listManager.dataList.Add(fileInfo);
XOR xor = new XOR();
if (xor.Encrypted(Path.GetExtension(fileInfo.fileName).Remove(0, 1)))
{
byte index = 0;
xor.Cipher(ref buffer, ref index);
}
using (FileStream fs = new FileStream(path + fileInfo.dataID, FileMode.Open, FileAccess.Write))
{
using (BinaryWriter bw = new BinaryWriter(fs, encoding))
{
bw.BaseStream.Position = fileInfo.offset;
bw.Write(buffer);
}
}
}
catch (Exception ex)
{
#if DEBUG
Debug.WriteLine("{0} has thrown {1} with message {2}.", this.GetType().FullName, ex.GetType().FullName, ex.Message);
#endif
return false;
}
return true;
}
}
}
ListManager.cs
Code:
using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;
namespace DataBurner
{
public class ListManager
{
public class RAPPELZDATA
{
public string fileName { get; set; }
public string fileHash { get; set; }
public int size { get; set; }
public int offset { get; set; }
public int dataID { get; set; }
}
public List<RAPPELZDATA> dataList = new List<RAPPELZDATA>();
public List<string> extList = new List<string>();
private Encoding encoding = Encoding.Default;
public void Create(string path)
{
#if DEBUG
DateTime startTime = DateTime.Now;
#endif
try
{
using (FileStream fs = File.Create(path))
{
using (BinaryWriter bw = new BinaryWriter(fs, encoding))
{
StringCipher stringCipher = new StringCipher();
XOR xor = new XOR();
byte xIndex = 0;
foreach (RAPPELZDATA data in dataList)
{
byte[] size = new byte[1] { Convert.ToByte(data.fileHash.Length) };
xor.Cipher(ref size, ref xIndex);
bw.Write(size);
byte[] hash = Encoding.Default.GetBytes(data.fileHash);
xor.Cipher(ref hash, ref xIndex);
bw.Write(hash);
byte[] fileInfo = new byte[8];
Buffer.BlockCopy(BitConverter.GetBytes(data.offset), 0, fileInfo, 0, 4);
Buffer.BlockCopy(BitConverter.GetBytes(data.size), 0, fileInfo, 4, 4);
xor.Cipher(ref fileInfo, ref xIndex);
bw.Write(fileInfo);
}
}
}
}
catch(Exception ex)
{
#if DEBUG
Debug.WriteLine("{0} has thrown {1} with message {2}.", this.GetType().FullName, ex.GetType().FullName, ex.Message);
#endif
}
#if DEBUG
Debug.WriteLine("Creating the Rappelz Data List took {0}ms", (DateTime.Now - startTime).TotalMilliseconds);
#endif
}
public void Load(string path)
{
#if DEBUG
DateTime startTime = DateTime.Now;
#endif
try
{
if(File.Exists(path))
{
dataList.Clear();
extList.Clear();
extList.Add("All");
XOR xor = new XOR();
byte xIndex = 0;
using(FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
{
using(BinaryReader br= new BinaryReader(fs, encoding))
{
while (br.PeekChar() != -1)
{
RAPPELZDATA data = new RAPPELZDATA();
byte[] size = new byte[1] { br.ReadByte() };
xor.Cipher(ref size, ref xIndex);
byte[] hash = br.ReadBytes(size[0]);
xor.Cipher(ref hash, ref xIndex);
byte[] fileInfo = br.ReadBytes(8);
xor.Cipher(ref fileInfo,ref xIndex);
data.fileHash = encoding.GetString(hash);
data.fileName = StringCipher.Decode(data.fileHash);
data.offset = BitConverter.ToInt32(fileInfo, 0);
data.size = BitConverter.ToInt32(fileInfo, 4);
data.dataID = getID(data.fileHash);
dataList.Add(data);
string ext = Path.GetExtension(data.fileName).Remove(0, 1).ToUpper();
if (extList.FindIndex(str => str == ext) == -1)
{
extList.Add(ext);
}
}
}
}
dataList.Sort(delegate(RAPPELZDATA item1, RAPPELZDATA item2)
{
if (item1.fileName == null && item2.fileName == null) return 0;
else if (item1.fileName == null) return -1;
else if (item2.fileName == null) return -1;
else return item1.fileName.CompareTo(item2.fileName);
});
extList.Sort();
}
}
catch (Exception ex)
{
#if DEBUG
Debug.WriteLine("{0} has thrown {1} with message {2}.", this.GetType().FullName, ex.GetType().FullName, ex.Message);
#endif
}
#if DEBUG
Debug.WriteLine("Reading the Rappelz Data List took {0}ms", (DateTime.Now - startTime).TotalMilliseconds);
#endif
}
public int getID(string hash)
{
if (!string.IsNullOrEmpty(hash))
{
byte[] buffer = encoding.GetBytes(hash.ToLower());
int a = 0;
for (int i = 0; i < buffer.Length; i++) { a = ((a << 5) - a) + buffer[i]; }
if (a < 0) { a = a * -1; }
return (a % 8) + 1;
}
else { return -1; }
}
public RAPPELZDATA Find(string fileName)
{
return dataList.Find(data => data.fileName.Contains(fileName));
}
public List<RAPPELZDATA> FindAll(string fileName, string ext)
{
if (ext != "All")
{
return dataList.FindAll(data => data.fileName.Contains(fileName) && data.fileName.Contains("." + ext.ToLower()));
}
return dataList.FindAll(data => data.fileName.Contains(fileName));
}
}
}
StringCipher.cs
Code:
using System;
namespace DataBurner
{
public class StringCipher
{
private static byte[] s_CipherTable = new byte[0x80]
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x67, 0x20, 0x00, 0x26, 0x77, 0x2C, 0x6C, 0x4E, 0x58, 0x4F, 0x00, 0x37, 0x2E, 0x25, 0x65, 0x00, 0x38, 0x5F, 0x5D, 0x23, 0x50, 0x31, 0x2D, 0x24, 0x56, 0x5B, 0x00, 0x59, 0x00, 0x5E, 0x00, 0x00,
0x4B, 0x7D, 0x6A, 0x30, 0x40, 0x47, 0x53, 0x29, 0x41, 0x78, 0x79, 0x36, 0x39, 0x45, 0x46, 0x7B, 0x57, 0x62, 0x3D, 0x52, 0x76, 0x74, 0x68, 0x32, 0x34, 0x4D, 0x28, 0x6B, 0x00, 0x6D, 0x61, 0x2B,
0x7E, 0x44, 0x27, 0x43, 0x21, 0x4A, 0x49, 0x64, 0x42, 0x55, 0x60, 0x71, 0x66, 0x70, 0x48, 0x51, 0x33, 0x4C, 0x6E, 0x6F, 0x5A, 0x69, 0X72, 0x73, 0x75, 0x3B, 0x7A, 0x63, 0x00, 0x54, 0x35, 0x00
};
private static byte[] s_CharTable = new byte[0x55]
{
0x5E, 0x26, 0x54, 0x5F, 0x4E, 0x73, 0x64, 0x7B, 0x78, 0x6F, 0x35, 0x76, 0x60, 0x72, 0x4F, 0x59, 0x56, 0x2B, 0x2C, 0x69, 0x49,
0x55, 0x23, 0x6B, 0x43, 0x4A, 0x71, 0x38, 0x24, 0x27, 0x7E, 0x4C, 0x30, 0x50, 0x5D, 0x46, 0x65, 0x42, 0x6E, 0x2D, 0x41, 0x75,
0x28, 0x70, 0x58, 0x48, 0x5A, 0x68, 0x77, 0x44, 0x79, 0x32, 0x7D, 0x61, 0x67, 0x57, 0x47, 0x37, 0x4B, 0x3D, 0x62, 0x51, 0x3B,
0x53, 0x52, 0x74, 0x29, 0x34, 0x36, 0x6C, 0x40, 0x6A, 0x45, 0x25, 0x39, 0x21, 0x63, 0x31, 0x5B, 0x33, 0x66, 0x6D, 0x4D, 0x7A,
0x00
};
public static bool IsEncoded(string hash)
{
if(Encode(Decode(hash)) == hash)
{
return true;
}
return false;
}
public static string Encode(string name)
{
char[] lower_str = name.ToLower().ToCharArray();
int c = 0;
for (int i = 0; i < lower_str.Length; i++) { c = lower_str[i] * 17 + c + 1; }
c = (lower_str.Length + c) & 0x1F;
if (c == 0) c = 0x20;
char last_char = (char)s_CharTable[c];
int a = c;
for (int i = 0; i < lower_str.Length; i++)
{
c = lower_str[i];
for (int j = 0; j < a; j++) { c = s_CipherTable[c]; }
a = (a + 1 + lower_str[i] * 17) & 0x1F;
if (a == 0) a = 0x20;
lower_str[i] = (char)c;
}
if (lower_str.Length > 4)
{
int b = (int)Math.Floor(0.3300000131130219 * lower_str.Length);
int d = (int)Math.Floor(0.6600000262260437 * lower_str.Length);
char e1 = lower_str[d];
char e2 = lower_str[b];
lower_str[d] = lower_str[0];
lower_str[b] = lower_str[1];
lower_str[0] = e1;
lower_str[1] = e2;
}
c = 0;
for (int i = 0; i < lower_str.Length; i++) { c += lower_str[i]; }
char first_char = (char)s_CharTable[c % 0x54];
return first_char + new string(lower_str) + last_char;
}
public static string Decode(string hash)
{
if (hash.Length > 0)
{
char[] short_str = hash.Substring(1, hash.Length - 2).ToCharArray();
if (short_str.Length > 4)
{
int b = (int)Math.Floor(0.3300000131130219 * short_str.Length);
int d = (int)Math.Floor(0.6600000262260437 * short_str.Length);
char e1 = short_str[d];
char e2 = short_str[b];
short_str[d] = short_str[0];
short_str[b] = short_str[1];
short_str[0] = e1;
short_str[1] = e2;
}
int c = Array.IndexOf<byte>(s_CharTable, (byte)hash[hash.Length - 1], 0, s_CharTable.Length);
int a = c;
for (int i = 0; i < short_str.Length; i++)
{
c = short_str[i];
for (int j = 0; j < a; j++)
{
int k;
k = Array.IndexOf<byte>(s_CipherTable, (byte)c, 0, s_CipherTable.Length);
if (k < s_CipherTable.Length) c = k;
else c = 0xFF;
}
short_str[i] = (char)c;
a = (1 + a + 17 * c) & 0x1F;
if (a == 0) a = 0x20;
}
return new string(short_str);
}
return "";
}
}
}
[Release] Databurner 2.0 07/25/2015 - Rappelz Private Server - 2 Replies Here is the latest version of my databurner library. Databurner is used to read, dump and update the rappelz Data.00x files. While I can't get update to work just right everything else works. FileManager is for the Data.00x files. ListManager is for the Data.000 file.
https://www.mediafire.com/?9bf6x3vq4vdx1n1
[Release] DataBurner 01/19/2014 - Rappelz Private Server - 9 Replies DataBurner is a dynamic link library that allows full control over the data files.
It allows hashing file names aswell as giving full dumps of the data files. This also includes packing into the data files.
https://github.com/xXExiledXx/DataBurner