白帽子的未经授权渗透测试合法吗?(flas制作好学吗?)

白帽子的未经授权渗透测试合法吗?

严格来说 不合法 。

公司主营业务:成都网站设计、做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联推出霍山免费做网站回馈大家。

本人是一个网络安全爱好者,也算一个半吊子白帽子。不会挖掘很深层的漏洞,对代码理解并不透彻,但却在一些漏洞平台有着名号。

关于这个问题,可以关注我,看我头条号的一片文章:

你真的了解《网络安全法》吗?

《网络安全法》第二规定:任何个人和组织不得从事非法侵入他人网络、干扰他人网络正常功能、网络数据等危害网络安全的活动。 现在的白帽子更加注重法律这一关,漏洞都会在官方厂商SRC上提交,避免引起不必要的误会。

flas制作好学吗?

flash因为各种安全漏洞频出,已经明确的被苹果、谷歌、微软列为未来淘汰产品了,Adobe已经正式声明将于2020年结束对flash的支持,各浏览器的支持也将会在2020年底彻底结束,未来将正式被HTML5等新技术所取代。下面引用一篇文章来帮你介绍一下各种替代flash的技术,希望对你的学习方向有所帮助。

Flash 的替代技术

-------2 年前 · 来自专栏 极光日报

简评:Flash 在过去的十几年里为我们提供了动画、视频、游戏,当然还有广告。但现在 Flash 退出历史舞台的时机已经来了,那么哪些技术未来将替代 Flash?

Web 动画

CSS

CSS animation 实现 Web 动画最简单的一种。随着 CSS3 的发布,动画也已经被加入到了标准之中。Mozilla 也推出了相关的文档,网络上也有很多的开源项目可以使用。

JavaScript

通过 HTML5 的 标签,开发者可以通过 JavaScript 绘制图形、变换颜色、透明度、图片等等。JavaScript 可以使用 SVG 来实现动画,SVG 相较于其他的方案拥有很多优点 - 可随意缩放而不影响显示效果、所占空间更小、更好的显示效果和更强的颜色控制。很多人可能没有意识到 SVG 能够实现多么优秀的动画效果,可以看看这个。

当然新的 Web Animations API 也非常强大。

Web 游戏

在过去的一段时间 Flash 统治了 Web 游戏界,但在今天结合 JavaScript, HTML5, WebGL 和WebAssembly 等技术已经完全能提供更好的体验,甚至还可以使用 WebVR 和 A-Frame 来构建 Web VR 应用。

Mozilla 为开发者们提供了一份开发 Web 游戏的技术清单,内容包括:

WebGL

HTML audio

Web Audio API

WebSockets

WebRTC

WebAssembly

视频

一直以来 Flash 视频播放都有发热严重等各种问题,而新一代的视频编解码器可以使用硬件渲染,大大提高了效率。不太好的就是要从 Flash 切换到 HTML5 只能将视频重新编码。可以通过 FFmpeg 和 Handbrake 这样的免费工具进行转码。

而 HTML 5 内置多媒体控件,因此无需用户安装任何额外的播放器,只需要像下面这样:

当然,你也可以自定义样式,来保证不同浏览器之间的外观和表现一致。

MDN 也提供了 Flash 迁移到 HTML5 的指南。

现在 Flash 已经注定被抛弃了,赶紧学习下新技术吧。

原文:Life After Flash: Multimedia for the Open Web

当年熊猫烧香电脑病毒到底有多可怕?

说起熊猫烧香,我就想起当年在办公室文员小姐姐的一幕:

把前台电脑桌面上的所有图标都换成熊猫烧香后关机,想看看小姐姐遇到传说中的熊猫烧香病毒会有什么反应。结果那天一早,老板就拿了一份文件让她打印,打开电脑的那一刻,老板就在旁边看着……

最后我的恶作剧被老板请来的电脑维修员识破,我被训斥了一顿,还被罚前台接。

转眼间十几年过去了,回想当初熊猫烧香病毒肆虐的时候,我们公司的电脑没有被感染,我身边的朋友也没有被感染,所以如果要问那个病毒有多可怕,我还真没感觉出来,因为那几年的电脑病毒实在太多了!

曾经的电脑病毒

我最早是九十年始接触电脑,那个时候只能在DOS下操作,想要进入某个程序就要记住它的英文名字,而且没有鼠标,所以经历过那段时期的人,如今都可以用纯键盘对电脑进行基本操作。

