本文整理汇总了C++中StringStream::write方法的典型用法代码示例。如果您正苦于以下问题:C++ StringStream::write方法的具体用法?C++ StringStream::write怎么用?C++ StringStream::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringStream
的用法示例。
在下文中一共展示了StringStream::write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
try
{
std::string input("abcdefghijklmnopqrstuvwxyz");
char buffer[32];
memset(buffer, 0, 32);
StringStream sStream;
sStream.write((const sys::byte*) input.c_str(), 5);
sStream.read((sys::byte*) buffer, 3);
cout << buffer << endl;
memset(buffer, 0, 32);
sStream.write((const sys::byte*) input.c_str(), 10);
sStream.read((sys::byte*) buffer, 11);
cout << buffer << endl;
memset(buffer, 0, 32);
sStream.read((sys::byte*) buffer, 100);
cout << buffer << endl;
}
catch (Throwable& t)
{
cerr << "Caught throwable: " << t.toString() << endl;
}
catch (...)
{
cerr << "Caught unknown exception" << endl;
}
return 0;
}
示例2: obfuscateLocalVarsInExpression
/*
* Return count of obfuscated local variables
*/
size_t obfuscateLocalVarsInExpression(StringStream &stream, char *pExpStart, const char *pExpEnd,
LocalVarsStack &localVarsInBlock, LocalVarsStack &localVarsInModule)
{
size_t count = 0;
char *p = pExpStart;
while (*p && p < pExpEnd) {
if (isStringStart(p)) {
size_t size = skipStringAndMove(&p, NULL);
stream.write(p - size, size);
continue;
}
const char *pWordStart = p;
while (*p && isVarChar(*p)) {
++p;
}
size_t wordSize = p - pWordStart;
if (wordSize) {
bool bFind;
stObfuscatedName var;
var.name.assign(pWordStart, wordSize);
bFind = localVarsInBlock.find(var);
if (!bFind)
bFind = localVarsInModule.find(var);
if (bFind) {
stream << var.fake_name;
++count;
}
else {
stream << var.name;
}
}
stream << *p;
++p;
}
return count;
}
示例3: replaceGlobalFunctions
/*
* Scaning all text
* Skip the "string"
* Why do finds the function name:
* function call:
* foo(arg1, arg2, ...)
* a = foo(arg1, arg2, ...)
* when function send to other function
* trycall(foo)
* ---------------------
* therefore function name is near '(' and ')'
*/
ptrdiff_t replaceGlobalFunctions(const char *szFileName, FakeFunctions &globalFunctions,
const StringList &excludeFunctions)
{
if (!szFileName || !szFileName[0])
return 0;
FILE *file = fopen(szFileName, "rt");
if (!file)
return 0;
fseek(file, 0, SEEK_END);
int size = ftell(file);
rewind(file);
char *pDataInSource = new char[size + 20]; // + 20 for additional 10_"data"_10
memset(pDataInSource, 0, 10);
char *pDataIn = pDataInSource + 10; // for delete/clear data
size_t realSize = fread(pDataIn, 1, size, file);
memset(pDataIn + realSize, 0, 10);
fclose(file);
StringStream stream;
char *p = pDataIn;
while (*p) {
if (isStringStart(p)) {
size_t size = skipStringAndMove(&p, NULL);
stream.write(p - size, size);
continue;
}
if (!strncmp(p, "tostring", sizeof("tostring") - 1))
*p = *p;
char *pStart = p;
while (isAlphaFun(*p)) {
++p;
}
size_t wordSize = p - pStart;
if (wordSize) {
if (isFunctionNameInCode(pStart, p)) {
std::string str(pStart, wordSize);
StringMapConstIter iter = globalFunctions.find(str);
if (iter != globalFunctions.end()) {
StringListConstIter IterFunExclude = std::find(excludeFunctions.begin(), excludeFunctions.end(), str);
if (IterFunExclude == excludeFunctions.end()) {
// replace
stream.write(iter->second.c_str(), FAKE_FUNCTION_LEN);
continue;
}
}
}
stream.write(pStart, wordSize);
if (!p[0]) {
break;
}
}
stream << *p;
++p;
}
file = fopen(szFileName, "wt");
const std::string& str = stream.str();
size_t obfuscateSize = str.length();
if (file) {
fwrite(str.c_str(), 1, obfuscateSize, file);
fclose(file);
}
delete[] pDataInSource;
print("%8d %s\n", obfuscateSize - realSize, szFileName);
return obfuscateSize - realSize;
}