日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
白帽子的未經(jīng)授權(quán)滲透測試合法嗎?(flas制作好學嗎?)

白帽子的未經(jīng)授權(quán)滲透測試合法嗎?

嚴格來說 不合法 。

公司主營業(yè)務:成都網(wǎng)站設計、做網(wǎng)站、移動網(wǎng)站開發(fā)等業(yè)務。幫助企業(yè)客戶真正實現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。成都創(chuàng)新互聯(lián)是一支青春激揚、勤奮敬業(yè)、活力青春激揚、勤奮敬業(yè)、活力澎湃、和諧高效的團隊。公司秉承以“開放、自由、嚴謹、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領域給我們帶來的挑戰(zhàn),讓我們激情的團隊有機會用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)推出霍山免費做網(wǎng)站回饋大家。

本人是一個網(wǎng)絡安全愛好者,也算一個半吊子白帽子。不會挖掘很深層的漏洞,對代碼理解并不透徹,但卻在一些漏洞平臺有著名號。

關(guān)于這個問題,可以關(guān)注我,看我頭條號的一片文章:

你真的了解《網(wǎng)絡安全法》嗎?

《網(wǎng)絡安全法》第二規(guī)定:任何個人和組織不得從事非法侵入他人網(wǎng)絡、干擾他人網(wǎng)絡正常功能、網(wǎng)絡數(shù)據(jù)等危害網(wǎng)絡安全的活動。 現(xiàn)在的白帽子更加注重法律這一關(guān),漏洞都會在官方廠商SRC上提交,避免引起不必要的誤會。

flas制作好學嗎?

flash因為各種安全漏洞頻出,已經(jīng)明確的被蘋果、谷歌、微軟列為未來淘汰產(chǎn)品了,Adobe已經(jīng)正式聲明將于2020年結(jié)束對flash的支持,各瀏覽器的支持也將會在2020年底徹底結(jié)束,未來將正式被HTML5等新技術(shù)所取代。下面引用一篇文章來幫你介紹一下各種替代flash的技術(shù),希望對你的學習方向有所幫助。

Flash 的替代技術(shù)

-------2 年前 · 來自專欄 極光日報

簡評:Flash 在過去的十幾年里為我們提供了動畫、視頻、游戲,當然還有廣告。但現(xiàn)在 Flash 退出歷史舞臺的時機已經(jīng)來了,那么哪些技術(shù)未來將替代 Flash?

Web 動畫

CSS

CSS animation 實現(xiàn) Web 動畫最簡單的一種。隨著 CSS3 的發(fā)布,動畫也已經(jīng)被加入到了標準之中。Mozilla 也推出了相關(guān)的文檔,網(wǎng)絡上也有很多的開源項目可以使用。

JavaScript

通過 HTML5 的 標簽,開發(fā)者可以通過 JavaScript 繪制圖形、變換顏色、透明度、圖片等等。JavaScript 可以使用 SVG 來實現(xiàn)動畫,SVG 相較于其他的方案擁有很多優(yōu)點 - 可隨意縮放而不影響顯示效果、所占空間更小、更好的顯示效果和更強的顏色控制。很多人可能沒有意識到 SVG 能夠?qū)崿F(xiàn)多么優(yōu)秀的動畫效果,可以看看這個。

當然新的 Web Animations API 也非常強大。

Web 游戲

在過去的一段時間 Flash 統(tǒng)治了 Web 游戲界,但在今天結(jié)合 JavaScript, HTML5, WebGL 和WebAssembly 等技術(shù)已經(jīng)完全能提供更好的體驗,甚至還可以使用 WebVR 和 A-Frame 來構(gòu)建 Web VR 應用。

Mozilla 為開發(fā)者們提供了一份開發(fā) Web 游戲的技術(shù)清單,內(nèi)容包括:

WebGL

HTML audio

Web Audio API

WebSockets

WebRTC

WebAssembly

視頻

一直以來 Flash 視頻播放都有發(fā)熱嚴重等各種問題,而新一代的視頻編解碼器可以使用硬件渲染,大大提高了效率。不太好的就是要從 Flash 切換到 HTML5 只能將視頻重新編碼??梢酝ㄟ^ FFmpeg 和 Handbrake 這樣的免費工具進行轉(zhuǎn)碼。

