This source file includes following definitions.
- file_os2_apptype
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #include "file.h"
28
29 #ifndef lint
30 FILE_RCSID("@(#)$File: apptype.c,v 1.12 2011/08/28 07:03:27 christos Exp $")
31 #endif
32
33 #include <stdlib.h>
34 #include <string.h>
35
36 #ifdef __EMX__
37 #include <io.h>
38 #define INCL_DOSSESMGR
39 #define INCL_DOSERRORS
40 #define INCL_DOSFILEMGR
41 #include <os2.h>
42 typedef ULONG APPTYPE;
43
44 protected int
45 file_os2_apptype(struct magic_set *ms, const char *fn, const void *buf,
46 size_t nb)
47 {
48 APPTYPE rc, type;
49 char path[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR],
50 fname[_MAX_FNAME], ext[_MAX_EXT];
51 char *filename;
52 FILE *fp;
53
54 if (fn)
55 filename = strdup(fn);
56 else if ((filename = tempnam("./", "tmp")) == NULL) {
57 file_error(ms, errno, "cannot create tempnam");
58 return -1;
59 }
60
61 _splitpath(filename, drive, dir, fname, ext);
62 (void)sprintf(path, "%s%s%s%s", drive,
63 (*dir == '\0') ? "./" : dir,
64 fname,
65 (*ext == '\0') ? "." : ext);
66
67 if (fn == NULL) {
68 if ((fp = fopen(path, "wb")) == NULL) {
69 file_error(ms, errno, "cannot open tmp file `%s'", path);
70 return -1;
71 }
72 if (fwrite(buf, 1, nb, fp) != nb) {
73 file_error(ms, errno, "cannot write tmp file `%s'",
74 path);
75 (void)fclose(fp);
76 return -1;
77 }
78 (void)fclose(fp);
79 }
80 rc = DosQueryAppType((unsigned char *)path, &type);
81
82 if (fn == NULL) {
83 unlink(path);
84 free(filename);
85 }
86 #if 0
87 if (rc == ERROR_INVALID_EXE_SIGNATURE)
88 printf("%s: not an executable file\n", fname);
89 else if (rc == ERROR_FILE_NOT_FOUND)
90 printf("%s: not found\n", fname);
91 else if (rc == ERROR_ACCESS_DENIED)
92 printf("%s: access denied\n", fname);
93 else if (rc != 0)
94 printf("%s: error code = %lu\n", fname, rc);
95 else
96 #else
97
98
99
100
101
102
103 if (rc)
104 return (0);
105
106 #endif
107
108 if (type & FAPPTYP_32BIT)
109 if (file_printf(ms, "32-bit ") == -1)
110 return -1;
111 if (type & FAPPTYP_PHYSDRV) {
112 if (file_printf(ms, "physical device driver") == -1)
113 return -1;
114 } else if (type & FAPPTYP_VIRTDRV) {
115 if (file_printf(ms, "virtual device driver") == -1)
116 return -1;
117 } else if (type & FAPPTYP_DLL) {
118 if (type & FAPPTYP_PROTDLL)
119 if (file_printf(ms, "protected ") == -1)
120 return -1;
121 if (file_printf(ms, "DLL") == -1)
122 return -1;
123 } else if (type & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT)) {
124 if (file_printf(ms, "Windows executable") == -1)
125 return -1;
126 } else if (type & FAPPTYP_DOS) {
127
128
129
130
131 if (stricmp(ext, ".com") == 0)
132 if (strncmp((const char *)buf, "MZ", 2))
133 return (0);
134 if (file_printf(ms, "DOS executable") == -1)
135 return -1;
136
137
138 if (file_printf(ms, ", magic(4)-> ") == -1)
139 return -1;
140 return (0);
141
142 } else if (type & FAPPTYP_BOUND) {
143 if (file_printf(ms, "bound executable") == -1)
144 return -1;
145 } else if ((type & 7) == FAPPTYP_WINDOWAPI) {
146 if (file_printf(ms, "PM executable") == -1)
147 return -1;
148 } else if (file_printf(ms, "OS/2 executable") == -1)
149 return -1;
150
151 switch (type & (FAPPTYP_NOTWINDOWCOMPAT |
152 FAPPTYP_WINDOWCOMPAT |
153 FAPPTYP_WINDOWAPI)) {
154 case FAPPTYP_NOTWINDOWCOMPAT:
155 if (file_printf(ms, " [NOTWINDOWCOMPAT]") == -1)
156 return -1;
157 break;
158 case FAPPTYP_WINDOWCOMPAT:
159 if (file_printf(ms, " [WINDOWCOMPAT]") == -1)
160 return -1;
161 break;
162 case FAPPTYP_WINDOWAPI:
163 if (file_printf(ms, " [WINDOWAPI]") == -1)
164 return -1;
165 break;
166 }
167 return 1;
168 }
169 #endif