Add Atari ST symbol entries and executable flags.

This commit is contained in:
2018-03-02 12:25:48 +00:00
parent f6fc1491ec
commit 90f178d5dd
6 changed files with 135 additions and 6 deletions

View File

@@ -43,6 +43,7 @@ namespace libexeinfo
public GEM.MagiCResourceHeader ResourceHeader;
public GEM.TreeObjectNode[] ResourceObjectRoots;
public Stream ResourceStream;
SymbolEntry[] symbols;
/// <summary>
/// Initializes a new instance of the <see cref="T:libexeinfo.AtariST" /> class.
@@ -123,11 +124,27 @@ namespace libexeinfo
BaseStream.Read(buffer, 0, buffer.Length);
Header = BigEndianMarshal.ByteArrayToStructureBigEndian<AtariHeader>(buffer);
Recognized = Header.signature == SIGNATURE;
List<string> strings = new List<string>();
if(!Recognized) return;
Type = "Atari ST executable";
if(Header.symb_len != 0)
{
BaseStream.Position = 0x1C + Header.text_len + Header.data_len;
buffer = new byte[Marshal.SizeOf(typeof(SymbolEntry))];
symbols = new SymbolEntry[Header.symb_len / Marshal.SizeOf(typeof(SymbolEntry))];
for(int i = 0; i < symbols.Length; i++)
{
BaseStream.Read(buffer, 0, buffer.Length);
symbols[i] = new SymbolEntry();
symbols[i] = BigEndianMarshal.ByteArrayToStructureBigEndian<SymbolEntry>(buffer);
symbols[i].type = (SymbolType)Swapping.Swap((ushort)symbols[i].type);
strings.Add(StringHandlers.CToString(symbols[i].name, Encoding.AtariSTEncoding));
}
}
if(ResourceStream == null) return;
buffer = new byte[Marshal.SizeOf(typeof(GEM.GemResourceHeader))];
@@ -159,8 +176,6 @@ namespace libexeinfo
Encoding.AtariSTEncoding);
}
List<string> strings = new List<string>();
if(ResourceHeader.rsh_ntree > 0)
{
ResourceStream.Position = ResourceHeader.rsh_trindex;

View File

@@ -28,7 +28,9 @@ namespace libexeinfo
{
public partial class AtariST
{
const ushort SIGNATURE = 0x601A;
const uint MINT_SIGNATURE = 0x4D694E54;
const ushort SIGNATURE = 0x601A;
const uint MINT_SIGNATURE = 0x4D694E54;
const ushort PF_FLAGS_MASK = 0xFFCF;
const ushort PF_SHARE_MASK = 0x30;
}
}

View File

@@ -0,0 +1,85 @@
//
// Enums.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
//
// Copyright (c) 2017 Copyright © Claunia.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace libexeinfo
{
public partial class AtariST
{
[Flags]
public enum PrgFlags : ushort
{
/// <summary>
/// If set clear only the BSS area on program load, otherwise clear the entire heap.
/// </summary>
PF_FASTLOAD = 0x01,
/// <summary>
/// If set, the program may be loaded into alternative RAM, otherwise it muse be loaded into standard RAM.
/// </summary>
PF_TTRAMLOAD = 0x02,
/// <summary>
/// If set, the program's malloc() requests may be satisfied from alternative RAM, otherwise they must be satisfied
/// from standard RAM.
/// </summary>
PF_TTRAMMEM = 0x04
}
public enum PrgSharing : ushort
{
/// <summary>
/// The processes' entire memory space will be considered private.
/// </summary>
PF_PRIVATE = 0,
/// <summary>
/// The processes' entire memory space will be readable and writable by any process.
/// </summary>
PF_GLOBAL = 1,
/// <summary>
/// The processes' entire memory space will only be readable and writable by itself and any other process in supervisor
/// mode.
/// </summary>
PF_SUPERVISOR = 2,
/// <summary>
/// The processes' entire memory space will be readable by any application but only writable by itself.
/// </summary>
PF_READABLE = 3
}
[Flags]
public enum SymbolType : ushort
{
Bss = 0x0100,
Text = 0x0200,
Data = 0x0400,
External = 0x0800,
EquatedRegister = 0x1000,
Global = 0x2000,
Equated = 0x4000,
Defined = 0x8000
}
}
}

View File

@@ -25,6 +25,7 @@
// THE SOFTWARE.
using System.Text;
using Encoding = Claunia.Encoding.Encoding;
namespace libexeinfo
{
@@ -34,21 +35,37 @@ namespace libexeinfo
/// Gets a string with human readable information for the Atari ST executable represented by this instance
/// </summary>
/// <value>Human readable information for this instance.</value>
public string Information => GetInfo(Header);
public string Information => GetInfo(Header, symbols);
/// <summary>
/// Gets a string with human readable information for a given Atari ST header
/// </summary>
/// <returns>Human readable information for given Atari ST header.</returns>
/// <param name="header">Atari ST executable header.</param>
static string GetInfo(AtariHeader header)
static string GetInfo(AtariHeader header, SymbolEntry[] symbols)
{
PrgFlags flags = (PrgFlags)(header.flags & PF_FLAGS_MASK);
PrgSharing sharing = (PrgSharing)((header.flags & PF_SHARE_MASK) >> 4);
StringBuilder sb = new StringBuilder();
sb.AppendLine("Atari ST executable:");
if(header.mint == MINT_SIGNATURE) sb.AppendLine("\tMiNT executable.");
sb.AppendFormat("\t{0} bytes in text segment", header.text_len).AppendLine();
sb.AppendFormat("\t{0} bytes in data segment", header.data_len).AppendLine();
sb.AppendFormat("\t{0} bytes in BSS segment", header.bss_len).AppendLine();
sb.AppendFormat("\t{0} bytes in symbol table", header.symb_len).AppendLine();
sb.AppendFormat("\tFlags: {0}", flags).AppendLine();
sb.AppendFormat("\tProcess sharing: {0}", sharing).AppendLine();
sb.AppendFormat("\t{0} fixups", header.absflags == 0 ? "Has" : "Doesn't have").AppendLine();
if(symbols == null || symbols.Length <= 0)
return sb.ToString();
sb.AppendLine("\tSymbol table:");
for(int i = 0; i < symbols.Length; i++)
sb.AppendFormat("\t\tSymbol {0}: \"{1}\", type {2}, value {3}", i,
StringHandlers.CToString(symbols[i].name, Encoding.AtariSTEncoding), symbols[i].type,
symbols[i].value).AppendLine();
return sb.ToString();
}
}

View File

@@ -42,5 +42,14 @@ namespace libexeinfo
public uint flags;
public ushort absflags;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SymbolEntry
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] name;
public SymbolType type;
public uint value;
}
}
}

View File

@@ -49,6 +49,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AtariST\Enums.cs" />
<Compile Include="Enums.cs" />
<Compile Include="GEM\Enums.cs" />
<Compile Include="GEM\Resources.cs" />