而 HTML 5 內(nèi)置多媒體控件,因此無需用戶安裝任何額外的播放器,只需要像下面這樣:

當然,你也可以自定義樣式,來保證不同瀏覽器之間的外觀和表現(xiàn)一致。

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

現(xiàn)在 Flash 已經(jīng)注定被拋棄了,趕緊學習下新技術(shù)吧。

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

當年熊貓燒香電腦病毒到底有多可怕?

說起熊貓燒香,我就想起當年在辦公室文員小姐姐的一幕:

把前臺電腦桌面上的所有圖標都換成熊貓燒香后關(guān)機,想看看小姐姐遇到傳說中的熊貓燒香病毒會有什么反應。結(jié)果那天一早,老板就拿了一份文件讓她打印,打開電腦的那一刻,老板就在旁邊看著……

最后我的惡作劇被老板請來的電腦維修員識破,我被訓斥了一頓,還被罰前臺接。

轉(zhuǎn)眼間十幾年過去了,回想當初熊貓燒香病毒肆虐的時候,我們公司的電腦沒有被感染,我身邊的朋友也沒有被感染,所以如果要問那個病毒有多可怕,我還真沒感覺出來,因為那幾年的電腦病毒實在太多了!

曾經(jīng)的電腦病毒

我最早是九十年始接觸電腦,那個時候只能在DOS下操作,想要進入某個程序就要記住它的英文名字,而且沒有鼠標,所以經(jīng)歷過那段時期的人,如今都可以用純鍵盤對電腦進行基本操作。

2002年,我擁有了自己的電腦,那時候比較流行的系統(tǒng)是WIN98,當然也有人喜歡用WIN ME。那個時候的寬帶還沒普及,曾經(jīng)有一段時期,我都是用,也是從連接上互聯(lián)網(wǎng)的那一刻開始,各種奇葩的病毒就出現(xiàn)了。

那時候的電腦配置很低,如果不小心點進有病毒的網(wǎng)頁,很容易就出現(xiàn)“假死機”狀態(tài),這時候想要關(guān)閉網(wǎng)頁也要等很久,硬盤呼呼呼地響著,等你把所有自動彈出來的網(wǎng)頁關(guān)閉后會發(fā)現(xiàn),電腦桌面上已經(jīng)鋪滿了各種網(wǎng)頁的快捷圖標。

如果只是添加快捷圖標到桌面上,這也不算什么大問題,最可怕的是這些病毒已經(jīng)修改了系統(tǒng)的注冊表,讓你每次開機都自動打開那些網(wǎng)頁,刪都刪不掉……

那時候這種病毒非常普遍,相信很多人都遇到過,至少我身邊的朋友叫我過去修電腦的時候,基本上都是類似這樣的情況。于是,大家就習慣了用GHOST備份系統(tǒng),這是一種非常方便的系統(tǒng)恢復工具,只要把新系統(tǒng)和所有需要的應用軟件都裝在C盤,然后用GHOST備份整個C盤,下次有問題直接恢復就可以了。

看似萬無一失的系統(tǒng)備份工具,最終卻敗在了熊貓燒香手里。

2006年12月,湖北仙桃的李俊為了表現(xiàn)自己的計算機能力,制造出了“熊貓燒香病毒”。這種病毒不但能夠感染exe、com、html等文件,最要命的是它會找到硬盤里的gho備份文件,并刪除掉!

熊貓燒香病毒除了會刪除GHO文件以外,還具有超強的傳播能力,幾乎把當時所有可以傳播的途徑都用上了:網(wǎng)頁傳播、EXE執(zhí)行文件傳播、U盤傳播、auto傳播等等。廣泛的傳播途徑,使得熊貓燒香病毒能夠在短短的一個多月時間里,感染高達數(shù)百萬個人用戶的電腦,甚至很多企業(yè)用戶和機關(guān)單位的電腦也紛紛中招。

熊貓燒香病毒中毒后的表現(xiàn),開始是電腦速度非常慢,進入系統(tǒng)后會發(fā)現(xiàn)桌面上的圖標都變成熊貓舉著三根香的圖片,所有文件無法執(zhí)行,殺毒軟件被關(guān)閉,硬盤里的數(shù)據(jù)被破壞,電腦會出現(xiàn)藍屏和頻繁重啟。

