Fix up line endings, add libxpwn.c that was necessary, made Makefile generate DOS readmes for Windows, fixed up some includes

This commit is contained in:
planetbeing 2008-05-21 07:01:39 -07:00
Родитель d42404ab5c
Коммит 6bf5301c16
45 изменённых файлов: 10792 добавлений и 10791 удалений

Просмотреть файл

@ -37,8 +37,8 @@ install-win: ipsw-patch/pch xpwn/xpwn
cp xpwn/ramdisk.dmg xpwn-build/ramdisk.dmg
cp -R ipsw-patch/FirmwareBundles xpwn-build/FirmwareBundles
cp -R ipsw-patch/bundles xpwn-build/bundles
cp README.markdown xpwn-build/README.txt
cp LICENSE xpwn-build/LICENSE.txt
sed "`echo s/$$/\\\r`/" README.markdown > xpwn-build/README.txt
sed "`echo s/$$/\\\r`/" LICENSE > xpwn-build/LICENSE.txt
cd xpwn-build; zip -r ../xpwn-windows.zip *
clean:
@ -73,3 +73,4 @@ dist-clean: clean
-rm dmg/zlib-1.2.3/contrib/minizip/*.o
-rm ipsw-patch/bzip2-1.0.5/*.exe
-rm -rf xpwn-build

Просмотреть файл

@ -1,29 +1,29 @@
UTILOBJS=hdutil.o
DMGOBJS=../dmg/base64.o ../dmg/resources.o ../dmg/checksum.o ../dmg/udif.o ../dmg/partition.o ../dmg/io.o ../dmg/filevault.o ../dmg/dmgfile.o ../dmg/zlib-1.2.3/libz.a ../dmg/openssl-0.9.8g/libcrypto.a
HFSOBJS=../hfs/volume.o ../hfs/btree.o ../hfs/extents.o ../hfs/rawfile.o ../hfs/catalog.o ../hfs/flatfile.o ../hfs/utility.o ../hfs/fastunicodecompare.o ../hfs/abstractfile.o ../hfs/hfslib.o
CFLAGS=-D_FILE_OFFSET_BITS=64 -DHAVE_CRYPT
LIBRARIES=`if $(CC) win32test.c -o /dev/null 2>/dev/null ; then echo ""; else echo "-lgdi32"; fi`
all: util
util: $(DMGOBJS) $(HFSOBJS) $(UTILOBJS)
$(CC) $(CFLAGS) $(DMGOBJS) $(HFSOBJS) $(UTILOBJS) $(LIBRARIES) -o hdutil
%.o: %.c
$(CC) $(CFLAGS) -I../dmg/zlib-1.2.3 -I../dmg/openssl-0.9.8g/include -c $< -o $@
../dmg/zlib-1.2.3/Makefile:
cd ../dmg/zlib-1.2.3; ./configure
../dmg/zlib-1.2.3/libz.a: ../dmg/zlib-1.2.3/Makefile
cd ../dmg/zlib-1.2.3; make
UTILOBJS=hdutil.o
DMGOBJS=../dmg/base64.o ../dmg/resources.o ../dmg/checksum.o ../dmg/udif.o ../dmg/partition.o ../dmg/io.o ../dmg/filevault.o ../dmg/dmgfile.o ../dmg/zlib-1.2.3/libz.a ../dmg/openssl-0.9.8g/libcrypto.a
HFSOBJS=../hfs/volume.o ../hfs/btree.o ../hfs/extents.o ../hfs/rawfile.o ../hfs/catalog.o ../hfs/flatfile.o ../hfs/utility.o ../hfs/fastunicodecompare.o ../hfs/abstractfile.o ../hfs/hfslib.o
CFLAGS=-D_FILE_OFFSET_BITS=64 -DHAVE_CRYPT
LIBRARIES=`if $(CC) win32test.c -o /dev/null 2>/dev/null ; then echo ""; else echo "-lgdi32"; fi`
all: util
util: $(DMGOBJS) $(HFSOBJS) $(UTILOBJS)
$(CC) $(CFLAGS) $(DMGOBJS) $(HFSOBJS) $(UTILOBJS) $(LIBRARIES) -o hdutil
%.o: %.c
$(CC) $(CFLAGS) -I../dmg/zlib-1.2.3 -I../dmg/openssl-0.9.8g/include -c $< -o $@
../dmg/zlib-1.2.3/Makefile:
cd ../dmg/zlib-1.2.3; ./configure
../dmg/zlib-1.2.3/libz.a: ../dmg/zlib-1.2.3/Makefile
cd ../dmg/zlib-1.2.3; make
../dmg/openssl-0.9.8g/libcrypto.a:
touch ../dmg/openssl-0.9.8g/Makefile
cd ../dmg/openssl-0.9.8g/crypto; make
clean:
-rm *.o
-rm hdutil
-rm hdutil.exe
touch ../dmg/openssl-0.9.8g/Makefile
cd ../dmg/openssl-0.9.8g/crypto; make
clean:
-rm *.o
-rm hdutil
-rm hdutil.exe

Просмотреть файл

@ -1,308 +1,308 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include "../hfs/hfsplus.h"
#include "../dmg/dmgfile.h"
#include "../dmg/filevault.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
char endianness;
void cmd_ls(Volume* volume, int argc, const char *argv[]) {
HFSPlusCatalogRecord* record;
char* name;
if(argc > 1)
hfs_ls(volume, argv[1]);
else
hfs_ls(volume, "/"); }
void cmd_cat(Volume* volume, int argc, const char *argv[]) {
HFSPlusCatalogRecord* record;
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include "../hfs/hfsplus.h"
#include "../dmg/dmgfile.h"
#include "../dmg/filevault.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
char endianness;
void cmd_ls(Volume* volume, int argc, const char *argv[]) {
HFSPlusCatalogRecord* record;
char* name;
if(argc > 1)
hfs_ls(volume, argv[1]);
else
hfs_ls(volume, "/"); }
void cmd_cat(Volume* volume, int argc, const char *argv[]) {
HFSPlusCatalogRecord* record;
AbstractFile* stdoutFile;
record = getRecordFromPath(argv[1], volume, NULL, NULL);
record = getRecordFromPath(argv[1], volume, NULL, NULL);
stdoutFile = createAbstractFileFromFile(stdout);
if(record != NULL) {
if(record->recordType == kHFSPlusFileRecord)
writeToFile((HFSPlusCatalogFile*)record, stdoutFile, volume);
else
printf("Not a file\n");
} else {
printf("No such file or directory\n");
}
if(record != NULL) {
if(record->recordType == kHFSPlusFileRecord)
writeToFile((HFSPlusCatalogFile*)record, stdoutFile, volume);
else
printf("Not a file\n");
} else {
printf("No such file or directory\n");
}
free(record);
free(stdoutFile);
}
void cmd_extract(Volume* volume, int argc, const char *argv[]) {
HFSPlusCatalogRecord* record;
AbstractFile *outFile;
if(argc < 3) {
printf("Not enough arguments");
return;
}
outFile = createAbstractFileFromFile(fopen(argv[2], "wb"));
if(outFile == NULL) {
printf("cannot create file");
}
record = getRecordFromPath(argv[1], volume, NULL, NULL);
if(record != NULL) {
if(record->recordType == kHFSPlusFileRecord)
writeToFile((HFSPlusCatalogFile*)record, outFile, volume);
else
printf("Not a file\n");
} else {
printf("No such file or directory\n");
}
outFile->close(outFile);
free(record);
}
void cmd_mv(Volume* volume, int argc, const char *argv[]) {
if(argc > 2) {
move(argv[1], argv[2], volume);
} else {
printf("Not enough arguments");
}
free(stdoutFile);
}
void cmd_symlink(Volume* volume, int argc, const char *argv[]) {
if(argc > 2) {
makeSymlink(argv[1], argv[2], volume);
} else {
printf("Not enough arguments");
}
}
void cmd_mkdir(Volume* volume, int argc, const char *argv[]) {
if(argc > 1) {
newFolder(argv[1], volume);
} else {
printf("Not enough arguments");
}
}
void cmd_add(Volume* volume, int argc, const char *argv[]) {
AbstractFile *inFile;
if(argc < 3) {
printf("Not enough arguments");
return;
}
inFile = createAbstractFileFromFile(fopen(argv[1], "rb"));
if(inFile == NULL) {
printf("file to add not found");
void cmd_extract(Volume* volume, int argc, const char *argv[]) {
HFSPlusCatalogRecord* record;
AbstractFile *outFile;
if(argc < 3) {
printf("Not enough arguments");
return;
}
outFile = createAbstractFileFromFile(fopen(argv[2], "wb"));
if(outFile == NULL) {
printf("cannot create file");
}
record = getRecordFromPath(argv[1], volume, NULL, NULL);
if(record != NULL) {
if(record->recordType == kHFSPlusFileRecord)
writeToFile((HFSPlusCatalogFile*)record, outFile, volume);
else
printf("Not a file\n");
} else {
printf("No such file or directory\n");
}
outFile->close(outFile);
free(record);
}
void cmd_mv(Volume* volume, int argc, const char *argv[]) {
if(argc > 2) {
move(argv[1], argv[2], volume);
} else {
printf("Not enough arguments");
}
}
void cmd_symlink(Volume* volume, int argc, const char *argv[]) {
if(argc > 2) {
makeSymlink(argv[1], argv[2], volume);
} else {
printf("Not enough arguments");
}
}
void cmd_mkdir(Volume* volume, int argc, const char *argv[]) {
if(argc > 1) {
newFolder(argv[1], volume);
} else {
printf("Not enough arguments");
}
}
void cmd_add(Volume* volume, int argc, const char *argv[]) {
AbstractFile *inFile;
if(argc < 3) {
printf("Not enough arguments");
return;
}
inFile = createAbstractFileFromFile(fopen(argv[1], "rb"));
if(inFile == NULL) {
printf("file to add not found");
}
add_hfs(volume, inFile, argv[2]);
}
void cmd_rm(Volume* volume, int argc, const char *argv[]) {
if(argc > 1) {
removeFile(argv[1], volume);
} else {
printf("Not enough arguments");
}
}
void cmd_chmod(Volume* volume, int argc, const char *argv[]) {
int mode;
if(argc > 2) {
sscanf(argv[1], "%o", &mode);
chmodFile(argv[2], mode, volume);
} else {
printf("Not enough arguments");
}
}
void cmd_extractall(Volume* volume, int argc, const char *argv[]) {
HFSPlusCatalogRecord* record;
char cwd[1024];
char* name;
ASSERT(getcwd(cwd, 1024) != NULL, "cannot get current working directory");
if(argc > 1)
record = getRecordFromPath(argv[1], volume, &name, NULL);
else
record = getRecordFromPath("/", volume, &name, NULL);
if(argc > 2) {
ASSERT(chdir(argv[2]) == 0, "chdir");
}
if(record != NULL) {
if(record->recordType == kHFSPlusFolderRecord)
extractAllInFolder(((HFSPlusCatalogFolder*)record)->folderID, volume);
else
printf("Not a folder\n");
} else {
printf("No such file or directory\n");
}
free(record);
ASSERT(chdir(cwd) == 0, "chdir");
}
void cmd_rmall(Volume* volume, int argc, const char *argv[]) {
HFSPlusCatalogRecord* record;
char* name;
char initPath[1024];
int lastCharOfPath;
if(argc > 1) {
record = getRecordFromPath(argv[1], volume, &name, NULL);
strcpy(initPath, argv[1]);
lastCharOfPath = strlen(argv[1]) - 1;
if(argv[1][lastCharOfPath] != '/') {
initPath[lastCharOfPath + 1] = '/';
initPath[lastCharOfPath + 2] = '\0';
}
} else {
record = getRecordFromPath("/", volume, &name, NULL);
initPath[0] = '/';
initPath[1] = '\0';
}
if(record != NULL) {
if(record->recordType == kHFSPlusFolderRecord) {
removeAllInFolder(((HFSPlusCatalogFolder*)record)->folderID, volume, initPath);
} else {
printf("Not a folder\n");
}
} else {
printf("No such file or directory\n");
}
free(record);
}
void cmd_addall(Volume* volume, int argc, const char *argv[]) {
if(argc < 2) {
printf("Not enough arguments");
return;
add_hfs(volume, inFile, argv[2]);
}
void cmd_rm(Volume* volume, int argc, const char *argv[]) {
if(argc > 1) {
removeFile(argv[1], volume);
} else {
printf("Not enough arguments");
}
}
void cmd_chmod(Volume* volume, int argc, const char *argv[]) {
int mode;
if(argc > 2) {
sscanf(argv[1], "%o", &mode);
chmodFile(argv[2], mode, volume);
} else {
printf("Not enough arguments");
}
}
void cmd_extractall(Volume* volume, int argc, const char *argv[]) {
HFSPlusCatalogRecord* record;
char cwd[1024];
char* name;
ASSERT(getcwd(cwd, 1024) != NULL, "cannot get current working directory");
if(argc > 1)
record = getRecordFromPath(argv[1], volume, &name, NULL);
else
record = getRecordFromPath("/", volume, &name, NULL);
if(argc > 2) {
ASSERT(chdir(argv[2]) == 0, "chdir");
}
if(argc > 2) {
addall_hfs(volume, argv[1], argv[2]);
} else {
addall_hfs(volume, argv[1], "/");
}
}
void cmd_grow(Volume* volume, int argc, const char *argv[]) {
uint64_t newSize;
if(argc < 2) {
printf("Not enough arguments\n");
return;
}
newSize = 0;
if(record != NULL) {
if(record->recordType == kHFSPlusFolderRecord)
extractAllInFolder(((HFSPlusCatalogFolder*)record)->folderID, volume);
else
printf("Not a folder\n");
} else {
printf("No such file or directory\n");
}
free(record);
ASSERT(chdir(cwd) == 0, "chdir");
}
void cmd_rmall(Volume* volume, int argc, const char *argv[]) {
HFSPlusCatalogRecord* record;
char* name;
char initPath[1024];
int lastCharOfPath;
if(argc > 1) {
record = getRecordFromPath(argv[1], volume, &name, NULL);
strcpy(initPath, argv[1]);
lastCharOfPath = strlen(argv[1]) - 1;
if(argv[1][lastCharOfPath] != '/') {
initPath[lastCharOfPath + 1] = '/';
initPath[lastCharOfPath + 2] = '\0';
}
} else {
record = getRecordFromPath("/", volume, &name, NULL);
initPath[0] = '/';
initPath[1] = '\0';
}
if(record != NULL) {
if(record->recordType == kHFSPlusFolderRecord) {
removeAllInFolder(((HFSPlusCatalogFolder*)record)->folderID, volume, initPath);
} else {
printf("Not a folder\n");
}
} else {
printf("No such file or directory\n");
}
free(record);
}
void cmd_addall(Volume* volume, int argc, const char *argv[]) {
if(argc < 2) {
printf("Not enough arguments");
return;
}
if(argc > 2) {
addall_hfs(volume, argv[1], argv[2]);
} else {
addall_hfs(volume, argv[1], "/");
}
}
void cmd_grow(Volume* volume, int argc, const char *argv[]) {
uint64_t newSize;
if(argc < 2) {
printf("Not enough arguments\n");
return;
}
newSize = 0;
sscanf(argv[1], "%lld", &newSize);
grow_hfs(volume, newSize);
printf("grew volume: %lld\n", newSize);
printf("grew volume: %lld\n", newSize);
}
void TestByteOrder()
{
short int word = 0x0001;
char *byte = (char *) &word;
endianness = byte[0] ? IS_LITTLE_ENDIAN : IS_BIG_ENDIAN;
void TestByteOrder()
{
short int word = 0x0001;
char *byte = (char *) &word;
endianness = byte[0] ? IS_LITTLE_ENDIAN : IS_BIG_ENDIAN;
}
int main(int argc, const char *argv[]) {
io_func* io;
Volume* volume;
AbstractFile* image;
int argOff;
TestByteOrder();
if(argc < 3) {
printf("usage: %s <image-file> (-k <key>) <ls|cat|mv|mkdir|add|rm|chmod|extract|extractall|rmall|addall> <arguments>\n", argv[0]);
return 0;
}
argOff = 2;
if(strstr(argv[1], ".dmg")) {
image = createAbstractFileFromFile(fopen(argv[1], "rb"));
if(argc > 3) {
if(strcmp(argv[2], "-k") == 0) {
image = createAbstractFileFromFileVault(image, argv[3]);
argOff = 4;
}
}
io = openDmgFilePartition(image, -1);
} else {
io = openFlatFile(argv[1]);
}
if(io == NULL) {
fprintf(stderr, "error: Cannot open image-file.\n");
return 1;
}
volume = openVolume(io);
if(volume == NULL) {
fprintf(stderr, "error: Cannot open volume.\n");
CLOSE(io);
return 1;
}
if(argc > argOff) {
if(strcmp(argv[argOff], "ls") == 0) {
cmd_ls(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "cat") == 0) {
cmd_cat(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "mv") == 0) {
int main(int argc, const char *argv[]) {
io_func* io;
Volume* volume;
AbstractFile* image;
int argOff;
TestByteOrder();
if(argc < 3) {
printf("usage: %s <image-file> (-k <key>) <ls|cat|mv|mkdir|add|rm|chmod|extract|extractall|rmall|addall> <arguments>\n", argv[0]);
return 0;
}
argOff = 2;
if(strstr(argv[1], ".dmg")) {
image = createAbstractFileFromFile(fopen(argv[1], "rb"));
if(argc > 3) {
if(strcmp(argv[2], "-k") == 0) {
image = createAbstractFileFromFileVault(image, argv[3]);
argOff = 4;
}
}
io = openDmgFilePartition(image, -1);
} else {
io = openFlatFile(argv[1]);
}
if(io == NULL) {
fprintf(stderr, "error: Cannot open image-file.\n");
return 1;
}
volume = openVolume(io);
if(volume == NULL) {
fprintf(stderr, "error: Cannot open volume.\n");
CLOSE(io);
return 1;
}
if(argc > argOff) {
if(strcmp(argv[argOff], "ls") == 0) {
cmd_ls(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "cat") == 0) {
cmd_cat(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "mv") == 0) {
cmd_mv(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[2], "symlink") == 0) {
cmd_symlink(volume, argc - 2, argv + 2);
} else if(strcmp(argv[argOff], "mkdir") == 0) {
cmd_mkdir(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "add") == 0) {
cmd_add(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "rm") == 0) {
cmd_rm(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "chmod") == 0) {
cmd_chmod(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "extract") == 0) {
cmd_extract(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "extractall") == 0) {
cmd_extractall(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "rmall") == 0) {
cmd_rmall(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "addall") == 0) {
cmd_addall(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "grow") == 0) {
cmd_grow(volume, argc - argOff, argv + argOff);
}
}
closeVolume(volume);
CLOSE(io);
return 0;
}
} else if(strcmp(argv[2], "symlink") == 0) {
cmd_symlink(volume, argc - 2, argv + 2);
} else if(strcmp(argv[argOff], "mkdir") == 0) {
cmd_mkdir(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "add") == 0) {
cmd_add(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "rm") == 0) {
cmd_rm(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "chmod") == 0) {
cmd_chmod(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "extract") == 0) {
cmd_extract(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "extractall") == 0) {
cmd_extractall(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "rmall") == 0) {
cmd_rmall(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "addall") == 0) {
cmd_addall(volume, argc - argOff, argv + argOff);
} else if(strcmp(argv[argOff], "grow") == 0) {
cmd_grow(volume, argc - argOff, argv + argOff);
}
}
closeVolume(volume);
CLOSE(io);
return 0;
}

Просмотреть файл

@ -1,9 +1,9 @@
#include <stdlib.h>
#ifdef WIN32
blahfs-o_f-0-(){ {}A
#else
int main(int argc, char* argv[]) {
return 0;
}
#endif
#include <stdlib.h>
#ifdef WIN32
blahfs-o_f-0-(){ {}A
#else
int main(int argc, char* argv[]) {
return 0;
}
#endif

Просмотреть файл

@ -1,5 +1,5 @@
all:
cd ../../; make
clean:
cd ../../; make clean
all:
cd ../../; make
clean:
cd ../../; make clean

Просмотреть файл

@ -1,47 +1,47 @@
#include <stdint.h>
#include <openssl/aes.h>
#include "abstractfile.h"
#ifndef INC_8900_H
#define INC_8900_H
typedef struct {
uint32_t magic; /* string "8900" */
unsigned char version[3]; /* string "1.0" */
uint8_t format; /* plaintext format is 0x4, encrypted format is 0x3 */
uint32_t unknown1;
uint32_t sizeOfData; /* size of data (ie, filesize - header(0x800) - footer signature(0x80) - footer certificate(0xC0A)) */
uint32_t footerSignatureOffset; /* offset to footer signature */
uint32_t footerCertOffset; /* offset to footer certificate, from end of header (0x800) */
uint32_t footerCertLen;
unsigned char salt[0x20]; /* a seemingly random salt (an awfully big one though... needs more attention) */
uint16_t unknown2;
uint16_t epoch; /* the security epoch of the file */
unsigned char headerSignature[0x10]; /* encrypt(sha1(header[0:0x40])[0:0x10], key_0x837, zero_iv) */
unsigned char padding[0x7B0];
} __attribute__((__packed__)) Apple8900Header;
#define SIGNATURE_8900 0x38393030
static uint8_t key_0x837[] = {0x18, 0x84, 0x58, 0xA6, 0xD1, 0x50, 0x34, 0xDF, 0xE3, 0x86, 0xF2, 0x3B, 0x61, 0xD4, 0x37, 0x74};
typedef struct Info8900 {
AbstractFile* file;
Apple8900Header header;
size_t offset;
void* buffer;
unsigned char footerSignature[0x80];
unsigned char* footerCertificate;
AES_KEY encryptKey;
AES_KEY decryptKey;
char dirty;
} Info8900;
AbstractFile* createAbstractFileFrom8900(AbstractFile* file);
AbstractFile* duplicate8900File(AbstractFile* file, AbstractFile* backing);
#endif
#include <stdint.h>
#include <openssl/aes.h>
#include "abstractfile.h"
#ifndef INC_8900_H
#define INC_8900_H
typedef struct {
uint32_t magic; /* string "8900" */
unsigned char version[3]; /* string "1.0" */
uint8_t format; /* plaintext format is 0x4, encrypted format is 0x3 */
uint32_t unknown1;
uint32_t sizeOfData; /* size of data (ie, filesize - header(0x800) - footer signature(0x80) - footer certificate(0xC0A)) */
uint32_t footerSignatureOffset; /* offset to footer signature */
uint32_t footerCertOffset; /* offset to footer certificate, from end of header (0x800) */
uint32_t footerCertLen;
unsigned char salt[0x20]; /* a seemingly random salt (an awfully big one though... needs more attention) */
uint16_t unknown2;
uint16_t epoch; /* the security epoch of the file */
unsigned char headerSignature[0x10]; /* encrypt(sha1(header[0:0x40])[0:0x10], key_0x837, zero_iv) */
unsigned char padding[0x7B0];
} __attribute__((__packed__)) Apple8900Header;
#define SIGNATURE_8900 0x38393030
static uint8_t key_0x837[] = {0x18, 0x84, 0x58, 0xA6, 0xD1, 0x50, 0x34, 0xDF, 0xE3, 0x86, 0xF2, 0x3B, 0x61, 0xD4, 0x37, 0x74};
typedef struct Info8900 {
AbstractFile* file;
Apple8900Header header;
size_t offset;
void* buffer;
unsigned char footerSignature[0x80];
unsigned char* footerCertificate;
AES_KEY encryptKey;
AES_KEY decryptKey;
char dirty;
} Info8900;
AbstractFile* createAbstractFileFrom8900(AbstractFile* file);
AbstractFile* duplicate8900File(AbstractFile* file, AbstractFile* backing);
#endif

Просмотреть файл

@ -1,44 +1,44 @@
RANLIB ?= ranlib
PCHOBJS=patch.o
XPWNOBJS=plist.o pwnutil.o outputstate.o nor_files.o 8900.o img2.o bspatch.o ibootim.o lzss.o lzssfile.o ../dmg/zlib-1.2.3/contrib/minizip/ioapi.o ../dmg/zlib-1.2.3/contrib/minizip/unzip.o ../dmg/zlib-1.2.3/contrib/minizip/zip.o
DMGOBJS=../dmg/base64.o ../dmg/resources.o ../dmg/checksum.o ../dmg/udif.o ../dmg/partition.o ../dmg/io.o ../dmg/filevault.o ../dmg/dmgfile.o ../dmg/dmglib.o
HFSOBJS=../hfs/volume.o ../hfs/btree.o ../hfs/extents.o ../hfs/rawfile.o ../hfs/catalog.o ../hfs/flatfile.o ../hfs/utility.o ../hfs/fastunicodecompare.o ../hfs/abstractfile.o ../hfs/hfslib.o
RANLIB ?= ranlib
PCHOBJS=patch.o
XPWNOBJS=plist.o pwnutil.o outputstate.o nor_files.o 8900.o img2.o bspatch.o ibootim.o lzss.o lzssfile.o ../dmg/zlib-1.2.3/contrib/minizip/ioapi.o ../dmg/zlib-1.2.3/contrib/minizip/unzip.o ../dmg/zlib-1.2.3/contrib/minizip/zip.o
DMGOBJS=../dmg/base64.o ../dmg/resources.o ../dmg/checksum.o ../dmg/udif.o ../dmg/partition.o ../dmg/io.o ../dmg/filevault.o ../dmg/dmgfile.o ../dmg/dmglib.o
HFSOBJS=../hfs/volume.o ../hfs/btree.o ../hfs/extents.o ../hfs/rawfile.o ../hfs/catalog.o ../hfs/flatfile.o ../hfs/utility.o ../hfs/fastunicodecompare.o ../hfs/abstractfile.o ../hfs/hfslib.o
CFLAGS=-D_FILE_OFFSET_BITS=64 -DHAVE_CRYPT -O3
STATIC_LIBRARIES=../dmg/zlib-1.2.3/libz.a ../dmg/openssl-0.9.8g/libcrypto.a ../dmg/openssl-0.9.8g/libcrypto.a bzip2-1.0.5/libbz2.a libpng-1.2.28/libpng.a
LIBRARIES=`if $(CC) win32test.c -o /dev/null 2>/dev/null ; then echo ""; else echo "-lgdi32"; fi` -lm
STATIC_LIBRARIES=../dmg/zlib-1.2.3/libz.a ../dmg/openssl-0.9.8g/libcrypto.a ../dmg/openssl-0.9.8g/libcrypto.a bzip2-1.0.5/libbz2.a libpng-1.2.28/libpng.a
LIBRARIES=`if $(CC) win32test.c -o /dev/null 2>/dev/null ; then echo ""; else echo "-lgdi32"; fi` -lm
INCLUDES=-I../hfs -I../dmg -Ilibpng-1.2.28 -I../dmg/zlib-1.2.3 -I../dmg/openssl-0.9.8g/include -Ibzip2-1.0.5
all: pch
pch: $(DMGOBJS) $(HFSOBJS) $(XPWNOBJS) $(PCHOBJS) $(STATIC_LIBRARIES)
$(CC) $(CFLAGS) $(DMGOBJS) $(HFSOBJS) $(XPWNOBJS) $(PCHOBJS) $(STATIC_LIBRARIES) $(LIBRARIES) -o pch
libxpwn.a: libxpwn.o $(DMGOBJS) $(HFSOBJS) $(XPWNOBJS) $(STATIC_LIBRARIES)
all: pch
pch: $(DMGOBJS) $(HFSOBJS) $(XPWNOBJS) $(PCHOBJS) $(STATIC_LIBRARIES)
$(CC) $(CFLAGS) $(DMGOBJS) $(HFSOBJS) $(XPWNOBJS) $(PCHOBJS) $(STATIC_LIBRARIES) $(LIBRARIES) -o pch
libxpwn.a: libxpwn.o $(DMGOBJS) $(HFSOBJS) $(XPWNOBJS) $(STATIC_LIBRARIES)
$(LD) libxpwn.o $(DMGOBJS) $(HFSOBJS) $(XPWNOBJS) $(STATIC_LIBRARIES) -r -o libxpwnbuild.o
ar rc libxpwn.a libxpwnbuild.o
ranlib libxpwn.a
%.o: %.c
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
../dmg/zlib-1.2.3/Makefile:
cd ../dmg/zlib-1.2.3; ./configure
../dmg/zlib-1.2.3/libz.a: ../dmg/zlib-1.2.3/Makefile
cd ../dmg/zlib-1.2.3; make
../dmg/openssl-0.9.8g/libcrypto.a:
touch ../dmg/openssl-0.9.8g/Makefile
cd ../dmg/openssl-0.9.8g/crypto; make
bzip2-1.0.5/libbz2.a:
cd bzip2-1.0.5; make
libpng-1.2.28/libpng.a:
cd libpng-1.2.28; make
clean:
-rm *.o
-rm pch
-rm pch.exe
-rm libxpwn.a
ranlib libxpwn.a
%.o: %.c
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
../dmg/zlib-1.2.3/Makefile:
cd ../dmg/zlib-1.2.3; ./configure
../dmg/zlib-1.2.3/libz.a: ../dmg/zlib-1.2.3/Makefile
cd ../dmg/zlib-1.2.3; make
../dmg/openssl-0.9.8g/libcrypto.a:
touch ../dmg/openssl-0.9.8g/Makefile
cd ../dmg/openssl-0.9.8g/crypto; make
bzip2-1.0.5/libbz2.a:
cd bzip2-1.0.5; make
libpng-1.2.28/libpng.a:
cd libpng-1.2.28; make
clean:
-rm *.o
-rm pch
-rm pch.exe
-rm libxpwn.a

Просмотреть файл

@ -1,218 +1,218 @@
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <bzlib.h>
#include "abstractfile.h"
static off_t offtin(unsigned char *buf)
{
off_t y;
y = buf[7] & 0x7F;
y <<= 8; y += buf[6];
y <<= 8; y += buf[5];
y <<= 8; y += buf[4];
y <<= 8; y += buf[3];
y <<= 8; y += buf[2];
y <<= 8; y += buf[1];
y <<= 8; y += buf[0];
if(buf[7] & 0x80) y = -y;
return y;
}
typedef struct {
bz_stream bz2;
AbstractFile* file;
off_t offset;
unsigned char* inBuffer;
unsigned char* outBuffer;
size_t bufferLen;
char ended;
} BZStream;
size_t bzRead(int *bzerr, BZStream* stream, unsigned char* out, size_t len) {
size_t toRead;
size_t haveRead;
size_t total;
total = len;
*bzerr = BZ_OK;
while(total > 0) {
if(!stream->ended) {
memmove(stream->inBuffer, stream->bz2.next_in, stream->bz2.avail_in);
stream->file->seek(stream->file, stream->offset);
haveRead = stream->file->read(stream->file, stream->inBuffer + stream->bz2.avail_in, stream->bufferLen - stream->bz2.avail_in);
stream->offset += haveRead;
stream->bz2.avail_in += haveRead;
stream->bz2.next_in = stream->inBuffer;
*bzerr = BZ2_bzDecompress(&(stream->bz2));
if(*bzerr == BZ_STREAM_END) {
stream->ended = TRUE;
} else {
if(*bzerr != BZ_OK) {
return 0;
}
}
}
if(total > (stream->bufferLen - stream->bz2.avail_out)) {
toRead = stream->bufferLen - stream->bz2.avail_out;
} else {
toRead = total;
}
memcpy(out, stream->outBuffer, toRead);
memmove(stream->outBuffer, stream->outBuffer + toRead, stream->bufferLen - toRead);
stream->bz2.next_out -= toRead;
stream->bz2.avail_out += toRead;
out += toRead;
total -= toRead;
if(total > 0 && stream->ended) {
return (len - total);
}
}
return len;
}
void closeBZStream(BZStream* stream) {
free(stream->inBuffer);
free(stream->outBuffer);
BZ2_bzDecompressEnd(&(stream->bz2));
free(stream);
}
BZStream* openBZStream(AbstractFile* file, off_t offset, size_t bufferLen) {
BZStream* stream;
stream = (BZStream*) malloc(sizeof(BZStream));
stream->file = file;
stream->offset = offset;
stream->bufferLen = bufferLen;
stream->inBuffer = (unsigned char*) malloc(bufferLen);
stream->outBuffer = (unsigned char*) malloc(bufferLen);
memset(&(stream->bz2), 0, sizeof(bz_stream));
BZ2_bzDecompressInit(&(stream->bz2), 0, FALSE);
stream->bz2.next_in = stream->inBuffer;
stream->bz2.avail_in = 0;
stream->bz2.next_out = stream->outBuffer;
stream->bz2.avail_out = bufferLen;
stream->ended = FALSE;
return stream;
}
int patch(AbstractFile* in, AbstractFile* out, AbstractFile* patch) {
unsigned char header[32], buf[8];
off_t oldsize, newsize;
off_t bzctrllen, bzdatalen;
off_t oldpos, newpos;
unsigned char *old, *newBuffer;
int i;
int cbz2err, dbz2err, ebz2err;
off_t ctrl[3];
size_t lenread;
BZStream* cpfbz2;
BZStream* dpfbz2;
BZStream* epfbz2;
/* Read header */
if (patch->read(patch, header, 32) < 32) {
return -1;
}
/* Check for appropriate magic */
if (memcmp(header, "BSDIFF40", 8) != 0)
return -2;
/* Read lengths from header */
bzctrllen = offtin(header + 8);
bzdatalen = offtin(header + 16);
newsize = offtin(header + 24);
if((bzctrllen < 0) || (bzdatalen < 0) || (newsize < 0))
return -3;
cpfbz2 = openBZStream(patch, 32, 1024);
dpfbz2 = openBZStream(patch, 32 + bzctrllen, 1024);
epfbz2 = openBZStream(patch, 32 + bzctrllen + bzdatalen, 1024);
oldsize = in->getLength(in);
old = malloc(oldsize + 1);
in->seek(in, 0);
in->read(in, old, oldsize);
in->close(in);
newBuffer = malloc(newsize + 1);
oldpos = 0;
newpos = 0;
while(newpos < newsize) {
/* Read control data */
for(i=0;i<=2;i++) {
lenread = bzRead(&cbz2err, cpfbz2, buf, 8);
if ((lenread < 8) || ((cbz2err != BZ_OK) &&
(cbz2err != BZ_STREAM_END)))
return -4;
ctrl[i] = offtin(buf);
};
/* Sanity-check */
if((newpos + ctrl[0]) > newsize)
return -5;
/* Read diff string */
memset(newBuffer + newpos, 0, ctrl[0]);
lenread = bzRead(&dbz2err, dpfbz2, newBuffer + newpos, ctrl[0]);
if ((lenread < ctrl[0]) ||
((dbz2err != BZ_OK) && (dbz2err != BZ_STREAM_END)))
return -6;
/* Add old data to diff string */
for(i = 0; i < ctrl[0]; i++) {
if(((oldpos + i)>=0) && ((oldpos + i)<oldsize)) {
newBuffer[newpos + i] += old[oldpos + i];
}
}
/* Adjust pointers */
newpos += ctrl[0];
oldpos += ctrl[0];
/* Sanity-check */
if((newpos + ctrl[1]) > newsize)
return -7;
/* Read extra string */
lenread = bzRead(&ebz2err, epfbz2, newBuffer + newpos, ctrl[1]);
if ((lenread < ctrl[1]) ||
((ebz2err != BZ_OK) && (ebz2err != BZ_STREAM_END)))
return -8;
/* Adjust pointers */
newpos += ctrl[1];
oldpos += ctrl[2];
};
closeBZStream(cpfbz2);
closeBZStream(dpfbz2);
closeBZStream(epfbz2);
out->seek(out, 0);
if(out->write(out, newBuffer, newsize) != newsize)
return -9;
out->close(out);
free(newBuffer);
#include <string.h>
#include <bzlib.h>
#include "abstractfile.h"
static off_t offtin(unsigned char *buf)
{
off_t y;
y = buf[7] & 0x7F;
y <<= 8; y += buf[6];
y <<= 8; y += buf[5];
y <<= 8; y += buf[4];
y <<= 8; y += buf[3];
y <<= 8; y += buf[2];
y <<= 8; y += buf[1];
y <<= 8; y += buf[0];
if(buf[7] & 0x80) y = -y;
return y;
}
typedef struct {
bz_stream bz2;
AbstractFile* file;
off_t offset;
unsigned char* inBuffer;
unsigned char* outBuffer;
size_t bufferLen;
char ended;
} BZStream;
size_t bzRead(int *bzerr, BZStream* stream, unsigned char* out, size_t len) {
size_t toRead;
size_t haveRead;
size_t total;
total = len;
*bzerr = BZ_OK;
while(total > 0) {
if(!stream->ended) {
memmove(stream->inBuffer, stream->bz2.next_in, stream->bz2.avail_in);
stream->file->seek(stream->file, stream->offset);
haveRead = stream->file->read(stream->file, stream->inBuffer + stream->bz2.avail_in, stream->bufferLen - stream->bz2.avail_in);
stream->offset += haveRead;
stream->bz2.avail_in += haveRead;
stream->bz2.next_in = stream->inBuffer;
*bzerr = BZ2_bzDecompress(&(stream->bz2));
if(*bzerr == BZ_STREAM_END) {
stream->ended = TRUE;
} else {
if(*bzerr != BZ_OK) {
return 0;
}
}
}
if(total > (stream->bufferLen - stream->bz2.avail_out)) {
toRead = stream->bufferLen - stream->bz2.avail_out;
} else {
toRead = total;
}
memcpy(out, stream->outBuffer, toRead);
memmove(stream->outBuffer, stream->outBuffer + toRead, stream->bufferLen - toRead);
stream->bz2.next_out -= toRead;
stream->bz2.avail_out += toRead;
out += toRead;
total -= toRead;
if(total > 0 && stream->ended) {
return (len - total);
}
}
return len;
}
void closeBZStream(BZStream* stream) {
free(stream->inBuffer);
free(stream->outBuffer);
BZ2_bzDecompressEnd(&(stream->bz2));
free(stream);
}
BZStream* openBZStream(AbstractFile* file, off_t offset, size_t bufferLen) {
BZStream* stream;
stream = (BZStream*) malloc(sizeof(BZStream));
stream->file = file;
stream->offset = offset;
stream->bufferLen = bufferLen;
stream->inBuffer = (unsigned char*) malloc(bufferLen);
stream->outBuffer = (unsigned char*) malloc(bufferLen);
memset(&(stream->bz2), 0, sizeof(bz_stream));
BZ2_bzDecompressInit(&(stream->bz2), 0, FALSE);
stream->bz2.next_in = stream->inBuffer;
stream->bz2.avail_in = 0;
stream->bz2.next_out = stream->outBuffer;
stream->bz2.avail_out = bufferLen;
stream->ended = FALSE;
return stream;
}
int patch(AbstractFile* in, AbstractFile* out, AbstractFile* patch) {
unsigned char header[32], buf[8];
off_t oldsize, newsize;
off_t bzctrllen, bzdatalen;
off_t oldpos, newpos;
unsigned char *old, *newBuffer;
int i;
int cbz2err, dbz2err, ebz2err;
off_t ctrl[3];
size_t lenread;
BZStream* cpfbz2;
BZStream* dpfbz2;
BZStream* epfbz2;
/* Read header */
if (patch->read(patch, header, 32) < 32) {
return -1;
}
/* Check for appropriate magic */
if (memcmp(header, "BSDIFF40", 8) != 0)
return -2;
/* Read lengths from header */
bzctrllen = offtin(header + 8);
bzdatalen = offtin(header + 16);
newsize = offtin(header + 24);
if((bzctrllen < 0) || (bzdatalen < 0) || (newsize < 0))
return -3;
cpfbz2 = openBZStream(patch, 32, 1024);
dpfbz2 = openBZStream(patch, 32 + bzctrllen, 1024);
epfbz2 = openBZStream(patch, 32 + bzctrllen + bzdatalen, 1024);
oldsize = in->getLength(in);
old = malloc(oldsize + 1);
in->seek(in, 0);
in->read(in, old, oldsize);
in->close(in);
newBuffer = malloc(newsize + 1);
oldpos = 0;
newpos = 0;
while(newpos < newsize) {
/* Read control data */
for(i=0;i<=2;i++) {
lenread = bzRead(&cbz2err, cpfbz2, buf, 8);
if ((lenread < 8) || ((cbz2err != BZ_OK) &&
(cbz2err != BZ_STREAM_END)))
return -4;
ctrl[i] = offtin(buf);
};
/* Sanity-check */
if((newpos + ctrl[0]) > newsize)
return -5;
/* Read diff string */
memset(newBuffer + newpos, 0, ctrl[0]);
lenread = bzRead(&dbz2err, dpfbz2, newBuffer + newpos, ctrl[0]);
if ((lenread < ctrl[0]) ||
((dbz2err != BZ_OK) && (dbz2err != BZ_STREAM_END)))
return -6;
/* Add old data to diff string */
for(i = 0; i < ctrl[0]; i++) {
if(((oldpos + i)>=0) && ((oldpos + i)<oldsize)) {
newBuffer[newpos + i] += old[oldpos + i];
}
}
/* Adjust pointers */
newpos += ctrl[0];
oldpos += ctrl[0];
/* Sanity-check */
if((newpos + ctrl[1]) > newsize)
return -7;
/* Read extra string */
lenread = bzRead(&ebz2err, epfbz2, newBuffer + newpos, ctrl[1]);
if ((lenread < ctrl[1]) ||
((ebz2err != BZ_OK) && (ebz2err != BZ_STREAM_END)))
return -8;
/* Adjust pointers */
newpos += ctrl[1];
oldpos += ctrl[2];
};
closeBZStream(cpfbz2);
closeBZStream(dpfbz2);
closeBZStream(epfbz2);
out->seek(out, 0);
if(out->write(out, newBuffer, newsize) != newsize)
return -9;
out->close(out);
free(newBuffer);
free(old);
patch->close(patch);
return 0;
}
patch->close(patch);
return 0;
}

Просмотреть файл

@ -1,59 +1,59 @@
# This Makefile builds a shared version of the library,
# libbz2.so.1.0.4, with soname libbz2.so.1.0,
# at least on x86-Linux (RedHat 7.2),
# with gcc-2.96 20000731 (Red Hat Linux 7.1 2.96-98).
# Please see the README file for some important info
# about building the library like this.
# ------------------------------------------------------------------
# This file is part of bzip2/libbzip2, a program and library for
# lossless, block-sorting data compression.
#
# bzip2/libbzip2 version 1.0.5 of 10 December 2007
# Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
#
# Please read the WARNING, DISCLAIMER and PATENTS sections in the
# README file.
#
# This program is released under the terms of the license contained
# in the file LICENSE.
# ------------------------------------------------------------------
SHELL=/bin/sh
CC=gcc
BIGFILES=-D_FILE_OFFSET_BITS=64
CFLAGS=-fpic -fPIC -Wall -Winline -O2 -g $(BIGFILES)
OBJS= blocksort.o \
huffman.o \
crctable.o \
randtable.o \
compress.o \
decompress.o \
bzlib.o
all: $(OBJS)
$(CC) -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.1.0.4 $(OBJS)
$(CC) $(CFLAGS) -o bzip2-shared bzip2.c libbz2.so.1.0.4
rm -f libbz2.so.1.0
ln -s libbz2.so.1.0.4 libbz2.so.1.0
clean:
rm -f $(OBJS) bzip2.o libbz2.so.1.0.4 libbz2.so.1.0 bzip2-shared
blocksort.o: blocksort.c
$(CC) $(CFLAGS) -c blocksort.c
huffman.o: huffman.c
$(CC) $(CFLAGS) -c huffman.c
crctable.o: crctable.c
$(CC) $(CFLAGS) -c crctable.c
randtable.o: randtable.c
$(CC) $(CFLAGS) -c randtable.c
compress.o: compress.c
$(CC) $(CFLAGS) -c compress.c
decompress.o: decompress.c
$(CC) $(CFLAGS) -c decompress.c
bzlib.o: bzlib.c
$(CC) $(CFLAGS) -c bzlib.c
# This Makefile builds a shared version of the library,
# libbz2.so.1.0.4, with soname libbz2.so.1.0,
# at least on x86-Linux (RedHat 7.2),
# with gcc-2.96 20000731 (Red Hat Linux 7.1 2.96-98).
# Please see the README file for some important info
# about building the library like this.
# ------------------------------------------------------------------
# This file is part of bzip2/libbzip2, a program and library for
# lossless, block-sorting data compression.
#
# bzip2/libbzip2 version 1.0.5 of 10 December 2007
# Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
#
# Please read the WARNING, DISCLAIMER and PATENTS sections in the
# README file.
#
# This program is released under the terms of the license contained
# in the file LICENSE.
# ------------------------------------------------------------------
SHELL=/bin/sh
CC=gcc
BIGFILES=-D_FILE_OFFSET_BITS=64
CFLAGS=-fpic -fPIC -Wall -Winline -O2 -g $(BIGFILES)
OBJS= blocksort.o \
huffman.o \
crctable.o \
randtable.o \
compress.o \
decompress.o \
bzlib.o
all: $(OBJS)
$(CC) -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.1.0.4 $(OBJS)
$(CC) $(CFLAGS) -o bzip2-shared bzip2.c libbz2.so.1.0.4
rm -f libbz2.so.1.0
ln -s libbz2.so.1.0.4 libbz2.so.1.0
clean:
rm -f $(OBJS) bzip2.o libbz2.so.1.0.4 libbz2.so.1.0 bzip2-shared
blocksort.o: blocksort.c
$(CC) $(CFLAGS) -c blocksort.c
huffman.o: huffman.c
$(CC) $(CFLAGS) -c huffman.c
crctable.o: crctable.c
$(CC) $(CFLAGS) -c crctable.c
randtable.o: randtable.c
$(CC) $(CFLAGS) -c randtable.c
compress.o: compress.c
$(CC) $(CFLAGS) -c compress.c
decompress.o: decompress.c
$(CC) $(CFLAGS) -c decompress.c
bzlib.o: bzlib.c
$(CC) $(CFLAGS) -c bzlib.c

Просмотреть файл

