bool Hide(char * bmpFileName, char * secretFileName) { DWORD dwBMPSize, dwSecretSize; char * lpBMP = GetFileContent(bmpFileName, &dwBMPSize); char * lpSecret = GetFileContent(secretFileName, &dwSecretSize); DWORD * lpFirstPoint = (DWORD *)(lpBMP + 10); printf("First point offset : %d\n", *lpFirstPoint); char * lpCurrentBMP = lpBMP + *lpFirstPoint + 3;// Alpha byte of first pixel (R,G,B,A R G B A) char * lpCurrentSecret = lpSecret; //第一个像素点保存Secret文件大小 *((DWORD*)lpCurrentBMP) = dwSecretSize; lpCurrentBMP += 6; for (; lpCurrentBMP < (lpBMP + dwBMPSize) && lpCurrentSecret < (lpSecret + dwSecretSize); lpCurrentBMP += 6) { *lpCurrentBMP = *lpCurrentSecret; *(lpCurrentBMP + 1) = *(lpCurrentSecret + 1); *(lpCurrentBMP + 2) = *(lpCurrentSecret + 2); lpCurrentSecret += 3; } SaveFile(lpBMP, dwBMPSize, bmpFileName); delete[] lpBMP; delete[] lpSecret; return true; }
std::string CResourceManager::GetRootXMLFile(LPTSTR pfn) { #ifdef SINGLE_PROCESS //return GetFileContent(Website_None, _T(""), _T("info.xml"), false); return GetFileContent(Website_Bank, pfn, _T("info.xml"), false); #else //return GetFileContent(Website_None, _T(""), _T("info.chk"), true); return GetFileContent(Website_Bank, pfn, _T("info.chk"), true); #endif }
std::string GetFileHexDigest(Hash::DigestType type, std::string path) { long fileSize = 0; char* fileContent = GetFileContent(path); std::string hexDigest = Hash::HexDigest(type, (uint8_t*) fileContent, (size_t) fileSize); delete [] fileContent; return hexDigest; }
// provider set void testProvRemoveLogfile() { // create a file SelfDeletingFilePath cfgfile(SCXFileSystem::DecodePath("./testfiles/log.conf")); { SCX_LogConfigurator subject(cfgfile); subject.Set( L"STDOUT", L"trace" ); subject.Set( L"STDOUT:scxtest.core.common.pal.system.common.entityenumeration", L"info" ); subject.Set( L"FILE:/myvar/opt/microsoft/scx/log/scx.log:scxtest.core.common.pal.system.common.entityenumeration", L"info" ); } SCX_LogConfigurator subject(cfgfile); subject.Remove( L"STDOUT" ); CPPUNIT_ASSERT_THROW_MESSAGE( "exception is expected since entry does not exist", subject.Remove( L"FILE:/var/opt/microsoft/scx/log/scx.log" ), SCXAdminException ); std::string str = GetFileContent(cfgfile); // we should not see these entries CPPUNIT_ASSERT( str.find("HYSTERICAL") == str.npos ); CPPUNIT_ASSERT( str.find("/var") == str.npos ); CPPUNIT_ASSERT( str.find("STDOUT") == str.npos ); // but should see these: CPPUNIT_ASSERT( str.find("FILE") != str.npos ); CPPUNIT_ASSERT( str.find("PATH: /myvar/opt/microsoft/scx/log/scx.log") != str.npos ); CPPUNIT_ASSERT( str.find("MODULE: scxtest.core.common.pal.system.common.entityenumeration INFO") != str.npos ); }
// generic reset void testResetLogConf() { SelfDeletingFilePath cfgfile(SCXFileSystem::DecodePath("./testfiles/log.conf")); // Create a simple example file std::vector<std::wstring> lines; lines.push_back(L"FILE ("); lines.push_back(L"PATH: /var/log-1"); lines.push_back(L"MODULE: TRACE"); lines.push_back(L"MODULE: scxtest.core.common.pal WARNING"); lines.push_back(L"MODULE: scxtest.core.common.pal.system.common HYSTERICAL"); lines.push_back(L"MODULE: scxtest.core.common.pal.system.common.entityenumeration INFO"); lines.push_back(L")"); lines.push_back(L""); // Must be here, or else the last newline will be omitted. SCXFile::WriteAllLinesAsUTF8(cfgfile, lines, std::ios_base::out); { SCX_LogConfigurator subject(cfgfile); CPPUNIT_ASSERT (subject.Reset() ); } std::string str = GetFileContent(cfgfile); CPPUNIT_ASSERT( str.find("HYSTERICAL") == str.npos ); // Should be gone CPPUNIT_ASSERT( str.find("scxtest.core.common.pal") == str.npos ); // should be gone CPPUNIT_ASSERT( str.find("FILE") != str.npos ); // should still be there CPPUNIT_ASSERT( str.find("/var/log-1") != str.npos ); // should still be there }
bool Recovery(char * bmpFileName, char * secretFileName) { DWORD dwBMPSize; char * lpBMP = GetFileContent(bmpFileName, &dwBMPSize); DWORD * lpFirstPoint = (DWORD *)(lpBMP + 10); printf("First point offset : %d\n", *lpFirstPoint); DWORD dwSecretSize = *(DWORD *)(lpBMP + *lpFirstPoint + 3); printf("Secret file size : %d\n", dwSecretSize); char * SecretBuf = new char[dwSecretSize]; char * lpCurrentBMP = lpBMP + *lpFirstPoint + 3 + 6; for (int i = 0; lpCurrentBMP < (lpBMP + dwBMPSize) && i < dwSecretSize; lpCurrentBMP += 6) { SecretBuf[i] = *lpCurrentBMP; SecretBuf[i + 1] = *(lpCurrentBMP + 1); SecretBuf[i + 2] = *(lpCurrentBMP + 2); i += 3; } SaveFile(SecretBuf, dwSecretSize, secretFileName); delete[] SecretBuf; delete[] lpBMP; return true; }
bool Cx_TextUtil::ReadTextFile(BYTE head[5], std::wstring& content, const std::wstring& filename, ULONG nLenLimitMB, UINT codepage) { ZeroMemory(head, sizeof(BYTE) * 5); content.resize(0); bool bRet = false; HANDLE hFile = ::CreateFileW(filename.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (INVALID_HANDLE_VALUE == hFile) { LOG_ERROR2(LOGHEAD L"IDS_OPEN_FAIL", filename << L", " << GetSystemErrorString(GetLastError())); } else { DWORD dwLength = ::GetFileSize(hFile, NULL); HGLOBAL hBuffer = NULL; if (dwLength != INVALID_FILE_SIZE) { if (dwLength > nLenLimitMB * 1024L * 1024L) { LOG_WARNING2(LOGHEAD L"IDS_HUGE_FILE", (dwLength / (1024.0*1024.0)) << L"MB, " << filename); dwLength = nLenLimitMB * 1024L * 1024L; } hBuffer = GlobalAlloc(GHND, dwLength + 8); } if (hBuffer != NULL) { LPBYTE pBuffer = (LPBYTE)GlobalLock(hBuffer); if (pBuffer != NULL) { DWORD dwBytesRead = 0; ::ReadFile(hFile, pBuffer, dwLength, &dwBytesRead, NULL); if (dwBytesRead > 0) { CopyMemory(head, pBuffer, sizeof(BYTE) * min(5, dwBytesRead)); bRet = GetFileContent(content, pBuffer, dwBytesRead, codepage); if (!bRet) { LOG_WARNING2(LOGHEAD L"IDS_NOT_ANSIFILE", filename); } } GlobalUnlock(hBuffer); } GlobalFree(hBuffer); } ::CloseHandle(hFile); } return bRet; }
//计算did模板文件的crc unsigned int CalcFileCrc(const char* pFile) { int iFileLen = 0; char* pContent = GetFileContent(pFile, iFileLen); if (NULL != pContent && iFileLen > 0) { unsigned int crc = CDidStructApi::ds_cal_crc(pContent, iFileLen); free(pContent); pContent = NULL; return crc; } return -1; }
// provider set void testProvSetThresholdForStdOut() { SelfDeletingFilePath cfgfile(SCXFileSystem::DecodePath("./testfiles/log.conf")); SCX_LogConfigurator subject(cfgfile); // set several entries: should create a new file with specific entries: subject.Set( L"STDOUT", L"TRACE" ); subject.Set( L"STDOUT:scxtest.core.common.pal.system.common.entityenumeration", L"INFO" ); std::string str = GetFileContent(cfgfile); // we should not see these entries CPPUNIT_ASSERT( str.find("HYSTERICAL") == str.npos ); CPPUNIT_ASSERT( str.find("FILE") == str.npos ); CPPUNIT_ASSERT( str.find("/var") == str.npos ); // but should see these: CPPUNIT_ASSERT( L"TRACE" == GetLogLevel(cfgfile, L"STDOUT", L"", L"") ); CPPUNIT_ASSERT( L"INFO" == GetLogLevel(cfgfile, L"STDOUT", L"", L"scxtest.core.common.pal.system.common.entityenumeration") ); }
// provider set void testProvSetThresholdForTwoBackends() { SelfDeletingFilePath cfgfile(SCXFileSystem::DecodePath("./testfiles/log.conf")); SCX_LogConfigurator subject(cfgfile); // Positive test to set lower case entry: should create a new file with specific entries (upper case): subject.Set( L"STDOUT", L"trace" ); subject.Set( L"STDOUT:scxtest.core.common.pal.system.common.entityenumeration", L"info" ); subject.Set( L"FILE:/myvar/opt/microsoft/scx/log/scx.log:scxtest.core.common.pal.system.common.entityenumeration", L"info" ); std::string str = GetFileContent(cfgfile); // we should not see these entries CPPUNIT_ASSERT( str.find("HYSTERICAL") == str.npos ); CPPUNIT_ASSERT( str.find("/var") == str.npos ); // but should see these: CPPUNIT_ASSERT( L"TRACE" == GetLogLevel(cfgfile, L"STDOUT", L"", L"") ); CPPUNIT_ASSERT( L"INFO" == GetLogLevel(cfgfile, L"STDOUT", L"", L"scxtest.core.common.pal.system.common.entityenumeration") ); CPPUNIT_ASSERT( L"INFO" == GetLogLevel(cfgfile, L"FILE", L"/myvar/opt/microsoft/scx/log/scx.log", L"scxtest.core.common.pal.system.common.entityenumeration") ); }
char* GetFileContent(std::string path) { long f = 0; return GetFileContent(path, f); }
bool NFCPluginManager::LoadPluginConfig() { std::string strContent; GetFileContent(mstrConfigName, strContent); rapidxml::xml_document<> xDoc; xDoc.parse<0>((char*)strContent.c_str()); rapidxml::xml_node<>* pRoot = xDoc.first_node(); rapidxml::xml_node<>* pAppNameNode = pRoot->first_node(mstrAppName.c_str()); if (!pAppNameNode) { NFASSERT(0, "There are no App ID", __FILE__, __FUNCTION__); return false; } for (rapidxml::xml_node<>* pPluginNode = pAppNameNode->first_node("Plugin"); pPluginNode; pPluginNode = pPluginNode->next_sibling("Plugin")) { const char* strPluginName = pPluginNode->first_attribute("Name")->value(); mPluginNameMap.insert(PluginNameMap::value_type(strPluginName, true)); } /* rapidxml::xml_node<>* pPluginAppNode = pAppNameNode->first_node("APPID"); if (!pPluginAppNode) { NFASSERT(0, "There are no App ID", __FILE__, __FUNCTION__); return false; } const char* strAppID = pPluginAppNode->first_attribute("Name")->value(); if (!strAppID) { NFASSERT(0, "There are no App ID", __FILE__, __FUNCTION__); return false; } if (!NF_StrTo(strAppID, mnAppID)) { NFASSERT(0, "App ID Convert Error", __FILE__, __FUNCTION__); return false; } */ rapidxml::xml_node<>* pPluginConfigPathNode = pAppNameNode->first_node("ConfigPath"); if (!pPluginConfigPathNode) { NFASSERT(0, "There are no ConfigPath", __FILE__, __FUNCTION__); return false; } if (NULL == pPluginConfigPathNode->first_attribute("Name")) { NFASSERT(0, "There are no ConfigPath.Name", __FILE__, __FUNCTION__); return false; } mstrConfigPath = pPluginConfigPathNode->first_attribute("Name")->value(); return true; }
procedurelist_t *SpecificationParser::GetProceduresFromFile(const string &filename) throw(JsonRpcException) { string content; GetFileContent(filename, content); return GetProceduresFromString(content); }