2002年,我拥有了自己的电脑,那时候比较流行的系统是WIN98,当然也有人喜欢用WIN ME。那个时候的宽带还没普及,曾经有一段时期,我都是用,也是从连接上互联网的那一刻开始,各种奇葩的病毒就出现了。

那时候的电脑配置很低,如果不小心点进有病毒的网页,很容易就出现“假死机”状态,这时候想要关闭网页也要等很久,硬盘呼呼呼地响着,等你把所有自动弹出来的网页关闭后会发现,电脑桌面上已经铺满了各种网页的快捷图标。

如果只是添加快捷图标到桌面上,这也不算什么大问题,最可怕的是这些病毒已经修改了系统的注册表,让你每次开机都自动打开那些网页,删都删不掉……

那时候这种病毒非常普遍,相信很多人都遇到过,至少我身边的朋友叫我过去修电脑的时候,基本上都是类似这样的情况。于是,大家就习惯了用GHOST备份系统,这是一种非常方便的系统恢复工具,只要把新系统和所有需要的应用软件都装在C盘,然后用GHOST备份整个C盘,下次有问题直接恢复就可以了。

看似万无一失的系统备份工具,最终却败在了熊猫烧香手里。

2006年12月,湖北仙桃的李俊为了表现自己的计算机能力,制造出了“熊猫烧香病毒”。这种病毒不但能够感染exe、com、html等文件,最要命的是它会找到硬盘里的gho备份文件,并删除掉!

熊猫烧香病毒除了会删除GHO文件以外,还具有超强的传播能力,几乎把当时所有可以传播的途径都用上了:网页传播、EXE执行文件传播、U盘传播、auto传播等等。广泛的传播途径,使得熊猫烧香病毒能够在短短的一个多月时间里,感染高达数百万个人用户的电脑,甚至很多企业用户和机关单位的电脑也纷纷中招。

熊猫烧香病毒中毒后的表现,开始是电脑速度非常慢,进入系统后会发现桌面上的图标都变成熊猫举着三根香的图片,所有文件无法执行,杀毒软件被关闭,硬盘里的数据被破坏,电脑会出现蓝屏和频繁重启。

病毒作者陈俊最初只是为了炫耀自己的技术才制造出这个病毒,但是后来网络上出现了很多“变种病毒”,有人在病毒里添加了自己的代码,让中毒的电脑自动下载指定的文件,或者点击指定的广告,从中获取利益。

从熊猫烧香病毒发作的症状来看,应该是当时网络上流行的多种病毒的集合体,理论上来说当时的杀毒软件应该可以对付这种病毒,遗憾的是,在熊猫烧香病毒横行的那段时间里,没有一个杀毒软件是它的对手。

卡巴斯基在那个时代也算是杀毒软件的大佬,它在查杀病毒时发出的声音被网友比喻成“猪叫声”。熊猫烧香病毒流行的时候,一些学校机房、公司办公室等场所不断地传出这种猪的惨叫声,但最终都没能杀掉病毒,反而是杀毒软件被病毒给关闭了。

2007年2月3日,李俊被公安机关抓获,湖北省仙桃市法院以破坏计算机系统罪将他判处有期徒刑四年。李俊也在公安人员的监督下,编写了熊猫烧香的专杀工具,至此熊猫烧香事件才告一段落,后来网络上出现了“金猪报喜”病毒也是熊猫烧香的变种,不过当时的杀毒软件厂商已经有了经验,该变种并没有造成多大的影响。

熊猫烧香病毒可怕吗?

如果要问经历过熊猫烧香病毒的人,我相信会得到两种答案:

一种是电脑上没有重要文件,对于电脑重装完全无所谓的用户,对他们来说熊猫烧香病毒跟平时遇到的病毒差不多,大不了整个硬盘重新分区格式化就解决了;另一种是电脑上有重要文件的用户,病毒导致他们文件丢失,造成了巨大的经济损失,这些人谈到熊猫烧香无不咬牙切齿。

所以电脑病毒可不可怕,关键还是看病毒对用户造成了多大的损失。一直以来,电脑病毒制造者都是受利益驱使,才会制造病毒出来,比如病毒在后台悄悄运行,用户有价值的资料,或者在后台自动执行自己的任务,点击广告等,这些病毒会给制造者带来经济收益。

最麻烦的就是不受利益驱使,纯粹为了表现制作者技术的病毒,熊猫烧香就是其中之一,还有一种更厉害的病毒叫“CIH”,这种病毒不仅会造成用户数据丢失,还不给用户重装的机会!