@ -1,210 +1,210 @@
This is the README for bzip2/libzip2.
This version is fully compatible with the previous public releases.
------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in this file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------
Complete documentation is available in Postscript form (manual.ps),
PDF (manual.pdf) or html (manual.html). A plain-text version of the
manual page is available as bzip2.txt.
HOW TO BUILD -- UNIX
Type 'make'. This builds the library libbz2.a and then the programs
bzip2 and bzip2recover. Six self-tests are run. If the self-tests
complete ok, carry on to installation:
To install in /usr/local/bin, /usr/local/lib, /usr/local/man and
/usr/local/include, type
make install
To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type
make install PREFIX=/xxx/yyy
If you are (justifiably) paranoid and want to see what 'make install'
is going to do, you can first do
make -n install or
make -n install PREFIX=/xxx/yyy respectively.
The -n instructs make to show the commands it would execute, but not
actually execute them.
HOW TO BUILD -- UNIX, shared library libbz2.so.
Do 'make -f Makefile-libbz2_so'. This Makefile seems to work for
Linux-ELF (RedHat 7.2 on an x86 box), with gcc. I make no claims
that it works for any other platform, though I suspect it probably
will work for most platforms employing both ELF and gcc.
bzip2-shared, a client of the shared library, is also built, but not
self-tested. So I suggest you also build using the normal Makefile,
since that conducts a self-test. A second reason to prefer the
version statically linked to the library is that, on x86 platforms,
building shared objects makes a valuable register (%ebx) unavailable
to gcc, resulting in a slowdown of 10%-20%, at least for bzip2.
Important note for people upgrading .so's from 0.9.0/0.9.5 to version
1.0.X. All the functions in the library have been renamed, from (eg)
bzCompress to BZ2_bzCompress, to avoid namespace pollution.
Unfortunately this means that the libbz2.so created by
Makefile-libbz2_so will not work with any program which used an older
version of the library. I do encourage library clients to make the
effort to upgrade to use version 1.0, since it is both faster and more
robust than previous versions.
HOW TO BUILD -- Windows 95, NT, DOS, Mac, etc.
It's difficult for me to support compilation on all these platforms.
My approach is to collect binaries for these platforms, and put them
on the master web site (http://www.bzip.org). Look there. However
(FWIW), bzip2-1.0.X is very standard ANSI C and should compile
unmodified with MS Visual C. If you have difficulties building, you
might want to read README.COMPILATION.PROBLEMS.
At least using MS Visual C++ 6, you can build from the unmodified
sources by issuing, in a command shell:
nmake -f makefile.msc
(you may need to first run the MSVC-provided script VCVARS32.BAT
so as to set up paths to the MSVC tools correctly).
VALIDATION
Correct operation, in the sense that a compressed file can always be
decompressed to reproduce the original, is obviously of paramount
importance. To validate bzip2, I used a modified version of Mark
Nelson's churn program. Churn is an automated test driver which
recursively traverses a directory structure, using bzip2 to compress
and then decompress each file it encounters, and checking that the
decompressed data is the same as the original.
Please read and be aware of the following:
WARNING:
This program and library (attempts to) compress data by
performing several non-trivial transformations on it.
Unless you are 100% familiar with *all* the algorithms
contained herein, and with the consequences of modifying them,
you should NOT meddle with the compression or decompression
machinery. Incorrect changes can and very likely *will*
lead to disastrous loss of data.
DISCLAIMER:
I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE
USE OF THIS PROGRAM/LIBRARY, HOWSOEVER CAUSED.
Every compression of a file implies an assumption that the
compressed file can be decompressed to reproduce the original.
Great efforts in design, coding and testing have been made to
ensure that this program works correctly. However, the complexity
of the algorithms, and, in particular, the presence of various
special cases in the code which occur with very low but non-zero
probability make it impossible to rule out the possibility of bugs
remaining in the program. DO NOT COMPRESS ANY DATA WITH THIS
PROGRAM UNLESS YOU ARE PREPARED TO ACCEPT THE POSSIBILITY, HOWEVER
SMALL, THAT THE DATA WILL NOT BE RECOVERABLE.
That is not to say this program is inherently unreliable.
Indeed, I very much hope the opposite is true. bzip2/libbzip2
has been carefully constructed and extensively tested.
PATENTS:
To the best of my knowledge, bzip2/libbzip2 does not use any
patented algorithms. However, I do not have the resources
to carry out a patent search. Therefore I cannot give any
guarantee of the above statement.
WHAT'S NEW IN 0.9.0 (as compared to 0.1pl2) ?
* Approx 10% faster compression, 30% faster decompression
* -t (test mode) is a lot quicker
* Can decompress concatenated compressed files
* Programming interface, so programs can directly read/write .bz2 files
* Less restrictive (BSD-style) licensing
* Flag handling more compatible with GNU gzip
* Much more documentation, i.e., a proper user manual
* Hopefully, improved portability (at least of the library)
WHAT'S NEW IN 0.9.5 ?
* Compression speed is much less sensitive to the input
data than in previous versions. Specifically, the very
slow performance caused by repetitive data is fixed.
* Many small improvements in file and flag handling.
* A Y2K statement.
WHAT'S NEW IN 1.0.0 ?
See the CHANGES file.
WHAT'S NEW IN 1.0.2 ?
See the CHANGES file.
WHAT'S NEW IN 1.0.3 ?
See the CHANGES file.
WHAT'S NEW IN 1.0.4 ?
See the CHANGES file.
WHAT'S NEW IN 1.0.5 ?
See the CHANGES file.
I hope you find bzip2 useful. Feel free to contact me at
jseward@bzip.org
if you have any suggestions or queries. Many people mailed me with
comments, suggestions and patches after the releases of bzip-0.15,
bzip-0.21, and bzip2 versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1,
1.0.2 and 1.0.3, and the changes in bzip2 are largely a result of this
feedback. I thank you for your comments.
bzip2's "home" is http://www.bzip.org/
Julian Seward
jseward@bzip.org
Cambridge, UK.
18 July 1996 (version 0.15)
25 August 1996 (version 0.21)
7 August 1997 (bzip2, version 0.1)
29 August 1997 (bzip2, version 0.1pl2)
23 August 1998 (bzip2, version 0.9.0)
8 June 1999 (bzip2, version 0.9.5)
4 Sept 1999 (bzip2, version 0.9.5d)
5 May 2000 (bzip2, version 1.0pre8)
30 December 2001 (bzip2, version 1.0.2pre1)
15 February 2005 (bzip2, version 1.0.3)
20 December 2006 (bzip2, version 1.0.4)
10 December 2007 (bzip2, version 1.0.5)
This is the README for bzip2/libzip2.
This version is fully compatible with the previous public releases.
------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in this file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------
Complete documentation is available in Postscript form (manual.ps),
PDF (manual.pdf) or html (manual.html). A plain-text version of the
manual page is available as bzip2.txt.
HOW TO BUILD -- UNIX
Type 'make'. This builds the library libbz2.a and then the programs
bzip2 and bzip2recover. Six self-tests are run. If the self-tests
complete ok, carry on to installation:
To install in /usr/local/bin, /usr/local/lib, /usr/local/man and
/usr/local/include, type
make install
To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type
make install PREFIX=/xxx/yyy
If you are (justifiably) paranoid and want to see what 'make install'
is going to do, you can first do
make -n install or
make -n install PREFIX=/xxx/yyy respectively.
The -n instructs make to show the commands it would execute, but not
actually execute them.
HOW TO BUILD -- UNIX, shared library libbz2.so.
Do 'make -f Makefile-libbz2_so'. This Makefile seems to work for
Linux-ELF (RedHat 7.2 on an x86 box), with gcc. I make no claims
that it works for any other platform, though I suspect it probably
will work for most platforms employing both ELF and gcc.
bzip2-shared, a client of the shared library, is also built, but not
self-tested. So I suggest you also build using the normal Makefile,
since that conducts a self-test. A second reason to prefer the
version statically linked to the library is that, on x86 platforms,
building shared objects makes a valuable register (%ebx) unavailable
to gcc, resulting in a slowdown of 10%-20%, at least for bzip2.
Important note for people upgrading .so's from 0.9.0/0.9.5 to version
1.0.X. All the functions in the library have been renamed, from (eg)
bzCompress to BZ2_bzCompress, to avoid namespace pollution.
Unfortunately this means that the libbz2.so created by
Makefile-libbz2_so will not work with any program which used an older
version of the library. I do encourage library clients to make the
effort to upgrade to use version 1.0, since it is both faster and more
robust than previous versions.
HOW TO BUILD -- Windows 95, NT, DOS, Mac, etc.
It's difficult for me to support compilation on all these platforms.
My approach is to collect binaries for these platforms, and put them
on the master web site (http://www.bzip.org). Look there. However
(FWIW), bzip2-1.0.X is very standard ANSI C and should compile
unmodified with MS Visual C. If you have difficulties building, you
might want to read README.COMPILATION.PROBLEMS.
At least using MS Visual C++ 6, you can build from the unmodified
sources by issuing, in a command shell:
nmake -f makefile.msc
(you may need to first run the MSVC-provided script VCVARS32.BAT
so as to set up paths to the MSVC tools correctly).
VALIDATION
Correct operation, in the sense that a compressed file can always be
decompressed to reproduce the original, is obviously of paramount
importance. To validate bzip2, I used a modified version of Mark
Nelson's churn program. Churn is an automated test driver which
recursively traverses a directory structure, using bzip2 to compress
and then decompress each file it encounters, and checking that the
decompressed data is the same as the original.
Please read and be aware of the following:
WARNING:
This program and library (attempts to) compress data by
performing several non-trivial transformations on it.
Unless you are 100% familiar with *all* the algorithms
contained herein, and with the consequences of modifying them,
you should NOT meddle with the compression or decompression
machinery. Incorrect changes can and very likely *will*
lead to disastrous loss of data.
DISCLAIMER:
I TAKE NO RESPONSIBILITY FOR ANY LOSS OF DATA ARISING FROM THE
USE OF THIS PROGRAM/LIBRARY, HOWSOEVER CAUSED.
Every compression of a file implies an assumption that the
compressed file can be decompressed to reproduce the original.
Great efforts in design, coding and testing have been made to
ensure that this program works correctly. However, the complexity
of the algorithms, and, in particular, the presence of various
special cases in the code which occur with very low but non-zero
probability make it impossible to rule out the possibility of bugs
remaining in the program. DO NOT COMPRESS ANY DATA WITH THIS
PROGRAM UNLESS YOU ARE PREPARED TO ACCEPT THE POSSIBILITY, HOWEVER
SMALL, THAT THE DATA WILL NOT BE RECOVERABLE.
That is not to say this program is inherently unreliable.
Indeed, I very much hope the opposite is true. bzip2/libbzip2
has been carefully constructed and extensively tested.
PATENTS:
To the best of my knowledge, bzip2/libbzip2 does not use any
patented algorithms. However, I do not have the resources
to carry out a patent search. Therefore I cannot give any
guarantee of the above statement.
WHAT'S NEW IN 0.9.0 (as compared to 0.1pl2) ?
* Approx 10% faster compression, 30% faster decompression
* -t (test mode) is a lot quicker
* Can decompress concatenated compressed files
* Programming interface, so programs can directly read/write .bz2 files
* Less restrictive (BSD-style) licensing
* Flag handling more compatible with GNU gzip
* Much more documentation, i.e., a proper user manual
* Hopefully, improved portability (at least of the library)
WHAT'S NEW IN 0.9.5 ?
* Compression speed is much less sensitive to the input
data than in previous versions. Specifically, the very
slow performance caused by repetitive data is fixed.
* Many small improvements in file and flag handling.
* A Y2K statement.
WHAT'S NEW IN 1.0.0 ?
See the CHANGES file.
WHAT'S NEW IN 1.0.2 ?
See the CHANGES file.
WHAT'S NEW IN 1.0.3 ?
See the CHANGES file.
WHAT'S NEW IN 1.0.4 ?
See the CHANGES file.
WHAT'S NEW IN 1.0.5 ?
See the CHANGES file.
I hope you find bzip2 useful. Feel free to contact me at
jseward@bzip.org
if you have any suggestions or queries. Many people mailed me with
comments, suggestions and patches after the releases of bzip-0.15,
bzip-0.21, and bzip2 versions 0.1pl2, 0.9.0, 0.9.5, 1.0.0, 1.0.1,
1.0.2 and 1.0.3, and the changes in bzip2 are largely a result of this
feedback. I thank you for your comments.
bzip2's "home" is http://www.bzip.org/
Julian Seward
jseward@bzip.org
Cambridge, UK.
18 July 1996 (version 0.15)
25 August 1996 (version 0.21)
7 August 1997 (bzip2, version 0.1)
29 August 1997 (bzip2, version 0.1pl2)
23 August 1998 (bzip2, version 0.9.0)
8 June 1999 (bzip2, version 0.9.5)
4 Sept 1999 (bzip2, version 0.9.5d)
5 May 2000 (bzip2, version 1.0pre8)
30 December 2001 (bzip2, version 1.0.2pre1)
15 February 2005 (bzip2, version 1.0.3)
20 December 2006 (bzip2, version 1.0.4)
10 December 2007 (bzip2, version 1.0.5)

Просмотреть файл

@ -1,58 +1,58 @@
------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------
bzip2-1.0.5 should compile without problems on the vast majority of
platforms. Using the supplied Makefile, I've built and tested it
myself for x86-linux and amd64-linux. With makefile.msc, Visual C++
6.0 and nmake, you can build a native Win32 version too. Large file
support seems to work correctly on at least on amd64-linux.
When I say "large file" I mean a file of size 2,147,483,648 (2^31)
bytes or above. Many older OSs can't handle files above this size,
but many newer ones can. Large files are pretty huge -- most files
you'll encounter are not Large Files.
Early versions of bzip2 (0.1, 0.9.0, 0.9.5) compiled on a wide variety
of platforms without difficulty, and I hope this version will continue
in that tradition. However, in order to support large files, I've had
to include the define -D_FILE_OFFSET_BITS=64 in the Makefile. This
can cause problems.
The technique of adding -D_FILE_OFFSET_BITS=64 to get large file
support is, as far as I know, the Recommended Way to get correct large
file support. For more details, see the Large File Support
Specification, published by the Large File Summit, at
http://ftp.sas.com/standards/large.file
As a general comment, if you get compilation errors which you think
are related to large file support, try removing the above define from
the Makefile, ie, delete the line
BIGFILES=-D_FILE_OFFSET_BITS=64
from the Makefile, and do 'make clean ; make'. This will give you a
version of bzip2 without large file support, which, for most
applications, is probably not a problem.
Alternatively, try some of the platform-specific hints listed below.
You can use the spewG.c program to generate huge files to test bzip2's
large file support, if you are feeling paranoid. Be aware though that
any compilation problems which affect bzip2 will also affect spewG.c,
alas.
AIX: I have reports that for large file support, you need to specify
-D_LARGE_FILES rather than -D_FILE_OFFSET_BITS=64. I have not tested
this myself.
------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------
bzip2-1.0.5 should compile without problems on the vast majority of
platforms. Using the supplied Makefile, I've built and tested it
myself for x86-linux and amd64-linux. With makefile.msc, Visual C++
6.0 and nmake, you can build a native Win32 version too. Large file
support seems to work correctly on at least on amd64-linux.
When I say "large file" I mean a file of size 2,147,483,648 (2^31)
bytes or above. Many older OSs can't handle files above this size,
but many newer ones can. Large files are pretty huge -- most files
you'll encounter are not Large Files.
Early versions of bzip2 (0.1, 0.9.0, 0.9.5) compiled on a wide variety
of platforms without difficulty, and I hope this version will continue
in that tradition. However, in order to support large files, I've had
to include the define -D_FILE_OFFSET_BITS=64 in the Makefile. This
can cause problems.
The technique of adding -D_FILE_OFFSET_BITS=64 to get large file
support is, as far as I know, the Recommended Way to get correct large
file support. For more details, see the Large File Support
Specification, published by the Large File Summit, at
http://ftp.sas.com/standards/large.file
As a general comment, if you get compilation errors which you think
are related to large file support, try removing the above define from
the Makefile, ie, delete the line
BIGFILES=-D_FILE_OFFSET_BITS=64
from the Makefile, and do 'make clean ; make'. This will give you a
version of bzip2 without large file support, which, for most
applications, is probably not a problem.
Alternatively, try some of the platform-specific hints listed below.
You can use the spewG.c program to generate huge files to test bzip2's
large file support, if you are feeling paranoid. Be aware though that
any compilation problems which affect bzip2 will also affect spewG.c,
alas.
AIX: I have reports that for large file support, you need to specify
-D_LARGE_FILES rather than -D_FILE_OFFSET_BITS=64. I have not tested
this myself.

Просмотреть файл

@ -1,45 +1,45 @@
----------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
----------------------------------------------------------------
The script xmlproc.sh takes an xml file as input,
and processes it to create .pdf, .html or .ps output.
It uses format.pl, a perl script to format <pre> blocks nicely,
and add CDATA tags so writers do not have to use eg. &lt;
The file "entities.xml" must be edited to reflect current
version, year, etc.
Usage:
./xmlproc.sh -v manual.xml
Validates an xml file to ensure no dtd-compliance errors
./xmlproc.sh -html manual.xml
Output: manual.html
./xmlproc.sh -pdf manual.xml
Output: manual.pdf
./xmlproc.sh -ps manual.xml
Output: manual.ps
Notum bene:
- pdfxmltex barfs if given a filename with an underscore in it
- xmltex won't work yet - there's a bug in passivetex
which we are all waiting for Sebastian to fix.
So we are going the xml -> pdf -> ps route for the time being,
using pdfxmltex.
----------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
----------------------------------------------------------------
The script xmlproc.sh takes an xml file as input,
and processes it to create .pdf, .html or .ps output.
It uses format.pl, a perl script to format <pre> blocks nicely,
and add CDATA tags so writers do not have to use eg. &lt;
The file "entities.xml" must be edited to reflect current
version, year, etc.
Usage:
./xmlproc.sh -v manual.xml
Validates an xml file to ensure no dtd-compliance errors
./xmlproc.sh -html manual.xml
Output: manual.html
./xmlproc.sh -pdf manual.xml
Output: manual.pdf
./xmlproc.sh -ps manual.xml
Output: manual.ps
Notum bene:
- pdfxmltex barfs if given a filename with an underscore in it
- xmltex won't work yet - there's a bug in passivetex
which we are all waiting for Sebastian to fix.
So we are going the xml -> pdf -> ps route for the time being,
using pdfxmltex.

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,282 +1,282 @@
/*-------------------------------------------------------------*/
/*--- Public header file for the library. ---*/
/*--- bzlib.h ---*/
/*-------------------------------------------------------------*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#ifndef _BZLIB_H
#define _BZLIB_H
#ifdef __cplusplus
extern "C" {
#endif
#define BZ_RUN 0
#define BZ_FLUSH 1
#define BZ_FINISH 2
#define BZ_OK 0
#define BZ_RUN_OK 1
#define BZ_FLUSH_OK 2
#define BZ_FINISH_OK 3
#define BZ_STREAM_END 4
#define BZ_SEQUENCE_ERROR (-1)
#define BZ_PARAM_ERROR (-2)
#define BZ_MEM_ERROR (-3)
#define BZ_DATA_ERROR (-4)
#define BZ_DATA_ERROR_MAGIC (-5)
#define BZ_IO_ERROR (-6)
#define BZ_UNEXPECTED_EOF (-7)
#define BZ_OUTBUFF_FULL (-8)
#define BZ_CONFIG_ERROR (-9)
typedef
struct {
char *next_in;
unsigned int avail_in;
unsigned int total_in_lo32;
unsigned int total_in_hi32;
char *next_out;
unsigned int avail_out;
unsigned int total_out_lo32;
unsigned int total_out_hi32;
void *state;
void *(*bzalloc)(void *,int,int);
void (*bzfree)(void *,void *);
void *opaque;
}
bz_stream;
#ifndef BZ_IMPORT
#define BZ_EXPORT
#endif
#ifndef BZ_NO_STDIO
/* Need a definitition for FILE */
#include <stdio.h>
#endif
#ifdef _WIN32
# include <windows.h>
# ifdef small
/* windows.h define small to char */
# undef small
# endif
# ifdef BZ_EXPORT
# define BZ_API(func) WINAPI func
# define BZ_EXTERN extern
# else
/* import windows dll dynamically */
# define BZ_API(func) (WINAPI * func)
# define BZ_EXTERN
# endif
#else
# define BZ_API(func) func
# define BZ_EXTERN extern
#endif
/*-- Core (low-level) library functions --*/
BZ_EXTERN int BZ_API(BZ2_bzCompressInit) (
bz_stream* strm,
int blockSize100k,
int verbosity,
int workFactor
);
BZ_EXTERN int BZ_API(BZ2_bzCompress) (
bz_stream* strm,
int action
);
BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) (
bz_stream* strm
);
BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) (
bz_stream *strm,
int verbosity,
int small
);
BZ_EXTERN int BZ_API(BZ2_bzDecompress) (
bz_stream* strm
);
BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) (
bz_stream *strm
);
/*-- High(er) level library functions --*/
#ifndef BZ_NO_STDIO
#define BZ_MAX_UNUSED 5000
typedef void BZFILE;
BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) (
int* bzerror,
FILE* f,
int verbosity,
int small,
void* unused,
int nUnused
);
BZ_EXTERN void BZ_API(BZ2_bzReadClose) (
int* bzerror,
BZFILE* b
);
BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) (
int* bzerror,
BZFILE* b,
void** unused,
int* nUnused
);
BZ_EXTERN int BZ_API(BZ2_bzRead) (
int* bzerror,
BZFILE* b,
void* buf,
int len
);
BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) (
int* bzerror,
FILE* f,
int blockSize100k,
int verbosity,
int workFactor
);
BZ_EXTERN void BZ_API(BZ2_bzWrite) (
int* bzerror,
BZFILE* b,
void* buf,
int len
);
BZ_EXTERN void BZ_API(BZ2_bzWriteClose) (
int* bzerror,
BZFILE* b,
int abandon,
unsigned int* nbytes_in,
unsigned int* nbytes_out
);
BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) (
int* bzerror,
BZFILE* b,
int abandon,
unsigned int* nbytes_in_lo32,
unsigned int* nbytes_in_hi32,
unsigned int* nbytes_out_lo32,
unsigned int* nbytes_out_hi32
);
#endif
/*-- Utility functions --*/
BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) (
char* dest,
unsigned int* destLen,
char* source,
unsigned int sourceLen,
int blockSize100k,
int verbosity,
int workFactor
);
BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) (
char* dest,
unsigned int* destLen,
char* source,
unsigned int sourceLen,
int small,
int verbosity
);
/*--
Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
to support better zlib compatibility.
This code is not _officially_ part of libbzip2 (yet);
I haven't tested it, documented it, or considered the
threading-safeness of it.
If this code breaks, please contact both Yoshioka and me.
--*/
BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) (
void
);
#ifndef BZ_NO_STDIO
BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) (
const char *path,
const char *mode
);
BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) (
int fd,
const char *mode
);
BZ_EXTERN int BZ_API(BZ2_bzread) (
BZFILE* b,
void* buf,
int len
);
BZ_EXTERN int BZ_API(BZ2_bzwrite) (
BZFILE* b,
void* buf,
int len
);
BZ_EXTERN int BZ_API(BZ2_bzflush) (
BZFILE* b
);
BZ_EXTERN void BZ_API(BZ2_bzclose) (
BZFILE* b
);
BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
BZFILE *b,
int *errnum
);
#endif
#ifdef __cplusplus
}
#endif
#endif
/*-------------------------------------------------------------*/
/*--- end bzlib.h ---*/
/*-------------------------------------------------------------*/
/*-------------------------------------------------------------*/
/*--- Public header file for the library. ---*/
/*--- bzlib.h ---*/
/*-------------------------------------------------------------*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#ifndef _BZLIB_H
#define _BZLIB_H
#ifdef __cplusplus
extern "C" {
#endif
#define BZ_RUN 0
#define BZ_FLUSH 1
#define BZ_FINISH 2
#define BZ_OK 0
#define BZ_RUN_OK 1
#define BZ_FLUSH_OK 2
#define BZ_FINISH_OK 3
#define BZ_STREAM_END 4
#define BZ_SEQUENCE_ERROR (-1)
#define BZ_PARAM_ERROR (-2)
#define BZ_MEM_ERROR (-3)
#define BZ_DATA_ERROR (-4)
#define BZ_DATA_ERROR_MAGIC (-5)
#define BZ_IO_ERROR (-6)
#define BZ_UNEXPECTED_EOF (-7)
#define BZ_OUTBUFF_FULL (-8)
#define BZ_CONFIG_ERROR (-9)
typedef
struct {
char *next_in;
unsigned int avail_in;
unsigned int total_in_lo32;
unsigned int total_in_hi32;
char *next_out;
unsigned int avail_out;
unsigned int total_out_lo32;
unsigned int total_out_hi32;
void *state;
void *(*bzalloc)(void *,int,int);
void (*bzfree)(void *,void *);
void *opaque;
}
bz_stream;
#ifndef BZ_IMPORT
#define BZ_EXPORT
#endif
#ifndef BZ_NO_STDIO
/* Need a definitition for FILE */
#include <stdio.h>
#endif
#ifdef _WIN32
# include <windows.h>
# ifdef small
/* windows.h define small to char */
# undef small
# endif
# ifdef BZ_EXPORT
# define BZ_API(func) WINAPI func
# define BZ_EXTERN extern
# else
/* import windows dll dynamically */
# define BZ_API(func) (WINAPI * func)
# define BZ_EXTERN
# endif
#else
# define BZ_API(func) func
# define BZ_EXTERN extern
#endif
/*-- Core (low-level) library functions --*/
BZ_EXTERN int BZ_API(BZ2_bzCompressInit) (
bz_stream* strm,
int blockSize100k,
int verbosity,
int workFactor
);
BZ_EXTERN int BZ_API(BZ2_bzCompress) (
bz_stream* strm,
int action
);
BZ_EXTERN int BZ_API(BZ2_bzCompressEnd) (
bz_stream* strm
);
BZ_EXTERN int BZ_API(BZ2_bzDecompressInit) (
bz_stream *strm,
int verbosity,
int small
);
BZ_EXTERN int BZ_API(BZ2_bzDecompress) (
bz_stream* strm
);
BZ_EXTERN int BZ_API(BZ2_bzDecompressEnd) (
bz_stream *strm
);
/*-- High(er) level library functions --*/
#ifndef BZ_NO_STDIO
#define BZ_MAX_UNUSED 5000
typedef void BZFILE;
BZ_EXTERN BZFILE* BZ_API(BZ2_bzReadOpen) (
int* bzerror,
FILE* f,
int verbosity,
int small,
void* unused,
int nUnused
);
BZ_EXTERN void BZ_API(BZ2_bzReadClose) (
int* bzerror,
BZFILE* b
);
BZ_EXTERN void BZ_API(BZ2_bzReadGetUnused) (
int* bzerror,
BZFILE* b,
void** unused,
int* nUnused
);
BZ_EXTERN int BZ_API(BZ2_bzRead) (
int* bzerror,
BZFILE* b,
void* buf,
int len
);
BZ_EXTERN BZFILE* BZ_API(BZ2_bzWriteOpen) (
int* bzerror,
FILE* f,
int blockSize100k,
int verbosity,
int workFactor
);
BZ_EXTERN void BZ_API(BZ2_bzWrite) (
int* bzerror,
BZFILE* b,
void* buf,
int len
);
BZ_EXTERN void BZ_API(BZ2_bzWriteClose) (
int* bzerror,
BZFILE* b,
int abandon,
unsigned int* nbytes_in,
unsigned int* nbytes_out
);
BZ_EXTERN void BZ_API(BZ2_bzWriteClose64) (
int* bzerror,
BZFILE* b,
int abandon,
unsigned int* nbytes_in_lo32,
unsigned int* nbytes_in_hi32,
unsigned int* nbytes_out_lo32,
unsigned int* nbytes_out_hi32
);
#endif
/*-- Utility functions --*/
BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffCompress) (
char* dest,
unsigned int* destLen,
char* source,
unsigned int sourceLen,
int blockSize100k,
int verbosity,
int workFactor
);
BZ_EXTERN int BZ_API(BZ2_bzBuffToBuffDecompress) (
char* dest,
unsigned int* destLen,
char* source,
unsigned int sourceLen,
int small,
int verbosity
);
/*--
Code contributed by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
to support better zlib compatibility.
This code is not _officially_ part of libbzip2 (yet);
I haven't tested it, documented it, or considered the
threading-safeness of it.
If this code breaks, please contact both Yoshioka and me.
--*/
BZ_EXTERN const char * BZ_API(BZ2_bzlibVersion) (
void
);
#ifndef BZ_NO_STDIO
BZ_EXTERN BZFILE * BZ_API(BZ2_bzopen) (
const char *path,
const char *mode
);
BZ_EXTERN BZFILE * BZ_API(BZ2_bzdopen) (
int fd,
const char *mode
);
BZ_EXTERN int BZ_API(BZ2_bzread) (
BZFILE* b,
void* buf,
int len
);
BZ_EXTERN int BZ_API(BZ2_bzwrite) (
BZFILE* b,
void* buf,
int len
);
BZ_EXTERN int BZ_API(BZ2_bzflush) (
BZFILE* b
);
BZ_EXTERN void BZ_API(BZ2_bzclose) (
BZFILE* b
);
BZ_EXTERN const char * BZ_API(BZ2_bzerror) (
BZFILE *b,
int *errnum
);
#endif
#ifdef __cplusplus
}
#endif
#endif
/*-------------------------------------------------------------*/
/*--- end bzlib.h ---*/
/*-------------------------------------------------------------*/

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,104 +1,104 @@
/*-------------------------------------------------------------*/
/*--- Table for doing CRCs ---*/
/*--- crctable.c ---*/
/*-------------------------------------------------------------*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#include "bzlib_private.h"
/*--
I think this is an implementation of the AUTODIN-II,
Ethernet & FDDI 32-bit CRC standard. Vaguely derived
from code by Rob Warnock, in Section 51 of the
comp.compression FAQ.
--*/
UInt32 BZ2_crc32Table[256] = {
/*-- Ugly, innit? --*/
0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L,
0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L,
0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L,
0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL,
0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L,
0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L,
0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L,
0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL,
0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L,
0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L,
0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L,
0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL,
0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L,
0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L,
0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L,
0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL,
0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL,
0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L,
0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L,
0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL,
0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL,
0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L,
0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L,
0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL,
0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL,
0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L,
0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L,
0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL,
0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL,
0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L,
0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L,
0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL,
0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L,
0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL,
0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL,
0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L,
0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L,
0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL,
0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL,
0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L,
0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L,
0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL,
0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL,
0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L,
0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L,
0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL,
0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL,
0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L,
0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L,
0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL,
0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L,
0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L,
0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L,
0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL,
0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L,
0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L,
0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L,
0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL,
0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L,
0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L,
0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L,
0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL,
0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L,
0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L
};
/*-------------------------------------------------------------*/
/*--- end crctable.c ---*/
/*-------------------------------------------------------------*/
/*-------------------------------------------------------------*/
/*--- Table for doing CRCs ---*/
/*--- crctable.c ---*/
/*-------------------------------------------------------------*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#include "bzlib_private.h"
/*--
I think this is an implementation of the AUTODIN-II,
Ethernet & FDDI 32-bit CRC standard. Vaguely derived
from code by Rob Warnock, in Section 51 of the
comp.compression FAQ.
--*/
UInt32 BZ2_crc32Table[256] = {
/*-- Ugly, innit? --*/
0x00000000L, 0x04c11db7L, 0x09823b6eL, 0x0d4326d9L,
0x130476dcL, 0x17c56b6bL, 0x1a864db2L, 0x1e475005L,
0x2608edb8L, 0x22c9f00fL, 0x2f8ad6d6L, 0x2b4bcb61L,
0x350c9b64L, 0x31cd86d3L, 0x3c8ea00aL, 0x384fbdbdL,
0x4c11db70L, 0x48d0c6c7L, 0x4593e01eL, 0x4152fda9L,
0x5f15adacL, 0x5bd4b01bL, 0x569796c2L, 0x52568b75L,
0x6a1936c8L, 0x6ed82b7fL, 0x639b0da6L, 0x675a1011L,
0x791d4014L, 0x7ddc5da3L, 0x709f7b7aL, 0x745e66cdL,
0x9823b6e0L, 0x9ce2ab57L, 0x91a18d8eL, 0x95609039L,
0x8b27c03cL, 0x8fe6dd8bL, 0x82a5fb52L, 0x8664e6e5L,
0xbe2b5b58L, 0xbaea46efL, 0xb7a96036L, 0xb3687d81L,
0xad2f2d84L, 0xa9ee3033L, 0xa4ad16eaL, 0xa06c0b5dL,
0xd4326d90L, 0xd0f37027L, 0xddb056feL, 0xd9714b49L,
0xc7361b4cL, 0xc3f706fbL, 0xceb42022L, 0xca753d95L,
0xf23a8028L, 0xf6fb9d9fL, 0xfbb8bb46L, 0xff79a6f1L,
0xe13ef6f4L, 0xe5ffeb43L, 0xe8bccd9aL, 0xec7dd02dL,
0x34867077L, 0x30476dc0L, 0x3d044b19L, 0x39c556aeL,
0x278206abL, 0x23431b1cL, 0x2e003dc5L, 0x2ac12072L,
0x128e9dcfL, 0x164f8078L, 0x1b0ca6a1L, 0x1fcdbb16L,
0x018aeb13L, 0x054bf6a4L, 0x0808d07dL, 0x0cc9cdcaL,
0x7897ab07L, 0x7c56b6b0L, 0x71159069L, 0x75d48ddeL,
0x6b93dddbL, 0x6f52c06cL, 0x6211e6b5L, 0x66d0fb02L,
0x5e9f46bfL, 0x5a5e5b08L, 0x571d7dd1L, 0x53dc6066L,
0x4d9b3063L, 0x495a2dd4L, 0x44190b0dL, 0x40d816baL,
0xaca5c697L, 0xa864db20L, 0xa527fdf9L, 0xa1e6e04eL,
0xbfa1b04bL, 0xbb60adfcL, 0xb6238b25L, 0xb2e29692L,
0x8aad2b2fL, 0x8e6c3698L, 0x832f1041L, 0x87ee0df6L,
0x99a95df3L, 0x9d684044L, 0x902b669dL, 0x94ea7b2aL,
0xe0b41de7L, 0xe4750050L, 0xe9362689L, 0xedf73b3eL,
0xf3b06b3bL, 0xf771768cL, 0xfa325055L, 0xfef34de2L,
0xc6bcf05fL, 0xc27dede8L, 0xcf3ecb31L, 0xcbffd686L,
0xd5b88683L, 0xd1799b34L, 0xdc3abdedL, 0xd8fba05aL,
0x690ce0eeL, 0x6dcdfd59L, 0x608edb80L, 0x644fc637L,
0x7a089632L, 0x7ec98b85L, 0x738aad5cL, 0x774bb0ebL,
0x4f040d56L, 0x4bc510e1L, 0x46863638L, 0x42472b8fL,
0x5c007b8aL, 0x58c1663dL, 0x558240e4L, 0x51435d53L,
0x251d3b9eL, 0x21dc2629L, 0x2c9f00f0L, 0x285e1d47L,
0x36194d42L, 0x32d850f5L, 0x3f9b762cL, 0x3b5a6b9bL,
0x0315d626L, 0x07d4cb91L, 0x0a97ed48L, 0x0e56f0ffL,
0x1011a0faL, 0x14d0bd4dL, 0x19939b94L, 0x1d528623L,
0xf12f560eL, 0xf5ee4bb9L, 0xf8ad6d60L, 0xfc6c70d7L,
0xe22b20d2L, 0xe6ea3d65L, 0xeba91bbcL, 0xef68060bL,
0xd727bbb6L, 0xd3e6a601L, 0xdea580d8L, 0xda649d6fL,
0xc423cd6aL, 0xc0e2d0ddL, 0xcda1f604L, 0xc960ebb3L,
0xbd3e8d7eL, 0xb9ff90c9L, 0xb4bcb610L, 0xb07daba7L,
0xae3afba2L, 0xaafbe615L, 0xa7b8c0ccL, 0xa379dd7bL,
0x9b3660c6L, 0x9ff77d71L, 0x92b45ba8L, 0x9675461fL,
0x8832161aL, 0x8cf30badL, 0x81b02d74L, 0x857130c3L,
0x5d8a9099L, 0x594b8d2eL, 0x5408abf7L, 0x50c9b640L,
0x4e8ee645L, 0x4a4ffbf2L, 0x470cdd2bL, 0x43cdc09cL,
0x7b827d21L, 0x7f436096L, 0x7200464fL, 0x76c15bf8L,
0x68860bfdL, 0x6c47164aL, 0x61043093L, 0x65c52d24L,
0x119b4be9L, 0x155a565eL, 0x18197087L, 0x1cd86d30L,
0x029f3d35L, 0x065e2082L, 0x0b1d065bL, 0x0fdc1becL,
0x3793a651L, 0x3352bbe6L, 0x3e119d3fL, 0x3ad08088L,
0x2497d08dL, 0x2056cd3aL, 0x2d15ebe3L, 0x29d4f654L,
0xc5a92679L, 0xc1683bceL, 0xcc2b1d17L, 0xc8ea00a0L,
0xd6ad50a5L, 0xd26c4d12L, 0xdf2f6bcbL, 0xdbee767cL,
0xe3a1cbc1L, 0xe760d676L, 0xea23f0afL, 0xeee2ed18L,
0xf0a5bd1dL, 0xf464a0aaL, 0xf9278673L, 0xfde69bc4L,
0x89b8fd09L, 0x8d79e0beL, 0x803ac667L, 0x84fbdbd0L,
0x9abc8bd5L, 0x9e7d9662L, 0x933eb0bbL, 0x97ffad0cL,
0xafb010b1L, 0xab710d06L, 0xa6322bdfL, 0xa2f33668L,
0xbcb4666dL, 0xb8757bdaL, 0xb5365d03L, 0xb1f740b4L
};
/*-------------------------------------------------------------*/
/*--- end crctable.c ---*/
/*-------------------------------------------------------------*/

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,175 +1,175 @@
/*
minibz2
libbz2.dll test program.
by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
This file is Public Domain. Welcome any email to me.
usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]
*/
#define BZ_IMPORT
#include <stdio.h>
#include <stdlib.h>
#include "bzlib.h"
#ifdef _WIN32
#include <io.h>
#endif
#ifdef _WIN32
#define BZ2_LIBNAME "libbz2-1.0.2.DLL"
#include <windows.h>
static int BZ2DLLLoaded = 0;
static HINSTANCE BZ2DLLhLib;
int BZ2DLLLoadLibrary(void)
{
HINSTANCE hLib;
if(BZ2DLLLoaded==1){return 0;}
hLib=LoadLibrary(BZ2_LIBNAME);
if(hLib == NULL){
fprintf(stderr,"Can't load %s\n",BZ2_LIBNAME);
return -1;
}
BZ2_bzlibVersion=GetProcAddress(hLib,"BZ2_bzlibVersion");
BZ2_bzopen=GetProcAddress(hLib,"BZ2_bzopen");
BZ2_bzdopen=GetProcAddress(hLib,"BZ2_bzdopen");
BZ2_bzread=GetProcAddress(hLib,"BZ2_bzread");
BZ2_bzwrite=GetProcAddress(hLib,"BZ2_bzwrite");
BZ2_bzflush=GetProcAddress(hLib,"BZ2_bzflush");
BZ2_bzclose=GetProcAddress(hLib,"BZ2_bzclose");
BZ2_bzerror=GetProcAddress(hLib,"BZ2_bzerror");
if (!BZ2_bzlibVersion || !BZ2_bzopen || !BZ2_bzdopen
|| !BZ2_bzread || !BZ2_bzwrite || !BZ2_bzflush
|| !BZ2_bzclose || !BZ2_bzerror) {
fprintf(stderr,"GetProcAddress failed.\n");
return -1;
}
BZ2DLLLoaded=1;
BZ2DLLhLib=hLib;
return 0;
}
int BZ2DLLFreeLibrary(void)
{
if(BZ2DLLLoaded==0){return 0;}
FreeLibrary(BZ2DLLhLib);
BZ2DLLLoaded=0;
}
#endif /* WIN32 */
void usage(void)
{
puts("usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]");
}
int main(int argc,char *argv[])
{
int decompress = 0;
int level = 9;
char *fn_r = NULL;
char *fn_w = NULL;
#ifdef _WIN32
if(BZ2DLLLoadLibrary()<0){
fprintf(stderr,"Loading of %s failed. Giving up.\n", BZ2_LIBNAME);
exit(1);
}
printf("Loading of %s succeeded. Library version is %s.\n",
BZ2_LIBNAME, BZ2_bzlibVersion() );
#endif
while(++argv,--argc){
if(**argv =='-' || **argv=='/'){
char *p;
for(p=*argv+1;*p;p++){
if(*p=='d'){
decompress = 1;
}else if('1'<=*p && *p<='9'){
level = *p - '0';
}else{
usage();
exit(1);
}
}
}else{
break;
}
}
if(argc>=1){
fn_r = *argv;
argc--;argv++;
}else{
fn_r = NULL;
}
if(argc>=1){
fn_w = *argv;
argc--;argv++;
}else{
fn_w = NULL;
}
{
int len;
char buff[0x1000];
char mode[10];
if(decompress){
BZFILE *BZ2fp_r = NULL;
FILE *fp_w = NULL;
if(fn_w){
if((fp_w = fopen(fn_w,"wb"))==NULL){
printf("can't open [%s]\n",fn_w);
perror("reason:");
exit(1);
}
}else{
fp_w = stdout;
}
if((fn_r == NULL && (BZ2fp_r = BZ2_bzdopen(fileno(stdin),"rb"))==NULL)
|| (fn_r != NULL && (BZ2fp_r = BZ2_bzopen(fn_r,"rb"))==NULL)){
printf("can't bz2openstream\n");
exit(1);
}
while((len=BZ2_bzread(BZ2fp_r,buff,0x1000))>0){
fwrite(buff,1,len,fp_w);
}
BZ2_bzclose(BZ2fp_r);
if(fp_w != stdout) fclose(fp_w);
}else{
BZFILE *BZ2fp_w = NULL;
FILE *fp_r = NULL;
if(fn_r){
if((fp_r = fopen(fn_r,"rb"))==NULL){
printf("can't open [%s]\n",fn_r);
perror("reason:");
exit(1);
}
}else{
fp_r = stdin;
}
mode[0]='w';
mode[1] = '0' + level;
mode[2] = '\0';
if((fn_w == NULL && (BZ2fp_w = BZ2_bzdopen(fileno(stdout),mode))==NULL)
|| (fn_w !=NULL && (BZ2fp_w = BZ2_bzopen(fn_w,mode))==NULL)){
printf("can't bz2openstream\n");
exit(1);
}
while((len=fread(buff,1,0x1000,fp_r))>0){
BZ2_bzwrite(BZ2fp_w,buff,len);
}
BZ2_bzclose(BZ2fp_w);
if(fp_r!=stdin)fclose(fp_r);
}
}
#ifdef _WIN32
BZ2DLLFreeLibrary();
#endif
return 0;
}
/*
minibz2
libbz2.dll test program.
by Yoshioka Tsuneo (tsuneo@rr.iij4u.or.jp)
This file is Public Domain. Welcome any email to me.
usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]
*/
#define BZ_IMPORT
#include <stdio.h>
#include <stdlib.h>
#include "bzlib.h"
#ifdef _WIN32
#include <io.h>
#endif
#ifdef _WIN32
#define BZ2_LIBNAME "libbz2-1.0.2.DLL"
#include <windows.h>
static int BZ2DLLLoaded = 0;
static HINSTANCE BZ2DLLhLib;
int BZ2DLLLoadLibrary(void)
{
HINSTANCE hLib;
if(BZ2DLLLoaded==1){return 0;}
hLib=LoadLibrary(BZ2_LIBNAME);
if(hLib == NULL){
fprintf(stderr,"Can't load %s\n",BZ2_LIBNAME);
return -1;
}
BZ2_bzlibVersion=GetProcAddress(hLib,"BZ2_bzlibVersion");
BZ2_bzopen=GetProcAddress(hLib,"BZ2_bzopen");
BZ2_bzdopen=GetProcAddress(hLib,"BZ2_bzdopen");
BZ2_bzread=GetProcAddress(hLib,"BZ2_bzread");
BZ2_bzwrite=GetProcAddress(hLib,"BZ2_bzwrite");
BZ2_bzflush=GetProcAddress(hLib,"BZ2_bzflush");
BZ2_bzclose=GetProcAddress(hLib,"BZ2_bzclose");
BZ2_bzerror=GetProcAddress(hLib,"BZ2_bzerror");
if (!BZ2_bzlibVersion || !BZ2_bzopen || !BZ2_bzdopen
|| !BZ2_bzread || !BZ2_bzwrite || !BZ2_bzflush
|| !BZ2_bzclose || !BZ2_bzerror) {
fprintf(stderr,"GetProcAddress failed.\n");
return -1;
}
BZ2DLLLoaded=1;
BZ2DLLhLib=hLib;
return 0;
}
int BZ2DLLFreeLibrary(void)
{
if(BZ2DLLLoaded==0){return 0;}
FreeLibrary(BZ2DLLhLib);
BZ2DLLLoaded=0;
}
#endif /* WIN32 */
void usage(void)
{
puts("usage: minibz2 [-d] [-{1,2,..9}] [[srcfilename] destfilename]");
}
int main(int argc,char *argv[])
{
int decompress = 0;
int level = 9;
char *fn_r = NULL;
char *fn_w = NULL;
#ifdef _WIN32
if(BZ2DLLLoadLibrary()<0){
fprintf(stderr,"Loading of %s failed. Giving up.\n", BZ2_LIBNAME);
exit(1);
}
printf("Loading of %s succeeded. Library version is %s.\n",
BZ2_LIBNAME, BZ2_bzlibVersion() );
#endif
while(++argv,--argc){
if(**argv =='-' || **argv=='/'){
char *p;
for(p=*argv+1;*p;p++){
if(*p=='d'){
decompress = 1;
}else if('1'<=*p && *p<='9'){
level = *p - '0';
}else{
usage();
exit(1);
}
}
}else{
break;
}
}
if(argc>=1){
fn_r = *argv;
argc--;argv++;
}else{
fn_r = NULL;
}
if(argc>=1){
fn_w = *argv;
argc--;argv++;
}else{
fn_w = NULL;
}
{
int len;
char buff[0x1000];
char mode[10];
if(decompress){
BZFILE *BZ2fp_r = NULL;
FILE *fp_w = NULL;
if(fn_w){
if((fp_w = fopen(fn_w,"wb"))==NULL){
printf("can't open [%s]\n",fn_w);
perror("reason:");
exit(1);
}
}else{
fp_w = stdout;
}
if((fn_r == NULL && (BZ2fp_r = BZ2_bzdopen(fileno(stdin),"rb"))==NULL)
|| (fn_r != NULL && (BZ2fp_r = BZ2_bzopen(fn_r,"rb"))==NULL)){
printf("can't bz2openstream\n");
exit(1);
}
while((len=BZ2_bzread(BZ2fp_r,buff,0x1000))>0){
fwrite(buff,1,len,fp_w);
}
BZ2_bzclose(BZ2fp_r);
if(fp_w != stdout) fclose(fp_w);
}else{
BZFILE *BZ2fp_w = NULL;
FILE *fp_r = NULL;
if(fn_r){
if((fp_r = fopen(fn_r,"rb"))==NULL){
printf("can't open [%s]\n",fn_r);
perror("reason:");
exit(1);
}
}else{
fp_r = stdin;
}
mode[0]='w';
mode[1] = '0' + level;
mode[2] = '\0';
if((fn_w == NULL && (BZ2fp_w = BZ2_bzdopen(fileno(stdout),mode))==NULL)
|| (fn_w !=NULL && (BZ2fp_w = BZ2_bzopen(fn_w,mode))==NULL)){
printf("can't bz2openstream\n");
exit(1);
}
while((len=fread(buff,1,0x1000,fp_r))>0){
BZ2_bzwrite(BZ2fp_w,buff,len);
}
BZ2_bzclose(BZ2fp_w);
if(fp_r!=stdin)fclose(fp_r);
}
}
#ifdef _WIN32
BZ2DLLFreeLibrary();
#endif
return 0;
}

Просмотреть файл

