How to tell if a file is an EXE or a DLL?

How to tell if a file is an EXE or a DLL?

 1 void DumpFile(LPWSTR filename)
 2 {
 3     HANDLE hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
 4
 5     HANDLE hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
 6
 7     LPVOID lpFileBase = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
 8
 9     PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)lpFileBase;
10
11     PIMAGE_NT_HEADERS pNTHeader = (PIMAGE_NT_HEADERS)((DWORD)pDosHeader + (DWORD)pDosHeader->e_lfanew);
12
13     if ((pNTHeader->FileHeader.Characteristics & IMAGE_FILE_DLL))
14          printf("dll");
15     if ((pNTHeader->FileHeader.Characteristics & IMAGE_FILE_EXECUTABLE_IMAGE))
16          printf("exe");
17     else
18          printf("????");
19
20     UnmapViewOfFile(lpFileBase);
21     CloseHandle(hFileMapping);
22     CloseHandle(hFile);
23 }
时间: 2024-10-30 21:52:25

How to tell if a file is an EXE or a DLL?的相关文章

fatal error LNK1104: cannot open file "Debug/构造函数.exe"

今天编写程序遇到下面这个问题: 现象: 编译没有错误,一连接就报错:fatal error LNK1104: cannot open file "Debug/构造函数.exe" 原因: 进程中正有一个xxx.exe运行,所以这个文件受保护,不能打开创建 解决: ctrl+alt+del,打开任务管理器,杀掉该进程

Could not load file or assembly'System.Data.SQLite.dll' or one of its depedencies

[问题]  在我本机的开发环境c#连接sqlite3没有问题,可是release版本移植到其他的机器就提示Could not load file or assembly'System.Data.SQLite.dll' or one of its depedencies.找不到指定模块. [解决] 搜来搜去没找到靠谱的答案,其实最后还是自己解决的. sqlite官方的下载页面里面说了:The Visual C++ 2010 SP1 runtime for x86 and the .NET Fr

IIS中发布后出现Could not load file or assembly'System.Data.SQLite.dll' or one of its depedencies

[问题]在我本机的开发环境c#连接sqlite3没有问题,可是release版本移植到其他的机器就提示Could not load file or assembly'System.Data.SQLite.dll' or one of its depedencies.找不到指定模块. [解决]搜来搜去没找到靠谱的答案,其实最后还是自己解决的. sqlite官方的下载页面里面说了:The Visual C++ 2010 SP1 runtime for x86 and the .NET Framewo

安装SQL2008时遇到"未能加载文件或"file:///d:microsoft..sql.chainer.packagedata.dll"或它的某个依赖项

安装SQL2008时遇到"未能加载文件或"file:///d:microsoft..sql.chainer.packagedata.dll"或它的某个依赖项,如下图所示 原因:SQL2008的安装路径过长. 解决:把SQL2008放到D盘或者E盘的根目录下再安装.

QT编译出现ld.exe: cannot open output file debug\nh_03testCallPy.exe: Permission denied collect2.exe: error: ld returned 1 exit status

D:/Qt/Qt5.9.0/Tools/mingw530_32/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot open output file debug\nh_03testCallPy.exe: Permission denied collect2.exe: error: ld returned 1 exit status 原因目前可能有如下: 1.程序已经在运行,进入

How to update WPF browser application manifest and xbap file with ‘mage.exe’

老外参考文章1 老外参考文章2 I created a WPF browser application MyApp then published it by ClickOnce in VS2008. Published folder like this: PublishedFolder\MyApp.xbap PublishedFolder\setup.exe PublishedFolder\Application Files\MyApp_0_0_0_1\ MyApp.xbap Published

The Portable Executable File Format from Top to Bottom(每个结构体都非常清楚)

The Portable Executable File Format from Top to Bottom Randy KathMicrosoft Developer Network Technology Group Created: June 12, 1993 Click to open or copy the files in the EXEVIEW sample application for this technical article. Click to open or copy t

VS2008 解决Unable to copy file 对路径的访问被拒绝。

在VS2008 + WINDOWS 7 环境下重新生成解决方案时遇到以下问题 Unable to delete file "F:\XX.exe". 对路径"F:\XX.exe"的访问被拒绝. Unable to copy file "obj\Release\XX.exe" to "bin\Release\XX.exe". 文件"bin\Release\XX.exe"正由另一进程使用,因此该进程无法访问该文件

错误 CS0006 Metadata file 'E:\项目名称\xxxx.dll'

错误 CS0006 Metadata file 'E:\桌面临时文件\Pos\xxxx.dll' 1.找到这个类库在当前类库右键发生 找到 应用程序-->把程序集名称改成提示错误 的名称 2.找到当前类库下的*.csproj文件右键编辑 把以下节点改成和上面名称同名 <RootNamespace>xxxx</RootNamespace> <AssemblyName>xxxx</AssemblyName> 3.如果有以下节点就修改没有就不用修改 <