- Fixed a bug in the dll export scanner (spotted and cured by CodeSquid)

- Fixed a bug in the installer runtime (spotted by CodeSquid)
- Renamed all usage of ExternalCommand to Plugin
- Added a compile time PluginDir command


git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@650 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
sunjammerx 2002-08-05 19:13:52 +00:00
parent 334dad1e15
commit 7e6be3cf1e
11 changed files with 76 additions and 59 deletions

View file

@ -1,6 +1,6 @@
#include "ExternalCommands.h"
#include "Plugins.h"
#include <windows.h>
@ -137,7 +137,7 @@ enum
};
void ExternalCommands::FindCommands(char* path,bool displayInfo)
void Plugins::FindCommands(char* path,bool displayInfo)
{
if (path)
{
@ -149,13 +149,11 @@ void ExternalCommands::FindCommands(char* path,bool displayInfo)
HANDLE handle;
char* slashPtr;
slashPtr = strrchr(path,'\\');
if (slashPtr && slashPtr-path < length)
length = slashPtr-path;
slashPtr = strrchr(path,'/');
if (slashPtr && slashPtr-path < length)
length = slashPtr-path;
if (path[length-1] == '\\' ||
path[length-1] == '/')
{
length--;
}
char* basePath = new char [length+1];
strncpy(basePath,path,length);
@ -185,7 +183,7 @@ void ExternalCommands::FindCommands(char* path,bool displayInfo)
}
}
void ExternalCommands::GetExports(char* pathToDll,bool displayInfo)
void Plugins::GetExports(char* pathToDll,bool displayInfo)
{
if (pathToDll)
{
@ -225,12 +223,12 @@ void ExternalCommands::GetExports(char* pathToDll,bool displayInfo)
// read the file offset stored at 0x3c (a single byte)
// then find the pe signature bytes stored at that offset
unsigned char peheaderoffset = dlldata[0x3c];
unsigned long* peheaderoffset = (unsigned long*) &dlldata[0x3c];
unsigned char pesignature[4] = {
dlldata[peheaderoffset+0],
dlldata[peheaderoffset+1],
dlldata[peheaderoffset+2],
dlldata[peheaderoffset+3],
dlldata[(*peheaderoffset)+0],
dlldata[(*peheaderoffset)+1],
dlldata[(*peheaderoffset)+2],
dlldata[(*peheaderoffset)+3],
};
if (pesignature[0] == 'P' &&
@ -239,15 +237,15 @@ void ExternalCommands::GetExports(char* pathToDll,bool displayInfo)
pesignature[3] == '\0')
{
// after the signature comes the COFF header
COFFHeader* coffHeader = (COFFHeader*)&dlldata[peheaderoffset+4];
COFFHeader* coffHeader = (COFFHeader*)&dlldata[(*peheaderoffset)+4];
if (coffHeader->Characteristics & IMAGE_FILE_DLL)
{
// after the COFF header comes the Optional Header magic number
// (two bytes)
unsigned char ohmagicnumber[2] = {
dlldata[peheaderoffset+4+COFFHeaderSize+0],
dlldata[peheaderoffset+4+COFFHeaderSize+1]
dlldata[(*peheaderoffset)+4+COFFHeaderSize+0],
dlldata[(*peheaderoffset)+4+COFFHeaderSize+1]
};
// 0x10b means a PE header, but 0x20b means a PE+ header
@ -265,7 +263,7 @@ void ExternalCommands::GetExports(char* pathToDll,bool displayInfo)
const int standardHeaderSize = (plus ? StandardHeaderSizePlus : StandardHeaderSize);
const int windowsHeaderSize = (plus ? WindowsHeaderSizePlus : WindowsHeaderSize);
int optionalHeaderOffset = peheaderoffset+4+COFFHeaderSize;
int optionalHeaderOffset = (*peheaderoffset)+4+COFFHeaderSize;
StandardHeader* standardHeader = (StandardHeader*)&dlldata[optionalHeaderOffset];
WindowsSpecificFields* windowsHeader = (WindowsSpecificFields*)&dlldata[optionalHeaderOffset+standardHeaderSize+4];
DataDirectory* directories = (DataDirectory*)&dlldata[optionalHeaderOffset+standardHeaderSize+windowsHeaderSize+4];
@ -273,7 +271,7 @@ void ExternalCommands::GetExports(char* pathToDll,bool displayInfo)
DataDirectory* exportHeader = directories;
SectionHeader* sectionTable =
(SectionHeader*) &dlldata[
peheaderoffset
(*peheaderoffset)
+ 4
+ COFFHeaderSize
+ coffHeader->SizeOfOptionalHeader];
@ -319,17 +317,17 @@ void ExternalCommands::GetExports(char* pathToDll,bool displayInfo)
}
}
bool ExternalCommands::IsExternalCommand(char* token)
bool Plugins::IsPluginCommand(char* token)
{
return GetExternalCommandDll(token) ? true : false;
return GetPluginDll(token) ? true : false;
}
char* ExternalCommands::GetExternalCommandDll(char* command)
char* Plugins::GetPluginDll(char* command)
{
return m_commands.find(command);
}
void ExternalCommands::StoreDllDataHandle(char* command,int handle)
void Plugins::StoreDllDataHandle(char* command,int handle)
{
int idx = -1;
m_commands.defines.find(command,0,&idx);
@ -340,7 +338,7 @@ void ExternalCommands::StoreDllDataHandle(char* command,int handle)
}
}
int ExternalCommands::GetDllDataHandle(char* command)
int Plugins::GetDllDataHandle(char* command)
{
int idx = -1;
if (-1 != m_commands.defines.find(command,0,&idx))

View file

@ -1,7 +1,7 @@
#ifndef __X18_EXTERNALCOMMANDS_H
#define __X18_EXTERNALCOMMANDS_H
#ifndef __X18_PLUGINS_H
#define __X18_PLUGINS_H
#include <windows.h>
@ -10,12 +10,12 @@
#include <vector>
class ExternalCommands
class Plugins
{
public:
void FindCommands(char*,bool);
bool IsExternalCommand(char*);
char* GetExternalCommandDll(char*);
bool IsPluginCommand(char*);
char* GetPluginDll(char*);
int GetDllDataHandle(char*);
void StoreDllDataHandle(char*,int);

View file

@ -1824,18 +1824,18 @@ void CEXEBuild::print_warnings()
// Added by Ximon Eighteen 5th August 2002
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
void CEXEBuild::build_external_command_table(void)
void CEXEBuild::build_plugin_table(void)
{
char* nsisdir = definedlist.find("NSISDIR");
if (nsisdir)
{
char* searchPath = new char [strlen(nsisdir)+12];
char* searchPath = new char [strlen(nsisdir)+6];
if (searchPath)
{
strcpy(searchPath,nsisdir);
strcat(searchPath,"\\dlls\\*.dll");
INFO_MSG("\nProcessing plugin dlls: \"%s\"\n",searchPath);
m_externalCommands.FindCommands(searchPath,display_info?true:false);
strcat(searchPath,"\\bin");
INFO_MSG("\nProcessing plugin dlls: \"%s\\*.dll\"\n",searchPath);
m_plugins.FindCommands(searchPath,display_info?true:false);
delete[] searchPath;
}
}

View file

@ -20,7 +20,7 @@ using namespace std;
#endif//NSIS_CONFIG_COMPRESSION_SUPPORT
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
#include "ExternalCommands.h"
#include "Plugins.h"
#endif //NSIS_CONFIG_PLUGIN_SUPPORT
#ifdef NSIS_CONFIG_CRC_SUPPORT
@ -52,7 +52,7 @@ class CEXEBuild {
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
// Added by Ximon Eighteen 5th August 2002
void build_external_command_table(void);
void build_plugin_table(void);
#endif //NSIS_CONFIG_PLUGIN_SUPPORT
// process a script (you can process as many scripts as you want,
@ -108,7 +108,7 @@ class CEXEBuild {
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
// Added by Ximon Eighteen 5th August 2002
ExternalCommands m_externalCommands;
Plugins m_plugins;
#endif //NSIS_CONFIG_PLUGIN_SUPPORT
// build.cpp functions used mostly within build.cpp

View file

@ -200,7 +200,7 @@
// "CallInstDLL dll command" had been invoked.
// - When the installer exits any extracted temporary dlls will
// be deleted.
//#define NSIS_CONFIG_PLUGIN_SUPPORT
#define NSIS_CONFIG_PLUGIN_SUPPORT
// fixes

View file

@ -1424,7 +1424,7 @@ static int ExecuteEntry(entry *entries, int pos)
#endif //NSIS_CONFIG_VISIBLE_SUPPORT
// Added by Ximon Eighteen 5th August 2002
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
case EW_EXTERNALCOMMANDPREP:
case EW_PLUGINCOMMANDPREP:
{
// parms[0] - dll name
// parms[1] - function name
@ -1447,13 +1447,15 @@ static int ExecuteEntry(entry *entries, int pos)
DllPathsAdd(parms[0],buf);
}
else
lstrcpy(buf,dllPath);
// leave buf containing the dll path
// and buf2 containing the function name
process_string_fromtab(buf2,parms[1]);
}
return 0;
case EW_EXTERNALCOMMAND:
case EW_PLUGINCOMMAND:
{
// parms contain command arguments
FARPROC funke;

View file

@ -122,8 +122,8 @@ enum
EW_GETLABELADDR, // both of these get converted to EW_ASSIGNVAR
EW_GETFUNCTIONADDR,
EW_EXTERNALCOMMANDPREP,
EW_EXTERNALCOMMAND
EW_PLUGINCOMMANDPREP,
EW_PLUGINCOMMAND
};

View file

@ -113,7 +113,7 @@ int main(int argc, char **argv)
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
// Added by Ximon Eighteen 5th August 2002
build.build_external_command_table();
build.build_plugin_table();
#endif //NSIS_CONFIG_PLUGIN_SUPPORT
if (!g_output) g_output=stdout;

View file

@ -97,11 +97,11 @@ parse_again:
// Added by Ximon Eighteen 5th August 2002
// We didn't recognise this command, could it be the name of a
// function exported from a dll?
if (m_externalCommands.IsExternalCommand(line.gettoken_str(0)))
if (m_plugins.IsPluginCommand(line.gettoken_str(0)))
{
np = 0; // parameters are optional
op = -1; // unlimited number of optional parameters
tkid = TOK__EXTERNALCOMMAND;
tkid = TOK__PLUGINCOMMAND;
}
else
#endif
@ -3190,8 +3190,18 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char
///////////////////////////////////////////////////////////////////////////////
// Added by Ximon Eighteen 5th August 2002
case TOK__EXTERNALCOMMAND:
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT
case TOK_PLUGINDIR:
{
if (line.getnumtokens() == 2)
{
SCRIPT_MSG("PluginDir: \"%s\"\n",line.gettoken_str(1));
m_plugins.FindCommands(line.gettoken_str(1),display_info?true:false);
return PS_OK;
}
}
return PS_ERROR;
case TOK__PLUGINCOMMAND:
{
if (line.getnumtokens()-1 > MAX_ENTRY_OFFSETS)
{
@ -3199,10 +3209,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char
return PS_ERROR;
}
char* dllPath = m_externalCommands.GetExternalCommandDll(line.gettoken_str(0));
char* dllPath = m_plugins.GetPluginDll(line.gettoken_str(0));
if (dllPath)
{
int dataHandle = m_externalCommands.GetDllDataHandle(dllPath);
int dataHandle = m_plugins.GetDllDataHandle(dllPath);
if (dataHandle == -1)
{
int error;
@ -3212,18 +3222,18 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char
return error;
}
m_externalCommands.StoreDllDataHandle(line.gettoken_str(0),dataHandle);
m_plugins.StoreDllDataHandle(line.gettoken_str(0),dataHandle);
}
// Create the runtime command to execute the custom instruction
ent.which = EW_EXTERNALCOMMANDPREP;
ent.which = EW_PLUGINCOMMANDPREP;
ent.offsets[0] = add_string(dllPath);
ent.offsets[1] = add_string(line.gettoken_str(0));
ent.offsets[2] = dataHandle;
add_entry(&ent);
SCRIPT_MSG("Plugin Command: %s",line.gettoken_str(0));
ent.which = EW_EXTERNALCOMMAND;
ent.which = EW_PLUGINCOMMAND;
for (int i = 0; i < MAX_ENTRY_OFFSETS && i+1 < line.getnumtokens(); i++)
{
@ -3240,14 +3250,19 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char
return add_entry(&ent);
}
ERROR_MSG("Error: Plugin dll for command \"%s\" not found.\n",line.gettoken_str(0));
return PS_ERROR;
}
else
ERROR_MSG("Error: Plugin dll for command \"%s\" not found.\n",line.gettoken_str(0));
}
return PS_ERROR;
#else
ERROR_MSG("Error: %s specified, NSIS_CONFIG_PLUGIN_SUPPORT not defined.\n",line.gettoken_str(0));
case TOK_PLUGINDIR:
case TOK__PLUGINCOMMAND:
{
ERROR_MSG("Error: %s specified, NSIS_CONFIG_PLUGIN_SUPPORT not defined.\n",line.gettoken_str(0));
}
return PS_ERROR;
#endif// NSIS_CONFIG_PLUGIN_SUPPORT
default: break;
}

View file

@ -193,6 +193,8 @@ static tokenType tokenlist[TOK__LAST] =
{TOK_GETLABELADDR,"GetLabelAddress",2,0,"output label"},
{TOK_GETCURRENTADDR,"GetCurrentAddress",1,0,"output"},
{TOK_PLUGINDIR,"PluginDir",1,0,"SetPluginDir directory"},
};
void CEXEBuild::print_help(char *commandname)

View file

@ -185,10 +185,10 @@ enum
TOK_SECTIONSETFLAGS,
TOK_SECTIONGETFLAGS,
TOK_SETSHELLVARCONTEXT,
TOK_PLUGINDIR,
TOK__LAST,
TOK__EXTERNALCOMMAND
TOK__PLUGINCOMMAND
};
#endif//_TOKENS_H_