@ -1,205 +1,205 @@
/*-------------------------------------------------------------*/
/*--- Huffman coding low-level stuff ---*/
/*--- huffman.c ---*/
/*-------------------------------------------------------------*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#include "bzlib_private.h"
/*---------------------------------------------------*/
#define WEIGHTOF(zz0) ((zz0) & 0xffffff00)
#define DEPTHOF(zz1) ((zz1) & 0x000000ff)
#define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3))
#define ADDWEIGHTS(zw1,zw2) \
(WEIGHTOF(zw1)+WEIGHTOF(zw2)) | \
(1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2)))
#define UPHEAP(z) \
{ \
Int32 zz, tmp; \
zz = z; tmp = heap[zz]; \
while (weight[tmp] < weight[heap[zz >> 1]]) { \
heap[zz] = heap[zz >> 1]; \
zz >>= 1; \
} \
heap[zz] = tmp; \
}
#define DOWNHEAP(z) \
{ \
Int32 zz, yy, tmp; \
zz = z; tmp = heap[zz]; \
while (True) { \
yy = zz << 1; \
if (yy > nHeap) break; \
if (yy < nHeap && \
weight[heap[yy+1]] < weight[heap[yy]]) \
yy++; \
if (weight[tmp] < weight[heap[yy]]) break; \
heap[zz] = heap[yy]; \
zz = yy; \
} \
heap[zz] = tmp; \
}
/*---------------------------------------------------*/
void BZ2_hbMakeCodeLengths ( UChar *len,
Int32 *freq,
Int32 alphaSize,
Int32 maxLen )
{
/*--
Nodes and heap entries run from 1. Entry 0
for both the heap and nodes is a sentinel.
--*/
Int32 nNodes, nHeap, n1, n2, i, j, k;
Bool tooLong;
Int32 heap [ BZ_MAX_ALPHA_SIZE + 2 ];
Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ];
Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ];
for (i = 0; i < alphaSize; i++)
weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
while (True) {
nNodes = alphaSize;
nHeap = 0;
heap[0] = 0;
weight[0] = 0;
parent[0] = -2;
for (i = 1; i <= alphaSize; i++) {
parent[i] = -1;
nHeap++;
heap[nHeap] = i;
UPHEAP(nHeap);
}
AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 );
while (nHeap > 1) {
n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
nNodes++;
parent[n1] = parent[n2] = nNodes;
weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
parent[nNodes] = -1;
nHeap++;
heap[nHeap] = nNodes;
UPHEAP(nHeap);
}
AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 );
tooLong = False;
for (i = 1; i <= alphaSize; i++) {
j = 0;
k = i;
while (parent[k] >= 0) { k = parent[k]; j++; }
len[i-1] = j;
if (j > maxLen) tooLong = True;
}
if (! tooLong) break;
/* 17 Oct 04: keep-going condition for the following loop used
to be 'i < alphaSize', which missed the last element,
theoretically leading to the possibility of the compressor
looping. However, this count-scaling step is only needed if
one of the generated Huffman code words is longer than
maxLen, which up to and including version 1.0.2 was 20 bits,
which is extremely unlikely. In version 1.0.3 maxLen was
changed to 17 bits, which has minimal effect on compression
ratio, but does mean this scaling step is used from time to
time, enough to verify that it works.
This means that bzip2-1.0.3 and later will only produce
Huffman codes with a maximum length of 17 bits. However, in
order to preserve backwards compatibility with bitstreams
produced by versions pre-1.0.3, the decompressor must still
handle lengths of up to 20. */
for (i = 1; i <= alphaSize; i++) {
j = weight[i] >> 8;
j = 1 + (j / 2);
weight[i] = j << 8;
}
}
}
/*---------------------------------------------------*/
void BZ2_hbAssignCodes ( Int32 *code,
UChar *length,
Int32 minLen,
Int32 maxLen,
Int32 alphaSize )
{
Int32 n, vec, i;
vec = 0;
for (n = minLen; n <= maxLen; n++) {
for (i = 0; i < alphaSize; i++)
if (length[i] == n) { code[i] = vec; vec++; };
vec <<= 1;
}
}
/*---------------------------------------------------*/
void BZ2_hbCreateDecodeTables ( Int32 *limit,
Int32 *base,
Int32 *perm,
UChar *length,
Int32 minLen,
Int32 maxLen,
Int32 alphaSize )
{
Int32 pp, i, j, vec;
pp = 0;
for (i = minLen; i <= maxLen; i++)
for (j = 0; j < alphaSize; j++)
if (length[j] == i) { perm[pp] = j; pp++; };
for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0;
for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1];
for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0;
vec = 0;
for (i = minLen; i <= maxLen; i++) {
vec += (base[i+1] - base[i]);
limit[i] = vec-1;
vec <<= 1;
}
for (i = minLen + 1; i <= maxLen; i++)
base[i] = ((limit[i-1] + 1) << 1) - base[i];
}
/*-------------------------------------------------------------*/
/*--- end huffman.c ---*/
/*-------------------------------------------------------------*/
/*-------------------------------------------------------------*/
/*--- Huffman coding low-level stuff ---*/
/*--- huffman.c ---*/
/*-------------------------------------------------------------*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#include "bzlib_private.h"
/*---------------------------------------------------*/
#define WEIGHTOF(zz0) ((zz0) & 0xffffff00)
#define DEPTHOF(zz1) ((zz1) & 0x000000ff)
#define MYMAX(zz2,zz3) ((zz2) > (zz3) ? (zz2) : (zz3))
#define ADDWEIGHTS(zw1,zw2) \
(WEIGHTOF(zw1)+WEIGHTOF(zw2)) | \
(1 + MYMAX(DEPTHOF(zw1),DEPTHOF(zw2)))
#define UPHEAP(z) \
{ \
Int32 zz, tmp; \
zz = z; tmp = heap[zz]; \
while (weight[tmp] < weight[heap[zz >> 1]]) { \
heap[zz] = heap[zz >> 1]; \
zz >>= 1; \
} \
heap[zz] = tmp; \
}
#define DOWNHEAP(z) \
{ \
Int32 zz, yy, tmp; \
zz = z; tmp = heap[zz]; \
while (True) { \
yy = zz << 1; \
if (yy > nHeap) break; \
if (yy < nHeap && \
weight[heap[yy+1]] < weight[heap[yy]]) \
yy++; \
if (weight[tmp] < weight[heap[yy]]) break; \
heap[zz] = heap[yy]; \
zz = yy; \
} \
heap[zz] = tmp; \
}
/*---------------------------------------------------*/
void BZ2_hbMakeCodeLengths ( UChar *len,
Int32 *freq,
Int32 alphaSize,
Int32 maxLen )
{
/*--
Nodes and heap entries run from 1. Entry 0
for both the heap and nodes is a sentinel.
--*/
Int32 nNodes, nHeap, n1, n2, i, j, k;
Bool tooLong;
Int32 heap [ BZ_MAX_ALPHA_SIZE + 2 ];
Int32 weight [ BZ_MAX_ALPHA_SIZE * 2 ];
Int32 parent [ BZ_MAX_ALPHA_SIZE * 2 ];
for (i = 0; i < alphaSize; i++)
weight[i+1] = (freq[i] == 0 ? 1 : freq[i]) << 8;
while (True) {
nNodes = alphaSize;
nHeap = 0;
heap[0] = 0;
weight[0] = 0;
parent[0] = -2;
for (i = 1; i <= alphaSize; i++) {
parent[i] = -1;
nHeap++;
heap[nHeap] = i;
UPHEAP(nHeap);
}
AssertH( nHeap < (BZ_MAX_ALPHA_SIZE+2), 2001 );
while (nHeap > 1) {
n1 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
n2 = heap[1]; heap[1] = heap[nHeap]; nHeap--; DOWNHEAP(1);
nNodes++;
parent[n1] = parent[n2] = nNodes;
weight[nNodes] = ADDWEIGHTS(weight[n1], weight[n2]);
parent[nNodes] = -1;
nHeap++;
heap[nHeap] = nNodes;
UPHEAP(nHeap);
}
AssertH( nNodes < (BZ_MAX_ALPHA_SIZE * 2), 2002 );
tooLong = False;
for (i = 1; i <= alphaSize; i++) {
j = 0;
k = i;
while (parent[k] >= 0) { k = parent[k]; j++; }
len[i-1] = j;
if (j > maxLen) tooLong = True;
}
if (! tooLong) break;
/* 17 Oct 04: keep-going condition for the following loop used
to be 'i < alphaSize', which missed the last element,
theoretically leading to the possibility of the compressor
looping. However, this count-scaling step is only needed if
one of the generated Huffman code words is longer than
maxLen, which up to and including version 1.0.2 was 20 bits,
which is extremely unlikely. In version 1.0.3 maxLen was
changed to 17 bits, which has minimal effect on compression
ratio, but does mean this scaling step is used from time to
time, enough to verify that it works.
This means that bzip2-1.0.3 and later will only produce
Huffman codes with a maximum length of 17 bits. However, in
order to preserve backwards compatibility with bitstreams
produced by versions pre-1.0.3, the decompressor must still
handle lengths of up to 20. */
for (i = 1; i <= alphaSize; i++) {
j = weight[i] >> 8;
j = 1 + (j / 2);
weight[i] = j << 8;
}
}
}
/*---------------------------------------------------*/
void BZ2_hbAssignCodes ( Int32 *code,
UChar *length,
Int32 minLen,
Int32 maxLen,
Int32 alphaSize )
{
Int32 n, vec, i;
vec = 0;
for (n = minLen; n <= maxLen; n++) {
for (i = 0; i < alphaSize; i++)
if (length[i] == n) { code[i] = vec; vec++; };
vec <<= 1;
}
}
/*---------------------------------------------------*/
void BZ2_hbCreateDecodeTables ( Int32 *limit,
Int32 *base,
Int32 *perm,
UChar *length,
Int32 minLen,
Int32 maxLen,
Int32 alphaSize )
{
Int32 pp, i, j, vec;
pp = 0;
for (i = minLen; i <= maxLen; i++)
for (j = 0; j < alphaSize; j++)
if (length[j] == i) { perm[pp] = j; pp++; };
for (i = 0; i < BZ_MAX_CODE_LEN; i++) base[i] = 0;
for (i = 0; i < alphaSize; i++) base[length[i]+1]++;
for (i = 1; i < BZ_MAX_CODE_LEN; i++) base[i] += base[i-1];
for (i = 0; i < BZ_MAX_CODE_LEN; i++) limit[i] = 0;
vec = 0;
for (i = minLen; i <= maxLen; i++) {
vec += (base[i+1] - base[i]);
limit[i] = vec-1;
vec <<= 1;
}
for (i = minLen + 1; i <= maxLen; i++)
base[i] = ((limit[i-1] + 1) << 1) - base[i];
}
/*-------------------------------------------------------------*/
/*--- end huffman.c ---*/
/*-------------------------------------------------------------*/

Просмотреть файл

@ -1,31 +1,31 @@
/* Spew out a long sequence of the byte 251. When fed to bzip2
versions 1.0.0 or 1.0.1, causes it to die with internal error
1007 in blocksort.c. This assertion misses an extremely rare
case, which is fixed in this version (1.0.2) and above.
*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#include <stdio.h>
int main ()
{
int i;
for (i = 0; i < 48500000 ; i++)
putchar(251);
return 0;
}
/* Spew out a long sequence of the byte 251. When fed to bzip2
versions 1.0.0 or 1.0.1, causes it to die with internal error
1007 in blocksort.c. This assertion misses an extremely rare
case, which is fixed in this version (1.0.2) and above.
*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#include <stdio.h>
int main ()
{
int i;
for (i = 0; i < 48500000 ; i++)
putchar(251);
return 0;
}

Просмотреть файл

@ -1,84 +1,84 @@
/*-------------------------------------------------------------*/
/*--- Table for randomising repetitive blocks ---*/
/*--- randtable.c ---*/
/*-------------------------------------------------------------*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#include "bzlib_private.h"
/*---------------------------------------------*/
Int32 BZ2_rNums[512] = {
619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
936, 638
};
/*-------------------------------------------------------------*/
/*--- end randtable.c ---*/
/*-------------------------------------------------------------*/
/*-------------------------------------------------------------*/
/*--- Table for randomising repetitive blocks ---*/
/*--- randtable.c ---*/
/*-------------------------------------------------------------*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#include "bzlib_private.h"
/*---------------------------------------------*/
Int32 BZ2_rNums[512] = {
619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
936, 638
};
/*-------------------------------------------------------------*/
/*--- end randtable.c ---*/
/*-------------------------------------------------------------*/

Просмотреть файл

@ -1,54 +1,54 @@
/* spew out a thoroughly gigantic file designed so that bzip2
can compress it reasonably rapidly. This is to help test
support for large files (> 2GB) in a reasonable amount of time.
I suggest you use the undocumented --exponential option to
bzip2 when compressing the resulting file; this saves a bit of
time. Note: *don't* bother with --exponential when compressing
Real Files; it'll just waste a lot of CPU time :-)
(but is otherwise harmless).
*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#define _FILE_OFFSET_BITS 64
#include <stdio.h>
#include <stdlib.h>
/* The number of megabytes of junk to spew out (roughly) */
#define MEGABYTES 5000
#define N_BUF 1000000
char buf[N_BUF];
int main ( int argc, char** argv )
{
int ii, kk, p;
srandom(1);
setbuffer ( stdout, buf, N_BUF );
for (kk = 0; kk < MEGABYTES * 515; kk+=3) {
p = 25+random()%50;
for (ii = 0; ii < p; ii++)
printf ( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" );
for (ii = 0; ii < p-1; ii++)
printf ( "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" );
for (ii = 0; ii < p+1; ii++)
printf ( "ccccccccccccccccccccccccccccccccccccc" );
}
fflush(stdout);
return 0;
}
/* spew out a thoroughly gigantic file designed so that bzip2
can compress it reasonably rapidly. This is to help test
support for large files (> 2GB) in a reasonable amount of time.
I suggest you use the undocumented --exponential option to
bzip2 when compressing the resulting file; this saves a bit of
time. Note: *don't* bother with --exponential when compressing
Real Files; it'll just waste a lot of CPU time :-)
(but is otherwise harmless).
*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#define _FILE_OFFSET_BITS 64
#include <stdio.h>
#include <stdlib.h>
/* The number of megabytes of junk to spew out (roughly) */
#define MEGABYTES 5000
#define N_BUF 1000000
char buf[N_BUF];
int main ( int argc, char** argv )
{
int ii, kk, p;
srandom(1);
setbuffer ( stdout, buf, N_BUF );
for (kk = 0; kk < MEGABYTES * 515; kk+=3) {
p = 25+random()%50;
for (ii = 0; ii < p; ii++)
printf ( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" );
for (ii = 0; ii < p-1; ii++)
printf ( "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" );
for (ii = 0; ii < p+1; ii++)
printf ( "ccccccccccccccccccccccccccccccccccccc" );
}
fflush(stdout);
return 0;
}

Просмотреть файл

@ -1,141 +1,141 @@
/* A test program written to test robustness to decompression of
corrupted data. Usage is
unzcrash filename
and the program will read the specified file, compress it (in memory),
and then repeatedly decompress it, each time with a different bit of
the compressed data inverted, so as to test all possible one-bit errors.
This should not cause any invalid memory accesses. If it does,
I want to know about it!
PS. As you can see from the above description, the process is
incredibly slow. A file of size eg 5KB will cause it to run for
many hours.
*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#include <stdio.h>
#include <assert.h>
#include "bzlib.h"
#define M_BLOCK 1000000
typedef unsigned char uchar;
#define M_BLOCK_OUT (M_BLOCK + 1000000)
uchar inbuf[M_BLOCK];
uchar outbuf[M_BLOCK_OUT];
uchar zbuf[M_BLOCK + 600 + (M_BLOCK / 100)];
int nIn, nOut, nZ;
static char *bzerrorstrings[] = {
"OK"
,"SEQUENCE_ERROR"
,"PARAM_ERROR"
,"MEM_ERROR"
,"DATA_ERROR"
,"DATA_ERROR_MAGIC"
,"IO_ERROR"
,"UNEXPECTED_EOF"
,"OUTBUFF_FULL"
,"???" /* for future */
,"???" /* for future */
,"???" /* for future */
,"???" /* for future */
,"???" /* for future */
,"???" /* for future */
};
void flip_bit ( int bit )
{
int byteno = bit / 8;
int bitno = bit % 8;
uchar mask = 1 << bitno;
//fprintf ( stderr, "(byte %d bit %d mask %d)",
// byteno, bitno, (int)mask );
zbuf[byteno] ^= mask;
}
int main ( int argc, char** argv )
{
FILE* f;
int r;
int bit;
int i;
if (argc != 2) {
fprintf ( stderr, "usage: unzcrash filename\n" );
return 1;
}
f = fopen ( argv[1], "r" );
if (!f) {
fprintf ( stderr, "unzcrash: can't open %s\n", argv[1] );
return 1;
}
nIn = fread ( inbuf, 1, M_BLOCK, f );
fprintf ( stderr, "%d bytes read\n", nIn );
nZ = M_BLOCK;
r = BZ2_bzBuffToBuffCompress (
zbuf, &nZ, inbuf, nIn, 9, 0, 30 );
assert (r == BZ_OK);
fprintf ( stderr, "%d after compression\n", nZ );
for (bit = 0; bit < nZ*8; bit++) {
fprintf ( stderr, "bit %d ", bit );
flip_bit ( bit );
nOut = M_BLOCK_OUT;
r = BZ2_bzBuffToBuffDecompress (
outbuf, &nOut, zbuf, nZ, 0, 0 );
fprintf ( stderr, " %d %s ", r, bzerrorstrings[-r] );
if (r != BZ_OK) {
fprintf ( stderr, "\n" );
} else {
if (nOut != nIn) {
fprintf(stderr, "nIn/nOut mismatch %d %d\n", nIn, nOut );
return 1;
} else {
for (i = 0; i < nOut; i++)
if (inbuf[i] != outbuf[i]) {
fprintf(stderr, "mismatch at %d\n", i );
return 1;
}
if (i == nOut) fprintf(stderr, "really ok!\n" );
}
}
flip_bit ( bit );
}
#if 0
assert (nOut == nIn);
for (i = 0; i < nOut; i++) {
if (inbuf[i] != outbuf[i]) {
fprintf ( stderr, "difference at %d !\n", i );
return 1;
}
}
#endif
fprintf ( stderr, "all ok\n" );
return 0;
}
/* A test program written to test robustness to decompression of
corrupted data. Usage is
unzcrash filename
and the program will read the specified file, compress it (in memory),
and then repeatedly decompress it, each time with a different bit of
the compressed data inverted, so as to test all possible one-bit errors.
This should not cause any invalid memory accesses. If it does,
I want to know about it!
PS. As you can see from the above description, the process is
incredibly slow. A file of size eg 5KB will cause it to run for
many hours.
*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.5 of 10 December 2007
Copyright (C) 1996-2007 Julian Seward <jseward@bzip.org>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
#include <stdio.h>
#include <assert.h>
#include "bzlib.h"
#define M_BLOCK 1000000
typedef unsigned char uchar;
#define M_BLOCK_OUT (M_BLOCK + 1000000)
uchar inbuf[M_BLOCK];
uchar outbuf[M_BLOCK_OUT];
uchar zbuf[M_BLOCK + 600 + (M_BLOCK / 100)];
int nIn, nOut, nZ;
static char *bzerrorstrings[] = {
"OK"
,"SEQUENCE_ERROR"
,"PARAM_ERROR"
,"MEM_ERROR"
,"DATA_ERROR"
,"DATA_ERROR_MAGIC"
,"IO_ERROR"
,"UNEXPECTED_EOF"
,"OUTBUFF_FULL"
,"???" /* for future */
,"???" /* for future */
,"???" /* for future */
,"???" /* for future */
,"???" /* for future */
,"???" /* for future */
};
void flip_bit ( int bit )
{
int byteno = bit / 8;
int bitno = bit % 8;
uchar mask = 1 << bitno;
//fprintf ( stderr, "(byte %d bit %d mask %d)",
// byteno, bitno, (int)mask );
zbuf[byteno] ^= mask;
}
int main ( int argc, char** argv )
{
FILE* f;
int r;
int bit;
int i;
if (argc != 2) {
fprintf ( stderr, "usage: unzcrash filename\n" );
return 1;
}
f = fopen ( argv[1], "r" );
if (!f) {
fprintf ( stderr, "unzcrash: can't open %s\n", argv[1] );
return 1;
}
nIn = fread ( inbuf, 1, M_BLOCK, f );
fprintf ( stderr, "%d bytes read\n", nIn );
nZ = M_BLOCK;
r = BZ2_bzBuffToBuffCompress (
zbuf, &nZ, inbuf, nIn, 9, 0, 30 );
assert (r == BZ_OK);
fprintf ( stderr, "%d after compression\n", nZ );
for (bit = 0; bit < nZ*8; bit++) {
fprintf ( stderr, "bit %d ", bit );
flip_bit ( bit );
nOut = M_BLOCK_OUT;
r = BZ2_bzBuffToBuffDecompress (
outbuf, &nOut, zbuf, nZ, 0, 0 );
fprintf ( stderr, " %d %s ", r, bzerrorstrings[-r] );
if (r != BZ_OK) {
fprintf ( stderr, "\n" );
} else {
if (nOut != nIn) {
fprintf(stderr, "nIn/nOut mismatch %d %d\n", nIn, nOut );
return 1;
} else {
for (i = 0; i < nOut; i++)
if (inbuf[i] != outbuf[i]) {
fprintf(stderr, "mismatch at %d\n", i );
return 1;
}
if (i == nOut) fprintf(stderr, "really ok!\n" );
}
}
flip_bit ( bit );
}
#if 0
assert (nOut == nIn);
for (i = 0; i < nOut; i++) {
if (inbuf[i] != outbuf[i]) {
fprintf ( stderr, "difference at %d !\n", i );
return 1;
}
}
#endif
fprintf ( stderr, "all ok\n" );
return 0;
}

Просмотреть файл

@ -1,314 +1,314 @@
#include <unistd.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "abstractfile.h"
#include "ibootim.h"
#include "lzss.h"
#include <png.h>
#include "nor_files.h"
void flipIBootIMHeader(IBootIMHeader* header) {
FLIPENDIANLE(header->unknown);
FLIPENDIANLE(header->compression_type);
FLIPENDIANLE(header->format);
FLIPENDIANLE(header->width);
FLIPENDIANLE(header->height);
}
size_t readIBootIM(AbstractFile* file, void* data, size_t len) {
InfoIBootIM* info = (InfoIBootIM*) (file->data);
memcpy(data, (void*)((uint8_t*)info->buffer + (uint32_t)info->offset), len);
info->offset += (size_t)len;
return len;
}
size_t writeIBootIM(AbstractFile* file, const void* data, size_t len) {
InfoIBootIM* info = (InfoIBootIM*) (file->data);
while((info->offset + (size_t)len) > info->length) {
info->length = info->offset + (size_t)len;
info->buffer = realloc(info->buffer, info->length);
}
memcpy((void*)((uint8_t*)info->buffer + (uint32_t)info->offset), data, len);
info->offset += (size_t)len;
info->dirty = TRUE;
return len;
}
int seekIBootIM(AbstractFile* file, off_t offset) {
InfoIBootIM* info = (InfoIBootIM*) (file->data);
info->offset = (size_t)offset;
return 0;
}
off_t tellIBootIM(AbstractFile* file) {
InfoIBootIM* info = (InfoIBootIM*) (file->data);
return (off_t)info->offset;
}
off_t getLengthIBootIM(AbstractFile* file) {
InfoIBootIM* info = (InfoIBootIM*) (file->data);
return info->length;
}
void closeIBootIM(AbstractFile* file) {
InfoIBootIM* info = (InfoIBootIM*) (file->data);
uint32_t cksum;
uint8_t *compressed;
if(info->dirty) {
compressed = malloc(info->length * 2);
info->compLength = (uint32_t)(compress_lzss(compressed, info->length * 2, info->buffer, info->length) - compressed);
flipIBootIMHeader(&(info->header));
info->file->seek(info->file, 0);
info->file->write(info->file, &(info->header), sizeof(info->header));
info->file->seek(info->file, sizeof(info->header));
info->file->write(info->file, compressed, info->compLength);
free(compressed);
}
free(info->buffer);
info->file->close(info->file);
free(info);
free(file);
}
AbstractFile* createAbstractFileFromIBootIM(AbstractFile* file) {
InfoIBootIM* info;
AbstractFile* toReturn;
uint8_t *compressed;
if(!file) {
return NULL;
}
info = (InfoIBootIM*) malloc(sizeof(InfoIBootIM));
info->file = file;
file->seek(file, 0);
file->read(file, &(info->header), sizeof(info->header));
flipIBootIMHeader(&(info->header));
if(strcmp(info->header.signature, IBOOTIM_SIGNATURE) != 0) {
free(info);
return NULL;
}
info->compLength = file->getLength(file) - sizeof(info->header);
if(info->header.compression_type != IBOOTIM_LZSS_TYPE) {
free(info);
return NULL;
}
if(info->header.format == IBOOTIM_ARGB) {
info->length = 4 * info->header.width * info->header.height;
} else if(info->header.format == IBOOTIM_GREY) {
info->length = 2 * info->header.width * info->header.height;
} else {
free(info);
return NULL;
}
info->buffer = malloc(info->length);
compressed = malloc(info->compLength);
file->read(file, compressed, info->compLength);
if(decompress_lzss(info->buffer, compressed, info->compLength) != info->length) {
free(compressed);
free(info);
return NULL;
}
free(compressed);
info->dirty = FALSE;
info->offset = 0;
toReturn = (AbstractFile*) malloc(sizeof(AbstractFile));
toReturn->data = info;
toReturn->read = readIBootIM;
toReturn->write = writeIBootIM;
toReturn->seek = seekIBootIM;
toReturn->tell = tellIBootIM;
toReturn->getLength = getLengthIBootIM;
toReturn->close = closeIBootIM;
return toReturn;
}
AbstractFile* duplicateIBootIMFile(AbstractFile* file, AbstractFile* backing) {
InfoIBootIM* info;
unsigned char* copyCertificate;
AbstractFile* toReturn;
if(!file) {
return NULL;
}
info = (InfoIBootIM*) malloc(sizeof(InfoIBootIM));
memcpy(info, file->data, sizeof(InfoIBootIM));
info->file = backing;
info->buffer = malloc(1);
info->length = 0;
info->dirty = TRUE;
info->offset = 0;
toReturn = (AbstractFile*) malloc(sizeof(AbstractFile));
toReturn->data = info;
toReturn->read = readIBootIM;
toReturn->write = writeIBootIM;
toReturn->seek = seekIBootIM;
toReturn->tell = tellIBootIM;
toReturn->getLength = getLengthIBootIM;
toReturn->close = closeIBootIM;
return toReturn;
}
void pngRead(png_structp png_ptr, png_bytep data, png_size_t length) {
AbstractFile* imageFile;
imageFile = png_get_io_ptr(png_ptr);
imageFile->read(imageFile, data, length);
}
void pngError(png_structp png_ptr, png_const_charp error_msg) {
printf("error: %s\n", error_msg);
exit(0);
}
void* replaceBootImage(AbstractFile* imageWrapper, AbstractFile* png, size_t *fileSize) {
AbstractFile* imageFile;
char header[8];
InfoIBootIM* info;
png_uint_32 i;
png_bytepp row_pointers;
uint8_t* imageBuffer;
void* buffer;
png->read(png, header, 8);
if(png_sig_cmp(header, 0, 8) != 0) {
printf("error: not a valid png file\n");
return NULL;
}
png->seek(png, 0);
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, pngError, pngError);
if (!png_ptr) {
return NULL;
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
return NULL;
}
png_infop end_info = png_create_info_struct(png_ptr);
if (!end_info)
{
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
return NULL;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
printf("error reading png\n");
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
free(buffer);
return NULL;
}
png_set_read_fn(png_ptr, png, pngRead);
png_read_info(png_ptr, info_ptr);
if(info_ptr->bit_depth > 8) {
printf("warning: bit depth per channel is greater than 8 (%d). Attempting to strip, but image quality will be degraded.\n", info_ptr->bit_depth);
}
if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY || info_ptr->color_type == PNG_COLOR_TYPE_RGB) {
printf("notice: attempting to add dummy transparency channel\n");
}
if(info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
printf("notice: attempting to expand palette into full rgb\n");
}
png_set_expand(png_ptr);
png_set_strip_16(png_ptr);
png_set_bgr(png_ptr);
png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
png_set_invert_alpha(png_ptr);
png_read_update_info(png_ptr, info_ptr);
if(info_ptr->width > 320 || info_ptr->height > 480) {
printf("error: dimensions out of range, must be within 320x480, not %dx%d\n", info_ptr->width, info_ptr->height);
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return NULL;
}
if(info_ptr->bit_depth != 8) {
printf("error: bit depth per channel must be 8 not %d!\n", info_ptr->bit_depth);
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return NULL;
}
if(info_ptr->color_type != PNG_COLOR_TYPE_GRAY_ALPHA && info_ptr->color_type != PNG_COLOR_TYPE_RGB_ALPHA) {
printf("error: incorrect color type, must be greyscale with alpha, or rgb with alpha\n");
if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY || info_ptr->color_type == PNG_COLOR_TYPE_RGB) {
printf("It appears you're missing an alpha channel. Add transparency to your image\n");
}
if(info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
printf("This PNG is saved with the palette color type rather than ARGB.\n");
}
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return NULL;
}
row_pointers = (png_bytepp) malloc(sizeof(png_bytep) * info_ptr->height);
imageBuffer = malloc(info_ptr->height * info_ptr->rowbytes);
for(i = 0; i < info_ptr->height; i++) {
row_pointers[i] = imageBuffer + (info_ptr->rowbytes * i);
}
png_read_image(png_ptr, row_pointers);
png_read_end(png_ptr, end_info);
buffer = malloc(1);
*fileSize = 0;
imageFile = duplicateAbstractFile(imageWrapper, createAbstractFileFromMemoryFile((void**)&buffer, fileSize));
info = (InfoIBootIM*) (imageFile->data);
info->header.width = (uint16_t) info_ptr->width;
info->header.height = (uint16_t) info_ptr->height;
if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
info->header.format = IBOOTIM_GREY;
} else {
info->header.format = IBOOTIM_ARGB;
}
imageFile->write(imageFile, imageBuffer, info_ptr->height * info_ptr->rowbytes);
imageFile->close(imageFile);
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
png->close(png);
free(row_pointers);
return buffer;
}
#include "common.h"
#include "abstractfile.h"
#include "ibootim.h"
#include "lzss.h"
#include <png.h>
#include "nor_files.h"
void flipIBootIMHeader(IBootIMHeader* header) {
FLIPENDIANLE(header->unknown);
FLIPENDIANLE(header->compression_type);
FLIPENDIANLE(header->format);
FLIPENDIANLE(header->width);
FLIPENDIANLE(header->height);
}
size_t readIBootIM(AbstractFile* file, void* data, size_t len) {
InfoIBootIM* info = (InfoIBootIM*) (file->data);
memcpy(data, (void*)((uint8_t*)info->buffer + (uint32_t)info->offset), len);
info->offset += (size_t)len;
return len;
}
size_t writeIBootIM(AbstractFile* file, const void* data, size_t len) {
InfoIBootIM* info = (InfoIBootIM*) (file->data);
while((info->offset + (size_t)len) > info->length) {
info->length = info->offset + (size_t)len;
info->buffer = realloc(info->buffer, info->length);
}
memcpy((void*)((uint8_t*)info->buffer + (uint32_t)info->offset), data, len);
info->offset += (size_t)len;
info->dirty = TRUE;
return len;
}
int seekIBootIM(AbstractFile* file, off_t offset) {
InfoIBootIM* info = (InfoIBootIM*) (file->data);
info->offset = (size_t)offset;
return 0;
}
off_t tellIBootIM(AbstractFile* file) {
InfoIBootIM* info = (InfoIBootIM*) (file->data);
return (off_t)info->offset;
}
off_t getLengthIBootIM(AbstractFile* file) {
InfoIBootIM* info = (InfoIBootIM*) (file->data);
return info->length;
}
void closeIBootIM(AbstractFile* file) {
InfoIBootIM* info = (InfoIBootIM*) (file->data);
uint32_t cksum;
uint8_t *compressed;
if(info->dirty) {
compressed = malloc(info->length * 2);
info->compLength = (uint32_t)(compress_lzss(compressed, info->length * 2, info->buffer, info->length) - compressed);
flipIBootIMHeader(&(info->header));
info->file->seek(info->file, 0);
info->file->write(info->file, &(info->header), sizeof(info->header));
info->file->seek(info->file, sizeof(info->header));
info->file->write(info->file, compressed, info->compLength);
free(compressed);
}
free(info->buffer);
info->file->close(info->file);
free(info);
free(file);
}
AbstractFile* createAbstractFileFromIBootIM(AbstractFile* file) {
InfoIBootIM* info;
AbstractFile* toReturn;
uint8_t *compressed;
if(!file) {
return NULL;
}
info = (InfoIBootIM*) malloc(sizeof(InfoIBootIM));
info->file = file;
file->seek(file, 0);
file->read(file, &(info->header), sizeof(info->header));
flipIBootIMHeader(&(info->header));
if(strcmp(info->header.signature, IBOOTIM_SIGNATURE) != 0) {
free(info);
return NULL;
}
info->compLength = file->getLength(file) - sizeof(info->header);
if(info->header.compression_type != IBOOTIM_LZSS_TYPE) {
free(info);
return NULL;
}
if(info->header.format == IBOOTIM_ARGB) {
info->length = 4 * info->header.width * info->header.height;
} else if(info->header.format == IBOOTIM_GREY) {
info->length = 2 * info->header.width * info->header.height;
} else {
free(info);
return NULL;
}
info->buffer = malloc(info->length);
compressed = malloc(info->compLength);
file->read(file, compressed, info->compLength);
if(decompress_lzss(info->buffer, compressed, info->compLength) != info->length) {
free(compressed);
free(info);
return NULL;
}
free(compressed);
info->dirty = FALSE;
info->offset = 0;
toReturn = (AbstractFile*) malloc(sizeof(AbstractFile));
toReturn->data = info;
toReturn->read = readIBootIM;
toReturn->write = writeIBootIM;
toReturn->seek = seekIBootIM;
toReturn->tell = tellIBootIM;
toReturn->getLength = getLengthIBootIM;
toReturn->close = closeIBootIM;
return toReturn;
}
AbstractFile* duplicateIBootIMFile(AbstractFile* file, AbstractFile* backing) {
InfoIBootIM* info;
unsigned char* copyCertificate;
AbstractFile* toReturn;
if(!file) {
return NULL;
}
info = (InfoIBootIM*) malloc(sizeof(InfoIBootIM));
memcpy(info, file->data, sizeof(InfoIBootIM));
info->file = backing;
info->buffer = malloc(1);
info->length = 0;
info->dirty = TRUE;
info->offset = 0;
toReturn = (AbstractFile*) malloc(sizeof(AbstractFile));
toReturn->data = info;
toReturn->read = readIBootIM;
toReturn->write = writeIBootIM;
toReturn->seek = seekIBootIM;
toReturn->tell = tellIBootIM;
toReturn->getLength = getLengthIBootIM;
toReturn->close = closeIBootIM;
return toReturn;
}
void pngRead(png_structp png_ptr, png_bytep data, png_size_t length) {
AbstractFile* imageFile;
imageFile = png_get_io_ptr(png_ptr);
imageFile->read(imageFile, data, length);
}
void pngError(png_structp png_ptr, png_const_charp error_msg) {
printf("error: %s\n", error_msg);
exit(0);
}
void* replaceBootImage(AbstractFile* imageWrapper, AbstractFile* png, size_t *fileSize) {
AbstractFile* imageFile;
char header[8];
InfoIBootIM* info;
png_uint_32 i;
png_bytepp row_pointers;
uint8_t* imageBuffer;
void* buffer;
png->read(png, header, 8);
if(png_sig_cmp(header, 0, 8) != 0) {
printf("error: not a valid png file\n");
return NULL;
}
png->seek(png, 0);
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, pngError, pngError);
if (!png_ptr) {
return NULL;
}
png_infop info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
return NULL;
}
png_infop end_info = png_create_info_struct(png_ptr);
if (!end_info)
{
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
return NULL;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
printf("error reading png\n");
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
free(buffer);
return NULL;
}
png_set_read_fn(png_ptr, png, pngRead);
png_read_info(png_ptr, info_ptr);
if(info_ptr->bit_depth > 8) {
printf("warning: bit depth per channel is greater than 8 (%d). Attempting to strip, but image quality will be degraded.\n", info_ptr->bit_depth);
}
if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY || info_ptr->color_type == PNG_COLOR_TYPE_RGB) {
printf("notice: attempting to add dummy transparency channel\n");
}
if(info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
printf("notice: attempting to expand palette into full rgb\n");
}
png_set_expand(png_ptr);
png_set_strip_16(png_ptr);
png_set_bgr(png_ptr);
png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
png_set_invert_alpha(png_ptr);
png_read_update_info(png_ptr, info_ptr);
if(info_ptr->width > 320 || info_ptr->height > 480) {
printf("error: dimensions out of range, must be within 320x480, not %dx%d\n", info_ptr->width, info_ptr->height);
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return NULL;
}
if(info_ptr->bit_depth != 8) {
printf("error: bit depth per channel must be 8 not %d!\n", info_ptr->bit_depth);
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return NULL;
}
if(info_ptr->color_type != PNG_COLOR_TYPE_GRAY_ALPHA && info_ptr->color_type != PNG_COLOR_TYPE_RGB_ALPHA) {
printf("error: incorrect color type, must be greyscale with alpha, or rgb with alpha\n");
if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY || info_ptr->color_type == PNG_COLOR_TYPE_RGB) {
printf("It appears you're missing an alpha channel. Add transparency to your image\n");
}
if(info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) {
printf("This PNG is saved with the palette color type rather than ARGB.\n");
}
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
return NULL;
}
row_pointers = (png_bytepp) malloc(sizeof(png_bytep) * info_ptr->height);
imageBuffer = malloc(info_ptr->height * info_ptr->rowbytes);
for(i = 0; i < info_ptr->height; i++) {
row_pointers[i] = imageBuffer + (info_ptr->rowbytes * i);
}
png_read_image(png_ptr, row_pointers);
png_read_end(png_ptr, end_info);
buffer = malloc(1);
*fileSize = 0;
imageFile = duplicateAbstractFile(imageWrapper, createAbstractFileFromMemoryFile((void**)&buffer, fileSize));
info = (InfoIBootIM*) (imageFile->data);
info->header.width = (uint16_t) info_ptr->width;
info->header.height = (uint16_t) info_ptr->height;
if(info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
info->header.format = IBOOTIM_GREY;
} else {
info->header.format = IBOOTIM_ARGB;
}
imageFile->write(imageFile, imageBuffer, info_ptr->height * info_ptr->rowbytes);
imageFile->close(imageFile);
png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
png->close(png);
free(row_pointers);
return buffer;
}

