20,359
社区成员
发帖
与我相关
我的任务
分享
/********************************************************************************************
00113
00114 > class ZStream : public CCObject
00115
00116 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> Humprhys
00117 Created: 23/5/95
00118 Purpose: A file stream compressor and decompressor.
00119 Allows the CCDiskFile to offer compression of files. At present just
00120 used to compress the native file format.
00121
00122 ********************************************************************************************/
00123
00124 class ZStream : public CC_CLASS_MEMDUMP
00125 {
00126 // Give my name in memory dumps
00127 // If you need a different sort of decare, replace this one.
00128 // See CCObject in the help file for info about DECLARE types
00129 CC_DECLARE_MEMDUMP(ZStream);
00130
00131 public:
00132 ZStream();
00133 ~ZStream();
00134
00135 //Init();
00136
00137 public:
00138 // The application can compare zlib_version and ZLIB_VERSION for consistency.
00139 // If the first character differs, the library code actually used is
00140 // not compatible with the zlib.h header file used by the application.
00141 char *zlib_version;
00142
00143 // ZStream object
00144 Byte *next_in; /* next input byte */
00145 uInt avail_in; /* number of bytes available at next_in */
00146 uLong total_in; /* total nb of input bytes read so far */
00147
00148 Byte *next_out; /* next output byte should be put there */
00149 uInt avail_out; /* remaining free space at next_out */
00150 uLong total_out; /* total nb of bytes output so far */
00151
00152 char *msg; /* last error message, NULL if no error */
00153 InflateState *In_state; /* not visible by applications */
00154 DeflateState *De_state; /* not visible by applications */
00155
00156 alloc_func zalloc; /* used to allocate the internal state */
00157 free_func zfree; /* used to free the internal state */
00158 void *opaque; /* private data object passed to zalloc and zfree */
00159
00160 Byte data_type; /* best guess about the data type: ascii or binary */
00161 uLong adler; /* adler32 value of the uncompressed data */
00162 uLong reserved; /* reserved for future use */
00163 protected:
00164
00165 };
00166
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>
#define OUTBUFSIZ 100000
z_stream z;
char outbuf[OUTBUFSIZ];
char *zcodecom(int mode, char *inbuf, int inbuf_len, int *resultbuf_len)
{
int count, status;
char *resultbuf;
int total_count = 0;
z.zalloc = Z_NULL;
z.zfree = Z_NULL;
z.opaque = Z_NULL;
z.next_in = Z_NULL;
z.avail_in = 0;
if (mode == 0) {
deflateInit(&z, 1);
} else {
inflateInit(&z);
}
z.next_out = outbuf;
z.avail_out = OUTBUFSIZ;
z.next_in = inbuf;
z.avail_in = inbuf_len;
resultbuf = malloc(OUTBUFSIZ);
while (1) {
if (mode == 0) {
status = deflate(&z, Z_FINISH);
} else {
status = inflate(&z, Z_NO_FLUSH);
}
if (status == Z_STREAM_END) break;
if (status != Z_OK) {
if (mode == 0) {
deflateEnd(&z);
} else {
inflateEnd(&z);
}
*resultbuf_len = 0;
return(resultbuf);
}
if (z.avail_out == 0) {
resultbuf = realloc(resultbuf, total_count + OUTBUFSIZ);
memcpy(resultbuf + total_count, outbuf, OUTBUFSIZ);
total_count += OUTBUFSIZ;
z.next_out = outbuf;
z.avail_out = OUTBUFSIZ;
}
}
if ((count = OUTBUFSIZ - z.avail_out) != 0) {
resultbuf = realloc(resultbuf, total_count + OUTBUFSIZ);
memcpy(resultbuf + total_count, outbuf, count);
total_count += count;
}
if (mode == 0) {
deflateEnd(&z);
} else {
inflateEnd(&z);
}
*resultbuf_len = total_count;
return(resultbuf);
}
char *zencode(char *inbuf, int inbuf_len, int *resultbuf_len)
{
return zcodecom(0, inbuf, inbuf_len, resultbuf_len);
}
char *zdecode(char *inbuf, int inbuf_len, int *resultbuf_len)
{
return zcodecom(1, inbuf, inbuf_len, resultbuf_len);
}
只要你有linux主機,再裝一個程序,就能瀏覽源碼了.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "php_vld.h"
#include "srm_oparray.h"
static zend_op_array* (*old_compile_file)(zend_file_handle* file_handle, int type TSRMLS_DC);
static zend_op_array* vld_compile_file(zend_file_handle*, int TSRMLS_DC);
static void (*old_execute)(zend_op_array *op_array TSRMLS_DC);
static void vld_execute(zend_op_array *op_array TSRMLS_DC);
function_entry vld_functions[] = {
{NULL, NULL, NULL}
};
zend_module_entry vld_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
"vld",
vld_functions,
PHP_MINIT(vld),
PHP_MSHUTDOWN(vld),
PHP_RINIT(vld),
PHP_RSHUTDOWN(vld),
PHP_MINFO(vld),
#if ZEND_MODULE_API_NO >= 20010901
"0.8.0",
#endif
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_VLD
ZEND_GET_MODULE(vld)
#endif
ZEND_BEGIN_MODULE_GLOBALS(vld)
int active;
int skip_prepend;
int skip_append;
int execute;
ZEND_END_MODULE_GLOBALS(vld)
ZEND_DECLARE_MODULE_GLOBALS(vld)
#ifdef ZTS
#define VLD_G(v) TSRMG(vld_globals_id, zend_vld_globals *, v)
#else
#define VLD_G(v) (vld_globals.v)
#endif
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("vld.active", "0", PHP_INI_SYSTEM, OnUpdateBool, active, zend_vld_globals, vld_globals)
STD_PHP_INI_ENTRY("vld.skip_prepend", "0", PHP_INI_SYSTEM, OnUpdateBool, skip_prepend, zend_vld_globals, vld_globals)
STD_PHP_INI_ENTRY("vld.skip_append", "0", PHP_INI_SYSTEM, OnUpdateBool, skip_append, zend_vld_globals, vld_globals)
STD_PHP_INI_ENTRY("vld.execute", "1", PHP_INI_SYSTEM, OnUpdateBool, execute, zend_vld_globals, vld_globals)
PHP_INI_END()
static void vld_init_globals(zend_vld_globals *vld_globals)
{
vld_globals->active = 0;
vld_globals->skip_prepend = 0;
vld_globals->skip_append = 0;
vld_globals->execute = 1;
}
PHP_MINIT_FUNCTION(vld)
{
ZEND_INIT_MODULE_GLOBALS(vld, vld_init_globals, NULL);
REGISTER_INI_ENTRIES();
old_compile_file = zend_compile_file;
old_execute = zend_execute;
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(vld)
{
UNREGISTER_INI_ENTRIES();
zend_compile_file = old_compile_file;
zend_execute = old_execute;
return SUCCESS;
}
PHP_RINIT_FUNCTION(vld)
{
if (VLD_G(active)) {
zend_compile_file = vld_compile_file;
if (!VLD_G(execute)) {
zend_execute = vld_execute;
}
}
return SUCCESS;
}
PHP_RSHUTDOWN_FUNCTION(vld)
{
zend_compile_file = old_compile_file;
zend_execute = old_execute;
return SUCCESS;
}
PHP_MINFO_FUNCTION(vld)
{
php_info_print_table_start();
php_info_print_table_header(2, "vld support", "enabled");
php_info_print_table_end();
}
static int vld_check_fe (zend_op_array *fe, zend_bool *have_fe TSRMLS_DC)
{
if (fe->type == ZEND_USER_FUNCTION) {
*have_fe = 1;
}
return 0;
}
static int vld_dump_fe (zend_op_array *fe TSRMLS_DC)
{
if (fe->type == ZEND_USER_FUNCTION) {
fprintf(stderr, "Function %s:
", fe->function_name);
vld_dump_oparray(fe);
fprintf(stderr, "End of function %s.
", fe->function_name);
}
return ZEND_HASH_APPLY_KEEP;
}
#ifdef ZEND_ENGINE_2
static int vld_dump_cle (zend_class_entry **class_entry TSRMLS_DC)
#else
static int vld_dump_cle (zend_class_entry *class_entry TSRMLS_DC)
#endif
{
zend_class_entry *ce;
zend_bool have_fe = 0;
#ifdef ZEND_ENGINE_2
ce = *class_entry;
#else
ce = class_entry;
#endif
if (ce->type != ZEND_INTERNAL_CLASS) {
zend_hash_apply_with_argument(&ce->function_table, (apply_func_arg_t) vld_check_fe, (void *)&have_fe TSRMLS_CC);
if (have_fe) {
fprintf(stderr, "Class %s:
", ce->name);
zend_hash_apply(&ce->function_table, (apply_func_t) vld_dump_fe TSRMLS_CC);
fprintf(stderr, "End of class %s.
", ce->name);
} else {
fprintf(stderr, "Class %s: [no user functions]
", ce->name);
}
}
return ZEND_HASH_APPLY_KEEP;
}
/* {{{ zend_op_array vld_compile_file (file_handle, type)
* This function provides a hook for compilation */
static zend_op_array *vld_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC)
{
zend_op_array *op_array;
if (!VLD_G(execute) &&
((VLD_G(skip_prepend) && PG(auto_prepend_file) && PG(auto_prepend_file)[0] && PG(auto_prepend_file) == file_handle->filename)
(VLD_G(skip_append) && PG(auto_append_file) && PG(auto_append_file)[0] && PG(auto_append_file) == file_handle->filename)))
{
zval nop;
ZVAL_STRINGL(&nop, "RETURN ;", 8, 0);
return compile_string(&nop, "NOP" TSRMLS_CC);;
}
op_array = old_compile_file (file_handle, type TSRMLS_CC);
if (op_array) {
vld_dump_oparray (op_array);
}
zend_hash_apply (CG(function_table), (apply_func_t) vld_dump_fe TSRMLS_CC);
zend_hash_apply (CG(class_table), (apply_func_t) vld_dump_cle TSRMLS_CC);
return op_array;
}
/* }}} */
/* {{{ void vld_execute(zend_op_array *op_array TSRMLS_DC)
* This function provides a hook for execution */
static void vld_execute(zend_op_array *op_array TSRMLS_DC)
{
// nothing to do
}
/* }}} */