exe.c
资源名称:shell.rar [点击查看]
上传用户:xhy777
上传日期:2007-02-14
资源大小:24088k
文件大小:8k
源码类别:
系统编程
开发平台:
Visual C++
- /*
- * exe.c Get info from a EXEHDR
- *
- * Modification History:
- *
- * 4/03/89 ToddLa Wrote it
- * 4/09/90 T-JackD modification such that the type of error is reflected...
- * 4/17/90 t-jackd modification such that notification of error can be set...
- */
- #include <windows.h>
- #include "desk.h"
- #include <newexe.h>
- #include "exe.h"
- static DWORD dwDummy;
- #define FOPEN(sz) CreateFile(sz, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL )
- #define FCLOSE(fh) CloseHandle(fh)
- #define FREAD(fh,buf,len) (ReadFile(fh,buf,len, &dwDummy, NULL) ? dwDummy : HFILE_ERROR)
- #define FSEEK(fh,off,i) SetFilePointer(fh,(DWORD)off, NULL, i)
- #define F_SEEK_SET FILE_BEGIN
- BOOL NEAR PASCAL IsFAPI(int fh, struct new_exe FAR *pne, long off);
- /*
- * Function will return a specific piece of information from a new EXEHDR
- *
- * szFile - Path Name a new exe
- * pBuf - Buffer to place returned info
- * nBuf - Size of buffer in BYTES
- * fInfo - What info to get?
- *
- * GEI_MODNAME - Get module name
- * GEI_DESCRIPTION - Get description
- * GEI_FLAGS - Get EXEHDR flags
- *
- * returns: LOWORD = ne_magic, HIWORD = ne_exever
- * 0 if error
- */
- DWORD FAR PASCAL GetExeInfo(LPTSTR szFile, void FAR *pBuf, int nBuf, UINT fInfo)
- {
- HANDLE fh;
- DWORD off;
- DWORD dw;
- BYTE len;
- struct exe_hdr exehdr;
- struct new_exe newexe;
- fh = FOPEN(szFile);
- if (fh == INVALID_HANDLE_VALUE)
- {
- return FALSE;
- }
- if (FREAD(fh, &exehdr, sizeof(exehdr)) != sizeof(exehdr) ||
- exehdr.e_magic != EMAGIC ||
- exehdr.e_lfanew == 0L)
- {
- goto error; /* Abort("Not an exe",h); */
- }
- FSEEK(fh, exehdr.e_lfanew, F_SEEK_SET);
- if (FREAD(fh, &newexe, sizeof(newexe)) != sizeof(newexe))
- {
- goto error; // Read error
- }
- if (newexe.ne_magic == PEMAGIC)
- {
- if (fInfo != GEI_DESCRIPTION &&
- fInfo != GEI_EXPVER)
- goto error;
- // make the file name the description
- lstrcpy(pBuf, szFile);
- // read the SubsystemVersion
- FSEEK(fh,exehdr.e_lfanew+18*4,F_SEEK_SET);
- FREAD(fh,&dw,4);
- newexe.ne_expver = LOBYTE(LOWORD(dw)) << 8 | LOBYTE(HIWORD(dw));
- goto exit;
- }
- if (newexe.ne_magic != NEMAGIC)
- {
- goto error; // Invalid NEWEXE
- }
- switch (fInfo)
- {
- #ifdef FAPI
- case GEI_FAPI:
- *(BOOL FAR *)pBuf = IsFAPI(fh,(struct new_exe FAR *)&newexe,
- exehdr.e_lfanew);
- break;
- #endif
- case GEI_EXEHDR:
- *(struct new_exe FAR *)pBuf = newexe;
- break;
- case GEI_FLAGS:
- *(WORD FAR *)pBuf = newexe.ne_flags;
- break;
- /* module name is the first entry in the medident name table */
- case GEI_MODNAME:
- off = exehdr.e_lfanew + newexe.ne_restab;
- goto readstr;
- break;
- /* module name is the first entry in the non-medident name table */
- case GEI_DESCRIPTION:
- off = newexe.ne_nrestab;
- readstr:
- FSEEK(fh, off, F_SEEK_SET);
- FREAD(fh, &len, sizeof(BYTE));
- nBuf--; // leave room for a
English
