Debian Codegraph @

support/babel/executable.c

raw symbols SCIP
1 /* executable.c Treaty of Babel module for Z-code files
2 * 2006 By L. Ross Raszewski
3 *
4 * This file depends on treaty_builder.h
5 *
6 * This file is public domain, but note that any changes to this file
7 * may render it noncompliant with the Treaty of Babel
8 */
9
10 #define FORMAT executable
11 #define HOME_PAGE "http://http://en.wikipedia.org/wiki/Executable"
12 #define FORMAT_EXT ".exe"
13 #define NO_METADATA
14 #define NO_COVER
15
16 #include "treaty_builder.h"
17 #include "ifiction.h"
18 #include <ctype.h>
19 #include <stdio.h>
20
21 static char elfmagic[] = { 0x7f, 0x45, 0x4c, 0x46, 0 };
22 static char javamagic[] = { 0xCA, 0xFE, 0xBA, 0xBE, 0 };
23 static char amigamagic[] = { 0, 0, 3, 0xe7, 0 };
24 static char machomagic[] = { 0xFE, 0xED, 0xFA, 0xCE, 0};
25 struct exetype
26 {
27 char *magic;
28 char *name;
29 int len;
30 };
31 static struct exetype magic[]= {
32 { "MZ", "MZ", 2 },
33 { elfmagic, "ELF", 4 },
34 { javamagic, "JAVA", 4 },
35 { amigamagic, "AMIGA", 4 },
36 { "#!", "SCRIPT", 2 },
37 { machomagic, "MACHO",4 },
38 { "APPL", "MAC",4 },
39 { NULL, NULL, 0 }
40 };
41
42 static char *deduce_magic(void *sf, int32 extent)
43 {
44 int i;
45 for(i=0;magic[i].magic;i++) {
46 if (extent >= magic[i].len && memcmp(magic[i].magic,sf,magic[i].len)==0)
47 return magic[i].name;
48 }
49 return NULL;
50 }
51
52 static int32 claim_story_file(void *sf, int32 extent)
53 {
54 if (deduce_magic(sf,extent)) return VALID_STORY_FILE_RV;
55 return NO_REPLY_RV;
56 }
57 static int32 get_story_file_IFID(void *sf, int32 extent, char *output, int32 output_extent)
58 {
59 char *o;
60 int32 i;
61
62 i = find_uuid_ifid_marker(sf, extent, output, output_extent);
63 if (i == VALID_STORY_FILE_RV || i == INVALID_USAGE_RV)
64 return i;
65
66 o=deduce_magic(sf,extent);
67 if (!o) return 0;
68 ASSERT_OUTPUT_SIZE((signed) strlen(o)+2);
69 strcpy(output,o);
70 strcat(output,"-");
71 return INCOMPLETE_REPLY_RV;
72 }