新聞中心
白帽子的未經(jīng)授權(quán)滲透測試合法嗎?
嚴(yán)格來說 不合法 。

公司主營業(yè)務(wù):成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、移動(dòng)網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競爭能力。成都創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)推出霍山免費(fèi)做網(wǎng)站回饋大家。
本人是一個(gè)網(wǎng)絡(luò)安全愛好者,也算一個(gè)半吊子白帽子。不會(huì)挖掘很深層的漏洞,對代碼理解并不透徹,但卻在一些漏洞平臺(tái)有著名號(hào)。
關(guān)于這個(gè)問題,可以關(guān)注我,看我頭條號(hào)的一片文章:
你真的了解《網(wǎng)絡(luò)安全法》嗎?
《網(wǎng)絡(luò)安全法》第二規(guī)定:任何個(gè)人和組織不得從事非法侵入他人網(wǎng)絡(luò)、干擾他人網(wǎng)絡(luò)正常功能、網(wǎng)絡(luò)數(shù)據(jù)等危害網(wǎng)絡(luò)安全的活動(dòng)。 現(xiàn)在的白帽子更加注重法律這一關(guān),漏洞都會(huì)在官方廠商SRC上提交,避免引起不必要的誤會(huì)。
flas制作好學(xué)嗎?
flash因?yàn)楦鞣N安全漏洞頻出,已經(jīng)明確的被蘋果、谷歌、微軟列為未來淘汰產(chǎn)品了,Adobe已經(jīng)正式聲明將于2020年結(jié)束對flash的支持,各瀏覽器的支持也將會(huì)在2020年底徹底結(jié)束,未來將正式被HTML5等新技術(shù)所取代。下面引用一篇文章來幫你介紹一下各種替代flash的技術(shù),希望對你的學(xué)習(xí)方向有所幫助。
Flash 的替代技術(shù)
-------2 年前 · 來自專欄 極光日報(bào)
簡評:Flash 在過去的十幾年里為我們提供了動(dòng)畫、視頻、游戲,當(dāng)然還有廣告。但現(xiàn)在 Flash 退出歷史舞臺(tái)的時(shí)機(jī)已經(jīng)來了,那么哪些技術(shù)未來將替代 Flash?
Web 動(dòng)畫
CSS
CSS animation 實(shí)現(xiàn) Web 動(dòng)畫最簡單的一種。隨著 CSS3 的發(fā)布,動(dòng)畫也已經(jīng)被加入到了標(biāo)準(zhǔn)之中。Mozilla 也推出了相關(guān)的文檔,網(wǎng)絡(luò)上也有很多的開源項(xiàng)目可以使用。
JavaScript
通過 HTML5 的
當(dāng)然新的 Web Animations API 也非常強(qiáng)大。
Web 游戲
在過去的一段時(shí)間 Flash 統(tǒng)治了 Web 游戲界,但在今天結(jié)合 JavaScript, HTML5, WebGL 和WebAssembly 等技術(shù)已經(jīng)完全能提供更好的體驗(yàn),甚至還可以使用 WebVR 和 A-Frame 來構(gòu)建 Web VR 應(yīng)用。
Mozilla 為開發(fā)者們提供了一份開發(fā) Web 游戲的技術(shù)清單,內(nèi)容包括:
WebGL
HTML audio
Web Audio API
WebSockets
WebRTC
WebAssembly
視頻
一直以來 Flash 視頻播放都有發(fā)熱嚴(yán)重等各種問題,而新一代的視頻編解碼器可以使用硬件渲染,大大提高了效率。不太好的就是要從 Flash 切換到 HTML5 只能將視頻重新編碼??梢酝ㄟ^ FFmpeg 和 Handbrake 這樣的免費(fèi)工具進(jìn)行轉(zhuǎn)碼。
而 HTML 5 內(nèi)置多媒體控件,因此無需用戶安裝任何額外的播放器,只需要像下面這樣:
當(dāng)然,你也可以自定義樣式,來保證不同瀏覽器之間的外觀和表現(xiàn)一致。
MDN 也提供了 Flash 遷移到 HTML5 的指南。
現(xiàn)在 Flash 已經(jīng)注定被拋棄了,趕緊學(xué)習(xí)下新技術(shù)吧。
原文:Life After Flash: Multimedia for the Open Web
當(dāng)年熊貓燒香電腦病毒到底有多可怕?
說起熊貓燒香,我就想起當(dāng)年在辦公室文員小姐姐的一幕:
把前臺(tái)電腦桌面上的所有圖標(biāo)都換成熊貓燒香后關(guān)機(jī),想看看小姐姐遇到傳說中的熊貓燒香病毒會(huì)有什么反應(yīng)。結(jié)果那天一早,老板就拿了一份文件讓她打印,打開電腦的那一刻,老板就在旁邊看著……
最后我的惡作劇被老板請來的電腦維修員識(shí)破,我被訓(xùn)斥了一頓,還被罰前臺(tái)接。
轉(zhuǎn)眼間十幾年過去了,回想當(dāng)初熊貓燒香病毒肆虐的時(shí)候,我們公司的電腦沒有被感染,我身邊的朋友也沒有被感染,所以如果要問那個(gè)病毒有多可怕,我還真沒感覺出來,因?yàn)槟菐啄甑碾娔X病毒實(shí)在太多了!
曾經(jīng)的電腦病毒我最早是九十年始接觸電腦,那個(gè)時(shí)候只能在DOS下操作,想要進(jìn)入某個(gè)程序就要記住它的英文名字,而且沒有鼠標(biāo),所以經(jīng)歷過那段時(shí)期的人,如今都可以用純鍵盤對電腦進(jìn)行基本操作。
2002年,我擁有了自己的電腦,那時(shí)候比較流行的系統(tǒng)是WIN98,當(dāng)然也有人喜歡用WIN ME。那個(gè)時(shí)候的寬帶還沒普及,曾經(jīng)有一段時(shí)期,我都是用,也是從連接上互聯(lián)網(wǎng)的那一刻開始,各種奇葩的病毒就出現(xiàn)了。
那時(shí)候的電腦配置很低,如果不小心點(diǎn)進(jìn)有病毒的網(wǎng)頁,很容易就出現(xiàn)“假死機(jī)”狀態(tài),這時(shí)候想要關(guān)閉網(wǎng)頁也要等很久,硬盤呼呼呼地響著,等你把所有自動(dòng)彈出來的網(wǎng)頁關(guān)閉后會(huì)發(fā)現(xiàn),電腦桌面上已經(jīng)鋪滿了各種網(wǎng)頁的快捷圖標(biāo)。
如果只是添加快捷圖標(biāo)到桌面上,這也不算什么大問題,最可怕的是這些病毒已經(jīng)修改了系統(tǒng)的注冊表,讓你每次開機(jī)都自動(dòng)打開那些網(wǎng)頁,刪都刪不掉……
那時(shí)候這種病毒非常普遍,相信很多人都遇到過,至少我身邊的朋友叫我過去修電腦的時(shí)候,基本上都是類似這樣的情況。于是,大家就習(xí)慣了用GHOST備份系統(tǒng),這是一種非常方便的系統(tǒng)恢復(fù)工具,只要把新系統(tǒng)和所有需要的應(yīng)用軟件都裝在C盤,然后用GHOST備份整個(gè)C盤,下次有問題直接恢復(fù)就可以了。
看似萬無一失的系統(tǒng)備份工具,最終卻敗在了熊貓燒香手里。
2006年12月,湖北仙桃的李俊為了表現(xiàn)自己的計(jì)算機(jī)能力,制造出了“熊貓燒香病毒”。這種病毒不但能夠感染exe、com、html等文件,最要命的是它會(huì)找到硬盤里的gho備份文件,并刪除掉!
熊貓燒香病毒除了會(huì)刪除GHO文件以外,還具有超強(qiáng)的傳播能力,幾乎把當(dāng)時(shí)所有可以傳播的途徑都用上了:網(wǎng)頁傳播、EXE執(zhí)行文件傳播、U盤傳播、auto傳播等等。廣泛的傳播途徑,使得熊貓燒香病毒能夠在短短的一個(gè)多月時(shí)間里,感染高達(dá)數(shù)百萬個(gè)人用戶的電腦,甚至很多企業(yè)用戶和機(jī)關(guān)單位的電腦也紛紛中招。
熊貓燒香病毒中毒后的表現(xiàn),開始是電腦速度非常慢,進(jìn)入系統(tǒng)后會(huì)發(fā)現(xiàn)桌面上的圖標(biāo)都變成熊貓舉著三根香的圖片,所有文件無法執(zhí)行,殺毒軟件被關(guān)閉,硬盤里的數(shù)據(jù)被破壞,電腦會(huì)出現(xiàn)藍(lán)屏和頻繁重啟。
病毒作者陳俊最初只是為了炫耀自己的技術(shù)才制造出這個(gè)病毒,但是后來網(wǎng)絡(luò)上出現(xiàn)了很多“變種病毒”,有人在病毒里添加了自己的代碼,讓中毒的電腦自動(dòng)下載指定的文件,或者點(diǎn)擊指定的廣告,從中獲取利益。
從熊貓燒香病毒發(fā)作的癥狀來看,應(yīng)該是當(dāng)時(shí)網(wǎng)絡(luò)上流行的多種病毒的集合體,理論上來說當(dāng)時(shí)的殺毒軟件應(yīng)該可以對付這種病毒,遺憾的是,在熊貓燒香病毒橫行的那段時(shí)間里,沒有一個(gè)殺毒軟件是它的對手。
卡巴斯基在那個(gè)時(shí)代也算是殺毒軟件的大佬,它在查殺病毒時(shí)發(fā)出的聲音被網(wǎng)友比喻成“豬叫聲”。熊貓燒香病毒流行的時(shí)候,一些學(xué)校機(jī)房、公司辦公室等場所不斷地傳出這種豬的慘叫聲,但最終都沒能殺掉病毒,反而是殺毒軟件被病毒給關(guān)閉了。
2007年2月3日,李俊被公安機(jī)關(guān)抓獲,湖北省仙桃市法院以破壞計(jì)算機(jī)系統(tǒng)罪將他判處有期徒刑四年。李俊也在公安人員的監(jiān)督下,編寫了熊貓燒香的專殺工具,至此熊貓燒香事件才告一段落,后來網(wǎng)絡(luò)上出現(xiàn)了“金豬報(bào)喜”病毒也是熊貓燒香的變種,不過當(dāng)時(shí)的殺毒軟件廠商已經(jīng)有了經(jīng)驗(yàn),該變種并沒有造成多大的影響。
熊貓燒香病毒可怕嗎?如果要問經(jīng)歷過熊貓燒香病毒的人,我相信會(huì)得到兩種答案:
一種是電腦上沒有重要文件,對于電腦重裝完全無所謂的用戶,對他們來說熊貓燒香病毒跟平時(shí)遇到的病毒差不多,大不了整個(gè)硬盤重新分區(qū)格式化就解決了;另一種是電腦上有重要文件的用戶,病毒導(dǎo)致他們文件丟失,造成了巨大的經(jīng)濟(jì)損失,這些人談到熊貓燒香無不咬牙切齒。所以電腦病毒可不可怕,關(guān)鍵還是看病毒對用戶造成了多大的損失。一直以來,電腦病毒制造者都是受利益驅(qū)使,才會(huì)制造病毒出來,比如病毒在后臺(tái)悄悄運(yùn)行,用戶有價(jià)值的資料,或者在后臺(tái)自動(dòng)執(zhí)行自己的任務(wù),點(diǎn)擊廣告等,這些病毒會(huì)給制造者帶來經(jīng)濟(jì)收益。
最麻煩的就是不受利益驅(qū)使,純粹為了表現(xiàn)制作者技術(shù)的病毒,熊貓燒香就是其中之一,還有一種更厲害的病毒叫“CIH”,這種病毒不僅會(huì)造成用戶數(shù)據(jù)丟失,還不給用戶重裝的機(jī)會(huì)!
CIH病毒我沒遇到過,但是在我的印象中這是一種可怕的病毒,傳說它發(fā)作的時(shí)候可以燒掉電腦主板。
CIH病毒的制造者叫陳盈豪,他也是為了炫耀自己的電腦技術(shù),寫出了這個(gè)病毒。該病毒發(fā)作的時(shí)候硬盤數(shù)據(jù)全部丟失,主板上的BIOS內(nèi)容也會(huì)被破壞,此時(shí)電腦連開機(jī)畫面都進(jìn)不去!想要拆機(jī)給主板放電?沒用,那個(gè)時(shí)候的主板沒有備份BIOS程序,一旦內(nèi)容被擦除,只能返回廠家用特殊工具重新燒入數(shù)據(jù)。
結(jié)語記得以前在培訓(xùn)機(jī)構(gòu)學(xué)電腦的時(shí)候,老師曾說過,電腦程序就像是一條條的鏈子,如果每個(gè)鏈子都非常完美地扣在一起,那就不會(huì)出現(xiàn)問題。如果某個(gè)鏈子松了,或者有了裂縫,其他的鏈子就有機(jī)會(huì)扣進(jìn)來,這就是病毒。
如今計(jì)算機(jī)和互聯(lián)網(wǎng)相關(guān)的法律不斷完善,對于處罰計(jì)算機(jī)犯罪的行為也有法可依,近幾年來電腦病毒也似乎在互聯(lián)網(wǎng)上銷聲匿跡了。大家覺得電腦病毒的減少,是法律完善的原因,還是殺毒軟件的功勞呢?歡迎在下方評論留言。
領(lǐng)導(dǎo)堅(jiān)持用char而不用string?
早期寫的string基礎(chǔ)類,分享給大家參考
先是頭文件:
//--------------------------------------------------------------------------
// ?÷∑?¥???…?√?
//
//
// 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 ; } }
新聞標(biāo)題:白帽子的未經(jīng)授權(quán)滲透測試合法嗎?(flas制作好學(xué)嗎?)
文章網(wǎng)址:http://www.dlmjj.cn/article/dhdjoho.html


咨詢
建站咨詢