病毒作者陳俊最初只是為了炫耀自己的技術(shù)才制造出這個病毒,但是后來網(wǎng)絡上出現(xiàn)了很多“變種病毒”,有人在病毒里添加了自己的代碼,讓中毒的電腦自動下載指定的文件,或者點擊指定的廣告,從中獲取利益。

從熊貓燒香病毒發(fā)作的癥狀來看,應該是當時網(wǎng)絡上流行的多種病毒的集合體,理論上來說當時的殺毒軟件應該可以對付這種病毒,遺憾的是,在熊貓燒香病毒橫行的那段時間里,沒有一個殺毒軟件是它的對手。

卡巴斯基在那個時代也算是殺毒軟件的大佬,它在查殺病毒時發(fā)出的聲音被網(wǎng)友比喻成“豬叫聲”。熊貓燒香病毒流行的時候,一些學校機房、公司辦公室等場所不斷地傳出這種豬的慘叫聲,但最終都沒能殺掉病毒,反而是殺毒軟件被病毒給關(guān)閉了。

2007年2月3日,李俊被公安機關(guān)抓獲,湖北省仙桃市法院以破壞計算機系統(tǒng)罪將他判處有期徒刑四年。李俊也在公安人員的監(jiān)督下,編寫了熊貓燒香的專殺工具,至此熊貓燒香事件才告一段落,后來網(wǎng)絡上出現(xiàn)了“金豬報喜”病毒也是熊貓燒香的變種,不過當時的殺毒軟件廠商已經(jīng)有了經(jīng)驗,該變種并沒有造成多大的影響。

熊貓燒香病毒可怕嗎?

如果要問經(jīng)歷過熊貓燒香病毒的人,我相信會得到兩種答案:

一種是電腦上沒有重要文件,對于電腦重裝完全無所謂的用戶,對他們來說熊貓燒香病毒跟平時遇到的病毒差不多,大不了整個硬盤重新分區(qū)格式化就解決了;另一種是電腦上有重要文件的用戶,病毒導致他們文件丟失,造成了巨大的經(jīng)濟損失,這些人談到熊貓燒香無不咬牙切齒。

所以電腦病毒可不可怕,關(guān)鍵還是看病毒對用戶造成了多大的損失。一直以來,電腦病毒制造者都是受利益驅(qū)使,才會制造病毒出來,比如病毒在后臺悄悄運行,用戶有價值的資料,或者在后臺自動執(zhí)行自己的任務,點擊廣告等,這些病毒會給制造者帶來經(jīng)濟收益。

最麻煩的就是不受利益驅(qū)使,純粹為了表現(xiàn)制作者技術(shù)的病毒,熊貓燒香就是其中之一,還有一種更厲害的病毒叫“CIH”,這種病毒不僅會造成用戶數(shù)據(jù)丟失,還不給用戶重裝的機會!

CIH病毒我沒遇到過,但是在我的印象中這是一種可怕的病毒,傳說它發(fā)作的時候可以燒掉電腦主板。

CIH病毒的制造者叫陳盈豪,他也是為了炫耀自己的電腦技術(shù),寫出了這個病毒。該病毒發(fā)作的時候硬盤數(shù)據(jù)全部丟失,主板上的BIOS內(nèi)容也會被破壞,此時電腦連開機畫面都進不去!想要拆機給主板放電?沒用,那個時候的主板沒有備份BIOS程序,一旦內(nèi)容被擦除,只能返回廠家用特殊工具重新燒入數(shù)據(jù)。

結(jié)語

記得以前在培訓機構(gòu)學電腦的時候,老師曾說過,電腦程序就像是一條條的鏈子,如果每個鏈子都非常完美地扣在一起,那就不會出現(xiàn)問題。如果某個鏈子松了,或者有了裂縫,其他的鏈子就有機會扣進來,這就是病毒。

如今計算機和互聯(lián)網(wǎng)相關(guān)的法律不斷完善,對于處罰計算機犯罪的行為也有法可依,近幾年來電腦病毒也似乎在互聯(lián)網(wǎng)上銷聲匿跡了。大家覺得電腦病毒的減少,是法律完善的原因,還是殺毒軟件的功勞呢?歡迎在下方評論留言。

領導堅持用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 ;

}

}


網(wǎng)站欄目:白帽子的未經(jīng)授權(quán)滲透測試合法嗎?(flas制作好學嗎?)
文章源于:http://m.5511xx.com/article/dhdjoho.html