CIH病毒我没遇到过,但是在我的印象中这是一种可怕的病毒,传说它发作的时候可以烧掉电脑主板。

CIH病毒的制造者叫陈盈豪,他也是为了炫耀自己的电脑技术,写出了这个病毒。该病毒发作的时候硬盘数据全部丢失,主板上的BIOS内容也会被破坏,此时电脑连开机画面都进不去!想要拆机给主板放电?没用,那个时候的主板没有备份BIOS程序,一旦内容被擦除,只能返回厂家用特殊工具重新烧入数据。

结语

记得以前在培训机构学电脑的时候,老师曾说过,电脑程序就像是一条条的链子,如果每个链子都非常完美地扣在一起,那就不会出现问题。如果某个链子松了,或者有了裂缝,其他的链子就有机会扣进来,这就是病毒。

如今计算机和互联网相关的法律不断完善,对于处罚计算机犯罪的行为也有法可依,近几年来电脑病毒也似乎在互联网上销声匿迹了。大家觉得电脑病毒的减少,是法律完善的原因,还是杀毒软件的功劳呢?欢迎在下方评论留言。

领导坚持用char而不用string?

早期写的string基础类,分享给大家参考

先是头文件:

//--------------------------------------------------------------------------

// ◊÷∑˚¥Æ¿‡…˘√˜

//

//

// 2000ƒÍ6‘¬6»’

//--------------------------------------------------------------------------

#ifndef _c_stringH

#define _c_stringH

#include "cmpublic.h"

#define EmptyString GetEmptyString()

struct TSStringData

{

long nRefs; // reference count

long nDataLength;

long nAllocLength;

// char data[nAllocLength]

char * data()

{ return (char *)(this+1); }

};

class TCString

{

public:

// Constructors

TCString();

TCString(const TCString& stringSrc);

TCString(char * lpsz);

TCString(char * lpsz,long nLen);

TCString(char ch) ;

TCString(char c, long nCount) ;

// TCString(const unsigned char* psz);

// Attributes & Operations

// as an array of characters

long GetLength() const

{

return GetData()->nDataLength;

};

inline bool IsEmpty()

{

return GetData()->nDataLength == 0;

}

void Empty(); // free up the data

char GetAt(long nIndex) const; // 1 based

char operator[](long nIndex) const; // same as GetAt

void SetAt(long nIndex, char ch);

operator char*() const; // as a C string

// overloaded assignment

const TCString& operator=(const TCString& stringSrc);

const TCString& operator=(char ch);

const TCString& operator=(char* lpsz);

// const TCString& operator=(const unsigned char* psz);

// string concatenation

const TCString& operator+=(const TCString& m_string);

const TCString& operator+=(char ch);

const TCString& operator+=(char * lpsz);

friend TCString operator+(const TCString& string1,

const TCString& string2);

friend TCString operator+(const TCString& string, char ch);

friend TCString operator+(char ch, const TCString& string);

friend TCString operator+(const TCString& string, char * lpsz);

friend TCString operator+(char * lpsz, const TCString& string);

// string comparison

inline long Compare(char * lpsz) const // straight character

{

return strcmp(m_pchData, lpsz);

};

inline long CompareNoCase(char * lpsz) const // ignore case

{

#ifdef __WIN32__

return stricmp(m_pchData, lpsz);

#else

return strcasecmp(m_pchData, lpsz);

#endif

};

// simple sub-string extraction

TCString Mid(long nFirst, long nCount) const;

TCString Mid(long nFirst) const;

TCString Left(long nCount) const;

TCString Right(long nCount) const;

// upper/lower/reverse conversion

void MakeUpper();

void MakeLower();

void MakeReverse();

// trimming whitespace (either side)

void TrimRight();

void TrimLeft();

// searching (return starting index, or -1 if not found)

// look for a single character match

long Find(char ch) const; // like "C" strchr , 1 base

long ReverseFind(char ch) const;

long FindOneOf(char * lpszCharSet) const;

// look for a specific sub-string

long Find(char * lpszSub) const; // like "C" strstr

// Access to string implementation buffer as "C" character array

char * GetBuffer(long nMinBufLength);

void ReleaseBuffer(long nNewLength = -1);

char * GetBufferSetLength(long nNewLength);

void FreeExtra();

// Use LockBuffer/UnlockBuffer to turn refcounting off

char * LockBuffer();

void UnlockBuffer();

// Implementation

public:

~TCString();

long GetAllocLength() const;

void CutNewLineChar() ;

inline long ToInt(void) const

{

return atol(m_pchData) ;

}

inline double ToFloat(void) const

{

return atof(m_pchData) ;

}

inline long SetIntToStr(long i)

{

char aResult[20] ;

long nlen ;

nlen = sprintf(aResult,"%d",i) ;

if ( nlen > 0 )

AssignCopy(nlen, aResult);

return nlen ;

}

inline void aCharToString(char *srcChar ,long nlen)

{

AssignCopy(nlen, srcChar) ;

}

protected:

char * m_pchData; // pointer to ref counted string data

// implementation helpers

TSStringData* GetData() const;

void Init();

void AllocCopy(TCString& dest, long nCopyLen, long nCopyIndex, long nExtraLen) const;

void AllocBuffer(long nLen);

void AssignCopy(long nSrcLen, char * lpszSrcData);

void ConcatCopy(long nSrc1Len, char * lpszSrc1Data, long nSrc2Len, char * lpszSrc2Data);

void ConcatInPlace(long nSrcLen, char * lpszSrcData);

void CopyBeforeWrite();

void AllocBeforeWrite(long nLen);

void Release();

static void Release(TSStringData* pData) ;

static long SafeStrlen(char * lpsz);

};

