您好,欢迎光临本网站![请登录][注册会员]  
文件名称: Loading a DLL from memory
  所属分类: C++
  开发工具:
  文件大小: 169kb
  下载次数: 0
  上传时间: 2013-03-26
  提 供 者: yizhen*******
 详细说明: 内存加载dll Loading a DLL from memory Loading a DLL from memory This tutorial describes a technique how a dynamic link library (DLL) can be loaded from memory without storing it on the hard-disk first. Author: Joachim Bauch Contact: mail@joachim-bauch.de Copyright: Creative Commons License (by-sa) Contents • Overview • Windows executables - the PE format • DOS header / stub • PE header • Section header • Loading the library • Allocate memory • Copy sections • Base relocation • Resolve imp orts • Protect memory • Notify library • Exported functions • Freeing the library • MemoryModule • Downloads • Known issues • License • Ports • Copyright Overview The default windows API functions to load external libraries into a program (LoadLibrary, LoadLibraryEx) only work with files on the filesystem. It's therefore impossible to load a DLL from memory. But sometimes, you need exactly this functionality (e.g. you don't want to distribute a lot of files or want to make disassembling harder). Common workarounds for this problems are to write the DLL into a temporary file first and import it from there. When the program terminates, the temporary file gets deleted. In this tutorial, I will describe first, how DLL files are structured and will present some code that can be used to load a DLL completely from memory - without storing on the disk first. Windows executables - the PE format Most windows binaries that can contain executable code (.exe, .dll, .sys) share a common file format that consists of the following parts: DOS header DOS stub PE header Section header Section 1 Section 2 . . . Section n All structures given below can be found in the header file winnt.h. DOS header / stub The DOS header is only used for backwards compatibility. It precedes the DOS stub that normally just displays an error message about the program not being able to be run from DOS mode. Microsoft defines the DOS header as follows: typedef struct _IMAGE_DOS_HEADER { // DOS .EXE header WORD e_magic; // Magic number WORD e_cblp; // Bytes on last page of file WORD e_cp; // Pages in file WORD e_crlc; // Relocations WORD e_cparhdr; // Size of header in paragraphs WORD e_minalloc; // Minimum extra paragraphs needed WORD e_maxalloc; // Maximum extra paragraphs needed WORD e_ss; // Initial (relative) SS value WORD e_sp; // Initial SP value WORD e_csum; // Checksum WORD e_ip; // Initial IP value WORD e_cs; // Initial (relative) CS value WORD e_lfarlc; // File address of relocation table WORD e_ovno; // Overlay number WORD e_res[4]; // Reserved words WORD e_oemid; // OEM identifier (for e_oeminfo) WORD e_oeminfo; // OEM information; e_oemid specific WORD e_res2[10]; // Reserved words LONG e_lfanew; // File address of new exe header } IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER; PE header The PE header contains informations about the different sections inside the executable that are used to store code and data or to define imports from other libraries or exports this libraries provides. It's defined as follows: typedef struct _IMAGE_NT_HEADERS { DWORD Signature; IMAGE_FILE_HEADER FileHeader; IMAGE_OPTIONAL_HEADER32 OptionalHeader; } IMAGE_NT_HEADERS32, *PIMAGE_NT_HEADERS32; The FileHeader describes the physical format of the file, i.e. contents, informations about symbols, etc: typedef struct _IMAGE_FILE_HEADER { WORD Machine; WORD NumberOfSections; DWORD TimeDateStamp; DWORD PointerToSymbolTable; DWORD NumberOfSymbols; WORD SizeOfOptionalHeader; WORD Characteristics; } IMAGE_FILE_HEADER, *PIMAGE_FILE_HEADER; The OptionalHeader contains informations about the logical format of the library, including required OS version, memory requirements and entry points: typedef struct _IMAGE_OPTIONAL_HEADER { // ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 内存dll
 输入关键字,在本站1000多万海量源码库中尽情搜索: