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;
- namespace SnDataSymbols
- {
- class Program
- {
- struct SnDebugHeader
- {
- public uint Magic; // SNR2
- public uint Unknown04;
- public uint Unknown08;
- public uint Unknown0C; // This is the same as Unknown04
- public uint SymbolCount; // 7409
- public uint Unknown14; // Zero
- public uint Unknown18; // Zero
- public uint Unknown1C; // Zero
- public uint Unknown20;
- public uint Unknown24; // Zero
- public uint Unknown28; // Zero
- public uint EndOfTable; // Offset to end of table, from this point on is zeros
- public uint Unknown30;
- public uint Unknown34;
- public uint Unknown38;
- public SnDebugHeader(BinaryReader p_Reader)
- {
- Magic = p_Reader.ReadUInt32();
- Unknown04 = p_Reader.ReadUInt32();
- Unknown08 = p_Reader.ReadUInt32();
- Unknown0C = p_Reader.ReadUInt32();
- SymbolCount = p_Reader.ReadUInt32();
- Unknown14 = p_Reader.ReadUInt32();
- Unknown18 = p_Reader.ReadUInt32();
- Unknown1C = p_Reader.ReadUInt32();
- Unknown20 = p_Reader.ReadUInt32();
- Unknown24 = p_Reader.ReadUInt32();
- Unknown28 = p_Reader.ReadUInt32();
- EndOfTable = p_Reader.ReadUInt32();
- Unknown30 = p_Reader.ReadUInt32();
- Unknown34 = p_Reader.ReadUInt32();
- Unknown38 = p_Reader.ReadUInt32();
- }
- }
- // Starting at 0x245DC
- // Size of the entire table = 15B4C
- // Maybe length of
- struct SnDebugEntry
- {
- // In order to get offset in file, subtract the segment header-> address from this to get offset in section header
- public uint NameAddress;
- // Address of the function/data that needs to be set
- public uint TargetAddress;
- public uint Unknown08;
- public SnDebugEntry(BinaryReader p_Reader)
- {
- NameAddress = p_Reader.ReadUInt32();
- TargetAddress = p_Reader.ReadUInt32();
- Unknown08 = p_Reader.ReadUInt32();
- }
- }
- struct SnStringEntry
- {
- // This is *NOT* in the data, we just keep this for lookup later
- public long Offset;
- // The actual string we want
- public string StringData;
- }
- static string ReadAsciiString(BinaryReader p_Reader)
- {
- var s_Ret = string.Empty;
- char s_Char = '\0';
- while ((s_Char = p_Reader.ReadChar()) != '\0')
- s_Ret += s_Char;
- return s_Ret;
- }
- public static void Align(BinaryReader p_Reader, int p_Alignment)
- {
- if (p_Reader.BaseStream.Position % p_Alignment == 0)
- return;
- var s_Number = p_Alignment - (p_Reader.BaseStream.Position % p_Alignment);
- p_Reader.ReadBytes((int)s_Number);
- }
- static void Main(string[] args)
- {
- Console.WriteLine("Hello World!");
- using var s_Reader = new BinaryReader(new FileStream(@"D:\Data\Projects\SnDebug\re4_sndata.bin", FileMode.Open, FileAccess.Read));
- var s_SnDebugHeader = new SnDebugHeader(s_Reader);
- if (s_SnDebugHeader.Magic != 844254803)
- {
- Console.WriteLine("invalid header magic");
- return;
- }
- Console.WriteLine($"Count: {s_SnDebugHeader.SymbolCount} EndOfTabe: {s_SnDebugHeader.EndOfTable}");
- s_Reader.BaseStream.Seek(60, SeekOrigin.Begin);
- var s_SymbolStringList = new List<SnStringEntry>();
- // Read out all of the symbols
- for (var i = 0; i < s_SnDebugHeader.SymbolCount; ++i)
- s_SymbolStringList.Add(new SnStringEntry
- {
- Offset = s_Reader.BaseStream.Position + 0x0035E900, // Hardcode this for now, s_addr of the .sndebug section
- StringData = ReadAsciiString(s_Reader)
- });
- Align(s_Reader, 4);
- var s_Entries = new List<SnDebugEntry>();
- for (var i = 0; i < s_SnDebugHeader.SymbolCount; ++i)
- s_Entries.Add(new SnDebugEntry(s_Reader));
- // Print all of the symbol information
- using TextWriter s_Writer = new StreamWriter("script.py");
- for (var i = 0; i < s_SnDebugHeader.SymbolCount; ++i)
- {
- var s_Entry = s_Entries[i];
- var s_SymbolNames = s_SymbolStringList.Where(p_Entry => p_Entry.Offset == s_Entry.NameAddress);
- if (s_SymbolNames.Count() > 1)
- throw new Exception("investigate this");
- //Console.WriteLine($"0x{s_Entry.TargetAddress.ToString("X")} {s_SymbolNames.First().StringData}");
- // idaapi.set_name(function_address, new_name, idaapi.SN_NOWARN)
- s_Writer.WriteLine($"idaapi.set_name(0x{s_Entry.TargetAddress.ToString("X")}, \"{s_SymbolNames.First().StringData}\", idaapi.SN_NOWARN)");
- }
- s_Writer.Close();
- Console.WriteLine("Done");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment