diff options
Diffstat (limited to 'util/scripts/win-binary/nsis/qtnsisext')
-rw-r--r-- | util/scripts/win-binary/nsis/qtnsisext/binpatch.cpp | 216 | ||||
-rw-r--r-- | util/scripts/win-binary/nsis/qtnsisext/binpatch.h | 81 | ||||
-rw-r--r-- | util/scripts/win-binary/nsis/qtnsisext/exdll.h | 137 | ||||
-rw-r--r-- | util/scripts/win-binary/nsis/qtnsisext/licensefinder.cpp | 250 | ||||
-rw-r--r-- | util/scripts/win-binary/nsis/qtnsisext/licensefinder.h | 74 | ||||
-rw-r--r-- | util/scripts/win-binary/nsis/qtnsisext/mingw.cpp | 156 | ||||
-rw-r--r-- | util/scripts/win-binary/nsis/qtnsisext/mingw.h | 45 | ||||
-rwxr-xr-x | util/scripts/win-binary/nsis/qtnsisext/qtlibspatcher.exe | bin | 0 -> 77824 bytes | |||
-rw-r--r-- | util/scripts/win-binary/nsis/qtnsisext/qtlibspatcher.vcproj | 206 | ||||
-rw-r--r-- | util/scripts/win-binary/nsis/qtnsisext/qtlibspatchermain.cpp | 200 | ||||
-rw-r--r-- | util/scripts/win-binary/nsis/qtnsisext/qtnsisext.cpp | 495 | ||||
-rw-r--r-- | util/scripts/win-binary/nsis/qtnsisext/qtnsisext.dll | bin | 0 -> 77824 bytes | |||
-rw-r--r-- | util/scripts/win-binary/nsis/qtnsisext/qtnsisext.vcproj | 164 |
13 files changed, 2024 insertions, 0 deletions
diff --git a/util/scripts/win-binary/nsis/qtnsisext/binpatch.cpp b/util/scripts/win-binary/nsis/qtnsisext/binpatch.cpp new file mode 100644 index 0000000..1c5109c --- /dev/null +++ b/util/scripts/win-binary/nsis/qtnsisext/binpatch.cpp @@ -0,0 +1,216 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the utils of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <stdio.h> +#include <locale> + +#include "binpatch.h" + +// returns positive value if it finds a null termination inside the buffer +long BinPatch::getBufferStringLength(char *data, char *end) +{ + long size = 0; + while (data < end) { + if (*data == '\0') + return size; + ++data; + ++size; + } + + return -1; +} + +// returns true if data ends with one of the tokens. (Sep. with ;) +bool BinPatch::endsWithTokens(const char *data) +{ + if(strlen(endTokens) > 0) { + char endstmp[1024]; + ulong tlen = ulong(strlen(data)); + + if(strlen(endTokens) >= sizeof(endstmp)) + return false; + + strcpy(endstmp, endTokens); + + char *token = strtok(endstmp, ";"); + + while(token != NULL) { + // check if it ends with the token + if ((tlen >= strlen(token)) + && (stricmp((data+tlen)-strlen(token), token) == 0)) + return true; + token = strtok(NULL, ";"); + } + } else { + return true; //true if no tokens + } + + return false; //no matching tokens +} + +bool BinPatch::patchHelper(char *inbuffer, const char *oldstr, const char *newstr, size_t len, long *rw) +{ + char nc1 = *oldstr; + char nc2 = 0; + char *inend = inbuffer + len; + size_t oldlen = strlen(oldstr); + size_t newlen = strlen(newstr); + char *instart = inbuffer; + *rw = 0; + bool write = true; + + isupper(nc1) ? nc2 = tolower(nc1) : nc2 = toupper(nc1); + + while(inbuffer < inend) { + if ((*inbuffer == nc1) || (*inbuffer == nc2)) { + if (inbuffer > (inend-oldlen) || inbuffer > (inend-newlen)) { + *rw = (long)(inend-inbuffer); //rewind, not enough to make a compare + break; + } + + if (strnicmp(inbuffer, oldstr, oldlen) == 0) { + if (useLength && (instart == inbuffer)) { + *rw = (long)(len+1); //we don't have access to the length byte, rewind all + 1! + write = false; + break; + } + + long oldsize = -1; + if (useLength) { //VC60 + oldsize = (unsigned char)(*(inbuffer-1)); + + // vc60 pdb files sometimes uses 0A, then it should be null terminated + if (oldsize < (long)oldlen) { + if (oldsize != 0x0A) { //strange case... skip + inbuffer+=oldlen; + continue; + } + + oldsize = getBufferStringLength(inbuffer, inend); + + if (oldsize < 0) { + *rw = (long)(inend-inbuffer); //rewind, entire string not in buffer + break; + } + } + + if (inbuffer > (inend-oldsize)) { + *rw = (long)(inend-inbuffer); //rewind, entire string not in buffer + break; + } + } else { //VC7x + oldsize = getBufferStringLength(inbuffer, inend); + if (oldsize < 0) { + *rw = (long)(inend-inbuffer); //rewind, entire string not in buffer + break; + } + } + + char oldPath[1024]; + if (oldsize > sizeof(oldPath)) { + //at least don't crash + inbuffer+=oldsize; + continue; + } + memset(oldPath, '\0', sizeof(oldPath)); + strncpy(oldPath, newstr, newlen); + + if (insertReplace) + strncat(oldPath, inbuffer+oldlen, oldsize-oldlen); + + // just replace if it ends with a token in endTokens + if (endsWithTokens(oldPath)) { + if (oldsize < (long)strlen(oldPath)) + oldsize = (long)strlen(oldPath); + + memcpy(inbuffer, oldPath, oldsize); + } + + inbuffer+=oldsize; + continue; + } + } + ++inbuffer; + } + + return write; +} + +bool BinPatch::patch(const char *oldstr, const char *newstr) +{ + size_t oldlen = strlen(oldstr); + size_t newlen = strlen(newstr); + + if ((!fileName || strlen(fileName) < 1) + || (!oldstr || oldlen < 1) + || (!newstr || newlen < 1)) + return false; + + FILE *input; + + if (!(input = fopen(fileName, "r+b"))) + { + fprintf(stderr, "Cannot open file %s!\n", fileName); + return false; + } + + char data[60000]; + long rw = 0; + long offset = 0; + + size_t len; + len = fread(data, sizeof(char), sizeof(data), input); + + do { + if (patchHelper(data, oldstr, newstr, len, &rw)) { + fseek(input, offset, SEEK_SET); //overwrite + fwrite(data, sizeof(char), len, input); + } + + offset += (long)((-rw) + len); + if (fseek(input, offset, SEEK_SET) != 0) + break; + len = fread(data, sizeof(char), sizeof(data), input); + } while(!(feof(input) && (len <= oldlen || len <= newlen))); + + fclose(input); + + return true; +} diff --git a/util/scripts/win-binary/nsis/qtnsisext/binpatch.h b/util/scripts/win-binary/nsis/qtnsisext/binpatch.h new file mode 100644 index 0000000..7cbc6a5 --- /dev/null +++ b/util/scripts/win-binary/nsis/qtnsisext/binpatch.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the utils of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef BINPATCH_H +#define BINPATCH_H + +#include <string.h> + +typedef unsigned long ulong; +typedef unsigned int uint; + +class BinPatch +{ +public: + BinPatch(const char *file) + : useLength(false), insertReplace(false) + { + strcpy(endTokens, ""); + strcpy(fileName, file); + } + + void enableUseLength(bool enabled) + { useLength = enabled; } + void enableInsertReplace(bool enabled) + { insertReplace = enabled; } + void setEndTokens(const char *tokens) + { strcpy(endTokens, tokens); } + + bool patch(const char *oldstr, const char *newstr); + +private: + long getBufferStringLength(char *data, char *end); + bool endsWithTokens(const char *data); + + bool patchHelper(char *inbuffer, const char *oldstr, + const char *newstr, size_t len, long *rw); + + bool useLength; + bool insertReplace; + char endTokens[1024]; + char fileName[1024]; +}; + +#endif
\ No newline at end of file diff --git a/util/scripts/win-binary/nsis/qtnsisext/exdll.h b/util/scripts/win-binary/nsis/qtnsisext/exdll.h new file mode 100644 index 0000000..3f5a0ef --- /dev/null +++ b/util/scripts/win-binary/nsis/qtnsisext/exdll.h @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the utils of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef _EXDLL_H_ +#define _EXDLL_H_ + +// only include this file from one place in your DLL. +// (it is all static, if you use it in two places it will fail) + +#define EXDLL_INIT() { \ + g_stringsize=string_size; \ + g_stacktop=stacktop; \ + g_variables=variables; } + +// For page showing plug-ins +#define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8) +#define WM_NOTIFY_CUSTOM_READY (WM_USER+0xd) +#define NOTIFY_BYE_BYE 'x' + +typedef struct _stack_t { + struct _stack_t *next; + char text[1]; // this should be the length of string_size +} stack_t; + + +static unsigned int g_stringsize; +static stack_t **g_stacktop; +static char *g_variables; + +static int __stdcall popstring(char *str); // 0 on success, 1 on empty stack +static void __stdcall pushstring(char *str); + +enum +{ +INST_0, // $0 +INST_1, // $1 +INST_2, // $2 +INST_3, // $3 +INST_4, // $4 +INST_5, // $5 +INST_6, // $6 +INST_7, // $7 +INST_8, // $8 +INST_9, // $9 +INST_R0, // $R0 +INST_R1, // $R1 +INST_R2, // $R2 +INST_R3, // $R3 +INST_R4, // $R4 +INST_R5, // $R5 +INST_R6, // $R6 +INST_R7, // $R7 +INST_R8, // $R8 +INST_R9, // $R9 +INST_CMDLINE, // $CMDLINE +INST_INSTDIR, // $INSTDIR +INST_OUTDIR, // $OUTDIR +INST_EXEDIR, // $EXEDIR +INST_LANG, // $LANGUAGE +__INST_LAST +}; + + +// utility functions (not required but often useful) +static int __stdcall popstring(char *str) +{ + stack_t *th; + if (!g_stacktop || !*g_stacktop) return 1; + th=(*g_stacktop); + lstrcpy(str,th->text); + *g_stacktop = th->next; + GlobalFree((HGLOBAL)th); + return 0; +} + +static void __stdcall pushstring(char *str) +{ + stack_t *th; + if (!g_stacktop) return; + th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize); + lstrcpyn(th->text,str,g_stringsize); + th->next=*g_stacktop; + *g_stacktop=th; +} + +static char * __stdcall getuservariable(int varnum) +{ + if (varnum < 0 || varnum >= __INST_LAST) return NULL; + return g_variables+varnum*g_stringsize; +} + +static void __stdcall setuservariable(int varnum, char *var) +{ + if (var != NULL && varnum >= 0 && varnum < __INST_LAST) + lstrcpy(g_variables + varnum*g_stringsize, var); +} + + + +#endif//_EXDLL_H_
\ No newline at end of file diff --git a/util/scripts/win-binary/nsis/qtnsisext/licensefinder.cpp b/util/scripts/win-binary/nsis/qtnsisext/licensefinder.cpp new file mode 100644 index 0000000..7de1618 --- /dev/null +++ b/util/scripts/win-binary/nsis/qtnsisext/licensefinder.cpp @@ -0,0 +1,250 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the utils of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "licensefinder.h" + +LicenseFinder::LicenseFinder() +{ + searched = false; + memset(licensee, '\0', sizeof(licensee)*sizeof(char)); + memset(m_key, '\0', sizeof(m_key)*sizeof(char)); + memset(m_oldkey, '\0', sizeof(m_oldkey)*sizeof(char)); + memset(m_customerId, '\0', sizeof(m_customerId)*sizeof(char)); + memset(m_products, '\0', sizeof(m_products)*sizeof(char)); + memset(m_expiryDate, '\0', sizeof(m_expiryDate)*sizeof(char)); +} + +char *LicenseFinder::getLicensee() +{ + if (!searched) + searchLicense(); + + return licensee; +} + +char *LicenseFinder::getLicenseKey() +{ + if (!searched) + searchLicense(); + + return m_key; +} + +char *LicenseFinder::getOldLicenseKey() +{ + if (!searched) + searchLicense(); + + return m_oldkey; +} + +char *LicenseFinder::getCustomerID() +{ + if (!searched) + searchLicense(); + + return m_customerId; +} + +char *LicenseFinder::getProducts() +{ + if (!searched) + searchLicense(); + + return m_products; +} + +char *LicenseFinder::getExpiryDate() +{ + if (!searched) + searchLicense(); + + return m_expiryDate; +} + +void LicenseFinder::searchLicense() +{ + searched = true; + char *path = getenv("HOME"); + if (path && lookInDirectory(path)) + return; + + path = getenv("USERPROFILE"); + if (path && lookInDirectory(path)) + return; + + path = getenv("HOMEDRIVE"); + if (path) { + char *dir = getenv("HOMEPATH"); + if (dir) { + char *combined = (char*)malloc(sizeof(char)*(strlen(path) + strlen(dir) + 1)); + strcpy(combined, path); + strcat(combined, dir); + lookInDirectory(combined); + free(combined); + } + } +} + +bool LicenseFinder::lookInDirectory(const char *dir) +{ + FILE *f; + char file[_MAX_PATH]; + char buf[60000]; + + // reset the buffers again, just to be safe :) + memset(file, '\0', sizeof(file)); + memset(buf, '\0', sizeof(buf)); + memset(licensee, '\0', sizeof(licensee)); + memset(m_key, '\0', sizeof(m_key)); + memset(m_oldkey, '\0', sizeof(m_oldkey)); + memset(m_customerId, '\0', sizeof(m_customerId)); + memset(m_products, '\0', sizeof(m_products)); + memset(m_expiryDate, '\0', sizeof(m_expiryDate)); + + if (((strlen(dir)+strlen("\\.qt-license"))*sizeof(char)) >= _MAX_PATH) + return false; + + strcpy(file, dir); + strcat(file, "\\.qt-license"); + if ((f = fopen(file, "r")) == NULL) + return false; + + size_t r = fread(buf, sizeof(char), 59999, f); + buf[r] = '\0'; + + /* Licensee */ + const char *pat1 = "Licensee=\""; + char *tmp = findPattern(buf, pat1, ulong(r)); + if (tmp && (strlen(tmp) > 1)) { + char *end = strchr(tmp, '\"'); + if (end && ((end-tmp) < MAX_LICENSEE_LENGTH)) + strncpy(licensee, tmp, end-tmp); + } + + /* LicenseKey */ + const char *pat2 = "LicenseKeyExt="; + tmp = findPattern(buf, pat2, ulong(r)); + if (tmp) { + char *end = strchr(tmp, '\r'); + if (!end) + end = strchr(tmp, '\n'); + if (end && ((end-tmp) < MAX_KEY_LENGTH)) + strncpy(m_key, tmp, end-tmp); + else if (strlen(tmp) < MAX_KEY_LENGTH) + strcpy(m_key, tmp); + } + + /* OldLicenseKey */ + const char *pat3 = "LicenseKey="; + tmp = findPattern(buf, pat3, ulong(r)); + if (tmp) { + char *end = strchr(tmp, '\r'); + if (!end) + end = strchr(tmp, '\n'); + if (end && ((end-tmp) < MAX_KEY_LENGTH)) + strncpy(m_oldkey, tmp, end-tmp); + else if (strlen(tmp) < MAX_KEY_LENGTH) + strcpy(m_oldkey, tmp); + } + + /* CustomerID */ + const char *pat4 = "CustomerID=\""; + tmp = findPattern(buf, pat4, ulong(r)); + if (tmp && (strlen(tmp) > 1)) { + char *end = strchr(tmp, '\"'); + if (end && ((end-tmp) < MAX_QT3INFO_LENGTH)) + strncpy(m_customerId, tmp, end-tmp); + } + + /* Products */ + const char *pat5 = "Products=\""; + tmp = findPattern(buf, pat5, ulong(r)); + if (tmp && (strlen(tmp) > 1)) { + char *end = strchr(tmp, '\"'); + if (end && ((end-tmp) < MAX_QT3INFO_LENGTH)) + strncpy(m_products, tmp, end-tmp); + } + + /* ExpiryDate */ + const char *pat6 = "ExpiryDate="; + tmp = findPattern(buf, pat6, ulong(r)); + if (tmp) { + char *end = strchr(tmp, '\r'); + if (!end) + end = strchr(tmp, '\n'); + if (end && ((end-tmp) < MAX_QT3INFO_LENGTH)) + strncpy(m_expiryDate, tmp, end-tmp); + else if (strlen(tmp) < MAX_QT3INFO_LENGTH) + strcpy(m_expiryDate, tmp); + } + + fclose(f); + + return true; +} + +/* copied from binpatch.cpp */ +char *LicenseFinder::findPattern(char *h, const char *n, ulong hlen) +{ + if (!h || !n || hlen == 0) + return 0; + + ulong nlen; + + char nc = *n++; + nlen = ulong(strlen(n)); + char hc; + + do { + do { + hc = *h++; + if (hlen-- < 1) + return 0; + } while (hc != nc); + if (nlen > hlen) + return 0; + } while (strncmp(h, n, nlen) != 0); + return h + nlen; +}
\ No newline at end of file diff --git a/util/scripts/win-binary/nsis/qtnsisext/licensefinder.h b/util/scripts/win-binary/nsis/qtnsisext/licensefinder.h new file mode 100644 index 0000000..0957d65 --- /dev/null +++ b/util/scripts/win-binary/nsis/qtnsisext/licensefinder.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the utils of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef LICENSEFINDER_H +#define LICENSEFINDER_H + +#define MAX_KEY_LENGTH 512 +#define MAX_LICENSEE_LENGTH 512 +#define MAX_QT3INFO_LENGTH 512 + +typedef unsigned long ulong; + +class LicenseFinder +{ +public: + LicenseFinder(); + char *getLicenseKey(); + char *getOldLicenseKey(); + char *getLicensee(); + char *getCustomerID(); + char *getProducts(); + char *getExpiryDate(); + +private: + void searchLicense(); + bool lookInDirectory(const char* dir); + char *findPattern(char *h, const char *n, ulong hlen); + bool searched; + char m_key[MAX_KEY_LENGTH]; + char m_oldkey[MAX_KEY_LENGTH]; + char licensee[MAX_LICENSEE_LENGTH]; + char m_customerId[MAX_QT3INFO_LENGTH]; + char m_products[MAX_QT3INFO_LENGTH]; + char m_expiryDate[MAX_QT3INFO_LENGTH]; +}; + +#endif
\ No newline at end of file diff --git a/util/scripts/win-binary/nsis/qtnsisext/mingw.cpp b/util/scripts/win-binary/nsis/qtnsisext/mingw.cpp new file mode 100644 index 0000000..15ff3c1 --- /dev/null +++ b/util/scripts/win-binary/nsis/qtnsisext/mingw.cpp @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the utils of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <windows.h> +#include <io.h> +#include <stdio.h> +#include "mingw.h" + +HANDLE hChildStdoutWr, hChildStdoutRd; + +#define VERSION_SIZE 30 +#define WIN32_VERSION_STRING "__W32API_VERSION 3.2" + +BOOL CreateChildProcess(char *command) +{ + PROCESS_INFORMATION piProcInfo; + STARTUPINFOA siStartInfo; + BOOL bFuncRetn = FALSE; + + ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) ); + + ZeroMemory( &siStartInfo, sizeof(STARTUPINFOA) ); + siStartInfo.cb = sizeof(STARTUPINFOA); + siStartInfo.hStdError = hChildStdoutWr; + siStartInfo.hStdOutput = hChildStdoutWr; + siStartInfo.dwFlags |= STARTF_USESTDHANDLES; + + bFuncRetn = CreateProcessA(NULL, + command, + NULL, // process security attributes + NULL, // thread security attributes + TRUE, // inherit handles + CREATE_NO_WINDOW, + NULL, // use environment + NULL, // use current directory + &siStartInfo, + &piProcInfo); + + if (bFuncRetn == 0) + return 0; + else + { + CloseHandle(piProcInfo.hProcess); + CloseHandle(piProcInfo.hThread); + return bFuncRetn; + } +} + +void getMinGWVersion(char *path, int *major, int *minor, int *patch) +{ + char command[MINGW_BUFFER_SIZE]; + char instr[VERSION_SIZE]; + + strcpy(command, path); + strcat(command, "\\bin\\gcc.exe --version"); + + SECURITY_ATTRIBUTES saAttr; + + saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); + saAttr.bInheritHandle = TRUE; + saAttr.lpSecurityDescriptor = NULL; + + if (!CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) + return;; + + if (CreateChildProcess(command) == 0) + return; + + DWORD nBytes = 0; + ReadFile(hChildStdoutRd, instr, VERSION_SIZE, &nBytes, NULL); + instr[VERSION_SIZE-1] = '\0'; + + char *gcc = strstr(instr, "(GCC)"); + if (gcc == NULL) + return; + + sscanf(gcc, "(GCC) %d.%d.%d ", major, minor, patch); +} + +bool hasValidIncludeFiles(char *path) +{ + char filename[MINGW_BUFFER_SIZE]; + char buffer[MINGW_BUFFER_SIZE]; + + strcpy(filename, path); + strcat(filename, "\\include\\w32api.h"); + + FILE *finc; + if ((finc = fopen(filename, "rb")) == NULL) + return false; + + memset(buffer, '\0', sizeof(char)*MINGW_BUFFER_SIZE); + fread(buffer, sizeof(char), MINGW_BUFFER_SIZE-1, finc); + + if (strstr(buffer, WIN32_VERSION_STRING) != NULL) + return true; + + return false; +} + +bool shInEnvironment() +{ + char chpath[_MAX_PATH]; + char *env = getenv("PATH"); + char seps[] = ";"; + char *path; + + path = strtok(env, seps); + while(path != NULL) + { + sprintf(chpath, "%s\\sh.exe", path); + if(_access(chpath, 0) != -1) + return true; + + path = strtok(NULL, seps); + } + + return false; +} diff --git a/util/scripts/win-binary/nsis/qtnsisext/mingw.h b/util/scripts/win-binary/nsis/qtnsisext/mingw.h new file mode 100644 index 0000000..e975a9e --- /dev/null +++ b/util/scripts/win-binary/nsis/qtnsisext/mingw.h @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the utils of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#define MINGW_BUFFER_SIZE 1024 + +void getMinGWVersion(char *path, int *major, int *minor, int *patch); +bool hasValidIncludeFiles(char *path); +bool shInEnvironment();
\ No newline at end of file diff --git a/util/scripts/win-binary/nsis/qtnsisext/qtlibspatcher.exe b/util/scripts/win-binary/nsis/qtnsisext/qtlibspatcher.exe Binary files differnew file mode 100755 index 0000000..b9ec6d2 --- /dev/null +++ b/util/scripts/win-binary/nsis/qtnsisext/qtlibspatcher.exe diff --git a/util/scripts/win-binary/nsis/qtnsisext/qtlibspatcher.vcproj b/util/scripts/win-binary/nsis/qtnsisext/qtlibspatcher.vcproj new file mode 100644 index 0000000..aeed5ec --- /dev/null +++ b/util/scripts/win-binary/nsis/qtnsisext/qtlibspatcher.vcproj @@ -0,0 +1,206 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8,00" + Name="qtlibspatcher" + ProjectGUID="{DC56C66A-5D15-46C8-91E6-AB36FC26F8DA}" + RootNamespace="qtlibspatcher" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="1" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="$(SolutionDir)$(ConfigurationName)" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="1" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="3" + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE" + RuntimeLibrary="0" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="1" + GenerateDebugInformation="false" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath=".\binpatch.cpp" + > + </File> + <File + RelativePath=".\qtlibspatchermain.cpp" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + <File + RelativePath=".\binpatch.h" + > + </File> + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" + > + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/util/scripts/win-binary/nsis/qtnsisext/qtlibspatchermain.cpp b/util/scripts/win-binary/nsis/qtnsisext/qtlibspatchermain.cpp new file mode 100644 index 0000000..008cc46 --- /dev/null +++ b/util/scripts/win-binary/nsis/qtnsisext/qtlibspatchermain.cpp @@ -0,0 +1,200 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the utils of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "binpatch.h" +#include <stdio.h> + +bool patchBinaryWithQtPathes(const char *fileName, const char *baseQtPath) +{ + bool result = true; + + static const struct + { + const char *variable; + const char *subDirectory; + } variables[] = { + {"qt_prfxpath=", ""}, + {"qt_docspath=", "/doc"}, + {"qt_hdrspath=", "/include"}, + {"qt_libspath=", "/lib"}, + {"qt_binspath=", "/bin"}, + {"qt_plugpath=", "/plugins"}, + {"qt_datapath=", ""}, + {"qt_trnspath=", "/translations"}, + {"qt_xmplpath=", "/examples"}, + {"qt_demopath=", "/demos"} + }; + + for (int i = 0; i < sizeof(variables)/sizeof(variables[0]); i++) { + char newStr[256] = ""; + strncpy(newStr, variables[i].variable, sizeof(newStr)); + newStr[sizeof(newStr) - 1] = 0; + strncat(newStr, baseQtPath, sizeof(newStr) - strlen(newStr) - 1); + newStr[sizeof(newStr) - 1] = 0; + strncat(newStr, variables[i].subDirectory, sizeof(newStr) - strlen(newStr) - 1); + newStr[sizeof(newStr) - 1] = 0; + BinPatch binFile(fileName); + if (!binFile.patch(variables[i].variable, newStr)) { + result = false; + break; + } + } + + return result; +} + +bool patchBinariesWithQtPathes(const char *baseQtPath) +{ + bool result = true; + + static const char *filesToPatch[] = { + "/bin/qmake.exe", + "/bin/QtCore4.dll", + "/bin/QtCored4.dll" + }; + + for (int i = 0; i < sizeof(filesToPatch)/sizeof(filesToPatch[0]); i++) { + char fileName[FILENAME_MAX] = ""; + strncpy(fileName, baseQtPath, sizeof(fileName)); + fileName[sizeof(fileName)-1] = '\0'; + strncat(fileName, filesToPatch[i], sizeof(fileName) - strlen(fileName) - 1); + fileName[sizeof(fileName)-1] = '\0'; + if (!patchBinaryWithQtPathes(fileName, baseQtPath)) { + result = false; + break; + } + } + + return result; +} + +bool patchDebugLibrariesWithQtPath(const char *baseQtPath) +{ + bool result = true; + + static const struct + { + const char *fileName; + const char *sourceLocation; + } libraries[] = { + {"/bin/Qt3Supportd4.dll", "/src/qt3support/"}, + {"/bin/QtCored4.dll", "/src/corelib/"}, + {"/bin/QtGuid4.dll", "/src/gui/"}, + {"/bin/QtHelpd4.dll", "/tools/assistant/lib/"}, + {"/bin/QtNetworkd4.dll", "/src/network/"}, + {"/bin/QtOpenGLd4.dll", "/src/opengl/"}, + {"/bin/QtScriptd4.dll", "/src/script/"}, + {"/bin/QtSqld4.dll", "/src/sql/"}, + {"/bin/QtSvgd4.dll", "/src/svg/"}, + {"/bin/QtTestd4.dll", "/src/testlib/"}, + {"/bin/QtWebKitd4.dll", "/src/3rdparty/webkit/WebCore/"}, + {"/bin/QtXmld4.dll", "/src/xml/"}, + {"/bin/QtXmlPatternsd4.dll", "/src/xmlpatterns/"}, + {"/plugins/accessible/qtaccessiblecompatwidgetsd4.dll", "/src/plugins/accessible/compat/"}, + {"/plugins/accessible/qtaccessiblewidgetsd4.dll", "/src/plugins/accessible/widgets/"}, + {"/plugins/codecs/qcncodecsd4.dll", "/src/plugins/codecs/cn/"}, + {"/plugins/codecs/qjpcodecsd4.dll", "/src/plugins/codecs/jp/"}, + {"/plugins/codecs/qkrcodecsd4.dll", "/src/plugins/codecs/kr/"}, + {"/plugins/codecs/qtwcodecsd4.dll", "/src/plugins/codecs/tw/"}, + {"/plugins/iconengines/qsvgicond4.dll", "/src/plugins/iconengines/svgiconengine/"}, + {"/plugins/imageformats/qgifd4.dll", "/src/plugins/imageformats/gif/"}, + {"/plugins/imageformats/qjpegd4.dll", "/src/plugins/imageformats/jpeg/"}, + {"/plugins/imageformats/qmngd4.dll", "/src/plugins/imageformats/mng/"}, + {"/plugins/imageformats/qsvgd4.dll", "/src/plugins/imageformats/svg/"}, + {"/plugins/imageformats/qtiffd4.dll", "/src/plugins/imageformats/tiff/"}, + {"/plugins/sqldrivers/qsqlited4.dll", "/src/plugins/sqldrivers/sqlite/"}, +// {"/plugins/sqldrivers/qsqlodbcd4.dll", "/src/plugins/sqldrivers/odbc/"} + }; + + for (int i = 0; i < sizeof(libraries)/sizeof(libraries[0]); i++) { + char fileName[FILENAME_MAX] = ""; + strncpy(fileName, baseQtPath, sizeof(fileName)); + fileName[sizeof(fileName)-1] = '\0'; + strncat(fileName, libraries[i].fileName, sizeof(fileName) - strlen(fileName) - 1); + fileName[sizeof(fileName)-1] = '\0'; + + char oldSourcePath[FILENAME_MAX] = + "C:/depot/qt-workbench/Trolltech/Code_less_create_more/Trolltech/Code_less_create_more/Trolltech"; + strncat(oldSourcePath, libraries[i].sourceLocation, sizeof(oldSourcePath) - strlen(oldSourcePath) - 1); + oldSourcePath[sizeof(oldSourcePath)-1] = '\0'; + + char newSourcePath[FILENAME_MAX] = ""; + strncpy(newSourcePath, baseQtPath, sizeof(newSourcePath)); + newSourcePath[sizeof(newSourcePath)-1] = '\0'; + strncat(newSourcePath, libraries[i].sourceLocation, sizeof(newSourcePath) - strlen(newSourcePath) - 1); + newSourcePath[sizeof(newSourcePath)-1] = '\0'; + + BinPatch binFile(fileName); + if (!binFile.patch(oldSourcePath, newSourcePath)) { + result = false; + break; + } + } + + return result; +} + +int main(int argc, char *args[]) +{ + if (argc != 2) { + printf("Please provide a QTDIR value as parameter.\n" + "This is also the location where the binaries are expected\n" + "in the \"/bin\" and \"/plugins\" subdirectories.\n"); + return 1; + } + + char baseQtPath[FILENAME_MAX] = ""; + strncpy(baseQtPath, args[1], sizeof(baseQtPath)); + baseQtPath[sizeof(baseQtPath)-1] = '\0'; + + // Convert backslash to slash + for (char *p = baseQtPath; *p != '\0'; p++) + if (*p == '\\') + *p = '/'; + + // Remove trailing slash(es) + for (char *p = baseQtPath + strlen(baseQtPath) - 1; p != baseQtPath; p--) + if (*p == '/') + *p = '\0'; + else + break; + + return patchBinariesWithQtPathes(baseQtPath) && patchDebugLibrariesWithQtPath(baseQtPath)?0:1; +} diff --git a/util/scripts/win-binary/nsis/qtnsisext/qtnsisext.cpp b/util/scripts/win-binary/nsis/qtnsisext/qtnsisext.cpp new file mode 100644 index 0000000..c9deb73 --- /dev/null +++ b/util/scripts/win-binary/nsis/qtnsisext/qtnsisext.cpp @@ -0,0 +1,495 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the utils of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <windows.h> +#include "exdll.h" +#include "keydec.h" +#include "licensefinder.h" +#include "binpatch.h" +#include "mingw.h" +#include <stdio.h> +#include <time.h> + +HINSTANCE g_hInstance; +HWND g_hwndParent; + +#define EXPORT_NSIS_FUNCTION(funcName) \ +extern "C" void __declspec(dllexport) funcName(HWND hwndParent, int string_size, \ + char *variables, stack_t **stacktop) + +BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) +{ + g_hInstance=static_cast<HINSTANCE>(hInst); + return TRUE; +} + +EXPORT_NSIS_FUNCTION(IsValidLicense) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + char isValid[2]; + char *key = (char *)LocalAlloc(LPTR, g_stringsize+1); + popstring(key); + + KeyDecoder kdec(key); + if (kdec.IsValid() && ( + kdec.getPlatforms() & KeyDecoder::Windows + || kdec.getPlatforms() & KeyDecoder::Embedded + || kdec.getPlatforms() & KeyDecoder::WinCE)) + strcpy(isValid, "1"); + else + strcpy(isValid, "0"); + + LocalFree(key); + pushstring(isValid); +} + +EXPORT_NSIS_FUNCTION(IsValidWinCELicense) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + char isValid[2]; + char *key = (char *)LocalAlloc(LPTR, g_stringsize+1); + popstring(key); + + KeyDecoder kdec(key); + if (kdec.IsValid() && (kdec.getPlatforms() & KeyDecoder::WinCE)) + strcpy(isValid, "1"); + else + strcpy(isValid, "0"); + + LocalFree(key); + pushstring(isValid); +} + +EXPORT_NSIS_FUNCTION(HasLicenseProduct) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + char retVal[2]; + char *key = (char *)LocalAlloc(LPTR, g_stringsize+1); + char *product = (char *)LocalAlloc(LPTR, g_stringsize+1); + uint qtproduct = 0; + + popstring(key); + popstring(product); + + for (int i=0; i<KeyDecoder::NumberOfProducts; ++i) { + if (KeyDecoder::Products[i] != 0 && stricmp(product, KeyDecoder::Products[i]) == 0) { + qtproduct = (1 << i); + break; + } + } + + KeyDecoder kdec(key); + if (kdec.IsValid() + && (qtproduct != 0) + && (kdec.getProducts() & qtproduct)) { + strcpy(retVal, "1"); + } else { + strcpy(retVal, "0"); + } + + LocalFree(product); + LocalFree(key); + pushstring(retVal); +} + +EXPORT_NSIS_FUNCTION(GetLicenseID) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + char *key = (char *)LocalAlloc(LPTR, g_stringsize+1); + popstring(key); + + char lcnsid[512]; + lcnsid[0] = '\0'; + + KeyDecoder kdec(key); + if (kdec.IsValid()) { + uint qtlcnsid = kdec.getLicenseID(); + sprintf(lcnsid, "%d", qtlcnsid); + } + + LocalFree(key); + pushstring(lcnsid); +} + +EXPORT_NSIS_FUNCTION(GetLicenseProduct) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + char *key = (char *)LocalAlloc(LPTR, g_stringsize+1); + popstring(key); + + char lcnsprod[512]; + lcnsprod[0] = '\0'; + + KeyDecoder kdec(key); + if (kdec.IsValid()) { + uint qtschema = kdec.getLicenseSchema(); + if(qtschema & KeyDecoder::SupportedEvaluation) + strcpy(lcnsprod, "SupportedEvaluation"); + else if(qtschema & KeyDecoder::UnsupportedEvaluation) + strcpy(lcnsprod, "UnsupportedEvaluation"); + else if(qtschema & KeyDecoder::FullSourceEvaluation) + strcpy(lcnsprod, "FullSourceEvaluation"); + else if(qtschema & KeyDecoder::Academic) + strcpy(lcnsprod, "Academic"); + else if(qtschema & KeyDecoder::Educational) + strcpy(lcnsprod, "Educational"); + else if(qtschema & KeyDecoder::FullCommercial) + { + uint qtproduct = kdec.getProducts(); + if (qtproduct & KeyDecoder::QtUniversal) + strcpy(lcnsprod, "Universal"); + else if(qtproduct & KeyDecoder::QtDesktop) + strcpy(lcnsprod, "Desktop"); + else if(qtproduct & KeyDecoder::QtDesktopLight) + strcpy(lcnsprod, "DesktopLight"); + else if(qtproduct & KeyDecoder::QtConsole) + strcpy(lcnsprod, "Console"); + } + } + + LocalFree(key); + pushstring(lcnsprod); +} + +EXPORT_NSIS_FUNCTION(GetLicensePlatform) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + char *key = (char *)LocalAlloc(LPTR, g_stringsize+1); + popstring(key); + + char lcnsplat[512]; + lcnsplat[0] = '\0'; + + KeyDecoder kdec(key); + if (kdec.getPlatforms() == KeyDecoder::AllOS) + strcpy(lcnsplat, "AllOS"); + else if (kdec.getPlatforms() & KeyDecoder::Embedded) + strcpy(lcnsplat, "Embedded"); + else if (kdec.getPlatforms() & KeyDecoder::WinCE) + strcpy(lcnsplat, "Embedded"); + else if (kdec.getPlatforms() & KeyDecoder::Windows) + strcpy(lcnsplat, "Windows"); + + LocalFree(key); + pushstring(lcnsplat); +} + +EXPORT_NSIS_FUNCTION(UsesUSLicense) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + char isUSCustomer[2]; + char *key = (char *)LocalAlloc(LPTR, g_stringsize+1); + popstring(key); + + KeyDecoder kdec(key); + if (kdec.IsValid() + && (kdec.getLicenseFeatures() & KeyDecoder::USCustomer)) + strcpy(isUSCustomer, "1"); + else + strcpy(isUSCustomer, "0"); + + LocalFree(key); + pushstring(isUSCustomer); +} + +EXPORT_NSIS_FUNCTION(IsValidDate) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + int year = 0; + int month = 0; + int day = 0; + char isValid[2]; + char *key = (char *)LocalAlloc(LPTR, g_stringsize+1); + char *pkgDate = (char *)LocalAlloc(LPTR, g_stringsize+1); + + popstring(key); + popstring(pkgDate); + + if (strlen(pkgDate) > 0) + { + sscanf(pkgDate, "%d-%d-%d", &year, &month, &day); + } else { + //use current date + char curDate[9]; + _strdate(curDate); + sscanf(curDate, "%d/%d/%d", &month, &day, &year); + year += 2000; + } + + KeyDecoder kdec(key); + CDate expiryDate = kdec.getExpiryDate(); + if (year == expiryDate.year()) { + if (month == expiryDate.month()) { + if (day <= expiryDate.day()) { + strcpy(isValid, "1"); + } else { + strcpy(isValid, "0"); + } + } else if (month < expiryDate.month()) { + strcpy(isValid, "1"); + } else { + strcpy(isValid, "0"); + } + } else if (year < expiryDate.year()) { + strcpy(isValid, "1"); + } else { + strcpy(isValid, "0"); + } + + LocalFree(pkgDate); + LocalFree(key); + pushstring(isValid); +} + +EXPORT_NSIS_FUNCTION(IsFloatingLicense) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + char *key = (char *)LocalAlloc(LPTR, g_stringsize+1); + popstring(key); + char isFloatingLicense[2]; + + KeyDecoder kdec(key); + if (kdec.IsValid() && + kdec.getLicenseFeatures() & KeyDecoder::FloatingLicense) + strcpy(isFloatingLicense, "1"); + else + strcpy(isFloatingLicense, "0"); + + LocalFree(key); + pushstring(isFloatingLicense); +} + +EXPORT_NSIS_FUNCTION(GetLicenseInfo) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + LicenseFinder f; + pushstring(f.getLicenseKey()); + pushstring(f.getOldLicenseKey()); + pushstring(f.getLicensee()); + pushstring(f.getCustomerID()); + pushstring(f.getProducts()); + pushstring(f.getExpiryDate()); +} + +EXPORT_NSIS_FUNCTION(PatchVC6Binary) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + char *fileName = (char *)LocalAlloc(LPTR, g_stringsize+1); + char *oldStr = (char *)LocalAlloc(LPTR, g_stringsize+1); + char *newStr = (char *)LocalAlloc(LPTR, g_stringsize+1); + + popstring(fileName); + popstring(oldStr); + popstring(newStr); + + // remove last separator... + int oldLen = (int)strlen(oldStr); + int newLen = (int)strlen(newStr); + if (oldStr[oldLen-1] == '\\') + oldStr[oldLen-1] = '\0'; + if (newStr[newLen-1] == '\\') + newStr[newLen-1] = '\0'; + + BinPatch binFile(fileName); + binFile.enableInsertReplace(true); + binFile.enableUseLength(true); + binFile.setEndTokens(".cpp;.h;.moc;.pdb"); + binFile.patch(oldStr, newStr); + + //patch also with path sep. the other way since + //vc60 in some cases uses different path separators :| + char *reverse = (char *)malloc(sizeof(char)*(oldLen+1)); + for (int i=0; i<oldLen; ++i) { + if (oldStr[i] == '\\') + reverse[i] = '/'; + else + reverse[i] = oldStr[i]; + } + reverse[oldLen] = '\0'; + binFile.patch(reverse, newStr); + + LocalFree(newStr); + LocalFree(oldStr); + LocalFree(fileName); +} + +EXPORT_NSIS_FUNCTION(PatchVC7Binary) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + char *fileName = (char *)LocalAlloc(LPTR, g_stringsize+1); + char *oldStr = (char *)LocalAlloc(LPTR, g_stringsize+1); + char *newStr = (char *)LocalAlloc(LPTR, g_stringsize+1); + + popstring(fileName); + popstring(oldStr); + popstring(newStr); + + BinPatch binFile(fileName); + binFile.enableInsertReplace(true); + binFile.setEndTokens(".cpp;.h;.moc;.pdb"); + binFile.patch(oldStr, newStr); + + LocalFree(newStr); + LocalFree(oldStr); + LocalFree(fileName); +} + +EXPORT_NSIS_FUNCTION(PatchBinary) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + char *fileName = (char *)LocalAlloc(LPTR, g_stringsize+1); + char *oldStr = (char *)LocalAlloc(LPTR, g_stringsize+1); + char *newStr = (char *)LocalAlloc(LPTR, g_stringsize+1); + + popstring(fileName); + popstring(oldStr); + popstring(newStr); + + BinPatch binFile(fileName); + binFile.patch(oldStr, newStr); + + LocalFree(newStr); + LocalFree(oldStr); + LocalFree(fileName); +} + +EXPORT_NSIS_FUNCTION(ShowLicenseFile) +{ + char licenseBuffer[60000]; + g_hwndParent = hwndParent; + EXDLL_INIT(); + + void *hCtrl = 0; + char *strCtrl = (char *)LocalAlloc(LPTR, g_stringsize+1); + char *strLicenseFile = (char *)LocalAlloc(LPTR, g_stringsize+1); + popstring(strCtrl); + popstring(strLicenseFile); + + if (sscanf(strCtrl, "%d", &hCtrl) == 1) { + FILE *fIn = fopen(strLicenseFile, "rb"); + if (fIn) { + size_t r = fread(licenseBuffer, sizeof(char), 59999, fIn); + licenseBuffer[r] = '\0'; + fclose(fIn); + SendMessage((HWND)hCtrl, (UINT)WM_SETTEXT, 0, (LPARAM)licenseBuffer); + } + } + + LocalFree(strLicenseFile); + LocalFree(strCtrl); +} + +EXPORT_NSIS_FUNCTION(HasValidWin32Library) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + char isValid[2]; + char *path = (char *)LocalAlloc(LPTR, g_stringsize+1); + popstring(path); + + if (hasValidIncludeFiles(path)) + strcpy(isValid, "1"); + else + strcpy(isValid, "0"); + + LocalFree(path); + pushstring(isValid); +} + +EXPORT_NSIS_FUNCTION(GetMinGWVersion) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + + char *path = (char *)LocalAlloc(LPTR, g_stringsize+1); + popstring(path); + + int major = 0, minor = 0, patch = 0; + char versionstr[MINGW_BUFFER_SIZE]; + + getMinGWVersion(path, &major, &minor, &patch); + sprintf(versionstr, "%d.%d.%d", major, minor, patch); + + LocalFree(path); + pushstring(versionstr); +} + +EXPORT_NSIS_FUNCTION(ShInPath) +{ + g_hwndParent = hwndParent; + EXDLL_INIT(); + char res[2]; + + if (shInEnvironment()) + res[0] = '1'; + else + res[0] = '0'; + + res[1] = '\0'; + + pushstring(res); +} diff --git a/util/scripts/win-binary/nsis/qtnsisext/qtnsisext.dll b/util/scripts/win-binary/nsis/qtnsisext/qtnsisext.dll Binary files differnew file mode 100644 index 0000000..a75d896 --- /dev/null +++ b/util/scripts/win-binary/nsis/qtnsisext/qtnsisext.dll diff --git a/util/scripts/win-binary/nsis/qtnsisext/qtnsisext.vcproj b/util/scripts/win-binary/nsis/qtnsisext/qtnsisext.vcproj new file mode 100644 index 0000000..3600136 --- /dev/null +++ b/util/scripts/win-binary/nsis/qtnsisext/qtnsisext.vcproj @@ -0,0 +1,164 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="7.10" + Name="qtnsisext" + ProjectGUID="{DC56C66A-5D15-46C8-91E6-AB36FC26F8DA}" + Keyword="Win32Proj"> + <Platforms> + <Platform + Name="Win32"/> + </Platforms> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="." + IntermediateDirectory="Debug" + ConfigurationType="2" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;QTNSISEXT_EXPORTS" + MinimalRebuild="TRUE" + BasicRuntimeChecks="3" + RuntimeLibrary="1" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="4"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLinkerTool" + OutputFile="$(OutDir)/qtnsisext.dll" + LinkIncremental="2" + GenerateDebugInformation="TRUE" + ProgramDatabaseFile="$(OutDir)/qtnsisext.pdb" + SubSystem="1" + ImportLibrary="$(OutDir)/qtnsisext.lib" + TargetMachine="1"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCWebDeploymentTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="." + IntermediateDirectory="Release" + ConfigurationType="2" + CharacterSet="2"> + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="..\..\..\..\..\..\qt\util\scripts\mac-binary\package\InstallerPane" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;QTNSISEXT_EXPORTS" + RuntimeLibrary="0" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="TRUE" + DebugInformationFormat="3" + CallingConvention="0" + CompileAs="2"/> + <Tool + Name="VCCustomBuildTool"/> + <Tool + Name="VCLinkerTool" + OutputFile="$(OutDir)/qtnsisext.dll" + LinkIncremental="1" + GenerateDebugInformation="FALSE" + SubSystem="1" + OptimizeReferences="2" + EnableCOMDATFolding="2" + ImportLibrary="$(OutDir)/qtnsisext.lib" + TargetMachine="1"/> + <Tool + Name="VCMIDLTool"/> + <Tool + Name="VCPostBuildEventTool"/> + <Tool + Name="VCPreBuildEventTool"/> + <Tool + Name="VCPreLinkEventTool"/> + <Tool + Name="VCResourceCompilerTool"/> + <Tool + Name="VCWebServiceProxyGeneratorTool"/> + <Tool + Name="VCXMLDataGeneratorTool"/> + <Tool + Name="VCWebDeploymentTool"/> + <Tool + Name="VCManagedWrapperGeneratorTool"/> + <Tool + Name="VCAuxiliaryManagedWrapperGeneratorTool"/> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> + <File + RelativePath=".\binpatch.cpp"> + </File> + <File + RelativePath="..\..\..\..\..\..\qt\util\scripts\mac-binary\package\InstallerPane\keydec.cpp"> + </File> + <File + RelativePath=".\licensefinder.cpp"> + </File> + <File + RelativePath=".\mingw.cpp"> + </File> + <File + RelativePath=".\qtnsisext.cpp"> + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> + <File + RelativePath=".\binpatch.h"> + </File> + <File + RelativePath=".\exdll.h"> + </File> + <File + RelativePath="..\..\..\..\..\..\qt\util\scripts\mac-binary\package\InstallerPane\keydec.h"> + </File> + <File + RelativePath=".\licensefinder.h"> + </File> + <File + RelativePath=".\mingw.h"> + </File> + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> |