#include "objdefs.h"
#include "optdefs.h"
#include "segdefs.h"
+#include "symdefs.h"
#include "xmalloc.h"
/* od65 */
Count = Read8 (F);
printf (" Count:%27u\n", Count);
- /* Read and print all options */
+ /* Read and print all files */
for (I = 0; I < Count; ++I) {
/* Read the data for one file */
/* Output a header */
printf (" Segments:\n");
- /* Read the number of files and print it */
+ /* Read the number of segments and print it */
Count = Read8 (F);
printf (" Count:%27u\n", Count);
- /* Read and print all options */
+ /* Read and print all segments */
for (I = 0; I < Count; ++I) {
/* Read the data for one segments */
case SEGTYPE_ABS: TypeDesc = "SEGTYPE_ABS"; break;
case SEGTYPE_ZP: TypeDesc = "SEGTYPE_ZP"; break;
case SEGTYPE_FAR: TypeDesc = "SEGTYPE_FAR"; break;
- default: TypeDesc = "SEGTYPE_UNKNOWN"; break;
+ default: TypeDesc = "SEGTYPE_UNKNOWN"; break;
}
/* Print the header */
+void DumpObjImports (FILE* F, unsigned long Offset)
+/* Dump the imports in the object file */
+{
+ ObjHeader H;
+ unsigned Count;
+ unsigned I;
+ FilePos Pos;
+
+ /* Seek to the header position */
+ FileSeek (F, Offset);
+
+ /* Read the header */
+ ReadObjHeader (F, &H);
+
+ /* Seek to the start of the options */
+ FileSeek (F, Offset + H.ImportOffs);
+
+ /* Output a header */
+ printf (" Imports:\n");
+
+ /* Read the number of imports and print it */
+ Count = Read16 (F);
+ printf (" Count:%27u\n", Count);
+
+ /* Read and print all imports */
+ for (I = 0; I < Count; ++I) {
+
+ const char* TypeDesc;
+
+ /* Read the data for one import */
+ unsigned char Type = Read8 (F);
+ char* Name = ReadMallocedStr (F);
+ unsigned Len = strlen (Name);
+ ReadFilePos (F, &Pos);
+
+ /* Get a description for the type */
+ switch (Type) {
+ case IMP_ZP: TypeDesc = "IMP_ZP"; break;
+ case IMP_ABS: TypeDesc = "IMP_ABS"; break;
+ default: TypeDesc = "IMP_UNKNOWN"; break;
+ }
+
+ /* Print the header */
+ printf (" Index:%27u\n", I);
+
+ /* Print the data */
+ printf (" Type:%22s0x%02X (%s)\n", "", Type, TypeDesc);
+ printf (" Name:%*s\"%s\"\n", 24-Len, "", Name);
+
+ /* Free the Name */
+ xfree (Name);
+ }
+}
+
+
+
+void DumpObjExports (FILE* F, unsigned long Offset)
+/* Dump the exports in the object file */
+{
+ ObjHeader H;
+ unsigned Count;
+ unsigned I;
+ FilePos Pos;
+
+ /* Seek to the header position */
+ FileSeek (F, Offset);
+
+ /* Read the header */
+ ReadObjHeader (F, &H);
+
+ /* Seek to the start of the options */
+ FileSeek (F, Offset + H.ExportOffs);
+
+ /* Output a header */
+ printf (" Exports:\n");
+
+ /* Read the number of exports and print it */
+ Count = Read16 (F);
+ printf (" Count:%27u\n", Count);
+
+ /* Read and print all exports */
+ for (I = 0; I < Count; ++I) {
+
+ const char* TypeDesc;
+
+ /* Read the data for one export */
+ unsigned char Type = Read8 (F);
+ char* Name = ReadMallocedStr (F);
+ unsigned Len = strlen (Name);
+ if (Type & EXP_EXPR) {
+ SkipExpr (F);
+ } else {
+ (void) Read32 (F);
+ }
+ ReadFilePos (F, &Pos);
+
+ /* Get a description for the type */
+ switch (Type) {
+ case EXP_ABS|EXP_CONST: TypeDesc = "EXP_ABS,EXP_CONST"; break;
+ case EXP_ZP|EXP_CONST: TypeDesc = "EXP_ZP,EXP_CONST"; break;
+ case EXP_ABS|EXP_EXPR: TypeDesc = "EXP_ABS,EXP_EXPR"; break;
+ case EXP_ZP|EXP_EXPR: TypeDesc = "EXP_ZP,EXP_EXPR"; break;
+ default: TypeDesc = "EXP_UNKNOWN"; break;
+ }
+
+ /* Print the header */
+ printf (" Index:%27u\n", I);
+
+ /* Print the data */
+ printf (" Type:%22s0x%02X (%s)\n", "", Type, TypeDesc);
+ printf (" Name:%*s\"%s\"\n", 24-Len, "", Name);
+
+ /* Free the Name */
+ xfree (Name);
+ }
+}
+
+
+
" -V\t\t\tPrint the version number and exit\n"
"\n"
"Long options:\n"
+ " --dump-exports\tDump exported symbols\n"
" --dump-files\t\tDump the source files\n"
" --dump-header\t\tDump the object file header\n"
+ " --dump-imports\tDump imported symbols\n"
" --dump-options\tDump object file options\n"
" --dump-segments\tDump the segments in the file\n"
" --help\t\tHelp (this text)\n"
+static void OptDumpExports (const char* Opt, const char* Arg)
+/* Dump the exported symbols */
+{
+ What |= D_EXPORTS;
+}
+
+
+
static void OptDumpFiles (const char* Opt, const char* Arg)
/* Dump the source files */
{
+static void OptDumpImports (const char* Opt, const char* Arg)
+/* Dump the imported symbols */
+{
+ What |= D_IMPORTS;
+}
+
+
+
static void OptDumpOptions (const char* Opt, const char* Arg)
/* Dump the object file options */
{
}
if (What & D_FILES) {
DumpObjFiles (F, 0);
- }
+ }
if (What & D_SEGMENTS) {
DumpObjSegments (F, 0);
}
- }
+ if (What & D_IMPORTS) {
+ DumpObjImports (F, 0);
+ }
+ if (What & D_EXPORTS) {
+ DumpObjExports (F, 0);
+ }
+ }
/* Close the file */
fclose (F);
{
/* Program long options */
static const LongOpt OptTab[] = {
+ { "--dump-exports", 0, OptDumpExports },
{ "--dump-files", 0, OptDumpFiles },
{ "--dump-header", 0, OptDumpHeader },
+ { "--dump-imports", 0, OptDumpImports },
{ "--dump-options", 0, OptDumpOptions },
{ "--dump-segments", 0, OptDumpSegments },
{ "--help", 0, OptHelp },