Просмотреть файл

@ -1,34 +1,34 @@
#include <stdint.h>
#include "abstractfile.h"
#define IMG2_SIGNATURE 0x496D6732
typedef struct Img2Header {
uint32_t signature; /* 0x0 */
uint32_t imageType; /* 0x4 */
uint16_t unknown1; /* 0x8 */
uint16_t security_epoch; /* 0xa */
uint32_t flags1; /* 0xc */
uint32_t dataLenPadded; /* 0x10 */
uint32_t dataLen; /* 0x14 */
uint32_t unknown3; /* 0x18 */
uint32_t flags2; /* 0x1c */ /* 0x01000000 has to be unset */
uint8_t reserved[0x40]; /* 0x20 */
uint32_t unknown4; /* 0x60 */ /* some sort of length field? */
uint32_t header_checksum; /* 0x64 */ /* standard crc32 on first 0x64 bytes */
uint32_t checksum2; /* 0x68 */
uint8_t unknown5[0x394]; /* 0x68 */
} __attribute__((__packed__)) Img2Header;
typedef struct InfoImg2 {
AbstractFile* file;
Img2Header header;
size_t offset;
void* buffer;
char dirty;
} InfoImg2;
AbstractFile* createAbstractFileFromImg2(AbstractFile* file);
AbstractFile* duplicateImg2File(AbstractFile* file, AbstractFile* backing);
#include <stdint.h>
#include "abstractfile.h"
#define IMG2_SIGNATURE 0x496D6732
typedef struct Img2Header {
uint32_t signature; /* 0x0 */
uint32_t imageType; /* 0x4 */
uint16_t unknown1; /* 0x8 */
uint16_t security_epoch; /* 0xa */
uint32_t flags1; /* 0xc */
uint32_t dataLenPadded; /* 0x10 */
uint32_t dataLen; /* 0x14 */
uint32_t unknown3; /* 0x18 */
uint32_t flags2; /* 0x1c */ /* 0x01000000 has to be unset */
uint8_t reserved[0x40]; /* 0x20 */
uint32_t unknown4; /* 0x60 */ /* some sort of length field? */
uint32_t header_checksum; /* 0x64 */ /* standard crc32 on first 0x64 bytes */
uint32_t checksum2; /* 0x68 */
uint8_t unknown5[0x394]; /* 0x68 */
} __attribute__((__packed__)) Img2Header;
typedef struct InfoImg2 {
AbstractFile* file;
Img2Header header;
size_t offset;
void* buffer;
char dirty;
} InfoImg2;
AbstractFile* createAbstractFileFromImg2(AbstractFile* file);
AbstractFile* duplicateImg2File(AbstractFile* file, AbstractFile* backing);

Просмотреть файл

@ -1,29 +1,29 @@
//---------------------------------------------------------------------------
#include <windows.h>
//---------------------------------------------------------------------------
// Important note about DLL memory management when your DLL uses the
// static version of the RunTime Library:
//
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
//
// To avoid using BORLNDMM.DLL, pass string information using "char *" or
// ShortString parameters.
//
// If your DLL uses the dynamic version of the RTL, you do not need to
// explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE, unsigned long, void*)
{
return 1;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <windows.h>
//---------------------------------------------------------------------------
// Important note about DLL memory management when your DLL uses the
// static version of the RunTime Library:
//
// If your DLL exports any functions that pass String objects (or structs/
// classes containing nested Strings) as parameter or function results,
// you will need to add the library MEMMGR.LIB to both the DLL project and
// any other projects that use the DLL. You will also need to use MEMMGR.LIB
// if any other projects which use the DLL will be performing new or delete
// operations on any non-TObject-derived classes which are exported from the
// DLL. Adding MEMMGR.LIB to your project will change the DLL and its calling
// EXE's to use the BORLNDMM.DLL as their memory manager. In these cases,
// the file BORLNDMM.DLL should be deployed along with your DLL.
//
// To avoid using BORLNDMM.DLL, pass string information using "char *" or
// ShortString parameters.
//
// If your DLL uses the dynamic version of the RTL, you do not need to
// explicitly add MEMMGR.LIB as this will be done implicitly for you
//---------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE, unsigned long, void*)
{
return 1;
}
//---------------------------------------------------------------------------

Просмотреть файл

@ -1,352 +1,352 @@
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "lzss.h"
#define BASE 65521L /* largest prime smaller than 65536 */
#define NMAX 5000
// NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8);
uint32_t lzadler32(uint8_t *buf, int32_t len)
{
unsigned long s1 = 1; // adler & 0xffff;
unsigned long s2 = 0; // (adler >> 16) & 0xffff;
int k;
while (len > 0) {
k = len < NMAX ? len : NMAX;
len -= k;
while (k >= 16) {
DO16(buf);
buf += 16;
k -= 16;
}
if (k != 0) do {
s1 += *buf++;
s2 += s1;
} while (--k);
s1 %= BASE;
s2 %= BASE;
}
return (s2 << 16) | s1;
}
/**************************************************************
LZSS.C -- A Data Compression Program
***************************************************************
4/6/1989 Haruhiko Okumura
Use, distribute, and modify this program freely.
Please send me your improved versions.
PC-VAN SCIENCE
NIFTY-Serve PAF01022
CompuServe 74050,1022
**************************************************************/
#define N 4096 /* size of ring buffer - must be power of 2 */
#define F 18 /* upper limit for match_length */
#define THRESHOLD 2 /* encode string into position and length
if match_length is greater than this */
#define NIL N /* index for root of binary search trees */
struct encode_state {
/*
* left & right children & parent. These constitute binary search trees.
*/
int lchild[N + 1], rchild[N + 257], parent[N + 1];
/* ring buffer of size N, with extra F-1 bytes to aid string comparison */
uint8_t text_buf[N + F - 1];
/*
* match_length of longest match.
* These are set by the insert_node() procedure.
*/
int match_position, match_length;
};
int
decompress_lzss(uint8_t *dst, uint8_t *src, uint32_t srclen)
{
/* ring buffer of size N, with extra F-1 bytes to aid string comparison */
uint8_t text_buf[N + F - 1];
uint8_t *dststart = dst;
uint8_t *srcend = src + srclen;
int i, j, k, r, c;
unsigned int flags;
dst = dststart;
srcend = src + srclen;
for (i = 0; i < N - F; i++)
text_buf[i] = ' ';
r = N - F;
flags = 0;
for ( ; ; ) {
if (((flags >>= 1) & 0x100) == 0) {
if (src < srcend) c = *src++; else break;
flags = c | 0xFF00; /* uses higher byte cleverly */
} /* to count eight */
if (flags & 1) {
if (src < srcend) c = *src++; else break;
*dst++ = c;
text_buf[r++] = c;
r &= (N - 1);
} else {
if (src < srcend) i = *src++; else break;
if (src < srcend) j = *src++; else break;
i |= ((j & 0xF0) << 4);
j = (j & 0x0F) + THRESHOLD;
for (k = 0; k <= j; k++) {
c = text_buf[(i + k) & (N - 1)];
*dst++ = c;
text_buf[r++] = c;
r &= (N - 1);
}
}
}
return dst - dststart;
}
/*
* initialize state, mostly the trees
*
* For i = 0 to N - 1, rchild[i] and lchild[i] will be the right and left
* children of node i. These nodes need not be initialized. Also, parent[i]
* is the parent of node i. These are initialized to NIL (= N), which stands
* for 'not used.' For i = 0 to 255, rchild[N + i + 1] is the root of the
* tree for strings that begin with character i. These are initialized to NIL.
* Note there are 256 trees. */
static void init_state(struct encode_state *sp)
{
int i;
memset(sp, 0, sizeof(*sp));
for (i = 0; i < N - F; i++)
sp->text_buf[i] = ' ';
for (i = N + 1; i <= N + 256; i++)
sp->rchild[i] = NIL;
for (i = 0; i < N; i++)
sp->parent[i] = NIL;
}
/*
* Inserts string of length F, text_buf[r..r+F-1], into one of the trees
* (text_buf[r]'th tree) and returns the longest-match position and length
* via the global variables match_position and match_length.
* If match_length = F, then removes the old node in favor of the new one,
* because the old one will be deleted sooner. Note r plays double role,
* as tree node and position in buffer.
*/
static void insert_node(struct encode_state *sp, int r)
{
int i, p, cmp;
uint8_t *key;
cmp = 1;
key = &sp->text_buf[r];
p = N + 1 + key[0];
sp->rchild[r] = sp->lchild[r] = NIL;
sp->match_length = 0;
for ( ; ; ) {
if (cmp >= 0) {
if (sp->rchild[p] != NIL)
p = sp->rchild[p];
else {
sp->rchild[p] = r;
sp->parent[r] = p;
return;
}
} else {
if (sp->lchild[p] != NIL)
p = sp->lchild[p];
else {
sp->lchild[p] = r;
sp->parent[r] = p;
return;
}
}
for (i = 1; i < F; i++) {
if ((cmp = key[i] - sp->text_buf[p + i]) != 0)
break;
}
if (i > sp->match_length) {
sp->match_position = p;
if ((sp->match_length = i) >= F)
break;
}
}
sp->parent[r] = sp->parent[p];
sp->lchild[r] = sp->lchild[p];
sp->rchild[r] = sp->rchild[p];
sp->parent[sp->lchild[p]] = r;
sp->parent[sp->rchild[p]] = r;
if (sp->rchild[sp->parent[p]] == p)
sp->rchild[sp->parent[p]] = r;
else
sp->lchild[sp->parent[p]] = r;
sp->parent[p] = NIL; /* remove p */
}
/* deletes node p from tree */
static void delete_node(struct encode_state *sp, int p)
{
int q;
if (sp->parent[p] == NIL)
return; /* not in tree */
if (sp->rchild[p] == NIL)
q = sp->lchild[p];
else if (sp->lchild[p] == NIL)
q = sp->rchild[p];
else {
q = sp->lchild[p];
if (sp->rchild[q] != NIL) {
do {
q = sp->rchild[q];
} while (sp->rchild[q] != NIL);
sp->rchild[sp->parent[q]] = sp->lchild[q];
sp->parent[sp->lchild[q]] = sp->parent[q];
sp->lchild[q] = sp->lchild[p];
sp->parent[sp->lchild[p]] = q;
}
sp->rchild[q] = sp->rchild[p];
sp->parent[sp->rchild[p]] = q;
}
sp->parent[q] = sp->parent[p];
if (sp->rchild[sp->parent[p]] == p)
sp->rchild[sp->parent[p]] = q;
else
sp->lchild[sp->parent[p]] = q;
sp->parent[p] = NIL;
}
uint8_t *
compress_lzss(uint8_t *dst, uint32_t dstlen, uint8_t *src, uint32_t srcLen)
{
/* Encoding state, mostly tree but some current match stuff */
struct encode_state *sp;
int i, c, len, r, s, last_match_length, code_buf_ptr;
uint8_t code_buf[17], mask;
uint8_t *srcend = src + srcLen;
uint8_t *dstend = dst + dstlen;
/* initialize trees */
sp = (struct encode_state *) malloc(sizeof(*sp));
init_state(sp);
/*
* code_buf[1..16] saves eight units of code, and code_buf[0] works
* as eight flags, "1" representing that the unit is an unencoded
* letter (1 byte), "" a position-and-length pair (2 bytes).
* Thus, eight units require at most 16 bytes of code.
*/
code_buf[0] = 0;
code_buf_ptr = mask = 1;
/* Clear the buffer with any character that will appear often. */
s = 0; r = N - F;
/* Read F bytes into the last F bytes of the buffer */
for (len = 0; len < F && src < srcend; len++)
sp->text_buf[r + len] = *src++;
if (!len) {
free(sp);
return (void *) 0; /* text of size zero */
}
/*
* Insert the F strings, each of which begins with one or more
* 'space' characters. Note the order in which these strings are
* inserted. This way, degenerate trees will be less likely to occur.
*/
for (i = 1; i <= F; i++)
insert_node(sp, r - i);
/*
* Finally, insert the whole string just read.
* The global variables match_length and match_position are set.
*/
insert_node(sp, r);
do {
/* match_length may be spuriously long near the end of text. */
if (sp->match_length > len)
sp->match_length = len;
if (sp->match_length <= THRESHOLD) {
sp->match_length = 1; /* Not long enough match. Send one byte. */
code_buf[0] |= mask; /* 'send one byte' flag */
code_buf[code_buf_ptr++] = sp->text_buf[r]; /* Send uncoded. */
} else {
/* Send position and length pair. Note match_length > THRESHOLD. */
code_buf[code_buf_ptr++] = (uint8_t) sp->match_position;
code_buf[code_buf_ptr++] = (uint8_t)
( ((sp->match_position >> 4) & 0xF0)
| (sp->match_length - (THRESHOLD + 1)) );
}
if ((mask <<= 1) == 0) { /* Shift mask left one bit. */
/* Send at most 8 units of code together */
for (i = 0; i < code_buf_ptr; i++)
if (dst < dstend)
*dst++ = code_buf[i];
else {
free(sp);
return (void *) 0;
}
code_buf[0] = 0;
code_buf_ptr = mask = 1;
}
last_match_length = sp->match_length;
for (i = 0; i < last_match_length && src < srcend; i++) {
delete_node(sp, s); /* Delete old strings and */
c = *src++;
sp->text_buf[s] = c; /* read new bytes */
/*
* If the position is near the end of buffer, extend the buffer
* to make string comparison easier.
*/
if (s < F - 1)
sp->text_buf[s + N] = c;
/* Since this is a ring buffer, increment the position modulo N. */
s = (s + 1) & (N - 1);
r = (r + 1) & (N - 1);
/* Register the string in text_buf[r..r+F-1] */
insert_node(sp, r);
}
while (i++ < last_match_length) {
delete_node(sp, s);
/* After the end of text, no need to read, */
s = (s + 1) & (N - 1);
r = (r + 1) & (N - 1);
/* but buffer may not be empty. */
if (--len)
insert_node(sp, r);
}
} while (len > 0); /* until length of string to be processed is zero */
if (code_buf_ptr > 1) { /* Send remaining code. */
for (i = 0; i < code_buf_ptr; i++)
if (dst < dstend)
*dst++ = code_buf[i];
else {
free(sp);
return (void *) 0;
}
}
#include <stdlib.h>
#include "lzss.h"
free(sp);
return dst;
}
#define BASE 65521L /* largest prime smaller than 65536 */
#define NMAX 5000
// NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1
#define DO1(buf,i) {s1 += buf[i]; s2 += s1;}
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8);
uint32_t lzadler32(uint8_t *buf, int32_t len)
{
unsigned long s1 = 1; // adler & 0xffff;
unsigned long s2 = 0; // (adler >> 16) & 0xffff;
int k;
while (len > 0) {
k = len < NMAX ? len : NMAX;
len -= k;
while (k >= 16) {
DO16(buf);
buf += 16;
k -= 16;
}
if (k != 0) do {
s1 += *buf++;
s2 += s1;
} while (--k);
s1 %= BASE;
s2 %= BASE;
}
return (s2 << 16) | s1;
}
/**************************************************************
LZSS.C -- A Data Compression Program
***************************************************************
4/6/1989 Haruhiko Okumura
Use, distribute, and modify this program freely.
Please send me your improved versions.
PC-VAN SCIENCE
NIFTY-Serve PAF01022
CompuServe 74050,1022
**************************************************************/
#define N 4096 /* size of ring buffer - must be power of 2 */
#define F 18 /* upper limit for match_length */
#define THRESHOLD 2 /* encode string into position and length
if match_length is greater than this */
#define NIL N /* index for root of binary search trees */
struct encode_state {
/*
* left & right children & parent. These constitute binary search trees.
*/
int lchild[N + 1], rchild[N + 257], parent[N + 1];
/* ring buffer of size N, with extra F-1 bytes to aid string comparison */
uint8_t text_buf[N + F - 1];
/*
* match_length of longest match.
* These are set by the insert_node() procedure.
*/
int match_position, match_length;
};
int
decompress_lzss(uint8_t *dst, uint8_t *src, uint32_t srclen)
{
/* ring buffer of size N, with extra F-1 bytes to aid string comparison */
uint8_t text_buf[N + F - 1];
uint8_t *dststart = dst;
uint8_t *srcend = src + srclen;
int i, j, k, r, c;
unsigned int flags;
dst = dststart;
srcend = src + srclen;
for (i = 0; i < N - F; i++)
text_buf[i] = ' ';
r = N - F;
flags = 0;
for ( ; ; ) {
if (((flags >>= 1) & 0x100) == 0) {
if (src < srcend) c = *src++; else break;
flags = c | 0xFF00; /* uses higher byte cleverly */
} /* to count eight */
if (flags & 1) {
if (src < srcend) c = *src++; else break;
*dst++ = c;
text_buf[r++] = c;
r &= (N - 1);
} else {
if (src < srcend) i = *src++; else break;
if (src < srcend) j = *src++; else break;
i |= ((j & 0xF0) << 4);
j = (j & 0x0F) + THRESHOLD;
for (k = 0; k <= j; k++) {
c = text_buf[(i + k) & (N - 1)];
*dst++ = c;
text_buf[r++] = c;
r &= (N - 1);
}
}
}
return dst - dststart;
}
/*
* initialize state, mostly the trees
*
* For i = 0 to N - 1, rchild[i] and lchild[i] will be the right and left
* children of node i. These nodes need not be initialized. Also, parent[i]
* is the parent of node i. These are initialized to NIL (= N), which stands
* for 'not used.' For i = 0 to 255, rchild[N + i + 1] is the root of the
* tree for strings that begin with character i. These are initialized to NIL.
* Note there are 256 trees. */
static void init_state(struct encode_state *sp)
{
int i;
memset(sp, 0, sizeof(*sp));
for (i = 0; i < N - F; i++)
sp->text_buf[i] = ' ';
for (i = N + 1; i <= N + 256; i++)
sp->rchild[i] = NIL;
for (i = 0; i < N; i++)
sp->parent[i] = NIL;
}
/*
* Inserts string of length F, text_buf[r..r+F-1], into one of the trees
* (text_buf[r]'th tree) and returns the longest-match position and length
* via the global variables match_position and match_length.
* If match_length = F, then removes the old node in favor of the new one,
* because the old one will be deleted sooner. Note r plays double role,
* as tree node and position in buffer.
*/
static void insert_node(struct encode_state *sp, int r)
{
int i, p, cmp;
uint8_t *key;
cmp = 1;
key = &sp->text_buf[r];
p = N + 1 + key[0];
sp->rchild[r] = sp->lchild[r] = NIL;
sp->match_length = 0;
for ( ; ; ) {
if (cmp >= 0) {
if (sp->rchild[p] != NIL)
p = sp->rchild[p];
else {
sp->rchild[p] = r;
sp->parent[r] = p;
return;
}
} else {
if (sp->lchild[p] != NIL)
p = sp->lchild[p];
else {
sp->lchild[p] = r;
sp->parent[r] = p;
return;
}
}
for (i = 1; i < F; i++) {
if ((cmp = key[i] - sp->text_buf[p + i]) != 0)
break;
}
if (i > sp->match_length) {
sp->match_position = p;
if ((sp->match_length = i) >= F)
break;
}
}
sp->parent[r] = sp->parent[p];
sp->lchild[r] = sp->lchild[p];
sp->rchild[r] = sp->rchild[p];
sp->parent[sp->lchild[p]] = r;
sp->parent[sp->rchild[p]] = r;
if (sp->rchild[sp->parent[p]] == p)
sp->rchild[sp->parent[p]] = r;
else
sp->lchild[sp->parent[p]] = r;
sp->parent[p] = NIL; /* remove p */
}
/* deletes node p from tree */
static void delete_node(struct encode_state *sp, int p)
{
int q;
if (sp->parent[p] == NIL)
return; /* not in tree */
if (sp->rchild[p] == NIL)
q = sp->lchild[p];
else if (sp->lchild[p] == NIL)
q = sp->rchild[p];
else {
q = sp->lchild[p];
if (sp->rchild[q] != NIL) {
do {
q = sp->rchild[q];
} while (sp->rchild[q] != NIL);
sp->rchild[sp->parent[q]] = sp->lchild[q];
sp->parent[sp->lchild[q]] = sp->parent[q];
sp->lchild[q] = sp->lchild[p];
sp->parent[sp->lchild[p]] = q;
}
sp->rchild[q] = sp->rchild[p];
sp->parent[sp->rchild[p]] = q;
}
sp->parent[q] = sp->parent[p];
if (sp->rchild[sp->parent[p]] == p)
sp->rchild[sp->parent[p]] = q;
else
sp->lchild[sp->parent[p]] = q;
sp->parent[p] = NIL;
}
uint8_t *
compress_lzss(uint8_t *dst, uint32_t dstlen, uint8_t *src, uint32_t srcLen)
{
/* Encoding state, mostly tree but some current match stuff */
struct encode_state *sp;
int i, c, len, r, s, last_match_length, code_buf_ptr;
uint8_t code_buf[17], mask;
uint8_t *srcend = src + srcLen;
uint8_t *dstend = dst + dstlen;
/* initialize trees */
sp = (struct encode_state *) malloc(sizeof(*sp));
init_state(sp);
/*
* code_buf[1..16] saves eight units of code, and code_buf[0] works
* as eight flags, "1" representing that the unit is an unencoded
* letter (1 byte), "" a position-and-length pair (2 bytes).
* Thus, eight units require at most 16 bytes of code.
*/
code_buf[0] = 0;
code_buf_ptr = mask = 1;
/* Clear the buffer with any character that will appear often. */
s = 0; r = N - F;
/* Read F bytes into the last F bytes of the buffer */
for (len = 0; len < F && src < srcend; len++)
sp->text_buf[r + len] = *src++;
if (!len) {
free(sp);
return (void *) 0; /* text of size zero */
}
/*
* Insert the F strings, each of which begins with one or more
* 'space' characters. Note the order in which these strings are
* inserted. This way, degenerate trees will be less likely to occur.
*/
for (i = 1; i <= F; i++)
insert_node(sp, r - i);
/*
* Finally, insert the whole string just read.
* The global variables match_length and match_position are set.
*/
insert_node(sp, r);
do {
/* match_length may be spuriously long near the end of text. */
if (sp->match_length > len)
sp->match_length = len;
if (sp->match_length <= THRESHOLD) {
sp->match_length = 1; /* Not long enough match. Send one byte. */
code_buf[0] |= mask; /* 'send one byte' flag */
code_buf[code_buf_ptr++] = sp->text_buf[r]; /* Send uncoded. */
} else {
/* Send position and length pair. Note match_length > THRESHOLD. */
code_buf[code_buf_ptr++] = (uint8_t) sp->match_position;
code_buf[code_buf_ptr++] = (uint8_t)
( ((sp->match_position >> 4) & 0xF0)
| (sp->match_length - (THRESHOLD + 1)) );
}
if ((mask <<= 1) == 0) { /* Shift mask left one bit. */
/* Send at most 8 units of code together */
for (i = 0; i < code_buf_ptr; i++)
if (dst < dstend)
*dst++ = code_buf[i];
else {
free(sp);
return (void *) 0;
}
code_buf[0] = 0;
code_buf_ptr = mask = 1;
}
last_match_length = sp->match_length;
for (i = 0; i < last_match_length && src < srcend; i++) {
delete_node(sp, s); /* Delete old strings and */
c = *src++;
sp->text_buf[s] = c; /* read new bytes */
/*
* If the position is near the end of buffer, extend the buffer
* to make string comparison easier.
*/
if (s < F - 1)
sp->text_buf[s + N] = c;
/* Since this is a ring buffer, increment the position modulo N. */
s = (s + 1) & (N - 1);
r = (r + 1) & (N - 1);
/* Register the string in text_buf[r..r+F-1] */
insert_node(sp, r);
}
while (i++ < last_match_length) {
delete_node(sp, s);
/* After the end of text, no need to read, */
s = (s + 1) & (N - 1);
r = (r + 1) & (N - 1);
/* but buffer may not be empty. */
if (--len)
insert_node(sp, r);
}
} while (len > 0); /* until length of string to be processed is zero */
if (code_buf_ptr > 1) { /* Send remaining code. */
for (i = 0; i < code_buf_ptr; i++)
if (dst < dstend)
*dst++ = code_buf[i];
else {
free(sp);
return (void *) 0;
}
}
free(sp);
return dst;
}

Просмотреть файл

@ -1,5 +1,5 @@
#include <stdint.h>
uint32_t lzadler32(uint8_t *buf, int32_t len);
int decompress_lzss(uint8_t *dst, uint8_t *src, uint32_t srclen);
uint8_t *compress_lzss(uint8_t *dst, uint32_t dstlen, uint8_t *src, uint32_t srcLen);
#include <stdint.h>
uint32_t lzadler32(uint8_t *buf, int32_t len);
int decompress_lzss(uint8_t *dst, uint8_t *src, uint32_t srclen);
uint8_t *compress_lzss(uint8_t *dst, uint32_t dstlen, uint8_t *src, uint32_t srcLen);

Просмотреть файл

@ -1,162 +1,162 @@
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "abstractfile.h"
#include "lzssfile.h"
#include "lzss.h"
void flipCompHeader(CompHeader* header) {
FLIPENDIAN(header->signature);
FLIPENDIAN(header->compression_type);
FLIPENDIAN(header->checksum);
FLIPENDIAN(header->length_uncompressed);
FLIPENDIAN(header->length_compressed);
}
size_t readComp(AbstractFile* file, void* data, size_t len) {
InfoComp* info = (InfoComp*) (file->data);
memcpy(data, (void*)((uint8_t*)info->buffer + (uint32_t)info->offset), len);
info->offset += (size_t)len;
return len;
}
size_t writeComp(AbstractFile* file, const void* data, size_t len) {
InfoComp* info = (InfoComp*) (file->data);
while((info->offset + (size_t)len) > info->header.length_uncompressed) {
info->header.length_uncompressed = info->offset + (size_t)len;
info->buffer = realloc(info->buffer, info->header.length_uncompressed);
}
memcpy((void*)((uint8_t*)info->buffer + (uint32_t)info->offset), data, len);
info->offset += (size_t)len;
info->dirty = TRUE;
return len;
}
int seekComp(AbstractFile* file, off_t offset) {
InfoComp* info = (InfoComp*) (file->data);
info->offset = (size_t)offset;
return 0;
}
off_t tellComp(AbstractFile* file) {
InfoComp* info = (InfoComp*) (file->data);
return (off_t)info->offset;
}
off_t getLengthComp(AbstractFile* file) {
InfoComp* info = (InfoComp*) (file->data);
return info->header.length_uncompressed;
}
void closeComp(AbstractFile* file) {
InfoComp* info = (InfoComp*) (file->data);
uint32_t cksum;
uint8_t *compressed;
if(info->dirty) {
info->header.checksum = lzadler32((uint8_t*)info->buffer, info->header.length_uncompressed);
compressed = malloc(info->header.length_uncompressed * 2);
info->header.length_compressed = (uint32_t)(compress_lzss(compressed, info->header.length_uncompressed * 2, info->buffer, info->header.length_uncompressed) - compressed);
info->file->seek(info->file, sizeof(info->header));
info->file->write(info->file, compressed, info->header.length_compressed);
free(compressed);
flipCompHeader(&(info->header));
info->file->seek(info->file, 0);
info->file->write(info->file, &(info->header), sizeof(info->header));
}
free(info->buffer);
info->file->close(info->file);
free(info);
free(file);
}
AbstractFile* createAbstractFileFromComp(AbstractFile* file) {
InfoComp* info;
AbstractFile* toReturn;
uint8_t *compressed;
if(!file) {
return NULL;
}
info = (InfoComp*) malloc(sizeof(InfoComp));
info->file = file;
file->seek(file, 0);
file->read(file, &(info->header), sizeof(info->header));
flipCompHeader(&(info->header));
if(info->header.signature != COMP_SIGNATURE) {
free(info);
return NULL;
}
if(info->header.compression_type != LZSS_SIGNATURE) {
free(info);
return NULL;
}
info->buffer = malloc(info->header.length_uncompressed);
compressed = malloc(info->header.length_compressed);
file->read(file, compressed, info->header.length_compressed);
if(decompress_lzss(info->buffer, compressed, info->header.length_compressed) != info->header.length_uncompressed) {
free(compressed);
free(info);
return NULL;
}
free(compressed);
info->dirty = FALSE;
info->offset = 0;
toReturn = (AbstractFile*) malloc(sizeof(AbstractFile));
toReturn->data = info;
toReturn->read = readComp;
toReturn->write = writeComp;
toReturn->seek = seekComp;
toReturn->tell = tellComp;
toReturn->getLength = getLengthComp;
toReturn->close = closeComp;
return toReturn;
}
AbstractFile* duplicateCompFile(AbstractFile* file, AbstractFile* backing) {
InfoComp* info;
unsigned char* copyCertificate;
AbstractFile* toReturn;
if(!file) {
return NULL;
}
info = (InfoComp*) malloc(sizeof(InfoComp));
memcpy(info, file->data, sizeof(InfoComp));
info->file = backing;
info->buffer = malloc(1);
info->header.length_uncompressed = 0;
info->dirty = TRUE;
info->offset = 0;
toReturn = (AbstractFile*) malloc(sizeof(AbstractFile));
toReturn->data = info;
toReturn->read = readComp;
toReturn->write = writeComp;
toReturn->seek = seekComp;
toReturn->tell = tellComp;
toReturn->getLength = getLengthComp;
toReturn->close = closeComp;
return toReturn;
}
#include <stdlib.h>
#include <string.h>
#include "common.h"
#include "abstractfile.h"
#include "lzssfile.h"
#include "lzss.h"
void flipCompHeader(CompHeader* header) {
FLIPENDIAN(header->signature);
FLIPENDIAN(header->compression_type);
FLIPENDIAN(header->checksum);
FLIPENDIAN(header->length_uncompressed);
FLIPENDIAN(header->length_compressed);
}
size_t readComp(AbstractFile* file, void* data, size_t len) {
InfoComp* info = (InfoComp*) (file->data);
memcpy(data, (void*)((uint8_t*)info->buffer + (uint32_t)info->offset), len);
info->offset += (size_t)len;
return len;
}
size_t writeComp(AbstractFile* file, const void* data, size_t len) {
InfoComp* info = (InfoComp*) (file->data);
while((info->offset + (size_t)len) > info->header.length_uncompressed) {
info->header.length_uncompressed = info->offset + (size_t)len;
info->buffer = realloc(info->buffer, info->header.length_uncompressed);
}
memcpy((void*)((uint8_t*)info->buffer + (uint32_t)info->offset), data, len);
info->offset += (size_t)len;
info->dirty = TRUE;
return len;
}
int seekComp(AbstractFile* file, off_t offset) {
InfoComp* info = (InfoComp*) (file->data);
info->offset = (size_t)offset;
return 0;
}
off_t tellComp(AbstractFile* file) {
InfoComp* info = (InfoComp*) (file->data);
return (off_t)info->offset;
}
off_t getLengthComp(AbstractFile* file) {
InfoComp* info = (InfoComp*) (file->data);
return info->header.length_uncompressed;
}
void closeComp(AbstractFile* file) {
InfoComp* info = (InfoComp*) (file->data);
uint32_t cksum;
uint8_t *compressed;
if(info->dirty) {
info->header.checksum = lzadler32((uint8_t*)info->buffer, info->header.length_uncompressed);
compressed = malloc(info->header.length_uncompressed * 2);
info->header.length_compressed = (uint32_t)(compress_lzss(compressed, info->header.length_uncompressed * 2, info->buffer, info->header.length_uncompressed) - compressed);
info->file->seek(info->file, sizeof(info->header));
info->file->write(info->file, compressed, info->header.length_compressed);
free(compressed);
flipCompHeader(&(info->header));
info->file->seek(info->file, 0);
info->file->write(info->file, &(info->header), sizeof(info->header));
}
free(info->buffer);
info->file->close(info->file);
free(info);
free(file);
}
AbstractFile* createAbstractFileFromComp(AbstractFile* file) {
InfoComp* info;
AbstractFile* toReturn;
uint8_t *compressed;
if(!file) {
return NULL;
}
info = (InfoComp*) malloc(sizeof(InfoComp));
info->file = file;
file->seek(file, 0);
file->read(file, &(info->header), sizeof(info->header));
flipCompHeader(&(info->header));
if(info->header.signature != COMP_SIGNATURE) {
free(info);
return NULL;
}
if(info->header.compression_type != LZSS_SIGNATURE) {
free(info);
return NULL;
}
info->buffer = malloc(info->header.length_uncompressed);
compressed = malloc(info->header.length_compressed);
file->read(file, compressed, info->header.length_compressed);
if(decompress_lzss(info->buffer, compressed, info->header.length_compressed) != info->header.length_uncompressed) {
free(compressed);
free(info);
return NULL;
}
free(compressed);
info->dirty = FALSE;
info->offset = 0;
toReturn = (AbstractFile*) malloc(sizeof(AbstractFile));
toReturn->data = info;
toReturn->read = readComp;
toReturn->write = writeComp;
toReturn->seek = seekComp;
toReturn->tell = tellComp;
toReturn->getLength = getLengthComp;
toReturn->close = closeComp;
return toReturn;
}
AbstractFile* duplicateCompFile(AbstractFile* file, AbstractFile* backing) {
InfoComp* info;
unsigned char* copyCertificate;
AbstractFile* toReturn;
if(!file) {
return NULL;
}
info = (InfoComp*) malloc(sizeof(InfoComp));
memcpy(info, file->data, sizeof(InfoComp));
info->file = backing;
info->buffer = malloc(1);
info->header.length_uncompressed = 0;
info->dirty = TRUE;
info->offset = 0;
toReturn = (AbstractFile*) malloc(sizeof(AbstractFile));
toReturn->data = info;
toReturn->read = readComp;
toReturn->write = writeComp;
toReturn->seek = seekComp;
toReturn->tell = tellComp;
toReturn->getLength = getLengthComp;
toReturn->close = closeComp;
return toReturn;
}

