Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- class Program
- {
- static void Main(string[] args)
- {
- String Arg = args[0];
- if (File.Exists(Arg))
- {
- Console.WriteLine("Loading file index");
- Regex regexObj = new Regex(@"^(?<START>\d+) (?<END>\d+) \d+ \d+ (?<PATH>(\s|\S)+)$", RegexOptions.IgnoreCase | RegexOptions.Multiline);
- Byte[] Data = File.ReadAllBytes(Arg);
- Int32 IndexOffset = Int32.Parse(ASCIIEncoding.ASCII.GetString(Data, 0, 9));
- String RawRow = "";
- for (int i = IndexOffset; i < Data.Length; i++)
- {
- if (Data[i] == 0x0A)
- {
- Match Row = regexObj.Match(RawRow);
- String Path = AppDomain.CurrentDomain.BaseDirectory + "Root\\" + Row.Groups["PATH"].Value;
- Int32 StartOffset = Int32.Parse(Row.Groups["START"].Value);
- Int32 EndOffset = Int32.Parse(Row.Groups["END"].Value);
- Int32 OffsetLength = EndOffset - StartOffset;
- Console.WriteLine("Extracting ./Root/" + Row.Groups["PATH"].Value);
- Directory.CreateDirectory(Path);
- Directory.Delete(Path);
- FileStream FStream = File.OpenWrite(Path);
- FStream.Write(Data, StartOffset, OffsetLength);
- FStream.Close();
- RawRow = "";
- }
- else
- RawRow += (char)Data[i];
- }
- }
- else if (Directory.Exists(Arg))
- {
- Console.WriteLine("Repacking");
- FileStream FStream = File.OpenWrite(AppDomain.CurrentDomain.BaseDirectory + "main.1050.com.gameloft.android.ANMP.GloftPOHM.obb");
- for (int i = 0; i < 9; i++)
- FStream.WriteByte(0);
- String Index = "";
- Int32 Offset = 9;
- foreach (String FullPath in Directory.GetFiles(Arg, "*", SearchOption.AllDirectories))
- {
- String Path = FullPath.Remove(0, Arg.Length + 1).Replace("\\", "/");
- Int32 StartOffset = Offset;
- Int32 OffsetLength = (Int32)(new FileInfo(FullPath)).Length;
- Int32 EndOffset = Offset + OffsetLength;
- Offset += OffsetLength;
- Index += String.Format("{0} {1} {2} {3} {4}\n", StartOffset, EndOffset, "0", StartOffset, Path);
- FStream.Write(File.ReadAllBytes(FullPath), 0, OffsetLength);
- }
- FStream.Write(Encoding.ASCII.GetBytes(Index), 0, Index.Length);
- FStream.Seek(0, SeekOrigin.Begin);
- FStream.Write((Encoding.ASCII.GetBytes(Offset.ToString("000000000"))), 0, 9);
- FStream.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement