diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89c3854 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.o +/src/bncsutil/libbncsutil.so diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index e785bfd..0000000 --- a/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -SUBDIRS = src/ diff --git a/README.md b/README.md index 882bcbe..ff6f1ce 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,58 @@ # BNCSUtil ## Preface **BNCSUtil** is the **B**attle.**N**et **C**hat **S**ervice **Util**ity which -aids applications trying to logon to Battle.net™ v1 using the binary +aids applications trying to logon to Classic Battle.net™ using the binary protocol. Specifically, BNCSUtil has functions that help with the cryptography of game versions, keys, and passwords. ## Installing -Simply place the .so or .dll file in the same directory as the application that -wishes to use it. If this does not work, install the file into the system +Simply place the `.so` or `.dll` file in the same directory as the application +that wishes to use it. If this does not work, install the file into the system library directory. -On Windows, this directory is: +### Windows +Copy the file to: + ``` C:\Windows\System32 ``` -On Linux, this directory is: +### Linux +If you just have the `.so` file, copy it to: + ``` /usr/lib/ ``` +And run: + +``` +sudo ldconfig +``` + +If you have just compiled from source, run this instead: + +``` +sudo make install +``` + ## Building ### Windows The official build of BNCSUtil for Windows is produced using Visual Studio 2005 -using the solution file in the `vc8_build` folder. The `vc7_build` is no longer -officially used or supported. +using the solution file in the `vc8_build` folder. BNCSUtil requires GMP. ### Linux To build: ``` -./configure +cd src/bncsutil +make clean make -make install ``` -If you have a fresh checkout or are having build-related issues, run the -following to (re)generate the configure script: -``` -autoreconf -if -``` +If you are having build related issues, ensure that: -Note that to use `autoreconf` you will need to have GNU `autotools` installed. +- You have the `gcc` package installed. +- You have the `glibc` development package installed. +- You have the `gmp` development package installed. diff --git a/configure.ac b/configure.ac deleted file mode 100644 index eee56f2..0000000 --- a/configure.ac +++ /dev/null @@ -1,43 +0,0 @@ -AC_INIT([bncsutil], [1.3.2], [bugs@example.com]) - -AM_INIT_AUTOMAKE([-Wall -Werror foreign]) -AM_PROG_LIBTOOL - -AC_PROG_INSTALL - -AC_LANG_C -AC_PROG_CC -AC_PROG_CXX -AC_PROG_INSTALL -AC_PROG_MAKE_SET - -AC_HEADER_STDC - -AC_CHECK_LIB(gmp, __gmpz_init,, AC_MSG_ERROR([ -bncsutil requires libgmp; see http://gmplib.org])) - -[echo -n "checking for little or big endian... " ] -AC_TRY_RUN([ -#include -int main() -{ - uint16_t s = 1; - uint16_t* ptr = &s; - uint8_t n = *((uint8_t*)ptr); - return n; -} - -] -, AC_DEFINE([BIGENDIAN], [1], [Define to 1 if system is big endian]) - [echo "big"] -, AC_DEFINE([LITTLEENDIAN], [1], [Define to 1 if system is little endian]) - [echo "little"] -) - -AC_CONFIG_HEADERS([config.h]) -AC_CONFIG_FILES([ - Makefile - src/Makefile -]) - -AC_OUTPUT diff --git a/product_version b/product_version index 3a3cd8c..1892b92 100644 --- a/product_version +++ b/product_version @@ -1 +1 @@ -1.3.1 +1.3.2 diff --git a/source_dist.sh b/source_dist.sh deleted file mode 100644 index 4ad32a8..0000000 --- a/source_dist.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh - -SCRIPT_PATH=`dirname $0`; - -PKGDIR=bncsutil-`cat $SCRIPT_PATH/product_version` -rm -fr $PKGDIR -mkdir $PKGDIR - -for b in config configure doc product_version src support tests vb6_example \ - vc7_build vc8_build windows_dist.bat source_dist.sh windows_dist.sh \ - README-Windows.txt -do - cp -R $SCRIPT_PATH/$b $PKGDIR -done - -rm -f $PKGDIR.tar.bz2 -rm -f $PKGDIR.tar.gz - -tar --exclude=.svn -cjvf $PKGDIR.tar.bz2 $PKGDIR -tar --exclude=.svn -czvf $PKGDIR.tar.gz $PKGDIR - -rm -fr $PKGDIR - -scp $PKGDIR.tar.bz2 $PKGDIR.tar.gz "ionws.com:/home/ericn/public_html/code/bncsutil/static/releases" diff --git a/src/Makefile.am b/src/Makefile.am deleted file mode 100644 index ca1181f..0000000 --- a/src/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -AUTOMAKE_OPTIONS = gnu -AM_CPPFLAGS = -I@ROOTINCDIR@ -lib_LTLIBRARIES = libbncsutil.la -nobase_include_HEADERS = bncsutil/bncsutil.h \ - bncsutil/cdkeydecoder.h \ - bncsutil/decodekey.h \ - bncsutil/libinfo.h \ - bncsutil/nls.h \ - bncsutil/sha1.h \ - bncsutil/bsha1.h \ - bncsutil/checkrevision.h \ - bncsutil/file.h \ - bncsutil/mutil.h \ - bncsutil/oldauth.h \ - bncsutil/stack.h \ - bncsutil/buffer.h \ - bncsutil/debug.h \ - bncsutil/keytables.h \ - bncsutil/mutil_types.h \ - bncsutil/pe.h - -libbncsutil_la_SOURCES = bncsutil/nls.c \ - bncsutil/pe.c \ - bncsutil/sha1.c \ - bncsutil/stack.c \ - bncsutil/bsha1.cpp \ - bncsutil/checkrevision.cpp \ - bncsutil/file.cpp \ - bncsutil/oldauth.cpp \ - bncsutil/cdkeydecoder.cpp \ - bncsutil/decodekey.cpp \ - bncsutil/libinfo.cpp - -libbncsutil_la_LDFLAGS = -version-info 0:0:0 diff --git a/src/bncsutil/Makefile b/src/bncsutil/Makefile new file mode 100644 index 0000000..7cabdd7 --- /dev/null +++ b/src/bncsutil/Makefile @@ -0,0 +1,37 @@ +SHELL = /bin/sh +SYSTEM = $(shell uname) +CXX = g++ +CXXFLAGS = -Wall -O3 -I ../ -Wno-multichar -fPIC +CXXOBJ = bsha1.o cdkeydecoder.o checkrevision.o decodekey.o file.o libinfo.o oldauth.o +CC = gcc +CCFLAGS = -Wall -O3 -I ../ -Wno-multichar -fPIC +CCOBJ = nls.o pe.o sha1.o stack.o + +ifeq ($(SYSTEM),Darwin) +LDFLAGS = -dynamiclib -lgmp -L/opt/local/lib +TARGET = libbncsutil.dylib +else +LDFLAGS = -shared -lgmp +TARGET = libbncsutil.so +endif + +$(TARGET): $(CXXOBJ) $(CCOBJ) + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(CXXOBJ) $(CCOBJ) -o $(TARGET) + +$(CXXOBJ): %.o: %.cpp + $(CXX) $(CXXFLAGS) -c $< -o $@ + +$(CCOBJ): %.o: %.c + $(CC) $(CCFLAGS) -c $< -o $@ + +clean: + rm -f $(CCOBJ) $(CXXOBJ) $(TARGET) *~ + +all: + make $(TARGET) + +install: $(TARGET) + mkdir -p /usr/include/bncsutil + cp *.h /usr/include/bncsutil + cp $(TARGET) /usr/lib + ldconfig diff --git a/src/bncsutil/bsha1.cpp b/src/bncsutil/bsha1.cpp index 6e5aa6b..3074255 100644 --- a/src/bncsutil/bsha1.cpp +++ b/src/bncsutil/bsha1.cpp @@ -27,7 +27,7 @@ #include #include -#define USE_NEW_BSHA1 0 +#define USE_NEW_BSHA1 0 #define BSHA_IC1 0x67452301lu #define BSHA_IC2 0xEFCDAB89lu @@ -41,10 +41,10 @@ #define BSHA_OC4 0x359D3E2Alu #if !USE_NEW_BSHA1 -# define BSHA_COP e = d; d = c; c = ROL(b, 30); b = a; a = g; +# define BSHA_COP e = d; d = c; c = ROL(b, 30); b = a; a = g; #else -# define BSHA_N_COP t[4] = t[3]; t[3] = t[2]; t[2] = ROL(t[1], 30); \ - t[1] = t[0]; t[0] = x +# define BSHA_N_COP t[4] = t[3]; t[3] = t[2]; t[2] = ROL(t[1], 30); \ + t[1] = t[0]; t[0] = x #endif #if !USE_NEW_BSHA1 @@ -60,108 +60,108 @@ #else #define BSHA_N_OP1() x = LSB4(*p++) + ROL(t[0], 5) + t[4] + \ - ((t[1] & t[2]) | (~t[1] & t[3])) + BSHA_OC1; BSHA_N_COP + ((t[1] & t[2]) | (~t[1] & t[3])) + BSHA_OC1; BSHA_N_COP #define BSHA_N_OP2() x = (t[3] ^ t[2] ^ t[1]) + t[4] + ROL(x, 5) + \ - LSB4(*p++) + BSHA_OC2; BSHA_N_COP + LSB4(*p++) + BSHA_OC2; BSHA_N_COP #define BSHA_N_OP3() x = LSB4(*p++) + ROL(x, 5) + t[4] + \ - ((t[2] & t[1]) | (t[3] & t[2]) | (t[3] & t[1])) - BSHA_OC3; BSHA_N_COP + ((t[2] & t[1]) | (t[3] & t[2]) | (t[3] & t[1])) - BSHA_OC3; BSHA_N_COP #define BSHA_N_OP4() x = (t[3] ^ t[2] ^ t[1]) + t[4] + ROL(x, 5) + \ - LSB4(*p++) - BSHA_OC4; BSHA_N_COP + LSB4(*p++) - BSHA_OC4; BSHA_N_COP #endif #if USE_NEW_BSHA1 MEXP(void) calcHashBuf(const char* input, unsigned int length, char* result) { - uint32_t vals[5]; - uint32_t t[5]; // a, b, c, d, e - uint32_t buf[0x50]; - uint32_t* p; - uint32_t x; - const char* in = input; - unsigned int i, j; - unsigned int sub_length; - - /* Initializer Values */ - p = vals; - *p++ = BSHA_IC1; - *p++ = BSHA_IC2; - *p++ = BSHA_IC3; - *p++ = BSHA_IC4; - *p++ = BSHA_IC5; - - memset(buf, 0, 320); // zero buf - - /* Process input in chunks. */ - for (i = 0; i < length; i += 0x40) { - sub_length = length - i; - - /* Maximum chunk size is 0x40 (64) bytes. */ - if (sub_length > 0x40) - sub_length = 0x40; - - memcpy(buf, in, sub_length); - in += sub_length; - - /* If necessary, pad with zeroes to 64 bytes. */ - if (sub_length < 0x40) - memset(buf + sub_length, 0, 0x40 - sub_length); - - for (j = 0; j < 64; j++) { - buf[j + 16] = - LSB4(ROL(1, LSB4(buf[j] ^ buf[j+8] ^ buf[j+2] ^ buf[j+13]) % 32)); - } - - memcpy(t, vals, 20); - p = buf; - - /* It's a kind of magic. */ - BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); - BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); - - BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); - BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); - - BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); - BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); - - BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); - BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); - - vals[0] += t[0]; - vals[1] += t[1]; - vals[2] += t[2]; - vals[3] += t[3]; - vals[4] += t[4]; - } - - /* Return result. */ - memcpy(result, vals, 20); + uint32_t vals[5]; + uint32_t t[5]; // a, b, c, d, e + uint32_t buf[0x50]; + uint32_t* p; + uint32_t x; + const char* in = input; + unsigned int i, j; + unsigned int sub_length; + + /* Initializer Values */ + p = vals; + *p++ = BSHA_IC1; + *p++ = BSHA_IC2; + *p++ = BSHA_IC3; + *p++ = BSHA_IC4; + *p++ = BSHA_IC5; + + memset(buf, 0, 320); // zero buf + + /* Process input in chunks. */ + for (i = 0; i < length; i += 0x40) { + sub_length = length - i; + + /* Maximum chunk size is 0x40 (64) bytes. */ + if (sub_length > 0x40) + sub_length = 0x40; + + memcpy(buf, in, sub_length); + in += sub_length; + + /* If necessary, pad with zeroes to 64 bytes. */ + if (sub_length < 0x40) + memset(buf + sub_length, 0, 0x40 - sub_length); + + for (j = 0; j < 64; j++) { + buf[j + 16] = + LSB4(ROL(1, LSB4(buf[j] ^ buf[j+8] ^ buf[j+2] ^ buf[j+13]) % 32)); + } + + memcpy(t, vals, 20); + p = buf; + + /* It's a kind of magic. */ + BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); + BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); BSHA_N_OP1(); + + BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); + BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); BSHA_N_OP2(); + + BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); + BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); BSHA_N_OP3(); + + BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); + BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); BSHA_N_OP4(); + + vals[0] += t[0]; + vals[1] += t[1]; + vals[2] += t[2]; + vals[3] += t[3]; + vals[4] += t[4]; + } + + /* Return result. */ + memcpy(result, vals, 20); } #else MEXP(void) calcHashBuf(const char* input, size_t length, char* result) { int i; - unsigned long a, b, c, d, e, g; - uint32_t* ldata; + uint32_t a, b, c, d, e, g; + uint32_t* ldata; char data[1024]; memset(data, 0, 1024); memcpy(data, input, length); ldata = (uint32_t*) data; - + for (i = 0; i < 64; i++) { ldata[i + 16] = LSB4(ROL(1, LSB4(ldata[i] ^ ldata[i+8] ^ ldata[i+2] ^ ldata[i+13]) % 32)); } - - //dumpbuf(data, 1024); - + + //dumpbuf(data, 1024); + a = BSHA_IC1; b = BSHA_IC2; c = BSHA_IC3; d = BSHA_IC4; e = BSHA_IC5; g = 0; - + // Loops unrolled. BSHA_OP1(a, b, c, d, e, *ldata++, g) BSHA_OP1(a, b, c, d, e, *ldata++, g) BSHA_OP1(a, b, c, d, e, *ldata++, g) BSHA_OP1(a, b, c, d, e, *ldata++, g) diff --git a/src/bncsutil/bsha1.h b/src/bncsutil/bsha1.h index 6283c2e..71fb980 100644 --- a/src/bncsutil/bsha1.h +++ b/src/bncsutil/bsha1.h @@ -41,7 +41,7 @@ extern "C" { * hash: Buffer, at least 20 bytes in length, to receive the hash. */ MEXP(void) calcHashBuf(const char* data, size_t length, char* hash); - + /* * New implementation. Broken. No plans to fix. */ diff --git a/src/bncsutil/cdkeydecoder.cpp b/src/bncsutil/cdkeydecoder.cpp index 41c233e..a606ba5 100644 --- a/src/bncsutil/cdkeydecoder.cpp +++ b/src/bncsutil/cdkeydecoder.cpp @@ -22,7 +22,7 @@ * write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA */ - + #include #include #include // w2/d2 and w3 tables @@ -31,7 +31,8 @@ #include // for isdigit(), isalnum(), and toupper() #include // for memcpy() #include // for sscanf() - +// #include + /** * Implementation-specific CD-key hash structure. */ @@ -63,13 +64,13 @@ CDKeyDecoder::CDKeyDecoder() { initialized = 0; keyOK = 0; hashLen = 0; - cdkey = (char*) 0; - w3value2 = (char*) 0; - keyHash = (char*) 0; + cdkey = (char*) 0; + w3value2 = (char*) 0; + keyHash = (char*) 0; } CDKeyDecoder::CDKeyDecoder(const char* cd_key) { - CDKeyDecoder(cd_key, std::strlen(cd_key)); + CDKeyDecoder(cd_key, std::strlen(cd_key)); } /** @@ -80,19 +81,19 @@ CDKeyDecoder::CDKeyDecoder(const char* cd_key) { */ CDKeyDecoder::CDKeyDecoder(const char* cdKey, size_t keyLength) { unsigned int i; - + initialized = 0; - product = 0; - value1 = 0; - value2 = 0; + product = 0; + value1 = 0; + value2 = 0; keyOK = 0; hashLen = 0; - cdkey = (char*) 0; - w3value2 = (char*) 0; - keyHash = (char*) 0; - + cdkey = (char*) 0; + w3value2 = (char*) 0; + keyHash = (char*) 0; + if (keyLength <= 0) return; - + // Initial sanity check if (keyLength == 13) { // StarCraft key @@ -101,9 +102,9 @@ CDKeyDecoder::CDKeyDecoder(const char* cdKey, size_t keyLength) { } keyType = KEY_STARCRAFT; #if DEBUG - bncsutil_debug_message_a( - "Created CD key decoder with STAR key %s.", cdKey - ); + bncsutil_debug_message_a( + "Created CD key decoder with STAR key %s.", cdKey + ); #endif } else { // D2/W2/W3 key @@ -114,54 +115,54 @@ CDKeyDecoder::CDKeyDecoder(const char* cdKey, size_t keyLength) { case 16: keyType = KEY_WARCRAFT2; #if DEBUG - bncsutil_debug_message_a( - "Created CD key decoder with W2/D2 key %s.", cdKey - ); + bncsutil_debug_message_a( + "Created CD key decoder with W2/D2 key %s.", cdKey + ); #endif break; case 26: keyType = KEY_WARCRAFT3; #if DEBUG - bncsutil_debug_message_a( - "Created CD key decoder with WAR3 key %s.", cdKey - ); + bncsutil_debug_message_a( + "Created CD key decoder with WAR3 key %s.", cdKey + ); #endif break; default: #if DEBUG - bncsutil_debug_message_a( - "Created CD key decoder with unrecognized key %s.", cdKey - ); + bncsutil_debug_message_a( + "Created CD key decoder with unrecognized key %s.", cdKey + ); #endif return; } } - + cdkey = new char[keyLength + 1]; initialized = 1; keyLen = keyLength; strcpy(cdkey, cdKey); - + switch (keyType) { case KEY_STARCRAFT: keyOK = processStarCraftKey(); #if DEBUG - bncsutil_debug_message_a("%s: ok=%d; product=%d; public=%d; " - "private=%d", cdkey, keyOK, getProduct(), getVal1(), getVal2()); + bncsutil_debug_message_a("%s: ok=%d; product=%d; public=%d; " + "private=%d", cdkey, keyOK, getProduct(), getVal1(), getVal2()); #endif break; case KEY_WARCRAFT2: keyOK = processWarCraft2Key(); #if DEBUG - bncsutil_debug_message_a("%s: ok=%d; product=%d; public=%d; " - "private=%d", cdkey, keyOK, getProduct(), getVal1(), getVal2()); + bncsutil_debug_message_a("%s: ok=%d; product=%d; public=%d; " + "private=%d", cdkey, keyOK, getProduct(), getVal1(), getVal2()); #endif break; case KEY_WARCRAFT3: keyOK = processWarCraft3Key(); #if DEBUG - bncsutil_debug_message_a("%s: ok=%d; product=%d; public=%d; ", - cdkey, keyOK, getProduct(), getVal1()); + bncsutil_debug_message_a("%s: ok=%d; product=%d; public=%d; ", + cdkey, keyOK, getProduct(), getVal1()); #endif break; default: @@ -174,8 +175,8 @@ CDKeyDecoder::~CDKeyDecoder() { delete [] cdkey; if (hashLen > 0 && keyHash != NULL) delete [] keyHash; - if (w3value2) - delete [] w3value2; + if (w3value2) + delete [] w3value2; } int CDKeyDecoder::isKeyValid() { @@ -187,27 +188,27 @@ int CDKeyDecoder::getVal2Length() { } uint32_t CDKeyDecoder::getProduct() { - switch (keyType) { - case KEY_STARCRAFT: - case KEY_WARCRAFT2: - return (uint32_t) LSB4(product); - case KEY_WARCRAFT3: - return (uint32_t) MSB4(product); - default: - return (uint32_t) -1; - } + switch (keyType) { + case KEY_STARCRAFT: + case KEY_WARCRAFT2: + return (uint32_t) LSB4(product); + case KEY_WARCRAFT3: + return (uint32_t) MSB4(product); + default: + return (uint32_t) -1; + } } uint32_t CDKeyDecoder::getVal1() { switch (keyType) { - case KEY_STARCRAFT: - case KEY_WARCRAFT2: - return (uint32_t) LSB4(value1); - case KEY_WARCRAFT3: - return (uint32_t) MSB4(value1); - default: - return (uint32_t) -1; - } + case KEY_STARCRAFT: + case KEY_WARCRAFT2: + return (uint32_t) LSB4(value1); + case KEY_WARCRAFT3: + return (uint32_t) MSB4(value1); + default: + return (uint32_t) -1; + } } uint32_t CDKeyDecoder::getVal2() { @@ -239,35 +240,35 @@ size_t CDKeyDecoder::calculateHash(uint32_t clientToken, { struct CDKEYHASH kh; SHA1Context sha; - + if (!initialized || !keyOK) return 0; hashLen = 0; - + kh.clientToken = clientToken; kh.serverToken = serverToken; - + switch (keyType) { case KEY_STARCRAFT: case KEY_WARCRAFT2: - kh.product = (uint32_t) LSB4(product); - kh.value1 = (uint32_t) LSB4(value1); + kh.product = (uint32_t) LSB4(product); + kh.value1 = (uint32_t) LSB4(value1); kh.value2.s.zero = 0; kh.value2.s.v = (uint32_t) LSB4(value2); - + keyHash = new char[20]; calcHashBuf((char*) &kh, 24, keyHash); hashLen = 20; #if DEBUG - bncsutil_debug_message_a("%s: Hash calculated.", cdkey); - bncsutil_debug_dump(keyHash, 20); + bncsutil_debug_message_a("%s: Hash calculated.", cdkey); + bncsutil_debug_dump(keyHash, 20); #endif return 20; case KEY_WARCRAFT3: - kh.product = (uint32_t) MSB4(product); - kh.value1 = (uint32_t) MSB4(value1); + kh.product = (uint32_t) MSB4(product); + kh.value1 = (uint32_t) MSB4(value1); memcpy(kh.value2.l.v, w3value2, 10); if (SHA1Reset(&sha)) @@ -281,10 +282,10 @@ size_t CDKeyDecoder::calculateHash(uint32_t clientToken, } SHA1Reset(&sha); hashLen = 20; - + #if DEBUG - bncsutil_debug_message_a("%s: Hash calculated.", cdkey); - bncsutil_debug_dump(keyHash, 20); + bncsutil_debug_message_a("%s: Hash calculated.", cdkey); + bncsutil_debug_dump(keyHash, 20); #endif return 20; @@ -300,7 +301,7 @@ size_t CDKeyDecoder::calculateHash(uint32_t clientToken, */ size_t CDKeyDecoder::getHash(char* outputBuffer) { if (hashLen == 0 || !keyHash || !outputBuffer) - return 0; + return 0; memcpy(outputBuffer, keyHash, hashLen); return hashLen; } @@ -318,21 +319,21 @@ int CDKeyDecoder::processStarCraftKey() { int accum, pos, i; char temp; int hashKey = 0x13AC9741; - char cdkey[14]; + char cdkey[14]; + + std::strcpy(cdkey, this->cdkey); - std::strcpy(cdkey, this->cdkey); - // Verification accum = 3; for (i = 0; i < (int) (keyLen - 1); i++) { accum += ((tolower(cdkey[i]) - '0') ^ (accum * 2)); } - - if ((accum % 10) != (cdkey[12] - '0')) { - bncsutil_debug_message_a("error: %s is not a valid StarCraft key", cdkey); + + if ((accum % 10) != (cdkey[12] - '0')) { + // bncsutil_debug_message_a("error: %s is not a valid StarCraft key", cdkey); return 0; - } - + } + // Shuffling pos = 0x0B; for (i = 0xC2; i >= 7; i -= 0x11) { @@ -341,7 +342,7 @@ int CDKeyDecoder::processStarCraftKey() { cdkey[i % 0x0C] = temp; pos--; } - + // Final Value for (i = (int) (keyLen - 2); i >= 0; i--) { temp = toupper(cdkey[i]); @@ -353,10 +354,10 @@ int CDKeyDecoder::processStarCraftKey() { cdkey[i] ^= ((char) i & 1); } } - + // Final Calculations sscanf(cdkey, "%2ld%7ld%3ld", &product, &value1, &value2); - + return 1; } @@ -364,10 +365,10 @@ int CDKeyDecoder::processWarCraft2Key() { unsigned long r, n, n2, v, v2, checksum; int i; unsigned char c1, c2, c; - char cdkey[17]; + char cdkey[17]; + + std::strcpy(cdkey, this->cdkey); - std::strcpy(cdkey, this->cdkey); - r = 1; checksum = 0; for (i = 0; i < 16; i += 2) { @@ -375,7 +376,7 @@ int CDKeyDecoder::processWarCraft2Key() { n = c1 * 3; c2 = w2Map[(int) cdkey[i + 1]]; n = c2 + n * 8; - + if (n >= 0x100) { n -= 0x100; checksum |= r; @@ -387,7 +388,7 @@ int CDKeyDecoder::processWarCraft2Key() { cdkey[i + 1] = getHexValue(n); r <<= 1; } - + v = 3; for (i = 0; i < 16; i++) { c = cdkey[i]; @@ -397,11 +398,11 @@ int CDKeyDecoder::processWarCraft2Key() { v += n; } v &= 0xFF; - + if (v != checksum) { return 0; } - + n = 0; for (int j = 15; j >= 0; j--) { c = cdkey[j]; @@ -441,55 +442,55 @@ int CDKeyDecoder::processWarCraft3Key() { int a, b; int i; char decode; - + a = 0; b = 0x21; - + memset(table, 0, W3_BUFLEN); memset(values, 0, (sizeof(int) * 4)); - + for (i = 0; ((unsigned int) i) < keyLen; i++) { cdkey[i] = toupper(cdkey[i]); a = (b + 0x07B5) % W3_BUFLEN; b = (a + 0x07B5) % W3_BUFLEN; - decode = w3KeyMap[cdkey[i]]; + decode = w3KeyMap[(int)cdkey[i]]; table[a] = (decode / 5); table[b] = (decode % 5); } - + // Mult i = W3_BUFLEN; do { mult(4, 5, values + 3, table[i - 1]); } while (--i); - + decodeKeyTable(values); - - // 00 00 38 08 f0 64 18 6c 79 14 14 8E B9 49 1D BB - // -------- - // val1 - product = values[0] >> 0xA; - product = SWAP4(product); + // 00 00 38 08 f0 64 18 6c 79 14 14 8E B9 49 1D BB + // -------- + // val1 + + product = values[0] >> 0xA; + product = SWAP4(product); #if LITTLEENDIAN - for (i = 0; i < 4; i++) { - values[i] = MSB4(values[i]); - } + for (i = 0; i < 4; i++) { + values[i] = MSB4(values[i]); + } #endif - value1 = LSB4(*(uint32_t*) (((char*) values) + 2)) & 0xFFFFFF03; + value1 = LSB4(*(uint32_t*) (((char*) values) + 2)) & 0xFFFFFF00; - w3value2 = new char[10]; + w3value2 = new char[10]; #if LITTLEENDIAN - *((uint16_t*) w3value2) = MSB2(*(uint16_t*) (((char*) values) + 6)); - *((uint32_t*) ((char*) w3value2 + 2)) = MSB4(*(uint32_t*) (((char*) values) + 8)); - *((uint32_t*) ((char*) w3value2 + 6)) = MSB4(*(uint32_t*) (((char*) values) + 12)); + *((uint16_t*) w3value2) = MSB2(*(uint16_t*) (((char*) values) + 6)); + *((uint32_t*) ((char*) w3value2 + 2)) = MSB4(*(uint32_t*) (((char*) values) + 8)); + *((uint32_t*) ((char*) w3value2 + 6)) = MSB4(*(uint32_t*) (((char*) values) + 12)); #else - *((uint16_t*) w3value2) = LSB2(*(uint16_t*) (((char*) values) + 6)); - *((uint32_t*) ((char*) w3value2 + 2)) = LSB4(*(uint32_t*) (((char*) values) + 8)); - *((uint32_t*) ((char*) w3value2 + 6)) = LSB4(*(uint32_t*) (((char*) values) + 12)); + *((uint16_t*) w3value2) = LSB2(*(uint16_t*) (((char*) values) + 6)); + *((uint32_t*) ((char*) w3value2 + 2)) = LSB4(*(uint32_t*) (((char*) values) + 8)); + *((uint32_t*) ((char*) w3value2 + 6)) = LSB4(*(uint32_t*) (((char*) values) + 12)); #endif - return 1; + return 1; } inline void CDKeyDecoder::mult(int r, const int x, int* a, int dcByte) { @@ -510,7 +511,7 @@ void CDKeyDecoder::decodeKeyTable(int* keyTable) { int ckt_temp; var8 = 29; int i = 464; - + // pass 1 do { int j; @@ -520,7 +521,7 @@ void CDKeyDecoder::decodeKeyTable(int* keyTable) { varC = keyTable[3 - var4]; varC &= (0xF << esi); varC = varC >> esi; - + if (i < 464) { for (j = 29; (unsigned int) j > var8; j--) { /* @@ -536,7 +537,7 @@ void CDKeyDecoder::decodeKeyTable(int* keyTable) { varC = w3TranslateMap[ebp ^ w3TranslateMap[varC + i] + i]; } } - + j = --var8; while (j >= 0) { ecx = (j & 7) << 2; @@ -547,12 +548,12 @@ void CDKeyDecoder::decodeKeyTable(int* keyTable) { varC = w3TranslateMap[ebp ^ w3TranslateMap[varC + i] + i]; j--; } - + j = 3 - var4; ebx = (w3TranslateMap[varC + i] & 0xF) << esi; keyTable[j] = (ebx | ~(0xF << esi) & ((int) keyTable[j])); } while ((i -= 16) >= 0); - + // pass 2 eax = 0; edx = 0; @@ -560,26 +561,26 @@ void CDKeyDecoder::decodeKeyTable(int* keyTable) { edi = 0; esi = 0; ebp = 0; - + for (i = 0; i < 4; i++) { copy[i] = LSB4(keyTable[i]); } scopy = (unsigned char*) copy; - + for (edi = 0; edi < 120; edi++) { unsigned int location = 12; eax = edi & 0x1F; ecx = esi & 0x1F; edx = 3 - (edi >> 5); - + location -= ((esi >> 5) << 2); ebp = *(int*) (scopy + location); ebp = LSB4(ebp); - + //ebp = (ebp & (1 << ecx)) >> ecx; ebp &= (1 << ecx); ebp = ebp >> ecx; - + //keyTable[edx] = ((ebp & 1) << eax) | (~(1 << eax) & keyTable[edx]); ckt = (keyTable + edx); ckt_temp = *ckt; diff --git a/src/bncsutil/cdkeydecoder.h b/src/bncsutil/cdkeydecoder.h index cdf46bb..0f845f1 100644 --- a/src/bncsutil/cdkeydecoder.h +++ b/src/bncsutil/cdkeydecoder.h @@ -27,7 +27,7 @@ #define BNCSUTIL_CDKEYDECODER_H #include - + /** * Internal key type constants. */ @@ -49,18 +49,18 @@ MCEXP(CDKeyDecoder) { unsigned long value2; unsigned long product; char* w3value2; - + int processStarCraftKey(); int processWarCraft2Key(); int processWarCraft3Key(); - + void decodeKeyTable(int* keyTable); - + inline char getHexValue(int v); inline int getNumValue(char v); - + inline void mult(const int r, const int x, int* a, int dcByte); - + public: /** * Creates a new CD-key decoder object. @@ -68,8 +68,8 @@ MCEXP(CDKeyDecoder) { */ CDKeyDecoder(); - CDKeyDecoder(const char* cd_key); - + CDKeyDecoder(const char* cd_key); + /** * Creates a new CD-key decoder object, using the specified key. * keyLength should be the length of the key, NOT INCLUDING the @@ -77,16 +77,16 @@ MCEXP(CDKeyDecoder) { * this constructor to check the validity of the provided key. */ CDKeyDecoder(const char* cdKey, size_t keyLength); - + virtual ~CDKeyDecoder(); - + int isKeyValid(); int getVal2Length(); uint32_t getProduct(); uint32_t getVal1(); uint32_t getVal2(); int getLongVal2(char* out); - + /** * Calculates the CD-Key hash for use in SID_AUTH_CHECK (0x51) * Returns the length of the generated hash; call getHash and pass @@ -99,7 +99,7 @@ MCEXP(CDKeyDecoder) { * endianness is not a factor. */ size_t calculateHash(uint32_t clientToken, uint32_t serverToken); - + /** * Places the calculated CD-key hash in outputBuffer. You must call * calculateHash before getHash. Returns the length of the hash diff --git a/src/bncsutil/checkrevision.cpp b/src/bncsutil/checkrevision.cpp index 7708e06..1bd4610 100644 --- a/src/bncsutil/checkrevision.cpp +++ b/src/bncsutil/checkrevision.cpp @@ -22,7 +22,7 @@ * write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA */ - + #include #include #include @@ -67,440 +67,442 @@ extern "C" { std::vector checkrevision_seeds; void initialize_checkrevision_seeds() { - static bool run = false; - - if (run) - return; - - run = true; - - checkrevision_seeds.reserve(8); - - checkrevision_seeds.push_back(0xE7F4CB62); - checkrevision_seeds.push_back(0xF6A14FFC); - checkrevision_seeds.push_back(0xAA5504AF); - checkrevision_seeds.push_back(0x871FCDC2); - checkrevision_seeds.push_back(0x11BF6A18); - checkrevision_seeds.push_back(0xC57292E6); - checkrevision_seeds.push_back(0x7927D27E); + static bool run = false; + + if (run) + return; + + run = true; + + checkrevision_seeds.reserve(8); + + checkrevision_seeds.push_back(0xE7F4CB62); + checkrevision_seeds.push_back(0xF6A14FFC); + checkrevision_seeds.push_back(0xAA5504AF); + checkrevision_seeds.push_back(0x871FCDC2); + checkrevision_seeds.push_back(0x11BF6A18); + checkrevision_seeds.push_back(0xC57292E6); + checkrevision_seeds.push_back(0x7927D27E); + checkrevision_seeds.push_back(0x2FEC8733); } MEXP(long) get_mpq_seed(int mpq_number) { - if (((size_t) mpq_number) >= checkrevision_seeds.size()) { - bncsutil_debug_message_a("error: no known revision check seed for " - "MPQ#%u", mpq_number); - return 0; - } - - return checkrevision_seeds[mpq_number]; + if (((size_t) mpq_number) >= checkrevision_seeds.size()) { + //bncsutil_debug_message_a("error: no known revision check seed for " + // "MPQ#%u", mpq_number); + return 0; + } + + return checkrevision_seeds[mpq_number]; } MEXP(long) set_mpq_seed(int mpq_number, long new_seed) { - long ret; - - if (((size_t) mpq_number) >= checkrevision_seeds.size()) { - ret = 0; - checkrevision_seeds.reserve((size_t) mpq_number); - } else { - ret = checkrevision_seeds[mpq_number]; - } - - checkrevision_seeds[mpq_number] = new_seed; - return ret; + long ret; + + if (((size_t) mpq_number) >= checkrevision_seeds.size()) { + ret = 0; + checkrevision_seeds.reserve((size_t) mpq_number); + } else { + ret = checkrevision_seeds[mpq_number]; + } + + checkrevision_seeds[mpq_number] = new_seed; + return ret; } MEXP(int) extractMPQNumber(const char* mpqName) { - const char* n; - int mpqNum; - if (mpqName == NULL) - return -1; - if ((n = (const char*) std::strchr(mpqName, '.')) == NULL) - return -1; - // extract int value of version number - mpqNum = atoi(n - 1); - return mpqNum; + const char* n; + int mpqNum; + if (mpqName == NULL) + return -1; + if ((n = (const char*) std::strchr(mpqName, '.')) == NULL) + return -1; + // extract int value of version number + mpqNum = atoi(n - 1); + return mpqNum; } -const char* basename(const char* file_name) +const char* get_basename(const char* file_name) { - const char* base; - - for (base = (file_name + strlen(file_name)); base >= file_name; base--) { - if (*base == '\\' || *base == '/') - break; - } - - return ++base; + const char* base; + + for (base = (file_name + strlen(file_name)); base >= file_name; base--) { + if (*base == '\\' || *base == '/') + break; + } + + return ++base; } MEXP(int) checkRevision(const char* formula, const char* files[], int numFiles, - int mpqNumber, unsigned long* checksum) + int mpqNumber, unsigned long* checksum) { - long values[4], ovd[4], ovs1[4], ovs2[4]; - char ops[4]; - const char* token; - int curFormula = 0; - file_t f; - uint8_t* file_buffer; - uint32_t* dwBuf; - uint32_t* current; - size_t seed_count; - + uint64_t values[4]; + long ovd[4], ovs1[4], ovs2[4]; + char ops[4]; + const char* token; + int curFormula = 0; + file_t f; + uint8_t* file_buffer; + uint32_t* dwBuf; + uint32_t* current; + size_t seed_count; + #if DEBUG - int i; - bncsutil_debug_message_a("checkRevision(\"%s\", {", formula); - for (i = 0; i < numFiles; i++) { - bncsutil_debug_message_a("\t\"%s\",", files[i]); - } - bncsutil_debug_message_a("}, %d, %d, %p);", numFiles, mpqNumber, checksum); + int i; + bncsutil_debug_message_a("checkRevision(\"%s\", {", formula); + for (i = 0; i < numFiles; i++) { + bncsutil_debug_message_a("\t\"%s\",", files[i]); + } + bncsutil_debug_message_a("}, %d, %d, %p);", numFiles, mpqNumber, checksum); #endif - - if (!formula || !files || numFiles == 0 || mpqNumber <= 0 || !checksum) { - bncsutil_debug_message("error: checkRevision() parameter sanity check " - "failed"); - return 0; - } - - seed_count = checkrevision_seeds.size(); - if (seed_count == 0) { - initialize_checkrevision_seeds(); - seed_count = checkrevision_seeds.size(); - } - - if (seed_count <= (size_t) mpqNumber) { - bncsutil_debug_message_a("error: no revision check seed value defined " - "for MPQ number %d", mpqNumber); - return 0; - } - - token = formula; - while (token && *token) { - if (*(token + 1) == '=') { - int variable = BUCR_GETNUM(*token); - if (variable < 0 || variable > 3) { - bncsutil_debug_message_a("error: Unknown revision check formula" - " variable %c", *token); - return 0; - } - - token += 2; // skip over equals sign - if (BUCR_ISNUM(*token)) { - values[variable] = atol(token); - } else { - if (curFormula > 3) { - // more than 4 operations? bloody hell. - bncsutil_debug_message("error: Revision check formula" - " contains more than 4 operations; unsupported."); - return 0; - } - ovd[curFormula] = variable; - ovs1[curFormula] = BUCR_GETNUM(*token); - ops[curFormula] = *(token + 1); - ovs2[curFormula] = BUCR_GETNUM(*(token + 2)); - curFormula++; - } - } - - for (; *token != 0; token++) { - if (*token == ' ') { - token++; - break; - } - } - } - - // Actual hashing (yay!) - // "hash A by the hashcode" - values[0] ^= checkrevision_seeds[mpqNumber]; - - for (int i = 0; i < numFiles; i++) { - size_t file_len, remainder, rounded_size, buffer_size; - - f = file_open(files[i], FILE_READ); - if (!f) { - bncsutil_debug_message_a("error: Failed to open file %s", - files[i]); - return 0; - } - - file_len = file_size(f); - remainder = file_len % 1024; - rounded_size = file_len - remainder; - - file_buffer = (uint8_t*) file_map(f, file_len, 0); - if (!file_buffer) { - file_close(f); - bncsutil_debug_message_a("error: Failed to map file %s into memory", - files[i]); - return 0; - } - - if (remainder == 0) { - // Mapped buffer may be used directly, without padding. - dwBuf = (uint32_t*) file_buffer; - buffer_size = file_len; - } else { - // Must be padded to nearest KB. - size_t extra = 1024 - remainder; - uint8_t pad = (uint8_t) 0xFF; - uint8_t* pad_dest; - - buffer_size = file_len + extra; - dwBuf = (uint32_t*) malloc(buffer_size); - if (!dwBuf) { - bncsutil_debug_message_a("error: Failed to allocate %d bytes " - "of memory as a temporary buffer", buffer_size); - file_unmap(f, file_buffer); - file_close(f); - return 0; - } - - memcpy(dwBuf, file_buffer, file_len); - file_unmap(f, file_buffer); - file_buffer = (uint8_t*) 0; - - pad_dest = ((uint8_t*) dwBuf) + file_len; - for (size_t j = file_len; j < buffer_size; j++) { - *pad_dest++ = pad--; - } - - } - - current = dwBuf; - for (size_t j = 0; j < buffer_size; j += 4) { - values[3] = LSB4(*(current++)); - for (int k = 0; k < curFormula; k++) { - switch (ops[k]) { - case '+': - values[ovd[k]] = values[ovs1[k]] + values[ovs2[k]]; - break; - case '-': - values[ovd[k]] = values[ovs1[k]] - values[ovs2[k]]; - break; - case '^': - values[ovd[k]] = values[ovs1[k]] ^ values[ovs2[k]]; - break; - case '*': - // well, you never know - values[ovd[k]] = values[ovs1[k]] * values[ovs2[k]]; - break; - case '/': - // well, you never know - values[ovd[k]] = values[ovs1[k]] / values[ovs2[k]]; - break; - default: - // unrecognized operation - // shit - file_unmap(f, dwBuf); - file_close(f); - return 0; - } - } - } - - if (file_buffer) - file_unmap(f, file_buffer); - else if (dwBuf && file_buffer == 0) - free(dwBuf); // padded buffer - file_close(f); - } - - *checksum = (unsigned long) LSB4(values[2]); + + if (!formula || !files || numFiles == 0 || mpqNumber < 0 || !checksum) { + //bncsutil_debug_message("error: checkRevision() parameter sanity check " + // "failed"); + return 0; + } + + seed_count = checkrevision_seeds.size(); + if (seed_count == 0) { + initialize_checkrevision_seeds(); + seed_count = checkrevision_seeds.size(); + } + + if (seed_count <= (size_t) mpqNumber) { + //bncsutil_debug_message_a("error: no revision check seed value defined " + // "for MPQ number %d", mpqNumber); + return 0; + } + + token = formula; + while (token && *token) { + if (*(token + 1) == '=') { + int variable = BUCR_GETNUM(*token); + if (variable < 0 || variable > 3) { + //bncsutil_debug_message_a("error: Unknown revision check formula" + // " variable %c", *token); + return 0; + } + + token += 2; // skip over equals sign + if (BUCR_ISNUM(*token)) { + values[variable] = ATOL64(token); + } else { + if (curFormula > 3) { + // more than 4 operations? bloody hell. + //bncsutil_debug_message("error: Revision check formula" + // " contains more than 4 operations; unsupported."); + return 0; + } + ovd[curFormula] = variable; + ovs1[curFormula] = BUCR_GETNUM(*token); + ops[curFormula] = *(token + 1); + ovs2[curFormula] = BUCR_GETNUM(*(token + 2)); + curFormula++; + } + } + + for (; *token != 0; token++) { + if (*token == ' ') { + token++; + break; + } + } + } + + // Actual hashing (yay!) + // "hash A by the hashcode" + values[0] ^= checkrevision_seeds[mpqNumber]; + + for (int i = 0; i < numFiles; i++) { + size_t file_len, remainder, rounded_size, buffer_size; + + f = file_open(files[i], FILE_READ); + if (!f) { + //bncsutil_debug_message_a("error: Failed to open file %s", + // files[i]); + return 0; + } + + file_len = file_size(f); + remainder = file_len % 1024; + rounded_size = file_len - remainder; + + file_buffer = (uint8_t*) file_map(f, file_len, 0); + if (!file_buffer) { + file_close(f); + //bncsutil_debug_message_a("error: Failed to map file %s into memory", + // files[i]); + return 0; + } + + if (remainder == 0) { + // Mapped buffer may be used directly, without padding. + dwBuf = (uint32_t*) file_buffer; + buffer_size = file_len; + } else { + // Must be padded to nearest KB. + size_t extra = 1024 - remainder; + uint8_t pad = (uint8_t) 0xFF; + uint8_t* pad_dest; + + buffer_size = file_len + extra; + dwBuf = (uint32_t*) malloc(buffer_size); + if (!dwBuf) { + //bncsutil_debug_message_a("error: Failed to allocate %d bytes " + // "of memory as a temporary buffer", buffer_size); + file_unmap(f, file_buffer); + file_close(f); + return 0; + } + + memcpy(dwBuf, file_buffer, file_len); + file_unmap(f, file_buffer); + file_buffer = (uint8_t*) 0; + + pad_dest = ((uint8_t*) dwBuf) + file_len; + for (size_t j = file_len; j < buffer_size; j++) { + *pad_dest++ = pad--; + } + + } + + current = dwBuf; + for (size_t j = 0; j < buffer_size; j += 4) { + values[3] = LSB4(*(current++)); + for (int k = 0; k < curFormula; k++) { + switch (ops[k]) { + case '+': + values[ovd[k]] = values[ovs1[k]] + values[ovs2[k]]; + break; + case '-': + values[ovd[k]] = values[ovs1[k]] - values[ovs2[k]]; + break; + case '^': + values[ovd[k]] = values[ovs1[k]] ^ values[ovs2[k]]; + break; + case '*': + // well, you never know + values[ovd[k]] = values[ovs1[k]] * values[ovs2[k]]; + break; + case '/': + // well, you never know + values[ovd[k]] = values[ovs1[k]] / values[ovs2[k]]; + break; + default: + // unrecognized operation + // shit + file_unmap(f, dwBuf); + file_close(f); + return 0; + } + } + } + + if (file_buffer) + file_unmap(f, file_buffer); + else if (dwBuf && file_buffer == 0) + free(dwBuf); // padded buffer + file_close(f); + } + + *checksum = (unsigned long) LSB4(values[2]); #if DEBUG - bncsutil_debug_message_a("\tChecksum = %lu", *checksum); + bncsutil_debug_message_a("\tChecksum = %lu", *checksum); #endif - return 1; + return 1; } MEXP(int) checkRevisionFlat(const char* valueString, const char* file1, const char* file2, const char* file3, int mpqNumber, unsigned long* checksum) { - const char* files[] = - {file1, file2, file3}; - return checkRevision(valueString, files, 3, mpqNumber, - checksum); + const char* files[] = + {file1, file2, file3}; + return checkRevision(valueString, files, 3, mpqNumber, + checksum); } MEXP(int) getExeInfo(const char* file_name, char* exe_info, - size_t exe_info_size, uint32_t* version, int platform) + size_t exe_info_size, uint32_t* version, int platform) { - const char* base = (char*) 0; - unsigned long file_size; - FILE* f = (FILE*) 0; - int ret; + const char* base = (char*) 0; + unsigned long file_size; + FILE* f = (FILE*) 0; + int ret; #ifdef MOS_WINDOWS - HANDLE hFile; - FILETIME ft; - SYSTEMTIME st; - LPBYTE buf; - VS_FIXEDFILEINFO* ffi; - DWORD infoSize, bytesRead; + HANDLE hFile; + FILETIME ft; + SYSTEMTIME st; + LPBYTE buf; + VS_FIXEDFILEINFO* ffi; + DWORD infoSize, bytesRead; #else - cm_pe_t pe; - cm_pe_resdir_t* root; - cm_pe_resdir_t* dir; - cm_pe_version_t ffi; - size_t i; - struct stat st; - struct tm* time; + cm_pe_t pe; + cm_pe_resdir_t* root; + cm_pe_resdir_t* dir; + cm_pe_version_t ffi; + size_t i; + struct stat st; + struct tm* time; #endif - - if (!file_name || !exe_info || !exe_info_size || !version) - return 0; - - base = basename(file_name); - - switch (platform) { - case BNCSUTIL_PLATFORM_X86: -#ifdef MOS_WINDOWS - infoSize = GetFileVersionInfoSize(file_name, &bytesRead); - if (infoSize == 0) - return 0; - buf = (LPBYTE) VirtualAlloc(NULL, infoSize, MEM_COMMIT, - PAGE_READWRITE); - if (buf == NULL) - return 0; - if (GetFileVersionInfo(file_name, NULL, infoSize, buf) == FALSE) - return 0; - if (!VerQueryValue(buf, "\\", (LPVOID*) &ffi, (PUINT) &infoSize)) - return 0; - - *version = - ((HIWORD(ffi->dwProductVersionMS) & 0xFF) << 24) | - ((LOWORD(ffi->dwProductVersionMS) & 0xFF) << 16) | - ((HIWORD(ffi->dwProductVersionLS) & 0xFF) << 8) | - (LOWORD(ffi->dwProductVersionLS) & 0xFF); + + if (!file_name || !exe_info || !exe_info_size || !version) + return 0; + + base = get_basename(file_name); + + switch (platform) { + case BNCSUTIL_PLATFORM_X86: +#ifdef MOS_WINDOWS + infoSize = GetFileVersionInfoSize(file_name, &bytesRead); + if (infoSize == 0) + return 0; + buf = (LPBYTE) VirtualAlloc(NULL, infoSize, MEM_COMMIT, + PAGE_READWRITE); + if (buf == NULL) + return 0; + if (GetFileVersionInfo(file_name, NULL, infoSize, buf) == FALSE) + return 0; + if (!VerQueryValue(buf, "\\", (LPVOID*) &ffi, (PUINT) &infoSize)) + return 0; + + *version = + ((HIWORD(ffi->dwProductVersionMS) & 0xFF) << 24) | + ((LOWORD(ffi->dwProductVersionMS) & 0xFF) << 16) | + ((HIWORD(ffi->dwProductVersionLS) & 0xFF) << 8) | + (LOWORD(ffi->dwProductVersionLS) & 0xFF); #if DEBUG - bncsutil_debug_message_a("%s version = %d.%d.%d.%d (0x%08X)", - base, (HIWORD(ffi->dwProductVersionMS) & 0xFF), - (LOWORD(ffi->dwProductVersionMS) & 0xFF), - (HIWORD(ffi->dwProductVersionLS) & 0xFF), - (LOWORD(ffi->dwProductVersionLS) & 0xFF), - *version); + bncsutil_debug_message_a("%s version = %d.%d.%d.%d (0x%08X)", + base, (HIWORD(ffi->dwProductVersionMS) & 0xFF), + (LOWORD(ffi->dwProductVersionMS) & 0xFF), + (HIWORD(ffi->dwProductVersionLS) & 0xFF), + (LOWORD(ffi->dwProductVersionLS) & 0xFF), + *version); #endif - VirtualFree(buf, 0lu, MEM_RELEASE); + VirtualFree(buf, 0lu, MEM_RELEASE); #else - pe = cm_pe_load(file_name); - if (!pe) - return 0; - root = cm_pe_load_resources(pe); - if (!root) { - cm_pe_unload(pe); - return 0; - } - - for (i = 0; i < root->subdir_count; i++) { - dir = (root->subdirs + i); - if (dir->name == 16) { - if (!cm_pe_fixed_version(pe, dir->subdirs->resources, - &ffi)) - { - cm_pe_unload_resources(root); - cm_pe_unload(pe); - return 0; - } - break; - } - } - *version = - ((HIWORD(ffi.dwProductVersionMS) & 0xFF) << 24) | - ((LOWORD(ffi.dwProductVersionMS) & 0xFF) << 16) | - ((HIWORD(ffi.dwProductVersionLS) & 0xFF) << 8) | - (LOWORD(ffi.dwProductVersionLS) & 0xFF); + pe = cm_pe_load(file_name); + if (!pe) + return 0; + root = cm_pe_load_resources(pe); + if (!root) { + cm_pe_unload(pe); + return 0; + } + + for (i = 0; i < root->subdir_count; i++) { + dir = (root->subdirs + i); + if (dir->name == 16) { + if (!cm_pe_fixed_version(pe, dir->subdirs->resources, + &ffi)) + { + cm_pe_unload_resources(root); + cm_pe_unload(pe); + return 0; + } + break; + } + } + *version = + ((HIWORD(ffi.dwProductVersionMS) & 0xFF) << 24) | + ((LOWORD(ffi.dwProductVersionMS) & 0xFF) << 16) | + ((HIWORD(ffi.dwProductVersionLS) & 0xFF) << 8) | + (LOWORD(ffi.dwProductVersionLS) & 0xFF); #if DEBUG - bncsutil_debug_message_a("%s version = %d.%d.%d.%d (0x%08X)", - base, (HIWORD(ffi.dwProductVersionMS) & 0xFF), - (LOWORD(ffi.dwProductVersionMS) & 0xFF), - (HIWORD(ffi.dwProductVersionLS) & 0xFF), - (LOWORD(ffi.dwProductVersionLS) & 0xFF), - *version); + bncsutil_debug_message_a("%s version = %d.%d.%d.%d (0x%08X)", + base, (HIWORD(ffi.dwProductVersionMS) & 0xFF), + (LOWORD(ffi.dwProductVersionMS) & 0xFF), + (HIWORD(ffi.dwProductVersionLS) & 0xFF), + (LOWORD(ffi.dwProductVersionLS) & 0xFF), + *version); #endif - - cm_pe_unload_resources(root); - cm_pe_unload(pe); + + cm_pe_unload_resources(root); + cm_pe_unload(pe); #endif - break; - case BNCSUTIL_PLATFORM_MAC: - case BNCSUTIL_PLATFORM_OSX: - f = fopen(file_name, "r"); - if (!f) - return 0; - if (fseek(f, -4, SEEK_END) != 0) { - fclose(f); - return 0; - } - if (fread(version, 4, 1, f) != 1) { - fclose(f); - return 0; - } + break; + case BNCSUTIL_PLATFORM_MAC: + case BNCSUTIL_PLATFORM_OSX: + f = fopen(file_name, "r"); + if (!f) + return 0; + if (fseek(f, -4, SEEK_END) != 0) { + fclose(f); + return 0; + } + if (fread(version, 4, 1, f) != 1) { + fclose(f); + return 0; + } #ifdef MOS_WINDOWS - fclose(f); + fclose(f); #endif - } - + } + #ifdef MOS_WINDOWS - hFile = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - if (hFile == INVALID_HANDLE_VALUE) - return 0; - file_size = GetFileSize(hFile, NULL); - if (!GetFileTime(hFile, &ft, NULL, NULL)) { - CloseHandle(hFile); - return 0; - } - - if (!FileTimeToSystemTime(&ft, &st)) { - CloseHandle(hFile); - return 0; - } - CloseHandle(hFile); - - ret = snprintf(exe_info, exe_info_size, - "%s %02u/%02u/%02u %02u:%02u:%02u %lu", base, st.wMonth, - st.wDay, (st.wYear % 100), st.wHour, st.wMinute, st.wSecond, - file_size); + hFile = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + if (hFile == INVALID_HANDLE_VALUE) + return 0; + file_size = GetFileSize(hFile, NULL); + if (!GetFileTime(hFile, &ft, NULL, NULL)) { + CloseHandle(hFile); + return 0; + } + + if (!FileTimeToSystemTime(&ft, &st)) { + CloseHandle(hFile); + return 0; + } + CloseHandle(hFile); + + ret = snprintf(exe_info, exe_info_size, + "%s %02u/%02u/%02u %02u:%02u:%02u %lu", base, st.wMonth, + st.wDay, (st.wYear % 100), st.wHour, st.wMinute, st.wSecond, + file_size); #else - if (!f) - f = fopen(file_name, "r"); - if (!f) - return 0; - if (fseek(f, 0, SEEK_END) == -1) { - fclose(f); - return 0; - } - file_size = ftell(f); - fclose(f); - - if (stat(file_name, &st) != 0) - return 0; - - time = gmtime(&st.st_mtime); - if (!time) - return 0; - - switch (platform) { - case BNCSUTIL_PLATFORM_MAC: - case BNCSUTIL_PLATFORM_OSX: - if (time->tm_year >= 100) // y2k - time->tm_year -= 100; - break; - } - - ret = (int) snprintf(exe_info, exe_info_size, - "%s %02u/%02u/%02u %02u:%02u:%02u %lu", base, - (time->tm_mon+1), time->tm_mday, time->tm_year, - time->tm_hour, time->tm_min, time->tm_sec, file_size); + if (!f) + f = fopen(file_name, "r"); + if (!f) + return 0; + if (fseek(f, 0, SEEK_END) == -1) { + fclose(f); + return 0; + } + file_size = ftell(f); + fclose(f); + + if (stat(file_name, &st) != 0) + return 0; + + time = gmtime(&st.st_mtime); + if (!time) + return 0; + + switch (platform) { + case BNCSUTIL_PLATFORM_MAC: + case BNCSUTIL_PLATFORM_OSX: + if (time->tm_year >= 100) // y2k + time->tm_year -= 100; + break; + } + + ret = (int) snprintf(exe_info, exe_info_size, + "%s %02u/%02u/%02u %02u:%02u:%02u %lu", base, + (time->tm_mon+1), time->tm_mday, time->tm_year, + time->tm_hour, time->tm_min, time->tm_sec, file_size); #endif #if DEBUG - bncsutil_debug_message(exe_info); + bncsutil_debug_message(exe_info); #endif - return ret; + return ret; } #ifdef __cplusplus diff --git a/src/bncsutil/checkrevision.h b/src/bncsutil/checkrevision.h index 1e42fe7..c31aa9f 100644 --- a/src/bncsutil/checkrevision.h +++ b/src/bncsutil/checkrevision.h @@ -71,8 +71,8 @@ MEXP(int) checkRevision( MEXP(int) checkRevisionFlat( const char* valueString, const char* file1, - const char* file2, - const char* file3, + const char* file2, + const char* file3, int mpqNumber, unsigned long* checksum ); @@ -87,11 +87,11 @@ MEXP(int) checkRevisionFlat( * necessary. */ MEXP(int) getExeInfo(const char* file_name, - char* exe_info, - size_t exe_info_size, - uint32_t* version, - int platform); - + char* exe_info, + size_t exe_info_size, + uint32_t* version, + int platform); + /** * Gets the seed value for the given MPQ file. If no seed value for the given * MPQ is registered with BNCSutil, returns 0. diff --git a/src/bncsutil/debug.c b/src/bncsutil/debug.c index 020a162..587edeb 100644 --- a/src/bncsutil/debug.c +++ b/src/bncsutil/debug.c @@ -18,127 +18,127 @@ #include #endif -struct _bncsutil_debug_env +typedef struct _bncsutil_debug_env { - int enabled; + int enabled; #ifdef MOS_WINDOWS - HANDLE output; - BOOL console_was_created; - WORD orig_attributes; - WORD sans_foreground; + HANDLE output; + BOOL console_was_created; + WORD orig_attributes; + WORD sans_foreground; #else - FILE* output; + FILE* output; #endif -}; +} debug_env_t; const char default_err_msg[] = "[unknown error]"; #ifdef MOS_WINDOWS BOOL debug_set_color(debug_env_t env, WORD color) { - return SetConsoleTextAttribute(env->output, color | env->sans_foreground); + return SetConsoleTextAttribute(env.output, color | env.sans_foreground); } BOOL debug_restore_color(debug_env_t env) { - return SetConsoleTextAttribute(env->output, env->orig_attributes); + return SetConsoleTextAttribute(env.output, env.orig_attributes); } BOOL debug_intense_color(debug_env_t env) { - CONSOLE_SCREEN_BUFFER_INFO info; - if (!GetConsoleScreenBufferInfo(env->output, &info)) - return FALSE; - return SetConsoleTextAttribute(env->output, info.wAttributes | - FOREGROUND_INTENSITY); + CONSOLE_SCREEN_BUFFER_INFO info; + if (!GetConsoleScreenBufferInfo(env.output, &info)) + return FALSE; + return SetConsoleTextAttribute(env.output, info.wAttributes | + FOREGROUND_INTENSITY); } BOOL debug_mellow_color(debug_env_t env) { - CONSOLE_SCREEN_BUFFER_INFO info; - if (!GetConsoleScreenBufferInfo(env->output, &info)) - return FALSE; - return SetConsoleTextAttribute(env->output, info.wAttributes | - ~FOREGROUND_INTENSITY); + CONSOLE_SCREEN_BUFFER_INFO info; + if (!GetConsoleScreenBufferInfo(env.output, &info)) + return FALSE; + return SetConsoleTextAttribute(env.output, info.wAttributes | + ~FOREGROUND_INTENSITY); } void debug_setup_console(debug_env_t env) { - CONSOLE_SCREEN_BUFFER_INFO info; - - if (AllocConsole()) { - // only set title if new console was created - SetConsoleTitle("BNCSutil Debug Console"); - env->console_was_created = TRUE; - } else { - env->console_was_created = FALSE; - } - env->output = GetStdHandle(STD_OUTPUT_HANDLE); - GetConsoleScreenBufferInfo(env->output, &info); - env->orig_attributes = info.wAttributes; - env->sans_foreground = info.wAttributes & - ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | - FOREGROUND_INTENSITY); + CONSOLE_SCREEN_BUFFER_INFO info; + + if (AllocConsole()) { + // only set title if new console was created + SetConsoleTitle("BNCSutil Debug Console"); + env.console_was_created = TRUE; + } else { + env.console_was_created = FALSE; + } + env.output = GetStdHandle(STD_OUTPUT_HANDLE); + GetConsoleScreenBufferInfo(env.output, &info); + env.orig_attributes = info.wAttributes; + env.sans_foreground = info.wAttributes & + ~(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | + FOREGROUND_INTENSITY); } #endif size_t debug_write(debug_env_t env, const char* message) { #ifdef MOS_WINDOWS - DWORD chars_written; - BOOL res; - if (!env->output) - debug_setup_console(env); - res = WriteConsole(env->output, message, (DWORD) strlen(message), - &chars_written, (LPVOID) 0); - return (res) ? (size_t) chars_written : (size_t) -1; + DWORD chars_written; + BOOL res; + if (!env.output) + debug_setup_console(env); + res = WriteConsole(env.output, message, (DWORD) strlen(message), + &chars_written, (LPVOID) 0); + return (res) ? (size_t) chars_written : (size_t) -1; #else - return fwrite(message, 1, strlen(message), env->output); + return fwrite(message, 1, strlen(message), env->output); #endif } size_t get_console_width(debug_env_t env) { #ifdef MOS_WINDOWS - CONSOLE_SCREEN_BUFFER_INFO info; - if (!GetConsoleScreenBufferInfo(env->output, &info)) - return (size_t) 0; - return (size_t) info.dwSize.X; + CONSOLE_SCREEN_BUFFER_INFO info; + if (!GetConsoleScreenBufferInfo(env.output, &info)) + return (size_t) 0; + return (size_t) info.dwSize.X; #else - char* columns = getenv("COLUMNS"); - if (!columns) - return (size_t) 0; - return (size_t) strtol(columns, (char**) 0, 0); + char* columns = getenv("COLUMNS"); + if (!columns) + return (size_t) 0; + return (size_t) strtol(columns, (char**) 0, 0); #endif } char* produce_dump(const char* data, size_t length) { - return (char*) 0; + return (char*) 0; } debug_env_t get_debug_environment() { - static debug_env_t env = (debug_env_t) 0; - - if (!env) { - env = (debug_env_t) malloc(sizeof(struct _bncsutil_debug_env)); + static debug_env_t env = (debug_env_t) 0; + + if (!env) { + env = (debug_env_t) malloc(sizeof(struct _bncsutil_debug_env)); /*#if defined(BNCSUTIL_DEBUG_MESSAGES) && BNCSUTIL_DEBUG_MESSAGES - env->enabled = 1; + env->enabled = 1; #else - env->enabled = 0; + env->enabled = 0; #endif*/ - env->enabled = 0; + env->enabled = 0; #ifdef MOS_WINDOWS - env->output = (HANDLE) NULL; - //debug_setup_console(env); + env->output = (HANDLE) NULL; + //debug_setup_console(env); #else - env->output = stderr; + env->output = stderr; #endif - } - - return env; + } + + return env; } /** @@ -146,8 +146,8 @@ debug_env_t get_debug_environment() */ MEXP(int) bncsutil_debug_status(void) { - debug_env_t env = get_debug_environment(); - return env->enabled; + debug_env_t env = get_debug_environment(); + return env->enabled; } /** * Set new_status to zero to turn debugging messages off or nonzero to turn @@ -155,197 +155,197 @@ MEXP(int) bncsutil_debug_status(void) */ MEXP(int) bncsutil_set_debug_status(int new_status) { - debug_env_t env = get_debug_environment(); - if (!env) { - return 0; - } + debug_env_t env = get_debug_environment(); + if (!env) { + return 0; + } #ifdef MOS_WINDOWS - if (env->enabled && !new_status && env->console_was_created) { - FreeConsole(); - } else if (!env->enabled && new_status) { - debug_setup_console(env); - } + if (env->enabled && !new_status && env->console_was_created) { + FreeConsole(); + } else if (!env->enabled && new_status) { + debug_setup_console(env); + } #endif - env->enabled = (new_status != 0) ? 1 : 0; - return 1; + env->enabled = (new_status != 0) ? 1 : 0; + return 1; } MEXP(int) bncsutil_internal_debug_messages() { #if DEBUG - return 1; + return 1; #else - return 0; + return 0; #endif } MEXP(void) bncsutil_debug_message(const char* message) { - debug_env_t env = get_debug_environment(); - char timestamp[12]; - /*size_t length;*/ + debug_env_t env = get_debug_environment(); + char timestamp[12]; + /*size_t length;*/ #ifdef MOS_WINDOWS - SYSTEMTIME local_time; + SYSTEMTIME local_time; #else - time_t unix_time; - struct tm* local_time; + time_t unix_time; + struct tm* local_time; #endif - if (!env->enabled) { - return; - } + if (!env->enabled) { + return; + } #ifdef MOS_WINDOWS - GetLocalTime(&local_time); - sprintf(timestamp, "[%02d:%02d:%02d] ", local_time.wHour, - local_time.wMinute, local_time.wSecond); - debug_set_color(env, FOREGROUND_RED | FOREGROUND_GREEN | - FOREGROUND_INTENSITY); -#else - time(&unix_time); - local_time = localtime(&unix_time); - sprintf(timestamp, "[%02d:%02d:%02d] ", local_time->tm_hour, - local_time->tm_min, local_time->tm_sec); + GetLocalTime(&local_time); + sprintf(timestamp, "[%02d:%02d:%02d] ", local_time.wHour, + local_time.wMinute, local_time.wSecond); + debug_set_color(env, FOREGROUND_RED | FOREGROUND_GREEN | + FOREGROUND_INTENSITY); +#else + time(&unix_time); + local_time = localtime(&unix_time); + sprintf(timestamp, "[%02d:%02d:%02d] ", local_time->tm_hour, + local_time->tm_min, local_time->tm_sec); #endif - debug_write(env, timestamp); + debug_write(env, timestamp); #ifdef MOS_WINDOWS - debug_restore_color(env); + debug_restore_color(env); #endif - - debug_write(env, message); - debug_write(env, "\r\n"); + + debug_write(env, message); + debug_write(env, "\r\n"); } MEXP(void) bncsutil_debug_message_a(const char* message, ...) { - char buf[4092]; - va_list args; - va_start(args, message); - - vsprintf(buf, message, args); - va_end(args); - - bncsutil_debug_message(buf); + char buf[4092]; + va_list args; + va_start(args, message); + + vsprintf(buf, message, args); + va_end(args); + + bncsutil_debug_message(buf); } MEXP(void) bncsutil_debug_dump(const void* data, size_t data_length) { - char ascii[] = " \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; - char hex[4]; - char pos_indicator[] = "0000 "; - debug_env_t env = get_debug_environment(); - size_t i; - size_t j = 2; /* printing to ASCII buffer skips over 2 spaces */ - size_t k; - char cur; - int on_boundary; - size_t current_string_length; - - if (!env->enabled) { - return; - } - - debug_intense_color(env); - for (i = 0; i < data_length; i++) { - on_boundary = ((i + 1) % 16 == 0); - - if ((i + 1) % 16 == 1) { + char ascii[] = " \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + char hex[4]; + char pos_indicator[] = "0000 "; + debug_env_t env = get_debug_environment(); + size_t i; + size_t j = 2; /* printing to ASCII buffer skips over 2 spaces */ + size_t k; + char cur; + int on_boundary; + size_t current_string_length; + + if (!env->enabled) { + return; + } + + debug_intense_color(env); + for (i = 0; i < data_length; i++) { + on_boundary = ((i + 1) % 16 == 0); + + if ((i + 1) % 16 == 1) { #ifdef MOS_WINDOWS - debug_set_color(env, FOREGROUND_RED | FOREGROUND_BLUE | - FOREGROUND_INTENSITY); + debug_set_color(env, FOREGROUND_RED | FOREGROUND_BLUE | + FOREGROUND_INTENSITY); #endif - debug_write(env, pos_indicator); + debug_write(env, pos_indicator); #ifdef MOS_WINDOWS - debug_restore_color(env); + debug_restore_color(env); #endif - } - - cur = *(((char*) data) + i); - /* The cast to unsigned char and then int is required to properly - * handle 8 bit characters. */ - ascii[j++] = (isprint((int) (unsigned char) cur)) ? cur : '.'; - sprintf(hex, "%02X ", (cur & 0xFF)); - debug_write(env, hex); - - if ((i + 1) % 8 == 0) { - debug_write(env, " "); - } - - if (on_boundary || (i + 1) == data_length) { - if (!on_boundary) { - current_string_length = 3 * (i % 16); - if ((i % 16) > 8) - current_string_length++; - - for (k = 0; k < (47 - current_string_length); k++) { - debug_write(env, " "); - } - } + } + + cur = *(((char*) data) + i); + /* The cast to unsigned char and then int is required to properly + * handle 8 bit characters. */ + ascii[j++] = (isprint((int) (unsigned char) cur)) ? cur : '.'; + sprintf(hex, "%02X ", (cur & 0xFF)); + debug_write(env, hex); + + if ((i + 1) % 8 == 0) { + debug_write(env, " "); + } + + if (on_boundary || (i + 1) == data_length) { + if (!on_boundary) { + current_string_length = 3 * (i % 16); + if ((i % 16) > 8) + current_string_length++; + + for (k = 0; k < (47 - current_string_length); k++) { + debug_write(env, " "); + } + } #ifdef MOS_WINDOWS - debug_set_color(env, FOREGROUND_BLUE | FOREGROUND_GREEN | - FOREGROUND_INTENSITY); -#endif - ascii[j] = 0; - debug_write(env, ascii); - debug_write(env, "\r\n"); - j = 2; /* reset position in ASCII buffer */ + debug_set_color(env, FOREGROUND_BLUE | FOREGROUND_GREEN | + FOREGROUND_INTENSITY); +#endif + ascii[j] = 0; + debug_write(env, ascii); + debug_write(env, "\r\n"); + j = 2; /* reset position in ASCII buffer */ #ifdef MOS_WINDOWS - debug_set_color(env, FOREGROUND_BLUE | FOREGROUND_INTENSITY); + debug_set_color(env, FOREGROUND_BLUE | FOREGROUND_INTENSITY); #endif - sprintf(pos_indicator, "%04X ", i + 1); + sprintf(pos_indicator, "%04X ", i + 1); #ifdef MOS_WINDOWS - debug_restore_color(env); -#endif - } - } + debug_restore_color(env); +#endif + } + } } #ifdef MOS_WINDOWS const char* sys_error_msg() { - const char* buffer; - DWORD res; - - res = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - (const void*) 0, (DWORD) 0, (DWORD) 0, (LPTSTR) &buffer, (DWORD) 0, - (va_list*) 0); - if (!res) { - bncsutil_debug_message("error: Failed to get Windows error message."); - return default_err_msg; - } - - return buffer; + const char* buffer; + DWORD res; + + res = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + (const void*) 0, (DWORD) 0, (DWORD) 0, (LPTSTR) &buffer, (DWORD) 0, + (va_list*) 0); + if (!res) { + bncsutil_debug_message("error: Failed to get Windows error message."); + return default_err_msg; + } + + return buffer; } void free_sys_err_msg(const char* message_pointer) { - if (message_pointer) - LocalFree(message_pointer); + if (message_pointer) + LocalFree(message_pointer); } #else const char* sys_error_msg() { - return (const char*) strerror(errno); + return (const char*) strerror(errno); } void free_sys_err_msg() { - /* Do nothing. */ + /* Do nothing. */ } #endif MEXP(void) bncsutil_print_dump(FILE* stream, const void* data, size_t length) { - + } #ifdef MOS_WINDOWS MEXP(void) bncsutil_print_dump_win(HANDLE stream, const void* data, - size_t length) + size_t length) { - + } #endif diff --git a/src/bncsutil/debug.h b/src/bncsutil/debug.h index 0cbf7d1..b799a17 100644 --- a/src/bncsutil/debug.h +++ b/src/bncsutil/debug.h @@ -6,86 +6,99 @@ * April 1, 2006 */ -#ifndef _DEBUG_H_INCLUDED_ -#define _DEBUG_H_INCLUDED_ 1 - -#undef DEBUG -#if defined(BNCSUTIL_DEBUG_MESSAGES) && BNCSUTIL_DEBUG_MESSAGES -# define INTERNAL_DEBUG(msg) bncsutil_debug_message(msg) -# define INTERNAL_DUMP(data, length) bncsutil_debug_dump((data), (length)) -# define DEBUG 1 -#else -# define INTERNAL_DEBUG(msg) -# define INTERNAL_DUMP(data, length) -# define DEBUG 0 -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef MOS_WINDOWS -#include -#endif - -#include -#include - -typedef struct _bncsutil_debug_env* debug_env_t; - -debug_env_t get_debug_environment(); - -/** - * Returns nonzero if debugging messages are enabled or zero if disabled. - */ -MEXP(int) bncsutil_debug_status(void); -/** - * Set new_status to zero to turn debugging messages off or nonzero to turn - * them on. Returns nonzero on success and zero on failure. - */ -MEXP(int) bncsutil_set_debug_status(int new_status); - -/** - * Returns nonzero if internal debug messages were compiled in or zero if - * they were not. - */ -MEXP(int) bncsutil_internal_debug_messages(); - -/** - * Prints a debug message. - */ -MEXP(void) bncsutil_debug_message(const char* message); +/* #ifndef _DEBUG_H_INCLUDED_ */ +/* #define _DEBUG_H_INCLUDED_ 1 */ + +/* #undef DEBUG */ +/* #if defined(BNCSUTIL_DEBUG_MESSAGES) && BNCSUTIL_DEBUG_MESSAGES */ +/* # define INTERNAL_DEBUG(msg) bncsutil_debug_message(msg) */ +/* # define INTERNAL_DUMP(data, length) bncsutil_debug_dump((data), (length)) */ +/* # define DEBUG 1 */ +/* #else */ +/* # define INTERNAL_DEBUG(msg) */ +/* # define INTERNAL_DUMP(data, length) */ +/* # define DEBUG 0 */ +/* #endif */ + +/* #undef DEBUG */ + +/* #ifdef __cplusplus */ +/* extern "C" { */ +/* #endif */ + +/* #ifdef MOS_WINDOWS */ +/* #include */ +/* #endif */ + +/* #include */ +/* #include */ + +/* typedef struct _bncsutil_debug_env* debug_env_t; */ + +/* debug_env_t get_debug_environment(); */ + +/* /\** */ +/* * Returns nonzero if debugging messages are enabled or zero if disabled. */ +/* *\/ */ +/* MEXP(int) bncsutil_debug_status(void); */ +/* /\** */ +/* * Set new_status to zero to turn debugging messages off or nonzero to turn */ +/* * them on. Returns nonzero on success and zero on failure. */ +/* *\/ */ +/* MEXP(int) bncsutil_set_debug_status(int new_status); */ + +/* /\** */ +/* * Returns nonzero if internal debug messages were compiled in or zero if */ +/* * they were not. */ +/* *\/ */ +/* MEXP(int) bncsutil_internal_debug_messages(); */ + +/* /\** */ +/* * Prints a debug message. */ +/* *\/ */ +/* MEXP(void) bncsutil_debug_message(const char* message); */ + +/* /\** */ +/* * Prints a debug message using a printf-style format string. */ +/* *\/ */ +/* MEXP(void) bncsutil_debug_message_a(const char* message, ...); */ + +/* /\** */ +/* * Prints a hex dump of data to the debug console. */ +/* *\/ */ +/* MEXP(void) bncsutil_debug_dump(const void* data, size_t data_length); */ + +/* /\** */ +/* * Returns a pointer to a message describing the last system error event. */ +/* *\/ */ +/* const char* sys_error_msg(); */ + +/* /\** */ +/* * Frees the pointer provided by sys_error_msg(). */ +/* *\/ */ +/* void free_sys_err_msg(const char* message_pointer); */ + +/* /\* Not implemented! *\/ */ +/* MEXP(void) bncsutil_print_dump(FILE* stream, const void* data, size_t length); */ +/* #ifdef MOS_WINDOWS */ +/* //MEXP(void) bncsutil_print_dump_win(HANDLE stream, const void* data, */ +/* // size_t length); */ +/* #endif */ + +/* #ifdef __cplusplus */ +/* } // extern "C" */ +/* #endif */ + +/* #endif /\* DEBUG *\/ */ + + +#ifndef __DEBUG_H__ +#define __DEBUG_H__ + +#define bncsutil_debug_message(x) +#define free_sys_err_msg(x) +#define bncsutil_debug_message_a(x, y) +#define sys_error_msg(x) -/** - * Prints a debug message using a printf-style format string. - */ -MEXP(void) bncsutil_debug_message_a(const char* message, ...); -/** - * Prints a hex dump of data to the debug console. - */ -MEXP(void) bncsutil_debug_dump(const void* data, size_t data_length); - -/** - * Returns a pointer to a message describing the last system error event. - */ -const char* sys_error_msg(); - -/** - * Frees the pointer provided by sys_error_msg(). - */ -void free_sys_err_msg(const char* message_pointer); - -/* Not implemented! */ -MEXP(void) bncsutil_print_dump(FILE* stream, const void* data, size_t length); -#ifdef MOS_WINDOWS -//MEXP(void) bncsutil_print_dump_win(HANDLE stream, const void* data, -// size_t length); #endif - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif /* DEBUG */ \ No newline at end of file diff --git a/src/bncsutil/decodekey.cpp b/src/bncsutil/decodekey.cpp index 6caf08d..c38276e 100644 --- a/src/bncsutil/decodekey.cpp +++ b/src/bncsutil/decodekey.cpp @@ -32,11 +32,11 @@ #include #ifdef MOS_WINDOWS - #include + #include #else - #include - #include - #include + #include + #include + #include #endif #include #include @@ -61,37 +61,37 @@ unsigned int numDecoders = 0; unsigned int sizeDecoders = 0; #ifdef MOS_WINDOWS -// HANDLE mutex; - CRITICAL_SECTION kd_control; +// HANDLE mutex; + CRITICAL_SECTION kd_control; #else - pthread_mutex_t mutex; + pthread_mutex_t mutex; #endif int kd_lock_decoders() { #ifdef MOS_WINDOWS -/* DWORD dwWaitResult; - dwWaitResult = WaitForSingleObject(mutex, MUTEX_TIMEOUT_MS); - switch (dwWaitResult) { - case WAIT_OBJECT_0: - // success - break; - case WAIT_TIMEOUT: - return 0; - break; - case WAIT_ABANDONED: - // weird, but should be OK - break; - default: - return 0; - break; - }*/ - EnterCriticalSection(&kd_control); +/* DWORD dwWaitResult; + dwWaitResult = WaitForSingleObject(mutex, MUTEX_TIMEOUT_MS); + switch (dwWaitResult) { + case WAIT_OBJECT_0: + // success + break; + case WAIT_TIMEOUT: + return 0; + break; + case WAIT_ABANDONED: + // weird, but should be OK + break; + default: + return 0; + break; + }*/ + EnterCriticalSection(&kd_control); #else - int err = 0; - pthread_cond_t cond = PTHREAD_COND_INITIALIZER; - struct timespec wait_time = {0, MUTEX_TIMEOUT_MS * 1000}; - - err = pthread_cond_timedwait(&cond, &mutex, &wait_time); + int err = 0; + pthread_cond_t cond = PTHREAD_COND_INITIALIZER; + struct timespec wait_time = {0, MUTEX_TIMEOUT_MS * 1000}; + + err = pthread_cond_timedwait(&cond, &mutex, &wait_time); switch (err) { case 0: // success @@ -99,7 +99,7 @@ int kd_lock_decoders() { default: // error return 0; - } + } #endif return 1; } @@ -111,312 +111,312 @@ int kd_lock_decoders() { #endif MEXP(int) kd_quick(const char* cd_key, uint32_t client_token, - uint32_t server_token, uint32_t* public_value, - uint32_t* product, char* hash_buffer, size_t buffer_len) + uint32_t server_token, uint32_t* public_value, + uint32_t* product, char* hash_buffer, size_t buffer_len) { - CDKeyDecoder kd(cd_key, strlen(cd_key)); - size_t hash_len; - - if (!kd.isKeyValid()) - return 0; - - *public_value = kd.getVal1(); - *product = kd.getProduct(); - - hash_len = kd.calculateHash(client_token, server_token); - if (!hash_len || hash_len > buffer_len) - return 0; - - kd.getHash(hash_buffer); - return 1; + CDKeyDecoder kd(cd_key, strlen(cd_key)); + size_t hash_len; + + if (!kd.isKeyValid()) + return 0; + + *public_value = kd.getVal1(); + *product = kd.getProduct(); + + hash_len = kd.calculateHash(client_token, server_token); + if (!hash_len || hash_len > buffer_len) + return 0; + + kd.getHash(hash_buffer); + return 1; } MEXP(int) kd_init() { - static int has_run = 0; + static int has_run = 0; + + if (has_run) + return 1; - if (has_run) - return 1; - #ifdef MOS_WINDOWS - /*mutex = CreateMutex(NULL, FALSE, NULL); - if (mutex == NULL) - return 0;*/ - InitializeCriticalSection(&kd_control); + /*mutex = CreateMutex(NULL, FALSE, NULL); + if (mutex == NULL) + return 0;*/ + InitializeCriticalSection(&kd_control); #else - if (pthread_mutex_init(&mutex, NULL)) - return 0; + if (pthread_mutex_init(&mutex, NULL)) + return 0; #endif - numDecoders = 0; - sizeDecoders = 0; - decoders = (CDKeyDecoder**) 0; - has_run = 1; + numDecoders = 0; + sizeDecoders = 0; + decoders = (CDKeyDecoder**) 0; + has_run = 1; #if DEBUG - bncsutil_debug_message("Initialized key decoding C API."); + bncsutil_debug_message("Initialized key decoding C API."); #endif - return 1; + return 1; } unsigned int kd_findAvailable() { - unsigned int i; - CDKeyDecoder** d; - - d = decoders; - for (i = 0; i < sizeDecoders; i++) { - if (*d == (CDKeyDecoder*) 0) - return i; - d++; - } - - // no room available, must expand - decoders = (CDKeyDecoder**) realloc(decoders, sizeof(CDKeyDecoder*) * - (sizeDecoders + DEFAULT_DECODERS_SIZE)); - if (!decoders) - return (unsigned int) -1; - - memset(decoders + sizeDecoders, 0, - sizeof(CDKeyDecoder*) * DEFAULT_DECODERS_SIZE); // zero new memory - - i = sizeDecoders; - sizeDecoders += DEFAULT_DECODERS_SIZE; - return i; + unsigned int i; + CDKeyDecoder** d; + + d = decoders; + for (i = 0; i < sizeDecoders; i++) { + if (*d == (CDKeyDecoder*) 0) + return i; + d++; + } + + // no room available, must expand + decoders = (CDKeyDecoder**) realloc(decoders, sizeof(CDKeyDecoder*) * + (sizeDecoders + DEFAULT_DECODERS_SIZE)); + if (!decoders) + return (unsigned int) -1; + + memset(decoders + sizeDecoders, 0, + sizeof(CDKeyDecoder*) * DEFAULT_DECODERS_SIZE); // zero new memory + + i = sizeDecoders; + sizeDecoders += DEFAULT_DECODERS_SIZE; + return i; } MEXP(int) kd_create(const char* cdkey, int keyLength) { - unsigned int i; - CDKeyDecoder** d; - static int dcs_initialized = 0; - - if (!dcs_initialized) { - if (!kd_init()) - return -1; - dcs_initialized = 1; - } - - if (!kd_lock_decoders()) return -1; - - i = kd_findAvailable(); - if (i == (unsigned int) -1) - return -1; - - d = (decoders + i); - *d = new CDKeyDecoder(cdkey, keyLength); - if (!(**d).isKeyValid()) { - delete *d; - *d = (CDKeyDecoder*) 0; - return -1; - } - - numDecoders++; - - kd_unlock_decoders(); - return (int) i; + unsigned int i; + CDKeyDecoder** d; + static int dcs_initialized = 0; + + if (!dcs_initialized) { + if (!kd_init()) + return -1; + dcs_initialized = 1; + } + + if (!kd_lock_decoders()) return -1; + + i = kd_findAvailable(); + if (i == (unsigned int) -1) + return -1; + + d = (decoders + i); + *d = new CDKeyDecoder(cdkey, keyLength); + if (!(**d).isKeyValid()) { + delete *d; + *d = (CDKeyDecoder*) 0; + return -1; + } + + numDecoders++; + + kd_unlock_decoders(); + return (int) i; } /* MEXP(int) kd_create(char* cdkey, int keyLength) { if (!kd_lock_decoders()) return -1; - CDKeyDecoder* d; - unsigned int i; - if (numDecoders >= sizeDecoders) { - CDKeyDecoder** temp = new CDKeyDecoder*[sizeDecoders]; - for (unsigned int j = 0; j < sizeDecoders; j++) { - temp[j] = decoders[j]; - } - delete [] decoders; - decoders = new CDKeyDecoder*[sizeDecoders + DEFAULT_DECODERS_SIZE]; - - for (unsigned int j = 0; j < sizeDecoders; j++) { - decoders[j] = temp[j]; - } - delete [] temp; - sizeDecoders += DEFAULT_DECODERS_SIZE; - } - i = numDecoders++; - decoders[i] = new CDKeyDecoder(cdkey, keyLength); - d = decoders[i]; - if (!d->isKeyValid()) { - delete decoders[i]; - return -1; - } - kd_unlock_decoders(); - - d = NULL; - return (int) i; + CDKeyDecoder* d; + unsigned int i; + if (numDecoders >= sizeDecoders) { + CDKeyDecoder** temp = new CDKeyDecoder*[sizeDecoders]; + for (unsigned int j = 0; j < sizeDecoders; j++) { + temp[j] = decoders[j]; + } + delete [] decoders; + decoders = new CDKeyDecoder*[sizeDecoders + DEFAULT_DECODERS_SIZE]; + + for (unsigned int j = 0; j < sizeDecoders; j++) { + decoders[j] = temp[j]; + } + delete [] temp; + sizeDecoders += DEFAULT_DECODERS_SIZE; + } + i = numDecoders++; + decoders[i] = new CDKeyDecoder(cdkey, keyLength); + d = decoders[i]; + if (!d->isKeyValid()) { + delete decoders[i]; + return -1; + } + kd_unlock_decoders(); + + d = NULL; + return (int) i; }*/ MEXP(int) kd_free(int decoder) { - CDKeyDecoder* d; + CDKeyDecoder* d; + + if (!kd_lock_decoders()) return 0; - if (!kd_lock_decoders()) return 0; + if ((unsigned int) decoder >= sizeDecoders) + return 0; - if ((unsigned int) decoder >= sizeDecoders) - return 0; + d = *(decoders + decoder); + if (!d) + return 0; - d = *(decoders + decoder); - if (!d) - return 0; + delete d; + *(decoders + decoder) = (CDKeyDecoder*) 0; - delete d; - *(decoders + decoder) = (CDKeyDecoder*) 0; - - kd_unlock_decoders(); - return 1; + kd_unlock_decoders(); + return 1; } MEXP(int) kd_val2Length(int decoder) { - CDKeyDecoder* d; - int value; + CDKeyDecoder* d; + int value; + + if (!kd_lock_decoders()) return -1; - if (!kd_lock_decoders()) return -1; + if ((unsigned int) decoder >= sizeDecoders) + return -1; - if ((unsigned int) decoder >= sizeDecoders) - return -1; + d = *(decoders + decoder); + if (!d) + return -1; - d = *(decoders + decoder); - if (!d) - return -1; + value = d->getVal2Length(); - value = d->getVal2Length(); - - kd_unlock_decoders(); - return value; + kd_unlock_decoders(); + return value; } MEXP(int) kd_product(int decoder) { - CDKeyDecoder* d; - int value; + CDKeyDecoder* d; + int value; + + if (!kd_lock_decoders()) return -1; - if (!kd_lock_decoders()) return -1; + if ((unsigned int) decoder >= sizeDecoders) + return -1; - if ((unsigned int) decoder >= sizeDecoders) - return -1; + d = *(decoders + decoder); + if (!d) + return -1; - d = *(decoders + decoder); - if (!d) - return -1; + value = d->getProduct(); - value = d->getProduct(); - - kd_unlock_decoders(); - return value; + kd_unlock_decoders(); + return value; } MEXP(int) kd_val1(int decoder) { - CDKeyDecoder* d; - int value; + CDKeyDecoder* d; + int value; + + if (!kd_lock_decoders()) return -1; - if (!kd_lock_decoders()) return -1; + if ((unsigned int) decoder >= sizeDecoders) + return -1; - if ((unsigned int) decoder >= sizeDecoders) - return -1; + d = *(decoders + decoder); + if (!d) + return -1; - d = *(decoders + decoder); - if (!d) - return -1; + value = d->getVal1(); - value = d->getVal1(); - - kd_unlock_decoders(); - return value; + kd_unlock_decoders(); + return value; } MEXP(int) kd_val2(int decoder) { - CDKeyDecoder* d; - int value; + CDKeyDecoder* d; + int value; - if (!kd_lock_decoders()) return -1; + if (!kd_lock_decoders()) return -1; + + if ((unsigned int) decoder >= sizeDecoders) + return -1; - if ((unsigned int) decoder >= sizeDecoders) - return -1; + d = *(decoders + decoder); + if (!d) + return -1; - d = *(decoders + decoder); - if (!d) - return -1; + value = d->getVal2(); - value = d->getVal2(); - - kd_unlock_decoders(); - return value; + kd_unlock_decoders(); + return value; } MEXP(int) kd_longVal2(int decoder, char* out) { - CDKeyDecoder* d; - int value; + CDKeyDecoder* d; + int value; - if (!kd_lock_decoders()) return -1; + if (!kd_lock_decoders()) return -1; - if ((unsigned int) decoder >= sizeDecoders) - return -1; + if ((unsigned int) decoder >= sizeDecoders) + return -1; - d = *(decoders + decoder); - if (!d) - return -1; + d = *(decoders + decoder); + if (!d) + return -1; - value = d->getLongVal2(out); - - kd_unlock_decoders(); - return value; + value = d->getLongVal2(out); + + kd_unlock_decoders(); + return value; } MEXP(int) kd_calculateHash(int decoder, uint32_t clientToken, - uint32_t serverToken) + uint32_t serverToken) { - CDKeyDecoder* d; - int value; + CDKeyDecoder* d; + int value; + + if (!kd_lock_decoders()) return -1; - if (!kd_lock_decoders()) return -1; + if ((unsigned int) decoder >= sizeDecoders) + return -1; - if ((unsigned int) decoder >= sizeDecoders) - return -1; + d = *(decoders + decoder); + if (!d) + return -1; - d = *(decoders + decoder); - if (!d) - return -1; + value = (int) d->calculateHash(clientToken, serverToken); - value = (int) d->calculateHash(clientToken, serverToken); - - kd_unlock_decoders(); - return value; + kd_unlock_decoders(); + return value; } MEXP(int) kd_getHash(int decoder, char* out) { - CDKeyDecoder* d; - int value; + CDKeyDecoder* d; + int value; + + if (!kd_lock_decoders()) return -1; - if (!kd_lock_decoders()) return -1; + if ((unsigned int) decoder >= sizeDecoders) + return -1; - if ((unsigned int) decoder >= sizeDecoders) - return -1; + d = *(decoders + decoder); + if (!d) + return -1; - d = *(decoders + decoder); - if (!d) - return -1; + value = (int) d->getHash(out); - value = (int) d->getHash(out); - - kd_unlock_decoders(); - return value; + kd_unlock_decoders(); + return value; } MEXP(int) kd_isValid(int decoder) { - CDKeyDecoder* d; - int value; + CDKeyDecoder* d; + int value; + + if (!kd_lock_decoders()) return -1; - if (!kd_lock_decoders()) return -1; + if ((unsigned int) decoder >= sizeDecoders) + return -1; - if ((unsigned int) decoder >= sizeDecoders) - return -1; + d = *(decoders + decoder); + if (!d) + return -1; - d = *(decoders + decoder); - if (!d) - return -1; + value = d->isKeyValid(); - value = d->isKeyValid(); - - kd_unlock_decoders(); - return value; + kd_unlock_decoders(); + return value; } #ifdef __cplusplus diff --git a/src/bncsutil/decodekey.h b/src/bncsutil/decodekey.h index dbade12..5dc8033 100644 --- a/src/bncsutil/decodekey.h +++ b/src/bncsutil/decodekey.h @@ -30,7 +30,7 @@ #ifdef __cplusplus extern "C" { #endif - + /** * Decodes a CD-key, retrieves its relevant values, and calculates a hash * suitable for SID_AUTH_CHECK (0x51) in one function call. Returns 1 on @@ -38,8 +38,8 @@ extern "C" { * calling this function. Available since BNCSutil 1.1.0. */ MEXP(int) kd_quick(const char* cd_key, uint32_t client_token, - uint32_t server_token, uint32_t* public_value, - uint32_t* product, char* hash_buffer, size_t buffer_len); + uint32_t server_token, uint32_t* public_value, + uint32_t* product, char* hash_buffer, size_t buffer_len); /** * Initializes the CD-key decoding C wrappers. @@ -96,7 +96,7 @@ MEXP(int) kd_longVal2(int decoder, char* out); * Returns the hash length or 0 on failure. */ MEXP(int) kd_calculateHash(int decoder, uint32_t clientToken, - uint32_t serverToken); + uint32_t serverToken); /** * Places the key hash in "out". The "out" buffer must be diff --git a/src/bncsutil/file.cpp b/src/bncsutil/file.cpp index 40fc9dc..bced9af 100644 --- a/src/bncsutil/file.cpp +++ b/src/bncsutil/file.cpp @@ -21,12 +21,12 @@ typedef std::map mapping_map; struct _file { #if BWIN - HANDLE f; + HANDLE f; #else - FILE* f; + FILE* f; #endif - const char* filename; - mapping_map mappings; + const char* filename; + mapping_map mappings; }; #include @@ -39,276 +39,265 @@ extern "C" { file_t file_open(const char* filename, unsigned int mode) { - file_t data; - HANDLE file; - DWORD access; - DWORD share_mode; - DWORD open_mode; - const char* sys_err; - size_t filename_buf_len; - - if (mode & FILE_READ) { - access = GENERIC_READ; - share_mode = FILE_SHARE_READ; - open_mode = OPEN_EXISTING; - } else if (mode & FILE_WRITE) { - access = GENERIC_WRITE; - share_mode = 0; - open_mode = CREATE_ALWAYS; - } - - file = CreateFile(filename, access, share_mode, NULL, open_mode, - FILE_ATTRIBUTE_NORMAL, NULL); - - if (file == INVALID_HANDLE_VALUE) { - sys_err = sys_error_msg(); - bncsutil_debug_message_a("Cannot open file \"%s\"; %s", filename, - sys_err); - free_sys_err_msg(sys_err); - return ((file_t) 0); - } - - try { - data = new _file; - } catch (std::bad_alloc) { - bncsutil_debug_message_a("Failed to allocate %u bytes to hold" - "file structure.", sizeof(struct _file)); - CloseHandle(file); - return (file_t) 0; - } - - filename_buf_len = strlen(filename) + 1; - data->filename = (const char*) malloc(filename_buf_len); - if (!data->filename) { - bncsutil_debug_message_a("Failed to allocate %u bytes to hold" - "filename.", filename_buf_len); - CloseHandle(file); - delete data; - return (file_t) 0; - } - strcpy_s((char*) data->filename, filename_buf_len, filename); - - data->f = file; - - return data; + file_t data; + HANDLE file; + DWORD access; + DWORD share_mode; + DWORD open_mode; + //const char* sys_err; + size_t filename_buf_len; + + if (mode & FILE_READ) { + access = GENERIC_READ; + share_mode = FILE_SHARE_READ; + open_mode = OPEN_EXISTING; + } else if (mode & FILE_WRITE) { + access = GENERIC_WRITE; + share_mode = 0; + open_mode = CREATE_ALWAYS; + } + + file = CreateFile(filename, access, share_mode, NULL, open_mode, + FILE_ATTRIBUTE_NORMAL, NULL); + + if (file == INVALID_HANDLE_VALUE) { + //sys_err = sys_error_msg(); + //bncsutil_debug_message_a("Cannot open file \"%s\"; %s", filename, sys_err); + //free_sys_err_msg(sys_err); + return ((file_t) 0); + } + + try { + data = new _file; + } catch (std::bad_alloc) { + //bncsutil_debug_message_a("Failed to allocate %u bytes to hold file structure.", sizeof(struct _file)); + CloseHandle(file); + return (file_t) 0; + } + + filename_buf_len = strlen(filename) + 1; + data->filename = (const char*) malloc(filename_buf_len); + if (!data->filename) { + //bncsutil_debug_message_a("Failed to allocate %u bytes to hold filename.", filename_buf_len); + CloseHandle(file); + delete data; + return (file_t) 0; + } + strcpy_s((char*) data->filename, filename_buf_len, filename); + + data->f = file; + + return data; } void file_close(file_t file) { - mapping_map::iterator it; - - if (!file) { - bncsutil_debug_message_a("error: null pointer given to file_close"); - return; - } - - for (it = file->mappings.begin(); it != file->mappings.end(); it++) { - UnmapViewOfFile((*it).first); - CloseHandle((*it).second); - } - - CloseHandle((HANDLE) file->f); - free((void*) file->filename); - delete file; + mapping_map::iterator it; + + if (!file) { + //bncsutil_debug_message_a("error: null pointer given to file_close"); + return; + } + + for (it = file->mappings.begin(); it != file->mappings.end(); it++) { + UnmapViewOfFile((*it).first); + CloseHandle((*it).second); + } + + CloseHandle((HANDLE) file->f); + free((void*) file->filename); + delete file; } size_t file_read(file_t file, void* ptr, size_t size, size_t count) { - DWORD bytes_read; - - if (!ReadFile(file->f, ptr, (DWORD) (size * count), &bytes_read, NULL)) { - return (size_t) 0; - } - - return (size_t) bytes_read; + DWORD bytes_read; + + if (!ReadFile(file->f, ptr, (DWORD) (size * count), &bytes_read, NULL)) { + return (size_t) 0; + } + + return (size_t) bytes_read; } size_t file_write(file_t file, const void* ptr, size_t size, - size_t count) + size_t count) { - DWORD bytes_written; - - if (!WriteFile(file->f, ptr, (DWORD) (size * count), &bytes_written, NULL)) - return (size_t) 0; - - return (size_t) bytes_written; + DWORD bytes_written; + + if (!WriteFile(file->f, ptr, (DWORD) (size * count), &bytes_written, NULL)) + return (size_t) 0; + + return (size_t) bytes_written; } size_t file_size(file_t file) { - return (size_t) GetFileSize(file->f, (LPDWORD) 0); + return (size_t) GetFileSize(file->f, (LPDWORD) 0); } void* file_map(file_t file, size_t len, off_t offset) { - HANDLE mapping = - CreateFileMapping((HANDLE) file->f, NULL, PAGE_READONLY, 0, 0, NULL); - void* base; - const char* err; - - if (!mapping) { - err = sys_error_msg(); - bncsutil_debug_message_a("Failed to create file mapping for \"%s\": %s", - file->filename, err); - free_sys_err_msg(err); - return (void*) 0; - } - - base = MapViewOfFile(mapping, FILE_MAP_READ, 0, (DWORD) offset, len); - if (!base) { - CloseHandle(mapping); - err = sys_error_msg(); - bncsutil_debug_message_a("Failed to map %u bytes of \"%s\" starting at " - "%u: %s", - len, file->filename, offset, err); - free_sys_err_msg(err); - return (void*) 0; - } - - file->mappings[base] = mapping; - - return base; + HANDLE mapping = + CreateFileMapping((HANDLE) file->f, NULL, PAGE_READONLY, 0, 0, NULL); + void* base; + //const char* err; + + if (!mapping) { + //err = sys_error_msg(); + //bncsutil_debug_message_a("Failed to create file mapping for \"%s\": %s", file->filename, err); + //free_sys_err_msg(err); + return (void*) 0; + } + + base = MapViewOfFile(mapping, FILE_MAP_READ, 0, (DWORD) offset, len); + if (!base) { + CloseHandle(mapping); + //err = sys_error_msg(); + //bncsutil_debug_message_a("Failed to map %u bytes of \"%s\" starting at %u: %s", len, file->filename, offset, err); + //free_sys_err_msg(err); + return (void*) 0; + } + + file->mappings[base] = mapping; + + return base; } void file_unmap(file_t file, const void* base) { - mapping_map::iterator item = file->mappings.find(base); - HANDLE mapping; - - if (item == file->mappings.end()) { - bncsutil_debug_message_a("warning: failed to unmap the block starting " - "at %p from %s; unknown block.", base, file->filename); - return; - } - - mapping = (*item).second; - - UnmapViewOfFile(base); - CloseHandle(mapping); - - file->mappings.erase(item); + mapping_map::iterator item = file->mappings.find(base); + HANDLE mapping; + + if (item == file->mappings.end()) { + //bncsutil_debug_message_a("warning: failed to unmap the block starting at %p from %s; unknown block.", base, file->filename); + return; + } + + mapping = (*item).second; + + UnmapViewOfFile(base); + CloseHandle(mapping); + + file->mappings.erase(item); } #else file_t file_open(const char* filename, unsigned int mode_flags) { - char mode[] = "rb"; - file_t data; - FILE* f; - size_t filename_buf_len; - const char* err; - - if (mode_flags & FILE_WRITE) - mode[0] = 'w'; - - f = fopen(filename, mode); - if (!f) { - return (file_t) 0; - } - - try { - data = new _file; - } catch (std::bad_alloc) { - bncsutil_debug_message_a("Failed to allocate %u bytes to hold" - "file structure."), sizeof(struct _file)); - fclose(f); - return (file_t) 0; - } - - filename_buf_len = strlen(filename) + 1; - data->filename = (const char*) malloc(filename_buf_len); - if (!data->filename) { - err = sys_error_msg(); - bncsutil_debug_message_a("Failed to allocate %u bytes to hold" - "filename; %s"), filename_buf_len); - free_sys_error_msg(err); - fclose(f); - delete data; - return (file_t) 0; - } - strcpy((char*) data->filename, filename); - - data->f = f; - - return data; + char mode[] = "rb"; + file_t data; + FILE* f; + size_t filename_buf_len; + //const char* err; + + if (mode_flags & FILE_WRITE) + mode[0] = 'w'; + + f = fopen(filename, mode); + if (!f) { + return (file_t) 0; + } + + try { + data = new _file; + } catch (std::bad_alloc) { + //bncsutil_debug_message_a("Failed to allocate %u bytes to hold file structure.", sizeof(struct _file)); + fclose(f); + return (file_t) 0; + } + + filename_buf_len = strlen(filename) + 1; + data->filename = (const char*) malloc(filename_buf_len); + if (!data->filename) { + //err = sys_error_msg(); + //bncsutil_debug_message_a("Failed to allocate %u bytes to hold filename; %s", filename_buf_len); + //free_sys_err_msg(err); + fclose(f); + delete data; + return (file_t) 0; + } + strcpy((char*) data->filename, filename); + + data->f = f; + + return data; } void file_close(file_t file) { - - if (!file) { - bncsutil_debug_message("error: null pointer given to file_close"); - return; - } - - for (it = file->mappings.begin(); it != file->mappings.end(); it++) { - munmap((void*) (*it).first, (*it).second); - } - - fclose(file->f); - delete file; + mapping_map::iterator it; + + if (!file) { + //bncsutil_debug_message("error: null pointer given to file_close"); + return; + } + + for (it = file->mappings.begin(); it != file->mappings.end(); it++) { + munmap((void*) (*it).first, (*it).second); + } + + fclose(file->f); + delete file; } size_t file_read(file_t file, void* ptr, size_t size, size_t count) { - return fread(ptr, size, count, file->f); + return fread(ptr, size, count, file->f); } size_t file_write(file_t file, const void* ptr, size_t size, - size_t count) + size_t count) { - return fwrite(ptr, size, count, file->f); + return fwrite(ptr, size, count, file->f); } size_t file_size(file_t file) { - long cur_pos = ftell(file->f); - size_t size_of_file; - - fseek(file->f, 0, SEEK_END); - size_of_file = (size_t) ftell(file->f); - fseek(file->f, cur_pos, SEEK_SET); - - return size_of_file; + long cur_pos = ftell(file->f); + size_t size_of_file; + + fseek(file->f, 0, SEEK_END); + size_of_file = (size_t) ftell(file->f); + fseek(file->f, cur_pos, SEEK_SET); + + return size_of_file; } void* file_map(file_t file, size_t len, off_t offset) { - int fd = fileno(file->f); - void* base = mmap((void*) 0, len, PROT_READ, MAP_SHARED, fd, offset); - const char* err; - - if (!base) { - err = sys_error_msg(); - bncsutil_debug_message_a("error: failed to map %u bytes of %s " - "starting at %u into memory; %s", len, file->filename, offset, - err); - free_sys_error_msg(err); - return (void*) 0; - } - - file->mappings[base] = len; - - return base; + int fd = fileno(file->f); + void* base = mmap((void*) 0, len, PROT_READ, MAP_SHARED, fd, offset); + //const char* err; + + if (!base) { + //err = sys_error_msg(); + //bncsutil_debug_message_a("error: failed to map %u bytes of %s starting at %u into memory; %s", len, file->filename, offset, err); + //free_sys_err_msg(err); + return (void*) 0; + } + + file->mappings[base] = len; + + return base; } void file_unmap(file_t file, const void* base) { - mapping_map::iterator item = file->mappings.find(base); - size_t len; - - if (item == file->mappings.end()) { - bncsutil_debug_message_a("warning: failed to unmap the block starting " - "at %p from %s; unknown block.", base, file->filename); - return; - } - - len = (*item).second; - - munmap((void*) base, len); - - file->mappings.erase(item); + mapping_map::iterator item = file->mappings.find(base); + size_t len; + + if (item == file->mappings.end()) { + //bncsutil_debug_message_a("warning: failed to unmap the block starting at %p from %s; unknown block.", base, file->filename); + return; + } + + len = (*item).second; + + munmap((void*) base, len); + + file->mappings.erase(item); } #endif diff --git a/src/bncsutil/file.h b/src/bncsutil/file.h index 4721e28..3ff4bbd 100644 --- a/src/bncsutil/file.h +++ b/src/bncsutil/file.h @@ -41,15 +41,15 @@ extern "C" { typedef struct _file* file_t; -#define FILE_READ (0x01) -#define FILE_WRITE (0x02) +#define FILE_READ (0x01) +#define FILE_WRITE (0x02) file_t file_open(const char* filename, unsigned int mode); void file_close(file_t file); size_t file_read(file_t file, void* ptr, size_t size, size_t count); size_t file_write(file_t file, const void* ptr, size_t size, - size_t count); + size_t count); size_t file_size(file_t file); void* file_map(file_t file, size_t len, off_t offset); diff --git a/src/bncsutil/gmp.h b/src/bncsutil/gmp.h new file mode 100644 index 0000000..2a036bf --- /dev/null +++ b/src/bncsutil/gmp.h @@ -0,0 +1,2189 @@ +/* Definitions for GNU multiple precision functions. -*- mode: c -*- + +Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2001, 2002, 2003, +2004, 2005, 2006, 2007 Free Software Foundation, Inc. + +This file is part of the GNU MP Library. + +The GNU MP Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +The GNU MP Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ + +#ifndef __GMP_H__ + +#if defined (__cplusplus) +#include /* for std::istream, std::ostream, std::string */ +#endif + + +#if ! defined (__GMP_WITHIN_CONFIGURE) +# if defined( _MSC_VER ) +# if defined( _WIN64 ) +# define __GMP_BITS_PER_MP_LIMB 64 +# define BITS_PER_MP_LIMB 64 +# define GMP_LIMB_BITS 64 +# define SIZEOF_MP_LIMB_T 8 +# define _LONG_LONG_LIMB 1 +# elif defined( _WIN32 ) +# define __GMP_BITS_PER_MP_LIMB 32 +# define BITS_PER_MP_LIMB 32 +# define GMP_LIMB_BITS 32 +# define SIZEOF_MP_LIMB_T 4 +# ifdef _LONG_LONG_LIMB +# undef _LONG_LONG_LIMB +# endif +# else +# error This is the wrong version of gmp.h +# endif +# endif +# define GMP_NAIL_BITS 0 +#endif +#define GMP_NUMB_BITS (GMP_LIMB_BITS - GMP_NAIL_BITS) +#define GMP_NUMB_MASK ((~ __GMP_CAST (mp_limb_t, 0)) >> GMP_NAIL_BITS) +#define GMP_NUMB_MAX GMP_NUMB_MASK +#define GMP_NAIL_MASK (~ GMP_NUMB_MASK) + + +/* The following (everything under ifndef __GNU_MP__) must be identical in + gmp.h and mp.h to allow both to be included in an application or during + the library build. */ +#ifndef __GNU_MP__ +#define __GNU_MP__ 4 + +#define __need_size_t /* tell gcc stddef.h we only want size_t */ +#if defined (__cplusplus) +#include /* for size_t */ +#else +#include /* for size_t */ +#endif +#undef __need_size_t + + + +/* __STDC__ - some ANSI compilers define this only to 0, hence the use of + "defined" and not "__STDC__-0". In particular Sun workshop C 5.0 + sets __STDC__ to 0, but requires "##" for token pasting. + + _AIX - gnu ansidecl.h asserts that all known AIX compilers are ANSI but + don't always define __STDC__. + + __DECC - current versions of DEC C (5.9 for instance) for alpha are ANSI, + but don't define __STDC__ in their default mode. Don't know if old + versions might have been K&R, but let's not worry about that unless + someone is still using one. + + _mips - gnu ansidecl.h says the RISC/OS MIPS compiler is ANSI in SVR4 + mode, but doesn't define __STDC__. + + _MSC_VER - Microsoft C is ANSI, but __STDC__ is undefined unless the /Za + option is given (in which case it's 1). + + _WIN32 - tested for by gnu ansidecl.h, no doubt on the assumption that + all w32 compilers are ansi. + + Note: This same set of tests is used by gen-psqr.c and + demos/expr/expr-impl.h, so if anything needs adding, then be sure to + update those too. */ + +#if defined (__STDC__) \ + || defined (__cplusplus) \ + || defined (_AIX) \ + || defined (__DECC) \ + || (defined (__mips) && defined (_SYSTYPE_SVR4)) \ + || defined (_MSC_VER) \ + || defined (_WIN32) +#define __GMP_HAVE_CONST 1 +#define __GMP_HAVE_PROTOTYPES 1 +#define __GMP_HAVE_TOKEN_PASTE 1 +#else +#define __GMP_HAVE_CONST 0 +#define __GMP_HAVE_PROTOTYPES 0 +#define __GMP_HAVE_TOKEN_PASTE 0 +#endif + + +#if __GMP_HAVE_CONST +#define __gmp_const const +#define __gmp_signed signed +#else +#define __gmp_const +#define __gmp_signed +#endif + + +/* __GMP_DECLSPEC supports Windows DLL versions of libgmp, and is empty in + all other circumstances. + + When compiling objects for libgmp, __GMP_DECLSPEC is an export directive, + or when compiling for an application it's an import directive. The two + cases are differentiated by __GMP_WITHIN_GMP defined by the GMP Makefiles + (and not defined from an application). + + __GMP_DECLSPEC_XX is similarly used for libgmpxx. __GMP_WITHIN_GMPXX + indicates when building libgmpxx, and in that case libgmpxx functions are + exports, but libgmp functions which might get called are imports. + + libmp.la uses __GMP_DECLSPEC, just as if it were libgmp.la. libgmp and + libmp don't call each other, so there's no conflict or confusion. + + Libtool DLL_EXPORT define is not used. + + There's no attempt to support GMP built both static and DLL. Doing so + would mean applications would have to tell us which of the two is going + to be used when linking, and that seems very tedious and error prone if + using GMP by hand, and equally tedious from a package since autoconf and + automake don't give much help. + + __GMP_DECLSPEC is required on all documented global functions and + variables, the various internals in gmp-impl.h etc can be left unadorned. + But internals used by the test programs or speed measuring programs + should have __GMP_DECLSPEC, and certainly constants or variables must + have it or the wrong address will be resolved. + + In gcc __declspec can go at either the start or end of a prototype. + + In Microsoft C __declspec must go at the start, or after the type like + void __declspec(...) *foo()". There's no __dllexport or anything to + guard against someone foolish #defining dllexport. _export used to be + available, but no longer. + + In Borland C _export still exists, but needs to go after the type, like + "void _export foo();". Would have to change the __GMP_DECLSPEC syntax to + make use of that. Probably more trouble than it's worth. */ + +#if defined (__GNUC__) +#define __GMP_DECLSPEC_EXPORT __declspec(__dllexport__) +#define __GMP_DECLSPEC_IMPORT __declspec(__dllimport__) +#endif +#if defined (_MSC_VER) || defined (__BORLANDC__) +#define __GMP_DECLSPEC_EXPORT __declspec(dllexport) +#define __GMP_DECLSPEC_IMPORT __declspec(dllimport) +#endif +#ifdef __WATCOMC__ +#define __GMP_DECLSPEC_EXPORT __export +#define __GMP_DECLSPEC_IMPORT __import +#endif +#ifdef __IBMC__ +#define __GMP_DECLSPEC_EXPORT _Export +#define __GMP_DECLSPEC_IMPORT _Import +#endif + +#if __GMP_LIBGMP_DLL +#if __GMP_WITHIN_GMP +/* compiling to go into a DLL libgmp */ +#define __GMP_DECLSPEC __GMP_DECLSPEC_EXPORT +#else +/* compiling to go into an application which will link to a DLL libgmp */ +#define __GMP_DECLSPEC __GMP_DECLSPEC_IMPORT +#endif +#else +/* all other cases */ +#define __GMP_DECLSPEC +#endif + + +#ifdef __GMP_SHORT_LIMB +typedef unsigned int mp_limb_t; +typedef int mp_limb_signed_t; +#else +#ifdef _LONG_LONG_LIMB +typedef unsigned long long int mp_limb_t; +typedef long long int mp_limb_signed_t; +#else +typedef unsigned long int mp_limb_t; +typedef long int mp_limb_signed_t; +#endif +#endif + +/* For reference, note that the name __mpz_struct gets into C++ mangled + function names, which means although the "__" suggests an internal, we + must leave this name for binary compatibility. */ +typedef struct +{ + int _mp_alloc; /* Number of *limbs* allocated and pointed + to by the _mp_d field. */ + int _mp_size; /* abs(_mp_size) is the number of limbs the + last field points to. If _mp_size is + negative this is a negative number. */ + mp_limb_t *_mp_d; /* Pointer to the limbs. */ +} __mpz_struct; + +#endif /* __GNU_MP__ */ + + +typedef __mpz_struct MP_INT; /* gmp 1 source compatibility */ +typedef __mpz_struct mpz_t[1]; + +typedef mp_limb_t * mp_ptr; +typedef __gmp_const mp_limb_t * mp_srcptr; +#if defined (_CRAY) && ! defined (_CRAYMPP) +/* plain `int' is much faster (48 bits) */ +#define __GMP_MP_SIZE_T_INT 1 +typedef int mp_size_t; +typedef int mp_exp_t; +#else +#define __GMP_MP_SIZE_T_INT 0 +typedef long int mp_size_t; +typedef long int mp_exp_t; +#endif + +typedef struct +{ + __mpz_struct _mp_num; + __mpz_struct _mp_den; +} __mpq_struct; + +typedef __mpq_struct MP_RAT; /* gmp 1 source compatibility */ +typedef __mpq_struct mpq_t[1]; + +typedef struct +{ + int _mp_prec; /* Max precision, in number of `mp_limb_t's. + Set by mpf_init and modified by + mpf_set_prec. The area pointed to by the + _mp_d field contains `prec' + 1 limbs. */ + int _mp_size; /* abs(_mp_size) is the number of limbs the + last field points to. If _mp_size is + negative this is a negative number. */ + mp_exp_t _mp_exp; /* Exponent, in the base of `mp_limb_t'. */ + mp_limb_t *_mp_d; /* Pointer to the limbs. */ +} __mpf_struct; + +/* typedef __mpf_struct MP_FLOAT; */ +typedef __mpf_struct mpf_t[1]; + +/* Available random number generation algorithms. */ +typedef enum +{ + GMP_RAND_ALG_DEFAULT = 0, + GMP_RAND_ALG_LC = GMP_RAND_ALG_DEFAULT /* Linear congruential. */ +} gmp_randalg_t; + +/* Random state struct. */ +typedef struct +{ + mpz_t _mp_seed; /* _mp_d member points to state of the generator. */ + gmp_randalg_t _mp_alg; /* Currently unused. */ + union { + void *_mp_lc; /* Pointer to function pointers structure. */ + } _mp_algdata; +} __gmp_randstate_struct; +typedef __gmp_randstate_struct gmp_randstate_t[1]; + +/* Types for function declarations in gmp files. */ +/* ??? Should not pollute user name space with these ??? */ +typedef __gmp_const __mpz_struct *mpz_srcptr; +typedef __mpz_struct *mpz_ptr; +typedef __gmp_const __mpf_struct *mpf_srcptr; +typedef __mpf_struct *mpf_ptr; +typedef __gmp_const __mpq_struct *mpq_srcptr; +typedef __mpq_struct *mpq_ptr; + + +/* This is not wanted in mp.h, so put it outside the __GNU_MP__ common + section. */ +#if __GMP_LIBGMP_DLL +#if __GMP_WITHIN_GMPXX +/* compiling to go into a DLL libgmpxx */ +#define __GMP_DECLSPEC_XX __GMP_DECLSPEC_EXPORT +#else +/* compiling to go into a application which will link to a DLL libgmpxx */ +#define __GMP_DECLSPEC_XX __GMP_DECLSPEC_IMPORT +#endif +#else +/* all other cases */ +#define __GMP_DECLSPEC_XX +#endif + + +#if __GMP_HAVE_PROTOTYPES +#define __GMP_PROTO(x) x +#else +#define __GMP_PROTO(x) () +#endif + +#ifndef __MPN +#if __GMP_HAVE_TOKEN_PASTE +#define __MPN(x) __gmpn_##x +#else +#define __MPN(x) __gmpn_/**/x +#endif +#endif + +/* For reference, "defined(EOF)" cannot be used here. In g++ 2.95.4, + defines EOF but not FILE. */ +#if defined (FILE) \ + || defined (H_STDIO) \ + || defined (_H_STDIO) /* AIX */ \ + || defined (_STDIO_H) /* glibc, Sun, SCO */ \ + || defined (_STDIO_H_) /* BSD, OSF */ \ + || defined (__STDIO_H) /* Borland */ \ + || defined (__STDIO_H__) /* IRIX */ \ + || defined (_STDIO_INCLUDED) /* HPUX */ \ + || defined (__dj_include_stdio_h_) /* DJGPP */ \ + || defined (_FILE_DEFINED) /* Microsoft */ \ + || defined (__STDIO__) /* Apple MPW MrC */ \ + || defined (_MSL_STDIO_H) /* Metrowerks */ \ + || defined (_STDIO_H_INCLUDED) /* QNX4 */ \ + || defined (_ISO_STDIO_ISO_H) /* Sun C++ */ +#define _GMP_H_HAVE_FILE 1 +#endif + +/* In ISO C, if a prototype involving "struct obstack *" is given without + that structure defined, then the struct is scoped down to just the + prototype, causing a conflict if it's subsequently defined for real. So + only give prototypes if we've got obstack.h. */ +#if defined (_OBSTACK_H) /* glibc */ +#define _GMP_H_HAVE_OBSTACK 1 +#endif + +/* The prototypes for gmp_vprintf etc are provided only if va_list is + available, via an application having included or . + Usually va_list is a typedef so can't be tested directly, but C99 + specifies that va_start is a macro (and it was normally a macro on past + systems too), so look for that. + + will define some sort of va_list for vprintf and vfprintf, but + let's not bother trying to use that since it's not standard and since + application uses for gmp_vprintf etc will almost certainly require the + whole or anyway. */ + +#ifdef va_start +#define _GMP_H_HAVE_VA_LIST 1 +#endif + +/* Test for gcc >= maj.min, as per __GNUC_PREREQ in glibc */ +#if defined (__GNUC__) && defined (__GNUC_MINOR__) +#define __GMP_GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +#else +#define __GMP_GNUC_PREREQ(maj, min) 0 +#endif + +/* "pure" is in gcc 2.96 and up, see "(gcc)Function Attributes". Basically + it means a function does nothing but examine its arguments and memory + (global or via arguments) to generate a return value, but changes nothing + and has no side-effects. __GMP_NO_ATTRIBUTE_CONST_PURE lets + tune/common.c etc turn this off when trying to write timing loops. */ +#if __GMP_GNUC_PREREQ (2,96) && ! defined (__GMP_NO_ATTRIBUTE_CONST_PURE) +#define __GMP_ATTRIBUTE_PURE __attribute__ ((__pure__)) +#else +#define __GMP_ATTRIBUTE_PURE +#endif + + +/* __GMP_CAST allows us to use static_cast in C++, so our macros are clean + to "g++ -Wold-style-cast". + + Casts in "extern inline" code within an extern "C" block don't induce + these warnings, so __GMP_CAST only needs to be used on documented + macros. */ + +#ifdef __cplusplus +#define __GMP_CAST(type, expr) (static_cast (expr)) +#else +#define __GMP_CAST(type, expr) ((type) (expr)) +#endif + + +/* An empty "throw ()" means the function doesn't throw any C++ exceptions, + this can save some stack frame info in applications. + + Currently it's given only on functions which never divide-by-zero etc, + don't allocate memory, and are expected to never need to allocate memory. + This leaves open the possibility of a C++ throw from a future GMP + exceptions scheme. + + mpz_set_ui etc are omitted to leave open the lazy allocation scheme + described in doc/tasks.html. mpz_get_d etc are omitted to leave open + exceptions for float overflows. + + Note that __GMP_NOTHROW must be given on any inlines the same as on their + prototypes (for g++ at least, where they're used together). Note also + that g++ 3.0 demands that __GMP_NOTHROW is before other attributes like + __GMP_ATTRIBUTE_PURE. */ + +#if defined (__cplusplus) +#define __GMP_NOTHROW throw () +#else +#define __GMP_NOTHROW +#endif + + +/* PORTME: What other compilers have a useful "extern inline"? "static + inline" would be an acceptable substitute if the compiler (or linker) + discards unused statics. */ + + /* gcc has __inline__ in all modes, including strict ansi. Give a prototype + for an inline too, so as to correctly specify "dllimport" on windows, in + case the function is called rather than inlined. + GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 + inline semantics, unless -fgnu89-inline is used. */ +#ifdef __GNUC__ +#ifdef __GNUC_STDC_INLINE__ +#define __GMP_EXTERN_INLINE extern __inline__ __attribute__ ((__gnu_inline__)) +#else +#define __GMP_EXTERN_INLINE extern __inline__ +#endif +#define __GMP_INLINE_PROTOTYPES 1 +#endif + +/* DEC C (eg. version 5.9) supports "static __inline foo()", even in -std1 + strict ANSI mode. Inlining is done even when not optimizing (ie. -O0 + mode, which is the default), but an unnecessary local copy of foo is + emitted unless -O is used. "extern __inline" is accepted, but the + "extern" appears to be ignored, ie. it becomes a plain global function + but which is inlined within its file. Don't know if all old versions of + DEC C supported __inline, but as a start let's do the right thing for + current versions. */ +#ifdef __DECC +#define __GMP_EXTERN_INLINE static __inline +#endif + +/* SCO OpenUNIX 8 cc supports "static inline foo()" but not in -Xc strict + ANSI mode (__STDC__ is 1 in that mode). Inlining only actually takes + place under -O. Without -O "foo" seems to be emitted whether it's used + or not, which is wasteful. "extern inline foo()" isn't useful, the + "extern" is apparently ignored, so foo is inlined if possible but also + emitted as a global, which causes multiple definition errors when + building a shared libgmp. */ +#ifdef __SCO_VERSION__ +#if __SCO_VERSION__ > 400000000 && __STDC__ != 1 \ + && ! defined (__GMP_EXTERN_INLINE) +#define __GMP_EXTERN_INLINE static inline +#endif +#endif + +/* C++ always has "inline" and since it's a normal feature the linker should + discard duplicate non-inlined copies, or if it doesn't then that's a + problem for everyone, not just GMP. */ +#if defined (__cplusplus) && ! defined (__GMP_EXTERN_INLINE) +#define __GMP_EXTERN_INLINE inline +#endif + +/* Don't do any inlining within a configure run, since if the compiler ends + up emitting copies of the code into the object file it can end up + demanding the various support routines (like mpn_popcount) for linking, + making the "alloca" test and perhaps others fail. And on hppa ia64 a + pre-release gcc 3.2 was seen not respecting the "extern" in "extern + __inline__", triggering this problem too. */ +#if defined (__GMP_WITHIN_CONFIGURE) && ! __GMP_WITHIN_CONFIGURE_INLINE +#undef __GMP_EXTERN_INLINE +#endif + +/* By default, don't give a prototype when there's going to be an inline + version. Note in particular that Cray C++ objects to the combination of + prototype and inline. */ +#ifdef __GMP_EXTERN_INLINE +#ifndef __GMP_INLINE_PROTOTYPES +#define __GMP_INLINE_PROTOTYPES 0 +#endif +#else +#define __GMP_INLINE_PROTOTYPES 1 +#endif + + +#define __GMP_ABS(x) ((x) >= 0 ? (x) : -(x)) +#define __GMP_MAX(h,i) ((h) > (i) ? (h) : (i)) + +/* __GMP_USHRT_MAX is not "~ (unsigned short) 0" because short is promoted + to int by "~". */ +#define __GMP_UINT_MAX (~ (unsigned) 0) +#define __GMP_ULONG_MAX (~ (unsigned long) 0) +#define __GMP_USHRT_MAX ((unsigned short) ~0) + + +/* __builtin_expect is in gcc 3.0, and not in 2.95. */ +#if __GMP_GNUC_PREREQ (3,0) +#define __GMP_LIKELY(cond) __builtin_expect ((cond) != 0, 1) +#define __GMP_UNLIKELY(cond) __builtin_expect ((cond) != 0, 0) +#else +#define __GMP_LIKELY(cond) (cond) +#define __GMP_UNLIKELY(cond) (cond) +#endif + +#ifdef _CRAY +#define __GMP_CRAY_Pragma(str) _Pragma (str) +#else +#define __GMP_CRAY_Pragma(str) +#endif + + +/* Allow direct user access to numerator and denominator of a mpq_t object. */ +#define mpq_numref(Q) (&((Q)->_mp_num)) +#define mpq_denref(Q) (&((Q)->_mp_den)) + + +#if defined (__cplusplus) +extern "C" { +#ifdef _GMP_H_HAVE_FILE +using std::FILE; +#endif +#endif + +#define mp_set_memory_functions __gmp_set_memory_functions +__GMP_DECLSPEC void mp_set_memory_functions __GMP_PROTO ((void *(*) (size_t), + void *(*) (void *, size_t, size_t), + void (*) (void *, size_t))) __GMP_NOTHROW; + +#define mp_get_memory_functions __gmp_get_memory_functions +__GMP_DECLSPEC void mp_get_memory_functions __GMP_PROTO ((void *(**) (size_t), + void *(**) (void *, size_t, size_t), + void (**) (void *, size_t))) __GMP_NOTHROW; + +#define mp_bits_per_limb __gmp_bits_per_limb +__GMP_DECLSPEC extern __gmp_const int mp_bits_per_limb; + +#define gmp_errno __gmp_errno +__GMP_DECLSPEC extern int gmp_errno; + +#define gmp_version __gmp_version +__GMP_DECLSPEC extern __gmp_const char * __gmp_const gmp_version; + + +/**************** Random number routines. ****************/ + +/* obsolete */ +#define gmp_randinit __gmp_randinit +__GMP_DECLSPEC void gmp_randinit __GMP_PROTO ((gmp_randstate_t, gmp_randalg_t, ...)); + +#define gmp_randinit_default __gmp_randinit_default +__GMP_DECLSPEC void gmp_randinit_default __GMP_PROTO ((gmp_randstate_t)); + +#define gmp_randinit_lc_2exp __gmp_randinit_lc_2exp +__GMP_DECLSPEC void gmp_randinit_lc_2exp __GMP_PROTO ((gmp_randstate_t, + mpz_srcptr, unsigned long int, + unsigned long int)); + +#define gmp_randinit_lc_2exp_size __gmp_randinit_lc_2exp_size +__GMP_DECLSPEC int gmp_randinit_lc_2exp_size __GMP_PROTO ((gmp_randstate_t, unsigned long)); + +#define gmp_randinit_mt __gmp_randinit_mt +__GMP_DECLSPEC void gmp_randinit_mt __GMP_PROTO ((gmp_randstate_t)); + +#define gmp_randinit_set __gmp_randinit_set +void gmp_randinit_set __GMP_PROTO ((gmp_randstate_t, __gmp_const __gmp_randstate_struct *)); + +#define gmp_randseed __gmp_randseed +__GMP_DECLSPEC void gmp_randseed __GMP_PROTO ((gmp_randstate_t, mpz_srcptr)); + +#define gmp_randseed_ui __gmp_randseed_ui +__GMP_DECLSPEC void gmp_randseed_ui __GMP_PROTO ((gmp_randstate_t, unsigned long int)); + +#define gmp_randclear __gmp_randclear +__GMP_DECLSPEC void gmp_randclear __GMP_PROTO ((gmp_randstate_t)); + +#define gmp_urandomb_ui __gmp_urandomb_ui +unsigned long gmp_urandomb_ui __GMP_PROTO ((gmp_randstate_t, unsigned long)); + +#define gmp_urandomm_ui __gmp_urandomm_ui +unsigned long gmp_urandomm_ui __GMP_PROTO ((gmp_randstate_t, unsigned long)); + + +/**************** Formatted output routines. ****************/ + +#define gmp_asprintf __gmp_asprintf +__GMP_DECLSPEC int gmp_asprintf __GMP_PROTO ((char **, __gmp_const char *, ...)); + +#define gmp_fprintf __gmp_fprintf +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC int gmp_fprintf __GMP_PROTO ((FILE *, __gmp_const char *, ...)); +#endif + +#define gmp_obstack_printf __gmp_obstack_printf +#if defined (_GMP_H_HAVE_OBSTACK) +__GMP_DECLSPEC int gmp_obstack_printf __GMP_PROTO ((struct obstack *, __gmp_const char *, ...)); +#endif + +#define gmp_obstack_vprintf __gmp_obstack_vprintf +#if defined (_GMP_H_HAVE_OBSTACK) && defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_obstack_vprintf __GMP_PROTO ((struct obstack *, __gmp_const char *, va_list)); +#endif + +#define gmp_printf __gmp_printf +__GMP_DECLSPEC int gmp_printf __GMP_PROTO ((__gmp_const char *, ...)); + +#define gmp_snprintf __gmp_snprintf +__GMP_DECLSPEC int gmp_snprintf __GMP_PROTO ((char *, size_t, __gmp_const char *, ...)); + +#define gmp_sprintf __gmp_sprintf +__GMP_DECLSPEC int gmp_sprintf __GMP_PROTO ((char *, __gmp_const char *, ...)); + +#define gmp_vasprintf __gmp_vasprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vasprintf __GMP_PROTO ((char **, __gmp_const char *, va_list)); +#endif + +#define gmp_vfprintf __gmp_vfprintf +#if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vfprintf __GMP_PROTO ((FILE *, __gmp_const char *, va_list)); +#endif + +#define gmp_vprintf __gmp_vprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vprintf __GMP_PROTO ((__gmp_const char *, va_list)); +#endif + +#define gmp_vsnprintf __gmp_vsnprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vsnprintf __GMP_PROTO ((char *, size_t, __gmp_const char *, va_list)); +#endif + +#define gmp_vsprintf __gmp_vsprintf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vsprintf __GMP_PROTO ((char *, __gmp_const char *, va_list)); +#endif + + +/**************** Formatted input routines. ****************/ + +#define gmp_fscanf __gmp_fscanf +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC int gmp_fscanf __GMP_PROTO ((FILE *, __gmp_const char *, ...)); +#endif + +#define gmp_scanf __gmp_scanf +__GMP_DECLSPEC int gmp_scanf __GMP_PROTO ((__gmp_const char *, ...)); + +#define gmp_sscanf __gmp_sscanf +__GMP_DECLSPEC int gmp_sscanf __GMP_PROTO ((__gmp_const char *, __gmp_const char *, ...)); + +#define gmp_vfscanf __gmp_vfscanf +#if defined (_GMP_H_HAVE_FILE) && defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vfscanf __GMP_PROTO ((FILE *, __gmp_const char *, va_list)); +#endif + +#define gmp_vscanf __gmp_vscanf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vscanf __GMP_PROTO ((__gmp_const char *, va_list)); +#endif + +#define gmp_vsscanf __gmp_vsscanf +#if defined (_GMP_H_HAVE_VA_LIST) +__GMP_DECLSPEC int gmp_vsscanf __GMP_PROTO ((__gmp_const char *, __gmp_const char *, va_list)); +#endif + + +/**************** Integer (i.e. Z) routines. ****************/ + +#define _mpz_realloc __gmpz_realloc +#define mpz_realloc __gmpz_realloc +__GMP_DECLSPEC void *_mpz_realloc __GMP_PROTO ((mpz_ptr, mp_size_t)); + +#define mpz_abs __gmpz_abs +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_abs) +__GMP_DECLSPEC void mpz_abs __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#endif + +#define mpz_add __gmpz_add +__GMP_DECLSPEC void mpz_add __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_add_ui __gmpz_add_ui +__GMP_DECLSPEC void mpz_add_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_addmul __gmpz_addmul +__GMP_DECLSPEC void mpz_addmul __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_addmul_ui __gmpz_addmul_ui +__GMP_DECLSPEC void mpz_addmul_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_and __gmpz_and +__GMP_DECLSPEC void mpz_and __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_array_init __gmpz_array_init +__GMP_DECLSPEC void mpz_array_init __GMP_PROTO ((mpz_ptr, mp_size_t, mp_size_t)); + +#define mpz_bin_ui __gmpz_bin_ui +__GMP_DECLSPEC void mpz_bin_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_bin_uiui __gmpz_bin_uiui +__GMP_DECLSPEC void mpz_bin_uiui __GMP_PROTO ((mpz_ptr, unsigned long int, unsigned long int)); + +#define mpz_cdiv_q __gmpz_cdiv_q +__GMP_DECLSPEC void mpz_cdiv_q __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_cdiv_q_2exp __gmpz_cdiv_q_2exp +__GMP_DECLSPEC void mpz_cdiv_q_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long)); + +#define mpz_cdiv_q_ui __gmpz_cdiv_q_ui +__GMP_DECLSPEC unsigned long int mpz_cdiv_q_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_cdiv_qr __gmpz_cdiv_qr +__GMP_DECLSPEC void mpz_cdiv_qr __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_cdiv_qr_ui __gmpz_cdiv_qr_ui +__GMP_DECLSPEC unsigned long int mpz_cdiv_qr_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_cdiv_r __gmpz_cdiv_r +__GMP_DECLSPEC void mpz_cdiv_r __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_cdiv_r_2exp __gmpz_cdiv_r_2exp +__GMP_DECLSPEC void mpz_cdiv_r_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long)); + +#define mpz_cdiv_r_ui __gmpz_cdiv_r_ui +__GMP_DECLSPEC unsigned long int mpz_cdiv_r_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_cdiv_ui __gmpz_cdiv_ui +__GMP_DECLSPEC unsigned long int mpz_cdiv_ui __GMP_PROTO ((mpz_srcptr, unsigned long int)) __GMP_ATTRIBUTE_PURE; + +#define mpz_clear __gmpz_clear +__GMP_DECLSPEC void mpz_clear __GMP_PROTO ((mpz_ptr)); + +#define mpz_clrbit __gmpz_clrbit +__GMP_DECLSPEC void mpz_clrbit __GMP_PROTO ((mpz_ptr, unsigned long int)); + +#define mpz_cmp __gmpz_cmp +__GMP_DECLSPEC int mpz_cmp __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_cmp_d __gmpz_cmp_d +__GMP_DECLSPEC int mpz_cmp_d __GMP_PROTO ((mpz_srcptr, double)) __GMP_ATTRIBUTE_PURE; + +#define _mpz_cmp_si __gmpz_cmp_si +__GMP_DECLSPEC int _mpz_cmp_si __GMP_PROTO ((mpz_srcptr, signed long int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define _mpz_cmp_ui __gmpz_cmp_ui +__GMP_DECLSPEC int _mpz_cmp_ui __GMP_PROTO ((mpz_srcptr, unsigned long int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_cmpabs __gmpz_cmpabs +__GMP_DECLSPEC int mpz_cmpabs __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_cmpabs_d __gmpz_cmpabs_d +__GMP_DECLSPEC int mpz_cmpabs_d __GMP_PROTO ((mpz_srcptr, double)) __GMP_ATTRIBUTE_PURE; + +#define mpz_cmpabs_ui __gmpz_cmpabs_ui +__GMP_DECLSPEC int mpz_cmpabs_ui __GMP_PROTO ((mpz_srcptr, unsigned long int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_com __gmpz_com +__GMP_DECLSPEC void mpz_com __GMP_PROTO ((mpz_ptr, mpz_srcptr)); + +#define mpz_combit __gmpz_combit +__GMP_DECLSPEC void mpz_combit __GMP_PROTO ((mpz_ptr, unsigned long int)); + +#define mpz_congruent_p __gmpz_congruent_p +__GMP_DECLSPEC int mpz_congruent_p __GMP_PROTO ((mpz_srcptr, mpz_srcptr, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; + +#define mpz_congruent_2exp_p __gmpz_congruent_2exp_p +__GMP_DECLSPEC int mpz_congruent_2exp_p __GMP_PROTO ((mpz_srcptr, mpz_srcptr, unsigned long)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_congruent_ui_p __gmpz_congruent_ui_p +__GMP_DECLSPEC int mpz_congruent_ui_p __GMP_PROTO ((mpz_srcptr, unsigned long, unsigned long)) __GMP_ATTRIBUTE_PURE; + +#define mpz_divexact __gmpz_divexact +__GMP_DECLSPEC void mpz_divexact __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_divexact_ui __gmpz_divexact_ui +__GMP_DECLSPEC void mpz_divexact_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long)); + +#define mpz_divisible_p __gmpz_divisible_p +__GMP_DECLSPEC int mpz_divisible_p __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; + +#define mpz_divisible_ui_p __gmpz_divisible_ui_p +__GMP_DECLSPEC int mpz_divisible_ui_p __GMP_PROTO ((mpz_srcptr, unsigned long)) __GMP_ATTRIBUTE_PURE; + +#define mpz_divisible_2exp_p __gmpz_divisible_2exp_p +__GMP_DECLSPEC int mpz_divisible_2exp_p __GMP_PROTO ((mpz_srcptr, unsigned long)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_dump __gmpz_dump +__GMP_DECLSPEC void mpz_dump __GMP_PROTO ((mpz_srcptr)); + +#define mpz_export __gmpz_export +__GMP_DECLSPEC void *mpz_export __GMP_PROTO ((void *, size_t *, int, size_t, int, size_t, mpz_srcptr)); + +#define mpz_fac_ui __gmpz_fac_ui +__GMP_DECLSPEC void mpz_fac_ui __GMP_PROTO ((mpz_ptr, unsigned long int)); + +#define mpz_fdiv_q __gmpz_fdiv_q +__GMP_DECLSPEC void mpz_fdiv_q __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_fdiv_q_2exp __gmpz_fdiv_q_2exp +__GMP_DECLSPEC void mpz_fdiv_q_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_fdiv_q_ui __gmpz_fdiv_q_ui +__GMP_DECLSPEC unsigned long int mpz_fdiv_q_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_fdiv_qr __gmpz_fdiv_qr +__GMP_DECLSPEC void mpz_fdiv_qr __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_fdiv_qr_ui __gmpz_fdiv_qr_ui +__GMP_DECLSPEC unsigned long int mpz_fdiv_qr_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_fdiv_r __gmpz_fdiv_r +__GMP_DECLSPEC void mpz_fdiv_r __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_fdiv_r_2exp __gmpz_fdiv_r_2exp +__GMP_DECLSPEC void mpz_fdiv_r_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_fdiv_r_ui __gmpz_fdiv_r_ui +__GMP_DECLSPEC unsigned long int mpz_fdiv_r_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_fdiv_ui __gmpz_fdiv_ui +__GMP_DECLSPEC unsigned long int mpz_fdiv_ui __GMP_PROTO ((mpz_srcptr, unsigned long int)) __GMP_ATTRIBUTE_PURE; + +#define mpz_fib_ui __gmpz_fib_ui +__GMP_DECLSPEC void mpz_fib_ui __GMP_PROTO ((mpz_ptr, unsigned long int)); + +#define mpz_fib2_ui __gmpz_fib2_ui +__GMP_DECLSPEC void mpz_fib2_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, unsigned long int)); + +#define mpz_fits_sint_p __gmpz_fits_sint_p +__GMP_DECLSPEC int mpz_fits_sint_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_fits_slong_p __gmpz_fits_slong_p +__GMP_DECLSPEC int mpz_fits_slong_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_fits_sshort_p __gmpz_fits_sshort_p +__GMP_DECLSPEC int mpz_fits_sshort_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_fits_uint_p __gmpz_fits_uint_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_uint_p) +__GMP_DECLSPEC int mpz_fits_uint_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_fits_ulong_p __gmpz_fits_ulong_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ulong_p) +__GMP_DECLSPEC int mpz_fits_ulong_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_fits_ushort_p __gmpz_fits_ushort_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_fits_ushort_p) +__GMP_DECLSPEC int mpz_fits_ushort_p __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_gcd __gmpz_gcd +__GMP_DECLSPEC void mpz_gcd __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_gcd_ui __gmpz_gcd_ui +__GMP_DECLSPEC unsigned long int mpz_gcd_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_gcdext __gmpz_gcdext +__GMP_DECLSPEC void mpz_gcdext __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_get_d __gmpz_get_d +__GMP_DECLSPEC double mpz_get_d __GMP_PROTO ((mpz_srcptr)) __GMP_ATTRIBUTE_PURE; + +#define mpz_get_d_2exp __gmpz_get_d_2exp +__GMP_DECLSPEC double mpz_get_d_2exp __GMP_PROTO ((signed long int *, mpz_srcptr)); + +#define mpz_get_si __gmpz_get_si +__GMP_DECLSPEC /* signed */ long int mpz_get_si __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_get_str __gmpz_get_str +__GMP_DECLSPEC char *mpz_get_str __GMP_PROTO ((char *, int, mpz_srcptr)); + +#define mpz_get_ui __gmpz_get_ui +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_get_ui) +__GMP_DECLSPEC unsigned long int mpz_get_ui __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_getlimbn __gmpz_getlimbn +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_getlimbn) +__GMP_DECLSPEC mp_limb_t mpz_getlimbn __GMP_PROTO ((mpz_srcptr, mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_hamdist __gmpz_hamdist +__GMP_DECLSPEC unsigned long int mpz_hamdist __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_import __gmpz_import +__GMP_DECLSPEC void mpz_import __GMP_PROTO ((mpz_ptr, size_t, int, size_t, int, size_t, __gmp_const void *)); + +#define mpz_init __gmpz_init +__GMP_DECLSPEC void mpz_init __GMP_PROTO ((mpz_ptr)); + +#define mpz_init2 __gmpz_init2 +__GMP_DECLSPEC void mpz_init2 __GMP_PROTO ((mpz_ptr, unsigned long)); + +#define mpz_init_set __gmpz_init_set +__GMP_DECLSPEC void mpz_init_set __GMP_PROTO ((mpz_ptr, mpz_srcptr)); + +#define mpz_init_set_d __gmpz_init_set_d +__GMP_DECLSPEC void mpz_init_set_d __GMP_PROTO ((mpz_ptr, double)); + +#define mpz_init_set_si __gmpz_init_set_si +__GMP_DECLSPEC void mpz_init_set_si __GMP_PROTO ((mpz_ptr, signed long int)); + +#define mpz_init_set_str __gmpz_init_set_str +__GMP_DECLSPEC int mpz_init_set_str __GMP_PROTO ((mpz_ptr, __gmp_const char *, int)); + +#define mpz_init_set_ui __gmpz_init_set_ui +__GMP_DECLSPEC void mpz_init_set_ui __GMP_PROTO ((mpz_ptr, unsigned long int)); + +#define mpz_inp_raw __gmpz_inp_raw +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_inp_raw __GMP_PROTO ((mpz_ptr, FILE *)); +#endif + +#define mpz_inp_str __gmpz_inp_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_inp_str __GMP_PROTO ((mpz_ptr, FILE *, int)); +#endif + +#define mpz_invert __gmpz_invert +__GMP_DECLSPEC int mpz_invert __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_ior __gmpz_ior +__GMP_DECLSPEC void mpz_ior __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_jacobi __gmpz_jacobi +__GMP_DECLSPEC int mpz_jacobi __GMP_PROTO ((mpz_srcptr, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; + +#define mpz_kronecker mpz_jacobi /* alias */ + +#define mpz_kronecker_si __gmpz_kronecker_si +__GMP_DECLSPEC int mpz_kronecker_si __GMP_PROTO ((mpz_srcptr, long)) __GMP_ATTRIBUTE_PURE; + +#define mpz_kronecker_ui __gmpz_kronecker_ui +__GMP_DECLSPEC int mpz_kronecker_ui __GMP_PROTO ((mpz_srcptr, unsigned long)) __GMP_ATTRIBUTE_PURE; + +#define mpz_si_kronecker __gmpz_si_kronecker +__GMP_DECLSPEC int mpz_si_kronecker __GMP_PROTO ((long, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; + +#define mpz_ui_kronecker __gmpz_ui_kronecker +__GMP_DECLSPEC int mpz_ui_kronecker __GMP_PROTO ((unsigned long, mpz_srcptr)) __GMP_ATTRIBUTE_PURE; + +#define mpz_lcm __gmpz_lcm +__GMP_DECLSPEC void mpz_lcm __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_lcm_ui __gmpz_lcm_ui +__GMP_DECLSPEC void mpz_lcm_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long)); + +#define mpz_legendre mpz_jacobi /* alias */ + +#define mpz_lucnum_ui __gmpz_lucnum_ui +__GMP_DECLSPEC void mpz_lucnum_ui __GMP_PROTO ((mpz_ptr, unsigned long int)); + +#define mpz_lucnum2_ui __gmpz_lucnum2_ui +__GMP_DECLSPEC void mpz_lucnum2_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, unsigned long int)); + +#define mpz_millerrabin __gmpz_millerrabin +__GMP_DECLSPEC int mpz_millerrabin __GMP_PROTO ((mpz_srcptr, int)) __GMP_ATTRIBUTE_PURE; + +#define mpz_mod __gmpz_mod +__GMP_DECLSPEC void mpz_mod __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_mod_ui mpz_fdiv_r_ui /* same as fdiv_r because divisor unsigned */ + +#define mpz_mul __gmpz_mul +__GMP_DECLSPEC void mpz_mul __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_mul_2exp __gmpz_mul_2exp +__GMP_DECLSPEC void mpz_mul_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_mul_si __gmpz_mul_si +__GMP_DECLSPEC void mpz_mul_si __GMP_PROTO ((mpz_ptr, mpz_srcptr, long int)); + +#define mpz_mul_ui __gmpz_mul_ui +__GMP_DECLSPEC void mpz_mul_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_neg __gmpz_neg +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_neg) +__GMP_DECLSPEC void mpz_neg __GMP_PROTO ((mpz_ptr, mpz_srcptr)); +#endif + +#define mpz_nextprime __gmpz_nextprime +__GMP_DECLSPEC void mpz_nextprime __GMP_PROTO ((mpz_ptr, mpz_srcptr)); + +#define mpz_out_raw __gmpz_out_raw +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_out_raw __GMP_PROTO ((FILE *, mpz_srcptr)); +#endif + +#define mpz_out_str __gmpz_out_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpz_out_str __GMP_PROTO ((FILE *, int, mpz_srcptr)); +#endif + +#define mpz_perfect_power_p __gmpz_perfect_power_p +__GMP_DECLSPEC int mpz_perfect_power_p __GMP_PROTO ((mpz_srcptr)) __GMP_ATTRIBUTE_PURE; + +#define mpz_perfect_square_p __gmpz_perfect_square_p +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_perfect_square_p) +__GMP_DECLSPEC int mpz_perfect_square_p __GMP_PROTO ((mpz_srcptr)) __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_popcount __gmpz_popcount +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_popcount) +__GMP_DECLSPEC unsigned long int mpz_popcount __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_pow_ui __gmpz_pow_ui +__GMP_DECLSPEC void mpz_pow_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_powm __gmpz_powm +__GMP_DECLSPEC void mpz_powm __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_powm_ui __gmpz_powm_ui +__GMP_DECLSPEC void mpz_powm_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int, mpz_srcptr)); + +#define mpz_probab_prime_p __gmpz_probab_prime_p +__GMP_DECLSPEC int mpz_probab_prime_p __GMP_PROTO ((mpz_srcptr, int)) __GMP_ATTRIBUTE_PURE; + +#define mpz_random __gmpz_random +__GMP_DECLSPEC void mpz_random __GMP_PROTO ((mpz_ptr, mp_size_t)); + +#define mpz_random2 __gmpz_random2 +__GMP_DECLSPEC void mpz_random2 __GMP_PROTO ((mpz_ptr, mp_size_t)); + +#define mpz_realloc2 __gmpz_realloc2 +__GMP_DECLSPEC void mpz_realloc2 __GMP_PROTO ((mpz_ptr, unsigned long)); + +#define mpz_remove __gmpz_remove +__GMP_DECLSPEC unsigned long int mpz_remove __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_root __gmpz_root +__GMP_DECLSPEC int mpz_root __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_rootrem __gmpz_rootrem +__GMP_DECLSPEC void mpz_rootrem __GMP_PROTO ((mpz_ptr,mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_rrandomb __gmpz_rrandomb +__GMP_DECLSPEC void mpz_rrandomb __GMP_PROTO ((mpz_ptr, gmp_randstate_t, unsigned long int)); + +#define mpz_scan0 __gmpz_scan0 +__GMP_DECLSPEC unsigned long int mpz_scan0 __GMP_PROTO ((mpz_srcptr, unsigned long int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_scan1 __gmpz_scan1 +__GMP_DECLSPEC unsigned long int mpz_scan1 __GMP_PROTO ((mpz_srcptr, unsigned long int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_set __gmpz_set +__GMP_DECLSPEC void mpz_set __GMP_PROTO ((mpz_ptr, mpz_srcptr)); + +#define mpz_set_d __gmpz_set_d +__GMP_DECLSPEC void mpz_set_d __GMP_PROTO ((mpz_ptr, double)); + +#define mpz_set_f __gmpz_set_f +__GMP_DECLSPEC void mpz_set_f __GMP_PROTO ((mpz_ptr, mpf_srcptr)); + +#define mpz_set_q __gmpz_set_q +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_set_q) +__GMP_DECLSPEC void mpz_set_q __GMP_PROTO ((mpz_ptr, mpq_srcptr)); +#endif + +#define mpz_set_si __gmpz_set_si +__GMP_DECLSPEC void mpz_set_si __GMP_PROTO ((mpz_ptr, signed long int)); + +#define mpz_set_str __gmpz_set_str +__GMP_DECLSPEC int mpz_set_str __GMP_PROTO ((mpz_ptr, __gmp_const char *, int)); + +#define mpz_set_ui __gmpz_set_ui +__GMP_DECLSPEC void mpz_set_ui __GMP_PROTO ((mpz_ptr, unsigned long int)); + +#define mpz_setbit __gmpz_setbit +__GMP_DECLSPEC void mpz_setbit __GMP_PROTO ((mpz_ptr, unsigned long int)); + +#define mpz_size __gmpz_size +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpz_size) +__GMP_DECLSPEC size_t mpz_size __GMP_PROTO ((mpz_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpz_sizeinbase __gmpz_sizeinbase +__GMP_DECLSPEC size_t mpz_sizeinbase __GMP_PROTO ((mpz_srcptr, int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_sqrt __gmpz_sqrt +__GMP_DECLSPEC void mpz_sqrt __GMP_PROTO ((mpz_ptr, mpz_srcptr)); + +#define mpz_sqrtrem __gmpz_sqrtrem +__GMP_DECLSPEC void mpz_sqrtrem __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr)); + +#define mpz_sub __gmpz_sub +__GMP_DECLSPEC void mpz_sub __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_sub_ui __gmpz_sub_ui +__GMP_DECLSPEC void mpz_sub_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_ui_sub __gmpz_ui_sub +__GMP_DECLSPEC void mpz_ui_sub __GMP_PROTO ((mpz_ptr, unsigned long int, mpz_srcptr)); + +#define mpz_submul __gmpz_submul +__GMP_DECLSPEC void mpz_submul __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_submul_ui __gmpz_submul_ui +__GMP_DECLSPEC void mpz_submul_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_swap __gmpz_swap +__GMP_DECLSPEC void mpz_swap __GMP_PROTO ((mpz_ptr, mpz_ptr)) __GMP_NOTHROW; + +#define mpz_tdiv_ui __gmpz_tdiv_ui +__GMP_DECLSPEC unsigned long int mpz_tdiv_ui __GMP_PROTO ((mpz_srcptr, unsigned long int)) __GMP_ATTRIBUTE_PURE; + +#define mpz_tdiv_q __gmpz_tdiv_q +__GMP_DECLSPEC void mpz_tdiv_q __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_tdiv_q_2exp __gmpz_tdiv_q_2exp +__GMP_DECLSPEC void mpz_tdiv_q_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_tdiv_q_ui __gmpz_tdiv_q_ui +__GMP_DECLSPEC unsigned long int mpz_tdiv_q_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_tdiv_qr __gmpz_tdiv_qr +__GMP_DECLSPEC void mpz_tdiv_qr __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_tdiv_qr_ui __gmpz_tdiv_qr_ui +__GMP_DECLSPEC unsigned long int mpz_tdiv_qr_ui __GMP_PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_tdiv_r __gmpz_tdiv_r +__GMP_DECLSPEC void mpz_tdiv_r __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + +#define mpz_tdiv_r_2exp __gmpz_tdiv_r_2exp +__GMP_DECLSPEC void mpz_tdiv_r_2exp __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_tdiv_r_ui __gmpz_tdiv_r_ui +__GMP_DECLSPEC unsigned long int mpz_tdiv_r_ui __GMP_PROTO ((mpz_ptr, mpz_srcptr, unsigned long int)); + +#define mpz_tstbit __gmpz_tstbit +__GMP_DECLSPEC int mpz_tstbit __GMP_PROTO ((mpz_srcptr, unsigned long int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpz_ui_pow_ui __gmpz_ui_pow_ui +__GMP_DECLSPEC void mpz_ui_pow_ui __GMP_PROTO ((mpz_ptr, unsigned long int, unsigned long int)); + +#define mpz_urandomb __gmpz_urandomb +__GMP_DECLSPEC void mpz_urandomb __GMP_PROTO ((mpz_ptr, gmp_randstate_t, unsigned long int)); + +#define mpz_urandomm __gmpz_urandomm +__GMP_DECLSPEC void mpz_urandomm __GMP_PROTO ((mpz_ptr, gmp_randstate_t, mpz_srcptr)); + +#define mpz_xor __gmpz_xor +#define mpz_eor __gmpz_xor +__GMP_DECLSPEC void mpz_xor __GMP_PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr)); + + +/**************** Rational (i.e. Q) routines. ****************/ + +#define mpq_abs __gmpq_abs +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_abs) +__GMP_DECLSPEC void mpq_abs __GMP_PROTO ((mpq_ptr, mpq_srcptr)); +#endif + +#define mpq_add __gmpq_add +__GMP_DECLSPEC void mpq_add __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); + +#define mpq_canonicalize __gmpq_canonicalize +__GMP_DECLSPEC void mpq_canonicalize __GMP_PROTO ((mpq_ptr)); + +#define mpq_clear __gmpq_clear +__GMP_DECLSPEC void mpq_clear __GMP_PROTO ((mpq_ptr)); + +#define mpq_cmp __gmpq_cmp +__GMP_DECLSPEC int mpq_cmp __GMP_PROTO ((mpq_srcptr, mpq_srcptr)) __GMP_ATTRIBUTE_PURE; + +#define _mpq_cmp_si __gmpq_cmp_si +__GMP_DECLSPEC int _mpq_cmp_si __GMP_PROTO ((mpq_srcptr, long, unsigned long)) __GMP_ATTRIBUTE_PURE; + +#define _mpq_cmp_ui __gmpq_cmp_ui +__GMP_DECLSPEC int _mpq_cmp_ui __GMP_PROTO ((mpq_srcptr, unsigned long int, unsigned long int)) __GMP_ATTRIBUTE_PURE; + +#define mpq_div __gmpq_div +__GMP_DECLSPEC void mpq_div __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); + +#define mpq_div_2exp __gmpq_div_2exp +__GMP_DECLSPEC void mpq_div_2exp __GMP_PROTO ((mpq_ptr, mpq_srcptr, unsigned long)); + +#define mpq_equal __gmpq_equal +__GMP_DECLSPEC int mpq_equal __GMP_PROTO ((mpq_srcptr, mpq_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpq_get_num __gmpq_get_num +__GMP_DECLSPEC void mpq_get_num __GMP_PROTO ((mpz_ptr, mpq_srcptr)); + +#define mpq_get_den __gmpq_get_den +__GMP_DECLSPEC void mpq_get_den __GMP_PROTO ((mpz_ptr, mpq_srcptr)); + +#define mpq_get_d __gmpq_get_d +__GMP_DECLSPEC double mpq_get_d __GMP_PROTO ((mpq_srcptr)) __GMP_ATTRIBUTE_PURE; + +#define mpq_get_str __gmpq_get_str +__GMP_DECLSPEC char *mpq_get_str __GMP_PROTO ((char *, int, mpq_srcptr)); + +#define mpq_init __gmpq_init +__GMP_DECLSPEC void mpq_init __GMP_PROTO ((mpq_ptr)); + +#define mpq_inp_str __gmpq_inp_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpq_inp_str __GMP_PROTO ((mpq_ptr, FILE *, int)); +#endif + +#define mpq_inv __gmpq_inv +__GMP_DECLSPEC void mpq_inv __GMP_PROTO ((mpq_ptr, mpq_srcptr)); + +#define mpq_mul __gmpq_mul +__GMP_DECLSPEC void mpq_mul __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); + +#define mpq_mul_2exp __gmpq_mul_2exp +__GMP_DECLSPEC void mpq_mul_2exp __GMP_PROTO ((mpq_ptr, mpq_srcptr, unsigned long)); + +#define mpq_neg __gmpq_neg +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpq_neg) +__GMP_DECLSPEC void mpq_neg __GMP_PROTO ((mpq_ptr, mpq_srcptr)); +#endif + +#define mpq_out_str __gmpq_out_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpq_out_str __GMP_PROTO ((FILE *, int, mpq_srcptr)); +#endif + +#define mpq_set __gmpq_set +__GMP_DECLSPEC void mpq_set __GMP_PROTO ((mpq_ptr, mpq_srcptr)); + +#define mpq_set_d __gmpq_set_d +__GMP_DECLSPEC void mpq_set_d __GMP_PROTO ((mpq_ptr, double)); + +#define mpq_set_den __gmpq_set_den +__GMP_DECLSPEC void mpq_set_den __GMP_PROTO ((mpq_ptr, mpz_srcptr)); + +#define mpq_set_f __gmpq_set_f +__GMP_DECLSPEC void mpq_set_f __GMP_PROTO ((mpq_ptr, mpf_srcptr)); + +#define mpq_set_num __gmpq_set_num +__GMP_DECLSPEC void mpq_set_num __GMP_PROTO ((mpq_ptr, mpz_srcptr)); + +#define mpq_set_si __gmpq_set_si +__GMP_DECLSPEC void mpq_set_si __GMP_PROTO ((mpq_ptr, signed long int, unsigned long int)); + +#define mpq_set_str __gmpq_set_str +__GMP_DECLSPEC int mpq_set_str __GMP_PROTO ((mpq_ptr, __gmp_const char *, int)); + +#define mpq_set_ui __gmpq_set_ui +__GMP_DECLSPEC void mpq_set_ui __GMP_PROTO ((mpq_ptr, unsigned long int, unsigned long int)); + +#define mpq_set_z __gmpq_set_z +__GMP_DECLSPEC void mpq_set_z __GMP_PROTO ((mpq_ptr, mpz_srcptr)); + +#define mpq_sub __gmpq_sub +__GMP_DECLSPEC void mpq_sub __GMP_PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr)); + +#define mpq_swap __gmpq_swap +__GMP_DECLSPEC void mpq_swap __GMP_PROTO ((mpq_ptr, mpq_ptr)) __GMP_NOTHROW; + + +/**************** Float (i.e. F) routines. ****************/ + +#define mpf_abs __gmpf_abs +__GMP_DECLSPEC void mpf_abs __GMP_PROTO ((mpf_ptr, mpf_srcptr)); + +#define mpf_add __gmpf_add +__GMP_DECLSPEC void mpf_add __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); + +#define mpf_add_ui __gmpf_add_ui +__GMP_DECLSPEC void mpf_add_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned long int)); +#define mpf_ceil __gmpf_ceil +__GMP_DECLSPEC void mpf_ceil __GMP_PROTO ((mpf_ptr, mpf_srcptr)); + +#define mpf_clear __gmpf_clear +__GMP_DECLSPEC void mpf_clear __GMP_PROTO ((mpf_ptr)); + +#define mpf_cmp __gmpf_cmp +__GMP_DECLSPEC int mpf_cmp __GMP_PROTO ((mpf_srcptr, mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_cmp_d __gmpf_cmp_d +__GMP_DECLSPEC int mpf_cmp_d __GMP_PROTO ((mpf_srcptr, double)) __GMP_ATTRIBUTE_PURE; + +#define mpf_cmp_si __gmpf_cmp_si +__GMP_DECLSPEC int mpf_cmp_si __GMP_PROTO ((mpf_srcptr, signed long int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_cmp_ui __gmpf_cmp_ui +__GMP_DECLSPEC int mpf_cmp_ui __GMP_PROTO ((mpf_srcptr, unsigned long int)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_div __gmpf_div +__GMP_DECLSPEC void mpf_div __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); + +#define mpf_div_2exp __gmpf_div_2exp +__GMP_DECLSPEC void mpf_div_2exp __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned long int)); + +#define mpf_div_ui __gmpf_div_ui +__GMP_DECLSPEC void mpf_div_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned long int)); + +#define mpf_dump __gmpf_dump +__GMP_DECLSPEC void mpf_dump __GMP_PROTO ((mpf_srcptr)); + +#define mpf_eq __gmpf_eq +__GMP_DECLSPEC int mpf_eq __GMP_PROTO ((mpf_srcptr, mpf_srcptr, unsigned long int)) __GMP_ATTRIBUTE_PURE; + +#define mpf_fits_sint_p __gmpf_fits_sint_p +__GMP_DECLSPEC int mpf_fits_sint_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_fits_slong_p __gmpf_fits_slong_p +__GMP_DECLSPEC int mpf_fits_slong_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_fits_sshort_p __gmpf_fits_sshort_p +__GMP_DECLSPEC int mpf_fits_sshort_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_fits_uint_p __gmpf_fits_uint_p +__GMP_DECLSPEC int mpf_fits_uint_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_fits_ulong_p __gmpf_fits_ulong_p +__GMP_DECLSPEC int mpf_fits_ulong_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_fits_ushort_p __gmpf_fits_ushort_p +__GMP_DECLSPEC int mpf_fits_ushort_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_floor __gmpf_floor +__GMP_DECLSPEC void mpf_floor __GMP_PROTO ((mpf_ptr, mpf_srcptr)); + +#define mpf_get_d __gmpf_get_d +__GMP_DECLSPEC double mpf_get_d __GMP_PROTO ((mpf_srcptr)) __GMP_ATTRIBUTE_PURE; + +#define mpf_get_d_2exp __gmpf_get_d_2exp +__GMP_DECLSPEC double mpf_get_d_2exp __GMP_PROTO ((signed long int *, mpf_srcptr)); + +#define mpf_get_default_prec __gmpf_get_default_prec +__GMP_DECLSPEC unsigned long int mpf_get_default_prec __GMP_PROTO ((void)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_get_prec __gmpf_get_prec +__GMP_DECLSPEC unsigned long int mpf_get_prec __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_get_si __gmpf_get_si +__GMP_DECLSPEC long mpf_get_si __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_get_str __gmpf_get_str +__GMP_DECLSPEC char *mpf_get_str __GMP_PROTO ((char *, mp_exp_t *, int, size_t, mpf_srcptr)); + +#define mpf_get_ui __gmpf_get_ui +__GMP_DECLSPEC unsigned long mpf_get_ui __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_init __gmpf_init +__GMP_DECLSPEC void mpf_init __GMP_PROTO ((mpf_ptr)); + +#define mpf_init2 __gmpf_init2 +__GMP_DECLSPEC void mpf_init2 __GMP_PROTO ((mpf_ptr, unsigned long int)); + +#define mpf_init_set __gmpf_init_set +__GMP_DECLSPEC void mpf_init_set __GMP_PROTO ((mpf_ptr, mpf_srcptr)); + +#define mpf_init_set_d __gmpf_init_set_d +__GMP_DECLSPEC void mpf_init_set_d __GMP_PROTO ((mpf_ptr, double)); + +#define mpf_init_set_si __gmpf_init_set_si +__GMP_DECLSPEC void mpf_init_set_si __GMP_PROTO ((mpf_ptr, signed long int)); + +#define mpf_init_set_str __gmpf_init_set_str +__GMP_DECLSPEC int mpf_init_set_str __GMP_PROTO ((mpf_ptr, __gmp_const char *, int)); + +#define mpf_init_set_ui __gmpf_init_set_ui +__GMP_DECLSPEC void mpf_init_set_ui __GMP_PROTO ((mpf_ptr, unsigned long int)); + +#define mpf_inp_str __gmpf_inp_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpf_inp_str __GMP_PROTO ((mpf_ptr, FILE *, int)); +#endif + +#define mpf_integer_p __gmpf_integer_p +__GMP_DECLSPEC int mpf_integer_p __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_mul __gmpf_mul +__GMP_DECLSPEC void mpf_mul __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); + +#define mpf_mul_2exp __gmpf_mul_2exp +__GMP_DECLSPEC void mpf_mul_2exp __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned long int)); + +#define mpf_mul_ui __gmpf_mul_ui +__GMP_DECLSPEC void mpf_mul_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned long int)); + +#define mpf_neg __gmpf_neg +__GMP_DECLSPEC void mpf_neg __GMP_PROTO ((mpf_ptr, mpf_srcptr)); + +#define mpf_out_str __gmpf_out_str +#ifdef _GMP_H_HAVE_FILE +__GMP_DECLSPEC size_t mpf_out_str __GMP_PROTO ((FILE *, int, size_t, mpf_srcptr)); +#endif + +#define mpf_pow_ui __gmpf_pow_ui +__GMP_DECLSPEC void mpf_pow_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned long int)); + +#define mpf_random2 __gmpf_random2 +__GMP_DECLSPEC void mpf_random2 __GMP_PROTO ((mpf_ptr, mp_size_t, mp_exp_t)); + +#define mpf_reldiff __gmpf_reldiff +__GMP_DECLSPEC void mpf_reldiff __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); + +#define mpf_set __gmpf_set +__GMP_DECLSPEC void mpf_set __GMP_PROTO ((mpf_ptr, mpf_srcptr)); + +#define mpf_set_d __gmpf_set_d +__GMP_DECLSPEC void mpf_set_d __GMP_PROTO ((mpf_ptr, double)); + +#define mpf_set_default_prec __gmpf_set_default_prec +__GMP_DECLSPEC void mpf_set_default_prec __GMP_PROTO ((unsigned long int)) __GMP_NOTHROW; + +#define mpf_set_prec __gmpf_set_prec +__GMP_DECLSPEC void mpf_set_prec __GMP_PROTO ((mpf_ptr, unsigned long int)); + +#define mpf_set_prec_raw __gmpf_set_prec_raw +__GMP_DECLSPEC void mpf_set_prec_raw __GMP_PROTO ((mpf_ptr, unsigned long int)) __GMP_NOTHROW; + +#define mpf_set_q __gmpf_set_q +__GMP_DECLSPEC void mpf_set_q __GMP_PROTO ((mpf_ptr, mpq_srcptr)); + +#define mpf_set_si __gmpf_set_si +__GMP_DECLSPEC void mpf_set_si __GMP_PROTO ((mpf_ptr, signed long int)); + +#define mpf_set_str __gmpf_set_str +__GMP_DECLSPEC int mpf_set_str __GMP_PROTO ((mpf_ptr, __gmp_const char *, int)); + +#define mpf_set_ui __gmpf_set_ui +__GMP_DECLSPEC void mpf_set_ui __GMP_PROTO ((mpf_ptr, unsigned long int)); + +#define mpf_set_z __gmpf_set_z +__GMP_DECLSPEC void mpf_set_z __GMP_PROTO ((mpf_ptr, mpz_srcptr)); + +#define mpf_size __gmpf_size +__GMP_DECLSPEC size_t mpf_size __GMP_PROTO ((mpf_srcptr)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpf_sqrt __gmpf_sqrt +__GMP_DECLSPEC void mpf_sqrt __GMP_PROTO ((mpf_ptr, mpf_srcptr)); + +#define mpf_sqrt_ui __gmpf_sqrt_ui +__GMP_DECLSPEC void mpf_sqrt_ui __GMP_PROTO ((mpf_ptr, unsigned long int)); + +#define mpf_sub __gmpf_sub +__GMP_DECLSPEC void mpf_sub __GMP_PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr)); + +#define mpf_sub_ui __gmpf_sub_ui +__GMP_DECLSPEC void mpf_sub_ui __GMP_PROTO ((mpf_ptr, mpf_srcptr, unsigned long int)); + +#define mpf_swap __gmpf_swap +__GMP_DECLSPEC void mpf_swap __GMP_PROTO ((mpf_ptr, mpf_ptr)) __GMP_NOTHROW; + +#define mpf_trunc __gmpf_trunc +__GMP_DECLSPEC void mpf_trunc __GMP_PROTO ((mpf_ptr, mpf_srcptr)); + +#define mpf_ui_div __gmpf_ui_div +__GMP_DECLSPEC void mpf_ui_div __GMP_PROTO ((mpf_ptr, unsigned long int, mpf_srcptr)); + +#define mpf_ui_sub __gmpf_ui_sub +__GMP_DECLSPEC void mpf_ui_sub __GMP_PROTO ((mpf_ptr, unsigned long int, mpf_srcptr)); + +#define mpf_urandomb __gmpf_urandomb +__GMP_DECLSPEC void mpf_urandomb __GMP_PROTO ((mpf_t, gmp_randstate_t, unsigned long int)); + + +/************ Low level positive-integer (i.e. N) routines. ************/ + +/* This is ugly, but we need to make user calls reach the prefixed function. */ + +#define mpn_add __MPN(add) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add) +__GMP_DECLSPEC mp_limb_t mpn_add __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t)); +#endif + +#define mpn_add_1 __MPN(add_1) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_add_1) +__GMP_DECLSPEC mp_limb_t mpn_add_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) __GMP_NOTHROW; +#endif + +#define mpn_add_n __MPN(add_n) +__GMP_DECLSPEC mp_limb_t mpn_add_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); + +#define mpn_addmul_1 __MPN(addmul_1) +__GMP_DECLSPEC mp_limb_t mpn_addmul_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); + +#define mpn_bdivmod __MPN(bdivmod) +__GMP_DECLSPEC mp_limb_t mpn_bdivmod __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, unsigned long int)); + +#define mpn_cmp __MPN(cmp) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_cmp) +__GMP_DECLSPEC int mpn_cmp __GMP_PROTO ((mp_srcptr, mp_srcptr, mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; +#endif + +#define mpn_divexact_by3(dst,src,size) \ + mpn_divexact_by3c (dst, src, size, __GMP_CAST (mp_limb_t, 0)) + +#define mpn_divexact_by3c __MPN(divexact_by3c) +__GMP_DECLSPEC mp_limb_t mpn_divexact_by3c __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); + +#define mpn_divmod_1(qp,np,nsize,dlimb) \ + mpn_divrem_1 (qp, __GMP_CAST (mp_size_t, 0), np, nsize, dlimb) + +#define mpn_divrem __MPN(divrem) +__GMP_DECLSPEC mp_limb_t mpn_divrem __GMP_PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t)); + +#define mpn_divrem_1 __MPN(divrem_1) +__GMP_DECLSPEC mp_limb_t mpn_divrem_1 __GMP_PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t)); + +#define mpn_divrem_2 __MPN(divrem_2) +__GMP_DECLSPEC mp_limb_t mpn_divrem_2 __GMP_PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr)); + +#define mpn_gcd __MPN(gcd) +__GMP_DECLSPEC mp_size_t mpn_gcd __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t)); + +#define mpn_gcd_1 __MPN(gcd_1) +__GMP_DECLSPEC mp_limb_t mpn_gcd_1 __GMP_PROTO ((mp_srcptr, mp_size_t, mp_limb_t)) __GMP_ATTRIBUTE_PURE; + +#define mpn_gcdext __MPN(gcdext) +__GMP_DECLSPEC mp_size_t mpn_gcdext __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t *, mp_ptr, mp_size_t, mp_ptr, mp_size_t)); + +#define mpn_get_str __MPN(get_str) +__GMP_DECLSPEC size_t mpn_get_str __GMP_PROTO ((unsigned char *, int, mp_ptr, mp_size_t)); + +#define mpn_hamdist __MPN(hamdist) +__GMP_DECLSPEC unsigned long int mpn_hamdist __GMP_PROTO ((mp_srcptr, mp_srcptr, mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpn_lshift __MPN(lshift) +__GMP_DECLSPEC mp_limb_t mpn_lshift __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int)); + +#define mpn_mod_1 __MPN(mod_1) +__GMP_DECLSPEC mp_limb_t mpn_mod_1 __GMP_PROTO ((mp_srcptr, mp_size_t, mp_limb_t)) __GMP_ATTRIBUTE_PURE; + +#define mpn_mul __MPN(mul) +__GMP_DECLSPEC mp_limb_t mpn_mul __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)); + +#define mpn_mul_1 __MPN(mul_1) +__GMP_DECLSPEC mp_limb_t mpn_mul_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); + +#define mpn_mul_n __MPN(mul_n) +__GMP_DECLSPEC void mpn_mul_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); + +#define mpn_perfect_square_p __MPN(perfect_square_p) +__GMP_DECLSPEC int mpn_perfect_square_p __GMP_PROTO ((mp_srcptr, mp_size_t)) __GMP_ATTRIBUTE_PURE; + +#define mpn_popcount __MPN(popcount) +__GMP_DECLSPEC unsigned long int mpn_popcount __GMP_PROTO ((mp_srcptr, mp_size_t)) __GMP_NOTHROW __GMP_ATTRIBUTE_PURE; + +#define mpn_pow_1 __MPN(pow_1) +__GMP_DECLSPEC mp_size_t mpn_pow_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t, mp_ptr)); + +/* undocumented now, but retained here for upward compatibility */ +#define mpn_preinv_mod_1 __MPN(preinv_mod_1) +__GMP_DECLSPEC mp_limb_t mpn_preinv_mod_1 __GMP_PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t)) __GMP_ATTRIBUTE_PURE; + +#define mpn_random __MPN(random) +__GMP_DECLSPEC void mpn_random __GMP_PROTO ((mp_ptr, mp_size_t)); + +#define mpn_random2 __MPN(random2) +__GMP_DECLSPEC void mpn_random2 __GMP_PROTO ((mp_ptr, mp_size_t)); + +#define mpn_rshift __MPN(rshift) +__GMP_DECLSPEC mp_limb_t mpn_rshift __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int)); + +#define mpn_scan0 __MPN(scan0) +__GMP_DECLSPEC unsigned long int mpn_scan0 __GMP_PROTO ((mp_srcptr, unsigned long int)) __GMP_ATTRIBUTE_PURE; + +#define mpn_scan1 __MPN(scan1) +__GMP_DECLSPEC unsigned long int mpn_scan1 __GMP_PROTO ((mp_srcptr, unsigned long int)) __GMP_ATTRIBUTE_PURE; + +#define mpn_set_str __MPN(set_str) +__GMP_DECLSPEC mp_size_t mpn_set_str __GMP_PROTO ((mp_ptr, __gmp_const unsigned char *, size_t, int)); + +#define mpn_sqrtrem __MPN(sqrtrem) +__GMP_DECLSPEC mp_size_t mpn_sqrtrem __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t)); + +#define mpn_sub __MPN(sub) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub) +__GMP_DECLSPEC mp_limb_t mpn_sub __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t)); +#endif + +#define mpn_sub_1 __MPN(sub_1) +#if __GMP_INLINE_PROTOTYPES || defined (__GMP_FORCE_mpn_sub_1) +__GMP_DECLSPEC mp_limb_t mpn_sub_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)) __GMP_NOTHROW; +#endif + +#define mpn_sub_n __MPN(sub_n) +__GMP_DECLSPEC mp_limb_t mpn_sub_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t)); + +#define mpn_submul_1 __MPN(submul_1) +__GMP_DECLSPEC mp_limb_t mpn_submul_1 __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t)); + +#define mpn_tdiv_qr __MPN(tdiv_qr) +__GMP_DECLSPEC void mpn_tdiv_qr __GMP_PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t)); + + +/**************** mpz inlines ****************/ + +/* The following are provided as inlines where possible, but always exist as + library functions too, for binary compatibility. + + Within gmp itself this inlining generally isn't relied on, since it + doesn't get done for all compilers, whereas if something is worth + inlining then it's worth arranging always. + + There are two styles of inlining here. When the same bit of code is + wanted for the inline as for the library version, then __GMP_FORCE_foo + arranges for that code to be emitted and the __GMP_EXTERN_INLINE + directive suppressed, eg. mpz_fits_uint_p. When a different bit of code + is wanted for the inline than for the library version, then + __GMP_FORCE_foo arranges the inline to be suppressed, eg. mpz_abs. */ + +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_abs) +__GMP_EXTERN_INLINE void +mpz_abs (mpz_ptr __gmp_w, mpz_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpz_set (__gmp_w, __gmp_u); + __gmp_w->_mp_size = __GMP_ABS (__gmp_w->_mp_size); +} +#endif + +#if GMP_NAIL_BITS == 0 +#define __GMPZ_FITS_UTYPE_P(z,maxval) \ + mp_size_t __gmp_n = z->_mp_size; \ + mp_ptr __gmp_p = z->_mp_d; \ + return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval)); +#else +#define __GMPZ_FITS_UTYPE_P(z,maxval) \ + mp_size_t __gmp_n = z->_mp_size; \ + mp_ptr __gmp_p = z->_mp_d; \ + return (__gmp_n == 0 || (__gmp_n == 1 && __gmp_p[0] <= maxval) \ + || (__gmp_n == 2 && __gmp_p[1] <= ((mp_limb_t) maxval >> GMP_NUMB_BITS))); +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_uint_p) +#if ! defined (__GMP_FORCE_mpz_fits_uint_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_fits_uint_p (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_UINT_MAX); +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ulong_p) +#if ! defined (__GMP_FORCE_mpz_fits_ulong_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_fits_ulong_p (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_ULONG_MAX); +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_fits_ushort_p) +#if ! defined (__GMP_FORCE_mpz_fits_ushort_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_fits_ushort_p (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + __GMPZ_FITS_UTYPE_P (__gmp_z, __GMP_USHRT_MAX); +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_get_ui) +#if ! defined (__GMP_FORCE_mpz_get_ui) +__GMP_EXTERN_INLINE +#endif +unsigned long +mpz_get_ui (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + mp_ptr __gmp_p = __gmp_z->_mp_d; + mp_size_t __gmp_n = __gmp_z->_mp_size; + mp_limb_t __gmp_l = __gmp_p[0]; + /* This is a "#if" rather than a plain "if" so as to avoid gcc warnings + about "<< GMP_NUMB_BITS" exceeding the type size, and to avoid Borland + C++ 6.0 warnings about condition always true for something like + "__GMP_ULONG_MAX < GMP_NUMB_MASK". */ +#if GMP_NAIL_BITS == 0 || defined (_LONG_LONG_LIMB) + /* limb==long and no nails, or limb==longlong, one limb is enough */ + return (__gmp_n != 0 ? __gmp_l : 0); +#else + /* limb==long and nails, need two limbs when available */ + __gmp_n = __GMP_ABS (__gmp_n); + if (__gmp_n <= 1) + return (__gmp_n != 0 ? __gmp_l : 0); + else + return __gmp_l + (__gmp_p[1] << GMP_NUMB_BITS); +#endif +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_getlimbn) +#if ! defined (__GMP_FORCE_mpz_getlimbn) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpz_getlimbn (mpz_srcptr __gmp_z, mp_size_t __gmp_n) __GMP_NOTHROW +{ + mp_limb_t __gmp_result = 0; + if (__GMP_LIKELY (__gmp_n >= 0 && __gmp_n < __GMP_ABS (__gmp_z->_mp_size))) + __gmp_result = __gmp_z->_mp_d[__gmp_n]; + return __gmp_result; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpz_neg) +__GMP_EXTERN_INLINE void +mpz_neg (mpz_ptr __gmp_w, mpz_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpz_set (__gmp_w, __gmp_u); + __gmp_w->_mp_size = - __gmp_w->_mp_size; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_perfect_square_p) +#if ! defined (__GMP_FORCE_mpz_perfect_square_p) +__GMP_EXTERN_INLINE +#endif +int +mpz_perfect_square_p (mpz_srcptr __gmp_a) +{ + mp_size_t __gmp_asize; + int __gmp_result; + + __gmp_asize = __gmp_a->_mp_size; + __gmp_result = (__gmp_asize >= 0); /* zero is a square, negatives are not */ + if (__GMP_LIKELY (__gmp_asize > 0)) + __gmp_result = mpn_perfect_square_p (__gmp_a->_mp_d, __gmp_asize); + return __gmp_result; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_popcount) +#if ! defined (__GMP_FORCE_mpz_popcount) +__GMP_EXTERN_INLINE +#endif +unsigned long +mpz_popcount (mpz_srcptr __gmp_u) __GMP_NOTHROW +{ + mp_size_t __gmp_usize; + unsigned long __gmp_result; + + __gmp_usize = __gmp_u->_mp_size; + __gmp_result = (__gmp_usize < 0 ? __GMP_ULONG_MAX : 0); + if (__GMP_LIKELY (__gmp_usize > 0)) + __gmp_result = mpn_popcount (__gmp_u->_mp_d, __gmp_usize); + return __gmp_result; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_set_q) +#if ! defined (__GMP_FORCE_mpz_set_q) +__GMP_EXTERN_INLINE +#endif +void +mpz_set_q (mpz_ptr __gmp_w, mpq_srcptr __gmp_u) +{ + mpz_tdiv_q (__gmp_w, mpq_numref (__gmp_u), mpq_denref (__gmp_u)); +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpz_size) +#if ! defined (__GMP_FORCE_mpz_size) +__GMP_EXTERN_INLINE +#endif +size_t +mpz_size (mpz_srcptr __gmp_z) __GMP_NOTHROW +{ + return __GMP_ABS (__gmp_z->_mp_size); +} +#endif + + +/**************** mpq inlines ****************/ + +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_abs) +__GMP_EXTERN_INLINE void +mpq_abs (mpq_ptr __gmp_w, mpq_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpq_set (__gmp_w, __gmp_u); + __gmp_w->_mp_num._mp_size = __GMP_ABS (__gmp_w->_mp_num._mp_size); +} +#endif + +#if defined (__GMP_EXTERN_INLINE) && ! defined (__GMP_FORCE_mpq_neg) +__GMP_EXTERN_INLINE void +mpq_neg (mpq_ptr __gmp_w, mpq_srcptr __gmp_u) +{ + if (__gmp_w != __gmp_u) + mpq_set (__gmp_w, __gmp_u); + __gmp_w->_mp_num._mp_size = - __gmp_w->_mp_num._mp_size; +} +#endif + + +/**************** mpn inlines ****************/ + +/* The comments with __GMPN_ADD_1 below apply here too. + + The test for FUNCTION returning 0 should predict well. If it's assumed + {yp,ysize} will usually have a random number of bits then the high limb + won't be full and a carry out will occur a good deal less than 50% of the + time. + + ysize==0 isn't a documented feature, but is used internally in a few + places. + + Producing cout last stops it using up a register during the main part of + the calculation, though gcc (as of 3.0) on an "if (mpn_add (...))" + doesn't seem able to move the true and false legs of the conditional up + to the two places cout is generated. */ + +#define __GMPN_AORS(cout, wp, xp, xsize, yp, ysize, FUNCTION, TEST) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x; \ + \ + /* ASSERT ((ysize) >= 0); */ \ + /* ASSERT ((xsize) >= (ysize)); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, xp, xsize)); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE2_P (wp, xsize, yp, ysize)); */ \ + \ + __gmp_i = (ysize); \ + if (__gmp_i != 0) \ + { \ + if (FUNCTION (wp, xp, yp, __gmp_i)) \ + { \ + do \ + { \ + if (__gmp_i >= (xsize)) \ + { \ + (cout) = 1; \ + goto __gmp_done; \ + } \ + __gmp_x = (xp)[__gmp_i]; \ + } \ + while (TEST); \ + } \ + } \ + if ((wp) != (xp)) \ + __GMPN_COPY_REST (wp, xp, xsize, __gmp_i); \ + (cout) = 0; \ + __gmp_done: \ + ; \ + } while (0) + +#define __GMPN_ADD(cout, wp, xp, xsize, yp, ysize) \ + __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_add_n, \ + (((wp)[__gmp_i++] = (__gmp_x + 1) & GMP_NUMB_MASK) == 0)) +#define __GMPN_SUB(cout, wp, xp, xsize, yp, ysize) \ + __GMPN_AORS (cout, wp, xp, xsize, yp, ysize, mpn_sub_n, \ + (((wp)[__gmp_i++] = (__gmp_x - 1) & GMP_NUMB_MASK), __gmp_x == 0)) + + +/* The use of __gmp_i indexing is designed to ensure a compile time src==dst + remains nice and clear to the compiler, so that __GMPN_COPY_REST can + disappear, and the load/add/store gets a chance to become a + read-modify-write on CISC CPUs. + + Alternatives: + + Using a pair of pointers instead of indexing would be possible, but gcc + isn't able to recognise compile-time src==dst in that case, even when the + pointers are incremented more or less together. Other compilers would + very likely have similar difficulty. + + gcc could use "if (__builtin_constant_p(src==dst) && src==dst)" or + similar to detect a compile-time src==dst. This works nicely on gcc + 2.95.x, it's not good on gcc 3.0 where __builtin_constant_p(p==p) seems + to be always false, for a pointer p. But the current code form seems + good enough for src==dst anyway. + + gcc on x86 as usual doesn't give particularly good flags handling for the + carry/borrow detection. It's tempting to want some multi instruction asm + blocks to help it, and this was tried, but in truth there's only a few + instructions to save and any gain is all too easily lost by register + juggling setting up for the asm. */ + +#if GMP_NAIL_BITS == 0 +#define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x, __gmp_r; \ + \ + /* ASSERT ((n) >= 1); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */ \ + \ + __gmp_x = (src)[0]; \ + __gmp_r = __gmp_x OP (v); \ + (dst)[0] = __gmp_r; \ + if (CB (__gmp_r, __gmp_x, (v))) \ + { \ + (cout) = 1; \ + for (__gmp_i = 1; __gmp_i < (n);) \ + { \ + __gmp_x = (src)[__gmp_i]; \ + __gmp_r = __gmp_x OP 1; \ + (dst)[__gmp_i] = __gmp_r; \ + ++__gmp_i; \ + if (!CB (__gmp_r, __gmp_x, 1)) \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, __gmp_i); \ + (cout) = 0; \ + break; \ + } \ + } \ + } \ + else \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, 1); \ + (cout) = 0; \ + } \ + } while (0) +#endif + +#if GMP_NAIL_BITS >= 1 +#define __GMPN_AORS_1(cout, dst, src, n, v, OP, CB) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x, __gmp_r; \ + \ + /* ASSERT ((n) >= 1); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, n)); */ \ + \ + __gmp_x = (src)[0]; \ + __gmp_r = __gmp_x OP (v); \ + (dst)[0] = __gmp_r & GMP_NUMB_MASK; \ + if (__gmp_r >> GMP_NUMB_BITS != 0) \ + { \ + (cout) = 1; \ + for (__gmp_i = 1; __gmp_i < (n);) \ + { \ + __gmp_x = (src)[__gmp_i]; \ + __gmp_r = __gmp_x OP 1; \ + (dst)[__gmp_i] = __gmp_r & GMP_NUMB_MASK; \ + ++__gmp_i; \ + if (__gmp_r >> GMP_NUMB_BITS == 0) \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, __gmp_i); \ + (cout) = 0; \ + break; \ + } \ + } \ + } \ + else \ + { \ + if ((src) != (dst)) \ + __GMPN_COPY_REST (dst, src, n, 1); \ + (cout) = 0; \ + } \ + } while (0) +#endif + +#define __GMPN_ADDCB(r,x,y) ((r) < (y)) +#define __GMPN_SUBCB(r,x,y) ((x) < (y)) + +#define __GMPN_ADD_1(cout, dst, src, n, v) \ + __GMPN_AORS_1(cout, dst, src, n, v, +, __GMPN_ADDCB) +#define __GMPN_SUB_1(cout, dst, src, n, v) \ + __GMPN_AORS_1(cout, dst, src, n, v, -, __GMPN_SUBCB) + + +/* Compare {xp,size} and {yp,size}, setting "result" to positive, zero or + negative. size==0 is allowed. On random data usually only one limb will + need to be examined to get a result, so it's worth having it inline. */ +#define __GMPN_CMP(result, xp, yp, size) \ + do { \ + mp_size_t __gmp_i; \ + mp_limb_t __gmp_x, __gmp_y; \ + \ + /* ASSERT ((size) >= 0); */ \ + \ + (result) = 0; \ + __gmp_i = (size); \ + while (--__gmp_i >= 0) \ + { \ + __gmp_x = (xp)[__gmp_i]; \ + __gmp_y = (yp)[__gmp_i]; \ + if (__gmp_x != __gmp_y) \ + { \ + /* Cannot use __gmp_x - __gmp_y, may overflow an "int" */ \ + (result) = (__gmp_x > __gmp_y ? 1 : -1); \ + break; \ + } \ + } \ + } while (0) + + +#if defined (__GMPN_COPY) && ! defined (__GMPN_COPY_REST) +#define __GMPN_COPY_REST(dst, src, size, start) \ + do { \ + /* ASSERT ((start) >= 0); */ \ + /* ASSERT ((start) <= (size)); */ \ + __GMPN_COPY ((dst)+(start), (src)+(start), (size)-(start)); \ + } while (0) +#endif + +/* Copy {src,size} to {dst,size}, starting at "start". This is designed to + keep the indexing dst[j] and src[j] nice and simple for __GMPN_ADD_1, + __GMPN_ADD, etc. */ +#if ! defined (__GMPN_COPY_REST) +#define __GMPN_COPY_REST(dst, src, size, start) \ + do { \ + mp_size_t __gmp_j; \ + /* ASSERT ((size) >= 0); */ \ + /* ASSERT ((start) >= 0); */ \ + /* ASSERT ((start) <= (size)); */ \ + /* ASSERT (MPN_SAME_OR_SEPARATE_P (dst, src, size)); */ \ + __GMP_CRAY_Pragma ("_CRI ivdep"); \ + for (__gmp_j = (start); __gmp_j < (size); __gmp_j++) \ + (dst)[__gmp_j] = (src)[__gmp_j]; \ + } while (0) +#endif + +/* Enhancement: Use some of the smarter code from gmp-impl.h. Maybe use + mpn_copyi if there's a native version, and if we don't mind demanding + binary compatibility for it (on targets which use it). */ + +#if ! defined (__GMPN_COPY) +#define __GMPN_COPY(dst, src, size) __GMPN_COPY_REST (dst, src, size, 0) +#endif + + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add) +#if ! defined (__GMP_FORCE_mpn_add) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_add (mp_ptr __gmp_wp, mp_srcptr __gmp_xp, mp_size_t __gmp_xsize, mp_srcptr __gmp_yp, mp_size_t __gmp_ysize) +{ + mp_limb_t __gmp_c; + __GMPN_ADD (__gmp_c, __gmp_wp, __gmp_xp, __gmp_xsize, __gmp_yp, __gmp_ysize); + return __gmp_c; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_add_1) +#if ! defined (__GMP_FORCE_mpn_add_1) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_add_1 (mp_ptr __gmp_dst, mp_srcptr __gmp_src, mp_size_t __gmp_size, mp_limb_t __gmp_n) __GMP_NOTHROW +{ + mp_limb_t __gmp_c; + __GMPN_ADD_1 (__gmp_c, __gmp_dst, __gmp_src, __gmp_size, __gmp_n); + return __gmp_c; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_cmp) +#if ! defined (__GMP_FORCE_mpn_cmp) +__GMP_EXTERN_INLINE +#endif +int +mpn_cmp (mp_srcptr __gmp_xp, mp_srcptr __gmp_yp, mp_size_t __gmp_size) __GMP_NOTHROW +{ + int __gmp_result; + __GMPN_CMP (__gmp_result, __gmp_xp, __gmp_yp, __gmp_size); + return __gmp_result; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub) +#if ! defined (__GMP_FORCE_mpn_sub) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_sub (mp_ptr __gmp_wp, mp_srcptr __gmp_xp, mp_size_t __gmp_xsize, mp_srcptr __gmp_yp, mp_size_t __gmp_ysize) +{ + mp_limb_t __gmp_c; + __GMPN_SUB (__gmp_c, __gmp_wp, __gmp_xp, __gmp_xsize, __gmp_yp, __gmp_ysize); + return __gmp_c; +} +#endif + +#if defined (__GMP_EXTERN_INLINE) || defined (__GMP_FORCE_mpn_sub_1) +#if ! defined (__GMP_FORCE_mpn_sub_1) +__GMP_EXTERN_INLINE +#endif +mp_limb_t +mpn_sub_1 (mp_ptr __gmp_dst, mp_srcptr __gmp_src, mp_size_t __gmp_size, mp_limb_t __gmp_n) __GMP_NOTHROW +{ + mp_limb_t __gmp_c; + __GMPN_SUB_1 (__gmp_c, __gmp_dst, __gmp_src, __gmp_size, __gmp_n); + return __gmp_c; +} +#endif + +#if defined (__cplusplus) +} +#endif + + +/* Allow faster testing for negative, zero, and positive. */ +#define mpz_sgn(Z) ((Z)->_mp_size < 0 ? -1 : (Z)->_mp_size > 0) +#define mpf_sgn(F) ((F)->_mp_size < 0 ? -1 : (F)->_mp_size > 0) +#define mpq_sgn(Q) ((Q)->_mp_num._mp_size < 0 ? -1 : (Q)->_mp_num._mp_size > 0) + +/* When using GCC, optimize certain common comparisons. */ +#if defined (__GNUC__) +#define mpz_cmp_ui(Z,UI) \ + (__builtin_constant_p (UI) && (UI) == 0 \ + ? mpz_sgn (Z) : _mpz_cmp_ui (Z,UI)) +#define mpz_cmp_si(Z,SI) \ + (__builtin_constant_p (SI) && (SI) == 0 ? mpz_sgn (Z) \ + : __builtin_constant_p (SI) && (SI) > 0 \ + ? _mpz_cmp_ui (Z, __GMP_CAST (unsigned long int, SI)) \ + : _mpz_cmp_si (Z,SI)) +#define mpq_cmp_ui(Q,NUI,DUI) \ + (__builtin_constant_p (NUI) && (NUI) == 0 \ + ? mpq_sgn (Q) : _mpq_cmp_ui (Q,NUI,DUI)) +#define mpq_cmp_si(q,n,d) \ + (__builtin_constant_p ((n) >= 0) && (n) >= 0 \ + ? mpq_cmp_ui (q, __GMP_CAST (unsigned long, n), d) \ + : _mpq_cmp_si (q, n, d)) +#else +#define mpz_cmp_ui(Z,UI) _mpz_cmp_ui (Z,UI) +#define mpz_cmp_si(Z,UI) _mpz_cmp_si (Z,UI) +#define mpq_cmp_ui(Q,NUI,DUI) _mpq_cmp_ui (Q,NUI,DUI) +#define mpq_cmp_si(q,n,d) _mpq_cmp_si(q,n,d) +#endif + + +/* Using "&" rather than "&&" means these can come out branch-free. Every + mpz_t has at least one limb allocated, so fetching the low limb is always + allowed. */ +#define mpz_odd_p(z) (((z)->_mp_size != 0) & __GMP_CAST (int, (z)->_mp_d[0])) +#define mpz_even_p(z) (! mpz_odd_p (z)) + + +/**************** C++ routines ****************/ + +#ifdef __cplusplus +__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpz_srcptr); +__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpq_srcptr); +__GMP_DECLSPEC_XX std::ostream& operator<< (std::ostream &, mpf_srcptr); +__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpz_ptr); +__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpq_ptr); +__GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpf_ptr); +#endif + + +/* Source-level compatibility with GMP 2 and earlier. */ +#define mpn_divmod(qp,np,nsize,dp,dsize) \ + mpn_divrem (qp, __GMP_CAST (mp_size_t, 0), np, nsize, dp, dsize) + +/* Source-level compatibility with GMP 1. */ +#define mpz_mdiv mpz_fdiv_q +#define mpz_mdivmod mpz_fdiv_qr +#define mpz_mmod mpz_fdiv_r +#define mpz_mdiv_ui mpz_fdiv_q_ui +#define mpz_mdivmod_ui(q,r,n,d) \ + (((r) == 0) ? mpz_fdiv_q_ui (q,n,d) : mpz_fdiv_qr_ui (q,r,n,d)) +#define mpz_mmod_ui(r,n,d) \ + (((r) == 0) ? mpz_fdiv_ui (n,d) : mpz_fdiv_r_ui (r,n,d)) + +/* Useful synonyms, but not quite compatible with GMP 1. */ +#define mpz_div mpz_fdiv_q +#define mpz_divmod mpz_fdiv_qr +#define mpz_div_ui mpz_fdiv_q_ui +#define mpz_divmod_ui mpz_fdiv_qr_ui +#define mpz_div_2exp mpz_fdiv_q_2exp +#define mpz_mod_2exp mpz_fdiv_r_2exp + +enum +{ + GMP_ERROR_NONE = 0, + GMP_ERROR_UNSUPPORTED_ARGUMENT = 1, + GMP_ERROR_DIVISION_BY_ZERO = 2, + GMP_ERROR_SQRT_OF_NEGATIVE = 4, + GMP_ERROR_INVALID_ARGUMENT = 8 +}; + +/* Major version number is the value of __GNU_MP__ too, above and in mp.h. */ +#define __GNU_MP_VERSION 4 +#define __GNU_MP_VERSION_MINOR 2 +#define __GNU_MP_VERSION_PATCHLEVEL 2 + +#define __GMP_H__ +#endif /* __GMP_H__ */ diff --git a/src/bncsutil/keytables.h b/src/bncsutil/keytables.h index e6cfe64..edb8e21 100644 --- a/src/bncsutil/keytables.h +++ b/src/bncsutil/keytables.h @@ -128,4 +128,4 @@ const unsigned char w3TranslateMap[] = { } // extern "C" #endif -#endif /* BNCSUTIL_KEYTABLES_H */ \ No newline at end of file +#endif /* BNCSUTIL_KEYTABLES_H */ diff --git a/src/bncsutil/libinfo.cpp b/src/bncsutil/libinfo.cpp index 99c4392..956ba2c 100644 --- a/src/bncsutil/libinfo.cpp +++ b/src/bncsutil/libinfo.cpp @@ -38,20 +38,19 @@ MEXP(int) bncsutil_getVersionString(char* outBuf) { // major major = (unsigned long) (BNCSUTIL_VERSION / 10000); if (major > 99 || major < 0) return 0; - + // minor ver -= (major * 10000); minor = (unsigned long) (ver / 100); if (minor > 99 || minor < 0) return 0; - + // revision ver -= (minor * 100); rev = ver; if (rev > 99 || rev < 0) return 0; - - printed = std::sprintf(outBuf, "%u.%u.%u", major, minor, rev); + + printed = std::sprintf(outBuf, "%lu.%lu.%lu", major, minor, rev); if (printed < 0) return 0; outBuf[8] = '\0'; return printed; } - \ No newline at end of file diff --git a/src/bncsutil/ms_stdint.h b/src/bncsutil/ms_stdint.h new file mode 100644 index 0000000..17dcad4 --- /dev/null +++ b/src/bncsutil/ms_stdint.h @@ -0,0 +1,232 @@ +// ISO C9x compliant stdint.h for Microsoft Visual Studio +// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 +// +// Copyright (c) 2006-2008 Alexander Chemeris +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// 3. The name of the author may be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _MSC_VER // [ +#error "Use this header only with Microsoft Visual C++ compilers!" +#endif // _MSC_VER ] + +#ifndef _MSC_STDINT_H_ // [ +#define _MSC_STDINT_H_ + +#if _MSC_VER > 1000 +#pragma once +#endif + +#include + +// For Visual Studio 6 in C++ mode wrap include with 'extern "C++" {}' +// or compiler give many errors like this: +// error C2733: second C linkage of overloaded function 'wmemchr' not allowed +#if (_MSC_VER < 1300) && defined(__cplusplus) + extern "C++" { +#endif +# include +#if (_MSC_VER < 1300) && defined(__cplusplus) + } +#endif + +// Define _W64 macros to mark types changing their size, like intptr_t. +#ifndef _W64 +# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 +# define _W64 __w64 +# else +# define _W64 +# endif +#endif + + +// 7.18.1 Integer types + +// 7.18.1.1 Exact-width integer types +typedef __int8 int8_t; +typedef __int16 int16_t; +typedef __int32 int32_t; +typedef __int64 int64_t; +typedef unsigned __int8 uint8_t; +typedef unsigned __int16 uint16_t; +typedef unsigned __int32 uint32_t; +typedef unsigned __int64 uint64_t; + +// 7.18.1.2 Minimum-width integer types +typedef int8_t int_least8_t; +typedef int16_t int_least16_t; +typedef int32_t int_least32_t; +typedef int64_t int_least64_t; +typedef uint8_t uint_least8_t; +typedef uint16_t uint_least16_t; +typedef uint32_t uint_least32_t; +typedef uint64_t uint_least64_t; + +// 7.18.1.3 Fastest minimum-width integer types +typedef int8_t int_fast8_t; +typedef int16_t int_fast16_t; +typedef int32_t int_fast32_t; +typedef int64_t int_fast64_t; +typedef uint8_t uint_fast8_t; +typedef uint16_t uint_fast16_t; +typedef uint32_t uint_fast32_t; +typedef uint64_t uint_fast64_t; + +// 7.18.1.4 Integer types capable of holding object pointers +#ifdef _WIN64 // [ + typedef __int64 intptr_t; + typedef unsigned __int64 uintptr_t; +#else // _WIN64 ][ + typedef _W64 int intptr_t; + typedef _W64 unsigned int uintptr_t; +#endif // _WIN64 ] + +// 7.18.1.5 Greatest-width integer types +typedef int64_t intmax_t; +typedef uint64_t uintmax_t; + + +// 7.18.2 Limits of specified-width integer types + +#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 + +// 7.18.2.1 Limits of exact-width integer types +#define INT8_MIN ((int8_t)_I8_MIN) +#define INT8_MAX _I8_MAX +#define INT16_MIN ((int16_t)_I16_MIN) +#define INT16_MAX _I16_MAX +#define INT32_MIN ((int32_t)_I32_MIN) +#define INT32_MAX _I32_MAX +#define INT64_MIN ((int64_t)_I64_MIN) +#define INT64_MAX _I64_MAX +#define UINT8_MAX _UI8_MAX +#define UINT16_MAX _UI16_MAX +#define UINT32_MAX _UI32_MAX +#define UINT64_MAX _UI64_MAX + +// 7.18.2.2 Limits of minimum-width integer types +#define INT_LEAST8_MIN INT8_MIN +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST64_MIN INT64_MIN +#define INT_LEAST64_MAX INT64_MAX +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX + +// 7.18.2.3 Limits of fastest minimum-width integer types +#define INT_FAST8_MIN INT8_MIN +#define INT_FAST8_MAX INT8_MAX +#define INT_FAST16_MIN INT16_MIN +#define INT_FAST16_MAX INT16_MAX +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST32_MAX INT32_MAX +#define INT_FAST64_MIN INT64_MIN +#define INT_FAST64_MAX INT64_MAX +#define UINT_FAST8_MAX UINT8_MAX +#define UINT_FAST16_MAX UINT16_MAX +#define UINT_FAST32_MAX UINT32_MAX +#define UINT_FAST64_MAX UINT64_MAX + +// 7.18.2.4 Limits of integer types capable of holding object pointers +#ifdef _WIN64 // [ +# define INTPTR_MIN INT64_MIN +# define INTPTR_MAX INT64_MAX +# define UINTPTR_MAX UINT64_MAX +#else // _WIN64 ][ +# define INTPTR_MIN INT32_MIN +# define INTPTR_MAX INT32_MAX +# define UINTPTR_MAX UINT32_MAX +#endif // _WIN64 ] + +// 7.18.2.5 Limits of greatest-width integer types +#define INTMAX_MIN INT64_MIN +#define INTMAX_MAX INT64_MAX +#define UINTMAX_MAX UINT64_MAX + +// 7.18.3 Limits of other integer types + +#ifdef _WIN64 // [ +# define PTRDIFF_MIN _I64_MIN +# define PTRDIFF_MAX _I64_MAX +#else // _WIN64 ][ +# define PTRDIFF_MIN _I32_MIN +# define PTRDIFF_MAX _I32_MAX +#endif // _WIN64 ] + +#define SIG_ATOMIC_MIN INT_MIN +#define SIG_ATOMIC_MAX INT_MAX + +#ifndef SIZE_MAX // [ +# ifdef _WIN64 // [ +# define SIZE_MAX _UI64_MAX +# else // _WIN64 ][ +# define SIZE_MAX _UI32_MAX +# endif // _WIN64 ] +#endif // SIZE_MAX ] + +// WCHAR_MIN and WCHAR_MAX are also defined in +#ifndef WCHAR_MIN // [ +# define WCHAR_MIN 0 +#endif // WCHAR_MIN ] +#ifndef WCHAR_MAX // [ +# define WCHAR_MAX _UI16_MAX +#endif // WCHAR_MAX ] + +#define WINT_MIN 0 +#define WINT_MAX _UI16_MAX + +#endif // __STDC_LIMIT_MACROS ] + + +// 7.18.4 Limits of other integer types + +#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 + +// 7.18.4.1 Macros for minimum-width integer constants + +#define INT8_C(val) val##i8 +#define INT16_C(val) val##i16 +#define INT32_C(val) val##i32 +#define INT64_C(val) val##i64 + +#define UINT8_C(val) val##ui8 +#define UINT16_C(val) val##ui16 +#define UINT32_C(val) val##ui32 +#define UINT64_C(val) val##ui64 + +// 7.18.4.2 Macros for greatest-width integer constants +#define INTMAX_C INT64_C +#define UINTMAX_C UINT64_C + +#endif // __STDC_CONSTANT_MACROS ] + + +#endif // _MSC_STDINT_H_ ] diff --git a/src/bncsutil/mutil.h b/src/bncsutil/mutil.h index aabdeac..a5f5c05 100644 --- a/src/bncsutil/mutil.h +++ b/src/bncsutil/mutil.h @@ -27,18 +27,28 @@ #ifndef MUTIL_H #define MUTIL_H +#define LITTLEENDIAN 1 + + #ifdef HAVE_CONFIG_H #include #endif /* Specific-Sized Integers */ #include "mutil_types.h" -#include +#include + +// functions for converting a string to a 64-bit number. +#if defined(_MSC_VER) +#define ATOL64(x) _atoi64(x) +#else +#define ATOL64(x) atoll(x) +#endif #ifdef _MSC_VER -#pragma intrinsic(_lrotl,_lrotr) /* use intrinsic compiler rotations */ -#define ROL(x,n) _lrotl((x),(n)) -#define ROR(x,n) _lrotr((x),(n)) +#pragma intrinsic(_lrotl,_lrotr) /* use intrinsic compiler rotations */ +#define ROL(x,n) _lrotl((x),(n)) +#define ROR(x,n) _lrotr((x),(n)) #else #ifndef ROL #define ROL(a,b) (((a) << (b)) | ((a) >> 32 - (b))) @@ -92,8 +102,8 @@ #define SWAP2(num) ((((num) >> 8) & 0x00FF) | (((num) << 8) & 0xFF00)) #define SWAP4(num) ((((num) >> 24) & 0x000000FF) | (((num) >> 8) & 0x0000FF00) | (((num) << 8) & 0x00FF0000) | (((num) << 24) & 0xFF000000)) -#define SWAP8(x) \ - (uint64_t)((((uint64_t)(x) & 0xff) << 56) | \ +#define SWAP8(x) \ + (uint64_t)((((uint64_t)(x) & 0xff) << 56) | \ ((uint64_t)(x) & 0xff00ULL) << 40 | \ ((uint64_t)(x) & 0xff0000ULL) << 24 | \ ((uint64_t)(x) & 0xff000000ULL) << 8 | \ @@ -119,17 +129,17 @@ #define MSB4(num) SWAP4(num) #endif /* (endianness) */ -#ifndef MOS_WINDOWS +#ifndef MOS_WINDOWS /* attempt automatic Windows detection */ - #ifdef _MSC_VER + #ifdef _MSC_VER /* Microsoft C++ compiler, has to be windows */ - #define MOS_WINDOWS - #else + #define MOS_WINDOWS + #else #if defined(_WIN) || defined(_WINDOWS) || defined(WINDOWS) || \ defined(_WIN32) || defined(_WIN64) || defined(WIN32) || defined(WIN64) #define MOS_WINDOWS - #endif - #endif + #endif + #endif #endif #if !(defined(MUTIL_LIB_BUILD)) && defined(BNCSUTIL_EXPORTS) @@ -163,6 +173,6 @@ #define NULL 0 #endif /* NULL */ -#include +// #include #endif /* MUTIL_H */ diff --git a/src/bncsutil/mutil_types.h b/src/bncsutil/mutil_types.h index a52b100..31b7320 100644 --- a/src/bncsutil/mutil_types.h +++ b/src/bncsutil/mutil_types.h @@ -26,6 +26,10 @@ #ifndef BNCSUTIL_MUTIL_TYPES_H_INCLUDED #define BNCSUTIL_MUTIL_TYPES_H_INCLUDED +#ifdef WIN32 + #include "ms_stdint.h" +#else + #if defined(_MSC_VER) || (defined(HAVE_STDINT_H) && !HAVE_STDINT_H) // no stdint.h available // so just wing it @@ -118,7 +122,7 @@ typedef unsigned long long uintmax_t; #define INTPTR_MIN INT32_MIN #define INTPTR_MAX INT32_MAX - + #define UINTPTR_MAX UINT32_MAX #define INTMAX_MIN INT64_MIN @@ -136,4 +140,6 @@ typedef unsigned long long uintmax_t; #include #endif +#endif /* WIN32 */ + #endif /* BNCSUTIL_MUTIL_TYPES_H_INCLUDED */ diff --git a/src/bncsutil/nls.c b/src/bncsutil/nls.c index 997f06a..3def492 100644 --- a/src/bncsutil/nls.c +++ b/src/bncsutil/nls.c @@ -29,24 +29,24 @@ #include #include #include -#include +#include "gmp.h" struct _nls { const char* username; const char* password; unsigned long username_len; unsigned long password_len; - + mpz_t n; mpz_t a; - + gmp_randstate_t rand; - char* A; - char* S; - char* K; - char* M1; - char* M2; + char* A; + char* S; + char* K; + char* M1; + char* M2; }; #ifdef MOS_WINDOWS @@ -95,7 +95,7 @@ uint32_t nls_get_u(const char* B); MEXP(nls_t*) nls_init(const char* username, const char* password) { return nls_init_l(username, (unsigned long) strlen(username), - password, (unsigned long) strlen(password)); + password, (unsigned long) strlen(password)); } MEXP(nls_t*) nls_init_l(const char* username, unsigned long username_length, @@ -105,21 +105,21 @@ MEXP(nls_t*) nls_init_l(const char* username, unsigned long username_length, char* d; /* destination */ const char* o; /* original */ nls_t* nls; - + nls = (nls_t*) malloc(sizeof(nls_t)); if (!nls) return (nls_t*) 0; - + nls->username_len = username_length; nls->password_len = password_length; - + nls->username = (char*) malloc(nls->username_len + 1); nls->password = (char*) malloc(nls->password_len + 1); if (!nls->username || !nls->password) { free(nls); return (nls_t*) 0; } - + d = (char*) nls->username; o = username; for (i = 0; i < nls->username_len; i++) { @@ -127,10 +127,10 @@ MEXP(nls_t*) nls_init_l(const char* username, unsigned long username_length, d++; o++; } - + *((char*) nls->username + username_length) = 0; *((char*) nls->password + password_length) = 0; - + d = (char*) nls->password; o = password; for (i = 0; i < nls->password_len; i++) { @@ -138,9 +138,9 @@ MEXP(nls_t*) nls_init_l(const char* username, unsigned long username_length, d++; o++; } - + mpz_init_set_str(nls->n, NLS_VAR_N_STR, 16); - + gmp_randinit_default(nls->rand); gmp_randseed_ui(nls->rand, nls_pre_seed()); mpz_init2(nls->a, 256); @@ -149,12 +149,12 @@ MEXP(nls_t*) nls_init_l(const char* username, unsigned long username_length, /* The following line replaces preceding 2 lines during testing. */ /*mpz_init_set_str(nls->a, "1234", 10);*/ - nls->A = (char*) 0; - nls->S = (char*) 0; - nls->K = (char*) 0; - nls->M1 = (char*) 0; - nls->M2 = (char*) 0; - + nls->A = (char*) 0; + nls->S = (char*) 0; + nls->K = (char*) 0; + nls->M1 = (char*) 0; + nls->M2 = (char*) 0; + return nls; } @@ -167,63 +167,63 @@ MEXP(void) nls_free(nls_t* nls) { free((void*) nls->username); free((void*) nls->password); - if (nls->A) - free(nls->A); - if (nls->S) - free(nls->S); - if (nls->K) - free(nls->K); - if (nls->M1) - free(nls->M1); - if (nls->M2) - free(nls->M2); + if (nls->A) + free(nls->A); + if (nls->S) + free(nls->S); + if (nls->K) + free(nls->K); + if (nls->M1) + free(nls->M1); + if (nls->M2) + free(nls->M2); free(nls); } MEXP(nls_t*) nls_reinit(nls_t* nls, const char* username, - const char* password) + const char* password) { - return nls_reinit_l(nls, username, (unsigned long) strlen(username), - password, (unsigned long) strlen(password)); + return nls_reinit_l(nls, username, (unsigned long) strlen(username), + password, (unsigned long) strlen(password)); } MEXP(nls_t*) nls_reinit_l(nls_t* nls, const char* username, - unsigned long username_length, const char* password, - unsigned long password_length) + unsigned long username_length, const char* password, + unsigned long password_length) { - unsigned int i; + unsigned int i; char* d; /* destination */ const char* o; /* original */ - if (nls->A) - free(nls->A); - if (nls->S) - free(nls->S); - if (nls->K) - free(nls->K); - if (nls->M1) - free(nls->M1); - if (nls->M2) - free(nls->M2); - - nls->username_len = username_length; + if (nls->A) + free(nls->A); + if (nls->S) + free(nls->S); + if (nls->K) + free(nls->K); + if (nls->M1) + free(nls->M1); + if (nls->M2) + free(nls->M2); + + nls->username_len = username_length; nls->password_len = password_length; - - nls->username = (const char*) realloc((void*) nls->username, - nls->username_len + 1); - if (!nls->username) { + + nls->username = (const char*) realloc((void*) nls->username, + nls->username_len + 1); + if (!nls->username) { free(nls); return (nls_t*) 0; } nls->password = (const char*) realloc((void*) nls->password, - nls->password_len + 1); + nls->password_len + 1); if (!nls->password) { - free((void*) nls->username); + free((void*) nls->username); free(nls); return (nls_t*) 0; } - + d = (char*) nls->username; o = username; for (i = 0; i < nls->username_len; i++) { @@ -232,30 +232,30 @@ MEXP(nls_t*) nls_reinit_l(nls_t* nls, const char* username, o++; } - d = (char*) nls->password; + d = (char*) nls->password; o = password; for (i = 0; i < nls->password_len; i++) { *d = (char) toupper(*o); d++; o++; } - + *((char*) nls->username + username_length) = 0; *((char*) nls->password + password_length) = 0; - mpz_urandomm(nls->a, nls->rand, nls->n); /* generates the private key */ + mpz_urandomm(nls->a, nls->rand, nls->n); /* generates the private key */ - nls->A = (char*) 0; - nls->S = (char*) 0; - nls->K = (char*) 0; - nls->M1 = (char*) 0; - nls->M2 = (char*) 0; + nls->A = (char*) 0; + nls->S = (char*) 0; + nls->K = (char*) 0; + nls->M1 = (char*) 0; + nls->M2 = (char*) 0; - return nls; + return nls; } MEXP(unsigned long) nls_account_create(nls_t* nls, char* buf, unsigned long bufSize) { - mpz_t s; /* salt */ + mpz_t s; /* salt */ mpz_t v; mpz_t x; @@ -263,20 +263,20 @@ MEXP(unsigned long) nls_account_create(nls_t* nls, char* buf, unsigned long bufS return 0; if (bufSize < nls->username_len + 65) return 0; - + mpz_init2(s, 256); mpz_urandomb(s, nls->rand, 256); mpz_export(buf, (size_t*) 0, -1, 1, 0, 0, s); - /*memset(buf, 0, 32);*/ - + /*memset(buf, 0, 32);*/ + nls_get_x(nls, x, buf); nls_get_v_mpz(nls, v, x); mpz_export(buf + 32, (size_t*) 0, -1, 1, 0, 0, v); - - mpz_clear(x); + + mpz_clear(x); mpz_clear(v); mpz_clear(s); - + strcpy(buf + 64, nls->username); return nls->username_len + 65; } @@ -286,7 +286,7 @@ MEXP(unsigned long) nls_account_logon(nls_t* nls, char* buf, unsigned long bufSi return 0; if (bufSize < nls->username_len + 33) return 0; - + nls_get_A(nls, buf); strcpy(buf + 32, nls->username); return nls->username_len + 33; @@ -297,27 +297,27 @@ MEXP(nls_t*) nls_account_change_proof(nls_t* nls, char* buf, { nls_t* nouveau; mpz_t s; /* salt */ - + if (!nls) return (nls_t*) 0; - + /* create new nls_t */ nouveau = nls_init_l(nls->username, nls->username_len, new_password, (unsigned long) strlen(new_password)); if (!nouveau) return (nls_t*) 0; - + /* fill buf */ nls_get_M1(nls, buf, B, salt); - + mpz_init2(s, 256); mpz_urandomb(s, nouveau->rand, 256); mpz_export(buf + 20, (size_t*) 0, -1, 1, 0, 0, s); - - nls_get_v(nouveau, buf + 52, buf + 20); + + nls_get_v(nouveau, buf + 52, buf + 20); mpz_clear(s); - + return nouveau; } @@ -326,34 +326,34 @@ MEXP(void) nls_get_S(nls_t* nls, char* out, const char* B, const char* salt) { mpz_t S_base, S_exp; mpz_t x; mpz_t v; - + if (!nls) return; - if (nls->S) { - memcpy(out, nls->S, 32); - return; - } - + if (nls->S) { + memcpy(out, nls->S, 32); + return; + } + mpz_init2(temp, 256); mpz_import(temp, 32, -1, 1, 0, 0, B); - + nls_get_x(nls, x, salt); nls_get_v_mpz(nls, v, x); - + mpz_init_set(S_base, nls->n); mpz_add(S_base, S_base, temp); mpz_sub(S_base, S_base, v); mpz_mod(S_base, S_base, nls->n); - + mpz_init_set(S_exp, x); mpz_mul_ui(S_exp, S_exp, nls_get_u(B)); mpz_add(S_exp, S_exp, nls->a); - + mpz_clear(x); mpz_clear(v); mpz_clear(temp); - + mpz_init(temp); mpz_powm(temp, S_base, S_exp, nls->n); mpz_clear(S_base); @@ -361,25 +361,25 @@ MEXP(void) nls_get_S(nls_t* nls, char* out, const char* B, const char* salt) { mpz_export(out, (size_t*) 0, -1, 1, 0, 0, temp); mpz_clear(temp); - nls->S = (char*) malloc(32); - if (nls->S) - memcpy(nls->S, out, 32); + nls->S = (char*) malloc(32); + if (nls->S) + memcpy(nls->S, out, 32); } MEXP(void) nls_get_v(nls_t* nls, char* out, const char* salt) { mpz_t g; mpz_t v; mpz_t x; - + if (!nls) return; - + mpz_init_set_ui(g, NLS_VAR_g); mpz_init(v); nls_get_x(nls, x, salt); - + mpz_powm(v, g, x, nls->n); - + mpz_export(out, (size_t*) 0, -1, 1, 0, 0, v); mpz_clear(v); mpz_clear(g); @@ -391,62 +391,62 @@ MEXP(void) nls_get_A(nls_t* nls, char* out) { mpz_t g; mpz_t A; size_t o; - + if (!nls) return; - if (nls->A) { - memcpy(out, nls->A, 32); - return; - } - + if (nls->A) { + memcpy(out, nls->A, 32); + return; + } + mpz_init_set_ui(g, NLS_VAR_g); mpz_init2(A, 256); - + mpz_powm(A, g, nls->a, nls->n); mpz_export(out, &o, -1, 1, 0, 0, A); - + mpz_clear(A); mpz_clear(g); - nls->A = (char*) malloc(32); - if (nls->A) - memcpy(nls->A, out, 32); + nls->A = (char*) malloc(32); + if (nls->A) + memcpy(nls->A, out, 32); } MEXP(void) nls_get_K(nls_t* nls, char* out, const char* S) { char odd[16], even[16]; uint8_t odd_hash[20], even_hash[20]; - + char* Sp = (char*) S; char* op = odd; char* ep = even; unsigned int i; - + SHA1Context ctx; - if (!nls) - return; + if (!nls) + return; + + if (nls->K) { + memcpy(out, nls->K, 40); + return; + } - if (nls->K) { - memcpy(out, nls->K, 40); - return; - } - for (i = 0; i < 16; i++) { *(op++) = *(Sp++); *(ep++) = *(Sp++); } - + SHA1Reset(&ctx); SHA1Input(&ctx, (uint8_t*) odd, 16); SHA1Result(&ctx, odd_hash); - + SHA1Reset(&ctx); SHA1Input(&ctx, (uint8_t*) even, 16); SHA1Result(&ctx, even_hash); - + Sp = out; op = (char*) odd_hash; ep = (char*) even_hash; @@ -455,9 +455,9 @@ MEXP(void) nls_get_K(nls_t* nls, char* out, const char* S) { *(Sp++) = *(ep++); } - nls->K = (char*) malloc(40); - if (nls->K) - memcpy(nls->K, out, 40); + nls->K = (char*) malloc(40); + if (nls->K) + memcpy(nls->K, out, 40); } MEXP(void) nls_get_M1(nls_t* nls, char* out, const char* B, const char* salt) { @@ -467,21 +467,21 @@ MEXP(void) nls_get_M1(nls_t* nls, char* out, const char* B, const char* salt) { char S[32]; char K[40]; - if (!nls) - return; + if (!nls) + return; - if (nls->M1) { - nls_dbg("nls_get_M1(): Using cached M[1] value."); - memcpy(out, nls->M1, 20); - return; - } + if (nls->M1) { + nls_dbg("nls_get_M1(): Using cached M[1] value."); + memcpy(out, nls->M1, 20); + return; + } /* calculate SHA-1 hash of username */ SHA1Reset(&sha); SHA1Input(&sha, (uint8_t*) nls->username, nls->username_len); SHA1Result(&sha, username_hash); - + nls_get_A(nls, A); nls_get_S(nls, S, B, salt); nls_get_K(nls, K, S); @@ -496,9 +496,9 @@ MEXP(void) nls_get_M1(nls_t* nls, char* out, const char* B, const char* salt) { SHA1Input(&sha, (uint8_t*) K, 40); SHA1Result(&sha, (uint8_t*) out); - nls->M1 = (char*) malloc(20); - if (nls->M1) - memcpy(nls->M1, out, 20); + nls->M1 = (char*) malloc(20); + if (nls->M1) + memcpy(nls->M1, out, 20); } MEXP(int) nls_check_M2(nls_t* nls, const char* var_M2, const char* B, @@ -506,66 +506,66 @@ MEXP(int) nls_check_M2(nls_t* nls, const char* var_M2, const char* B, { SHA1Context sha; char local_M2[20]; - char* A; - char S[32]; - char* K; - char* M1; + char* A; + char S[32]; + char* K; + char* M1; uint8_t username_hash[20]; - int res; - int mustFree = 0; - - if (!nls) - return 0; - - if (nls->M2) - return (memcmp(nls->M2, var_M2, 20) == 0); - - if (nls->A && nls->K && nls->M1) { - A = nls->A; - K = nls->K; - M1 = nls->M1; - } else { - if (!B || !salt) - return 0; - - A = (char*) malloc(32); - if (!A) - return 0; - K = (char*) malloc(40); - if (!K) { - free(A); - return 0; - } - M1 = (char*) malloc(20); - if (!M1) { - free(K); - free(A); - return 0; - } - - mustFree = 1; - - /* get the other values needed for the hash */ - nls_get_A(nls, A); - nls_get_S(nls, S, (char*) B, (char*) salt); - nls_get_K(nls, K, S); - - /* calculate SHA-1 hash of username */ - SHA1Reset(&sha); - SHA1Input(&sha, (uint8_t*) nls->username, nls->username_len); - SHA1Result(&sha, username_hash); - - /* calculate M[1] */ - SHA1Reset(&sha); - SHA1Input(&sha, (uint8_t*) bncsutil_NLS_I, 20); - SHA1Input(&sha, username_hash, 20); - SHA1Input(&sha, (uint8_t*) salt, 32); - SHA1Input(&sha, (uint8_t*) A, 32); - SHA1Input(&sha, (uint8_t*) B, 32); - SHA1Input(&sha, (uint8_t*) K, 40); - SHA1Result(&sha, (uint8_t*) M1); - } - + int res; + int mustFree = 0; + + if (!nls) + return 0; + + if (nls->M2) + return (memcmp(nls->M2, var_M2, 20) == 0); + + if (nls->A && nls->K && nls->M1) { + A = nls->A; + K = nls->K; + M1 = nls->M1; + } else { + if (!B || !salt) + return 0; + + A = (char*) malloc(32); + if (!A) + return 0; + K = (char*) malloc(40); + if (!K) { + free(A); + return 0; + } + M1 = (char*) malloc(20); + if (!M1) { + free(K); + free(A); + return 0; + } + + mustFree = 1; + + /* get the other values needed for the hash */ + nls_get_A(nls, A); + nls_get_S(nls, S, (char*) B, (char*) salt); + nls_get_K(nls, K, S); + + /* calculate SHA-1 hash of username */ + SHA1Reset(&sha); + SHA1Input(&sha, (uint8_t*) nls->username, nls->username_len); + SHA1Result(&sha, username_hash); + + /* calculate M[1] */ + SHA1Reset(&sha); + SHA1Input(&sha, (uint8_t*) bncsutil_NLS_I, 20); + SHA1Input(&sha, username_hash, 20); + SHA1Input(&sha, (uint8_t*) salt, 32); + SHA1Input(&sha, (uint8_t*) A, 32); + SHA1Input(&sha, (uint8_t*) B, 32); + SHA1Input(&sha, (uint8_t*) K, 40); + SHA1Result(&sha, (uint8_t*) M1); + } + /* calculate M[2] */ SHA1Reset(&sha); SHA1Input(&sha, (uint8_t*) A, 32); @@ -573,19 +573,19 @@ MEXP(int) nls_check_M2(nls_t* nls, const char* var_M2, const char* B, SHA1Input(&sha, (uint8_t*) K, 40); SHA1Result(&sha, (uint8_t*) local_M2); - res = (memcmp(local_M2, var_M2, 20) == 0); + res = (memcmp(local_M2, var_M2, 20) == 0); + + if (mustFree) { + free(A); + free(K); + free(M1); + } - if (mustFree) { - free(A); - free(K); - free(M1); - } + /* cache result */ + nls->M2 = (char*) malloc(20); + if (nls->M2) + memcpy(nls->M2, local_M2, 20); - /* cache result */ - nls->M2 = (char*) malloc(20); - if (nls->M2) - memcpy(nls->M2, local_M2, 20); - return res; } @@ -595,55 +595,55 @@ MEXP(int) nls_check_signature(uint32_t address, const char* signature_raw) { mpz_t result; mpz_t modulus; mpz_t signature; - size_t size, alloc_size; - int cmp_result; - + size_t size, alloc_size; + int cmp_result; + /* build the "check" array */ - memcpy(check, &address, 4); - memset(check + 4, 0xBB, 28); - + memcpy(check, &address, 4); + memset(check + 4, 0xBB, 28); + /* initialize the modulus */ mpz_init2(modulus, 1024); mpz_import(modulus, 128, -1, 1, 0, 0, bncsutil_NLS_sig_n); - + /* initialize the server signature */ mpz_init2(signature, 1024); mpz_import(signature, 128, -1, 1, 0, 0, signature_raw); - + /* initialize the result */ mpz_init2(result, 1024); - + /* calculate the result */ mpz_powm_ui(result, signature, NLS_SIGNATURE_KEY, modulus); - + /* clear (free) the intermediates */ mpz_clear(signature); mpz_clear(modulus); - /* allocate space for raw signature */ - alloc_size = mpz_size(result) * sizeof(mp_limb_t); - result_raw = (char*) malloc(alloc_size); - if (!result_raw) { - mpz_clear(result); - return 0; - } - + /* allocate space for raw signature */ + alloc_size = mpz_size(result) * sizeof(mp_limb_t); + result_raw = (char*) malloc(alloc_size); + if (!result_raw) { + mpz_clear(result); + return 0; + } + /* get a byte array of the signature */ mpz_export(result_raw, &size, -1, 1, 0, 0, result); - + /* clear (free) the result */ mpz_clear(result); - + /* check the result */ cmp_result = (memcmp(result_raw, check, 32) == 0); - /* free the result_raw buffer */ - free(result_raw); + /* free the result_raw buffer */ + free(result_raw); - /* return */ - return cmp_result; + /* return */ + return cmp_result; } - + unsigned long nls_pre_seed() { #ifdef MOS_WINDOWS return (unsigned long) GetTickCount(); @@ -673,28 +673,28 @@ void nls_get_x(nls_t* nls, mpz_t x_c, const char* raw_salt) { char* userpass; uint8_t hash[20], final_hash[20]; SHA1Context shac; - + // build the string Username:Password userpass = (char*) malloc(nls->username_len + nls->password_len + 2); memcpy(userpass, nls->username, nls->username_len); userpass[nls->username_len] = ':'; memcpy(userpass + nls->username_len + 1, nls->password, nls->password_len); userpass[nls->username_len + nls->password_len + 1] = 0; // null-terminator - + // get the SHA-1 hash of the string SHA1Reset(&shac); SHA1Input(&shac, (uint8_t*) userpass, (nls->username_len + nls->password_len + 1)); SHA1Result(&shac, hash); free(userpass); - + // get the SHA-1 hash of the salt and user:pass hash SHA1Reset(&shac); SHA1Input(&shac, (uint8_t*) raw_salt, 32); SHA1Input(&shac, hash, 20); SHA1Result(&shac, final_hash); SHA1Reset(&shac); - + // create an arbitrary-length integer from the hash and return it mpz_init2(x_c, 160); mpz_import(x_c, 20, -1, 1, 0, 0, (char*) final_hash); @@ -712,12 +712,12 @@ uint32_t nls_get_u(const char* B) { SHA1Context sha; uint8_t hash[20]; uint32_t u; - + SHA1Reset(&sha); SHA1Input(&sha, (uint8_t*) B, 32); SHA1Result(&sha, hash); SHA1Reset(&sha); - + u = *(uint32_t*) hash; u = MSB4(u); // needed? yes return u; diff --git a/src/bncsutil/nls.h b/src/bncsutil/nls.h index 3e94df1..545a447 100644 --- a/src/bncsutil/nls.h +++ b/src/bncsutil/nls.h @@ -72,7 +72,7 @@ MEXP(void) nls_free(nls_t* nls); * pointer on failure. */ MEXP(nls_t*) nls_reinit(nls_t* nls, const char* username, - const char* password); + const char* password); /** * Re-initializes an nls_t structure with a new username and @@ -80,8 +80,8 @@ MEXP(nls_t*) nls_reinit(nls_t* nls, const char* username, * on success or a NULL pointer on failure. */ MEXP(nls_t*) nls_reinit_l(nls_t* nls, const char* username, - unsigned long username_length, const char* password, - unsigned long password_length); + unsigned long username_length, const char* password, + unsigned long password_length); /* Packet Generation Functions */ @@ -123,7 +123,7 @@ MEXP(unsigned long) nls_account_logon(nls_t* nls, char* buf, unsigned long bufSi */ MEXP(nls_t*) nls_account_change_proof(nls_t* nls, char* buf, const char* new_password, const char* B, const char* salt); - + /* Calculation Functions */ /** @@ -161,8 +161,8 @@ MEXP(void) nls_get_M1(nls_t* nls, char* out, const char* B, const char* salt); * safely set to NULL. */ MEXP(int) nls_check_M2(nls_t* nls, const char* var_M2, const char* B, - const char* salt); - + const char* salt); + /** * Checks the server signature received in SID_AUTH_INFO (0x50). * Pass the IPv4 address of the server you're connecting to in the address @@ -188,142 +188,142 @@ MEXP(int) nls_check_signature(uint32_t address, const char* signature_raw); class NLS { public: - NLS(const char* username, const char* password) : n((nls_t*) 0) - { - n = nls_init(username, password); - } - - NLS(const char* username, size_t username_length, const char* password, - size_t password_length) - { - n = nls_init_l(username, username_length, password, password_length); - } - - NLS(const std::string& username, const std::string& password) - { - n = nls_init_l(username.c_str(), username.length(), - password.c_str(), password.length()); - } - - virtual ~NLS() - { - std::vector::iterator i; - - if (n) - nls_free(n); - - for (i = blocks.begin(); i != blocks.end(); i++) { - delete [] *i; - } - } - - void getSecret(char* out, const char* salt, const char* B) - { - nls_get_S(n, out, B, salt); - } - - const char* getSecret(const char* salt, const char* B) - { - char* buf = allocateBuffer(32); - getSecret(buf, salt, B); - return buf; - } - - void getVerifier(char* out, const char* salt) - { - nls_get_v(n, out, salt); - } - - const char* getVerifier(const char* salt) - { - char* buf = allocateBuffer(32); - getVerifier(buf, salt); - return buf; - } - - void getPublicKey(char* out) - { - nls_get_A(n, out); - } - - const char* getPublicKey(void) - { - char* buf = allocateBuffer(32); - getPublicKey(buf); - return buf; - } - - void getHashedSecret(char* out, const char* secret) - { - nls_get_K(n, out, secret); - } - - const char* getHashedSecret(const char* secret) - { - char* buf = allocateBuffer(40); - getHashedSecret(buf, secret); - return buf; - } - - void getClientSessionKey(char* out, const char* salt, const char* B) - { - nls_get_M1(n, out, B, salt); - } - - const char* getClientSessionKey(const char* salt, const char* B) - { - char* buf = allocateBuffer(20); - getClientSessionKey(buf, salt, B); - return buf; - } - - bool checkServerSessionKey(const char* key, const char* salt, - const char* B) - { - return (nls_check_M2(n, key, B, salt) != 0); - } - - NLS makeChangeProof(char* buf, const char* new_password, const char* salt, - const char* B) - { - return NLS(nls_account_change_proof(n, buf, new_password, B, salt)); - } - - NLS makeChangeProof(char* buf, const std::string& new_password, - const char* salt, const char* B) - { - return NLS(nls_account_change_proof(n, buf, new_password.c_str(), B, - salt)); - } - - std::pair makeChangeProof(const char* new_password, - const char* salt, const char* B) - { - char* buf = allocateBuffer(84); - NLS nls = NLS(nls_account_change_proof(n, buf, new_password, B, salt)); - return std::pair(nls, buf); - } - - std::pair makeChangeProof(const std::string& new_password, - const char* salt, const char* B) - { - return makeChangeProof(new_password.c_str(), salt, B); - } + NLS(const char* username, const char* password) : n((nls_t*) 0) + { + n = nls_init(username, password); + } + + NLS(const char* username, size_t username_length, const char* password, + size_t password_length) + { + n = nls_init_l(username, username_length, password, password_length); + } + + NLS(const std::string& username, const std::string& password) + { + n = nls_init_l(username.c_str(), username.length(), + password.c_str(), password.length()); + } + + virtual ~NLS() + { + std::vector::iterator i; + + if (n) + nls_free(n); + + for (i = blocks.begin(); i != blocks.end(); i++) { + delete [] *i; + } + } + + void getSecret(char* out, const char* salt, const char* B) + { + nls_get_S(n, out, B, salt); + } + + const char* getSecret(const char* salt, const char* B) + { + char* buf = allocateBuffer(32); + getSecret(buf, salt, B); + return buf; + } + + void getVerifier(char* out, const char* salt) + { + nls_get_v(n, out, salt); + } + + const char* getVerifier(const char* salt) + { + char* buf = allocateBuffer(32); + getVerifier(buf, salt); + return buf; + } + + void getPublicKey(char* out) + { + nls_get_A(n, out); + } + + const char* getPublicKey(void) + { + char* buf = allocateBuffer(32); + getPublicKey(buf); + return buf; + } + + void getHashedSecret(char* out, const char* secret) + { + nls_get_K(n, out, secret); + } + + const char* getHashedSecret(const char* secret) + { + char* buf = allocateBuffer(40); + getHashedSecret(buf, secret); + return buf; + } + + void getClientSessionKey(char* out, const char* salt, const char* B) + { + nls_get_M1(n, out, B, salt); + } + + const char* getClientSessionKey(const char* salt, const char* B) + { + char* buf = allocateBuffer(20); + getClientSessionKey(buf, salt, B); + return buf; + } + + bool checkServerSessionKey(const char* key, const char* salt, + const char* B) + { + return (nls_check_M2(n, key, B, salt) != 0); + } + + NLS makeChangeProof(char* buf, const char* new_password, const char* salt, + const char* B) + { + return NLS(nls_account_change_proof(n, buf, new_password, B, salt)); + } + + NLS makeChangeProof(char* buf, const std::string& new_password, + const char* salt, const char* B) + { + return NLS(nls_account_change_proof(n, buf, new_password.c_str(), B, + salt)); + } + + std::pair makeChangeProof(const char* new_password, + const char* salt, const char* B) + { + char* buf = allocateBuffer(84); + NLS nls = NLS(nls_account_change_proof(n, buf, new_password, B, salt)); + return std::pair(nls, buf); + } + + std::pair makeChangeProof(const std::string& new_password, + const char* salt, const char* B) + { + return makeChangeProof(new_password.c_str(), salt, B); + } private: - std::vector blocks; - nls_t* n; - - NLS(nls_t* nls) - { - n = nls; - } - - char* allocateBuffer(size_t length) - { - char* buf = new char[length]; - blocks.push_back(buf); - return buf; - } + std::vector blocks; + nls_t* n; + + NLS(nls_t* nls) + { + n = nls; + } + + char* allocateBuffer(size_t length) + { + char* buf = new char[length]; + blocks.push_back(buf); + return buf; + } }; #endif diff --git a/src/bncsutil/oldauth.cpp b/src/bncsutil/oldauth.cpp index 804634a..bde739d 100644 --- a/src/bncsutil/oldauth.cpp +++ b/src/bncsutil/oldauth.cpp @@ -22,7 +22,7 @@ * write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA */ - + #include // for MEXP() #include #include @@ -44,11 +44,11 @@ uint32_t serverToken, char* outBuffer) { lp[0] = clientToken; lp[1] = serverToken; calcHashBuf(intermediate, 28, outBuffer); - + #if DEBUG - bncsutil_debug_message_a("doubleHashPassword(\"%s\", 0x%08X, 0x%08X) =", - password, clientToken, serverToken); - bncsutil_debug_dump(outBuffer, 20); + bncsutil_debug_message_a("doubleHashPassword(\"%s\", 0x%08X, 0x%08X) =", + password, clientToken, serverToken); + bncsutil_debug_dump(outBuffer, 20); #endif } @@ -61,7 +61,7 @@ MEXP(void) hashPassword(const char* password, char* outBuffer) { calcHashBuf(password, std::strlen(password), outBuffer); #if DEBUG - bncsutil_debug_message_a("hashPassword(\"%s\") =", password); - bncsutil_debug_dump(outBuffer, 20); + bncsutil_debug_message_a("hashPassword(\"%s\") =", password); + bncsutil_debug_dump(outBuffer, 20); #endif -} \ No newline at end of file +} diff --git a/src/bncsutil/oldauth.h b/src/bncsutil/oldauth.h index 95016ff..a0382cc 100644 --- a/src/bncsutil/oldauth.h +++ b/src/bncsutil/oldauth.h @@ -46,4 +46,4 @@ MEXP(void) hashPassword(const char* password, char* outBuffer); } // extern "C" #endif -#endif /* BNCSUTIL_OLDAUTH_H */ \ No newline at end of file +#endif /* BNCSUTIL_OLDAUTH_H */ diff --git a/src/bncsutil/pe.c b/src/bncsutil/pe.c index a762858..24de769 100644 --- a/src/bncsutil/pe.c +++ b/src/bncsutil/pe.c @@ -32,453 +32,453 @@ int cm_pe_load_resdir(FILE* f, uint32_t offset, cm_pe_resdir_t* dir); MEXP(cm_pe_t) cm_pe_load(const char* filename) { - cm_pe_t pe; - cm_pe_header_t* header; - cm_pe_optional_header_t* opt_header; - cm_pe_windows_header_t* win_header; - long pe_offset = 0; - size_t i; - size_t count; - - pe = (cm_pe_t) malloc(sizeof(struct cm_pe)); - if (!pe) - return (cm_pe_t) 0; - - memset(pe, 0, sizeof(struct cm_pe)); - - pe->f = fopen(filename, "r"); - if (!pe->f) { - free(pe); - return (cm_pe_t) 0; - } - - if (fseek(pe->f, 0x3CL, SEEK_SET) == -1) - goto err_trap; - - if (fread(&pe_offset, 4, 1, pe->f) != 1) - goto err_trap; - + cm_pe_t pe; + cm_pe_header_t* header; + cm_pe_optional_header_t* opt_header; + cm_pe_windows_header_t* win_header; + long pe_offset = 0; + //size_t i; + size_t count; + + pe = (cm_pe_t) malloc(sizeof(struct cm_pe)); + if (!pe) + return (cm_pe_t) 0; + + memset(pe, 0, sizeof(struct cm_pe)); + + pe->f = fopen(filename, "r"); + if (!pe->f) { + free(pe); + return (cm_pe_t) 0; + } + + if (fseek(pe->f, 0x3CL, SEEK_SET) == -1) + goto err_trap; + + if (fread(&pe_offset, 4, 1, pe->f) != 1) + goto err_trap; + #if BIG_ENDIAN - pe_offset = LSB4(pe_offset); + pe_offset = LSB4(pe_offset); #endif - - if (fseek(pe->f, pe_offset, SEEK_SET) == -1) - goto err_trap; - - if (fread(&pe->header, sizeof(cm_pe_header_t), 1, pe->f) != 1) - goto err_trap; - - header = &pe->header; + + if (fseek(pe->f, pe_offset, SEEK_SET) == -1) + goto err_trap; + + if (fread(&pe->header, sizeof(cm_pe_header_t), 1, pe->f) != 1) + goto err_trap; + + header = &pe->header; #if BIGENDIAN - /* Without regular expressions, this would've sucked. */ - header->signature = SWAP32(header->signature); - header->machine = SWAP16(header->machine); - header->section_count = SWAP16(header->section_count); - header->timestamp = SWAP32(header->timestamp); - header->symbol_table_offset = SWAP32(header->symbol_table_offset); - header->symbol_count = SWAP32(header->symbol_count); - header->optional_header_size = SWAP16(header->optional_header_size); - header->characteristics = SWAP16(header->characteristics); + /* Without regular expressions, this would've sucked. */ + header->signature = SWAP32(header->signature); + header->machine = SWAP16(header->machine); + header->section_count = SWAP16(header->section_count); + header->timestamp = SWAP32(header->timestamp); + header->symbol_table_offset = SWAP32(header->symbol_table_offset); + header->symbol_count = SWAP32(header->symbol_count); + header->optional_header_size = SWAP16(header->optional_header_size); + header->characteristics = SWAP16(header->characteristics); #endif - - if (header->optional_header_size > 0) { - if (fread(&pe->optional_header, PE_OPTIONAL_HEADER_MIN_SIZE, 1, pe->f) - != 1) - { - goto err_trap; - } - - opt_header = &pe->optional_header; - win_header = &pe->windows_header; - + + if (header->optional_header_size > 0) { + if (fread(&pe->optional_header, PE_OPTIONAL_HEADER_MIN_SIZE, 1, pe->f) + != 1) + { + goto err_trap; + } + + opt_header = &pe->optional_header; + win_header = &pe->windows_header; + #if BIGENDIAN - opt_header->magic = SWAP16(opt_header->magic); + opt_header->magic = SWAP16(opt_header->magic); #endif - - if (opt_header->magic == IMAGE_FORMAT_PE32) { - if (fread(&opt_header->data_base, 4, 1, pe->f) != 1) - goto err_trap; - if (fread(&win_header->image_base, 4, 1, pe->f) != 1) - goto err_trap; - // The 40 is not a typo. - if (fread(&win_header->section_alignment, 40, 1, pe->f) != 1) - goto err_trap; - if (fread(&win_header->stack_reserve_size, 4, 1, pe->f) != 1) - goto err_trap; - if (fread(&win_header->stack_commit_size, 4, 1, pe->f) != 1) - goto err_trap; - if (fread(&win_header->heap_reserve_size, 4, 1, pe->f) != 1) - goto err_trap; - if (fread(&win_header->heap_commit_size, 4, 1, pe->f) != 1) - goto err_trap; - if (fread(&win_header->loader_flags, 4, 1, pe->f) != 1) - goto err_trap; - if (fread(&win_header->data_directory_count, 4, 1, pe->f) != 1) - goto err_trap; - } else if (opt_header->magic == IMAGE_FORMAT_PE32_PLUS) { - if (fread(win_header, sizeof(cm_pe_windows_header_t), 1, pe->f)!= 1) - goto err_trap; - } else { - goto err_trap; - } - + + if (opt_header->magic == IMAGE_FORMAT_PE32) { + if (fread(&opt_header->data_base, 4, 1, pe->f) != 1) + goto err_trap; + if (fread(&win_header->image_base, 4, 1, pe->f) != 1) + goto err_trap; + // The 40 is not a typo. + if (fread(&win_header->section_alignment, 40, 1, pe->f) != 1) + goto err_trap; + if (fread(&win_header->stack_reserve_size, 4, 1, pe->f) != 1) + goto err_trap; + if (fread(&win_header->stack_commit_size, 4, 1, pe->f) != 1) + goto err_trap; + if (fread(&win_header->heap_reserve_size, 4, 1, pe->f) != 1) + goto err_trap; + if (fread(&win_header->heap_commit_size, 4, 1, pe->f) != 1) + goto err_trap; + if (fread(&win_header->loader_flags, 4, 1, pe->f) != 1) + goto err_trap; + if (fread(&win_header->data_directory_count, 4, 1, pe->f) != 1) + goto err_trap; + } else if (opt_header->magic == IMAGE_FORMAT_PE32_PLUS) { + if (fread(win_header, sizeof(cm_pe_windows_header_t), 1, pe->f)!= 1) + goto err_trap; + } else { + goto err_trap; + } + #if BIGENDIAN - opt_header->code_section_size = SWAP32(opt_header->code_section_size); - opt_header->initialized_data_size = - SWAP32(opt_header->initialized_data_size); - opt_header->uninitialized_data_size = - SWAP32(opt_header->uninitialized_data_size); - opt_header->entry_point = SWAP32(opt_header->entry_point); - opt_header->code_base = SWAP32(opt_header->code_base); - opt_header->data_base = SWAP32(opt_header->data_base); - - win_header->image_base = SWAP64(win_header->image_base); - win_header->section_alignment = SWAP32(win_header->section_alignment); - win_header->file_alignment = SWAP32(win_header->file_alignment); - win_header->major_os_version = SWAP16(win_header->major_os_version); - win_header->minor_os_version = SWAP16(win_header->minor_os_version); - win_header->major_image_version = - SWAP16(win_header->major_image_version); - win_header->minor_image_version = - SWAP16(win_header->minor_image_version); - win_header->major_subsystem_version = - SWAP16(win_header->major_subsystem_version); - win_header->minor_subsystem_version = - SWAP16(win_header->minor_subsystem_version); - win_header->reserved = SWAP32(win_header->reserved); - win_header->image_size = SWAP32(win_header->image_size); - win_header->headers_size = SWAP32(win_header->headers_size); - win_header->checksum = SWAP32(win_header->checksum); - win_header->subsystem = SWAP16(win_header->subsystem); - win_header->dll_characteristics = - SWAP16(win_header->dll_characteristics); - win_header->stack_reserve_size = SWAP64(win_header->stack_reserve_size); - win_header->stack_commit_size = SWAP64(win_header->stack_commit_size); - win_header->heap_reserve_size = SWAP64(win_header->heap_reserve_size); - win_header->heap_commit_size = SWAP64(win_header->heap_commit_size); - win_header->loader_flags = SWAP32(win_header->loader_flags); - win_header->data_directory_count = - SWAP32(win_header->data_directory_count); + opt_header->code_section_size = SWAP32(opt_header->code_section_size); + opt_header->initialized_data_size = + SWAP32(opt_header->initialized_data_size); + opt_header->uninitialized_data_size = + SWAP32(opt_header->uninitialized_data_size); + opt_header->entry_point = SWAP32(opt_header->entry_point); + opt_header->code_base = SWAP32(opt_header->code_base); + opt_header->data_base = SWAP32(opt_header->data_base); + + win_header->image_base = SWAP64(win_header->image_base); + win_header->section_alignment = SWAP32(win_header->section_alignment); + win_header->file_alignment = SWAP32(win_header->file_alignment); + win_header->major_os_version = SWAP16(win_header->major_os_version); + win_header->minor_os_version = SWAP16(win_header->minor_os_version); + win_header->major_image_version = + SWAP16(win_header->major_image_version); + win_header->minor_image_version = + SWAP16(win_header->minor_image_version); + win_header->major_subsystem_version = + SWAP16(win_header->major_subsystem_version); + win_header->minor_subsystem_version = + SWAP16(win_header->minor_subsystem_version); + win_header->reserved = SWAP32(win_header->reserved); + win_header->image_size = SWAP32(win_header->image_size); + win_header->headers_size = SWAP32(win_header->headers_size); + win_header->checksum = SWAP32(win_header->checksum); + win_header->subsystem = SWAP16(win_header->subsystem); + win_header->dll_characteristics = + SWAP16(win_header->dll_characteristics); + win_header->stack_reserve_size = SWAP64(win_header->stack_reserve_size); + win_header->stack_commit_size = SWAP64(win_header->stack_commit_size); + win_header->heap_reserve_size = SWAP64(win_header->heap_reserve_size); + win_header->heap_commit_size = SWAP64(win_header->heap_commit_size); + win_header->loader_flags = SWAP32(win_header->loader_flags); + win_header->data_directory_count = + SWAP32(win_header->data_directory_count); #endif - - if (win_header->data_directory_count > 0) { - count = win_header->data_directory_count; - pe->data_directories = (cm_pe_data_directory_t*) - calloc(sizeof(cm_pe_data_directory_t), count); - - if (!pe->data_directories) - goto err_trap; - - if (fread(pe->data_directories, sizeof(cm_pe_data_directory_t), - count, pe->f) != count) - { - goto dir_err_trap; - } - + + if (win_header->data_directory_count > 0) { + count = win_header->data_directory_count; + pe->data_directories = (cm_pe_data_directory_t*) + calloc(sizeof(cm_pe_data_directory_t), count); + + if (!pe->data_directories) + goto err_trap; + + if (fread(pe->data_directories, sizeof(cm_pe_data_directory_t), + count, pe->f) != count) + { + goto dir_err_trap; + } + #if BIGENDIAN - for (i = 0; i < count; i++) { - pe->data_directories[i].rva = - SWAP32(pe->data_directories[i].rva); - pe->data_directories[i].size = - SWAP32(pe->data_directories[i].size); - } + for (i = 0; i < count; i++) { + pe->data_directories[i].rva = + SWAP32(pe->data_directories[i].rva); + pe->data_directories[i].size = + SWAP32(pe->data_directories[i].size); + } #endif - } - - count = (size_t) header->section_count; - if (count) { - pe->sections = (cm_pe_section_t*) calloc(sizeof(cm_pe_section_t), - count); - - if (!pe->sections) - goto dir_err_trap; - - if (fread(pe->sections, sizeof(cm_pe_section_t), count, pe->f) - != count) - { - goto sect_err_trap; - } - } - + } + + count = (size_t) header->section_count; + if (count) { + pe->sections = (cm_pe_section_t*) calloc(sizeof(cm_pe_section_t), + count); + + if (!pe->sections) + goto dir_err_trap; + + if (fread(pe->sections, sizeof(cm_pe_section_t), count, pe->f) + != count) + { + goto sect_err_trap; + } + } + #if BIGENDIAN - for (i = 0; i < count; i++) { - pe->sections[i].virtual_size = SWAP32(pe->sections[i].virtual_size); - pe->sections[i].virtual_address = - SWAP32(pe->sections[i].virtual_address); - pe->sections[i].raw_data_size = - SWAP32(pe->sections[i].raw_data_size); - pe->sections[i].raw_data_offset = - SWAP32(pe->sections[i].raw_data_offset); - pe->sections[i].relocations_offset = - SWAP32(pe->sections[i].relocations_offset); - pe->sections[i].line_numbers_offset = - SWAP32(pe->sections[i].line_numbers_offset); - pe->sections[i].relocation_count = - SWAP16(pe->sections[i].relocation_count); - pe->sections[i].line_number_count = - SWAP16(pe->sections[i].line_number_count); - pe->sections[i].characteristics = - SWAP32(pe->sections[i].characteristics); - } + for (i = 0; i < count; i++) { + pe->sections[i].virtual_size = SWAP32(pe->sections[i].virtual_size); + pe->sections[i].virtual_address = + SWAP32(pe->sections[i].virtual_address); + pe->sections[i].raw_data_size = + SWAP32(pe->sections[i].raw_data_size); + pe->sections[i].raw_data_offset = + SWAP32(pe->sections[i].raw_data_offset); + pe->sections[i].relocations_offset = + SWAP32(pe->sections[i].relocations_offset); + pe->sections[i].line_numbers_offset = + SWAP32(pe->sections[i].line_numbers_offset); + pe->sections[i].relocation_count = + SWAP16(pe->sections[i].relocation_count); + pe->sections[i].line_number_count = + SWAP16(pe->sections[i].line_number_count); + pe->sections[i].characteristics = + SWAP32(pe->sections[i].characteristics); + } #endif - } - - return pe; + } + + return pe; sect_err_trap: - free(pe->sections); + free(pe->sections); dir_err_trap: - free(pe->data_directories); + free(pe->data_directories); err_trap: - fclose(pe->f); - free(pe); - return (cm_pe_t) 0; + fclose(pe->f); + free(pe); + return (cm_pe_t) 0; } MEXP(void) cm_pe_unload(cm_pe_t pe) { - if (pe->data_directories) - free(pe->data_directories); - if (pe->sections) - free(pe->sections); - if (pe->f) - fclose(pe->f); - free(pe); + if (pe->data_directories) + free(pe->data_directories); + if (pe->sections) + free(pe->sections); + if (pe->f) + fclose(pe->f); + free(pe); } MEXP(cm_pe_section_t*) cm_pe_get_section(cm_pe_t pe, const char* name) { - unsigned int i; - cm_pe_section_t* s; - uint32_t section_count = pe->header.section_count; - - if (!pe || !pe->sections) - return (cm_pe_section_t*) 0; - - for (i = 0, s = pe->sections; i < section_count; i++, s++) { - if (strcmp(s->name, name) == 0) - return s; - } - - return (cm_pe_section_t*) 0; + unsigned int i; + cm_pe_section_t* s; + uint32_t section_count = pe->header.section_count; + + if (!pe || !pe->sections) + return (cm_pe_section_t*) 0; + + for (i = 0, s = pe->sections; i < section_count; i++, s++) { + if (strcmp(s->name, name) == 0) + return s; + } + + return (cm_pe_section_t*) 0; } MEXP(cm_pe_resdir_t*) cm_pe_load_resources(cm_pe_t pe) { - cm_pe_section_t* sect; - cm_pe_resdir_t* root = (cm_pe_resdir_t*) 0; - cm_pe_resdir_t* dir; - cm_pe_resdir_t* subdirs; - cm_pe_res_t res; - cm_pe_res_t* resources; - cm_stack_t stack; - size_t i; - uint32_t base; - - // no need to check validity of pe pointer; cm_pe_get_section does this - sect = cm_pe_get_section(pe, ".rsrc"); - if (!sect) - return (cm_pe_resdir_t*) 0; - - root = (cm_pe_resdir_t*) malloc(sizeof(cm_pe_resdir_t)); - if (!root) - return (cm_pe_resdir_t*) 0; - - base = sect->raw_data_offset; - if (!cm_pe_load_resdir(pe->f, base, root)) { - free(root); - return (cm_pe_resdir_t*) 0; - } - - stack = cm_stack_create(); - if (!stack) { - free(root); - return (cm_pe_resdir_t*) 0; - } - - cm_stack_push(stack, root); - - while (dir = (cm_pe_resdir_t*) cm_stack_pop(stack)) { - while (dir->subdir_count + dir->resource_count < - dir->named_entry_count + dir->id_entry_count) - { - if (fseek(pe->f, dir->offset, SEEK_SET) == -1) { - cm_pe_unload_resources(root); - cm_stack_destroy(stack); - return (cm_pe_resdir_t*) 0; - } - - if (fread(&res, CM_RES_REAL_SIZE, 1, pe->f) != 1) { - cm_pe_unload_resources(root); - cm_stack_destroy(stack); - return (cm_pe_resdir_t*) 0; - } - - #if BIGENDIAN - res.name = SWAP4(res.name); - res.offset = SWAP4(res.offset); - #endif - if (res.offset & 0x80000000) { - // subdirectory - i = dir->subdir_count++; - subdirs = (cm_pe_resdir_t*) realloc(dir->subdirs, - sizeof(cm_pe_resdir_t) * dir->subdir_count); - if (!subdirs) { - cm_pe_unload_resources(root); - cm_stack_destroy(stack); - return (cm_pe_resdir_t*) 0; - } - dir->subdirs = subdirs; - - cm_stack_push(stack, dir); - dir->offset += CM_RES_REAL_SIZE; - dir = (subdirs + i); - - res.offset &= 0x7FFFFFFF; - res.file_offset = base + res.offset; - - if (!cm_pe_load_resdir(pe->f, res.file_offset, dir)) { - cm_pe_unload_resources(root); - cm_stack_destroy(stack); - return (cm_pe_resdir_t*) 0; - } - dir->name = res.name; - - cm_stack_push(stack, dir); - break; - } - // real resource - res.file_offset = base + res.offset; - i = dir->resource_count++; - resources = (cm_pe_res_t*) realloc(dir->resources, - sizeof(cm_pe_res_t) * dir->resource_count); - if (!resources) { - cm_pe_unload_resources(root); - cm_stack_destroy(stack); - return (cm_pe_resdir_t*) 0; - } - dir->resources = resources; - memcpy(dir->resources + i, &res, sizeof(cm_pe_res_t)); - dir->offset += CM_RES_REAL_SIZE; - } - } - - cm_stack_destroy(stack); - return root; + cm_pe_section_t* sect; + cm_pe_resdir_t* root = (cm_pe_resdir_t*) 0; + cm_pe_resdir_t* dir; + cm_pe_resdir_t* subdirs; + cm_pe_res_t res; + cm_pe_res_t* resources; + cm_stack_t stack; + size_t i; + uint32_t base; + + // no need to check validity of pe pointer; cm_pe_get_section does this + sect = cm_pe_get_section(pe, ".rsrc"); + if (!sect) + return (cm_pe_resdir_t*) 0; + + root = (cm_pe_resdir_t*) malloc(sizeof(cm_pe_resdir_t)); + if (!root) + return (cm_pe_resdir_t*) 0; + + base = sect->raw_data_offset; + if (!cm_pe_load_resdir(pe->f, base, root)) { + free(root); + return (cm_pe_resdir_t*) 0; + } + + stack = cm_stack_create(); + if (!stack) { + free(root); + return (cm_pe_resdir_t*) 0; + } + + cm_stack_push(stack, root); + + while ( (dir = (cm_pe_resdir_t*) cm_stack_pop(stack)) ) { + while (dir->subdir_count + dir->resource_count < + dir->named_entry_count + dir->id_entry_count) + { + if (fseek(pe->f, dir->offset, SEEK_SET) == -1) { + cm_pe_unload_resources(root); + cm_stack_destroy(stack); + return (cm_pe_resdir_t*) 0; + } + + if (fread(&res, CM_RES_REAL_SIZE, 1, pe->f) != 1) { + cm_pe_unload_resources(root); + cm_stack_destroy(stack); + return (cm_pe_resdir_t*) 0; + } + + #if BIGENDIAN + res.name = SWAP4(res.name); + res.offset = SWAP4(res.offset); + #endif + if (res.offset & 0x80000000) { + // subdirectory + i = dir->subdir_count++; + subdirs = (cm_pe_resdir_t*) realloc(dir->subdirs, + sizeof(cm_pe_resdir_t) * dir->subdir_count); + if (!subdirs) { + cm_pe_unload_resources(root); + cm_stack_destroy(stack); + return (cm_pe_resdir_t*) 0; + } + dir->subdirs = subdirs; + + cm_stack_push(stack, dir); + dir->offset += CM_RES_REAL_SIZE; + dir = (subdirs + i); + + res.offset &= 0x7FFFFFFF; + res.file_offset = base + res.offset; + + if (!cm_pe_load_resdir(pe->f, res.file_offset, dir)) { + cm_pe_unload_resources(root); + cm_stack_destroy(stack); + return (cm_pe_resdir_t*) 0; + } + dir->name = res.name; + + cm_stack_push(stack, dir); + break; + } + // real resource + res.file_offset = base + res.offset; + i = dir->resource_count++; + resources = (cm_pe_res_t*) realloc(dir->resources, + sizeof(cm_pe_res_t) * dir->resource_count); + if (!resources) { + cm_pe_unload_resources(root); + cm_stack_destroy(stack); + return (cm_pe_resdir_t*) 0; + } + dir->resources = resources; + memcpy(dir->resources + i, &res, sizeof(cm_pe_res_t)); + dir->offset += CM_RES_REAL_SIZE; + } + } + + cm_stack_destroy(stack); + return root; } MEXP(int) cm_pe_unload_resources(cm_pe_resdir_t* root) { - cm_pe_resdir_t* dir; - cm_stack_t stack; - - stack = cm_stack_create(); - if (!stack) - return 0; - - cm_stack_push(stack, root); - - while (dir = cm_stack_pop(stack)) { - if (dir->subdir_count) { - dir->subdir_count--; - cm_stack_push(stack, dir); - cm_stack_push(stack, (dir->subdirs + dir->subdir_count)); - continue; - } - - if (dir->subdirs) { - free(dir->subdirs); - dir->subdirs = (cm_pe_resdir_t*) 0; - } - - if (dir->resources) { - free(dir->resources); - dir->resource_count = 0; - } - } - - cm_stack_destroy(stack); - free(root); - return 1; + cm_pe_resdir_t* dir; + cm_stack_t stack; + + stack = cm_stack_create(); + if (!stack) + return 0; + + cm_stack_push(stack, root); + + while ( (dir = cm_stack_pop(stack)) ) { + if (dir->subdir_count) { + dir->subdir_count--; + cm_stack_push(stack, dir); + cm_stack_push(stack, (dir->subdirs + dir->subdir_count)); + continue; + } + + if (dir->subdirs) { + free(dir->subdirs); + dir->subdirs = (cm_pe_resdir_t*) 0; + } + + if (dir->resources) { + free(dir->resources); + dir->resource_count = 0; + } + } + + cm_stack_destroy(stack); + free(root); + return 1; } MEXP(int) cm_pe_fixed_version(cm_pe_t pe, cm_pe_res_t* res, - cm_pe_version_t* ver) + cm_pe_version_t* ver) { - cm_pe_section_t* sect = (pe->sections + 3); + cm_pe_section_t* sect = (pe->sections + 3); #if BIGENDIAN - uint32_t check = 0xBD04EFFE; + uint32_t check = 0xBD04EFFE; #else - uint32_t check = 0xFEEF04BD; + uint32_t check = 0xFEEF04BD; #endif - uint32_t rva; - uint32_t size; - uint32_t offset; - uint32_t align; - - if (!pe || !res || !ver) - return 0; - - if (fseek(pe->f, res->file_offset, SEEK_SET) == -1) - return 0; - if (fread(&rva, 4, 1, pe->f) != 1) - return 0; - if (fread(&size, 4, 1, pe->f) != 1) - return 0; + uint32_t rva; + uint32_t size; + uint32_t offset; + uint32_t align; + + if (!pe || !res || !ver) + return 0; + + if (fseek(pe->f, res->file_offset, SEEK_SET) == -1) + return 0; + if (fread(&rva, 4, 1, pe->f) != 1) + return 0; + if (fread(&size, 4, 1, pe->f) != 1) + return 0; #if BIGENDIAN - rva = SWAP4(rva); - size = SWAP4(size); + rva = SWAP4(rva); + size = SWAP4(size); #endif - - offset = sect->raw_data_offset + (rva - sect->virtual_address) + 0x26; - align = 4 -(offset & 0xF % 4); - if (align < 4) - offset += align; - if (fseek(pe->f, offset, SEEK_SET) == -1) - return 0; - if (fread(ver, sizeof(cm_pe_version_t), 1, pe->f) != 1) - return 0; - - if (ver->dwSignature != check) - return 0; - + + offset = sect->raw_data_offset + (rva - sect->virtual_address) + 0x26; + align = 4 -(offset & 0xF % 4); + if (align < 4) + offset += align; + if (fseek(pe->f, offset, SEEK_SET) == -1) + return 0; + if (fread(ver, sizeof(cm_pe_version_t), 1, pe->f) != 1) + return 0; + + if (ver->dwSignature != check) + return 0; + #if BIGENDIAN - ver->dwSignature = SWAP32(ver->dwSignature); - ver->dwStrucVersion = SWAP32(ver->dwStrucVersion); - ver->dwFileVersionMS = SWAP32(ver->dwFileVersionMS); - ver->dwFileVersionLS = SWAP32(ver->dwFileVersionLS); - ver->dwProductVersionMS = SWAP32(ver->dwProductVersionMS); - ver->dwProductVersionLS = SWAP32(ver->dwProductVersionLS); - ver->dwFileFlagsMask = SWAP32(ver->dwFileFlagsMask); - ver->dwFileFlags = SWAP32(ver->dwFileFlags); - ver->dwFileOS = SWAP32(ver->dwFileOS); - ver->dwFileType = SWAP32(ver->dwFileType); - ver->dwFileSubtype = SWAP32(ver->dwFileSubtype); - ver->dwFileDateMS = SWAP32(ver->dwFileDateMS); - ver->dwFileDateLS = SWAP32(ver->dwFileDateLS); + ver->dwSignature = SWAP32(ver->dwSignature); + ver->dwStrucVersion = SWAP32(ver->dwStrucVersion); + ver->dwFileVersionMS = SWAP32(ver->dwFileVersionMS); + ver->dwFileVersionLS = SWAP32(ver->dwFileVersionLS); + ver->dwProductVersionMS = SWAP32(ver->dwProductVersionMS); + ver->dwProductVersionLS = SWAP32(ver->dwProductVersionLS); + ver->dwFileFlagsMask = SWAP32(ver->dwFileFlagsMask); + ver->dwFileFlags = SWAP32(ver->dwFileFlags); + ver->dwFileOS = SWAP32(ver->dwFileOS); + ver->dwFileType = SWAP32(ver->dwFileType); + ver->dwFileSubtype = SWAP32(ver->dwFileSubtype); + ver->dwFileDateMS = SWAP32(ver->dwFileDateMS); + ver->dwFileDateLS = SWAP32(ver->dwFileDateLS); #endif - - return 1; + + return 1; } int cm_pe_load_resdir(FILE* f, uint32_t offset, cm_pe_resdir_t* dir) { - memset(dir, 0, sizeof(cm_pe_resdir_t)); - - if (fseek(f, offset, SEEK_SET) == -1) - return 0; - - if (fread(dir, 16, 1, f) != 1) - return 0; - + memset(dir, 0, sizeof(cm_pe_resdir_t)); + + if (fseek(f, offset, SEEK_SET) == -1) + return 0; + + if (fread(dir, 16, 1, f) != 1) + return 0; + #if BIGENDIAN - dir->characteristics = SWAP32(dir->characteristics); - dir->timestamp = SWAP32(dir->timestamp); - dir->major_version = SWAP16(dir->major_version); - dir->minor_version = SWAP16(dir->minor_version); - dir->named_entry_count = SWAP16(dir->named_entry_count); - dir->id_entry_count = SWAP16(dir->id_entry_count); + dir->characteristics = SWAP32(dir->characteristics); + dir->timestamp = SWAP32(dir->timestamp); + dir->major_version = SWAP16(dir->major_version); + dir->minor_version = SWAP16(dir->minor_version); + dir->named_entry_count = SWAP16(dir->named_entry_count); + dir->id_entry_count = SWAP16(dir->id_entry_count); #endif - - dir->offset = (uint32_t) ftell(f); - - return 1; -} \ No newline at end of file + + dir->offset = (uint32_t) ftell(f); + + return 1; +} diff --git a/src/bncsutil/pe.h b/src/bncsutil/pe.h index 9ff28d6..1795a10 100644 --- a/src/bncsutil/pe.h +++ b/src/bncsutil/pe.h @@ -34,135 +34,135 @@ extern "C" { #endif typedef struct cm_pe_header { - uint32_t signature; - uint16_t machine; // IMAGE_FILE_MACHINE_* - uint16_t section_count; - uint32_t timestamp; - uint32_t symbol_table_offset; - uint32_t symbol_count; - uint16_t optional_header_size; - uint16_t characteristics; + uint32_t signature; + uint16_t machine; // IMAGE_FILE_MACHINE_* + uint16_t section_count; + uint32_t timestamp; + uint32_t symbol_table_offset; + uint32_t symbol_count; + uint16_t optional_header_size; + uint16_t characteristics; } cm_pe_header_t; -#define IMAGE_FORMAT_PE32 0x10B -#define IMAGE_FORMAT_PE32_PLUS 0x20B +#define IMAGE_FORMAT_PE32 0x10B +#define IMAGE_FORMAT_PE32_PLUS 0x20B typedef struct cm_pe_optional_header { - uint16_t magic; // image format (PE32/PE32+) - uint8_t major_linker_version; - uint8_t minor_linker_version; - uint32_t code_section_size; - uint32_t initialized_data_size; - uint32_t uninitialized_data_size; - uint32_t entry_point; - uint32_t code_base; - uint32_t data_base; // not present in PE32+! + uint16_t magic; // image format (PE32/PE32+) + uint8_t major_linker_version; + uint8_t minor_linker_version; + uint32_t code_section_size; + uint32_t initialized_data_size; + uint32_t uninitialized_data_size; + uint32_t entry_point; + uint32_t code_base; + uint32_t data_base; // not present in PE32+! } cm_pe_optional_header_t; #define PE_OPTIONAL_HEADER_MIN_SIZE (sizeof(cm_pe_optional_header_t) - 4) typedef struct cm_pe_windows_header { - uint64_t image_base; - uint32_t section_alignment; - uint32_t file_alignment; - uint16_t major_os_version; - uint16_t minor_os_version; - uint16_t major_image_version; - uint16_t minor_image_version; - uint16_t major_subsystem_version; - uint16_t minor_subsystem_version; - uint32_t reserved; - uint32_t image_size; - uint32_t headers_size; - uint32_t checksum; - uint16_t subsystem; - uint16_t dll_characteristics; - uint64_t stack_reserve_size; - uint64_t stack_commit_size; - uint64_t heap_reserve_size; - uint64_t heap_commit_size; - uint32_t loader_flags; - uint32_t data_directory_count; + uint64_t image_base; + uint32_t section_alignment; + uint32_t file_alignment; + uint16_t major_os_version; + uint16_t minor_os_version; + uint16_t major_image_version; + uint16_t minor_image_version; + uint16_t major_subsystem_version; + uint16_t minor_subsystem_version; + uint32_t reserved; + uint32_t image_size; + uint32_t headers_size; + uint32_t checksum; + uint16_t subsystem; + uint16_t dll_characteristics; + uint64_t stack_reserve_size; + uint64_t stack_commit_size; + uint64_t heap_reserve_size; + uint64_t heap_commit_size; + uint32_t loader_flags; + uint32_t data_directory_count; } cm_pe_windows_header_t; typedef struct cm_pe_data_directory { - uint32_t rva; - uint32_t size; + uint32_t rva; + uint32_t size; } cm_pe_data_directory_t; typedef struct cm_pe_section { - char name[8]; - uint32_t virtual_size; - uint32_t virtual_address; - uint32_t raw_data_size; - uint32_t raw_data_offset; - uint32_t relocations_offset; - uint32_t line_numbers_offset; - uint16_t relocation_count; - uint16_t line_number_count; - uint32_t characteristics; + char name[8]; + uint32_t virtual_size; + uint32_t virtual_address; + uint32_t raw_data_size; + uint32_t raw_data_offset; + uint32_t relocations_offset; + uint32_t line_numbers_offset; + uint16_t relocation_count; + uint16_t line_number_count; + uint32_t characteristics; } cm_pe_section_t; -typedef struct VS_FIXEDFILEINFO { - uint32_t dwSignature; - uint32_t dwStrucVersion; - uint32_t dwFileVersionMS; - uint32_t dwFileVersionLS; - union { - struct { - uint32_t dwProductVersionMS; - uint32_t dwProductVersionLS; - }; - uint64_t qwProductVersion; - }; - uint32_t dwFileFlagsMask; - uint32_t dwFileFlags; - uint32_t dwFileOS; - uint32_t dwFileType; - uint32_t dwFileSubtype; - union { - struct { - uint32_t dwFileDateMS; - uint32_t dwFileDateLS; - }; - uint64_t qwFileDate; - }; +typedef struct VS_FIXEDFILEINFO { + uint32_t dwSignature; + uint32_t dwStrucVersion; + uint32_t dwFileVersionMS; + uint32_t dwFileVersionLS; + union { + struct { + uint32_t dwProductVersionMS; + uint32_t dwProductVersionLS; + }; + uint64_t qwProductVersion; + }; + uint32_t dwFileFlagsMask; + uint32_t dwFileFlags; + uint32_t dwFileOS; + uint32_t dwFileType; + uint32_t dwFileSubtype; + union { + struct { + uint32_t dwFileDateMS; + uint32_t dwFileDateLS; + }; + uint64_t qwFileDate; + }; } cm_pe_version_t; typedef struct cm_pe_resource { - uint32_t name; - uint32_t offset; - uint32_t file_offset; + uint32_t name; + uint32_t offset; + uint32_t file_offset; } cm_pe_res_t; -#define CM_RES_REAL_SIZE 8 +#define CM_RES_REAL_SIZE 8 typedef struct cm_pe_resdir { - uint32_t characteristics; - uint32_t timestamp; - uint16_t major_version; - uint16_t minor_version; - uint16_t named_entry_count; - uint16_t id_entry_count; - - size_t subdir_count; - struct cm_pe_resdir* subdirs; - size_t resource_count; - cm_pe_res_t* resources; - - uint32_t offset; - uint32_t name; + uint32_t characteristics; + uint32_t timestamp; + uint16_t major_version; + uint16_t minor_version; + uint16_t named_entry_count; + uint16_t id_entry_count; + + size_t subdir_count; + struct cm_pe_resdir* subdirs; + size_t resource_count; + cm_pe_res_t* resources; + + uint32_t offset; + uint32_t name; } cm_pe_resdir_t; typedef struct cm_pe { - FILE* f; - cm_pe_header_t header; - cm_pe_optional_header_t optional_header; - cm_pe_windows_header_t windows_header; - cm_pe_data_directory_t* data_directories; - cm_pe_section_t* sections; + FILE* f; + cm_pe_header_t header; + cm_pe_optional_header_t optional_header; + cm_pe_windows_header_t windows_header; + cm_pe_data_directory_t* data_directories; + cm_pe_section_t* sections; } *cm_pe_t; -#define IMAGE_FILE_MACHINE_UNKNOWN 0x0 +#define IMAGE_FILE_MACHINE_UNKNOWN 0x0 #define IMAGE_FILE_MACHINE_ALPHA 0x184 #define IMAGE_FILE_MACHINE_ARM 0x1c0 #define IMAGE_FILE_MACHINE_ALPHA64 0x284 @@ -171,7 +171,7 @@ typedef struct cm_pe { #define IMAGE_FILE_MACHINE_M68K 0x268 #define IMAGE_FILE_MACHINE_MIPS16 0x266 #define IMAGE_FILE_MACHINE_MIPSFPU 0x366 -#define IMAGE_FILE_MACHINE_MIPSFPU16 0x466 +#define IMAGE_FILE_MACHINE_MIPSFPU16 0x466 #define IMAGE_FILE_MACHINE_POWERPC 0x1f0 #define IMAGE_FILE_MACHINE_R3000 0x162 #define IMAGE_FILE_MACHINE_R4000 0x166 @@ -185,7 +185,7 @@ MEXP(void) cm_pe_unload(cm_pe_t pe); MEXP(cm_pe_resdir_t*) cm_pe_load_resources(cm_pe_t pe); MEXP(int) cm_pe_unload_resources(cm_pe_resdir_t* dir); MEXP(int) cm_pe_fixed_version(cm_pe_t pe, cm_pe_res_t* res, - cm_pe_version_t* ver); + cm_pe_version_t* ver); #ifdef __cplusplus } diff --git a/src/bncsutil/sha1.h b/src/bncsutil/sha1.h index e7753d4..23a3452 100644 --- a/src/bncsutil/sha1.h +++ b/src/bncsutil/sha1.h @@ -74,7 +74,7 @@ int SHA1Input( SHA1Context *, unsigned int); int SHA1Result( SHA1Context *, uint8_t Message_Digest[SHA1HashSize]); - + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/bncsutil/stack.c b/src/bncsutil/stack.c index 88edcd4..1b37f6d 100644 --- a/src/bncsutil/stack.c +++ b/src/bncsutil/stack.c @@ -20,9 +20,10 @@ * A copy of the GNU Lesser General Public License is included in the BNCSutil * distribution in the file COPYING. If you did not receive this copy, * write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, + * Boston, MA 02111-1307 USA + */ -/* +/** * Mule Server * Copyright (c) 2004-2006 Eric Naeseth. * @@ -32,81 +33,81 @@ #include #include - + cm_stack_t cm_stack_create() { - cm_stack_t stack = (cm_stack_t) calloc(1, sizeof(struct cm_stack)); - if (!stack) - return (cm_stack_t) 0; - return stack; + cm_stack_t stack = (cm_stack_t) calloc(1, sizeof(struct cm_stack)); + if (!stack) + return (cm_stack_t) 0; + return stack; } void cm_stack_destroy(cm_stack_t stack) { - cm_stack_node_t* node; - cm_stack_node_t* next; - - if (!stack) - return; - - node = stack->top; - - while (node) { - next = node->next; - free(node); - node = next; - } - - free(stack); + cm_stack_node_t* node; + cm_stack_node_t* next; + + if (!stack) + return; + + node = stack->top; + + while (node) { + next = node->next; + free(node); + node = next; + } + + free(stack); } void cm_stack_push(cm_stack_t stack, void* item) { - cm_stack_node_t* new_node; - - if (!stack || !item) - return; - - new_node = (cm_stack_node_t*) malloc(sizeof(cm_stack_node_t)); - if (!new_node) - return; - new_node->next = stack->top; - new_node->value = item; - - stack->size++; - - stack->top = new_node; + cm_stack_node_t* new_node; + + if (!stack || !item) + return; + + new_node = (cm_stack_node_t*) malloc(sizeof(cm_stack_node_t)); + if (!new_node) + return; + new_node->next = stack->top; + new_node->value = item; + + stack->size++; + + stack->top = new_node; } void* cm_stack_pop(cm_stack_t stack) { - cm_stack_node_t* next; - void* value; - - if (!stack || !stack->top) - return (void*) 0; - - next = stack->top->next; - value = stack->top->value; - free(stack->top); - - stack->top = next; - stack->size--; - return value; + cm_stack_node_t* next; + void* value; + + if (!stack || !stack->top) + return (void*) 0; + + next = stack->top->next; + value = stack->top->value; + free(stack->top); + + stack->top = next; + stack->size--; + return value; } void* cm_stack_peek(cm_stack_t stack) { - if (!stack || !stack->top) - return (void*) 0; - - return stack->top->value; + if (!stack || !stack->top) + return (void*) 0; + + return stack->top->value; } unsigned int cm_stack_size(cm_stack_t stack) { - if (!stack) - return 0; - - return stack->size; -} \ No newline at end of file + if (!stack) + return 0; + + return stack->size; +} diff --git a/src/bncsutil/stack.h b/src/bncsutil/stack.h index c18197c..882b075 100644 --- a/src/bncsutil/stack.h +++ b/src/bncsutil/stack.h @@ -23,7 +23,7 @@ * Boston, MA 02111-1307 USA */ -/* +/** * Mule Server * Copyright (c) 2004-2006 Eric Naeseth. * @@ -35,13 +35,13 @@ #define CM_STACK_H_INCLUDED 1 typedef struct cm_stack_node { - void* value; - struct cm_stack_node* next; + void* value; + struct cm_stack_node* next; } cm_stack_node_t; typedef struct cm_stack { - unsigned int size; - cm_stack_node_t* top; + unsigned int size; + cm_stack_node_t* top; } *cm_stack_t; cm_stack_t cm_stack_create(); @@ -51,4 +51,4 @@ void* cm_stack_pop(cm_stack_t stack); void* cm_stack_peek(cm_stack_t stack); unsigned int cm_stack_size(cm_stack_t stack); -#endif \ No newline at end of file +#endif diff --git a/tests/checkrevision.c b/tests/checkrevision.c index fa1b95b..b17da36 100644 --- a/tests/checkrevision.c +++ b/tests/checkrevision.c @@ -1,69 +1,69 @@ -#include -#include - -typedef unsigned int uint32_t; - +#include +#include + +typedef unsigned int uint32_t; + typedef int (__stdcall *check_revision_t)(const char*, const char**, int, int, unsigned long*); -typedef int (__stdcall *exe_info_t)(const char*, char*, size_t, uint32_t*, int); -typedef int (__stdcall *ver_info_t)(char*); -typedef int (__stdcall *set_debug_t)(int); - -int main(int argc, char* argv[]) -{ - HMODULE lib; - check_revision_t check_revision; - exe_info_t exe_info; - ver_info_t ver_info; - set_debug_t set_debug; - const char* paths[] = { - "BNCSutil.dll", - "BNCSutil_1.1.dll" - }; - int has_debug[] = { 1, 0 }; - unsigned long checksum = 0; - uint32_t version = 0; - char exeInfo[1024]; - const unsigned long expectedChecksum = 0x98214637; - int i; - char lib_version[12]; - - const char formula[] = - "A=767237111 B=654373374 C=621868803 4 A=A+S B=B-C C=C-A A=A+B"; - - for (i = 0; i < 2; i++) { - lib = LoadLibrary(paths[i]); - if (!lib) { - printf("Failed to load \"%s\"\n", paths[i]); - continue; - } - - if (has_debug[i]) { - set_debug = (set_debug_t) GetProcAddress(lib, "bncsutil_set_debug_status"); - set_debug(0); - } - - ver_info = (ver_info_t) GetProcAddress(lib, "bncsutil_getVersionString"); - check_revision = (check_revision_t) GetProcAddress(lib, "checkRevision"); - exe_info = (exe_info_t) GetProcAddress(lib, "getExeInfo"); - - ver_info(lib_version); - printf("Using BNCSutil %s:\n", lib_version); - - if (!check_revision(formula, (argv + 1), (argc - 1), 7, &checksum)) { - printf("\tCheckRevision call failed.\n"); - continue; - } - printf("\tChecksum: 0x%08X\n", checksum); - - if (!exe_info(argv[1], exeInfo, 1024, &version, 1)) { - printf("\tGetExeInfo call failed.\n"); - continue; - } - printf("\tVersion: 0x%08X\n", version); - printf("\t%s\n", exeInfo); - - FreeLibrary(lib); - } - - return 0; -} +typedef int (__stdcall *exe_info_t)(const char*, char*, size_t, uint32_t*, int); +typedef int (__stdcall *ver_info_t)(char*); +typedef int (__stdcall *set_debug_t)(int); + +int main(int argc, char* argv[]) +{ + HMODULE lib; + check_revision_t check_revision; + exe_info_t exe_info; + ver_info_t ver_info; + set_debug_t set_debug; + const char* paths[] = { + "BNCSutil.dll", + "BNCSutil_1.1.dll" + }; + int has_debug[] = { 1, 0 }; + unsigned long checksum = 0; + uint32_t version = 0; + char exeInfo[1024]; + const unsigned long expectedChecksum = 0x98214637; + int i; + char lib_version[12]; + + const char formula[] = + "A=767237111 B=654373374 C=621868803 4 A=A+S B=B-C C=C-A A=A+B"; + + for (i = 0; i < 2; i++) { + lib = LoadLibrary(paths[i]); + if (!lib) { + printf("Failed to load \"%s\"\n", paths[i]); + continue; + } + + if (has_debug[i]) { + set_debug = (set_debug_t) GetProcAddress(lib, "bncsutil_set_debug_status"); + set_debug(0); + } + + ver_info = (ver_info_t) GetProcAddress(lib, "bncsutil_getVersionString"); + check_revision = (check_revision_t) GetProcAddress(lib, "checkRevision"); + exe_info = (exe_info_t) GetProcAddress(lib, "getExeInfo"); + + ver_info(lib_version); + printf("Using BNCSutil %s:\n", lib_version); + + if (!check_revision(formula, (argv + 1), (argc - 1), 7, &checksum)) { + printf("\tCheckRevision call failed.\n"); + continue; + } + printf("\tChecksum: 0x%08X\n", checksum); + + if (!exe_info(argv[1], exeInfo, 1024, &version, 1)) { + printf("\tGetExeInfo call failed.\n"); + continue; + } + printf("\tVersion: 0x%08X\n", version); + printf("\t%s\n", exeInfo); + + FreeLibrary(lib); + } + + return 0; +} diff --git a/tests/nls.cpp b/tests/nls.cpp index 1e8436a..d33d080 100644 --- a/tests/nls.cpp +++ b/tests/nls.cpp @@ -10,27 +10,27 @@ int main() { - char salt[32]; - char B[32]; - int i; - int j = 0; + char salt[32]; + char B[32]; + int i; + int j = 0; - for (i = 0; i < 32; i++) { - salt[i] = j++; - } - for (i = 0; i < 32; i++) { - B[i] = j++; - } + for (i = 0; i < 32; i++) { + salt[i] = j++; + } + for (i = 0; i < 32; i++) { + B[i] = j++; + } - NLS nls("Cloaked", "foo"); - bncsutil_debug_message("NLS Test"); - bncsutil_debug_message("Salt:"); - bncsutil_debug_dump(salt, 32); - bncsutil_debug_message("Client public key:"); - bncsutil_debug_dump(nls.getPublicKey(), 32); - bncsutil_debug_message("Server public key:"); - bncsutil_debug_dump(B, 32); - bncsutil_debug_message("Client session key:"); - bncsutil_debug_dump(nls.getClientSessionKey(salt, B), 20); - return 0; -} \ No newline at end of file + NLS nls("Cloaked", "foo"); + bncsutil_debug_message("NLS Test"); + bncsutil_debug_message("Salt:"); + bncsutil_debug_dump(salt, 32); + bncsutil_debug_message("Client public key:"); + bncsutil_debug_dump(nls.getPublicKey(), 32); + bncsutil_debug_message("Server public key:"); + bncsutil_debug_dump(B, 32); + bncsutil_debug_message("Client session key:"); + bncsutil_debug_dump(nls.getClientSessionKey(salt, B), 20); + return 0; +} diff --git a/vc8_build/BNCSutil.sln b/vc8_build/BNCSutil.sln deleted file mode 100644 index 8ca2162..0000000 --- a/vc8_build/BNCSutil.sln +++ /dev/null @@ -1,19 +0,0 @@ -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BNCSutil", "BNCSutil.vcproj", "{CFB9AEE6-C0BB-49B0-B0F5-F564975202B8}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CFB9AEE6-C0BB-49B0-B0F5-F564975202B8}.Debug|Win32.ActiveCfg = Debug|Win32 - {CFB9AEE6-C0BB-49B0-B0F5-F564975202B8}.Debug|Win32.Build.0 = Debug|Win32 - {CFB9AEE6-C0BB-49B0-B0F5-F564975202B8}.Release|Win32.ActiveCfg = Release|Win32 - {CFB9AEE6-C0BB-49B0-B0F5-F564975202B8}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/vc8_build/BNCSutil.vcproj b/vc8_build/BNCSutil.vcproj index ad37e93..8c04042 100644 --- a/vc8_build/BNCSutil.vcproj +++ b/vc8_build/BNCSutil.vcproj @@ -1,11 +1,12 @@ @@ -92,9 +95,6 @@ - @@ -156,6 +156,8 @@ SubSystem="2" OptimizeReferences="2" EnableCOMDATFolding="2" + RandomizedBaseAddress="1" + DataExecutionPrevention="0" ImportLibrary="$(OutDir)/BNCSutil.lib" TargetMachine="1" /> @@ -178,7 +180,171 @@ Name="VCAppVerifierTool" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + - - @@ -393,10 +619,6 @@ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" > - - diff --git a/vc8_build/BNCSutil1.aps b/vc8_build/BNCSutil1.aps deleted file mode 100644 index a042a20..0000000 Binary files a/vc8_build/BNCSutil1.aps and /dev/null differ diff --git a/vc8_build/BNCSutil1.rc b/vc8_build/BNCSutil1.rc deleted file mode 100644 index 8dd58cc..0000000 --- a/vc8_build/BNCSutil1.rc +++ /dev/null @@ -1,102 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource1.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource1.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,2,0,0 - PRODUCTVERSION 1,2,0,0 - FILEFLAGSMASK 0x17L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x2L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "CompanyName", "Cloaked" - VALUE "FileDescription", "BNCSutil Library" - VALUE "FileVersion", "1, 2, 0, 0" - VALUE "InternalName", "BNCSutil" - VALUE "LegalCopyright", "Copyright © 2004-2006 Eric Naeseth." - VALUE "OriginalFilename", "bncsutil.dll" - VALUE "ProductName", " BNCSutil Library" - VALUE "ProductVersion", "1, 2, 0, 0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/vc8_build/bncsutil.def b/vc8_build/bncsutil.def index ce3a416..32db61d 100644 --- a/vc8_build/bncsutil.def +++ b/vc8_build/bncsutil.def @@ -42,11 +42,4 @@ EXPORTS nls_check_M2=_nls_check_M2@16 @33 nls_check_signature=_nls_check_signature@8 @34 nls_account_change_proof=_nls_account_change_proof@20 @35 - - bncsutil_debug_message=_bncsutil_debug_message@4 @36 - bncsutil_debug_dump=_bncsutil_debug_dump@8 @37 - bncsutil_print_dump=_bncsutil_print_dump@12 @38 - bncsutil_print_dump_win=_bncsutil_print_dump_win@12 @39 - bncsutil_debug_status=_bncsutil_debug_status@0 @40 - bncsutil_set_debug_status=_bncsutil_set_debug_status@4 @41 - bncsutil_internal_debug_messages=_bncsutil_internal_debug_messages@0 @42 \ No newline at end of file + \ No newline at end of file diff --git a/vc8_build/bncsutil.rc b/vc8_build/bncsutil.rc deleted file mode 100644 index 3406a30..0000000 --- a/vc8_build/bncsutil.rc +++ /dev/null @@ -1,101 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,3,1,0 - PRODUCTVERSION 1,3,1,0 - FILEFLAGSMASK 0x17L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x0L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "Comments", "BNCSutil Logon Library" - VALUE "CompanyName", "ionws.com" - VALUE "FileDescription", "BNCSutil Logon Library" - VALUE "FileVersion", "1, 3, 1, 0" - VALUE "InternalName", "bncsutil" - VALUE "LegalCopyright", "Copyright © 2004-2006 Eric Naeseth." - VALUE "OriginalFilename", "BNCSutil.dll" - VALUE "ProductName", "BNCSutil Logon Library" - VALUE "ProductVersion", "1, 3, 1, 0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END - - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" -END - -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" -END - -#endif // APSTUDIO_INVOKED - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/vc8_build/gmp.lib b/vc8_build/gmp.lib new file mode 100644 index 0000000..b5e2d63 Binary files /dev/null and b/vc8_build/gmp.lib differ diff --git a/vc8_build/manual_link.bat b/vc8_build/manual_link.bat deleted file mode 100644 index 50d27d6..0000000 --- a/vc8_build/manual_link.bat +++ /dev/null @@ -1 +0,0 @@ -LINK /OUT:"Release/BNCSutil.dll" /INCREMENTAL:NO /NOLOGO /LIBPATH:".." /DLL /DEF:"bncsutil.def" /DEBUG /PDB:"Release/BNCSutil.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /IMPLIB:"Release/BNCSutil.lib" /MACHINE:X86 kernel32.lib version.lib gmp.lib Release\BNCSutil1.res Release\*.obj ..\manual_build\nls.o user32.lib \ No newline at end of file diff --git a/vc8_build/resource.h b/vc8_build/resource.h deleted file mode 100644 index 8a67e0c..0000000 --- a/vc8_build/resource.h +++ /dev/null @@ -1,1210 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by bncsutil.rc -// -#define SW_HIDE 0 -#define HIDE_WINDOW 0 -#define WM_NULL 0x0000 -#define WA_INACTIVE 0 -#define HTNOWHERE 0 -#define SMTO_NORMAL 0x0000 -#define ICON_SMALL 0 -#define SIZE_RESTORED 0 -#define BN_CLICKED 0 -#define BST_UNCHECKED 0x0000 -#define HDS_HORZ 0x0000 -#define TBS_HORZ 0x0000 -#define TBS_BOTTOM 0x0000 -#define TBS_RIGHT 0x0000 -#define LVS_ICON 0x0000 -#define LVS_ALIGNTOP 0x0000 -#define TCS_TABS 0x0000 -#define TCS_SINGLELINE 0x0000 -#define TCS_RIGHTJUSTIFY 0x0000 -#define DTS_SHORTDATEFORMAT 0x0000 -#define PGS_VERT 0x00000000 -#define LANG_NEUTRAL 0x00 -#define SUBLANG_NEUTRAL 0x00 -#define SORT_DEFAULT 0x0 -#define SORT_JAPANESE_XJIS 0x0 -#define SORT_CHINESE_BIG5 0x0 -#define SORT_CHINESE_PRCP 0x0 -#define SORT_KOREAN_KSC 0x0 -#define SORT_HUNGARIAN_DEFAULT 0x0 -#define SORT_GEORGIAN_TRADITIONAL 0x0 -#define CREATEPROCESS_MANIFEST_RESOURCE_ID 1 -#define MINIMUM_RESERVED_MANIFEST_RESOURCE_ID 1 -#define SW_SHOWNORMAL 1 -#define SW_NORMAL 1 -#define SHOW_OPENWINDOW 1 -#define SW_PARENTCLOSING 1 -#define VK_LBUTTON 0x01 -#define WM_CREATE 0x0001 -#define WA_ACTIVE 1 -#define PWR_OK 1 -#define PWR_SUSPENDREQUEST 1 -#define NFR_ANSI 1 -#define UIS_SET 1 -#define UISF_HIDEFOCUS 0x1 -#define XBUTTON1 0x0001 -#define WMSZ_LEFT 1 -#define HTCLIENT 1 -#define SMTO_BLOCK 0x0001 -#define MA_ACTIVATE 1 -#define ICON_BIG 1 -#define SIZE_MINIMIZED 1 -#define MK_LBUTTON 0x0001 -#define TME_HOVER 0x00000001 -#define CS_VREDRAW 0x0001 -#define CF_TEXT 1 -#define IDOK 1 -#define BN_PAINT 1 -#define BST_CHECKED 0x0001 -#define TTS_ALWAYSTIP 0x01 -#define TBS_AUTOTICKS 0x0001 -#define UDS_WRAP 0x0001 -#define PBS_SMOOTH 0x01 -#define LVS_REPORT 0x0001 -#define TVS_HASBUTTONS 0x0001 -#define TCS_SCROLLOPPOSITE 0x0001 -#define ACS_CENTER 0x0001 -#define MCS_DAYSTATE 0x0001 -#define DTS_UPDOWN 0x0001 -#define PGS_HORZ 0x00000001 -#define NFS_EDIT 0x0001 -#define LANG_ARABIC 0x01 -#define SUBLANG_DEFAULT 0x01 -#define SUBLANG_ARABIC_SAUDI_ARABIA 0x01 -#define SUBLANG_AZERI_LATIN 0x01 -#define SUBLANG_CHINESE_TRADITIONAL 0x01 -#define SUBLANG_DUTCH 0x01 -#define SUBLANG_ENGLISH_US 0x01 -#define SUBLANG_FRENCH 0x01 -#define SUBLANG_GERMAN 0x01 -#define SUBLANG_ITALIAN 0x01 -#define SUBLANG_KOREAN 0x01 -#define SUBLANG_LITHUANIAN 0x01 -#define SUBLANG_MALAY_MALAYSIA 0x01 -#define SUBLANG_NORWEGIAN_BOKMAL 0x01 -#define SUBLANG_PORTUGUESE_BRAZILIAN 0x01 -#define SUBLANG_SPANISH 0x01 -#define SUBLANG_SWEDISH 0x01 -#define SUBLANG_URDU_PAKISTAN 0x01 -#define SUBLANG_UZBEK_LATIN 0x01 -#define SORT_JAPANESE_UNICODE 0x1 -#define SORT_CHINESE_UNICODE 0x1 -#define SORT_KOREAN_UNICODE 0x1 -#define SORT_GERMAN_PHONE_BOOK 0x1 -#define SORT_HUNGARIAN_TECHNICAL 0x1 -#define SORT_GEORGIAN_MODERN 0x1 -#define VS_VERSION_INFO 1 -#define VFFF_ISSHAREDFILE 0x0001 -#define VFF_CURNEDEST 0x0001 -#define VIFF_FORCEINSTALL 0x0001 -#define ISOLATIONAWARE_MANIFEST_RESOURCE_ID 2 -#define SW_SHOWMINIMIZED 2 -#define SHOW_ICONWINDOW 2 -#define SW_OTHERZOOM 2 -#define VK_RBUTTON 0x02 -#define WM_DESTROY 0x0002 -#define WA_CLICKACTIVE 2 -#define PWR_SUSPENDRESUME 2 -#define NFR_UNICODE 2 -#define UIS_CLEAR 2 -#define UISF_HIDEACCEL 0x2 -#define XBUTTON2 0x0002 -#define WMSZ_RIGHT 2 -#define HTCAPTION 2 -#define SMTO_ABORTIFHUNG 0x0002 -#define MA_ACTIVATEANDEAT 2 -#define SIZE_MAXIMIZED 2 -#define MK_RBUTTON 0x0002 -#define TME_LEAVE 0x00000002 -#define CS_HREDRAW 0x0002 -#define CF_BITMAP 2 -#define IDCANCEL 2 -#define BN_HILITE 2 -#define BST_INDETERMINATE 0x0002 -#define HDS_BUTTONS 0x0002 -#define TTS_NOPREFIX 0x02 -#define TBS_VERT 0x0002 -#define UDS_SETBUDDYINT 0x0002 -#define LVS_SMALLICON 0x0002 -#define TVS_HASLINES 0x0002 -#define TCS_BOTTOM 0x0002 -#define TCS_RIGHT 0x0002 -#define ACS_TRANSPARENT 0x0002 -#define MCS_MULTISELECT 0x0002 -#define DTS_SHOWNONE 0x0002 -#define PGS_AUTOSCROLL 0x00000002 -#define NFS_STATIC 0x0002 -#define LANG_BULGARIAN 0x02 -#define SUBLANG_SYS_DEFAULT 0x02 -#define SUBLANG_ARABIC_IRAQ 0x02 -#define SUBLANG_AZERI_CYRILLIC 0x02 -#define SUBLANG_CHINESE_SIMPLIFIED 0x02 -#define SUBLANG_DUTCH_BELGIAN 0x02 -#define SUBLANG_ENGLISH_UK 0x02 -#define SUBLANG_FRENCH_BELGIAN 0x02 -#define SUBLANG_GERMAN_SWISS 0x02 -#define SUBLANG_ITALIAN_SWISS 0x02 -#define SUBLANG_KASHMIRI_INDIA 0x02 -#define SUBLANG_MALAY_BRUNEI_DARUSSALAM 0x02 -#define SUBLANG_NEPALI_INDIA 0x02 -#define SUBLANG_NORWEGIAN_NYNORSK 0x02 -#define SUBLANG_PORTUGUESE 0x02 -#define SUBLANG_SERBIAN_LATIN 0x02 -#define SUBLANG_SPANISH_MEXICAN 0x02 -#define SUBLANG_SWEDISH_FINLAND 0x02 -#define SUBLANG_URDU_INDIA 0x02 -#define SUBLANG_UZBEK_CYRILLIC 0x02 -#define SORT_CHINESE_PRC 0x2 -#define VFF_FILEINUSE 0x0002 -#define VIFF_DONTDELETEOLD 0x0002 -#define ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID 3 -#define SW_SHOWMAXIMIZED 3 -#define SW_MAXIMIZE 3 -#define SHOW_FULLSCREEN 3 -#define SW_PARENTOPENING 3 -#define VK_CANCEL 0x03 -#define WM_MOVE 0x0003 -#define PWR_CRITICALRESUME 3 -#define NF_QUERY 3 -#define UIS_INITIALIZE 3 -#define WMSZ_TOP 3 -#define HTSYSMENU 3 -#define MA_NOACTIVATE 3 -#define SIZE_MAXSHOW 3 -#define CF_METAFILEPICT 3 -#define IDABORT 3 -#define BN_UNHILITE 3 -#define LVS_LIST 0x0003 -#define LVS_TYPEMASK 0x0003 -#define LANG_CATALAN 0x03 -#define SUBLANG_ARABIC_EGYPT 0x03 -#define SUBLANG_CHINESE_HONGKONG 0x03 -#define SUBLANG_ENGLISH_AUS 0x03 -#define SUBLANG_FRENCH_CANADIAN 0x03 -#define SUBLANG_GERMAN_AUSTRIAN 0x03 -#define SUBLANG_SERBIAN_CYRILLIC 0x03 -#define SUBLANG_SPANISH_MODERN 0x03 -#define SORT_CHINESE_BOPOMOFO 0x3 -#define SW_SHOWNOACTIVATE 4 -#define SHOW_OPENNOACTIVATE 4 -#define SW_OTHERUNZOOM 4 -#define VK_MBUTTON 0x04 -#define NF_REQUERY 4 -#define WMSZ_TOPLEFT 4 -#define HTGROWBOX 4 -#define MA_NOACTIVATEANDEAT 4 -#define SIZE_MAXHIDE 4 -#define MK_SHIFT 0x0004 -#define CF_SYLK 4 -#define IDRETRY 4 -#define BN_DISABLE 4 -#define BST_PUSHED 0x0004 -#define HDS_HOTTRACK 0x0004 -#define TBS_TOP 0x0004 -#define TBS_LEFT 0x0004 -#define UDS_ALIGNRIGHT 0x0004 -#define PBS_VERTICAL 0x04 -#define LVS_SINGLESEL 0x0004 -#define TVS_LINESATROOT 0x0004 -#define TCS_MULTISELECT 0x0004 -#define ACS_AUTOPLAY 0x0004 -#define MCS_WEEKNUMBERS 0x0004 -#define DTS_LONGDATEFORMAT 0x0004 -#define PGS_DRAGNDROP 0x00000004 -#define NFS_LISTCOMBO 0x0004 -#define LANG_CHINESE 0x04 -#define SUBLANG_ARABIC_LIBYA 0x04 -#define SUBLANG_CHINESE_SINGAPORE 0x04 -#define SUBLANG_ENGLISH_CAN 0x04 -#define SUBLANG_FRENCH_SWISS 0x04 -#define SUBLANG_GERMAN_LUXEMBOURG 0x04 -#define SUBLANG_SPANISH_GUATEMALA 0x04 -#define VFF_BUFFTOOSMALL 0x0004 -#define SW_SHOW 5 -#define VK_XBUTTON1 0x05 -#define WM_SIZE 0x0005 -#define WMSZ_TOPRIGHT 5 -#define HTMENU 5 -#define CF_DIF 5 -#define IDIGNORE 5 -#define BN_DOUBLECLICKED 5 -#define LANG_CZECH 0x05 -#define SUBLANG_ARABIC_ALGERIA 0x05 -#define SUBLANG_CHINESE_MACAU 0x05 -#define SUBLANG_ENGLISH_NZ 0x05 -#define SUBLANG_FRENCH_LUXEMBOURG 0x05 -#define SUBLANG_GERMAN_LIECHTENSTEIN 0x05 -#define SUBLANG_SPANISH_COSTA_RICA 0x05 -#define SW_MINIMIZE 6 -#define VK_XBUTTON2 0x06 -#define WM_ACTIVATE 0x0006 -#define WMSZ_BOTTOM 6 -#define HTHSCROLL 6 -#define CF_TIFF 6 -#define IDYES 6 -#define BN_SETFOCUS 6 -#define LANG_DANISH 0x06 -#define SUBLANG_ARABIC_MOROCCO 0x06 -#define SUBLANG_ENGLISH_EIRE 0x06 -#define SUBLANG_FRENCH_MONACO 0x06 -#define SUBLANG_SPANISH_PANAMA 0x06 -#define SW_SHOWMINNOACTIVE 7 -#define WM_SETFOCUS 0x0007 -#define WMSZ_BOTTOMLEFT 7 -#define HTVSCROLL 7 -#define CF_OEMTEXT 7 -#define IDNO 7 -#define BN_KILLFOCUS 7 -#define LANG_GERMAN 0x07 -#define SUBLANG_ARABIC_TUNISIA 0x07 -#define SUBLANG_ENGLISH_SOUTH_AFRICA 0x07 -#define SUBLANG_SPANISH_DOMINICAN_REPUBLIC 0x07 -#define SW_SHOWNA 8 -#define VK_BACK 0x08 -#define WM_KILLFOCUS 0x0008 -#define WMSZ_BOTTOMRIGHT 8 -#define HTMINBUTTON 8 -#define SMTO_NOTIMEOUTIFNOTHUNG 0x0008 -#define MK_CONTROL 0x0008 -#define CS_DBLCLKS 0x0008 -#define CF_DIB 8 -#define IDCLOSE 8 -#define BST_FOCUS 0x0008 -#define HDS_HIDDEN 0x0008 -#define TBS_BOTH 0x0008 -#define UDS_ALIGNLEFT 0x0008 -#define LVS_SHOWSELALWAYS 0x0008 -#define TVS_EDITLABELS 0x0008 -#define TCS_FLATBUTTONS 0x0008 -#define ACS_TIMER 0x0008 -#define MCS_NOTODAYCIRCLE 0x0008 -#define NFS_BUTTON 0x0008 -#define LANG_GREEK 0x08 -#define SUBLANG_ARABIC_OMAN 0x08 -#define SUBLANG_ENGLISH_JAMAICA 0x08 -#define SUBLANG_SPANISH_VENEZUELA 0x08 -#define SW_RESTORE 9 -#define VK_TAB 0x09 -#define HTMAXBUTTON 9 -#define CF_PALETTE 9 -#define IDHELP 9 -#define DTS_TIMEFORMAT 0x0009 -#define LANG_ENGLISH 0x09 -#define SUBLANG_ARABIC_YEMEN 0x09 -#define SUBLANG_ENGLISH_CARIBBEAN 0x09 -#define SUBLANG_SPANISH_COLOMBIA 0x09 -#define SW_SHOWDEFAULT 10 -#define WM_ENABLE 0x000A -#define HTLEFT 10 -#define CF_PENDATA 10 -#define IDTRYAGAIN 10 -#define HELP_CONTEXTMENU 0x000a -#define LANG_SPANISH 0x0a -#define SUBLANG_ARABIC_SYRIA 0x0a -#define SUBLANG_ENGLISH_BELIZE 0x0a -#define SUBLANG_SPANISH_PERU 0x0a -#define SW_FORCEMINIMIZE 11 -#define SW_MAX 11 -#define WM_SETREDRAW 0x000B -#define HTRIGHT 11 -#define CF_RIFF 11 -#define IDCONTINUE 11 -#define HELP_FINDER 0x000b -#define LANG_FINNISH 0x0b -#define SUBLANG_ARABIC_JORDAN 0x0b -#define SUBLANG_ENGLISH_TRINIDAD 0x0b -#define SUBLANG_SPANISH_ARGENTINA 0x0b -#define VK_CLEAR 0x0C -#define WM_SETTEXT 0x000C -#define HTTOP 12 -#define CF_WAVE 12 -#define HELP_WM_HELP 0x000c -#define DTS_SHORTDATECENTURYFORMAT 0x000C -#define LANG_FRENCH 0x0c -#define SUBLANG_ARABIC_LEBANON 0x0c -#define SUBLANG_ENGLISH_ZIMBABWE 0x0c -#define SUBLANG_SPANISH_ECUADOR 0x0c -#define VK_RETURN 0x0D -#define WM_GETTEXT 0x000D -#define HTTOPLEFT 13 -#define CF_UNICODETEXT 13 -#define HELP_SETPOPUP_POS 0x000d -#define LANG_HEBREW 0x0d -#define SUBLANG_ARABIC_KUWAIT 0x0d -#define SUBLANG_ENGLISH_PHILIPPINES 0x0d -#define SUBLANG_SPANISH_CHILE 0x0d -#define WM_GETTEXTLENGTH 0x000E -#define HTTOPRIGHT 14 -#define CF_ENHMETAFILE 14 -#define LANG_HUNGARIAN 0x0e -#define SUBLANG_ARABIC_UAE 0x0e -#define SUBLANG_SPANISH_URUGUAY 0x0e -#define WM_PAINT 0x000F -#define HTBOTTOM 15 -#define CF_HDROP 15 -#define LANG_ICELANDIC 0x0f -#define SUBLANG_ARABIC_BAHRAIN 0x0f -#define SUBLANG_SPANISH_PARAGUAY 0x0f -#define MAXIMUM_RESERVED_MANIFEST_RESOURCE_ID 16 -#define VK_SHIFT 0x10 -#define WM_CLOSE 0x0010 -#define HTBOTTOMLEFT 16 -#define WVR_ALIGNTOP 0x0010 -#define MK_MBUTTON 0x0010 -#define TME_NONCLIENT 0x00000010 -#define CF_LOCALE 16 -#define HELP_TCARD_DATA 0x0010 -#define TTS_NOANIMATE 0x10 -#define TBS_NOTICKS 0x0010 -#define UDS_AUTOBUDDY 0x0010 -#define LVS_SORTASCENDING 0x0010 -#define TVS_DISABLEDRAGDROP 0x0010 -#define TCS_FORCEICONLEFT 0x0010 -#define MCS_NOTODAY 0x0010 -#define DTS_APPCANPARSE 0x0010 -#define NFS_ALL 0x0010 -#define LANG_ITALIAN 0x10 -#define SUBLANG_ARABIC_QATAR 0x10 -#define SUBLANG_SPANISH_BOLIVIA 0x10 -#define VK_CONTROL 0x11 -#define WM_QUERYENDSESSION 0x0011 -#define HTBOTTOMRIGHT 17 -#define CF_DIBV5 17 -#define HELP_TCARD_OTHER_CALLER 0x0011 -#define LANG_JAPANESE 0x11 -#define SUBLANG_SPANISH_EL_SALVADOR 0x11 -#define VK_MENU 0x12 -#define WM_QUIT 0x0012 -#define HTBORDER 18 -#define CF_MAX 18 -#define LANG_KOREAN 0x12 -#define SUBLANG_SPANISH_HONDURAS 0x12 -#define VK_PAUSE 0x13 -#define WM_QUERYOPEN 0x0013 -#define HTOBJECT 19 -#define LANG_DUTCH 0x13 -#define SUBLANG_SPANISH_NICARAGUA 0x13 -#define VK_CAPITAL 0x14 -#define WM_ERASEBKGND 0x0014 -#define HTCLOSE 20 -#define LANG_NORWEGIAN 0x14 -#define SUBLANG_SPANISH_PUERTO_RICO 0x14 -#define VK_KANA 0x15 -#define VK_HANGEUL 0x15 -#define VK_HANGUL 0x15 -#define WM_SYSCOLORCHANGE 0x0015 -#define HTHELP 21 -#define LANG_POLISH 0x15 -#define WM_ENDSESSION 0x0016 -#define LANG_PORTUGUESE 0x16 -#define VK_JUNJA 0x17 -#define RT_MANIFEST 24 -#define VK_FINAL 0x18 -#define WM_SHOWWINDOW 0x0018 -#define LANG_ROMANIAN 0x18 -#define VK_HANJA 0x19 -#define VK_KANJI 0x19 -#define LANG_RUSSIAN 0x19 -#define WM_WININICHANGE 0x001A -#define LANG_CROATIAN 0x1a -#define LANG_SERBIAN 0x1a -#define VK_ESCAPE 0x1B -#define WM_DEVMODECHANGE 0x001B -#define LANG_SLOVAK 0x1b -#define VK_CONVERT 0x1C -#define WM_ACTIVATEAPP 0x001C -#define LANG_ALBANIAN 0x1c -#define VK_NONCONVERT 0x1D -#define WM_FONTCHANGE 0x001D -#define LANG_SWEDISH 0x1d -#define VK_ACCEPT 0x1E -#define WM_TIMECHANGE 0x001E -#define LANG_THAI 0x1e -#define VK_MODECHANGE 0x1F -#define WM_CANCELMODE 0x001F -#define LANG_TURKISH 0x1f -#define VK_SPACE 0x20 -#define WM_SETCURSOR 0x0020 -#define WVR_ALIGNLEFT 0x0020 -#define MK_XBUTTON1 0x0020 -#define CS_OWNDC 0x0020 -#define TTS_NOFADE 0x20 -#define TBS_ENABLESELRANGE 0x0020 -#define UDS_ARROWKEYS 0x0020 -#define LVS_SORTDESCENDING 0x0020 -#define TVS_SHOWSELALWAYS 0x0020 -#define TCS_FORCELABELLEFT 0x0020 -#define DTS_RIGHTALIGN 0x0020 -#define NFS_USEFONTASSOC 0x0020 -#define LANG_URDU 0x20 -#define VK_PRIOR 0x21 -#define WM_MOUSEACTIVATE 0x0021 -#define LANG_INDONESIAN 0x21 -#define VK_NEXT 0x22 -#define WM_CHILDACTIVATE 0x0022 -#define LANG_UKRAINIAN 0x22 -#define VK_END 0x23 -#define WM_QUEUESYNC 0x0023 -#define LANG_BELARUSIAN 0x23 -#define VK_HOME 0x24 -#define WM_GETMINMAXINFO 0x0024 -#define LANG_SLOVENIAN 0x24 -#define VK_LEFT 0x25 -#define LANG_ESTONIAN 0x25 -#define VK_UP 0x26 -#define WM_PAINTICON 0x0026 -#define LANG_LATVIAN 0x26 -#define VK_RIGHT 0x27 -#define WM_ICONERASEBKGND 0x0027 -#define LANG_LITHUANIAN 0x27 -#define VK_DOWN 0x28 -#define WM_NEXTDLGCTL 0x0028 -#define VK_SELECT 0x29 -#define LANG_FARSI 0x29 -#define VK_PRINT 0x2A -#define WM_SPOOLERSTATUS 0x002A -#define LANG_VIETNAMESE 0x2a -#define VK_EXECUTE 0x2B -#define WM_DRAWITEM 0x002B -#define LANG_ARMENIAN 0x2b -#define VK_SNAPSHOT 0x2C -#define WM_MEASUREITEM 0x002C -#define LANG_AZERI 0x2c -#define VK_INSERT 0x2D -#define WM_DELETEITEM 0x002D -#define LANG_BASQUE 0x2d -#define VK_DELETE 0x2E -#define WM_VKEYTOITEM 0x002E -#define VK_HELP 0x2F -#define WM_CHARTOITEM 0x002F -#define LANG_MACEDONIAN 0x2f -#define WM_SETFONT 0x0030 -#define WM_GETFONT 0x0031 -#define WM_SETHOTKEY 0x0032 -#define WM_GETHOTKEY 0x0033 -#define LANG_AFRIKAANS 0x36 -#define WM_QUERYDRAGICON 0x0037 -#define LANG_GEORGIAN 0x37 -#define LANG_FAEROESE 0x38 -#define WM_COMPAREITEM 0x0039 -#define LANG_HINDI 0x39 -#define WM_GETOBJECT 0x003D -#define LANG_MALAY 0x3e -#define LANG_KAZAK 0x3f -#define WVR_ALIGNBOTTOM 0x0040 -#define MK_XBUTTON2 0x0040 -#define CS_CLASSDC 0x0040 -#define HDS_DRAGDROP 0x0040 -#define TTS_BALLOON 0x40 -#define TBS_FIXEDLENGTH 0x0040 -#define UDS_HORZ 0x0040 -#define LVS_SHAREIMAGELISTS 0x0040 -#define TVS_RTLREADING 0x0040 -#define TCS_HOTTRACK 0x0040 -#define LANG_KYRGYZ 0x40 -#define WM_COMPACTING 0x0041 -#define LANG_SWAHILI 0x41 -#define LANG_UZBEK 0x43 -#define WM_COMMNOTIFY 0x0044 -#define LANG_TATAR 0x44 -#define LANG_BENGALI 0x45 -#define WM_WINDOWPOSCHANGING 0x0046 -#define LANG_PUNJABI 0x46 -#define WM_WINDOWPOSCHANGED 0x0047 -#define LANG_GUJARATI 0x47 -#define WM_POWER 0x0048 -#define LANG_ORIYA 0x48 -#define LANG_TAMIL 0x49 -#define WM_COPYDATA 0x004A -#define LANG_TELUGU 0x4a -#define WM_CANCELJOURNAL 0x004B -#define LANG_KANNADA 0x4b -#define LANG_MALAYALAM 0x4c -#define LANG_ASSAMESE 0x4d -#define WM_NOTIFY 0x004E -#define LANG_MARATHI 0x4e -#define LANG_SANSKRIT 0x4f -#define WM_INPUTLANGCHANGEREQUEST 0x0050 -#define LANG_MONGOLIAN 0x50 -#define WM_INPUTLANGCHANGE 0x0051 -#define WM_TCARD 0x0052 -#define WM_HELP 0x0053 -#define WM_USERCHANGED 0x0054 -#define WM_NOTIFYFORMAT 0x0055 -#define LANG_GALICIAN 0x56 -#define LANG_KONKANI 0x57 -#define LANG_MANIPURI 0x58 -#define LANG_SINDHI 0x59 -#define LANG_SYRIAC 0x5a -#define VK_LWIN 0x5B -#define VK_RWIN 0x5C -#define VK_APPS 0x5D -#define VK_SLEEP 0x5F -#define VK_NUMPAD0 0x60 -#define LANG_KASHMIRI 0x60 -#define VK_NUMPAD1 0x61 -#define LANG_NEPALI 0x61 -#define VK_NUMPAD2 0x62 -#define VK_NUMPAD3 0x63 -#define VK_NUMPAD4 0x64 -#define VS_USER_DEFINED 100 -#define VK_NUMPAD5 0x65 -#define LANG_DIVEHI 0x65 -#define VK_NUMPAD6 0x66 -#define VK_NUMPAD7 0x67 -#define VK_NUMPAD8 0x68 -#define VK_NUMPAD9 0x69 -#define VK_MULTIPLY 0x6A -#define VK_ADD 0x6B -#define VK_SEPARATOR 0x6C -#define VK_SUBTRACT 0x6D -#define VK_DECIMAL 0x6E -#define VK_DIVIDE 0x6F -#define VK_F1 0x70 -#define VK_F2 0x71 -#define VK_F3 0x72 -#define VK_F4 0x73 -#define VK_F5 0x74 -#define VK_F6 0x75 -#define VK_F7 0x76 -#define VK_F8 0x77 -#define VK_F9 0x78 -#define WHEEL_DELTA 120 -#define VK_F10 0x79 -#define VK_F11 0x7A -#define VK_F12 0x7B -#define WM_CONTEXTMENU 0x007B -#define VK_F13 0x7C -#define WM_STYLECHANGING 0x007C -#define VK_F14 0x7D -#define WM_STYLECHANGED 0x007D -#define VK_F15 0x7E -#define WM_DISPLAYCHANGE 0x007E -#define VK_F16 0x7F -#define WM_GETICON 0x007F -#define LANG_INVARIANT 0x7f -#define VK_F17 0x80 -#define WM_SETICON 0x0080 -#define WVR_ALIGNRIGHT 0x0080 -#define CS_PARENTDC 0x0080 -#define CF_OWNERDISPLAY 0x0080 -#define HDS_FULLDRAG 0x0080 -#define TTS_CLOSE 0x80 -#define TBS_NOTHUMB 0x0080 -#define UDS_NOTHOUSANDS 0x0080 -#define LVS_NOLABELWRAP 0x0080 -#define TVS_NOTOOLTIPS 0x0080 -#define TCS_VERTICAL 0x0080 -#define VK_F18 0x81 -#define WM_NCCREATE 0x0081 -#define CF_DSPTEXT 0x0081 -#define VK_F19 0x82 -#define WM_NCDESTROY 0x0082 -#define CF_DSPBITMAP 0x0082 -#define VK_F20 0x83 -#define WM_NCCALCSIZE 0x0083 -#define CF_DSPMETAFILEPICT 0x0083 -#define VK_F21 0x84 -#define WM_NCHITTEST 0x0084 -#define VK_F22 0x85 -#define WM_NCPAINT 0x0085 -#define VK_F23 0x86 -#define WM_NCACTIVATE 0x0086 -#define VK_F24 0x87 -#define WM_GETDLGCODE 0x0087 -#define WM_SYNCPAINT 0x0088 -#define CF_DSPENHMETAFILE 0x008E -#define VK_NUMLOCK 0x90 -#define VK_SCROLL 0x91 -#define VK_OEM_NEC_EQUAL 0x92 -#define VK_OEM_FJ_JISHO 0x92 -#define VK_OEM_FJ_MASSHOU 0x93 -#define VK_OEM_FJ_TOUROKU 0x94 -#define VK_OEM_FJ_LOYA 0x95 -#define VK_OEM_FJ_ROYA 0x96 -#define VK_LSHIFT 0xA0 -#define WM_NCMOUSEMOVE 0x00A0 -#define VK_RSHIFT 0xA1 -#define WM_NCLBUTTONDOWN 0x00A1 -#define VK_LCONTROL 0xA2 -#define WM_NCLBUTTONUP 0x00A2 -#define VK_RCONTROL 0xA3 -#define WM_NCLBUTTONDBLCLK 0x00A3 -#define VK_LMENU 0xA4 -#define WM_NCRBUTTONDOWN 0x00A4 -#define VK_RMENU 0xA5 -#define WM_NCRBUTTONUP 0x00A5 -#define VK_BROWSER_BACK 0xA6 -#define WM_NCRBUTTONDBLCLK 0x00A6 -#define VK_BROWSER_FORWARD 0xA7 -#define WM_NCMBUTTONDOWN 0x00A7 -#define VK_BROWSER_REFRESH 0xA8 -#define WM_NCMBUTTONUP 0x00A8 -#define VK_BROWSER_STOP 0xA9 -#define WM_NCMBUTTONDBLCLK 0x00A9 -#define VK_BROWSER_SEARCH 0xAA -#define VK_BROWSER_FAVORITES 0xAB -#define WM_NCXBUTTONDOWN 0x00AB -#define VK_BROWSER_HOME 0xAC -#define WM_NCXBUTTONUP 0x00AC -#define VK_VOLUME_MUTE 0xAD -#define WM_NCXBUTTONDBLCLK 0x00AD -#define VK_VOLUME_DOWN 0xAE -#define VK_VOLUME_UP 0xAF -#define VK_MEDIA_NEXT_TRACK 0xB0 -#define EM_GETSEL 0x00B0 -#define VK_MEDIA_PREV_TRACK 0xB1 -#define EM_SETSEL 0x00B1 -#define VK_MEDIA_STOP 0xB2 -#define EM_GETRECT 0x00B2 -#define VK_MEDIA_PLAY_PAUSE 0xB3 -#define EM_SETRECT 0x00B3 -#define VK_LAUNCH_MAIL 0xB4 -#define EM_SETRECTNP 0x00B4 -#define VK_LAUNCH_MEDIA_SELECT 0xB5 -#define EM_SCROLL 0x00B5 -#define VK_LAUNCH_APP1 0xB6 -#define EM_LINESCROLL 0x00B6 -#define VK_LAUNCH_APP2 0xB7 -#define EM_SCROLLCARET 0x00B7 -#define EM_GETMODIFY 0x00B8 -#define EM_SETMODIFY 0x00B9 -#define VK_OEM_1 0xBA -#define EM_GETLINECOUNT 0x00BA -#define VK_OEM_PLUS 0xBB -#define EM_LINEINDEX 0x00BB -#define VK_OEM_COMMA 0xBC -#define EM_SETHANDLE 0x00BC -#define VK_OEM_MINUS 0xBD -#define EM_GETHANDLE 0x00BD -#define VK_OEM_PERIOD 0xBE -#define EM_GETTHUMB 0x00BE -#define VK_OEM_2 0xBF -#define VK_OEM_3 0xC0 -#define EM_LINELENGTH 0x00C1 -#define EM_REPLACESEL 0x00C2 -#define EM_GETLINE 0x00C4 -#define EM_LIMITTEXT 0x00C5 -#define EM_CANUNDO 0x00C6 -#define EM_UNDO 0x00C7 -#define EM_FMTLINES 0x00C8 -#define EM_LINEFROMCHAR 0x00C9 -#define EM_SETTABSTOPS 0x00CB -#define EM_SETPASSWORDCHAR 0x00CC -#define EM_EMPTYUNDOBUFFER 0x00CD -#define EM_GETFIRSTVISIBLELINE 0x00CE -#define EM_SETREADONLY 0x00CF -#define EM_SETWORDBREAKPROC 0x00D0 -#define EM_GETWORDBREAKPROC 0x00D1 -#define EM_GETPASSWORDCHAR 0x00D2 -#define EM_SETMARGINS 0x00D3 -#define EM_GETMARGINS 0x00D4 -#define EM_GETLIMITTEXT 0x00D5 -#define EM_POSFROMCHAR 0x00D6 -#define EM_CHARFROMPOS 0x00D7 -#define EM_SETIMESTATUS 0x00D8 -#define EM_GETIMESTATUS 0x00D9 -#define VK_OEM_4 0xDB -#define VK_OEM_5 0xDC -#define VK_OEM_6 0xDD -#define VK_OEM_7 0xDE -#define VK_OEM_8 0xDF -#define VK_OEM_AX 0xE1 -#define VK_OEM_102 0xE2 -#define VK_ICO_HELP 0xE3 -#define VK_ICO_00 0xE4 -#define VK_PROCESSKEY 0xE5 -#define VK_ICO_CLEAR 0xE6 -#define VK_PACKET 0xE7 -#define VK_OEM_RESET 0xE9 -#define VK_OEM_JUMP 0xEA -#define VK_OEM_PA1 0xEB -#define VK_OEM_PA2 0xEC -#define VK_OEM_PA3 0xED -#define VK_OEM_WSCTRL 0xEE -#define VK_OEM_CUSEL 0xEF -#define VK_OEM_ATTN 0xF0 -#define BM_GETCHECK 0x00F0 -#define VK_OEM_FINISH 0xF1 -#define BM_SETCHECK 0x00F1 -#define VK_OEM_COPY 0xF2 -#define BM_GETSTATE 0x00F2 -#define VK_OEM_AUTO 0xF3 -#define BM_SETSTATE 0x00F3 -#define VK_OEM_ENLW 0xF4 -#define BM_SETSTYLE 0x00F4 -#define VK_OEM_BACKTAB 0xF5 -#define BM_CLICK 0x00F5 -#define VK_ATTN 0xF6 -#define BM_GETIMAGE 0x00F6 -#define VK_CRSEL 0xF7 -#define BM_SETIMAGE 0x00F7 -#define VK_EXSEL 0xF8 -#define VK_EREOF 0xF9 -#define VK_PLAY 0xFA -#define VK_ZOOM 0xFB -#define VK_NONAME 0xFC -#define VK_PA1 0xFD -#define VK_OEM_CLEAR 0xFE -#define WM_KEYFIRST 0x0100 -#define WM_KEYDOWN 0x0100 -#define WVR_HREDRAW 0x0100 -#define HDS_FILTERBAR 0x0100 -#define RBS_TOOLTIPS 0x0100 -#define SBARS_SIZEGRIP 0x0100 -#define TBS_TOOLTIPS 0x0100 -#define UDS_HOTTRACK 0x0100 -#define LVS_AUTOARRANGE 0x0100 -#define TVS_CHECKBOXES 0x0100 -#define TCS_BUTTONS 0x0100 -#define WM_KEYUP 0x0101 -#define WM_CHAR 0x0102 -#define WM_DEADCHAR 0x0103 -#define WM_SYSKEYDOWN 0x0104 -#define WM_SYSKEYUP 0x0105 -#define WM_SYSCHAR 0x0106 -#define WM_SYSDEADCHAR 0x0107 -#define WM_KEYLAST 0x0108 -#define WM_IME_STARTCOMPOSITION 0x010D -#define WM_IME_ENDCOMPOSITION 0x010E -#define WM_IME_COMPOSITION 0x010F -#define WM_IME_KEYLAST 0x010F -#define WM_INITDIALOG 0x0110 -#define WM_COMMAND 0x0111 -#define WM_SYSCOMMAND 0x0112 -#define WM_TIMER 0x0113 -#define WM_HSCROLL 0x0114 -#define WM_VSCROLL 0x0115 -#define WM_INITMENU 0x0116 -#define WM_INITMENUPOPUP 0x0117 -#define WM_MENUSELECT 0x011F -#define WM_MENUCHAR 0x0120 -#define WM_ENTERIDLE 0x0121 -#define WM_MENURBUTTONUP 0x0122 -#define WM_MENUDRAG 0x0123 -#define WM_MENUGETOBJECT 0x0124 -#define WM_UNINITMENUPOPUP 0x0125 -#define WM_MENUCOMMAND 0x0126 -#define WM_CHANGEUISTATE 0x0127 -#define WM_UPDATEUISTATE 0x0128 -#define WM_QUERYUISTATE 0x0129 -#define WM_CTLCOLORMSGBOX 0x0132 -#define WM_CTLCOLOREDIT 0x0133 -#define WM_CTLCOLORLISTBOX 0x0134 -#define WM_CTLCOLORBTN 0x0135 -#define WM_CTLCOLORDLG 0x0136 -#define WM_CTLCOLORSCROLLBAR 0x0137 -#define WM_CTLCOLORSTATIC 0x0138 -#define MN_GETHMENU 0x01E1 -#define WM_MOUSEFIRST 0x0200 -#define WM_MOUSEMOVE 0x0200 -#define WVR_VREDRAW 0x0200 -#define CS_NOCLOSE 0x0200 -#define CF_PRIVATEFIRST 0x0200 -#define RBS_VARHEIGHT 0x0200 -#define TBS_REVERSED 0x0200 -#define LVS_EDITLABELS 0x0200 -#define TVS_TRACKSELECT 0x0200 -#define TCS_MULTILINE 0x0200 -#define WM_LBUTTONDOWN 0x0201 -#define WM_LBUTTONUP 0x0202 -#define WM_LBUTTONDBLCLK 0x0203 -#define WM_RBUTTONDOWN 0x0204 -#define WM_RBUTTONUP 0x0205 -#define WM_RBUTTONDBLCLK 0x0206 -#define WM_MBUTTONDOWN 0x0207 -#define WM_MBUTTONUP 0x0208 -#define WM_MBUTTONDBLCLK 0x0209 -#define WM_MOUSEWHEEL 0x020A -#define WM_XBUTTONDOWN 0x020B -#define WM_XBUTTONUP 0x020C -#define WM_XBUTTONDBLCLK 0x020D -#define WM_MOUSELAST 0x020D -#define WM_PARENTNOTIFY 0x0210 -#define WM_ENTERMENULOOP 0x0211 -#define WM_EXITMENULOOP 0x0212 -#define WM_NEXTMENU 0x0213 -#define WM_SIZING 0x0214 -#define WM_CAPTURECHANGED 0x0215 -#define WM_MOVING 0x0216 -#define WM_POWERBROADCAST 0x0218 -#define WM_DEVICECHANGE 0x0219 -#define WM_MDICREATE 0x0220 -#define WM_MDIDESTROY 0x0221 -#define WM_MDIACTIVATE 0x0222 -#define WM_MDIRESTORE 0x0223 -#define WM_MDINEXT 0x0224 -#define WM_MDIMAXIMIZE 0x0225 -#define WM_MDITILE 0x0226 -#define WM_MDICASCADE 0x0227 -#define WM_MDIICONARRANGE 0x0228 -#define WM_MDIGETACTIVE 0x0229 -#define WM_MDISETMENU 0x0230 -#define WM_ENTERSIZEMOVE 0x0231 -#define WM_EXITSIZEMOVE 0x0232 -#define WM_DROPFILES 0x0233 -#define WM_MDIREFRESHMENU 0x0234 -#define WM_IME_SETCONTEXT 0x0281 -#define WM_IME_NOTIFY 0x0282 -#define WM_IME_CONTROL 0x0283 -#define WM_IME_COMPOSITIONFULL 0x0284 -#define WM_IME_SELECT 0x0285 -#define WM_IME_CHAR 0x0286 -#define WM_IME_REQUEST 0x0288 -#define WM_IME_KEYDOWN 0x0290 -#define WM_IME_KEYUP 0x0291 -#define WM_NCMOUSEHOVER 0x02A0 -#define WM_MOUSEHOVER 0x02A1 -#define WM_NCMOUSELEAVE 0x02A2 -#define WM_MOUSELEAVE 0x02A3 -#define CF_PRIVATELAST 0x02FF -#define WM_CUT 0x0300 -#define CF_GDIOBJFIRST 0x0300 -#define WM_COPY 0x0301 -#define WM_PASTE 0x0302 -#define WM_CLEAR 0x0303 -#define WM_UNDO 0x0304 -#define WM_RENDERFORMAT 0x0305 -#define WM_RENDERALLFORMATS 0x0306 -#define WM_DESTROYCLIPBOARD 0x0307 -#define WM_DRAWCLIPBOARD 0x0308 -#define WM_PAINTCLIPBOARD 0x0309 -#define WM_VSCROLLCLIPBOARD 0x030A -#define WM_SIZECLIPBOARD 0x030B -#define WM_ASKCBFORMATNAME 0x030C -#define WM_CHANGECBCHAIN 0x030D -#define WM_HSCROLLCLIPBOARD 0x030E -#define WM_QUERYNEWPALETTE 0x030F -#define WM_PALETTEISCHANGING 0x0310 -#define WM_PALETTECHANGED 0x0311 -#define WM_HOTKEY 0x0312 -#define WM_PRINT 0x0317 -#define WM_PRINTCLIENT 0x0318 -#define WM_APPCOMMAND 0x0319 -#define WM_HANDHELDFIRST 0x0358 -#define WM_HANDHELDLAST 0x035F -#define WM_AFXFIRST 0x0360 -#define WM_AFXLAST 0x037F -#define WM_PENWINFIRST 0x0380 -#define WM_PENWINLAST 0x038F -#define WM_DDE_FIRST 0x03E0 -#define CF_GDIOBJLAST 0x03FF -#define WM_USER 0x0400 -#define WVR_VALIDRECTS 0x0400 -#define RBS_BANDBORDERS 0x0400 -#define TBS_DOWNISLEFT 0x0400 -#define LVS_OWNERDRAWFIXED 0x0400 -#define TVS_SINGLEEXPAND 0x0400 -#define TCS_FIXEDWIDTH 0x0400 -#define ctlFirst 0x0400 -#define psh1 0x0400 -#define psh2 0x0401 -#define psh3 0x0402 -#define psh4 0x0403 -#define psh5 0x0404 -#define psh6 0x0405 -#define psh7 0x0406 -#define psh8 0x0407 -#define psh9 0x0408 -#define psh10 0x0409 -#define psh11 0x040a -#define psh12 0x040b -#define psh13 0x040c -#define psh14 0x040d -#define psh15 0x040e -#define psh16 0x040f -#define _WIN32_WINDOWS 0x0410 -#define chx1 0x0410 -#define chx2 0x0411 -#define chx3 0x0412 -#define chx4 0x0413 -#define chx5 0x0414 -#define chx6 0x0415 -#define chx7 0x0416 -#define chx8 0x0417 -#define chx9 0x0418 -#define chx10 0x0419 -#define chx11 0x041a -#define chx12 0x041b -#define chx13 0x041c -#define chx14 0x041d -#define chx15 0x041e -#define chx16 0x041f -#define rad1 0x0420 -#define rad2 0x0421 -#define rad3 0x0422 -#define rad4 0x0423 -#define rad5 0x0424 -#define rad6 0x0425 -#define rad7 0x0426 -#define rad8 0x0427 -#define rad9 0x0428 -#define rad10 0x0429 -#define rad11 0x042a -#define rad12 0x042b -#define rad13 0x042c -#define rad14 0x042d -#define rad15 0x042e -#define rad16 0x042f -#define grp1 0x0430 -#define grp2 0x0431 -#define grp3 0x0432 -#define grp4 0x0433 -#define frm1 0x0434 -#define frm2 0x0435 -#define frm3 0x0436 -#define frm4 0x0437 -#define rct1 0x0438 -#define rct2 0x0439 -#define rct3 0x043a -#define rct4 0x043b -#define ico1 0x043c -#define ico2 0x043d -#define ico3 0x043e -#define ico4 0x043f -#define stc1 0x0440 -#define stc2 0x0441 -#define stc3 0x0442 -#define stc4 0x0443 -#define stc5 0x0444 -#define stc6 0x0445 -#define stc7 0x0446 -#define stc8 0x0447 -#define stc9 0x0448 -#define stc10 0x0449 -#define stc11 0x044a -#define stc12 0x044b -#define stc13 0x044c -#define stc14 0x044d -#define stc15 0x044e -#define stc16 0x044f -#define stc17 0x0450 -#define stc18 0x0451 -#define stc19 0x0452 -#define stc20 0x0453 -#define stc21 0x0454 -#define stc22 0x0455 -#define stc23 0x0456 -#define stc24 0x0457 -#define stc25 0x0458 -#define stc26 0x0459 -#define stc27 0x045a -#define stc28 0x045b -#define stc29 0x045c -#define stc30 0x045d -#define stc31 0x045e -#define stc32 0x045f -#define lst1 0x0460 -#define lst2 0x0461 -#define lst3 0x0462 -#define lst4 0x0463 -#define lst5 0x0464 -#define lst6 0x0465 -#define lst7 0x0466 -#define lst8 0x0467 -#define lst9 0x0468 -#define lst10 0x0469 -#define lst11 0x046a -#define lst12 0x046b -#define lst13 0x046c -#define lst14 0x046d -#define lst15 0x046e -#define lst16 0x046f -#define cmb1 0x0470 -#define cmb2 0x0471 -#define cmb3 0x0472 -#define cmb4 0x0473 -#define cmb5 0x0474 -#define cmb6 0x0475 -#define cmb7 0x0476 -#define cmb8 0x0477 -#define cmb9 0x0478 -#define cmb10 0x0479 -#define cmb11 0x047a -#define cmb12 0x047b -#define cmb13 0x047c -#define cmb14 0x047d -#define cmb15 0x047e -#define cmb16 0x047f -#define edt1 0x0480 -#define edt2 0x0481 -#define edt3 0x0482 -#define edt4 0x0483 -#define edt5 0x0484 -#define edt6 0x0485 -#define edt7 0x0486 -#define edt8 0x0487 -#define edt9 0x0488 -#define edt10 0x0489 -#define edt11 0x048a -#define edt12 0x048b -#define edt13 0x048c -#define edt14 0x048d -#define edt15 0x048e -#define edt16 0x048f -#define scr1 0x0490 -#define scr2 0x0491 -#define scr3 0x0492 -#define scr4 0x0493 -#define scr5 0x0494 -#define scr6 0x0495 -#define scr7 0x0496 -#define scr8 0x0497 -#define ctl1 0x04A0 -#define ctlLast 0x04ff -#define _WIN32_WINNT 0x0500 -#define WINVER 0x0501 -#define _WIN32_IE 0x0501 -#define FILEOPENORD 1536 -#define MULTIFILEOPENORD 1537 -#define PRINTDLGORD 1538 -#define PRNSETUPDLGORD 1539 -#define FINDDLGORD 1540 -#define REPLACEDLGORD 1541 -#define FONTDLGORD 1542 -#define FORMATDLGORD31 1543 -#define FORMATDLGORD30 1544 -#define RUNDLGORD 1545 -#define PAGESETUPDLGORD 1546 -#define NEWFILEOPENORD 1547 -#define PRINTDLGEXORD 1549 -#define PAGESETUPDLGORDMOTIF 1550 -#define COLORMGMTDLGORD 1551 -#define NEWFILEOPENV2ORD 1552 -#define CS_SAVEBITS 0x0800 -#define RBS_FIXEDORDER 0x0800 -#define SBARS_TOOLTIPS 0x0800 -#define SBT_TOOLTIPS 0x0800 -#define LVS_ALIGNLEFT 0x0800 -#define TVS_INFOTIP 0x0800 -#define TCS_RAGGEDRIGHT 0x0800 -#define LVS_ALIGNMASK 0x0c00 -#define CS_BYTEALIGNCLIENT 0x1000 -#define RBS_REGISTERDROP 0x1000 -#define LVS_OWNERDATA 0x1000 -#define TVS_FULLROWSELECT 0x1000 -#define TCS_FOCUSONBUTTONDOWN 0x1000 -#define CS_BYTEALIGNWINDOW 0x2000 -#define RBS_AUTOSIZE 0x2000 -#define LVS_NOSCROLL 0x2000 -#define TVS_NOSCROLL 0x2000 -#define TCS_OWNERDRAWFIXED 0x2000 -#define CS_GLOBALCLASS 0x4000 -#define RBS_VERTICALGRIPPER 0x4000 -#define LVS_NOCOLUMNHEADER 0x4000 -#define TVS_NONEVENHEIGHT 0x4000 -#define TCS_TOOLTIPS 0x4000 -#define IDH_NO_HELP 28440 -#define IDH_MISSING_CONTEXT 28441 -#define IDH_GENERIC_HELP_BUTTON 28442 -#define IDH_OK 28443 -#define IDH_CANCEL 28444 -#define IDH_HELP 28445 -#define IDTIMEOUT 32000 -#define OCR_NORMAL 32512 -#define OIC_SAMPLE 32512 -#define IDI_APPLICATION 32512 -#define OCR_IBEAM 32513 -#define OIC_HAND 32513 -#define IDI_HAND 32513 -#define OCR_WAIT 32514 -#define OIC_QUES 32514 -#define IDI_QUESTION 32514 -#define OCR_CROSS 32515 -#define OIC_BANG 32515 -#define IDI_EXCLAMATION 32515 -#define OCR_UP 32516 -#define OIC_NOTE 32516 -#define IDI_ASTERISK 32516 -#define OIC_WINLOGO 32517 -#define IDI_WINLOGO 32517 -#define OCR_SIZE 32640 -#define OCR_ICON 32641 -#define OCR_SIZENWSE 32642 -#define OCR_SIZENESW 32643 -#define OCR_SIZEWE 32644 -#define OCR_SIZENS 32645 -#define OCR_SIZEALL 32646 -#define OCR_ICOCUR 32647 -#define OCR_NO 32648 -#define OCR_HAND 32649 -#define OCR_APPSTARTING 32650 -#define OBM_LFARROWI 32734 -#define OBM_RGARROWI 32735 -#define OBM_DNARROWI 32736 -#define OBM_UPARROWI 32737 -#define OBM_COMBO 32738 -#define OBM_MNARROW 32739 -#define OBM_LFARROWD 32740 -#define OBM_RGARROWD 32741 -#define OBM_DNARROWD 32742 -#define OBM_UPARROWD 32743 -#define OBM_RESTORED 32744 -#define OBM_ZOOMD 32745 -#define OBM_REDUCED 32746 -#define OBM_RESTORE 32747 -#define OBM_ZOOM 32748 -#define OBM_REDUCE 32749 -#define OBM_LFARROW 32750 -#define OBM_RGARROW 32751 -#define OBM_DNARROW 32752 -#define OBM_UPARROW 32753 -#define OBM_CLOSE 32754 -#define OBM_OLD_RESTORE 32755 -#define OBM_OLD_ZOOM 32756 -#define OBM_OLD_REDUCE 32757 -#define OBM_BTNCORNERS 32758 -#define OBM_CHECKBOXES 32759 -#define OBM_CHECK 32760 -#define OBM_BTSIZE 32761 -#define OBM_OLD_LFARROW 32762 -#define OBM_OLD_RGARROW 32763 -#define OBM_OLD_DNARROW 32764 -#define OBM_OLD_UPARROW 32765 -#define OBM_SIZE 32766 -#define OBM_OLD_CLOSE 32767 -#define WM_APP 0x8000 -#define HELP_TCARD 0x8000 -#define RBS_DBLCLKTOGGLE 0x8000 -#define LVS_NOSORTHEADER 0x8000 -#define TVS_NOHSCROLL 0x8000 -#define TCS_FOCUSNEVER 0x8000 -#define SC_SIZE 0xF000 -#define SC_SEPARATOR 0xF00F -#define SC_MOVE 0xF010 -#define SC_MINIMIZE 0xF020 -#define SC_MAXIMIZE 0xF030 -#define SC_NEXTWINDOW 0xF040 -#define SC_PREVWINDOW 0xF050 -#define SC_CLOSE 0xF060 -#define SC_VSCROLL 0xF070 -#define SC_HSCROLL 0xF080 -#define SC_MOUSEMENU 0xF090 -#define SC_KEYMENU 0xF100 -#define SC_ARRANGE 0xF110 -#define SC_RESTORE 0xF120 -#define SC_TASKLIST 0xF130 -#define SC_SCREENSAVE 0xF140 -#define SC_HOTKEY 0xF150 -#define SC_DEFAULT 0xF160 -#define SC_MONITORPOWER 0xF170 -#define SC_CONTEXTHELP 0xF180 -#define LVS_TYPESTYLEMASK 0xfc00 -#define HTERROR -2 -#define PWR_FAIL -1 -#define HTTRANSPARENT -1 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 101 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1001 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/vc8_build/resource1.h b/vc8_build/resource1.h deleted file mode 100644 index c321beb..0000000 --- a/vc8_build/resource1.h +++ /dev/null @@ -1,14 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by BNCSutil1.rc - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 101 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1001 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/windows_dist.bat b/windows_dist.bat deleted file mode 100644 index 25c300a..0000000 --- a/windows_dist.bat +++ /dev/null @@ -1,19 +0,0 @@ -@REM GMP Library Path -@SET GMPPath=D:\gmp-4.2.1 - -@SET VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio 8 -@SET VCINSTALLDIR=C:\Program Files\Microsoft Visual Studio 8\VC -@SET FrameworkDir=C:\WINDOWS\Microsoft.NET\Framework -@SET FrameworkVersion=v2.0.40607 -@SET FrameworkSDKDir=C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0 -@set PATH=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;C:\Program Files\Microsoft Visual Studio 8\VC\BIN;C:\Program Files\Microsoft Visual Studio 8\VC\VCPackages;C:\Program Files\Microsoft Visual Studio 8\Common7\Tools;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\bin;C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607;%PATH% -@set INCLUDE=C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE;%GMPPath%;%INCLUDE% -@set LIB=C:\Program Files\Microsoft Visual Studio 8\VC\LIB;C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\lib;%LIB% -@set LIBPATH=C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607 - -@Set MSSdk=C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK -@Set Lib=%MSSdk%\Lib;%Lib% -@Set Include=%MSSdk%\Include;%Include% -@Set Path=%MSSdk%\Bin;%MSSdk%\Bin\win95;%path% - -sh windows_dist.sh \ No newline at end of file diff --git a/windows_dist.sh b/windows_dist.sh deleted file mode 100644 index 66dd477..0000000 --- a/windows_dist.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh - -SCRIPT_PATH=`dirname $0`; -PKGDIR=bncsutil-`cat $SCRIPT_PATH/product_version` -FILES="" - -for config in Release Debug -do - vcbuild /u /r /nologo /htmllog:./$config/BuildLog.html $SCRIPT_PATH/vc8_build/BNCSutil.vcproj $config - rm -f $PKGDIR-$config.zip - mkdir $PKGDIR - - for f in BNCSutil.dll BNCSutil.lib BNCSutil.pdb BuildLog.html - do - cp $SCRIPT_PATH/vc8_build/$config/$f $PKGDIR/$f - done - - mkdir $PKGDIR/bncsutil - for f in $SCRIPT_PATH/src/bncsutil/*.h - do - cp $f $PKGDIR/bncsutil/`basename $f` - done - - cp vb6_example/BNCSutil.bas $PKGDIR - cp vb6_example/NLS.cls $PKGDIR - - zip -9q -r $PKGDIR-$config.zip $PKGDIR - rm -fr $PKGDIR - - FILES="$FILES $PKGDIR-$config.zip" -done - -zip -9q -r ${PKGDIR}_vb_example.zip vb6_example -FILES="$FILES ${PKGDIR}_vb_example.zip" - -pscp $FILES "ericn@ionws.com:/home/ericn/public_html/code/bncsutil/static/releases" \ No newline at end of file