Просмотреть файл

@ -1,27 +1,27 @@
#include <stdint.h>
#include "abstractfile.h"
#define COMP_SIGNATURE 0x636F6D70
#define LZSS_SIGNATURE 0x6C7A7373
typedef struct CompHeader {
uint32_t signature;
uint32_t compression_type;
uint32_t checksum;
uint32_t length_uncompressed;
uint32_t length_compressed;
uint8_t padding[0x16C];
} __attribute__((__packed__)) CompHeader;
typedef struct InfoComp {
AbstractFile* file;
CompHeader header;
size_t offset;
void* buffer;
char dirty;
} InfoComp;
AbstractFile* createAbstractFileFromComp(AbstractFile* file);
AbstractFile* duplicateCompFile(AbstractFile* file, AbstractFile* backing);
#include <stdint.h>
#include "abstractfile.h"
#define COMP_SIGNATURE 0x636F6D70
#define LZSS_SIGNATURE 0x6C7A7373
typedef struct CompHeader {
uint32_t signature;
uint32_t compression_type;
uint32_t checksum;
uint32_t length_uncompressed;
uint32_t length_compressed;
uint8_t padding[0x16C];
} __attribute__((__packed__)) CompHeader;
typedef struct InfoComp {
AbstractFile* file;
CompHeader header;
size_t offset;
void* buffer;
char dirty;
} InfoComp;
AbstractFile* createAbstractFileFromComp(AbstractFile* file);
AbstractFile* duplicateCompFile(AbstractFile* file, AbstractFile* backing);

Просмотреть файл

@ -1,59 +1,59 @@
#include "../hfs/common.h"
#include "8900.h"
#include "img2.h"
#include "lzssfile.h"
#include "ibootim.h"
AbstractFile* openAbstractFile(AbstractFile* file) {
uint32_t signatureBE;
uint32_t signatureLE;
file->seek(file, 0);
file->read(file, &signatureBE, sizeof(signatureBE));
signatureLE = signatureBE;
FLIPENDIAN(signatureBE);
FLIPENDIANLE(signatureLE);
file->seek(file, 0);
if(signatureBE == SIGNATURE_8900) {
return openAbstractFile(createAbstractFileFrom8900(file));
} else if(signatureLE == IMG2_SIGNATURE) {
return openAbstractFile(createAbstractFileFromImg2(file));
} else if(signatureBE == COMP_SIGNATURE) {
return openAbstractFile(createAbstractFileFromComp(file));
} else if(signatureBE == IBOOTIM_SIG_UINT) {
return openAbstractFile(createAbstractFileFromIBootIM(file));
} else {
return file;
}
}
AbstractFile* duplicateAbstractFile(AbstractFile* file, AbstractFile* backing) {
uint32_t signatureBE;
uint32_t signatureLE;
AbstractFile* orig;
file->seek(file, 0);
file->read(file, &signatureBE, sizeof(signatureBE));
signatureLE = signatureBE;
FLIPENDIAN(signatureBE);
FLIPENDIANLE(signatureLE);
file->seek(file, 0);
if(signatureBE == SIGNATURE_8900) {
orig = createAbstractFileFrom8900(file);
return duplicateAbstractFile(orig, duplicate8900File(orig, backing));
} else if(signatureLE == IMG2_SIGNATURE) {
orig = createAbstractFileFromImg2(file);
return duplicateAbstractFile(orig, duplicateImg2File(orig, backing));
} else if(signatureBE == COMP_SIGNATURE) {
orig = createAbstractFileFromComp(file);
return duplicateAbstractFile(orig, duplicateCompFile(orig, backing));
} else if(signatureBE == IBOOTIM_SIG_UINT) {
orig = createAbstractFileFromIBootIM(file);
return duplicateAbstractFile(orig, duplicateIBootIMFile(orig, backing));
} else {
file->close(file);
return backing;
}
}
#include "../hfs/common.h"
#include "8900.h"
#include "img2.h"
#include "lzssfile.h"
#include "ibootim.h"
AbstractFile* openAbstractFile(AbstractFile* file) {
uint32_t signatureBE;
uint32_t signatureLE;
file->seek(file, 0);
file->read(file, &signatureBE, sizeof(signatureBE));
signatureLE = signatureBE;
FLIPENDIAN(signatureBE);
FLIPENDIANLE(signatureLE);
file->seek(file, 0);
if(signatureBE == SIGNATURE_8900) {
return openAbstractFile(createAbstractFileFrom8900(file));
} else if(signatureLE == IMG2_SIGNATURE) {
return openAbstractFile(createAbstractFileFromImg2(file));
} else if(signatureBE == COMP_SIGNATURE) {
return openAbstractFile(createAbstractFileFromComp(file));
} else if(signatureBE == IBOOTIM_SIG_UINT) {
return openAbstractFile(createAbstractFileFromIBootIM(file));
} else {
return file;
}
}
AbstractFile* duplicateAbstractFile(AbstractFile* file, AbstractFile* backing) {
uint32_t signatureBE;
uint32_t signatureLE;
AbstractFile* orig;
file->seek(file, 0);
file->read(file, &signatureBE, sizeof(signatureBE));
signatureLE = signatureBE;
FLIPENDIAN(signatureBE);
FLIPENDIANLE(signatureLE);
file->seek(file, 0);
if(signatureBE == SIGNATURE_8900) {
orig = createAbstractFileFrom8900(file);
return duplicateAbstractFile(orig, duplicate8900File(orig, backing));
} else if(signatureLE == IMG2_SIGNATURE) {
orig = createAbstractFileFromImg2(file);
return duplicateAbstractFile(orig, duplicateImg2File(orig, backing));
} else if(signatureBE == COMP_SIGNATURE) {
orig = createAbstractFileFromComp(file);
return duplicateAbstractFile(orig, duplicateCompFile(orig, backing));
} else if(signatureBE == IBOOTIM_SIG_UINT) {
orig = createAbstractFileFromIBootIM(file);
return duplicateAbstractFile(orig, duplicateIBootIMFile(orig, backing));
} else {
file->close(file);
return backing;
}
}

Просмотреть файл

@ -1,19 +1,19 @@
#ifndef NOR_FILES_H
#define NOR_FILES_H
#include "abstractfile.h"
#include "8900.h"
#include "img2.h"
#include "lzssfile.h"
#include "abstractfile.h"
#include "8900.h"
#include "img2.h"
#include "lzssfile.h"
#ifdef __cplusplus
extern "C" {
#endif
AbstractFile* openAbstractFile(AbstractFile* file);
#endif
AbstractFile* openAbstractFile(AbstractFile* file);
AbstractFile* duplicateAbstractFile(AbstractFile* file, AbstractFile* backing);
#ifdef __cplusplus
}
#endif
#endif

Просмотреть файл