const TCString& GetEmptyString();

inline bool operator==(const TCString& s1, const TCString& s2)

{

return s1.Compare(s2) == 0;

}

inline bool operator==(const TCString& s1, char * s2)

{

return s1.Compare(s2) == 0 ;

}

inline bool operator==(char * s1, const TCString& s2)

{

return s2.Compare(s1) == 0;

}

inline bool operator!=(const TCString& s1, const TCString& s2)

{

return s1.Compare(s2) != 0;

}

inline bool operator!=(const TCString& s1, char * s2)

{

return s1.Compare(s2) != 0;

}

inline bool operator!=(char * s1, const TCString& s2)

{

return s2.Compare(s1) != 0;

}

inline bool operator<(const TCString& s1, const TCString& s2)

{

return s1.Compare(s2) < 0;

}

inline bool operator<(const TCString& s1, char * s2)

{

return s1.Compare(s2) < 0;

}

inline bool operator<(char * s1, const TCString& s2)

{

return s2.Compare(s1) > 0;

}

inline bool operator>(const TCString& s1, const TCString& s2)

{

return s1.Compare(s2) > 0;

}

inline bool operator>(const TCString& s1, char * s2)

{

return s1.Compare(s2) > 0;

}

inline bool operator>(char * s1, const TCString& s2)

{

return s2.Compare(s1) < 0;

}

inline bool operator<=(const TCString& s1, const TCString& s2)

{

return s1.Compare(s2) <= 0;

}

inline bool operator<=(const TCString& s1, char * s2)

{

return s1.Compare(s2) <= 0;

}

inline bool operator<=(char * s1, const TCString& s2)

{

return s2.Compare(s1) >= 0;

}

inline bool operator>=(const TCString& s1, const TCString& s2)

{

return s1.Compare(s2) >= 0;

}

inline bool operator>=(const TCString& s1, char * s2)

{

return s1.Compare(s2) >= 0;

}

inline bool operator>=(char * s1, const TCString& s2)

{

return s2.Compare(s1) <= 0;

}

#endif

下面是cpp

#include "cmpublic.h"

static long sa_InitData[] = { -1, 0, 0, 0 };

static TSStringData* pStringDataNil = (TSStringData*)&sa_InitData;

static char * pStringNil = (char * )(((char *)&sa_InitData)+sizeof(TSStringData));

// special function to make EmptyString work even during initialization

const TCString& GetEmptyString()

{

return *(TCString*)&pStringNil;

}

TCString::TCString()

{

Init();

}

TCString::TCString(const TCString& stringSrc)

{

ASSERT(stringSrc.GetData()->nRefs != 0);

if (stringSrc.GetData()->nRefs >= 0)

{

ASSERT(stringSrc.GetData() != pStringDataNil);

m_pchData = stringSrc.m_pchData;

// InterlockedIncrement(&GetData()->nRefs);

GetData()->nRefs += 1 ;

}

else

{

Init();

*this = stringSrc.m_pchData;

}

}

//////////////////////////////////////////////////////////////////////////////

// More sophisticated construction

TCString::TCString(char ch)

{

Init();

long nLen = 1 ;

AllocBuffer(nLen) ;

m_pchData[0] = ch ;

}

TCString::TCString(char c, long nCount)

{

Init();

if (nCount != 0)

{

AllocBuffer(nCount);

memset(m_pchData, c, nCount);

}

}

TCString::TCString(char * lpsz)

{

Init();

long nLen = SafeStrlen(lpsz);

if (nLen != 0)

{

AllocBuffer(nLen);

memcpy(m_pchData, lpsz, nLen*sizeof(char));

}

}

TCString::TCString(char * lpsz,long nLen)

{

Init();

if (nLen > 0)

{

AllocBuffer(nLen);

memcpy(m_pchData, lpsz, nLen);

}

}

void TCString::AllocBuffer(long nLen)

// always allocate one extra character for '\0' termination

// assumes [optimistically] that data length will equal allocation length

{

ASSERT(nLen >= 0);

ASSERT(nLen <= LONG_MAX-1); // max size (enough room for 1 extra)

long nNewAllocSize;

if (nLen == 0)

Init();

else

{

if (nLen > 64)

nNewAllocSize = nLen + nLen / 4;

else

if (nLen > 8)

nNewAllocSize = nLen + 16;

else

nNewAllocSize = nLen + 4;

TSStringData* pData =

(TSStringData*)new char[sizeof(TSStringData) + (nNewAllocSize+1)*sizeof(char)];

if( pData == NULL )

{

Init();

throw TCException("Alloc mem error!");

}

pData->nRefs = 1;

pData->data()[nLen] = '\0';

pData->nDataLength = nLen;

pData->nAllocLength = nNewAllocSize;

m_pchData = pData->data();

}

}

void TCString::Release()

{

if (GetData() != pStringDataNil)

{

ASSERT(GetData()->nRefs != 0);

GetData()->nRefs -= 1 ;

// if (InterlockedDecrement(&GetData()->nRefs) <= 0)

if (GetData()->nRefs <= 0 )

delete[] (char *)GetData();

Init();

}

}

void TCString::Release(TSStringData* pData)

{

if (pData != pStringDataNil)

{

ASSERT(pData->nRefs != 0);

// if (InterlockedDecrement(&pData->nRefs) <= 0)

pData->nRefs -= 1 ;

if (pData->nRefs <= 0)

delete[] (char *)pData;

}

}

void TCString::Empty()

{

if (GetData()->nRefs >= 0)

Release();

else

*this = pStringNil;

ASSERT(GetData()->nDataLength == 0);

ASSERT(GetData()->nRefs < 0 || GetData()->nAllocLength == 0);

}

void TCString::CopyBeforeWrite()

{

if (GetData()->nRefs > 1)

{

TSStringData* pData = GetData();

AllocBuffer(pData->nDataLength);

memcpy(m_pchData, pData->data(), (pData->nDataLength+1)*sizeof(char));

Release(pData);

}

ASSERT(GetData()->nRefs <= 1);

}

void TCString::AllocBeforeWrite(long nLen)

{

if (GetData()->nRefs > 1 || nLen > GetData()->nAllocLength)

{

Release();

AllocBuffer(nLen);

}

ASSERT(GetData()->nRefs <= 1);

}

TCString::~TCString()

// free any attached data

{

if (GetData() != pStringDataNil)

{

// if (InterlockedDecrement(&GetData()->nRefs) <= 0)

GetData()->nRefs -= 1 ;

if (GetData()->nRefs <= 0)

delete[] (char*)GetData();

}

}

//////////////////////////////////////////////////////////////////////////////

// Helpers for the rest of the implementation

void TCString::AllocCopy(TCString& dest, long nCopyLen, long nCopyIndex,

long nExtraLen) const

{

// will clone the data attached to this string

// allocating 'nExtraLen' characters

// Places results in uninitialized string 'dest'

// Will copy the part or all of original data to start of new string

long nNewLen = nCopyLen + nExtraLen;

if (nNewLen == 0)

{

dest.Init();

}

else

{

dest.AllocBuffer(nNewLen);

memcpy(dest.m_pchData, m_pchData+nCopyIndex, nCopyLen*sizeof(char));

}

}

//////////////////////////////////////////////////////////////////////////////

// Assignment operators

// All assign a new value to the string

// (a) first see if the buffer is big enough

// (b) if enough room, copy on top of old buffer, set size and type

// (c) otherwise free old string data, and create a new one

//

// All routines return the new string (but as a 'const TCString&' so that

// assigning it again will cause a copy, eg: s1 = s2 = "hi there".

//

void TCString::AssignCopy(long nSrcLen, char * lpszSrcData)

{

AllocBeforeWrite(nSrcLen);

memcpy(m_pchData, lpszSrcData, nSrcLen*sizeof(char));

GetData()->nDataLength = nSrcLen;

m_pchData[nSrcLen] = '\0';

}

const TCString& TCString::operator=(const TCString& stringSrc)

{

if (m_pchData != stringSrc.m_pchData)

{

if ((GetData()->nRefs < 0 && GetData() != pStringDataNil) ||

stringSrc.GetData()->nRefs < 0)

{

// actual copy necessary since one of the strings is locked

AssignCopy(stringSrc.GetData()->nDataLength, stringSrc.m_pchData);

}

else

{

// can just copy references around

Release();

ASSERT(stringSrc.GetData() != pStringDataNil);

m_pchData = stringSrc.m_pchData;

// InterlockedIncrement(&GetData()->nRefs);

GetData()->nRefs += 1 ;

}

}

return *this;

}

const TCString& TCString::operator=(char * lpsz)

{

ASSERT(lpsz != NULL);

AssignCopy(SafeStrlen(lpsz), lpsz);

return *this;

}

const TCString& TCString::operator=(char ch)

{

// ASSERT(!_istlead(ch)); can't set single lead byte

AssignCopy(1, &ch);

return *this;

}

TCString operator+(const TCString& string1, char ch)

{

TCString s;

s.ConcatCopy(string1.GetData()->nDataLength, string1.m_pchData, 1, &ch);

return s;

}

TCString operator+(char ch, const TCString& string)

{

TCString s;

s.ConcatCopy(1, &ch, string.GetData()->nDataLength, string.m_pchData);

return s;

}

//////////////////////////////////////////////////////////////////////////////

// Very simple sub-string extraction

TCString TCString::Mid(long nFirst) const

{

return Mid(nFirst, GetData()->nDataLength - nFirst + 1);

}

TCString TCString::Mid(long nFirst, long nCount) const

{

// out-of-bounds requests return sensible things

ASSERT( nFirst > 0 );

if (nFirst <= 0)

nFirst = 1;

if (nCount < 0)

nCount = 0;

nFirst -= 1;

if (nFirst + nCount > GetData()->nDataLength)

nCount = GetData()->nDataLength - nFirst ;

if (nFirst > GetData()->nDataLength)

nCount = 0;

TCString dest;

AllocCopy(dest, nCount, nFirst, 0);

return dest;

}

TCString TCString::Right(long nCount) const

{

if (nCount < 0)

nCount = 0;

else if (nCount > GetData()->nDataLength)

nCount = GetData()->nDataLength;

TCString dest;

AllocCopy(dest, nCount, GetData()->nDataLength-nCount, 0);

return dest;

}

TCString TCString::Left(long nCount) const

{

if (nCount < 0)

nCount = 0;

else if (nCount > GetData()->nDataLength)

nCount = GetData()->nDataLength;

TCString dest;

AllocCopy(dest, nCount, 0, 0);

return dest;

}

void TCString::ConcatCopy(long nSrc1Len, char * lpszSrc1Data,

long nSrc2Len, char * lpszSrc2Data)

{

// -- master concatenation routine

// Concatenate two sources

// -- assume that 'this' is a new TCString object

long nNewLen = nSrc1Len + nSrc2Len;

if (nNewLen != 0)

{

AllocBuffer(nNewLen);

memcpy(m_pchData, lpszSrc1Data, nSrc1Len*sizeof(char));

memcpy(m_pchData+nSrc1Len, lpszSrc2Data, nSrc2Len*sizeof(char));

}

}

TCString operator+(const TCString& string1, const TCString& string2)

{

TCString s;

s.ConcatCopy(string1.GetData()->nDataLength, string1.m_pchData,

string2.GetData()->nDataLength, string2.m_pchData);

return s;

}

TCString operator+(const TCString& string, char * lpsz)

{

ASSERT(lpsz != NULL);

TCString s;

s.ConcatCopy(string.GetData()->nDataLength, string.m_pchData,

TCString::SafeStrlen(lpsz), lpsz);

return s;

}

TCString operator+(char * lpsz, const TCString& string)

{

ASSERT(lpsz != NULL);

TCString s;

s.ConcatCopy(TCString::SafeStrlen(lpsz), lpsz, string.GetData()->nDataLength,

string.m_pchData);

return s;

}

