clamav/libclamav/pe.h

153 lines
5.4 KiB
C
Raw Normal View History

2004-05-11 23:30:57 +00:00
/*
* Copyright (C) 2007-2008 Sourcefire, Inc.
2004-05-11 23:30:57 +00:00
*
* Authors: Alberto Wu, Tomasz Kojm
*
2004-05-11 23:30:57 +00:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
2004-05-11 23:30:57 +00:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
2004-05-11 23:30:57 +00:00
*/
#ifndef __PE_H
#define __PE_H
#include "clamav.h"
#include "execs.h"
#include "others.h"
#include "cltypes.h"
#include "fmap.h"
2009-11-24 14:53:15 +02:00
/** @file */
/** Header for this PE file */
struct pe_image_file_hdr {
2009-11-24 14:53:15 +02:00
uint32_t Magic; /**< PE magic header: PE\\0\\0 */
uint16_t Machine;/**< CPU this executable runs on, see libclamav/pe.c for possible values */
uint16_t NumberOfSections;/**< Number of sections in this executable */
uint32_t TimeDateStamp; /**< Unreliable */
uint32_t PointerToSymbolTable; /**< debug */
uint32_t NumberOfSymbols; /**< debug */
uint16_t SizeOfOptionalHeader; /**< == 224 */
uint16_t Characteristics;
};
2009-11-24 14:53:15 +02:00
/** PE data directory header */
struct pe_image_data_dir {
uint32_t VirtualAddress;
uint32_t Size;
};
2009-11-24 14:53:15 +02:00
/** 32-bit PE optional header */
struct pe_image_optional_hdr32 {
uint16_t Magic;
2009-11-24 14:53:15 +02:00
uint8_t MajorLinkerVersion; /**< unreliable */
uint8_t MinorLinkerVersion; /**< unreliable */
uint32_t SizeOfCode; /**< unreliable */
uint32_t SizeOfInitializedData; /**< unreliable */
uint32_t SizeOfUninitializedData; /**< unreliable */
uint32_t AddressOfEntryPoint;
uint32_t BaseOfCode;
uint32_t BaseOfData;
2009-11-24 14:53:15 +02:00
uint32_t ImageBase; /**< multiple of 64 KB */
uint32_t SectionAlignment; /**< usually 32 or 4096 */
uint32_t FileAlignment; /**< usually 32 or 512 */
uint16_t MajorOperatingSystemVersion; /**< not used */
uint16_t MinorOperatingSystemVersion; /**< not used */
uint16_t MajorImageVersion; /** unreliable */
uint16_t MinorImageVersion; /** unreliable */
uint16_t MajorSubsystemVersion;
uint16_t MinorSubsystemVersion;
uint32_t Win32VersionValue; /* ? */
uint32_t SizeOfImage;
uint32_t SizeOfHeaders;
2009-11-24 14:53:15 +02:00
uint32_t CheckSum; /**< NT drivers only */
uint16_t Subsystem;
uint16_t DllCharacteristics;
uint32_t SizeOfStackReserve;
uint32_t SizeOfStackCommit;
uint32_t SizeOfHeapReserve;
uint32_t SizeOfHeapCommit;
uint32_t LoaderFlags; /* ? */
2009-11-24 14:53:15 +02:00
uint32_t NumberOfRvaAndSizes; /**< unreliable */
struct pe_image_data_dir DataDirectory[16];
};
2009-11-24 14:53:15 +02:00
/** PE 64-bit optional header */
struct pe_image_optional_hdr64 {
uint16_t Magic;
2009-11-24 14:53:15 +02:00
uint8_t MajorLinkerVersion; /**< unreliable */
uint8_t MinorLinkerVersion; /**< unreliable */
uint32_t SizeOfCode; /**< unreliable */
uint32_t SizeOfInitializedData; /**< unreliable */
uint32_t SizeOfUninitializedData; /**< unreliable */
uint32_t AddressOfEntryPoint;
uint32_t BaseOfCode;
2009-11-24 14:53:15 +02:00
uint64_t ImageBase; /**< multiple of 64 KB */
uint32_t SectionAlignment; /**< usually 32 or 4096 */
uint32_t FileAlignment; /**< usually 32 or 512 */
uint16_t MajorOperatingSystemVersion; /**< not used */
uint16_t MinorOperatingSystemVersion; /**< not used */
uint16_t MajorImageVersion; /**< unreliable */
uint16_t MinorImageVersion; /**< unreliable */
uint16_t MajorSubsystemVersion;
uint16_t MinorSubsystemVersion;
uint32_t Win32VersionValue; /* ? */
uint32_t SizeOfImage;
uint32_t SizeOfHeaders;
2009-11-24 14:53:15 +02:00
uint32_t CheckSum; /**< NT drivers only */
uint16_t Subsystem;
uint16_t DllCharacteristics;
uint64_t SizeOfStackReserve;
uint64_t SizeOfStackCommit;
uint64_t SizeOfHeapReserve;
uint64_t SizeOfHeapCommit;
uint32_t LoaderFlags; /* ? */
2009-11-24 14:53:15 +02:00
uint32_t NumberOfRvaAndSizes; /**< unreliable */
struct pe_image_data_dir DataDirectory[16];
};
2009-11-24 14:53:15 +02:00
/** PE section header */
struct pe_image_section_hdr {
2009-11-24 14:53:15 +02:00
uint8_t Name[8]; /**< may not end with NULL */
/*
union {
uint32_t PhysicalAddress;
uint32_t VirtualSize;
} AddrSize;
*/
uint32_t VirtualSize;
uint32_t VirtualAddress;
2009-11-24 14:53:15 +02:00
uint32_t SizeOfRawData; /**< multiple of FileAlignment */
uint32_t PointerToRawData; /**< offset to the section's data */
uint32_t PointerToRelocations; /**< object files only */
uint32_t PointerToLinenumbers; /**< object files only */
uint16_t NumberOfRelocations; /**< object files only */
uint16_t NumberOfLinenumbers; /**< object files only */
uint32_t Characteristics;
};
2009-11-24 14:53:15 +02:00
/** Data for the bytecode PE hook */
2009-10-02 17:33:11 +03:00
struct cli_pe_hook_data {
struct cli_exe_info exe_info;
struct pe_image_file_hdr *file_hdr;
struct pe_image_optional_hdr32 *opt32;
struct pe_image_optional_hdr64 *opt64;
struct pe_image_data_dir *dirs;
2009-11-24 14:53:15 +02:00
uint32_t overlays;/**< number of overlays */
int32_t overlays_sz;/**< size of overlays */
2009-10-02 17:33:11 +03:00
};
2009-08-31 17:26:22 +02:00
int cli_scanpe(cli_ctx *ctx);
2004-05-11 23:30:57 +00:00
2009-10-02 18:09:31 +02:00
int cli_peheader(fmap_t *map, struct cli_exe_info *peinfo);
2004-05-11 23:30:57 +00:00
#endif