Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions KitX File Format Helper/KitX.KXP.Helper/Decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,19 @@ public string Decode(string releaseFolder)

byte[] src = File.ReadAllBytes(PackagePath); // 读取包的全部字节

int cursor = 0; // 文件流指针
byte[] header = new byte[16];

for (; cursor < 16; ++cursor) // 取出哈希部分的字节
hash[cursor] = src[cursor];
for(int i = 0; i < 16; ++ i)
header[i] = src[i];

for (int i = 0; i < 16; ++i)
if (header[i] != Header.header[i])
throw new Exception("It's not a KXP Package.");

int cursor = 16; // 文件流指针

for (; cursor < 32; ++cursor) // 取出哈希部分的字节
hash[cursor - 16] = src[cursor];

#if DEBUG
Console.WriteLine($"Hash Code: {Encoding.UTF8.GetString(hash)}");
Expand Down Expand Up @@ -131,7 +140,7 @@ public string Decode(string releaseFolder)

MD5 md5 = MD5.Create();

byte[] localHash = md5.ComputeHash(src, 16, src.Length - 16);
byte[] localHash = md5.ComputeHash(src, 32, src.Length - 32);

md5.Dispose();

Expand Down
5 changes: 5 additions & 0 deletions KitX File Format Helper/KitX.KXP.Helper/Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public void Encode(string rootDir, string saveFolder, string filename)
Console.Write($"Hash Code: {Encoding.UTF8.GetString(hash)}");
#endif

foreach (var item in Header.header)
{
fs.WriteByte(item); // 写入文件标头
}

foreach (var item in hash)
{
fs.WriteByte(item); // 写入哈希值
Expand Down
26 changes: 26 additions & 0 deletions KitX File Format Helper/KitX.KXP.Helper/Header.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace KitX.KXP.Helper
{
internal static class Header
{
public static byte[] header = new byte[16]
{
110, // n
105, // i
100, // d
117, // u
111, // o
106, // j
105, // i
117, // u
104, // h
117, // u
105, // i
108, // l
097, // a
105, // i
097, // a
063, // ?
};

}
}