⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cbinmod.h

📁 WinCE5.0部分核心源码
💻 H
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// This source code is licensed under Microsoft Shared Source License
// Version 1.0 for Windows CE.
// For a copy of the license visit http://go.microsoft.com/fwlink/?LinkId=3223.
//
#pragma once

#include <windows.h>
#include <string>

using namespace std;

#include <pehdr.h>
#include <romldr.h>

#define MAX_RECORDS 2048
#define BUFFER_SIZE  64*1024

typedef struct _RECORD_DATA {
  DWORD dwStartAddress;
  DWORD dwLength;
  DWORD dwChecksum;
  DWORD dwFilePointer;
}RECORD_DATA, *PRECORD_DATA;

class CBinMod
{
protected:
  BYTE pBuffer[BUFFER_SIZE];
  string image;
  HANDLE hFile;
  FILE *fpLog;
  
  DWORD pTOC;
  DWORD dwImageStart;
  DWORD dwImageLength;
  DWORD dwNumRecords;
  DWORD dwROMOffset;
  
  RECORD_DATA Records[MAX_RECORDS];

  DWORD FindHole(DWORD size, ROMHDR *pToc);
  bool ReWriteCheckSum(DWORD dwAddress);
  bool ComputeRomOffset(DWORD &state);
  bool AccessBinFile(PBYTE pBuffer, DWORD dwAddress, DWORD dwLength, DWORD dwROMOffsetRead, bool bWrite);
  bool GetNewFileData(BYTE **buffer, DWORD *csize, DWORD *rsize, const char *file_name, bool compressed);

  virtual DWORD my_SetFilePointer(HANDLE handle, LONG dist, PLONG dist_high, DWORD method)
  {
    return SetFilePointer(handle, dist, dist_high, method);
  };
  virtual BOOL my_ReadFile(HANDLE handle, LPVOID buffer, DWORD bytes, LPDWORD cb, LPOVERLAPPED ol)
  {
    return ReadFile( handle,  buffer,  bytes,  cb, ol);
  };
  virtual BOOL my_WriteFile(HANDLE handle, LPVOID buffer, DWORD bytes, LPDWORD cb, LPOVERLAPPED ol)
  {
    return WriteFile( handle,  buffer,  bytes,  cb, ol);
  };
  virtual BOOL my_FlushFileBuffers(HANDLE hFile)
  {
    return FlushFileBuffers( hFile);
  };
  virtual HANDLE my_CreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
  {
    return CreateFile( lpFileName,  dwDesiredAccess,  dwShareMode,  lpSecurityAttributes,  dwCreationDisposition,  dwFlagsAndAttributes,  hTemplateFile);
  };
  virtual BOOL my_CloseHandle(HANDLE hObject)
  {
    return CloseHandle( hObject);
  };
  virtual DWORD my_GetFileSize(HANDLE handle, LPDWORD lpFileSizeHigh)
  {
    return GetFileSize( handle,  lpFileSizeHigh);
  };

  virtual DWORD my_GetFileAttributes(LPCTSTR lpFileName)
  {
    return GetFileAttributes(lpFileName);
  };

  void dprintf(char *message, ...);
  
public:    
  CBinMod(bool log2file = false);
  ~CBinMod();

  bool Init(string _image);
  bool Replace(string _file);
  bool Extract(string _file);
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -