Skip to content

Instantly share code, notes, and snippets.

@13xforever
Created October 20, 2016 10:21
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save 13xforever/3d547ee0d8c3951b7b6059eb1922e79c to your computer and use it in GitHub Desktop.
Nintendo Zone hotspot.conf Decoder
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace hotspot_conf_decoder
{
class Program
{
static void Main(string[] args)
{
var hotspotConfPath = @"C:\Programs\3DSHackingToolkit\PackHack\ExtractedRomFS\hotspot.conf";
if (args.Length > 0 && !string.IsNullOrEmpty(args[0]))
hotspotConfPath = args[0];
using (var reader = File.OpenText(hotspotConfPath))
{
var interval = reader.ReadLine();
var intervalVal = reader.ReadLine();
var header = reader.ReadLine();
var configs = new List<List<string>>();
do
{
var line = reader.ReadLine();
var lineValues = DecodeCsvLine(line);
for (var i = 0; i < 4; i++)
lineValues[i] = DecodeBase64(lineValues[i]);
configs.Add(lineValues);
} while (!reader.EndOfStream);
var resultPath = Path.Combine(Path.GetDirectoryName(hotspotConfPath), "hotspot_decoded.conf");
using (var stream = File.Open(resultPath, FileMode.Create, FileAccess.Write, FileShare.Read))
using (var writer = new StreamWriter(stream))
{
writer.WriteLine(interval);
writer.WriteLine(intervalVal);
writer.WriteLine(header);
foreach (var line in configs)
writer.WriteLine(string.Join(",", line));
}
}
}
private static List<string> DecodeCsvLine(string input)
{
var result = new List<string>();
var buf = new StringBuilder();
foreach (var c in input)
{
switch (c)
{
case ',':
result.Add(buf.ToString());
buf.Clear();
break;
default:
buf.Append(c);
break;
}
}
result.Add(buf.ToString());
return result;
}
private static string DecodeBase64(string str)
{
if (string.IsNullOrEmpty(str))
return str;
var validBase64 = str.Replace('*', '=').Replace('.', '+').Replace('-', '/');
var bytes = Convert.FromBase64String(validBase64);
string result;
var isBinary = bytes.Last() == 0x00;
if (isBinary)
{
Array.Resize(ref bytes, bytes.Length-1);
var buf = new StringBuilder(bytes.Length*2);
foreach (var b in bytes)
buf.Append(b.ToString("x2"));
result = buf.ToString();
}
else
result = Encoding.UTF8.GetString(bytes);
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment