⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 decompile.c

📁 The Kannel Open Source WAP and SMS gateway works as both an SMS gateway, for implementing keyword b
💻 C
📖 第 1 页 / 共 3 页
字号:
/* ====================================================================  * The Kannel Software License, Version 1.0  *  * Copyright (c) 2001-2004 Kannel Group   * Copyright (c) 1998-2001 WapIT Ltd.    * All rights reserved.  *  * Redistribution and use in source and binary forms, with or without  * modification, are permitted provided that the following conditions  * are met:  *  * 1. Redistributions of source code must retain the above copyright  *    notice, this list of conditions and the following disclaimer.  *  * 2. Redistributions in binary form must reproduce the above copyright  *    notice, this list of conditions and the following disclaimer in  *    the documentation and/or other materials provided with the  *    distribution.  *  * 3. The end-user documentation included with the redistribution,  *    if any, must include the following acknowledgment:  *       "This product includes software developed by the  *        Kannel Group (http://www.kannel.org/)."  *    Alternately, this acknowledgment may appear in the software itself,  *    if and wherever such third-party acknowledgments normally appear.  *  * 4. The names "Kannel" and "Kannel Group" must not be used to  *    endorse or promote products derived from this software without  *    prior written permission. For written permission, please   *    contact org@kannel.org.  *  * 5. Products derived from this software may not be called "Kannel",  *    nor may "Kannel" appear in their name, without prior written  *    permission of the Kannel Group.  *  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE  * DISCLAIMED.  IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,   * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT   * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE   * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,   * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  * ====================================================================  *  * This software consists of voluntary contributions made by many  * individuals on behalf of the Kannel Group.  For more information on   * the Kannel Group, please see <http://www.kannel.org/>.  *  * Portions of this software are based upon software originally written at   * WapIT Ltd., Helsinki, Finland for the Kannel project.   */ /* * decompile.c - A program to test the WML compiler. This tool was written *               from the WBXML 1.2 and WML 1.1 specs. * * Author: Chris Wulff, Vanteon (cwulff@vanteon.com) * */#include <stdio.h>#include <stdlib.h>#include <memory.h>#include <string.h>#include "decompile.h"const WBXML_MB_U_INT32 ZERO_WBXML_MB_U_INT32 = {0,0,0,0};long dtd_id;#define INDENT_SIZE		4DTD_TYPE_LIST DTDTypeList[] ={	{1, "UNKNOWN"},	{2, "-//WAPFORUM//DTD WML 1.0//EN\"\n"	 "\"http://www.wapforum.org/DTD/wml.xml"},	{3, "-//WAPFORUM//DTD WTA 1.0//EN"},	{4, "-//WAPFORUM//DTD WML 1.1//EN\"\n"	 "\"http://www.wapforum.org/DTD/wml_1.1.xml"},	{5, "-//WAPFORUM//DTD SI 1.0//EN\"\n"	 "\"http://www.wapforum.org/DTD/si.dtd"},	{6, "-//WAPFORUM//DTD SL 1.0//EN\"\n"	 "\"http://www.wapforum.org/DTD/sl.dtd"},	{7, "-//WAPFORUM//DTD CO 1.0//EN"},	{8, "-//WAPFORUM//DTD CHANNEL 1.1//EN"},	{9, "-//WAPFORUM//DTD WML 1.2//EN\"\n"	 "\"http://www.wapforum.org/DTD/wml12.dtd"},	{0, NULL}};/************************************** * DTD Public Type 4 (WML 1.1) Tables * **************************************/CODEPAGE_TAG_NAME_LIST CodepageTagNames[] ={	{4, "a",         0, 0x1c},	{4, "anchor",    0, 0x22},	{4, "access",    0, 0x23},	{4, "b",         0, 0x24},	{4, "big",       0, 0x25},	{4, "br",        0, 0x26},	{4, "card",      0, 0x27},	{4, "do",        0, 0x28},	{4, "em",        0, 0x29},	{4, "fieldset",  0, 0x2a},	{4, "go",        0, 0x2b},	{4, "head",      0, 0x2c},	{4, "i",         0, 0x2d},	{4, "img",       0, 0x2e},	{4, "input",     0, 0x2f},	{4, "meta",      0, 0x30},	{4, "noop",      0, 0x31},	{4, "p",         0, 0x20},	{4, "postfield", 0, 0x21},	{4, "pre",       0, 0x1b},	{4, "prev",      0, 0x32},	{4, "onevent",   0, 0x33},	{4, "optgroup",  0, 0x34},	{4, "option",    0, 0x35},	{4, "refresh",   0, 0x36},	{4, "select",    0, 0x37},	{4, "setvar",    0, 0x3e},	{4, "small",     0, 0x38},	{4, "strong",    0, 0x39},	{4, "table",     0, 0x1f},	{4, "td",        0, 0x1d},	{4, "template",  0, 0x3b},	{4, "timer",     0, 0x3c},	{4, "tr",        0, 0x1e},	{4, "u",         0, 0x3d},	{4, "wml",       0, 0x3f},	{6, "TAG_05",    1, 0x05},	{6, "TAG_06",    1, 0x06},	{6, "TAG_07",    1, 0x07},	{0, NULL, 0, 0}};CODEPAGE_ATTRSTART_NAME_LIST CodepageAttrstartNames[] ={	{4, "accept-charset",  NULL,                                0, 0x05},	{4, "accesskey",       NULL,                                0, 0x5e},	{4, "align",           NULL,                                0, 0x52},	{4, "align",           "bottom",                            0, 0x06},	{4, "align",           "center",                            0, 0x07},	{4, "align",           "left",                              0, 0x08},	{4, "align",           "middle",                            0, 0x09},	{4, "align",           "right",                             0, 0x0a},	{4, "align",           "top",                               0, 0x0b},	{4, "alt",             NULL,                                0, 0x0c},	{4, "class",           NULL,                                0, 0x54},	{4, "columns",         NULL,                                0, 0x53},	{4, "content",         NULL,                                0, 0x0d},	{4, "content",         "application/vnd.wap.wmlc;charset=", 0, 0x5c},	{4, "domain",          NULL,                                0, 0x0f},	{4, "emptyok",         "false",                             0, 0x10},	{4, "emptyok",         "true",                              0, 0x11},	{4, "enctype",         NULL,                                0, 0x5f},	{4, "enctype",         "application/x-www-form-urlencoded", 0, 0x60},	{4, "enctype",         "multipart/form-data",               0, 0x61},	{4, "format",          NULL,                                0, 0x12},	{4, "forua",           "false",                             0, 0x56},	{4, "forua",           "true",                              0, 0x57},	{4, "height",          NULL,                                0, 0x13},	{4, "href",            NULL,                                0, 0x4a},	{4, "href",            "http://",                           0, 0x4b},	{4, "href",            "https://",                          0, 0x4c},	{4, "hspace",          NULL,                                0, 0x14},	{4, "http-equiv",      NULL,                                0, 0x5a},	{4, "http-equiv",      "Content-Type",                      0, 0x5b},	{4, "http-equiv",      "Expires",                           0, 0x5d},	{4, "id",              NULL,                                0, 0x55},	{4, "ivalue",          NULL,                                0, 0x15},	{4, "iname",           NULL,                                0, 0x16},	{4, "label",           NULL,                                0, 0x18},	{4, "localsrc",        NULL,                                0, 0x19},	{4, "maxlength",       NULL,                                0, 0x1a},	{4, "method",          "get",                               0, 0x1b},	{4, "method",          "post",                              0, 0x1c},	{4, "mode",            "nowrap",                            0, 0x1d},	{4, "mode",            "wrap",                              0, 0x1e},	{4, "multiple",        "false",                             0, 0x1f},	{4, "multiple",        "true",                              0, 0x20},	{4, "name",            NULL,                                0, 0x21},	{4, "newcontext",      "false",                             0, 0x22},	{4, "newcontext",      "true",                              0, 0x23},	{4, "onenterbackward", NULL,                                0, 0x25},	{4, "onenterforward",  NULL,                                0, 0x26},	{4, "onpick",          NULL,                                0, 0x24},	{4, "ontimer",         NULL,                                0, 0x27},	{4, "optional",        "false",                             0, 0x28},	{4, "optional",        "true",                              0, 0x29},	{4, "path",            NULL,                                0, 0x2a},	{4, "scheme",          NULL,                                0, 0x2e},	{4, "sendreferer",     "false",                             0, 0x2f},	{4, "sendreferer",     "true",                              0, 0x30},	{4, "size",            NULL,                                0, 0x31},	{4, "src",             NULL,                                0, 0x32},	{4, "src",             "http://",                           0, 0x58},	{4, "src",             "https://",                          0, 0x59},	{4, "ordered",         "true",                              0, 0x33},	{4, "ordered",         "false",                             0, 0x34},	{4, "tabindex",        NULL,                                0, 0x35},	{4, "title",           NULL,                                0, 0x36},	{4, "type",            NULL,                                0, 0x37},	{4, "type",            "accept",                            0, 0x38},	{4, "type",            "delete",                            0, 0x39},	{4, "type",            "help",                              0, 0x3a},	{4, "type",            "password",                          0, 0x3b},	{4, "type",            "onpick",                            0, 0x3c},	{4, "type",            "onenterbackward",                   0, 0x3d},	{4, "type",            "onenterforward",                    0, 0x3e},	{4, "type",            "ontimer",                           0, 0x3f},	{4, "type",            "options",                           0, 0x45},	{4, "type",            "prev",                              0, 0x46},	{4, "type",            "reset",                             0, 0x47},	{4, "type",            "text",                              0, 0x48},	{4, "type",            "vnd.",                              0, 0x49},	{4, "value",           NULL,                                0, 0x4d},	{4, "vspace",          NULL,                                0, 0x4e},	{4, "width",           NULL,                                0, 0x4f},	{4, "xml:lang",        NULL,                                0, 0x50},	{6, "ATTR_06",         NULL,                                1, 0x06},	{6, "ATTR_07",         NULL,                                1, 0x07},	{6, "ATTR_08",         NULL,                                1, 0x08},	{6, "ATTR_11",         NULL,                                1, 0x11},	{6, "ATTR_12",         NULL,                                1, 0x12},	{6, "ATTR_13",         NULL,                                1, 0x13},	{6, "ATTR_14",         NULL,                                1, 0x14},	{6, "ATTR_15",         NULL,                                1, 0x15},	{6, "ATTR_21",         NULL,                                1, 0x21},	{6, "ATTR_22",         NULL,                                1, 0x22},	{6, "ATTR_23",         NULL,                                1, 0x23},	{6, "ATTR_24",         NULL,                                1, 0x24},	{6, "ATTR_28",         NULL,                                1, 0x28},	{6, "ATTR_29",         NULL,                                1, 0x29},	{6, "ATTR_45",         NULL,                                1, 0x45},	{6, "ATTR_61",         NULL,                                1, 0x61},	{6, "ATTR_62",         NULL,                                1, 0x62},	{6, "ATTR_63",         NULL,                                1, 0x63},	{6, "ATTR_64",         NULL,                                1, 0x64},	{6, "ATTR_6A",         NULL,                                1, 0x6A},	{6, "ATTR_6B",         NULL,                                1, 0x6B},	{6, "ATTR_6C",         NULL,                                1, 0x6C},	{6, "ATTR_70",         NULL,                                1, 0x70},	{6, "ATTR_71",         NULL,                                1, 0x71},	{6, "ATTR_73",         NULL,                                1, 0x73},	{6, "ATTR_74",         NULL,                                1, 0x74},	{0, NULL,              NULL,                                0, 0}};CODEPAGE_ATTRVALUE_NAME_LIST CodepageAttrvalueNames[] ={	{4, ".com/",           0, 0x85},	{4, ".edu/",           0, 0x86},	{4, ".net/",           0, 0x87},	{4, ".org/",           0, 0x88},	{4, "accept",          0, 0x89},	{4, "bottom",          0, 0x8a},	{4, "clear",           0, 0x8b},	{4, "delete",          0, 0x8c},	{4, "help",            0, 0x8d},	{4, "http://",         0, 0x8e},	{4, "http://www.",     0, 0x8f},	{4, "https://",        0, 0x90},	{4, "https://www.",    0, 0x91},	{4, "middle",          0, 0x93},	{4, "nowrap",          0, 0x94},	{4, "onenterbackward", 0, 0x96},	{4, "onenterforward",  0, 0x97},	{4, "onpick",          0, 0x95},	{4, "ontimer",         0, 0x98},	{4, "options",         0, 0x99},	{4, "password",        0, 0x9a},	{4, "reset",           0, 0x9b},	{4, "text",            0, 0x9d},	{4, "top",             0, 0x9e},	{4, "unknown",         0, 0x9f},	{4, "wrap",            0, 0xa0},	{4, "www.",            0, 0xa1},	{0, NULL, 0, 0}};/************************** * Node Tree Construction * **************************//* * Function: NewNode * * Description: * *  Allocate and initialize a new node. This links the new node *  as the first child of the current node in the buffer. This causes *  child nodes to be linked in reverse order. If there is no current *  node, then the new node will be linked in as the first child at the *  top of the tree. * * Parameters: * *  buffer - WBXML buffer to link the new node into *  type   - Type of node to allocate * * Return value: * *  P_WBXML_NODE - A pointer to the newly allocated node. * */static P_WBXML_NODE NewNode(P_WBXML_INFO buffer, WBXML_NODE_TYPE type){	if (buffer)	{		P_WBXML_NODE newnode = malloc(sizeof(WBXML_NODE));		if (newnode)		{			newnode->m_prev = NULL;			newnode->m_child = NULL;			if (buffer->m_curnode)			{				/* Insert this node as the first child of the current node */				newnode->m_parent = buffer->m_curnode;				newnode->m_next = buffer->m_curnode->m_child;				if (buffer->m_curnode->m_child)				{					((P_WBXML_NODE)buffer->m_curnode->m_child)->m_prev = newnode;				}				buffer->m_curnode->m_child = newnode;			}			else			{				/* Insert this node at the top of the tree */				newnode->m_parent = NULL;				newnode->m_next = buffer->m_tree;								if (buffer->m_tree)				{					buffer->m_tree->m_prev = newnode;				}				buffer->m_tree = newnode;			}			newnode->m_page = buffer->m_curpage;			newnode->m_type = type;			newnode->m_data = NULL;		}		else		{			ParseError(ERR_NOT_ENOUGH_MEMORY);		}		return newnode;	}	else	{		ParseError(ERR_INTERNAL_BAD_PARAM);	}	return NULL;}/* * Function: FreeNode * * Description: * *  Free a node, all its children and forward siblings. * * Parameters: * *  node - The node to free * */static void FreeNode(P_WBXML_NODE node){	if (node)	{		if (node->m_child)		{			FreeNode(node->m_child);		}		if (node->m_next)		{			FreeNode(node->m_next);		}		free(node);	}}static void AddDTDNode(P_WBXML_INFO buffer, const WBXML_DTD_TYPE dtdnum, const WBXML_MB_U_INT32 index){	P_WBXML_NODE newnode = NewNode(buffer, NODE_DTD_TYPE);	newnode->m_data = malloc(sizeof(DTD_NODE_DATA));	memcpy( &( ((DTD_NODE_DATA*)newnode->m_data)->m_dtdnum ), &(dtdnum[0]), sizeof(WBXML_MB_U_INT32) );	memcpy( &( ((DTD_NODE_DATA*)newnode->m_data)->m_index ), &(index[0]), sizeof(WBXML_MB_U_INT32) );	dtd_id = (long) dtdnum[0];}static void AddStringTableNode(P_WBXML_INFO buffer, const P_WBXML_STRING_TABLE strings){	P_WBXML_NODE newnode = NewNode(buffer, NODE_STRING_TABLE);	newnode->m_data = malloc(sizeof(WBXML_STRING_TABLE));	memcpy( newnode->m_data, strings, sizeof(WBXML_STRING_TABLE) );}static void AddCodepageTagNode(P_WBXML_INFO buffer, WBXML_TAG tag){	P_WBXML_NODE newnode = NewNode(buffer, NODE_CODEPAGE_TAG);	newnode->m_data = malloc(sizeof(WBXML_TAG));	*((P_WBXML_TAG)newnode->m_data) = tag;}static void AddCodepageLiteralTagNode(P_WBXML_INFO buffer, WBXML_MB_U_INT32 index){	P_WBXML_NODE newnode = NewNode(buffer, NODE_CODEPAGE_LITERAL_TAG);	newnode->m_data = malloc(sizeof(WBXML_MB_U_INT32));	memcpy( ((P_WBXML_MB_U_INT32)newnode->m_data), &index, sizeof(WBXML_MB_U_INT32) );}static void AddAttrStartNode(P_WBXML_INFO buffer, WBXML_TAG tag){	P_WBXML_NODE newnode = NewNode(buffer, NODE_ATTRSTART);	newnode->m_data = malloc(sizeof(WBXML_TAG));	*((P_WBXML_TAG)newnode->m_data) = tag;}static void AddAttrStartLiteralNode(P_WBXML_INFO buffer, WBXML_MB_U_INT32 index){	P_WBXML_NODE newnode = NewNode(buffer, NODE_ATTRSTART_LITERAL);	newnode->m_data = malloc(sizeof(WBXML_MB_U_INT32));	memcpy( ((P_WBXML_MB_U_INT32)newnode->m_data), &index, sizeof(WBXML_MB_U_INT32) );}static void AddAttrValueNode(P_WBXML_INFO buffer, WBXML_TAG tag){	P_WBXML_NODE newnode = NewNode(buffer, NODE_ATTRVALUE);	newnode->m_data = malloc(sizeof(WBXML_TAG));	*((P_WBXML_TAG)newnode->m_data) = tag;}static void AddAttrEndNode(P_WBXML_INFO buffer){	P_WBXML_NODE newnode = NewNode(buffer, NODE_ATTREND);	newnode->m_data = NULL;}static void AddStringNode(P_WBXML_INFO buffer, char* string){	P_WBXML_NODE newnode = NewNode(buffer, NODE_STRING);	newnode->m_data = strdup(string);}static void AddVariableStringNode(P_WBXML_INFO buffer, char* string, WBXML_VARIABLE_TYPE type){	/* TODO: add this node */}static void AddVariableIndexNode(P_WBXML_INFO buffer, char* string, WBXML_VARIABLE_TYPE type){	/* TODO: add this node */}/**************** * Flow Control * ****************/void Message(char* msg){  printf("%s\n", msg);}void ParseError(WBXML_PARSE_ERROR error){  switch (error)  {    case ERR_END_OF_DATA:      Message("Input stream is incomplete (EOF).");      break;    case ERR_INTERNAL_BAD_PARAM:      Message("Internal error: Bad parameter.");      break;	case ERR_TAG_NOT_FOUND:      Message("Tag not found.");      break;			case ERR_FILE_NOT_FOUND:      Message("File not found.");      break;	case ERR_FILE_NOT_READ:      Message("File read error.");      break;	case ERR_NOT_ENOUGH_MEMORY:      Message("Not enough memory");      break;    default:      Message("Unknown error.");      break;  }  exit(error);}void ParseWarning(WBXML_PARSE_WARNING warning){  switch (warning)  {    case WARN_FUTURE_EXPANSION_EXT_0:      Message("Token EXT_0 encountered. This token is reserved for future expansion.");      break;    case WARN_FUTURE_EXPANSION_EXT_1:      Message("Token EXT_1 encountered. This token is reserved for future expansion.");      break;    case WARN_FUTURE_EXPANSION_EXT_2:      Message("Token EXT_2 encountered. This token is reserved for future expansion.");      break;    default:      Message("Unknown warning.");      break;  }}WBXML_LENGTH BytesLeft(P_WBXML_INFO buffer){  if (buffer)  {    WBXML_LENGTH bytesRead = (buffer->m_curpos - buffer->m_start);    if (bytesRead >= buffer->m_length)    {      return 0;    }    else    {      return (buffer->m_length - bytesRead);    }  }  else  {    ParseError(ERR_INTERNAL_BAD_PARAM);  }  return 0;}BOOL IsTag(P_WBXML_INFO buffer, WBXML_TAG tag){  BOOL result = FALSE;  if (buffer)  {    if (BytesLeft(buffer) >= sizeof(WBXML_TAG))    {      result = ((*((WBXML_TAG*) buffer->m_curpos)) == tag);    }    else    {		/* No more data, so nope, not this tag */      result = FALSE;    }  }  else  {    ParseError(ERR_INTERNAL_BAD_PARAM);  }  return result;}BOOL IsCodepageTag(P_WBXML_INFO buffer, CP_TAG_TYPE type){	WBXML_U_INT8 result = *(buffer->m_curpos);	/* NOTE THAT THESE ARE NOT UNIQUE! */	switch (type)	{		case CP_TAG_TAG:			return TRUE;		case CP_TAG_ATTRSTART:			return ((result & 0x80) != 0x80);		case CP_TAG_ATTRVALUE:			return ((result & 0x80) == 0x80);		default:			return FALSE;	}}BOOL Is_attrValue  (P_WBXML_INFO buffer){	WBXML_INFO tmpbuffer;	memcpy(&tmpbuffer, buffer, sizeof(WBXML_INFO));	tmpbuffer.m_curpos += SWITCHPAGE_SIZE;	return ((Is_switchPage(buffer) && IsCodepageTag(&tmpbuffer, CP_TAG_ATTRVALUE)) ||		    IsCodepageTag(buffer, CP_TAG_ATTRVALUE) ||			Is_string(buffer) ||			Is_extension(buffer) ||			Is_entity(buffer) ||			Is_pi(buffer) ||			Is_opaque(buffer));}BOOL Is_extension  (P_WBXML_INFO buffer){	WBXML_INFO tmpbuffer;	memcpy(&tmpbuffer, buffer, sizeof(WBXML_INFO));	tmpbuffer.m_curpos += SWITCHPAGE_SIZE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -