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

📄 unit2.pas

📁 知道大家有没有用过PEDUMP
💻 PAS
字号:
unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls, ComCtrls, ShellAPI;

type
  TForm2 = class(TForm)
    Panel1: TPanel;
    Edit_Size: TEdit;
    StaticText2: TStaticText;
    Edit_Addr: TEdit;
    StaticText1: TStaticText;
    Edit_FileName: TEdit;
    StaticText3: TStaticText;
    Edit_ID: TEdit;
    ProgressBar1: TProgressBar;
    OpenDialog1: TOpenDialog;
    StaticText4: TStaticText;
    Edit_Type: TEdit;
    Panel2: TPanel;
    Memo1: TMemo;
    btn_Read: TBitBtn;
    btn_OutRes: TBitBtn;
    btn_InRes: TBitBtn;
    btm_Directory: TBitBtn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure btn_ReadClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btn_OutResClick(Sender: TObject);
    procedure btn_InResClick(Sender: TObject);
    procedure btm_DirectoryClick(Sender: TObject);
  private
    iAddr,iSize:Integer;  { 资源地址和大小 }
    CapStr:String;
    CaptionBtn:TRect;
    procedure DrawCaptButton(CapStr:String);
    procedure WMNCPaint(var Msg:TWMNCPaint);message WM_NCPaint;
    procedure WMNCActivate(var Msg:TWMNCActivate);message WM_NCActivate;
    procedure WMSetText(var Msg:TWMSetText);message WM_SetText;
    procedure WMNCHitTest(var Msg:TWMNCHitTest);message WM_NCHittest;
    procedure WMNCLButtonDown(var Msg:TWMNCLButtonDown);message WM_NCLButtonDown;
    { Private declarations }
  public
    { Public declarations }
  end;

type
  PIconHeader = ^TIconHeader;
  TIconHeader = packed record
    wReserved:Word;         { Currently zero }
    wType:Word;             { 1 for icons }
    wCount:Word;            { Number of components }
  end;

  PIconResInfo = ^TIconResInfo;
  TIconResInfo = packed record
    bWidth:Byte;
    bHeight:Byte;
    bColorCount:Byte;
    bReserved:Byte;
    wPlanes:Word;
    wBitCount:Word;
    lBytesInRes:DWORD;
    wNameOrdinal:Word;      { Points to component }
  end;

  PCursorResInfo = ^TCursorResInfo;
  TCursorResInfo = packed record
    wWidth:Word;
    wHeight:Word;
    wPlanes:Word;
    wBitCount:Word;
    lBytesInRes:DWORD;
    wNameOrdinal:Word;      { Points to component }
  end;

const
  htCaptionBtn=htSizeLast+1;

var
  Form2: TForm2;

implementation

{$R *.DFM}

uses func;

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:=caFree;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  Constraints.MinHeight:=Height;
  Constraints.MinWidth:=Width;
  
  CapStr:='→←';
end;

procedure TForm2.DrawCaptButton(CapStr:String);
var
  xFrame,yFrame,xSize,ySize:Integer;
  R:TRect;
begin
  xFrame:=GetSystemMetrics(SM_CXFRAME);
  yFrame:=GetSystemMetrics(SM_CYFRAME);
  xSize:=GetSystemMetrics(SM_CXSIZE);
  ySize:=GetSystemMetrics(SM_CYSIZE);
  //按钮属性调整->>
  CaptionBtn:=Bounds(Width-xFrame-5*xSize+4,yFrame+2,xSize+13,ySize-4);
  Canvas.Handle:=GetWindowDC(Self.Handle);
  Canvas.Font.Name:='宋体';
  Canvas.Font.Color:=clBlack;
  Canvas.Pen.Color:=clYellow;
  Canvas.Brush.Color:=clBtnFace;
  try
    DrawButtonFace(Canvas,CaptionBtn,1,bsAutoDetect,False,False,False);
    R:=Bounds(Width-xFrame-5*xSize+5,yFrame+3,xSize+10,ySize-7);
    with CaptionBtn do
      Canvas.TextRect(R,R.Left+2,R.Top,CapStr);
  finally
    ReleaseDC(Self.Handle,Canvas.Handle);
    Canvas.Handle:=0;
  end;
end;

procedure TForm2.WMNCActivate(var Msg: TWMNCActivate);
begin
inherited;
  DrawCaptButton(CapStr);
end;

procedure TForm2.WMNCHitTest(var Msg: TWMNCHitTest);
begin
inherited;
  with Msg do
  begin
    if PtInRect(CaptionBtn,Point(xPos-Left,yPos-Top)) then
      Result:=htCaptionBtn;
  end;
end;

procedure TForm2.WMNCLButtonDown(var Msg: TWMNCLButtonDown);
begin
inherited;
  if(Msg.HitTest=htCaptionBtn)then
    if CapStr='←→' then
    begin
      CapStr:='→←';
      inherited;
      DrawCaptButton(CapStr);
//      frm_main.FormStyle:=fsStayOnTop;
      SetWindowPos(Handle,Hwnd_Topmost,0,0,0,0,
                  (SWP_NOMOVE or SWP_NOSIZE));
    end else
    begin
      CapStr:='←→';
      inherited;
      DrawCaptButton(CapStr);
//      frm_main.FormStyle:=fsNormal;
      SetWindowPos(Handle,Hwnd_Notopmost,0,0,0,0,
                  (SWP_NOMOVE or SWP_NOSIZE));
    end;
end;

procedure TForm2.WMNCPaint(var Msg: TWMNCPaint);
begin
inherited;
  DrawCaptButton(CapStr);
end;

procedure TForm2.WMSetText(var Msg: TWMSetText);
begin
inherited;
  DrawCaptButton(CapStr);
end;

procedure TForm2.FormResize(Sender: TObject);
begin
  Perform(WM_NCACTIVATE,Word(Active),0);
end;

procedure TForm2.btn_ReadClick(Sender: TObject);
const
  Max_Buf=1024;
var
  iFile,i,iPos:Integer;
  ResBuffer:array[0..Max_Buf-1] of Byte;
  StrLineHex:String;
begin
  Memo1.Clear;
  ProgressBar1.Position:=0;
  ProgressBar1.Max:=iSize div Max_Buf;
  iFile:=FileOpen(Edit_FileName.Text,fmOpenRead or fmShareDenyNone);
  try
    iPos:=0;
    while iPos<iSize-Max_Buf do
    begin
      ProgressBar1.Position:=ProgressBar1.Position+1;
//      Application.ProcessMessages;
      FileRead(iFile,ResBuffer,SizeOf(ResBuffer));
      iPos:=iPos+Max_Buf;
      Caption:=Format('资源分析显示[POSITION:$%.*x]',[8,iPos]);
      StrLineHex:=IntToHex(ResBuffer[0],2);
      for i:=1 to Max_Buf-1 do
      begin
        StrLineHex:=StrLineHex+' '+IntToHex(ResBuffer[i],2);
      end;
      Memo1.Lines.Add(StrLineHex);
    end;
    FileRead(iFile,ResBuffer,iSize-iPos);
    StrLineHex:=IntToHex(ResBuffer[0],2);
    for i:=1 to iSize-iPos-1 do
    begin
      StrLineHex:=StrLineHex+' '+IntToHex(ResBuffer[i],2);
    end;
    Caption:=Format('资源分析显示[POSITION:$%.*x]',[8,iSize]);
    Memo1.Lines.Add(StrLineHex);
    ProgressBar1.Position:=0;
  finally
    FileClose(iFile);
  end;
end;

procedure TForm2.FormShow(Sender: TObject);
begin
  iAddr:=StrToIntDef(Edit_Addr.Text,0);
  Edit_Addr.Hint:=IntToStr(iAddr);
  iSize:=StrToIntDef(Edit_Size.Text,0);
  Edit_Size.Hint:=IntToStr(iSize);
  if (iAddr=0)or(iSize=0) then
    ShowMessage('资源地址或大小转化错误');
