SHOW:
|
|
- or go back to the newest paste.
1 | using System; | |
2 | using System.Collections.Generic; | |
3 | using System.IO; | |
4 | using System.Linq; | |
5 | using System.Text; | |
6 | using System.Text.RegularExpressions; | |
7 | ||
8 | class Program | |
9 | { | |
10 | static void Main(string[] args) | |
11 | { | |
12 | String Arg = args[0]; | |
13 | if (File.Exists(Arg)) | |
14 | { | |
15 | Console.WriteLine("Loading file index"); | |
16 | Regex regexObj = new Regex(@"^(?<START>\d+) (?<END>\d+) \d+ \d+ (?<PATH>(\s|\S)+)$", RegexOptions.IgnoreCase | RegexOptions.Multiline); | |
17 | Byte[] Data = File.ReadAllBytes(Arg); | |
18 | - | Int32 IndexOffset = Int32.Parse(((Char)Data[0]).ToString() + (Char)Data[1] + (Char)Data[2] + (Char)Data[3] + (Char)Data[4] + (Char)Data[5] + (Char)Data[6] + (Char)Data[7] + (Char)Data[8]); |
18 | + | Int32 IndexOffset = Int32.Parse(ASCIIEncoding.ASCII.GetString(Data, 0, 9)); |
19 | String RawRow = ""; | |
20 | for (int i = IndexOffset; i < Data.Length; i++) | |
21 | { | |
22 | if (Data[i] == 0x0A) | |
23 | { | |
24 | Match Row = regexObj.Match(RawRow); | |
25 | String Path = AppDomain.CurrentDomain.BaseDirectory + "Root\\" + Row.Groups["PATH"].Value; | |
26 | Int32 StartOffset = Int32.Parse(Row.Groups["START"].Value); | |
27 | Int32 EndOffset = Int32.Parse(Row.Groups["END"].Value); | |
28 | Int32 OffsetLength = EndOffset - StartOffset; | |
29 | Console.WriteLine("Extracting ./Root/" + Row.Groups["PATH"].Value); | |
30 | Directory.CreateDirectory(Path); | |
31 | Directory.Delete(Path); | |
32 | FileStream FStream = File.OpenWrite(Path); | |
33 | FStream.Write(Data, StartOffset, OffsetLength); | |
34 | FStream.Close(); | |
35 | RawRow = ""; | |
36 | } | |
37 | else | |
38 | RawRow += (char)Data[i]; | |
39 | } | |
40 | } | |
41 | else if (Directory.Exists(Arg)) | |
42 | { | |
43 | Console.WriteLine("Repacking"); | |
44 | FileStream FStream = File.OpenWrite(AppDomain.CurrentDomain.BaseDirectory + "main.1050.com.gameloft.android.ANMP.GloftPOHM.obb"); | |
45 | for (int i = 0; i < 9; i++) | |
46 | FStream.WriteByte(0); | |
47 | String Index = ""; | |
48 | Int32 Offset = 9; | |
49 | foreach (String FullPath in Directory.GetFiles(Arg, "*", SearchOption.AllDirectories)) | |
50 | { | |
51 | String Path = FullPath.Remove(0, Arg.Length + 1).Replace("\\", "/"); | |
52 | Int32 StartOffset = Offset; | |
53 | Int32 OffsetLength = (Int32)(new FileInfo(FullPath)).Length; | |
54 | Int32 EndOffset = Offset + OffsetLength; | |
55 | Offset += OffsetLength; | |
56 | Index += String.Format("{0} {1} {2} {3} {4}\n", StartOffset, EndOffset, "0", StartOffset, Path); | |
57 | FStream.Write(File.ReadAllBytes(FullPath), 0, OffsetLength); | |
58 | } | |
59 | - | FStream.Write(Encoding.ASCII.GetBytes(Index), 0, Index.Length - 1); |
59 | + | FStream.Write(Encoding.ASCII.GetBytes(Index), 0, Index.Length); |
60 | FStream.Seek(0, SeekOrigin.Begin); | |
61 | FStream.Write((Encoding.ASCII.GetBytes(Offset.ToString("000000000"))), 0, 9); | |
62 | FStream.Close(); | |
63 | } | |
64 | } | |
65 | } |