PageRenderTime 75ms CodeModel.GetById 61ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/ghost/util.h

http://ghostcb.googlecode.com/
C++ Header | 98 lines | 56 code | 17 blank | 25 comment | 0 complexity | d1accbe05d6b83feb6d968945e03cef2 MD5 | raw file
 1/*
 2
 3   Copyright [2008] [Trevor Hogan]
 4
 5   Licensed under the Apache License, Version 2.0 (the "License");
 6   you may not use this file except in compliance with the License.
 7   You may obtain a copy of the License at
 8
 9       http://www.apache.org/licenses/LICENSE-2.0
10
11   Unless required by applicable law or agreed to in writing, software
12   distributed under the License is distributed on an "AS IS" BASIS,
13   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   See the License for the specific language governing permissions and
15   limitations under the License.
16
17   CODE PORTED FROM THE ORIGINAL GHOST PROJECT: http://ghost.pwner.org/
18
19*/
20
21#ifndef UTIL_H
22#define UTIL_H
23
24// byte arrays
25
26BYTEARRAY UTIL_CreateByteArray( unsigned char *a, int size );
27BYTEARRAY UTIL_CreateByteArray( unsigned char c );
28BYTEARRAY UTIL_CreateByteArray( uint16_t i, bool reverse );
29BYTEARRAY UTIL_CreateByteArray( uint32_t i, bool reverse );
30uint16_t UTIL_ByteArrayToUInt16( BYTEARRAY b, bool reverse, unsigned int start = 0 );
31uint32_t UTIL_ByteArrayToUInt32( BYTEARRAY b, bool reverse, unsigned int start = 0 );
32string UTIL_ByteArrayToDecString( BYTEARRAY b );
33string UTIL_ByteArrayToHexString( BYTEARRAY b );
34void UTIL_AppendByteArray( BYTEARRAY &b, BYTEARRAY append );
35void UTIL_AppendByteArrayFast( BYTEARRAY &b, BYTEARRAY &append );
36void UTIL_AppendByteArray( BYTEARRAY &b, unsigned char *a, int size );
37void UTIL_AppendByteArray( BYTEARRAY &b, string append, bool terminator = true );
38void UTIL_AppendByteArrayFast( BYTEARRAY &b, string &append, bool terminator = true );
39void UTIL_AppendByteArray( BYTEARRAY &b, uint16_t i, bool reverse );
40void UTIL_AppendByteArray( BYTEARRAY &b, uint32_t i, bool reverse );
41BYTEARRAY UTIL_ExtractCString( BYTEARRAY &b, unsigned int start );
42unsigned char UTIL_ExtractHex( BYTEARRAY &b, unsigned int start, bool reverse );
43BYTEARRAY UTIL_ExtractNumbers( string s, unsigned int count );
44BYTEARRAY UTIL_ExtractHexNumbers( string s );
45
46// conversions
47
48string UTIL_ToString( unsigned long i );
49string UTIL_ToString( unsigned short i );
50string UTIL_ToString( unsigned int i );
51string UTIL_ToString( long i );
52string UTIL_ToString( short i );
53string UTIL_ToString( int i );
54string UTIL_ToString( float f, int digits );
55string UTIL_ToString( double d, int digits );
56string UTIL_ToHexString( uint32_t i );
57uint16_t UTIL_ToUInt16( string &s );
58uint32_t UTIL_ToUInt32( string &s );
59int16_t UTIL_ToInt16( string &s );
60int32_t UTIL_ToInt32( string &s );
61double UTIL_ToDouble( string &s );
62string UTIL_MSToString( uint32_t ms );
63
64void UTIL_Construct_UTF8_Latin1_Map( );
65string UTIL_Latin1ToUTF8( string &s );
66string UTIL_UTF8ToLatin1( string &s );
67
68unsigned long UTIL_ToULong( int i );
69
70// files
71
72bool UTIL_FileExists( string file );
73string UTIL_FileRead( string file, uint32_t start, uint32_t length );
74string UTIL_FileRead( string file );
75bool UTIL_FileWrite( string file, unsigned char *data, uint32_t length );
76string UTIL_FileSafeName( string fileName );
77string UTIL_AddPathSeperator( string path );
78
79// stat strings
80
81BYTEARRAY UTIL_EncodeStatString( BYTEARRAY &data );
82BYTEARRAY UTIL_DecodeStatString( BYTEARRAY &data );
83
84// other
85
86bool UTIL_IsLanIP( BYTEARRAY ip );
87bool UTIL_IsLocalIP( BYTEARRAY ip, vector<BYTEARRAY> &localIPs );
88void UTIL_Replace( string &Text, string Key, string Value );
89vector<string> UTIL_Tokenize( string s, char delim );
90
91// math
92
93uint32_t UTIL_Factorial( uint32_t x );
94
95#define nCr(n, r) (UTIL_Factorial(n) / UTIL_Factorial((n)-(r)) / UTIL_Factorial(r))
96#define nPr(n, r) (UTIL_Factorial(n) / UTIL_Factorial((n)-(r)))
97
98#endif