end;

procedure TForm2.btn_OutResClick(Sender: TObject);
const
  Max_Buf=1024;
var
  iFile:Integer; iPos:LongInt;
  ResBuffer:array[0..Max_Buf-1] of Byte;
  ResStream:TMemoryStream;
  TmpResPath:String;
  OutFileName:String;
begin
  TmpResPath:=MyPath+'TmpRes\';
  if not DirectoryExists(TmpResPath) then
  begin
    {$I-}
    MkDir(TmpResPath);
    if IOResult <> 0 then
    begin
      MessageBox(Handle,'不能建立临时目录','警告',MB_OK);
      Exit;
    end;
    {$I+}
  end;

  iFile:=FileOpen(Edit_FileName.Text,fmOpenRead or fmShareDenyNone);
  ResStream:=TMemoryStream.Create;
  try
    iPos:=FileSeek(iFile,iAddr,0);
    while iPos<iAddr+iSize-Max_Buf-1 do
    begin
      FileRead(iFile,ResBuffer,SizeOf(ResBuffer));
      iPos:=FileSeek(iFile,0,1);
      ResStream.WriteBuffer(ResBuffer,SizeOf(ResBuffer));
    end;
    FileRead(iFile,ResBuffer,iAddr+iSize-iPos);
    ResStream.WriteBuffer(ResBuffer,iAddr+iSize-iPos);
    OutFileName:=Format('%s%u.tmp',[TmpResPath,iAddr]);
    ResStream.SaveToFile(OutFileName);
    MessageBox(Handle,PChar(Format('成功导出文件[%s]',[OutFileName])),'信息',MB_OK);
    Caption:=Format('资源分析显示[..\TmpRes\%u.tmp]',[iAddr]);
  finally
    ResStream.Free;
    FileClose(iFile);
  end;
end;

procedure TForm2.btn_InResClick(Sender: TObject);
const
  Max_Buf=1024;
var
  iFile:Integer;
  ResBuffer:array[0..Max_Buf-1] of Byte;
  ResStream:TFileStream;
  InFileName:String;
  NumRead,NumWritten:Integer;
begin
  OpenDialog1.InitialDir:=MyPath+'TmpRes\';
  OpenDialog1.FileName:=Format('%u.tmp',[iAddr]);
  if OpenDialog1.Execute then
  begin
    InFileName:=OpenDialog1.FileName;

    iFile:=FileOpen(Edit_FileName.Text,fmOpenReadWrite or fmShareDenyNone);
    ResStream:=TFileStream.Create(InFileName,fmOpenRead or fmShareDenyNone);
    try
      Caption:=Format('%u-%u',[ResStream.Size,iSize]);
      if (ResStream.Size<>iSize) then
      begin
        if MessageBox(Handle,PChar(Format('导入文件[%s]大小不匹配'+#13+
                                          '理论大小[%u]字节<-->导入文件大小[%u]字节'+#13+
                                          '你确定要继续吗?',[InFileName,iSize,ResStream.Size])),
                             '警告',MB_YESNO)=IDNO then Exit;
      end;
      FileSeek(iFile,iAddr,0);
      repeat
         NumRead:=ResStream.Read(ResBuffer,SizeOf(ResBuffer));
         NumWritten:=FileWrite(iFile,ResBuffer,NumRead);
      until (NumRead=0) or (NumWritten<>NumRead);
      MessageBox(Handle,PChar(Format('成功导入文件[%s]',[InFileName])),'信息',MB_OK);
    finally
      ResStream.Free;
      FileClose(iFile);
    end;
  end;
end;

procedure TForm2.btm_DirectoryClick(Sender: TObject);
begin
  WinExec(PChar('Explorer.exe '+MyPath+'TmpRes\'),SW_NORMAL);
end;

end.

⌨️ 快捷键说明

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