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;
}
}
}
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));
}
}
}
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 "";
}
}
}
Code:
namespace DataBurner
{
public class XOR
{
private byte[] s_CipherTable = new byte[0x200]
{
0x77, 0xE8, 0x5E, 0xEC, 0xB7, 0x4E, 0xC1, 0x87, 0x4F, 0xE6, 0xF5, 0x3C, 0x1F, 0xB3, 0x15, 0x43,
0x6A, 0x49, 0x30, 0xA6, 0xBF, 0x53, 0xA8, 0x35, 0x5B, 0xE5, 0x9E, 0x0E, 0x41, 0xEC, 0x22, 0xB8,
0xD4, 0x80, 0xA4, 0x8C, 0xCE, 0x65, 0x13, 0x1D, 0x4B, 0x08, 0x5A, 0x6A, 0xBB, 0x6F, 0xAD, 0x25,
0xB8, 0xDD, 0xCC, 0x77, 0x30, 0x74, 0xAC,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, 0x68, 0x01, 0x8C, 0x1E, 0x0F, 0xEF, 0x8B, 0xB3, 0x41, 0x44, 0x96, 0x21, 0xA8, 0xDA,
0x5E, 0x8B, 0x4A, 0x53, 0x1B, 0xFD, 0xF5, 0x21, 0x3F, 0xF7, 0xBA, 0x68, 0x47, 0xF9, 0x65, 0xDF,
0x52, 0xCE, 0xE0, 0xDE, 0xEC, 0xEF, 0xCD, 0x77, 0xA2, 0x0E, 0xBC, 0x38, 0x2F, 0x64, 0x12, 0x8D,
0xF0, 0x5C, 0xE0, 0x0B, 0x59, 0xD6, 0x2D, 0x99, 0xCD, 0xE7, 0x01, 0x15, 0xE0, 0x67, 0xF4, 0x32,
0x35, 0xD4, 0x11, 0x21, 0xC3, 0xDE, 0x98, 0x65, 0xED, 0x54, 0x9D, 0x1C, 0xB9, 0xB0, 0xAA, 0xA9,
0x0C, 0x8A, 0xB4, 0x66, 0x60, 0xE1, 0xFF, 0x2E, 0xC8, 0x00, 0x43, 0xA9, 0x67, 0x37, 0xDB, 0x9C
};
public void Cipher(ref byte[] buffer, ref byte index)
{
for (int i = 0; i < buffer.Length; i++)
{
buffer[i] ^= s_CipherTable[index];
index++;
}
}
public bool Encrypted(string ext)
{
if (ext == "mp3") return false;
if (ext == "ogg") return false;
if (ext == "raw") return false;
if (ext == "dds") return false;
if (ext == "tga") return false;
if (ext == "naf") return false;
if (ext == "nx3") return false;
if (ext == "cob") return false;
if (ext == "nfm") return false;
return true;
}
}
}
And I realized my error, the function "Create" is not used to that, but to the contrary, if someone can serve to something, that's how I did it:
Code:
string c = "data.000";
DataBurner.ListManager dl = new DataBurner.ListManager();
DataBurner.FileManager fl = new DataBurner.FileManager(dl);
dl.Load(c);
foreach (DataBurner.ListManager.RAPPELZDATA dato in dl.dataList)
{
Console.Write(dato.fileName + " - ");
Console.Write(dato.size + "\n");
FileStream fs = File.Create(".\\des\\" + dato.fileName);
byte[] f = fl.ReadFile(c, dato.fileName, dato.size, dato.offset, dato.dataID);
for (int i = 0; i < f.Length; i++)
{
fs.WriteByte(f[i]);
}
fs.Close();
}
Console.ReadKey();






for ?