@ -3,12 +3,12 @@
#include "abstractfile.h"
typedef struct OutputState {
char* fileName;
void* buffer;
size_t bufferSize;
struct OutputState* next;
struct OutputState* prev;
typedef struct OutputState {
char* fileName;
void* buffer;
size_t bufferSize;
struct OutputState* next;
struct OutputState* prev;
} OutputState;
#ifdef __cplusplus
@ -16,7 +16,7 @@ extern "C" {
#endif
void addToOutput(OutputState** state, char* fileName, void* buffer, size_t bufferSize);
AbstractFile* getFileFromOutputState(OutputState** state, const char* fileName);
AbstractFile* getFileFromOutputStateForOverwrite(OutputState** state, const char* fileName);
AbstractFile* getFileFromOutputStateForOverwrite(OutputState** state, const char* fileName);
void writeOutput(OutputState** state, char* ipsw);
void releaseOutput(OutputState** state);
OutputState* loadZip(const char* ipsw);

Просмотреть файл

@ -1,494 +1,494 @@
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include "common.h"
#include "nor_files.h"
#include "dmg.h"
#include "filevault.h"
#include "ibootim.h"
#include "plist.h"
#include "outputstate.h"
#include "hfslib.h"
#include "dmglib.h"
#include "pwnutil.h"
char endianness;
void TestByteOrder()
{
short int word = 0x0001;
char *byte = (char *) &word;
endianness = byte[0] ? IS_LITTLE_ENDIAN : IS_BIG_ENDIAN;
}
int doPatch(StringValue* patchValue, StringValue* fileValue, const char* bundlePath, OutputState** state) {
char* patchPath;
size_t bufferSize;
void* buffer;
AbstractFile* patchFile;
AbstractFile* file;
AbstractFile* out;
buffer = malloc(1);
patchPath = malloc(sizeof(char) * (strlen(bundlePath) + strlen(patchValue->value) + 2));
strcpy(patchPath, bundlePath);
strcat(patchPath, "/");
strcat(patchPath, patchValue->value);
printf("%s (%s)... ", fileValue->value, patchPath); fflush(stdout);
patchFile = createAbstractFileFromFile(fopen(patchPath, "rb"));
bufferSize = 0;
out = duplicateAbstractFile(getFileFromOutputState(state, fileValue->value), createAbstractFileFromMemoryFile((void**)&buffer, &bufferSize));
file = openAbstractFile(getFileFromOutputState(state, fileValue->value));
if(!patchFile || !file || !out) {
printf("file error\n");
exit(0);
}
if(patch(file, out, patchFile) != 0) {
printf("patch failed\n");
exit(0);
}
printf("writing... "); fflush(stdout);
/* out = createAbstractFileFromFile(fopen(filePath, "wb"));
out->write(out, buffer, bufferSize);
out->close(out);*/
addToOutput(state, fileValue->value, buffer, bufferSize);
printf("success\n"); fflush(stdout);
free(patchPath);
}
void doPatchInPlace(Volume* volume, char* filePath, char* patchPath) {
void* buffer;
void* buffer2;
size_t bufferSize;
size_t bufferSize2;
AbstractFile* bufferFile;
AbstractFile* patchFile;
AbstractFile* out;
buffer = malloc(1);
bufferSize = 0;
bufferFile = createAbstractFileFromMemoryFile((void**)&buffer, &bufferSize);
printf("retrieving..."); fflush(stdout);
get_hfs(volume, filePath, bufferFile);
printf("patching..."); fflush(stdout);
patchFile = createAbstractFileFromFile(fopen(patchPath, "rb"));
buffer2 = malloc(1);
bufferSize2 = 0;
out = duplicateAbstractFile(createAbstractFileFromMemoryFile((void**)&buffer, &bufferSize), createAbstractFileFromMemoryFile((void**)&buffer2, &bufferSize2));
if(!patchFile || !bufferFile || !out) {
printf("file error\n");
exit(0);
}
if(patch(bufferFile, out, patchFile) != 0) {
printf("patch failed\n");
exit(0);
}
printf("writing... "); fflush(stdout);
add_hfs(volume, createAbstractFileFromMemoryFile((void**)&buffer2, &bufferSize2), filePath);
free(buffer2);
free(buffer);
printf("success\n"); fflush(stdout);
}
void fixupBootNeuterArgs(Volume* volume, char unlockBaseband, char selfDestruct, char use39, char use46) {
char bootNeuterPlist[] = "/System/Library/LaunchDaemons/com.devteam.bootneuter.auto.plist";
AbstractFile* plistFile;
char* plist;
Dictionary* info;
size_t bufferSize;
ArrayValue* arguments;
printf("fixing up BootNeuter arguments...\n");
plist = malloc(1);
bufferSize = 0;
plistFile = createAbstractFileFromMemoryFile((void**)&plist, &bufferSize);
get_hfs(volume, bootNeuterPlist, plistFile);
plistFile->close(plistFile);
info = createRoot(plist);
free(plist);
arguments = (ArrayValue*) getValueByKey(info, "ProgramArguments");
addStringToArray(arguments, "-autoMode");
addStringToArray(arguments, "YES");
if(unlockBaseband) {
addStringToArray(arguments, "-unlockBaseband");
addStringToArray(arguments, "YES");
}
if(selfDestruct) {
addStringToArray(arguments, "-selfDestruct");
addStringToArray(arguments, "YES");
}
if(use39) {
addStringToArray(arguments, "-bootLoader");
addStringToArray(arguments, "3.9");
} else if(use46) {
addStringToArray(arguments, "-bootLoader");
addStringToArray(arguments, "4.6");
}
plist = getXmlFromRoot(info);
releaseDictionary(info);
plistFile = createAbstractFileFromMemory((void**)&plist, sizeof(char) * strlen(plist));
add_hfs(volume, plistFile, bootNeuterPlist);
free(plist);
}
int main(int argc, char* argv[]) {
TestByteOrder();
Dictionary* info;
Dictionary* firmwarePatches;
Dictionary* patchDict;
ArrayValue* patchArray;
void* buffer;
StringValue* actionValue;
StringValue* pathValue;
StringValue* fileValue;
StringValue* patchValue;
char* patchPath;
char* rootFSPathInIPSW;
io_func* rootFS;
Volume* rootVolume;
size_t rootSize;
char* ramdiskFSPathInIPSW;
io_func* ramdiskFS;
Volume* ramdiskVolume;
int i;
OutputState* outputState;
char* bundlePath;
char* bundleRoot = "FirmwareBundles/";
int mergePaths;
char* outputIPSW;
void* imageBuffer;
size_t imageSize;
FILE* temp;
AbstractFile* bootloader39;
AbstractFile* bootloader46;
AbstractFile* applelogo;
AbstractFile* recoverymode;
char unlockBaseband;
char selfDestruct;
char use39;
char use46;
char doBootNeuter;
char noBB;
applelogo = NULL;
recoverymode = NULL;
bootloader39 = NULL;
bootloader46 = NULL;
unlockBaseband = FALSE;
selfDestruct = FALSE;
use39 = FALSE;
use46 = FALSE;
doBootNeuter = FALSE;
noBB = FALSE;
if(argc < 3) {
printf("usage %s <input.ipsw> <target.ipsw> [-b <bootimage.png>] [-r <recoveryimage.png>] [-e \"<action to exclude>\"] [-nobbupdate] [[-unlock] [-use39] [-use46] [-cleanup] -3 <bootloader 3.9 file> -4 <bootloader 4.6 file>] <path/to/merge1> <path/to/merge2>...\n", argv[0]);
return 0;
}
outputIPSW = argv[2];
info = parseIPSW(argv[1], bundleRoot, &bundlePath, &outputState);
if(info == NULL) {
printf("error: Could not load IPSW\n");
exit(1);
}
firmwarePatches = (Dictionary*)getValueByKey(info, "FilesystemPatches");
for(i = 3; i < argc; i++) {
if(argv[i][0] != '-') {
break;
}
if(strcmp(argv[i], "-e") == 0) {
removeKey(firmwarePatches, argv[i + 1]);
i++;
continue;
}
if(strcmp(argv[i], "-unlock") == 0) {
unlockBaseband = TRUE;
continue;
}
if(strcmp(argv[i], "-cleanup") == 0) {
selfDestruct = TRUE;
continue;
}
if(strcmp(argv[i], "-nobbupdate") == 0) {
noBB = TRUE;
continue;
}
if(strcmp(argv[i], "-use39") == 0) {
if(use46) {
printf("error: select only one of -use39 and -use46\n");
exit(1);
}
use39 = TRUE;
continue;
}
if(strcmp(argv[i], "-use46") == 0) {
if(use39) {
printf("error: select only one of -use39 and -use46\n");
exit(1);
}
use46 = TRUE;
continue;
}
if(strcmp(argv[i], "-b") == 0) {
applelogo = createAbstractFileFromFile(fopen(argv[i + 1], "rb"));
if(!applelogo) {
printf("cannot open %s\n", argv[i + 1]);
exit(1);
}
i++;
continue;
}
if(strcmp(argv[i], "-r") == 0) {
recoverymode = createAbstractFileFromFile(fopen(argv[i + 1], "rb"));
if(!recoverymode) {
printf("cannot open %s\n", argv[i + 1]);
exit(1);
}
i++;
continue;
}
if(strcmp(argv[i], "-3") == 0) {
bootloader39 = createAbstractFileFromFile(fopen(argv[i + 1], "rb"));
if(!bootloader39) {
printf("cannot open %s\n", argv[i + 1]);
exit(1);
}
i++;
continue;
}
if(strcmp(argv[i], "-4") == 0) {
bootloader46 = createAbstractFileFromFile(fopen(argv[i + 1], "rb"));
if(!bootloader46) {
printf("cannot open %s\n", argv[i + 1]);
exit(1);
}
i++;
continue;
}
}
if(use39 || use46 || unlockBaseband || selfDestruct || bootloader39 || bootloader46) {
if(noBB) {
printf("error: bbupdate must be enabled for bootneuter\n");
exit(1);
} else {
if(!(bootloader39) || !(bootloader46)) {
printf("error: you must specify both bootloader files.\n");
exit(1);
} else {
doBootNeuter = TRUE;
}
}
}
mergePaths = i;
firmwarePatches = (Dictionary*)getValueByKey(info, "FirmwarePatches");
patchDict = (Dictionary*) firmwarePatches->values;
while(patchDict != NULL) {
fileValue = (StringValue*) getValueByKey(patchDict, "File");
if(strcmp(patchDict->dValue.key, "Restore Ramdisk") == 0) {
ramdiskFSPathInIPSW = fileValue->value;
}
patchValue = (StringValue*) getValueByKey(patchDict, "Patch2");
if(patchValue) {
if(!noBB) {
printf("%s: ", patchDict->dValue.key); fflush(stdout);
doPatch(patchValue, fileValue, bundlePath, &outputState);
patchDict = (Dictionary*) patchDict->dValue.next;
continue; /* skip over the normal Patch */
}
}
patchValue = (StringValue*) getValueByKey(patchDict, "Patch");
if(patchValue) {
printf("%s: ", patchDict->dValue.key); fflush(stdout);
doPatch(patchValue, fileValue, bundlePath, &outputState);
}
if(strcmp(patchDict->dValue.key, "AppleLogo") == 0 && applelogo) {
printf("replacing %s\n", fileValue->value); fflush(stdout);
ASSERT((imageBuffer = replaceBootImage(getFileFromOutputState(&outputState, fileValue->value), applelogo, &imageSize)) != NULL, "failed to use new image");
addToOutput(&outputState, fileValue->value, imageBuffer, imageSize);
}
if(strcmp(patchDict->dValue.key, "RecoveryMode") == 0 && recoverymode) {
printf("replacing %s\n", fileValue->value); fflush(stdout);
ASSERT((imageBuffer = replaceBootImage(getFileFromOutputState(&outputState, fileValue->value), recoverymode, &imageSize)) != NULL, "failed to use new image");
addToOutput(&outputState, fileValue->value, imageBuffer, imageSize);
}
patchDict = (Dictionary*) patchDict->dValue.next;
}
fileValue = (StringValue*) getValueByKey(info, "RootFilesystem");
rootFSPathInIPSW = fileValue->value;
sscanf(((StringValue*) getValueByKey(info, "RootFilesystemResize"))->value, "%d", &rootSize);
rootSize *= 1024 * 1024;
buffer = malloc(rootSize);
extractDmg(
createAbstractFileFromFileVault(getFileFromOutputState(&outputState, rootFSPathInIPSW), ((StringValue*)getValueByKey(info, "RootFilesystemKey"))->value),
createAbstractFileFromMemoryFile((void**)&buffer, &rootSize), -1);
rootFS = IOFuncFromAbstractFile(createAbstractFileFromMemoryFile((void**)&buffer, &rootSize));
rootVolume = openVolume(rootFS);
printf("Growing root: %d\n", rootSize); fflush(stdout);
grow_hfs(rootVolume, rootSize);
firmwarePatches = (Dictionary*)getValueByKey(info, "FilesystemPatches");
patchArray = (ArrayValue*) firmwarePatches->values;
while(patchArray != NULL) {
for(i = 0; i < patchArray->size; i++) {
patchDict = (Dictionary*) patchArray->values[i];
fileValue = (StringValue*) getValueByKey(patchDict, "File");
actionValue = (StringValue*) getValueByKey(patchDict, "Action");
if(strcmp(actionValue->value, "ReplaceKernel") == 0) {
pathValue = (StringValue*) getValueByKey(patchDict, "Path");
printf("replacing kernel... %s -> %s\n", fileValue->value, pathValue->value); fflush(stdout);
add_hfs(rootVolume, getFileFromOutputState(&outputState, fileValue->value), pathValue->value);
} if(strcmp(actionValue->value, "Patch") == 0) {
patchValue = (StringValue*) getValueByKey(patchDict, "Patch");
patchPath = malloc(sizeof(char) * (strlen(bundlePath) + strlen(patchValue->value) + 2));
strcpy(patchPath, bundlePath);
strcat(patchPath, "/");
strcat(patchPath, patchValue->value);
printf("patching %s (%s)... ", fileValue->value, patchPath);
doPatchInPlace(rootVolume, fileValue->value, patchPath);
free(patchPath);
}
}
patchArray = (ArrayValue*) patchArray->dValue.next;
}
for(mergePaths; mergePaths < argc; mergePaths++) {
addall_hfs(rootVolume, argv[mergePaths], "/");
}
if(doBootNeuter) {
ramdiskFS = IOFuncFromAbstractFile(openAbstractFile(getFileFromOutputState(&outputState, ramdiskFSPathInIPSW)));
ramdiskVolume = openVolume(ramdiskFS);
firmwarePatches = (Dictionary*)getValueByKey(info, "BasebandPatches");
if(firmwarePatches != NULL) {
patchDict = (Dictionary*) firmwarePatches->values;
while(patchDict != NULL) {
pathValue = (StringValue*) getValueByKey(patchDict, "Path");
fileValue = (StringValue*) getValueByKey(patchDict, "File");
if(fileValue) {
printf("copying %s -> %s... ", fileValue->value, pathValue->value); fflush(stdout);
if(copyAcrossVolumes(ramdiskVolume, rootVolume, fileValue->value, pathValue->value)) {
patchValue = (StringValue*) getValueByKey(patchDict, "Patch");
if(patchValue) {
patchPath = malloc(sizeof(char) * (strlen(bundlePath) + strlen(patchValue->value) + 2));
strcpy(patchPath, bundlePath);
strcat(patchPath, "/");
strcat(patchPath, patchValue->value);
printf("patching %s (%s)... ", pathValue->value, patchPath); fflush(stdout);
doPatchInPlace(rootVolume, pathValue->value, patchPath);
free(patchPath);
}
}
}
if(strcmp(patchDict->dValue.key, "Bootloader 3.9") == 0 && bootloader39 != NULL) {
add_hfs(rootVolume, bootloader39, pathValue->value);
}
if(strcmp(patchDict->dValue.key, "Bootloader 4.6") == 0 && bootloader46 != NULL) {
add_hfs(rootVolume, bootloader46, pathValue->value);
}
patchDict = (Dictionary*) patchDict->dValue.next;
}
}
closeVolume(ramdiskVolume);
CLOSE(ramdiskFS);
fixupBootNeuterArgs(rootVolume, unlockBaseband, selfDestruct, use39, use46);
}
closeVolume(rootVolume);
CLOSE(rootFS);
buildDmg(createAbstractFileFromMemoryFile((void**)&buffer, &rootSize), getFileFromOutputStateForOverwrite(&outputState, rootFSPathInIPSW));
free(buffer);
writeOutput(&outputState, outputIPSW);
releaseDictionary(info);
free(bundlePath);
return 0;
}
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include "common.h"
#include "nor_files.h"
#include "dmg.h"
#include "filevault.h"
#include "ibootim.h"
#include "plist.h"
#include "outputstate.h"
#include "hfslib.h"
#include "dmglib.h"
#include "pwnutil.h"
char endianness;
void TestByteOrder()
{
short int word = 0x0001;
char *byte = (char *) &word;
endianness = byte[0] ? IS_LITTLE_ENDIAN : IS_BIG_ENDIAN;
}
int doPatch(StringValue* patchValue, StringValue* fileValue, const char* bundlePath, OutputState** state) {
char* patchPath;
size_t bufferSize;
void* buffer;
AbstractFile* patchFile;
AbstractFile* file;
AbstractFile* out;
buffer = malloc(1);
patchPath = malloc(sizeof(char) * (strlen(bundlePath) + strlen(patchValue->value) + 2));
strcpy(patchPath, bundlePath);
strcat(patchPath, "/");
strcat(patchPath, patchValue->value);
printf("%s (%s)... ", fileValue->value, patchPath); fflush(stdout);
patchFile = createAbstractFileFromFile(fopen(patchPath, "rb"));
bufferSize = 0;
out = duplicateAbstractFile(getFileFromOutputState(state, fileValue->value), createAbstractFileFromMemoryFile((void**)&buffer, &bufferSize));
file = openAbstractFile(getFileFromOutputState(state, fileValue->value));
if(!patchFile || !file || !out) {
printf("file error\n");
exit(0);
}
if(patch(file, out, patchFile) != 0) {
printf("patch failed\n");
exit(0);
}
printf("writing... "); fflush(stdout);
/* out = createAbstractFileFromFile(fopen(filePath, "wb"));
out->write(out, buffer, bufferSize);
out->close(out);*/
addToOutput(state, fileValue->value, buffer, bufferSize);
printf("success\n"); fflush(stdout);
free(patchPath);
}
void doPatchInPlace(Volume* volume, char* filePath, char* patchPath) {
void* buffer;
void* buffer2;
size_t bufferSize;
size_t bufferSize2;
AbstractFile* bufferFile;
AbstractFile* patchFile;
AbstractFile* out;
buffer = malloc(1);
bufferSize = 0;
bufferFile = createAbstractFileFromMemoryFile((void**)&buffer, &bufferSize);
printf("retrieving..."); fflush(stdout);
get_hfs(volume, filePath, bufferFile);
printf("patching..."); fflush(stdout);
patchFile = createAbstractFileFromFile(fopen(patchPath, "rb"));
buffer2 = malloc(1);
bufferSize2 = 0;
out = duplicateAbstractFile(createAbstractFileFromMemoryFile((void**)&buffer, &bufferSize), createAbstractFileFromMemoryFile((void**)&buffer2, &bufferSize2));
if(!patchFile || !bufferFile || !out) {
printf("file error\n");
exit(0);
}
if(patch(bufferFile, out, patchFile) != 0) {
printf("patch failed\n");
exit(0);
}
printf("writing... "); fflush(stdout);
add_hfs(volume, createAbstractFileFromMemoryFile((void**)&buffer2, &bufferSize2), filePath);
free(buffer2);
free(buffer);
printf("success\n"); fflush(stdout);
}
void fixupBootNeuterArgs(Volume* volume, char unlockBaseband, char selfDestruct, char use39, char use46) {
char bootNeuterPlist[] = "/System/Library/LaunchDaemons/com.devteam.bootneuter.auto.plist";
AbstractFile* plistFile;
char* plist;
Dictionary* info;
size_t bufferSize;
ArrayValue* arguments;
printf("fixing up BootNeuter arguments...\n");
plist = malloc(1);
bufferSize = 0;
plistFile = createAbstractFileFromMemoryFile((void**)&plist, &bufferSize);
get_hfs(volume, bootNeuterPlist, plistFile);
plistFile->close(plistFile);
info = createRoot(plist);
free(plist);
arguments = (ArrayValue*) getValueByKey(info, "ProgramArguments");
addStringToArray(arguments, "-autoMode");
addStringToArray(arguments, "YES");
if(unlockBaseband) {
addStringToArray(arguments, "-unlockBaseband");
addStringToArray(arguments, "YES");
}
if(selfDestruct) {
addStringToArray(arguments, "-selfDestruct");
addStringToArray(arguments, "YES");
}
if(use39) {
addStringToArray(arguments, "-bootLoader");
addStringToArray(arguments, "3.9");
} else if(use46) {
addStringToArray(arguments, "-bootLoader");
addStringToArray(arguments, "4.6");
}
plist = getXmlFromRoot(info);
releaseDictionary(info);
plistFile = createAbstractFileFromMemory((void**)&plist, sizeof(char) * strlen(plist));
add_hfs(volume, plistFile, bootNeuterPlist);
free(plist);
}
int main(int argc, char* argv[]) {
TestByteOrder();
Dictionary* info;
Dictionary* firmwarePatches;
Dictionary* patchDict;
ArrayValue* patchArray;
void* buffer;
StringValue* actionValue;
StringValue* pathValue;
StringValue* fileValue;
StringValue* patchValue;
char* patchPath;
char* rootFSPathInIPSW;
io_func* rootFS;
Volume* rootVolume;
size_t rootSize;
char* ramdiskFSPathInIPSW;
io_func* ramdiskFS;
Volume* ramdiskVolume;
int i;
OutputState* outputState;
char* bundlePath;
char* bundleRoot = "FirmwareBundles/";
int mergePaths;
char* outputIPSW;
void* imageBuffer;
size_t imageSize;
FILE* temp;
AbstractFile* bootloader39;
AbstractFile* bootloader46;
AbstractFile* applelogo;
AbstractFile* recoverymode;
char unlockBaseband;
char selfDestruct;
char use39;
char use46;
char doBootNeuter;
char noBB;
applelogo = NULL;
recoverymode = NULL;
bootloader39 = NULL;
bootloader46 = NULL;
unlockBaseband = FALSE;
selfDestruct = FALSE;
use39 = FALSE;
use46 = FALSE;
doBootNeuter = FALSE;
noBB = FALSE;
if(argc < 3) {
printf("usage %s <input.ipsw> <target.ipsw> [-b <bootimage.png>] [-r <recoveryimage.png>] [-e \"<action to exclude>\"] [-nobbupdate] [[-unlock] [-use39] [-use46] [-cleanup] -3 <bootloader 3.9 file> -4 <bootloader 4.6 file>] <path/to/merge1> <path/to/merge2>...\n", argv[0]);
return 0;
}
outputIPSW = argv[2];
info = parseIPSW(argv[1], bundleRoot, &bundlePath, &outputState);
if(info == NULL) {
printf("error: Could not load IPSW\n");
exit(1);
}
firmwarePatches = (Dictionary*)getValueByKey(info, "FilesystemPatches");
for(i = 3; i < argc; i++) {
if(argv[i][0] != '-') {
break;
}
if(strcmp(argv[i], "-e") == 0) {
removeKey(firmwarePatches, argv[i + 1]);
i++;
continue;
}
if(strcmp(argv[i], "-unlock") == 0) {
unlockBaseband = TRUE;
continue;
}
if(strcmp(argv[i], "-cleanup") == 0) {
selfDestruct = TRUE;
continue;
}
if(strcmp(argv[i], "-nobbupdate") == 0) {
noBB = TRUE;
continue;
}
if(strcmp(argv[i], "-use39") == 0) {
if(use46) {
printf("error: select only one of -use39 and -use46\n");
exit(1);
}
use39 = TRUE;
continue;
}
if(strcmp(argv[i], "-use46") == 0) {
if(use39) {
printf("error: select only one of -use39 and -use46\n");
exit(1);
}
use46 = TRUE;
continue;
}
if(strcmp(argv[i], "-b") == 0) {
applelogo = createAbstractFileFromFile(fopen(argv[i + 1], "rb"));
if(!applelogo) {
printf("cannot open %s\n", argv[i + 1]);
exit(1);
}
i++;
continue;
}
if(strcmp(argv[i], "-r") == 0) {
recoverymode = createAbstractFileFromFile(fopen(argv[i + 1], "rb"));
if(!recoverymode) {
printf("cannot open %s\n", argv[i + 1]);
exit(1);
}
i++;
continue;
}
if(strcmp(argv[i], "-3") == 0) {
bootloader39 = createAbstractFileFromFile(fopen(argv[i + 1], "rb"));
if(!bootloader39) {
printf("cannot open %s\n", argv[i + 1]);
exit(1);
}
i++;
continue;
}
if(strcmp(argv[i], "-4") == 0) {
bootloader46 = createAbstractFileFromFile(fopen(argv[i + 1], "rb"));
if(!bootloader46) {
printf("cannot open %s\n", argv[i + 1]);
exit(1);
}
i++;
continue;
}
}
if(use39 || use46 || unlockBaseband || selfDestruct || bootloader39 || bootloader46) {
if(noBB) {
printf("error: bbupdate must be enabled for bootneuter\n");
exit(1);
} else {
if(!(bootloader39) || !(bootloader46)) {
printf("error: you must specify both bootloader files.\n");
exit(1);
} else {
doBootNeuter = TRUE;
}
}
}
mergePaths = i;
firmwarePatches = (Dictionary*)getValueByKey(info, "FirmwarePatches");
patchDict = (Dictionary*) firmwarePatches->values;
while(patchDict != NULL) {
fileValue = (StringValue*) getValueByKey(patchDict, "File");
if(strcmp(patchDict->dValue.key, "Restore Ramdisk") == 0) {
ramdiskFSPathInIPSW = fileValue->value;
}
patchValue = (StringValue*) getValueByKey(patchDict, "Patch2");
if(patchValue) {
if(!noBB) {
printf("%s: ", patchDict->dValue.key); fflush(stdout);
doPatch(patchValue, fileValue, bundlePath, &outputState);
patchDict = (Dictionary*) patchDict->dValue.next;
continue; /* skip over the normal Patch */
}
}
patchValue = (StringValue*) getValueByKey(patchDict, "Patch");
if(patchValue) {
printf("%s: ", patchDict->dValue.key); fflush(stdout);
doPatch(patchValue, fileValue, bundlePath, &outputState);
}
if(strcmp(patchDict->dValue.key, "AppleLogo") == 0 && applelogo) {
printf("replacing %s\n", fileValue->value); fflush(stdout);
ASSERT((imageBuffer = replaceBootImage(getFileFromOutputState(&outputState, fileValue->value), applelogo, &imageSize)) != NULL, "failed to use new image");
addToOutput(&outputState, fileValue->value, imageBuffer, imageSize);
}
if(strcmp(patchDict->dValue.key, "RecoveryMode") == 0 && recoverymode) {
printf("replacing %s\n", fileValue->value); fflush(stdout);
ASSERT((imageBuffer = replaceBootImage(getFileFromOutputState(&outputState, fileValue->value), recoverymode, &imageSize)) != NULL, "failed to use new image");
addToOutput(&outputState, fileValue->value, imageBuffer, imageSize);
}
patchDict = (Dictionary*) patchDict->dValue.next;
}
fileValue = (StringValue*) getValueByKey(info, "RootFilesystem");
rootFSPathInIPSW = fileValue->value;
sscanf(((StringValue*) getValueByKey(info, "RootFilesystemResize"))->value, "%d", &rootSize);
rootSize *= 1024 * 1024;
buffer = malloc(rootSize);
extractDmg(
createAbstractFileFromFileVault(getFileFromOutputState(&outputState, rootFSPathInIPSW), ((StringValue*)getValueByKey(info, "RootFilesystemKey"))->value),
createAbstractFileFromMemoryFile((void**)&buffer, &rootSize), -1);
rootFS = IOFuncFromAbstractFile(createAbstractFileFromMemoryFile((void**)&buffer, &rootSize));
rootVolume = openVolume(rootFS);
printf("Growing root: %d\n", rootSize); fflush(stdout);
grow_hfs(rootVolume, rootSize);
firmwarePatches = (Dictionary*)getValueByKey(info, "FilesystemPatches");
patchArray = (ArrayValue*) firmwarePatches->values;
while(patchArray != NULL) {
for(i = 0; i < patchArray->size; i++) {
patchDict = (Dictionary*) patchArray->values[i];
fileValue = (StringValue*) getValueByKey(patchDict, "File");
actionValue = (StringValue*) getValueByKey(patchDict, "Action");
if(strcmp(actionValue->value, "ReplaceKernel") == 0) {
pathValue = (StringValue*) getValueByKey(patchDict, "Path");
printf("replacing kernel... %s -> %s\n", fileValue->value, pathValue->value); fflush(stdout);
add_hfs(rootVolume, getFileFromOutputState(&outputState, fileValue->value), pathValue->value);
} if(strcmp(actionValue->value, "Patch") == 0) {
patchValue = (StringValue*) getValueByKey(patchDict, "Patch");
patchPath = malloc(sizeof(char) * (strlen(bundlePath) + strlen(patchValue->value) + 2));
strcpy(patchPath, bundlePath);
strcat(patchPath, "/");
strcat(patchPath, patchValue->value);
printf("patching %s (%s)... ", fileValue->value, patchPath);
doPatchInPlace(rootVolume, fileValue->value, patchPath);
free(patchPath);
}
}
patchArray = (ArrayValue*) patchArray->dValue.next;
}
for(mergePaths; mergePaths < argc; mergePaths++) {
addall_hfs(rootVolume, argv[mergePaths], "/");
}
if(doBootNeuter) {
ramdiskFS = IOFuncFromAbstractFile(openAbstractFile(getFileFromOutputState(&outputState, ramdiskFSPathInIPSW)));
ramdiskVolume = openVolume(ramdiskFS);
firmwarePatches = (Dictionary*)getValueByKey(info, "BasebandPatches");
if(firmwarePatches != NULL) {
patchDict = (Dictionary*) firmwarePatches->values;
while(patchDict != NULL) {
pathValue = (StringValue*) getValueByKey(patchDict, "Path");
fileValue = (StringValue*) getValueByKey(patchDict, "File");
if(fileValue) {
printf("copying %s -> %s... ", fileValue->value, pathValue->value); fflush(stdout);
if(copyAcrossVolumes(ramdiskVolume, rootVolume, fileValue->value, pathValue->value)) {
patchValue = (StringValue*) getValueByKey(patchDict, "Patch");
if(patchValue) {
patchPath = malloc(sizeof(char) * (strlen(bundlePath) + strlen(patchValue->value) + 2));
strcpy(patchPath, bundlePath);
strcat(patchPath, "/");
strcat(patchPath, patchValue->value);
printf("patching %s (%s)... ", pathValue->value, patchPath); fflush(stdout);
doPatchInPlace(rootVolume, pathValue->value, patchPath);
free(patchPath);
}
}
}
if(strcmp(patchDict->dValue.key, "Bootloader 3.9") == 0 && bootloader39 != NULL) {
add_hfs(rootVolume, bootloader39, pathValue->value);
}
if(strcmp(patchDict->dValue.key, "Bootloader 4.6") == 0 && bootloader46 != NULL) {
add_hfs(rootVolume, bootloader46, pathValue->value);
}
patchDict = (Dictionary*) patchDict->dValue.next;
}
}
closeVolume(ramdiskVolume);
CLOSE(ramdiskFS);
fixupBootNeuterArgs(rootVolume, unlockBaseband, selfDestruct, use39, use46);
}
closeVolume(rootVolume);
CLOSE(rootFS);
buildDmg(createAbstractFileFromMemoryFile((void**)&buffer, &rootSize), getFileFromOutputStateForOverwrite(&outputState, rootFSPathInIPSW));
free(buffer);
writeOutput(&outputState, outputIPSW);
releaseDictionary(info);
free(bundlePath);
return 0;
}

Просмотреть файл

@ -2,499 +2,499 @@
#include <string.h>
#include "plist.h"
#include "common.h"
Tag* getNextTag(char** xmlPtr) {
char* xml;
char* tagEnd;
char* curChar;
Tag* tag;
int tagDepth;
xml = *xmlPtr;
xml = strchr(xml, '<');
if(xml == NULL) {
return NULL;
}
tag = (Tag*) malloc(sizeof(Tag));
tagEnd = strchr(xml, '>');
tag->name = (char*) malloc(sizeof(char) * (tagEnd - xml));
memcpy(tag->name, xml + 1, tagEnd - xml - 1);
tag->name[tagEnd - xml - 1] = '\0';
if((tagEnd - xml - 1) > 0) {
if(tag->name[tagEnd - xml - 2] == '/') {
tag->xml = malloc(sizeof(char) * 1);
tag->xml[0] = '\0';
*xmlPtr = tagEnd + 1;
return tag;
}
}
xml = tagEnd;
curChar = xml;
tagDepth = 1;
while(*curChar != '\0') {
if(*curChar == '<') {
if(*(curChar + 1) == '/') {
tagDepth--;
if(tagDepth == 0) {
break;
}
} else {
tagDepth++;
}
} else if(*curChar == '>') {
if(*(curChar - 1) == '/') {
tagDepth--;
}
}
curChar++;
}
tag->xml = (char*) malloc(sizeof(char) * (curChar - xml));
memcpy(tag->xml, xml + 1, curChar - xml - 1);
tag->xml[curChar - xml - 1] = '\0';
*xmlPtr = strchr(curChar, '>') + 1;
return tag;
}
void releaseTag(Tag* tag) {
free(tag->name);
free(tag->xml);
free(tag);
}
void releaseArray(ArrayValue* myself) {
int i;
free(myself->dValue.key);
for(i = 0; i < myself->size; i++) {
switch(myself->values[i]->type) {
case DictionaryType:
releaseDictionary((Dictionary*) myself->values[i]);
break;
case ArrayType:
releaseArray((ArrayValue*) myself->values[i]);
break;
case StringType:
free(((StringValue*)(myself->values[i]))->value);
case BoolType:
case IntegerType:
free(myself->values[i]->key);
free(myself->values[i]);
break;
}
}
free(myself->values);
free(myself);
}
void releaseDictionary(Dictionary* myself) {
DictValue* next;
DictValue* toRelease;
free(myself->dValue.key);
next = myself->values;
while(next != NULL) {
toRelease = next;
next = next->next;
switch(toRelease->type) {
case DictionaryType:
releaseDictionary((Dictionary*) toRelease);
break;
case ArrayType:
releaseArray((ArrayValue*) toRelease);
break;
case StringType:
free(((StringValue*)(toRelease))->value);
case IntegerType:
case BoolType:
free(toRelease->key);
free(toRelease);
break;
}
}
free(myself);
}
void createArray(ArrayValue* myself, char* xml) {
Tag* valueTag;
DictValue* curValue;
int i;
myself->values = NULL;
myself->size = 0;
while(*xml != '\0') {
valueTag = getNextTag(&xml);
if(valueTag == NULL) {
break;
}
myself->size++;
myself->values = realloc(myself->values, sizeof(DictValue*) * myself->size);
curValue = (DictValue*) malloc(sizeof(DictValue));
curValue->key = (char*) malloc(sizeof("arraykey"));
strcpy(curValue->key, "arraykey");
curValue->next = NULL;
if(strcmp(valueTag->name, "dict") == 0) {
curValue->type = DictionaryType;
curValue = (DictValue*) realloc(curValue, sizeof(Dictionary));
createDictionary((Dictionary*) curValue, valueTag->xml);
} else if(strcmp(valueTag->name, "string") == 0) {
curValue->type = StringType;
curValue = (DictValue*) realloc(curValue, sizeof(StringValue));
((StringValue*)curValue)->value = (char*) malloc(sizeof(char) * (strlen(valueTag->xml) + 1));
strcpy(((StringValue*)curValue)->value, valueTag->xml);
} else if(strcmp(valueTag->name, "integer") == 0) {
curValue->type = IntegerType;
curValue = (DictValue*) realloc(curValue, sizeof(IntegerValue));
sscanf(valueTag->xml, "%d", &(((IntegerValue*)curValue)->value));
} else if(strcmp(valueTag->name, "array") == 0) {
curValue->type = ArrayType;
curValue = (DictValue*) realloc(curValue, sizeof(ArrayValue));
createArray((ArrayValue*) curValue, valueTag->xml);
} else if(strcmp(valueTag->name, "true/") == 0) {
curValue->type = BoolType;
curValue = (DictValue*) realloc(curValue, sizeof(BoolValue));
((BoolValue*)curValue)->value = TRUE;
} else if(strcmp(valueTag->name, "false/") == 0) {
curValue->type = BoolType;
curValue = (DictValue*) realloc(curValue, sizeof(BoolValue));
((BoolValue*)curValue)->value = FALSE;
}
myself->values[myself->size - 1] = curValue;
releaseTag(valueTag);
}
}
void removeKey(Dictionary* dict, char* key) {
DictValue* next;
DictValue* toRelease;
next = dict->values;
while(next != NULL) {
if(strcmp(next->key, key) == 0) {
toRelease = next;
if(toRelease->prev) {
toRelease->prev->next = toRelease->next;
} else {
dict->values = toRelease->next;
}
if(toRelease->next) {
toRelease->next->prev = toRelease->prev;
}
switch(toRelease->type) {
case DictionaryType:
releaseDictionary((Dictionary*) toRelease);
break;
case ArrayType:
releaseArray((ArrayValue*) toRelease);
break;
case StringType:
free(((StringValue*)(toRelease))->value);
case IntegerType:
case BoolType:
free(toRelease->key);
free(toRelease);
break;
}
return;
}
next = next->next;
}
return;
}
void createDictionary(Dictionary* myself, char* xml) {
Tag* keyTag;
Tag* valueTag;
DictValue* curValue;
DictValue* lastValue;
curValue = NULL;
lastValue = NULL;
while(*xml != '\0') {
keyTag = getNextTag(&xml);
if(keyTag == NULL) {
break;
}
if(strcmp(keyTag->name, "key") != 0) {
releaseTag(keyTag);
continue;
}
curValue = (DictValue*) malloc(sizeof(DictValue));
curValue->key = (char*) malloc(sizeof(char) * (strlen(keyTag->xml) + 1));
strcpy(curValue->key, keyTag->xml);
curValue->next = NULL;
releaseTag(keyTag);
valueTag = getNextTag(&xml);
if(valueTag == NULL) {
break;
}
if(strcmp(valueTag->name, "dict") == 0) {
curValue->type = DictionaryType;
curValue = (DictValue*) realloc(curValue, sizeof(Dictionary));
createDictionary((Dictionary*) curValue, valueTag->xml);
} else if(strcmp(valueTag->name, "string") == 0) {
curValue->type = StringType;
curValue = (DictValue*) realloc(curValue, sizeof(StringValue));
((StringValue*)curValue)->value = (char*) malloc(sizeof(char) * (strlen(valueTag->xml) + 1));
strcpy(((StringValue*)curValue)->value, valueTag->xml);
} else if(strcmp(valueTag->name, "integer") == 0) {
curValue->type = IntegerType;
curValue = (DictValue*) realloc(curValue, sizeof(IntegerValue));
sscanf(valueTag->xml, "%d", &(((IntegerValue*)curValue)->value));
} else if(strcmp(valueTag->name, "array") == 0) {
curValue->type = ArrayType;
curValue = (DictValue*) realloc(curValue, sizeof(ArrayValue));
createArray((ArrayValue*) curValue, valueTag->xml);
} else if(strcmp(valueTag->name, "true/") == 0) {
curValue->type = BoolType;
curValue = (DictValue*) realloc(curValue, sizeof(BoolValue));
((BoolValue*)curValue)->value = TRUE;
} else if(strcmp(valueTag->name, "false/") == 0) {
curValue->type = BoolType;
curValue = (DictValue*) realloc(curValue, sizeof(BoolValue));
((BoolValue*)curValue)->value = FALSE;
}
curValue->prev = lastValue;
if(lastValue == NULL) {
myself->values = curValue;
} else {
lastValue->next = curValue;
}
lastValue = curValue;
releaseTag(valueTag);
}
}
char* getXmlFromArrayValue(ArrayValue* myself, int tabsCount) {
char tabs[100];
char buffer[4096];
char* toReturn;
char* ret;
size_t toReturnSize;
int i;
DictValue* curValue;
tabs[0] = '\0';
for(i = 0; i < tabsCount; i++) {
strcat(tabs, "\t");
}
sprintf(buffer, "%s<array>\n", tabs);
toReturnSize = sizeof(char) * (strlen(buffer) + 1);
toReturn = malloc(toReturnSize);
toReturn = strcpy(toReturn, buffer);
for(i = 0; i < myself->size; i++) {
curValue = myself->values[i];
if(curValue->type == DictionaryType) {
ret = getXmlFromDictionary((Dictionary*)curValue, tabsCount + 1);
toReturnSize += sizeof(char) * (strlen(ret) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, ret);
free(ret);
} else if(curValue->type == StringType) {
sprintf(buffer, "%s\t<string>%s</string>\n", tabs, ((StringValue*)curValue)->value);
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
} else if(curValue->type == IntegerType) {
sprintf(buffer, "%s\t<string>%d</string>\n", tabs, ((IntegerValue*)curValue)->value);
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
} else if(curValue->type == ArrayType) {
ret = getXmlFromArrayValue((ArrayValue*)curValue, tabsCount + 1);
toReturnSize += sizeof(char) * (strlen(ret) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, ret);
free(ret);
} else if(curValue->type == BoolType) {
if(((BoolValue*)curValue)->value) {
sprintf(buffer, "%s\t<true/>\n", tabs);
} else {
sprintf(buffer, "%s\t<false/>\n", tabs);
}
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
}
}
sprintf(buffer, "%s</array>\n", tabs);
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
return toReturn;
}
char* getXmlFromDictionary(Dictionary* myself, int tabsCount) {
char tabs[100];
char buffer[4096];
char* toReturn;
char* ret;
size_t toReturnSize;
int i;
DictValue* curValue;
tabs[0] = '\0';
for(i = 0; i < tabsCount; i++) {
strcat(tabs, "\t");
}
sprintf(buffer, "%s<dict>\n", tabs);
toReturnSize = sizeof(char) * (strlen(buffer) + 1);
toReturn = malloc(toReturnSize);
toReturn = strcpy(toReturn, buffer);
curValue = myself->values;
while(curValue != NULL) {
sprintf(buffer, "%s\t<key>%s</key>\n", tabs, curValue->key);
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
if(curValue->type == DictionaryType) {
ret = getXmlFromDictionary((Dictionary*)curValue, tabsCount + 1);
toReturnSize += sizeof(char) * (strlen(ret) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, ret);
free(ret);
} else if(curValue->type == StringType) {
sprintf(buffer, "%s\t<string>%s</string>\n", tabs, ((StringValue*)curValue)->value);
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
} else if(curValue->type == IntegerType) {
sprintf(buffer, "%s\t<string>%d</string>\n", tabs, ((IntegerValue*)curValue)->value);
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
} else if(curValue->type == ArrayType) {
ret = getXmlFromArrayValue((ArrayValue*)curValue, tabsCount + 1);
toReturnSize += sizeof(char) * (strlen(ret) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, ret);
free(ret);
} else if(curValue->type == BoolType) {
if(((BoolValue*)curValue)->value) {
sprintf(buffer, "%s\t<true/>\n", tabs);
} else {
sprintf(buffer, "%s\t<false/>\n", tabs);
}
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
}
curValue = curValue->next;
}
sprintf(buffer, "%s</dict>\n", tabs);
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
return toReturn;
}
Dictionary* createRoot(char* xml) {
Tag* tag;
Dictionary* dict;
xml = strstr(xml, "<dict>");
tag = getNextTag(&xml);
dict = malloc(sizeof(Dictionary));
dict->dValue.next = NULL;
dict->dValue.key = malloc(sizeof("root"));
strcpy(dict->dValue.key, "root");
createDictionary(dict, tag->xml);
releaseTag(tag);
return dict;
}
char* getXmlFromRoot(Dictionary* root) {
char buffer[4096];
char* toReturn;
char* ret;
size_t toReturnSize;
sprintf(buffer, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n");
toReturnSize = sizeof(char) * (strlen(buffer) + 1);
toReturn = malloc(toReturnSize);
toReturn = strcpy(toReturn, buffer);
ret = getXmlFromDictionary(root, 0);
toReturnSize += sizeof(char) * (strlen(ret) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, ret);
free(ret);
sprintf(buffer, "</plist>\n");
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
return toReturn;
}
DictValue* getValueByKey(Dictionary* myself, const char* key) {
Tag* getNextTag(char** xmlPtr) {
char* xml;
char* tagEnd;
char* curChar;
Tag* tag;
int tagDepth;
xml = *xmlPtr;
xml = strchr(xml, '<');
if(xml == NULL) {
return NULL;
}
tag = (Tag*) malloc(sizeof(Tag));
tagEnd = strchr(xml, '>');
tag->name = (char*) malloc(sizeof(char) * (tagEnd - xml));
memcpy(tag->name, xml + 1, tagEnd - xml - 1);
tag->name[tagEnd - xml - 1] = '\0';
if((tagEnd - xml - 1) > 0) {
if(tag->name[tagEnd - xml - 2] == '/') {
tag->xml = malloc(sizeof(char) * 1);
tag->xml[0] = '\0';
*xmlPtr = tagEnd + 1;
return tag;
}
}
xml = tagEnd;
curChar = xml;
tagDepth = 1;
while(*curChar != '\0') {
if(*curChar == '<') {
if(*(curChar + 1) == '/') {
tagDepth--;
if(tagDepth == 0) {
break;
}
} else {
tagDepth++;
}
} else if(*curChar == '>') {
if(*(curChar - 1) == '/') {
tagDepth--;
}
}
curChar++;
}
tag->xml = (char*) malloc(sizeof(char) * (curChar - xml));
memcpy(tag->xml, xml + 1, curChar - xml - 1);
tag->xml[curChar - xml - 1] = '\0';
*xmlPtr = strchr(curChar, '>') + 1;
return tag;
}
void releaseTag(Tag* tag) {
free(tag->name);
free(tag->xml);
free(tag);
}
void releaseArray(ArrayValue* myself) {
int i;
free(myself->dValue.key);
for(i = 0; i < myself->size; i++) {
switch(myself->values[i]->type) {
case DictionaryType:
releaseDictionary((Dictionary*) myself->values[i]);
break;
case ArrayType:
releaseArray((ArrayValue*) myself->values[i]);
break;
case StringType:
free(((StringValue*)(myself->values[i]))->value);
case BoolType:
case IntegerType:
free(myself->values[i]->key);
free(myself->values[i]);
break;
}
}
free(myself->values);
free(myself);
}
void releaseDictionary(Dictionary* myself) {
DictValue* next;
DictValue* toRelease;
free(myself->dValue.key);
next = myself->values;
while(next != NULL) {
toRelease = next;
next = next->next;
switch(toRelease->type) {
case DictionaryType:
releaseDictionary((Dictionary*) toRelease);
break;
case ArrayType:
releaseArray((ArrayValue*) toRelease);
break;
case StringType:
free(((StringValue*)(toRelease))->value);
case IntegerType:
case BoolType:
free(toRelease->key);
free(toRelease);
break;
}
}
free(myself);
}
void createArray(ArrayValue* myself, char* xml) {
Tag* valueTag;
DictValue* curValue;
int i;
myself->values = NULL;
myself->size = 0;
while(*xml != '\0') {
valueTag = getNextTag(&xml);
if(valueTag == NULL) {
break;
}
myself->size++;
myself->values = realloc(myself->values, sizeof(DictValue*) * myself->size);
curValue = (DictValue*) malloc(sizeof(DictValue));
curValue->key = (char*) malloc(sizeof("arraykey"));
strcpy(curValue->key, "arraykey");
curValue->next = NULL;
if(strcmp(valueTag->name, "dict") == 0) {
curValue->type = DictionaryType;
curValue = (DictValue*) realloc(curValue, sizeof(Dictionary));
createDictionary((Dictionary*) curValue, valueTag->xml);
} else if(strcmp(valueTag->name, "string") == 0) {
curValue->type = StringType;
curValue = (DictValue*) realloc(curValue, sizeof(StringValue));
((StringValue*)curValue)->value = (char*) malloc(sizeof(char) * (strlen(valueTag->xml) + 1));
strcpy(((StringValue*)curValue)->value, valueTag->xml);
} else if(strcmp(valueTag->name, "integer") == 0) {
curValue->type = IntegerType;
curValue = (DictValue*) realloc(curValue, sizeof(IntegerValue));
sscanf(valueTag->xml, "%d", &(((IntegerValue*)curValue)->value));
} else if(strcmp(valueTag->name, "array") == 0) {
curValue->type = ArrayType;
curValue = (DictValue*) realloc(curValue, sizeof(ArrayValue));
createArray((ArrayValue*) curValue, valueTag->xml);
} else if(strcmp(valueTag->name, "true/") == 0) {
curValue->type = BoolType;
curValue = (DictValue*) realloc(curValue, sizeof(BoolValue));
((BoolValue*)curValue)->value = TRUE;
} else if(strcmp(valueTag->name, "false/") == 0) {
curValue->type = BoolType;
curValue = (DictValue*) realloc(curValue, sizeof(BoolValue));
((BoolValue*)curValue)->value = FALSE;
}
myself->values[myself->size - 1] = curValue;
releaseTag(valueTag);
}
}
void removeKey(Dictionary* dict, char* key) {
DictValue* next;
DictValue* toRelease;
next = dict->values;
while(next != NULL) {
if(strcmp(next->key, key) == 0) {
toRelease = next;
if(toRelease->prev) {
toRelease->prev->next = toRelease->next;
} else {
dict->values = toRelease->next;
}
if(toRelease->next) {
toRelease->next->prev = toRelease->prev;
}
switch(toRelease->type) {
case DictionaryType:
releaseDictionary((Dictionary*) toRelease);
break;
case ArrayType:
releaseArray((ArrayValue*) toRelease);
break;
case StringType:
free(((StringValue*)(toRelease))->value);
case IntegerType:
case BoolType:
free(toRelease->key);
free(toRelease);
break;
}
return;
}
next = next->next;
}
return;
}
void createDictionary(Dictionary* myself, char* xml) {
Tag* keyTag;
Tag* valueTag;
DictValue* curValue;
DictValue* lastValue;
curValue = NULL;
lastValue = NULL;
while(*xml != '\0') {
keyTag = getNextTag(&xml);
if(keyTag == NULL) {
break;
}
if(strcmp(keyTag->name, "key") != 0) {
releaseTag(keyTag);
continue;
}
curValue = (DictValue*) malloc(sizeof(DictValue));
curValue->key = (char*) malloc(sizeof(char) * (strlen(keyTag->xml) + 1));
strcpy(curValue->key, keyTag->xml);
curValue->next = NULL;
releaseTag(keyTag);
valueTag = getNextTag(&xml);
if(valueTag == NULL) {
break;
}
if(strcmp(valueTag->name, "dict") == 0) {
curValue->type = DictionaryType;
curValue = (DictValue*) realloc(curValue, sizeof(Dictionary));
createDictionary((Dictionary*) curValue, valueTag->xml);
} else if(strcmp(valueTag->name, "string") == 0) {
curValue->type = StringType;
curValue = (DictValue*) realloc(curValue, sizeof(StringValue));
((StringValue*)curValue)->value = (char*) malloc(sizeof(char) * (strlen(valueTag->xml) + 1));
strcpy(((StringValue*)curValue)->value, valueTag->xml);
} else if(strcmp(valueTag->name, "integer") == 0) {
curValue->type = IntegerType;
curValue = (DictValue*) realloc(curValue, sizeof(IntegerValue));
sscanf(valueTag->xml, "%d", &(((IntegerValue*)curValue)->value));
} else if(strcmp(valueTag->name, "array") == 0) {
curValue->type = ArrayType;
curValue = (DictValue*) realloc(curValue, sizeof(ArrayValue));
createArray((ArrayValue*) curValue, valueTag->xml);
} else if(strcmp(valueTag->name, "true/") == 0) {
curValue->type = BoolType;
curValue = (DictValue*) realloc(curValue, sizeof(BoolValue));
((BoolValue*)curValue)->value = TRUE;
} else if(strcmp(valueTag->name, "false/") == 0) {
curValue->type = BoolType;
curValue = (DictValue*) realloc(curValue, sizeof(BoolValue));
((BoolValue*)curValue)->value = FALSE;
}
curValue->prev = lastValue;
if(lastValue == NULL) {
myself->values = curValue;
} else {
lastValue->next = curValue;
}
lastValue = curValue;
releaseTag(valueTag);
}
}
char* getXmlFromArrayValue(ArrayValue* myself, int tabsCount) {
char tabs[100];
char buffer[4096];
char* toReturn;
char* ret;
size_t toReturnSize;
int i;
DictValue* curValue;
tabs[0] = '\0';
for(i = 0; i < tabsCount; i++) {
strcat(tabs, "\t");
}
sprintf(buffer, "%s<array>\n", tabs);
toReturnSize = sizeof(char) * (strlen(buffer) + 1);
toReturn = malloc(toReturnSize);
toReturn = strcpy(toReturn, buffer);
for(i = 0; i < myself->size; i++) {
curValue = myself->values[i];
if(curValue->type == DictionaryType) {
ret = getXmlFromDictionary((Dictionary*)curValue, tabsCount + 1);
toReturnSize += sizeof(char) * (strlen(ret) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, ret);
free(ret);
} else if(curValue->type == StringType) {
sprintf(buffer, "%s\t<string>%s</string>\n", tabs, ((StringValue*)curValue)->value);
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
} else if(curValue->type == IntegerType) {
sprintf(buffer, "%s\t<string>%d</string>\n", tabs, ((IntegerValue*)curValue)->value);
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
} else if(curValue->type == ArrayType) {
ret = getXmlFromArrayValue((ArrayValue*)curValue, tabsCount + 1);
toReturnSize += sizeof(char) * (strlen(ret) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, ret);
free(ret);
} else if(curValue->type == BoolType) {
if(((BoolValue*)curValue)->value) {
sprintf(buffer, "%s\t<true/>\n", tabs);
} else {
sprintf(buffer, "%s\t<false/>\n", tabs);
}
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
}
}
sprintf(buffer, "%s</array>\n", tabs);
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
return toReturn;
}
char* getXmlFromDictionary(Dictionary* myself, int tabsCount) {
char tabs[100];
char buffer[4096];
char* toReturn;
char* ret;
size_t toReturnSize;
int i;
DictValue* curValue;
tabs[0] = '\0';
for(i = 0; i < tabsCount; i++) {
strcat(tabs, "\t");
}
sprintf(buffer, "%s<dict>\n", tabs);
toReturnSize = sizeof(char) * (strlen(buffer) + 1);
toReturn = malloc(toReturnSize);
toReturn = strcpy(toReturn, buffer);
curValue = myself->values;
while(curValue != NULL) {
sprintf(buffer, "%s\t<key>%s</key>\n", tabs, curValue->key);
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
if(curValue->type == DictionaryType) {
ret = getXmlFromDictionary((Dictionary*)curValue, tabsCount + 1);
toReturnSize += sizeof(char) * (strlen(ret) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, ret);
free(ret);
} else if(curValue->type == StringType) {
sprintf(buffer, "%s\t<string>%s</string>\n", tabs, ((StringValue*)curValue)->value);
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
} else if(curValue->type == IntegerType) {
sprintf(buffer, "%s\t<string>%d</string>\n", tabs, ((IntegerValue*)curValue)->value);
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
} else if(curValue->type == ArrayType) {
ret = getXmlFromArrayValue((ArrayValue*)curValue, tabsCount + 1);
toReturnSize += sizeof(char) * (strlen(ret) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, ret);
free(ret);
} else if(curValue->type == BoolType) {
if(((BoolValue*)curValue)->value) {
sprintf(buffer, "%s\t<true/>\n", tabs);
} else {
sprintf(buffer, "%s\t<false/>\n", tabs);
}
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
}
curValue = curValue->next;
}
sprintf(buffer, "%s</dict>\n", tabs);
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
return toReturn;
}
Dictionary* createRoot(char* xml) {
Tag* tag;
Dictionary* dict;
xml = strstr(xml, "<dict>");
tag = getNextTag(&xml);
dict = malloc(sizeof(Dictionary));
dict->dValue.next = NULL;
dict->dValue.key = malloc(sizeof("root"));
strcpy(dict->dValue.key, "root");
createDictionary(dict, tag->xml);
releaseTag(tag);
return dict;
}
char* getXmlFromRoot(Dictionary* root) {
char buffer[4096];
char* toReturn;
char* ret;
size_t toReturnSize;
sprintf(buffer, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n");
toReturnSize = sizeof(char) * (strlen(buffer) + 1);
toReturn = malloc(toReturnSize);
toReturn = strcpy(toReturn, buffer);
ret = getXmlFromDictionary(root, 0);
toReturnSize += sizeof(char) * (strlen(ret) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, ret);
free(ret);
sprintf(buffer, "</plist>\n");
toReturnSize += sizeof(char) * (strlen(buffer) + 1);
toReturn = realloc(toReturn, toReturnSize);
toReturn = strcat(toReturn, buffer);
return toReturn;
}
DictValue* getValueByKey(Dictionary* myself, const char* key) {
DictValue* next;
if(myself == NULL) {
return NULL;
}
next = myself->values;
while(next != NULL) {
if(strcmp(next->key, key) == 0)
return next;
next = next->next;
}
return NULL;
}
void addStringToArray(ArrayValue* array, char* str) {
DictValue* curValue;
array->size++;
array->values = realloc(array->values, sizeof(DictValue*) * array->size);
curValue = (DictValue*) malloc(sizeof(StringValue));
curValue->key = (char*) malloc(sizeof("arraykey"));
strcpy(curValue->key, "arraykey");
curValue->next = NULL;
curValue->prev = NULL;
curValue->type = StringType;
curValue = (DictValue*) realloc(curValue, sizeof(StringValue));
((StringValue*)curValue)->value = (char*) malloc(sizeof(char) * (strlen(str) + 1));
strcpy(((StringValue*)curValue)->value, str);
array->values[array->size - 1] = curValue;
}
next = myself->values;
while(next != NULL) {
if(strcmp(next->key, key) == 0)
return next;
next = next->next;
}
return NULL;
}
void addStringToArray(ArrayValue* array, char* str) {
DictValue* curValue;
array->size++;
array->values = realloc(array->values, sizeof(DictValue*) * array->size);
curValue = (DictValue*) malloc(sizeof(StringValue));
curValue->key = (char*) malloc(sizeof("arraykey"));
strcpy(curValue->key, "arraykey");
curValue->next = NULL;
curValue->prev = NULL;
curValue->type = StringType;
curValue = (DictValue*) realloc(curValue, sizeof(StringValue));
((StringValue*)curValue)->value = (char*) malloc(sizeof(char) * (strlen(str) + 1));
strcpy(((StringValue*)curValue)->value, str);
array->values[array->size - 1] = curValue;
}

Просмотреть файл

@ -1,62 +1,62 @@
#ifndef PLIST_H
#define PLIST_H
enum DictTypes {
DictionaryType = 1,
ArrayType,
StringType,
IntegerType,
BoolType
};
typedef struct DictValue {
int type;
char* key;
struct DictValue* next;
struct DictValue* prev;
} DictValue;
typedef struct StringValue {
DictValue dValue;
char* value;
} StringValue;
typedef struct IntegerValue {
DictValue dValue;
int value;
} IntegerValue;
typedef struct BoolValue {
DictValue dValue;
char value;
} BoolValue;
typedef struct ArrayValue {
DictValue dValue;
int size;
DictValue** values;
} ArrayValue;
typedef struct Dictionary {
DictValue dValue;
DictValue* values;
} Dictionary;
typedef struct Tag {
char* name;
char* xml;
} Tag;
enum DictTypes {
DictionaryType = 1,
ArrayType,
StringType,
IntegerType,
BoolType
};
typedef struct DictValue {
int type;
char* key;
struct DictValue* next;
struct DictValue* prev;
} DictValue;
typedef struct StringValue {
DictValue dValue;
char* value;
} StringValue;
typedef struct IntegerValue {
DictValue dValue;
int value;
} IntegerValue;
typedef struct BoolValue {
DictValue dValue;
char value;
} BoolValue;
typedef struct ArrayValue {
DictValue dValue;
int size;
DictValue** values;
} ArrayValue;
typedef struct Dictionary {
DictValue dValue;
DictValue* values;
} Dictionary;
typedef struct Tag {
char* name;
char* xml;
} Tag;
#ifdef __cplusplus
extern "C" {
#endif
void createArray(ArrayValue* myself, char* xml);
void createDictionary(Dictionary* myself, char* xml);
void releaseArray(ArrayValue* myself);
void releaseDictionary(Dictionary* myself);
char* getXmlFromArrayValue(ArrayValue* myself, int tabsCount);
void createArray(ArrayValue* myself, char* xml);
void createDictionary(Dictionary* myself, char* xml);
void releaseArray(ArrayValue* myself);
void releaseDictionary(Dictionary* myself);
char* getXmlFromArrayValue(ArrayValue* myself, int tabsCount);
char* getXmlFromDictionary(Dictionary* myself, int tabsCount);
Dictionary* createRoot(char* xml);
Dictionary* createRoot(char* xml);
char* getXmlFromRoot(Dictionary* root);
char* getXmlFromRoot(Dictionary* root);
DictValue* getValueByKey(Dictionary* myself, const char* key);

Просмотреть файл

@ -1,9 +1,9 @@
#include <stdlib.h>
#ifdef WIN32
blahfs-o_f-0-(){ {}A
#else
int main(int argc, char* argv[]) {
return 0;
}
#endif
#include <stdlib.h>
#ifdef WIN32
blahfs-o_f-0-(){ {}A
#else
int main(int argc, char* argv[]) {
return 0;
}
#endif

Просмотреть файл

@ -6,7 +6,7 @@ CFLAGS=-O3
LIBUSB=`if $(CC) ../win32test.c -o /dev/null 2>/dev/null ; then echo "../libusb-0.1.12/.libs/libusb.a"; else echo "../libusb-win32/libusb.a"; fi`
LIBUSBH=`if $(CC) win32test.c -o /dev/null 2>/dev/null ; then echo "-I./libusb-0.1.12/"; else echo "-I./libusb-win32/src/"; fi`
INC=-I./include/ $(LIBUSBH)
INC=-I./include/ $(LIBUSBH) -I../hfs -I../dmg
SRCDIR=src
OBJDIR=build

Просмотреть файл

@ -1,263 +1,263 @@
# LIBUSB-WIN32, Generic Windows USB Library
# Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# If you're cross-compiling and your mingw32 tools are called
# i586-mingw32msvc-gcc and so on, then you can compile libusb-win32
# by running
# make host_prefix=i586-mingw32msvc all
ifdef host_prefix
override host_prefix := $(host_prefix)-
endif
CC = $(host_prefix)gcc
LD = $(host_prefix)ld
WINDRES = $(host_prefix)windres
DLLTOOL = $(host_prefix)dlltool
MAKE = make
CP = cp
CD = cd
MV = mv
RM = -rm -fr
TAR = tar
ISCC = iscc
INSTALL = install
LIB = lib
IMPLIB = implib
UNIX2DOS = unix2dos
VERSION_MAJOR = 0
VERSION_MINOR = 1
VERSION_MICRO = 12
VERSION_NANO = 1
VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_MICRO).$(VERSION_NANO)
RC_VERSION = $(VERSION_MAJOR),$(VERSION_MINOR),$(VERSION_MICRO),$(VERSION_NANO)
RC_VERSION_STR = '\"$(VERSION)\"'
INST_VERSION = $(VERSION)
INF_DATE = $(shell date +"%m/%d/%Y")
DATE = $(shell date +"%Y%m%d")
DDK_MAKE_DIR = ./ddk_make
TARGET = libusb
DLL_TARGET = $(TARGET)$(VERSION_MAJOR)
LIB_TARGET = $(TARGET)
DRIVER_TARGET = $(TARGET)$(VERSION_MAJOR).sys
DLL_TARGET_X64 = $(TARGET)$(VERSION_MAJOR)_x64
DRIVER_TARGET_X64 = $(TARGET)$(VERSION_MAJOR)_x64.sys
INSTALL_DIR = /usr
DLL_OBJECTS = usb.o error.o descriptors.o windows.o resource.o install.o \
registry.o
DRIVER_OBJECTS = abort_endpoint.o claim_interface.o clear_feature.o \
dispatch.o get_configuration.o \
get_descriptor.o get_interface.o get_status.o \
ioctl.o libusb_driver.o pnp.o release_interface.o reset_device.o \
reset_endpoint.o set_configuration.o set_descriptor.o \
set_feature.o set_interface.o transfer.o vendor_request.o \
power.o driver_registry.o driver_debug.o libusb_driver_rc.o
INSTALLER_NAME = $(TARGET)-win32-filter-bin-$(INST_VERSION).exe
SRC_DIST_DIR = $(TARGET)-win32-src-$(INST_VERSION)
BIN_DIST_DIR = $(TARGET)-win32-device-bin-$(INST_VERSION)
DIST_SOURCE_FILES = ./src
DIST_MISC_FILES = COPYING_LGPL.txt COPYING_GPL.txt AUTHORS.txt
SRC_DIR = ./src
DRIVER_SRC_DIR = $(SRC_DIR)/driver
VPATH = .:./src:./src/driver:./tests
INCLUDES = -I./src -I./src/driver -I.
CFLAGS = -O2 -Wall -mno-cygwin
WIN_CFLAGS = $(CFLAGS) -mwindows
CPPFLAGS = -DVERSION_MAJOR=$(VERSION_MAJOR) \
-DVERSION_MINOR=$(VERSION_MINOR) \
-DVERSION_MICRO=$(VERSION_MICRO) \
-DVERSION_NANO=$(VERSION_NANO) \
-DINF_DATE='$(INF_DATE)' \
-DINF_VERSION='$(VERSION)' \
-DDBG
WINDRES_FLAGS = -I./src -DRC_VERSION='$(RC_VERSION)' \
-DRC_VERSION_STR=$(RC_VERSION_STR)
LDFLAGS = -s -mno-cygwin -L. -lusb -lgdi32 -luser32 -lcfgmgr32 \
-lsetupapi -lcomctl32
WIN_LDFLAGS = $(LDFLAGS) -mwindows
DLL_LDFLAGS = -s -mdll -mno-cygwin \
-Wl,--kill-at \
-Wl,--out-implib,$(LIB_TARGET).a \
-Wl,--enable-stdcall-fixup \
-L. -lcfgmgr32 -lsetupapi
DRIVER_LDFLAGS = -s -shared -Wl,--entry,_DriverEntry@8 \
-nostartfiles -nostdlib -L. -lusbd -lntoskrnl -lhal
EXE_FILES = testlibusb.exe testlibusb-win.exe inf-wizard.exe install-filter.exe
.PHONY: all
all: $(DLL_TARGET).dll $(EXE_FILES) $(DRIVER_TARGET) README.txt
$(DLL_TARGET).dll: $(DLL_OBJECTS)
$(CC) -o $@ $(DLL_OBJECTS) $(DLL_TARGET).def $(DLL_LDFLAGS)
$(DRIVER_TARGET): libusbd.a $(DRIVER_OBJECTS)
$(CC) -o $@ $(DRIVER_OBJECTS) $(DLL_TARGET)_drv.def $(DRIVER_LDFLAGS)
libusbd.a:
$(DLLTOOL) --dllname usbd.sys --add-underscore --def ./src/driver/usbd.def \
--output-lib libusbd.a
inf-wizard.exe: inf_wizard_rc.o inf_wizard.o registry.o error.o
$(CC) $(WIN_CFLAGS) -o $@ -I./src $^ $(WIN_LDFLAGS)
testlibusb.exe: testlibusb.o
$(CC) $(CFLAGS) -o $@ -I./src $^ $(LDFLAGS)
install-filter.exe: install_filter.o
$(CC) $(CFLAGS) -o $@ -I./src $^ $(WIN_LDFLAGS)
testlibusb-win.exe: testlibusb_win.o testlibusb_win_rc.o
$(CC) $(WIN_CFLAGS) -o $@ -I./src $^ $(WIN_LDFLAGS)
%.o: %.c libusb_driver.h driver_api.h
$(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS) $(INCLUDES)
%.o: %.rc
$(WINDRES) $(WINDRES_FLAGS) $< -o $@
README.txt: README.in
sed -e 's/@VERSION@/$(INST_VERSION)/' $< > $@
.PHONY: bcc_implib
bcc_lib:
$(IMPLIB) -a $(LIB_TARGET).lib $(DLL_TARGET).dll
.PHONY: msvc_lib
msvc_lib:
$(LIB) /machine:i386 /def:$(DLL_TARGET).def
$(MV) $(DLL_TARGET).lib $(LIB_TARGET).lib
.PHONY: bin_dist
bin_dist: all
$(INSTALL) -d $(BIN_DIST_DIR)/lib/gcc
$(INSTALL) -d $(BIN_DIST_DIR)/lib/bcc
$(INSTALL) -d $(BIN_DIST_DIR)/lib/msvc
$(INSTALL) -d $(BIN_DIST_DIR)/lib/msvc_x64
$(INSTALL) -d $(BIN_DIST_DIR)/lib/dynamic
$(INSTALL) -d $(BIN_DIST_DIR)/include
$(INSTALL) -d $(BIN_DIST_DIR)/bin
$(INSTALL) -d $(BIN_DIST_DIR)/examples
$(INSTALL) $(EXE_FILES) $(BIN_DIST_DIR)/bin
$(INSTALL) $(DRIVER_TARGET) $(BIN_DIST_DIR)/bin
$(INSTALL) $(DLL_TARGET).dll $(BIN_DIST_DIR)/bin
$(INSTALL) $(DDK_MAKE_DIR)/$(DRIVER_TARGET) $(BIN_DIST_DIR)/bin/$(DRIVER_TARGET_X64)
$(INSTALL) $(DDK_MAKE_DIR)/$(DLL_TARGET).dll $(BIN_DIST_DIR)/bin/$(DLL_TARGET_X64).dll
$(INSTALL) $(SRC_DIR)/usb.h $(BIN_DIST_DIR)/include
$(INSTALL) $(LIB_TARGET).a $(BIN_DIST_DIR)/lib/gcc
$(MAKE) bcc_lib
$(INSTALL) $(LIB_TARGET).lib $(BIN_DIST_DIR)/lib/bcc
$(MAKE) msvc_lib
$(INSTALL) $(LIB_TARGET).lib $(BIN_DIST_DIR)/lib/msvc
$(INSTALL) $(DDK_MAKE_DIR)/$(LIB_TARGET).lib $(BIN_DIST_DIR)/lib/msvc_x64
$(INSTALL) $(SRC_DIR)/libusb_dyn.c $(BIN_DIST_DIR)/lib/dynamic
$(INSTALL) $(DIST_MISC_FILES) README.txt $(BIN_DIST_DIR)
$(INSTALL) ./examples/*.iss $(BIN_DIST_DIR)/examples
$(INSTALL) ./examples/*.c $(BIN_DIST_DIR)/examples
$(UNIX2DOS) $(BIN_DIST_DIR)/examples/*.iss
$(UNIX2DOS) $(BIN_DIST_DIR)/*.txt
.PHONY: src_dist
src_dist:
$(INSTALL) -d $(SRC_DIST_DIR)/src
$(INSTALL) -d $(SRC_DIST_DIR)/src/driver
$(INSTALL) -d $(SRC_DIST_DIR)/tests
$(INSTALL) -d $(SRC_DIST_DIR)/examples
$(INSTALL) -d $(SRC_DIST_DIR)/ddk_make
$(INSTALL) $(SRC_DIR)/*.c $(SRC_DIST_DIR)/src
$(INSTALL) $(SRC_DIR)/*.h $(SRC_DIST_DIR)/src
$(INSTALL) $(SRC_DIR)/*.rc $(SRC_DIST_DIR)/src
$(INSTALL) ./examples/*.iss $(SRC_DIST_DIR)/examples
$(INSTALL) ./ddk_make/sources* $(SRC_DIST_DIR)/ddk_make
$(INSTALL) ./ddk_make/makefile $(SRC_DIST_DIR)/ddk_make
$(INSTALL) ./ddk_make/*.txt $(SRC_DIST_DIR)/ddk_make
$(INSTALL) ./ddk_make/*.bat $(SRC_DIST_DIR)/ddk_make
$(UNIX2DOS) $(SRC_DIST_DIR)/ddk_make/*
$(INSTALL) $(SRC_DIR)/driver/*.h $(SRC_DIST_DIR)/src/driver
$(INSTALL) $(SRC_DIR)/driver/*.c $(SRC_DIST_DIR)/src/driver
$(INSTALL) $(SRC_DIR)/driver/*.def $(SRC_DIST_DIR)/src/driver
$(INSTALL) $(SRC_DIR)/driver/*.rc $(SRC_DIST_DIR)/src/driver
$(INSTALL) ./tests/*.c $(SRC_DIST_DIR)/tests
$(INSTALL) ./tests/*.rc $(SRC_DIST_DIR)/tests
$(INSTALL) $(DIST_MISC_FILES) *.in Makefile manifest.txt *.def \
installer_license.txt $(SRC_DIST_DIR)
$(UNIX2DOS) $(SRC_DIST_DIR)/*.txt
.PHONY: dist
dist: bin_dist src_dist
sed -e 's/@VERSION@/$(INST_VERSION)/' \
-e 's/@BIN_DIST_DIR@/$(BIN_DIST_DIR)/' \
-e 's/@SRC_DIST_DIR@/$(SRC_DIST_DIR)/' \
-e 's/@INSTALLER_TARGET@/$(INSTALLER_TARGET)/' \
install.iss.in > install.iss
$(UNIX2DOS) install.iss
$(TAR) -czf $(SRC_DIST_DIR).tar.gz $(SRC_DIST_DIR)
$(TAR) -czf $(BIN_DIST_DIR).tar.gz $(BIN_DIST_DIR)
$(ISCC) install.iss
$(RM) $(SRC_DIST_DIR)
$(RM) $(BIN_DIST_DIR)
.PHONY: snapshot
snapshot: INST_VERSION = $(DATE)
snapshot: dist
.PHONY: clean
clean:
$(RM) *.o *.dll *.a *.exp *.lib *.exe *.tar.gz *~ *.iss *.rc *.h
$(RM) ./src/*~ *.sys *.log
$(RM) $(DRIVER_SRC_DIR)/*~
$(RM) README.txt
# LIBUSB-WIN32, Generic Windows USB Library
# Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# If you're cross-compiling and your mingw32 tools are called
# i586-mingw32msvc-gcc and so on, then you can compile libusb-win32
# by running
# make host_prefix=i586-mingw32msvc all
ifdef host_prefix
override host_prefix := $(host_prefix)-
endif
CC = $(host_prefix)gcc
LD = $(host_prefix)ld
WINDRES = $(host_prefix)windres
DLLTOOL = $(host_prefix)dlltool
MAKE = make
CP = cp
CD = cd
MV = mv
RM = -rm -fr
TAR = tar
ISCC = iscc
INSTALL = install
LIB = lib
IMPLIB = implib
UNIX2DOS = unix2dos
VERSION_MAJOR = 0
VERSION_MINOR = 1
VERSION_MICRO = 12
VERSION_NANO = 1
VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_MICRO).$(VERSION_NANO)
RC_VERSION = $(VERSION_MAJOR),$(VERSION_MINOR),$(VERSION_MICRO),$(VERSION_NANO)
RC_VERSION_STR = '\"$(VERSION)\"'
INST_VERSION = $(VERSION)
INF_DATE = $(shell date +"%m/%d/%Y")
DATE = $(shell date +"%Y%m%d")
DDK_MAKE_DIR = ./ddk_make
TARGET = libusb
DLL_TARGET = $(TARGET)$(VERSION_MAJOR)
LIB_TARGET = $(TARGET)
DRIVER_TARGET = $(TARGET)$(VERSION_MAJOR).sys
DLL_TARGET_X64 = $(TARGET)$(VERSION_MAJOR)_x64
DRIVER_TARGET_X64 = $(TARGET)$(VERSION_MAJOR)_x64.sys
INSTALL_DIR = /usr
DLL_OBJECTS = usb.o error.o descriptors.o windows.o resource.o install.o \
registry.o
DRIVER_OBJECTS = abort_endpoint.o claim_interface.o clear_feature.o \
dispatch.o get_configuration.o \
get_descriptor.o get_interface.o get_status.o \
ioctl.o libusb_driver.o pnp.o release_interface.o reset_device.o \
reset_endpoint.o set_configuration.o set_descriptor.o \
set_feature.o set_interface.o transfer.o vendor_request.o \
power.o driver_registry.o driver_debug.o libusb_driver_rc.o
INSTALLER_NAME = $(TARGET)-win32-filter-bin-$(INST_VERSION).exe
SRC_DIST_DIR = $(TARGET)-win32-src-$(INST_VERSION)
BIN_DIST_DIR = $(TARGET)-win32-device-bin-$(INST_VERSION)
DIST_SOURCE_FILES = ./src
DIST_MISC_FILES = COPYING_LGPL.txt COPYING_GPL.txt AUTHORS.txt
SRC_DIR = ./src
DRIVER_SRC_DIR = $(SRC_DIR)/driver
VPATH = .:./src:./src/driver:./tests
INCLUDES = -I./src -I./src/driver -I.
CFLAGS = -O2 -Wall -mno-cygwin
WIN_CFLAGS = $(CFLAGS) -mwindows
CPPFLAGS = -DVERSION_MAJOR=$(VERSION_MAJOR) \
-DVERSION_MINOR=$(VERSION_MINOR) \
-DVERSION_MICRO=$(VERSION_MICRO) \
-DVERSION_NANO=$(VERSION_NANO) \
-DINF_DATE='$(INF_DATE)' \
-DINF_VERSION='$(VERSION)' \
-DDBG
WINDRES_FLAGS = -I./src -DRC_VERSION='$(RC_VERSION)' \
-DRC_VERSION_STR=$(RC_VERSION_STR)
LDFLAGS = -s -mno-cygwin -L. -lusb -lgdi32 -luser32 -lcfgmgr32 \
-lsetupapi -lcomctl32
WIN_LDFLAGS = $(LDFLAGS) -mwindows
DLL_LDFLAGS = -s -mdll -mno-cygwin \
-Wl,--kill-at \
-Wl,--out-implib,$(LIB_TARGET).a \
-Wl,--enable-stdcall-fixup \
-L. -lcfgmgr32 -lsetupapi
DRIVER_LDFLAGS = -s -shared -Wl,--entry,_DriverEntry@8 \
-nostartfiles -nostdlib -L. -lusbd -lntoskrnl -lhal
EXE_FILES = testlibusb.exe testlibusb-win.exe inf-wizard.exe install-filter.exe
.PHONY: all
all: $(DLL_TARGET).dll $(EXE_FILES) $(DRIVER_TARGET) README.txt
$(DLL_TARGET).dll: $(DLL_OBJECTS)
$(CC) -o $@ $(DLL_OBJECTS) $(DLL_TARGET).def $(DLL_LDFLAGS)
$(DRIVER_TARGET): libusbd.a $(DRIVER_OBJECTS)
$(CC) -o $@ $(DRIVER_OBJECTS) $(DLL_TARGET)_drv.def $(DRIVER_LDFLAGS)
libusbd.a:
$(DLLTOOL) --dllname usbd.sys --add-underscore --def ./src/driver/usbd.def \
--output-lib libusbd.a
inf-wizard.exe: inf_wizard_rc.o inf_wizard.o registry.o error.o
$(CC) $(WIN_CFLAGS) -o $@ -I./src $^ $(WIN_LDFLAGS)
testlibusb.exe: testlibusb.o
$(CC) $(CFLAGS) -o $@ -I./src $^ $(LDFLAGS)
install-filter.exe: install_filter.o
$(CC) $(CFLAGS) -o $@ -I./src $^ $(WIN_LDFLAGS)
testlibusb-win.exe: testlibusb_win.o testlibusb_win_rc.o
$(CC) $(WIN_CFLAGS) -o $@ -I./src $^ $(WIN_LDFLAGS)
%.o: %.c libusb_driver.h driver_api.h
$(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS) $(INCLUDES)
%.o: %.rc
$(WINDRES) $(WINDRES_FLAGS) $< -o $@
README.txt: README.in
sed -e 's/@VERSION@/$(INST_VERSION)/' $< > $@
.PHONY: bcc_implib
bcc_lib:
$(IMPLIB) -a $(LIB_TARGET).lib $(DLL_TARGET).dll
.PHONY: msvc_lib
msvc_lib:
$(LIB) /machine:i386 /def:$(DLL_TARGET).def
$(MV) $(DLL_TARGET).lib $(LIB_TARGET).lib
.PHONY: bin_dist
bin_dist: all
$(INSTALL) -d $(BIN_DIST_DIR)/lib/gcc
$(INSTALL) -d $(BIN_DIST_DIR)/lib/bcc
$(INSTALL) -d $(BIN_DIST_DIR)/lib/msvc
$(INSTALL) -d $(BIN_DIST_DIR)/lib/msvc_x64
$(INSTALL) -d $(BIN_DIST_DIR)/lib/dynamic
$(INSTALL) -d $(BIN_DIST_DIR)/include
$(INSTALL) -d $(BIN_DIST_DIR)/bin
$(INSTALL) -d $(BIN_DIST_DIR)/examples
$(INSTALL) $(EXE_FILES) $(BIN_DIST_DIR)/bin
$(INSTALL) $(DRIVER_TARGET) $(BIN_DIST_DIR)/bin
$(INSTALL) $(DLL_TARGET).dll $(BIN_DIST_DIR)/bin
$(INSTALL) $(DDK_MAKE_DIR)/$(DRIVER_TARGET) $(BIN_DIST_DIR)/bin/$(DRIVER_TARGET_X64)
$(INSTALL) $(DDK_MAKE_DIR)/$(DLL_TARGET).dll $(BIN_DIST_DIR)/bin/$(DLL_TARGET_X64).dll
$(INSTALL) $(SRC_DIR)/usb.h $(BIN_DIST_DIR)/include
$(INSTALL) $(LIB_TARGET).a $(BIN_DIST_DIR)/lib/gcc
$(MAKE) bcc_lib
$(INSTALL) $(LIB_TARGET).lib $(BIN_DIST_DIR)/lib/bcc
$(MAKE) msvc_lib
$(INSTALL) $(LIB_TARGET).lib $(BIN_DIST_DIR)/lib/msvc
$(INSTALL) $(DDK_MAKE_DIR)/$(LIB_TARGET).lib $(BIN_DIST_DIR)/lib/msvc_x64
$(INSTALL) $(SRC_DIR)/libusb_dyn.c $(BIN_DIST_DIR)/lib/dynamic
$(INSTALL) $(DIST_MISC_FILES) README.txt $(BIN_DIST_DIR)
$(INSTALL) ./examples/*.iss $(BIN_DIST_DIR)/examples
$(INSTALL) ./examples/*.c $(BIN_DIST_DIR)/examples
$(UNIX2DOS) $(BIN_DIST_DIR)/examples/*.iss
$(UNIX2DOS) $(BIN_DIST_DIR)/*.txt
.PHONY: src_dist
src_dist:
$(INSTALL) -d $(SRC_DIST_DIR)/src
$(INSTALL) -d $(SRC_DIST_DIR)/src/driver
$(INSTALL) -d $(SRC_DIST_DIR)/tests
$(INSTALL) -d $(SRC_DIST_DIR)/examples
$(INSTALL) -d $(SRC_DIST_DIR)/ddk_make
$(INSTALL) $(SRC_DIR)/*.c $(SRC_DIST_DIR)/src
$(INSTALL) $(SRC_DIR)/*.h $(SRC_DIST_DIR)/src
$(INSTALL) $(SRC_DIR)/*.rc $(SRC_DIST_DIR)/src
$(INSTALL) ./examples/*.iss $(SRC_DIST_DIR)/examples
$(INSTALL) ./ddk_make/sources* $(SRC_DIST_DIR)/ddk_make
$(INSTALL) ./ddk_make/makefile $(SRC_DIST_DIR)/ddk_make
$(INSTALL) ./ddk_make/*.txt $(SRC_DIST_DIR)/ddk_make
$(INSTALL) ./ddk_make/*.bat $(SRC_DIST_DIR)/ddk_make
$(UNIX2DOS) $(SRC_DIST_DIR)/ddk_make/*
$(INSTALL) $(SRC_DIR)/driver/*.h $(SRC_DIST_DIR)/src/driver
$(INSTALL) $(SRC_DIR)/driver/*.c $(SRC_DIST_DIR)/src/driver
$(INSTALL) $(SRC_DIR)/driver/*.def $(SRC_DIST_DIR)/src/driver
$(INSTALL) $(SRC_DIR)/driver/*.rc $(SRC_DIST_DIR)/src/driver
$(INSTALL) ./tests/*.c $(SRC_DIST_DIR)/tests
$(INSTALL) ./tests/*.rc $(SRC_DIST_DIR)/tests
$(INSTALL) $(DIST_MISC_FILES) *.in Makefile manifest.txt *.def \
installer_license.txt $(SRC_DIST_DIR)
$(UNIX2DOS) $(SRC_DIST_DIR)/*.txt
.PHONY: dist
dist: bin_dist src_dist
sed -e 's/@VERSION@/$(INST_VERSION)/' \
-e 's/@BIN_DIST_DIR@/$(BIN_DIST_DIR)/' \
-e 's/@SRC_DIST_DIR@/$(SRC_DIST_DIR)/' \
-e 's/@INSTALLER_TARGET@/$(INSTALLER_TARGET)/' \
install.iss.in > install.iss
$(UNIX2DOS) install.iss
$(TAR) -czf $(SRC_DIST_DIR).tar.gz $(SRC_DIST_DIR)
$(TAR) -czf $(BIN_DIST_DIR).tar.gz $(BIN_DIST_DIR)
$(ISCC) install.iss
$(RM) $(SRC_DIST_DIR)
$(RM) $(BIN_DIST_DIR)
.PHONY: snapshot
snapshot: INST_VERSION = $(DATE)
snapshot: dist
.PHONY: clean
clean:
$(RM) *.o *.dll *.a *.exp *.lib *.exe *.tar.gz *~ *.iss *.rc *.h
$(RM) ./src/*~ *.sys *.log
$(RM) $(DRIVER_SRC_DIR)/*~
$(RM) README.txt

Просмотреть файл

@ -1,165 +1,165 @@
/* LIBUSB-WIN32, Generic Windows USB Library
* Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __DRIVER_API_H__
#define __DRIVER_API_H__
enum {
LIBUSB_DEBUG_OFF,
LIBUSB_DEBUG_ERR,
LIBUSB_DEBUG_MSG,
};
/* 64k */
#define LIBUSB_MAX_READ_WRITE 0x10000
#define LIBUSB_MAX_NUMBER_OF_DEVICES 256
#define LIBUSB_MAX_NUMBER_OF_CHILDREN 32
#define LIBUSB_IOCTL_SET_CONFIGURATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x801, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_GET_CONFIGURATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x802, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_SET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x803, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_GET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x804, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_SET_FEATURE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x805, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_CLEAR_FEATURE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x806, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_GET_STATUS CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x807, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_SET_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x808, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_GET_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x809, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_INTERRUPT_OR_BULK_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80A, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_INTERRUPT_OR_BULK_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80B, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_VENDOR_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80C, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_VENDOR_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80D, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_RESET_ENDPOINT CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80E, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_ABORT_ENDPOINT CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80F, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_RESET_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x810, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_SET_DEBUG_LEVEL CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x811, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_GET_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x812, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_ISOCHRONOUS_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x813, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_ISOCHRONOUS_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x814, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_CLAIM_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x815, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_RELEASE_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x816, METHOD_BUFFERED, FILE_ANY_ACCESS)
#include <pshpack1.h>
typedef struct {
unsigned int timeout;
union {
struct
{
unsigned int configuration;
} configuration;
struct
{
unsigned int interface;
unsigned int altsetting;
} interface;
struct
{
unsigned int endpoint;
unsigned int packet_size;
} endpoint;
struct
{
unsigned int type;
unsigned int recipient;
unsigned int request;
unsigned int value;
unsigned int index;
} vendor;
struct
{
unsigned int recipient;
unsigned int feature;
unsigned int index;
} feature;
struct
{
unsigned int recipient;
unsigned int index;
unsigned int status;
} status;
struct
{
unsigned int type;
unsigned int index;
unsigned int language_id;
unsigned int recipient;
} descriptor;
struct
{
unsigned int level;
} debug;
struct
{
unsigned int major;
unsigned int minor;
unsigned int micro;
unsigned int nano;
} version;
};
} libusb_request;
#include <poppack.h>
#endif
/* LIBUSB-WIN32, Generic Windows USB Library
* Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __DRIVER_API_H__
#define __DRIVER_API_H__
enum {
LIBUSB_DEBUG_OFF,
LIBUSB_DEBUG_ERR,
LIBUSB_DEBUG_MSG,
};
/* 64k */
#define LIBUSB_MAX_READ_WRITE 0x10000
#define LIBUSB_MAX_NUMBER_OF_DEVICES 256
#define LIBUSB_MAX_NUMBER_OF_CHILDREN 32
#define LIBUSB_IOCTL_SET_CONFIGURATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x801, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_GET_CONFIGURATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x802, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_SET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x803, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_GET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x804, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_SET_FEATURE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x805, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_CLEAR_FEATURE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x806, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_GET_STATUS CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x807, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_SET_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x808, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_GET_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x809, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_INTERRUPT_OR_BULK_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80A, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_INTERRUPT_OR_BULK_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80B, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_VENDOR_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80C, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_VENDOR_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80D, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_RESET_ENDPOINT CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80E, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_ABORT_ENDPOINT CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80F, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_RESET_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x810, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_SET_DEBUG_LEVEL CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x811, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_GET_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x812, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_ISOCHRONOUS_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x813, METHOD_IN_DIRECT, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_ISOCHRONOUS_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x814, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_CLAIM_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x815, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define LIBUSB_IOCTL_RELEASE_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x816, METHOD_BUFFERED, FILE_ANY_ACCESS)
#include <pshpack1.h>
typedef struct {
unsigned int timeout;
union {
struct
{
unsigned int configuration;
} configuration;
struct
{
unsigned int interface;
unsigned int altsetting;
} interface;
struct
{
unsigned int endpoint;
unsigned int packet_size;
} endpoint;
struct
{
unsigned int type;
unsigned int recipient;
unsigned int request;
unsigned int value;
unsigned int index;
} vendor;
struct
{
unsigned int recipient;
unsigned int feature;
unsigned int index;
} feature;
struct
{
unsigned int recipient;
unsigned int index;
unsigned int status;
} status;
struct
{
unsigned int type;
unsigned int index;
unsigned int language_id;
unsigned int recipient;
} descriptor;
struct
{
unsigned int level;
} debug;
struct
{
unsigned int major;
unsigned int minor;
unsigned int micro;
unsigned int nano;
} version;
};
} libusb_request;
#include <poppack.h>
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,9 +1,9 @@
#include <stdlib.h>
#ifdef WIN32
blahfs-o_f-0-(){ {}A
#else
int main(int argc, char* argv[]) {
return 0;
}
#endif
#include <stdlib.h>
#ifdef WIN32
blahfs-o_f-0-(){ {}A
#else
int main(int argc, char* argv[]) {
return 0;
}
#endif