2010-12-12 21:58:35 +10:00
|
|
|
/*
|
|
|
|
ansicon.h - Header file for common definitions.
|
|
|
|
|
|
|
|
Jason Hood, 12 December, 2010 (originally injdll.h, 20 June, 2009).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ANSICON_H
|
|
|
|
#define ANSICON_H
|
|
|
|
|
|
|
|
#ifndef UNICODE
|
|
|
|
# define UNICODE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2012-11-24 23:41:29 +10:00
|
|
|
#ifdef _WIN64
|
2014-02-08 18:30:53 +10:00
|
|
|
#define _WIN32_WINNT 0x0501 // at least XP required
|
2012-11-24 23:41:29 +10:00
|
|
|
#else
|
2014-02-08 18:30:53 +10:00
|
|
|
#define _WIN32_WINNT 0x0500 // at least Windows 2000 required
|
2012-11-24 23:41:29 +10:00
|
|
|
#endif
|
2017-11-21 11:46:58 +10:00
|
|
|
#define WINVER _WIN32_WINNT
|
2010-12-12 21:58:35 +10:00
|
|
|
#include <windows.h>
|
2017-11-21 11:46:58 +10:00
|
|
|
#include <tlhelp32.h>
|
2010-12-12 21:58:35 +10:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2014-01-25 23:43:41 +10:00
|
|
|
#ifndef LOAD_LIBRARY_AS_IMAGE_RESOURCE
|
|
|
|
#define LOAD_LIBRARY_AS_IMAGE_RESOURCE 0x20
|
|
|
|
#endif
|
|
|
|
#ifndef LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE
|
|
|
|
#define LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE 0x20
|
|
|
|
#endif
|
2017-11-21 11:46:58 +10:00
|
|
|
#ifndef TH32CS_SNAPMODULE32
|
|
|
|
#define TH32CS_SNAPMODULE32 0x10
|
|
|
|
#endif
|
|
|
|
#if !defined(HandleToULong) && !defined(_WIN64)
|
|
|
|
#define HandleToULong HandleToUlong
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __IMAGE_COR20_HEADER_DEFINED__
|
|
|
|
#define COMIMAGE_FLAGS_ILONLY 1
|
|
|
|
#define COMIMAGE_FLAGS_32BITREQUIRED 2
|
|
|
|
|
|
|
|
// CLR 2.0 header structure.
|
|
|
|
typedef struct IMAGE_COR20_HEADER
|
|
|
|
{
|
|
|
|
DWORD cb;
|
|
|
|
WORD MajorRuntimeVersion;
|
|
|
|
WORD MinorRuntimeVersion;
|
|
|
|
IMAGE_DATA_DIRECTORY MetaData;
|
|
|
|
DWORD Flags;
|
|
|
|
union {
|
|
|
|
DWORD EntryPointToken;
|
|
|
|
DWORD EntryPointRVA;
|
|
|
|
} DUMMYUNIONNAME;
|
|
|
|
IMAGE_DATA_DIRECTORY Resources;
|
|
|
|
IMAGE_DATA_DIRECTORY StrongNameSignature;
|
|
|
|
IMAGE_DATA_DIRECTORY CodeManagerTable;
|
|
|
|
IMAGE_DATA_DIRECTORY VTableFixups;
|
|
|
|
IMAGE_DATA_DIRECTORY ExportAddressTableJumps;
|
|
|
|
IMAGE_DATA_DIRECTORY ManagedNativeHeader;
|
|
|
|
} IMAGE_COR20_HEADER, *PIMAGE_COR20_HEADER;
|
|
|
|
#endif
|
2014-01-25 23:43:41 +10:00
|
|
|
|
2014-02-08 01:10:51 +10:00
|
|
|
#define lenof(array) (sizeof(array)/sizeof(*(array)))
|
|
|
|
#define TSIZE(size) ((size) * sizeof(TCHAR))
|
|
|
|
#define PTRSZ sizeof(PVOID)
|
|
|
|
|
|
|
|
// Macro for adding pointers/DWORDs together without C arithmetic interfering
|
|
|
|
#define MakeVA( cast, offset ) (cast)((DWORD_PTR)pDosHeader + (DWORD)(offset))
|
|
|
|
|
2017-07-25 18:18:34 +10:00
|
|
|
#define DATADIRS OptionalHeader.NumberOfRvaAndSizes
|
2014-02-05 00:21:42 +10:00
|
|
|
#define EXPORTDIR OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]
|
|
|
|
#define IMPORTDIR OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT]
|
|
|
|
#define BOUNDDIR OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT]
|
|
|
|
#define IATDIR OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT]
|
|
|
|
#define COMDIR OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR]
|
|
|
|
|
|
|
|
// Reduce the verbosity of some functions (assuming variable names).
|
|
|
|
#define ReadProcVar(a, b) ReadProcMem( a, b, sizeof(*(b)) )
|
|
|
|
#define WriteProcVar(a, b) WriteProcMem( a, b, sizeof(*(b)) )
|
|
|
|
#define ReadProcMem(a, b, c) ReadProcessMemory( ppi->hProcess, a, b, c, NULL )
|
|
|
|
#define WriteProcMem(a, b, c) WriteProcessMemory( ppi->hProcess, a, b, c, NULL )
|
|
|
|
#define VirtProtVar(a, b) VirtualProtectEx( ppi->hProcess, a, sizeof(*(a)), b, &pr )
|
|
|
|
|
2010-12-12 21:58:35 +10:00
|
|
|
|
2018-05-07 10:31:41 +10:00
|
|
|
#ifdef PDATE // i.e. from ansicon.c
|
|
|
|
#define EXTERN __declspec(dllimport) extern
|
|
|
|
#else
|
|
|
|
#define EXTERN __declspec(dllexport) extern
|
|
|
|
#endif
|
|
|
|
|
|
|
|
EXTERN int ProcessType( LPPROCESS_INFORMATION, PBYTE*, BOOL* );
|
2014-02-08 01:10:51 +10:00
|
|
|
BOOL Wow64Process( HANDLE );
|
2014-02-05 00:21:42 +10:00
|
|
|
|
2018-05-07 10:31:41 +10:00
|
|
|
#ifdef _WIN64
|
|
|
|
EXTERN
|
|
|
|
#endif
|
2014-02-08 01:10:51 +10:00
|
|
|
void InjectDLL( LPPROCESS_INFORMATION, PBYTE );
|
2018-05-04 11:45:10 +10:00
|
|
|
void RemoteLoad32( LPPROCESS_INFORMATION );
|
2014-02-08 01:10:51 +10:00
|
|
|
#ifdef _WIN64
|
|
|
|
void InjectDLL32( LPPROCESS_INFORMATION, PBYTE );
|
2018-05-07 10:31:41 +10:00
|
|
|
EXTERN void RemoteLoad64( LPPROCESS_INFORMATION );
|
|
|
|
EXTERN DWORD GetProcRVA( LPCTSTR, LPCSTR, int );
|
2014-02-08 01:10:51 +10:00
|
|
|
#else
|
2018-05-07 10:31:41 +10:00
|
|
|
EXTERN DWORD GetProcRVA( LPCTSTR, LPCSTR );
|
2014-02-08 01:10:51 +10:00
|
|
|
#endif
|
2014-02-05 00:21:42 +10:00
|
|
|
|
2017-07-25 18:18:34 +10:00
|
|
|
extern HANDLE hHeap;
|
2010-12-12 21:58:35 +10:00
|
|
|
|
2018-05-07 10:31:41 +10:00
|
|
|
EXTERN TCHAR prog_path[MAX_PATH];
|
Exclude modules from being hooked; hook only selected GUI programs.
Added environment variable ANSICON_EXC to specify modules that should not be
hooked. This should work around the nvd3d9wrap.dll issue. Since it helps to
know what the modules are, logging is now always available, controlled by -l
or ANSICON_LOG. A side-effect caused debugstr.c to move to util.c.
GUI programs are once again not hooked, unless run by "ansicon" directly or in
the ANSICON_GUI environment variable. Since not hooking still leaves ANSICON in
the environment, created ANSICON_VER as a dynamic-only variable, which can also
serve as a version check.
Due to an email requesting a reverse video option, realised I always take the
current attributes as default. This means if you turned on reverse and ran a
program, it would take the reverse as its default. Created ANSICON_DEF variable
to explicitly set the default attribute, using the current if it doesn't exist.
The reverse video option is done via a "negative" attribute (e.g. "-m-f0" is
reversed black on white, meaning you'll get white on black, with foreground
sequences changing the background). (The difference from "\e[7m" is that it
won't be reset on "\e[m".)
A child program will inherit the parent's modes (but not shift); the parent will
read the child's modes on exit (but not unload). The exception is "ansicon",
which will always start with the default modes and leave the parent unchanged.
Improved the AutoRun entry, only running "ansicon" if ANSICON_VER doesn't exist.
The "ansicon" command is always first.
Stopped -u implying -p; return the program's exit code; don't restore the
original color when just using -p; output error messages to stderr.
2011-12-14 20:53:51 +10:00
|
|
|
extern LPTSTR prog;
|
|
|
|
LPTSTR get_program_name( LPTSTR );
|
2010-12-12 21:58:35 +10:00
|
|
|
|
2018-05-07 10:31:41 +10:00
|
|
|
EXTERN TCHAR DllName[MAX_PATH];
|
|
|
|
EXTERN LPTSTR DllNameType;
|
2014-02-08 01:10:51 +10:00
|
|
|
extern char ansi_dll[MAX_PATH];
|
|
|
|
extern DWORD ansi_len;
|
|
|
|
extern char* ansi_bits;
|
|
|
|
void set_ansi_dll( void );
|
2018-05-04 11:45:10 +10:00
|
|
|
DWORD get_os_version( void );
|
2014-02-05 00:21:42 +10:00
|
|
|
|
2018-05-07 10:31:41 +10:00
|
|
|
EXTERN int log_level;
|
|
|
|
EXTERN void DEBUGSTR( int level, LPCSTR szFormat, ... );
|
|
|
|
|
|
|
|
// Replacements for C runtime functions.
|
|
|
|
#undef RtlFillMemory
|
|
|
|
#undef RtlMoveMemory
|
|
|
|
#undef RtlZeroMemory
|
|
|
|
void WINAPI RtlFillMemory( PVOID, SIZE_T, BYTE );
|
|
|
|
void WINAPI RtlMoveMemory( PVOID, const VOID*, SIZE_T );
|
|
|
|
void WINAPI RtlZeroMemory( PVOID, SIZE_T );
|
|
|
|
|
|
|
|
#define arrcpy( dst, src ) RtlMoveMemory( dst, src, sizeof(dst) )
|
|
|
|
|
|
|
|
unsigned long ac_wcstoul( const wchar_t*, wchar_t**, int );
|
|
|
|
int ac_wtoi( const wchar_t* );
|
|
|
|
long ac_wcstol( const wchar_t*, wchar_t**, int );
|
|
|
|
wchar_t* ac_wcspbrk( const wchar_t*, const wchar_t* );
|
|
|
|
wchar_t* ac_wcsrchr( const wchar_t*, wchar_t );
|
|
|
|
int ac_strnicmp( const char*, const char*, size_t );
|
|
|
|
int ac_sprintf( char*, const char*, ... );
|
|
|
|
int ac_wprintf( wchar_t*, const char*, ... );
|
2010-12-12 21:58:35 +10:00
|
|
|
|
|
|
|
#endif
|