summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryazoo <yazoo>2008-01-29 07:43:06 +0000
committeryazoo <yazoo>2008-01-29 07:43:06 +0000
commit8522e44467ebcac54201def2c6583639e74e9e24 (patch)
tree9d475da6b178bf96359f06d39773441b76b8d567
parent7ecf94d4b339bc2197f449f0f1538f2915313087 (diff)
Portage win32
-rw-r--r--MPQCryptography.c31
-rw-r--r--MPQCryptography.h8
-rw-r--r--extract.c9
-rw-r--r--hashtab.c4
-rw-r--r--hashtab.h4
-rw-r--r--int-bios.h2
-rw-r--r--lookupa.h4
-rw-r--r--mpq-bios.c39
-rw-r--r--mpq-bios.h4
-rw-r--r--mpq-file.c9
-rw-r--r--mpq-file.h5
-rw-r--r--mpq-fs.h4
-rw-r--r--mpq-misc.h4
-rw-r--r--recycle.c4
14 files changed, 103 insertions, 28 deletions
diff --git a/MPQCryptography.c b/MPQCryptography.c
index 9791c0a..6c33e55 100644
--- a/MPQCryptography.c
+++ b/MPQCryptography.c
@@ -25,7 +25,12 @@
#endif
#include "MPQCryptography.h"
+
+#ifdef WIN32
+#include "stdint.h"
+#else
#include "inttypes.h"
+#endif
static int crypt_table_initialized = 0;
static uint32_t crypt_table[0x500];
@@ -88,13 +93,13 @@ void __mpqlib_init_cryptography()
void __mpqlib_encrypt(void *_data, uint32_t length, uint32_t key, bool disable_input_swapping)
{
- char * data = (char *) _data;
- assert(crypt_table_initialized);
- assert(data);
-
+ char * data = (char *) _data;
uint32_t *buffer32 = (uint32_t *) data;
uint32_t seed = 0xEEEEEEEE;
uint32_t ch;
+
+ assert(crypt_table_initialized);
+ assert(data);
// Round to 4 bytes
length = length / 4;
@@ -126,13 +131,13 @@ void __mpqlib_encrypt(void *_data, uint32_t length, uint32_t key, bool disable_i
void __mpqlib_decrypt(void *_data, uint32_t length, uint32_t key, bool disable_output_swapping)
{
char * data = (char *) _data;
- assert(crypt_table_initialized);
- assert(data);
-
uint32_t *buffer32 = (uint32_t *) data;
uint32_t seed = 0xEEEEEEEE;
uint32_t ch;
+ assert(crypt_table_initialized);
+ assert(data);
+
// Round to 4 bytes
length = length / 4;
@@ -166,14 +171,14 @@ void __mpqlib_decrypt(void *_data, uint32_t length, uint32_t key, bool disable_o
uint32_t __mpqlib_hash_cstring(const char *string, uint32_t type)
{
- assert(crypt_table_initialized);
- assert(string);
-
uint32_t seed1 = 0x7FED7FED;
uint32_t seed2 = 0xEEEEEEEE;
uint32_t shifted_type = (type << 8);
int32_t ch;
+ assert(crypt_table_initialized);
+ assert(string);
+
while (*string != 0) {
ch = *string++;
if (ch > 0x60 && ch < 0x7b)
@@ -188,14 +193,14 @@ uint32_t __mpqlib_hash_cstring(const char *string, uint32_t type)
uint32_t __mpqlib_hash_data(const char *data, uint32_t length, uint32_t type)
{
- assert(crypt_table_initialized);
- assert(data);
-
uint32_t seed1 = 0x7FED7FED;
uint32_t seed2 = 0xEEEEEEEE;
uint32_t shifted_type = (type << 8);
int32_t ch;
+ assert(crypt_table_initialized);
+ assert(data);
+
while (length > 0) {
ch = *data++;
diff --git a/MPQCryptography.h b/MPQCryptography.h
index b1d621e..01aa418 100644
--- a/MPQCryptography.h
+++ b/MPQCryptography.h
@@ -7,9 +7,15 @@
*
*/
+#ifdef WIN32
+#include "stdint.h"
+#include <stdlib.h>
+#define bool char
+#else
#include <stdbool.h>
#include <stdint.h>
#include <openssl/rsa.h>
+#endif
#if defined(__cplusplus)
extern "C" {
@@ -40,8 +46,10 @@ extern "C" {
#define __MPQLIB_CRC_FINALIZE 0x4
void __mpqlib_crc32(const unsigned char *buffer, uint32_t length, uint32_t * crc, uint32_t flags);
+#ifdef USE_SSL
int __mpqlib_verify_weak_signature(RSA * public_key, const unsigned char *signature, const unsigned char *digest);
int __mpqlib_verify_strong_signature(RSA * public_key, const unsigned char *signature, const unsigned char *digest);
+#endif
#if defined(__cplusplus)
}
diff --git a/extract.c b/extract.c
index 905ee83..035f2d2 100644
--- a/extract.c
+++ b/extract.c
@@ -1242,6 +1242,9 @@ static void huff_init_tree(struct huffman_tree *ht, struct huffman_tree_item *hi
/*
* Compression structure (size: 12596 bytes on x86-32)
*/
+#ifdef WIN32
+#pragma pack(1)
+#endif
typedef struct {
unsigned long offs0000; /* 0000 */
unsigned long cmp_type; /* 0004 - Compression type (PZIP_CMP_BINARY or
@@ -1272,7 +1275,11 @@ typedef struct {
unsigned char slen_bits[0x10]; /* 30F4 - Numbers of bits for skip copied block length */
unsigned char clen_bits[0x10]; /* 3104 - Number of valid bits for copied block */
unsigned short len_base[0x10]; /* 3114 - Buffer for */
-} __attribute__ ((packed)) pkzip_data_cmp;
+}
+#ifndef WIN32
+__attribute__ ((packed))
+#endif
+pkzip_data_cmp;
typedef struct {
const char *in_buf; /* Pointer to input data buffer */
diff --git a/hashtab.c b/hashtab.c
index 8e278a1..1ddab62 100644
--- a/hashtab.c
+++ b/hashtab.c
@@ -28,7 +28,11 @@ This implements a hash table.
--------------------------------------------------------------------
*/
+#ifdef WIN32
+#include "stdint.h"
+#else
#include <stdint.h>
+#endif
#include <memory.h>
#include "lookupa.h"
diff --git a/hashtab.h b/hashtab.h
index 2f8b22c..45ad923 100644
--- a/hashtab.h
+++ b/hashtab.h
@@ -31,7 +31,11 @@ This implements a hash table.
#ifndef HASHTAB
#define HASHTAB
+#ifdef WIN32
+#include "stdint.h"
+#else
#include <stdint.h>
+#endif
#include <stdlib.h>
/* PRIVATE TYPES AND DEFINITIONS */
diff --git a/int-bios.h b/int-bios.h
index 83676f9..2c1c4ee 100644
--- a/int-bios.h
+++ b/int-bios.h
@@ -1,7 +1,7 @@
#ifndef __INT_BIOS_H__
#define __INT_BIOS_H__
-#include <mpq-bios.h>
+#include "mpq-bios.h"
/*
* Internal BIOS functions.
diff --git a/lookupa.h b/lookupa.h
index 8001b3c..8ac120d 100644
--- a/lookupa.h
+++ b/lookupa.h
@@ -10,7 +10,11 @@ Source is http://burtleburtle.net/bob/c/lookupa.h
#ifndef LOOKUPA
#define LOOKUPA
+#ifdef WIN32
+#include "stdint.h"
+#else
#include <stdint.h>
+#endif
#define CHECKSTATE 8
#define hashsize(n) ((uint32_t)1<<(n))
diff --git a/mpq-bios.c b/mpq-bios.c
index 8251b95..35173d6 100644
--- a/mpq-bios.c
+++ b/mpq-bios.c
@@ -1,5 +1,14 @@
#define _LARGEFILE64_SOURCE
+
+#ifdef WIN32
+#include <stdio.h>
+#include <io.h>
+#include <sys/types.h>
+#define lseek64 _lseeki64
+#else
#include <unistd.h>
+#endif
+
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -12,11 +21,13 @@
#include "mpq-misc.h"
#include "int-bios.h"
#include "errors.h"
-#include "inttypes.h"
/*
* MPQ header.
*/
+#ifdef WIN32
+#pragma pack(1)
+#endif
typedef struct {
/* basic version of the header. */
@@ -35,7 +46,11 @@ typedef struct {
uint64_t extended_block_table_offset;
uint16_t hash_table_offset_high;
uint16_t block_table_offset_high;
-} __attribute__ ((packed)) mpq_header_t;
+}
+#ifndef WIN32
+__attribute__ ((packed))
+#endif
+mpq_header_t;
/*
* One hash entry.
@@ -47,7 +62,11 @@ typedef struct {
uint16_t language;
uint16_t platform;
uint32_t file_block_index;
-} __attribute__ ((packed)) mpq_hash_t;
+}
+#ifndef WIN32
+__attribute__ ((packed))
+#endif
+mpq_hash_t;
/*
* One block entry.
@@ -58,7 +77,11 @@ typedef struct {
uint32_t block_size;
uint32_t file_size;
uint32_t flags;
-} __attribute__ ((packed)) mpq_block_t;
+}
+#ifndef WIN32
+__attribute__ ((packed))
+#endif
+mpq_block_t;
/*
@@ -81,7 +104,7 @@ typedef struct {
} block_t;
struct mpq_archive_t {
- int fd;
+ int fd;
int closeit;
uint32_t header_size;
@@ -108,7 +131,11 @@ struct mpq_archive_t * mpqlib_open_archive(const char * fname) {
int fd;
struct mpq_archive_t * r;
- if ((fd = open(fname, O_RDONLY | O_LARGEFILE | O_BINARY)) == -1) {
+#ifdef WIN32
+ if ((fd = open(fname, _O_RDONLY | _O_BINARY)) == -1) {
+#else
+ if ((fd = open(fname, O_RDONLY | O_LARGEFILE | O_BINARY)) == -1) {
+#endif
__mpqlib_errno = MPQLIB_ERROR_OPEN;
return NULL;
}
diff --git a/mpq-bios.h b/mpq-bios.h
index 4e82973..61e2020 100644
--- a/mpq-bios.h
+++ b/mpq-bios.h
@@ -1,7 +1,11 @@
#ifndef __MPQ_BIOS_H__
#define __MPQ_BIOS_H__
+#ifdef WIN32
+#include "stdint.h"
+#else
#include <stdint.h>
+#endif
struct mpq_archive_t;
diff --git a/mpq-file.c b/mpq-file.c
index f6a26d8..2088335 100644
--- a/mpq-file.c
+++ b/mpq-file.c
@@ -162,10 +162,11 @@ uint32_t mpqlib_read(struct mpq_file_t * mpq_f, void * _buffer, uint32_t size) {
uint32_t cl_size;
uint32_t offset_begin, offset_end;
- __mpqlib_errno = MPQLIB_ERROR_NO_ERROR;
-
- uint32_t first_sector_begins, last_sector_ends;
-
+ uint32_t first_sector_begins;
+ uint32_t last_sector_ends;
+
+ __mpqlib_errno = MPQLIB_ERROR_NO_ERROR;
+
/* Computing various cursors and stuff. */
if ((size + mpq_f->cursor) >= mpq_f->file_size)
size = mpq_f->file_size - mpq_f->cursor;
diff --git a/mpq-file.h b/mpq-file.h
index 1cec05d..7557758 100644
--- a/mpq-file.h
+++ b/mpq-file.h
@@ -1,8 +1,11 @@
#ifndef __MPQ_FILE_H__
#define __MPQ_FILE_H__
+#ifdef WIN32
+#include "stdint.h"
+#else
#include <stdint.h>
-
+#endif
struct mpq_file_t;
enum mpqlib_file_seek_t {
diff --git a/mpq-fs.h b/mpq-fs.h
index 4d247b6..558f21e 100644
--- a/mpq-fs.h
+++ b/mpq-fs.h
@@ -1,8 +1,8 @@
#ifndef __MPQ_FS_H__
#define __MPQ_FS_H__
-#include <mpq-bios.h>
-#include <mpq-file.h>
+#include "mpq-bios.h"
+#include "mpq-file.h"
#ifdef __cplusplus
extern "C" {
diff --git a/mpq-misc.h b/mpq-misc.h
index 0f38e66..72565de 100644
--- a/mpq-misc.h
+++ b/mpq-misc.h
@@ -1,7 +1,11 @@
#ifndef __MPQ_MISC_H__
#define __MPQ_MISC_H__
+#ifdef WIN32
+typedef unsigned long int uint32_t;
+#else
#include <stdint.h>
+#endif
#ifdef __cplusplus
extern "C" {
diff --git a/recycle.c b/recycle.c
index 261c54f..ff823d1 100644
--- a/recycle.c
+++ b/recycle.c
@@ -13,7 +13,11 @@ This also decreases memory fragmentation, and freeing structures
--------------------------------------------------------------------
*/
+#ifdef WIN32
+#include "stdint.h"
+#else
#include <stdint.h>
+#endif
#include <stdio.h>
#include <memory.h>
#include "recycle.h"