From 7e6be3cf1e6f63eecb52670f9536e59c06a5e0f1 Mon Sep 17 00:00:00 2001 From: sunjammerx Date: Mon, 5 Aug 2002 19:13:52 +0000 Subject: [PATCH] - 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 --- Source/{ExternalCommands.cpp => Plugins.cpp} | 48 ++++++++++---------- Source/{ExternalCommands.h => Plugins.h} | 10 ++-- Source/build.cpp | 10 ++-- Source/build.h | 6 +-- Source/exehead/config.h | 2 +- Source/exehead/exec.c | 6 ++- Source/exehead/fileform.h | 4 +- Source/makenssi.cpp | 2 +- Source/script.cpp | 41 +++++++++++------ Source/tokens.cpp | 2 + Source/tokens.h | 4 +- 11 files changed, 76 insertions(+), 59 deletions(-) rename Source/{ExternalCommands.cpp => Plugins.cpp} (89%) rename Source/{ExternalCommands.h => Plugins.h} (67%) diff --git a/Source/ExternalCommands.cpp b/Source/Plugins.cpp similarity index 89% rename from Source/ExternalCommands.cpp rename to Source/Plugins.cpp index 619d2531..6c9b639b 100644 --- a/Source/ExternalCommands.cpp +++ b/Source/Plugins.cpp @@ -1,6 +1,6 @@ -#include "ExternalCommands.h" +#include "Plugins.h" #include @@ -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)) diff --git a/Source/ExternalCommands.h b/Source/Plugins.h similarity index 67% rename from Source/ExternalCommands.h rename to Source/Plugins.h index f5d3eaf1..9f920b17 100644 --- a/Source/ExternalCommands.h +++ b/Source/Plugins.h @@ -1,7 +1,7 @@ -#ifndef __X18_EXTERNALCOMMANDS_H -#define __X18_EXTERNALCOMMANDS_H +#ifndef __X18_PLUGINS_H +#define __X18_PLUGINS_H #include @@ -10,12 +10,12 @@ #include -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); diff --git a/Source/build.cpp b/Source/build.cpp index 7a431908..d5abed5d 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -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; } } diff --git a/Source/build.h b/Source/build.h index b915fe93..78d12c1f 100644 --- a/Source/build.h +++ b/Source/build.h @@ -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 diff --git a/Source/exehead/config.h b/Source/exehead/config.h index 82e5e253..28bda974 100644 --- a/Source/exehead/config.h +++ b/Source/exehead/config.h @@ -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 diff --git a/Source/exehead/exec.c b/Source/exehead/exec.c index a6ef631e..3248a5f7 100644 --- a/Source/exehead/exec.c +++ b/Source/exehead/exec.c @@ -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; diff --git a/Source/exehead/fileform.h b/Source/exehead/fileform.h index 1f40474a..3722dbc3 100644 --- a/Source/exehead/fileform.h +++ b/Source/exehead/fileform.h @@ -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 }; diff --git a/Source/makenssi.cpp b/Source/makenssi.cpp index 010f81ee..bb671e62 100644 --- a/Source/makenssi.cpp +++ b/Source/makenssi.cpp @@ -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; diff --git a/Source/script.cpp b/Source/script.cpp index 58993232..a9f16699 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -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; } diff --git a/Source/tokens.cpp b/Source/tokens.cpp index 6a4755e0..f96cc10e 100644 --- a/Source/tokens.cpp +++ b/Source/tokens.cpp @@ -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) diff --git a/Source/tokens.h b/Source/tokens.h index 7aa5043f..b78282bb 100644 --- a/Source/tokens.h +++ b/Source/tokens.h @@ -185,10 +185,10 @@ enum TOK_SECTIONSETFLAGS, TOK_SECTIONGETFLAGS, TOK_SETSHELLVARCONTEXT, - + TOK_PLUGINDIR, TOK__LAST, - TOK__EXTERNALCOMMAND + TOK__PLUGINCOMMAND }; #endif//_TOKENS_H_ \ No newline at end of file