-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathUnpacker.cs
47 lines (35 loc) · 1.35 KB
/
Unpacker.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.IO;
using UnpackMiColorFace.Decompiler;
using XiaomiWatch.Common;
namespace UnpackMiColorFace
{
internal class Unpacker
{
const uint magic_v1_1 = 0x46616365;
const uint magic_v1_2 = 0x46696C65;
const uint magic_v2 = 0x5AA53412;
const uint magic_v3_1 = 0x00000607;
const uint magic_v3_2 = 0x00020001;
private static WatchType watchType;
internal static void Exec(string filename)
{
if (string.IsNullOrWhiteSpace(filename))
throw new ArgumentNullException("filename");
byte[] data = File.ReadAllBytes(filename);
int version = 0;
if (data.GetDWord(0, 1) == magic_v1_1 && data.GetDWord(4, 1) == magic_v1_2)
version = 1;
if (data.GetDWord(0, 1) == magic_v2)
version = 2;
if (data.GetDWord(0, 1) == magic_v3_1 && data.GetDWord(4, 1) == magic_v3_2)
version = 3;
if (version == 0)
throw new MissingFieldException();
watchType = WatchDetector.GetWatchType(data, version);
Console.WriteLine($"Watch detected: {watchType}");
var decompiler = DecompilerFactory.GetDecompiler(version, filename);
decompiler.Process(watchType, data);
}
}
}