unit DTocsgEncMain; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Tocsg.Controls, Vcl.Buttons, Vcl.ExtCtrls, Tocsg.Trace, ShellAPI; type TDlgTgEncMain = class(TForm) edSrcPath: TEdit; btnEnc: TButton; edDestPath: TEdit; Label1: TLabel; Label2: TLabel; btnPath: TSpeedButton; OpenDialog: TOpenDialog; Label3: TLabel; Label4: TLabel; btnEncSavePath: TSpeedButton; edEncPath: TEdit; btnDec: TButton; edDecPath: TEdit; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; edEmpNo: TEdit; edHostName: TEdit; edPart: TEdit; edPG: TEdit; btnGetHead: TButton; mmHead: TMemo; Shape1: TShape; Label9: TLabel; edCode: TEdit; procedure btnEncClick(Sender: TObject); procedure btnPathClick(Sender: TObject); procedure btnEncSavePathClick(Sender: TObject); procedure btnDecClick(Sender: TObject); procedure btnGetHeadClick(Sender: TObject); private { Private declarations } Trace_: TTgTrace; MgCtrls_: TManagerInputControlsData; FOldEditProc: TWndMethod; FOldEncEditProc: TWndMethod; procedure NewEdSrcEditProc(var Msg: TMessage); procedure NewEdEncEditProc(var Msg: TMessage); public { Public declarations } Constructor Create(aOwner: TComponent); override; Destructor Destroy; override; end; var DlgTgEncMain: TDlgTgEncMain; implementation uses Tocsg.Path, Tocsg.Encrypt, Tocsg.Safe, superobject, GlobalDefine, Tocsg.DRM.Encrypt, Tocsg.WinInfo, Tocsg.WTS, Tocsg.Hash, Tocsg.Graphic, Vcl.Imaging.pngimage, Tocsg.WndUtil; {$R *.dfm} Constructor TDlgTgEncMain.Create(aOwner: TComponent); begin Inherited Create(aOwner); FOldEditProc := edSrcPath.WindowProc; edSrcPath.WindowProc := NewEdSrcEditProc; DragAcceptFiles(edSrcPath.Handle, True); FOldEncEditProc:= edEncPath.WindowProc; edEncPath.WindowProc := NewEdEncEditProc; DragAcceptFiles(edEncPath.Handle, True); DeleteFile(CutFileExt(GetRunExePath) + '.log'); Trace_ := TTgTrace.Create(GetRunExePathDir, 'TocsgEnc.log'); edHostName.Text := GetComName + '\' + WTS_GetCurrentUserName; MgCtrls_ := TManagerInputControlsData.Create(CutFileExt(GetRunExePath) + '.ini'); MgCtrls_.RegInputCtrl(edSrcPath); MgCtrls_.RegInputCtrl(edDestPath); MgCtrls_.RegInputCtrl(edEncPath); MgCtrls_.RegInputCtrl(edDecPath); MgCtrls_.RegInputCtrl(edEmpNo); MgCtrls_.RegInputCtrl(edHostName); MgCtrls_.RegInputCtrl(edPart); MgCtrls_.RegInputCtrl(edPG); MgCtrls_.RegInputCtrl(edCode); MgCtrls_.Load; end; Destructor TDlgTgEncMain.Destroy; begin if Assigned(edSrcPath) and edSrcPath.HandleAllocated then DragAcceptFiles(edSrcPath.Handle, False); edSrcPath.WindowProc := FOldEditProc; if Assigned(edEncPath) and edEncPath.HandleAllocated then DragAcceptFiles(edEncPath.Handle, False); edEncPath.WindowProc := FOldEncEditProc; FreeAndNil(MgCtrls_); FreeAndNil(Trace_); Inherited; end; procedure TDlgTgEncMain.NewEdEncEditProc(var Msg: TMessage); var hDrop: THandle; FileCount: Integer; FileName: array[0..MAX_PATH] of Char; begin // WM_DROPFILES 메시지가 들어왔는지 확인합니다. if Msg.Msg = WM_DROPFILES then begin hDrop := Msg.WParam; try FileCount := DragQueryFile(hDrop, $FFFFFFFF, nil, 0); if FileCount > 0 then begin DragQueryFile(hDrop, 0, FileName, MAX_PATH); edEncPath.Text := String(FileName); edDecPath.Text := CutFileExt(edEncPath.Text) + '_enc' + ExtractFileExt(edEncPath.Text); end; finally DragFinish(hDrop); end; Msg.Result := 0; end else begin FOldEncEditProc(Msg); end; end; procedure TDlgTgEncMain.NewEdSrcEditProc(var Msg: TMessage); var hDrop: THandle; FileCount: Integer; FileName: array[0..MAX_PATH] of Char; begin // WM_DROPFILES 메시지가 들어왔는지 확인합니다. if Msg.Msg = WM_DROPFILES then begin hDrop := Msg.WParam; try FileCount := DragQueryFile(hDrop, $FFFFFFFF, nil, 0); if FileCount > 0 then begin DragQueryFile(hDrop, 0, FileName, MAX_PATH); edSrcPath.Text := String(FileName); edDestPath.Text := CutFileExt(edSrcPath.Text) + '_enc' + ExtractFileExt(edSrcPath.Text); end; finally DragFinish(hDrop); end; Msg.Result := 0; end else begin FOldEditProc(Msg); end; end; procedure TDlgTgEncMain.btnEncSavePathClick(Sender: TObject); begin edDestPath.Text := Trim(edDestPath.Text); if edDestPath.Text <> '' then begin edEncPath.Text := edDestPath.Text; edDecPath.Text := CutFileExt(edDestPath.Text) + '_dec' + ExtractFileExt(edDestPath.Text); end; end; procedure TDlgTgEncMain.btnGetHeadClick(Sender: TObject); var dec: TTgDrmDec; begin edEncPath.Text := Trim(edEncPath.Text); if not FileExists(edEncPath.Text) then begin MessageBox(Handle, PChar('암호화 파일이 존재하지 않습니다.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; MgCtrls_.Save; Guard(dec, TTgDrmDec.Create(edEncPath.Text)); if not dec.CheckSig(SIG_DRM) then begin MessageBox(Handle, PChar('암호화 파일이 아닙니다.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; if not dec.ExtrHead(PASS_DRM_HEAD) then begin MessageBox(Handle, PChar('헤더 정보를 가져올 수 없습니다.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; mmHead.Clear; mmHead.Lines.Add('Version : ' + IntToStr(dec.Head.wVer)); mmHead.Lines.Add('CustomerCode : ' + IntToStr(dec.Head.dwCustomerCode)); // mmHead.Lines.Add('DateTime : ' + DateTimeToStr(dec.Head.dtEnc)); mmHead.Lines.Add('EmpNo : ' + dec.EmpNo); mmHead.Lines.Add('HostName : ' + dec.HostName); mmHead.Lines.Add('PartName : ' + dec.PartName); // mmHead.Lines.Add('PolicyGroup : ' + dec.PolicyGroup); end; procedure TDlgTgEncMain.btnPathClick(Sender: TObject); begin OpenDialog.FileName := ''; if OpenDialog.Execute(Handle) then begin edSrcPath.Text := OpenDialog.FileName; edDestPath.Text := CutFileExt(edSrcPath.Text) + '_enc' + ExtractFileExt(edSrcPath.Text); end; end; procedure TDlgTgEncMain.btnDecClick(Sender: TObject); var dec: TTgDrmDec; begin edEncPath.Text := Trim(edEncPath.Text); edDecPath.Text := Trim(edDecPath.Text); if not FileExists(edEncPath.Text) then begin MessageBox(Handle, PChar('암호화 파일이 존재하지 않습니다.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; if not DirectoryExists(ExtractFilePath(edDecPath.Text)) then begin MessageBox(Handle, PChar('저장 경로가 존재하지 않습니다.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; MgCtrls_.Save; Guard(dec, TTgDrmDec.Create(edEncPath.Text)); if not dec.CheckSig(SIG_DRM) then begin MessageBox(Handle, PChar('암호화 파일이 아닙니다.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; if not dec.ExtrHead(PASS_DRM_HEAD) then begin MessageBox(Handle, PChar('헤더 정보를 가져올 수 없습니다.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; if dec.DecryptToFile(PASS_DRM_DATA, edDecPath.Text) then begin if FileExists(edSrcPath.Text) then begin if GetFileToSha1Str(edSrcPath.Text) = GetFileToSha1Str(edDecPath.Text) then MessageBox(Handle, PChar('파일이 복호화 되었습니다. (해시 같음)'), PChar(Caption), MB_ICONQUESTION or MB_OK) else MessageBox(Handle, PChar('파일이 복호화 되었습니다. (해시 다름)'), PChar(Caption), MB_ICONWARNING or MB_OK); end else MessageBox(Handle, PChar('파일이 복호화 되었습니다.'), PChar(Caption), MB_ICONQUESTION or MB_OK); end else MessageBox(Handle, PChar('복호화 실패!'), PChar(Caption), MB_ICONWARNING or MB_OK); end; procedure TDlgTgEncMain.btnEncClick(Sender: TObject); var // enc: TTgEncrypt; // fsSrc, fsDest: TFileStream; enc: TTgDrmEnc; begin // ShowMessage(GetWindowCaption($C125A)); //exit; edSrcPath.Text := Trim(edSrcPath.Text); edDestPath.Text := Trim(edDestPath.Text); edEmpNo.Text := Trim(edEmpNo.Text); edHostName.Text := Trim(edHostName.Text); edPart.Text := Trim(edPart.Text); edPG.Text := Trim(edPG.Text); edCode.Text := Trim(edCode.Text); if not FileExists(edSrcPath.Text) then begin MessageBox(Handle, PChar('대상 파일이 존재하지 않습니다.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; if not DirectoryExists(ExtractFilePath(edDestPath.Text)) then begin MessageBox(Handle, PChar('저장 경로가 존재하지 않습니다.'), PChar(Caption), MB_ICONWARNING or MB_OK); exit; end; if edEmpNo.Text = '' then begin MessageBox(Handle, PChar('사번을 입력해 주십시오.'), PChar(Caption), MB_ICONWARNING or MB_OK); edEmpNo.SetFocus; exit; end; if edHostName.Text = '' then begin MessageBox(Handle, PChar('호스트 이름을 입력해 주십시오.'), PChar(Caption), MB_ICONWARNING or MB_OK); edHostName.SetFocus; exit; end; if edPart.Text = '' then begin MessageBox(Handle, PChar('부서 이름을 입력해 주십시오.'), PChar(Caption), MB_ICONWARNING or MB_OK); edPart.SetFocus; exit; end; if edPG.Text = '' then begin MessageBox(Handle, PChar('정책 그룹을 입력해 주십시오.'), PChar(Caption), MB_ICONWARNING or MB_OK); edPG.SetFocus; exit; end; // 113001 if edCode.Text = '' then begin MessageBox(Handle, PChar('업체 코드를 입력해 주십시오.'), PChar(Caption), MB_ICONWARNING or MB_OK); edCode.SetFocus; exit; end; MgCtrls_.Save; Guard(enc, TTgDrmEnc.Create(edDestPath.Text)); enc.SetHaed(PASS_DRM_HEAD, SIG_DRM, edEmpNo.Text, edHostName.Text, edPart.Text, edPG.Text, StrToInt64Def(edCode.Text, 0)); if enc.EncryptFromFile(PASS_DRM_DATA, edSrcPath.Text) then MessageBox(Handle, PChar('파일이 암호화 되었습니다.'), PChar(Caption), MB_ICONQUESTION or MB_OK); end; end.