//////////////////////////////////////////////////////////////////////////////

// concatenate in place

void TCString::ConcatInPlace(long nSrcLen, char * lpszSrcData)

{

// -- the main routine for += operators

// concatenating an empty string is a no-op!

if (nSrcLen == 0)

return;

// if the buffer is too small, or we have a width mis-match, just

// allocate a new buffer (slow but sure)

if (GetData()->nRefs > 1 || (GetData()->nDataLength + nSrcLen) > GetData()->nAllocLength)

{

// we have to grow the buffer, use the ConcatCopy routine

TSStringData* pOldData = GetData();

ConcatCopy(GetData()->nDataLength, m_pchData, nSrcLen, lpszSrcData);

ASSERT(pOldData != NULL);

TCString::Release(pOldData);

}

else

{

// fast concatenation when buffer big enough

memcpy(m_pchData+GetData()->nDataLength, lpszSrcData, nSrcLen*sizeof(char));

GetData()->nDataLength += nSrcLen;

ASSERT(GetData()->nDataLength <= GetData()->nAllocLength);

m_pchData[GetData()->nDataLength] = '\0';

}

}

const TCString& TCString::operator+=(char * lpsz)

{

ASSERT(lpsz != NULL);

ConcatInPlace(SafeStrlen(lpsz), lpsz);

return *this;

}

const TCString& TCString::operator+=(char ch)

{

ConcatInPlace(1, &ch);

return *this;

}

const TCString& TCString::operator+=(const TCString& m_string)

{

ConcatInPlace(m_string.GetData()->nDataLength, m_string.m_pchData);

return *this;

}

///////////////////////////////////////////////////////////////////////////////

// Advanced direct buffer access

char * TCString::GetBuffer(long nMinBufLength)

{

ASSERT(nMinBufLength >= 0);

if (GetData()->nRefs > 1 || nMinBufLength > GetData()->nAllocLength)

{

// we have to grow the buffer

TSStringData* pOldData = GetData();

int nOldLen = GetData()->nDataLength; // AllocBuffer will tromp it

if (nMinBufLength < nOldLen)

nMinBufLength = nOldLen;

AllocBuffer(nMinBufLength);

memcpy(m_pchData, pOldData->data(), (nOldLen+1)*sizeof(char));

GetData()->nDataLength = nOldLen;

TCString::Release(pOldData);

}

ASSERT(GetData()->nRefs <= 1);

// return a pointer to the character storage for this string

ASSERT(m_pchData != NULL);

return m_pchData;

}

void TCString::ReleaseBuffer(long nNewLength)

{

CopyBeforeWrite(); // just in case GetBuffer was not called

if (nNewLength == -1)

nNewLength = strlen(m_pchData); // zero terminated

ASSERT(nNewLength <= GetData()->nAllocLength);

GetData()->nDataLength = nNewLength;

m_pchData[nNewLength] = '\0';

}

char * TCString::GetBufferSetLength(long nNewLength)

{

ASSERT(nNewLength >= 0);

GetBuffer(nNewLength);

GetData()->nDataLength = nNewLength;

m_pchData[nNewLength] = '\0';

return m_pchData;

}

void TCString::FreeExtra()

{

ASSERT(GetData()->nDataLength <= GetData()->nAllocLength);

if (GetData()->nDataLength != GetData()->nAllocLength)

{

TSStringData* pOldData = GetData();

AllocBuffer(GetData()->nDataLength);

memcpy(m_pchData, pOldData->data(), pOldData->nDataLength*sizeof(char));

ASSERT(m_pchData[GetData()->nDataLength] == '\0');

TCString::Release(pOldData);

}

ASSERT(GetData() != NULL);

}

char * TCString::LockBuffer()

{

char * lpsz = GetBuffer(0);

GetData()->nRefs = -1;

return lpsz;

}

void TCString::UnlockBuffer()

{

ASSERT(GetData()->nRefs == -1);

if (GetData() != pStringDataNil)

GetData()->nRefs = 1;

}

///////////////////////////////////////////////////////////////////////////////

// Commonly used routines (rarely used routines in STREX.CPP)

long TCString::Find(char ch) const

{

// find first single character

char * lpsz = strchr(m_pchData, ch);

// return -1 if not found and index otherwise

return (lpsz == NULL) ? -1 : (long)(lpsz - m_pchData + 1);

}

long TCString::ReverseFind(char ch) const

{

// find last single character

char * lpsz = strrchr(m_pchData, ch);

// return -1 if not found, distance from beginning otherwise

return (lpsz == NULL) ? -1 : (long)(lpsz - m_pchData + 1);

}

// find a sub-string (like strstr)

long TCString::Find(char * lpszSub) const

{

ASSERT(lpszSub != NULL);

// find first matching substring

char * lpsz = strstr(m_pchData, lpszSub);

// return -1 for not found, distance from beginning otherwise

return (lpsz == NULL) ? -1 : (long)(lpsz - m_pchData + 1);

}

long TCString::FindOneOf(char * lpszCharSet) const

{

ASSERT(lpszCharSet != NULL);

char * lpsz = strpbrk(m_pchData, lpszCharSet);

return (lpsz == NULL) ? -1 : (long)(lpsz - m_pchData+1);

}

void TCString::MakeUpper()

{

CopyBeforeWrite();

for (long i = 0;i< GetLength() ; i++)

{

if ((*(m_pchData+i) >= 'a')&&*(m_pchData+i) <= 'z')

{

*(m_pchData+i) = char(*(m_pchData+i) + 'A' -'a') ;

}

}

}

void TCString::MakeLower()

{

CopyBeforeWrite();

for (long i = 0;i< GetLength() ; i++)

{

if ((*(m_pchData+i) >= 'A')&&*(m_pchData+i) <= 'Z')

{

*(m_pchData+i) = char(*(m_pchData+i) + 'a' -'A') ;

}

}

}

void TCString::MakeReverse()

{

CopyBeforeWrite();

char ch ;

for (long i=0;i

{

ch = *(m_pchData+i) ;

*(m_pchData+i) = *(m_pchData+GetLength()-i);

*(m_pchData+GetLength()-i) = ch ;

}

}

void TCString::SetAt(long nIndex, char ch)

{

ASSERT(nIndex > 0);

ASSERT(nIndex <= GetData()->nDataLength);

CopyBeforeWrite();

m_pchData[nIndex - 1] = ch;

}

void TCString::TrimRight()

{

CopyBeforeWrite();

// find beginning of trailing spaces by starting at beginning (DBCS aware)

char * lpsz = m_pchData;

char * lpszLast = NULL;

while (*lpsz != '\0')

{

if ( (*lpsz == 0x20)||(*lpsz == 0x09) )

{

if (lpszLast == NULL)

lpszLast = lpsz;

}

else

lpszLast = NULL;

lpsz = lpsz + 1 ;

}

if (lpszLast != NULL)

{

// truncate at trailing space start

*lpszLast = '\0';

GetData()->nDataLength = lpszLast - m_pchData;

}

}

void TCString::TrimLeft()

{

CopyBeforeWrite();

// find first non-space character

char * lpsz = m_pchData;

while ( (*lpsz == 0x20)||(*lpsz == 0x09) )

lpsz = lpsz + 1;

// fix up data and length

int nDataLength = GetData()->nDataLength - (lpsz - m_pchData);

memmove(m_pchData, lpsz, (nDataLength+1)*sizeof(char));

GetData()->nDataLength = nDataLength;

}

long TCString::GetAllocLength() const

{

return GetData()->nAllocLength;

}

TCString::operator char*() const

{

return m_pchData;

}

long TCString::SafeStrlen(char * lpsz)

{

return (lpsz == NULL) ? 0 : strlen(lpsz);

}

TSStringData* TCString::GetData() const

{

ASSERT(m_pchData != NULL);

return ((TSStringData*)m_pchData)-1;

}

void TCString::Init()

{

m_pchData = EmptyString.m_pchData;

}

char TCString::GetAt(long nIndex) const

{

ASSERT(nIndex > 0);

ASSERT(nIndex <= GetData()->nDataLength);

return m_pchData[nIndex - 1];

}

char TCString::operator[](long nIndex) const

{

// same as GetAt

ASSERT(nIndex > 0);

ASSERT(nIndex <= GetData()->nDataLength);

return m_pchData[nIndex - 1];

}

void TCString::CutNewLineChar()

{

if ( m_pchData[GetData()->nDataLength - 1 ] == '\n' )

{

m_pchData[GetData()->nDataLength-1] ='\0' ;

GetData()->nDataLength -= 1 ;

}

}

分享标题:白帽子的未经授权渗透测试合法吗?(flas制作好学吗?)
文章网址:http://www.hantingmc.com/qtweb/news17/485167.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联