BSOne.SFC/Tocsg.Module/FasooDRM/EXE_bs1fsg/Dbs1fsgMain.pas

189 lines
5.3 KiB
Plaintext

unit Dbs1fsgMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
type
TDlgbs1fsgMain = class(TForm)
Button1: TButton;
tMtx: TTimer;
procedure Button1Click(Sender: TObject);
procedure tMtxTimer(Sender: TObject);
private
{ Private declarations }
sOwnerMtx_, sFsDir_: String;
InfoList_: TStringList;
public
{ Public declarations }
Constructor Create(aOwner: TComponent); override;
Destructor Destroy; override;
procedure process_WM_COPYDATA(var msg: TMessage); Message WM_COPYDATA;
end;
var
Dlgbs1fsgMain: TDlgbs1fsgMain;
implementation
uses
Tocsg.Fasoo.Global, Tocsg.Safe, Tocsg.Strings, Tocsg.Win32, ProcessParam,
Tocsg.Exception, superobject, Tocsg.Fasoo.Global.Define, Tocsg.Trace;
{$R *.dfm}
Constructor TDlgbs1fsgMain.Create(aOwner: TComponent);
begin
Inherited Create(aOwner);
sOwnerMtx_ := gParam.OwnerMtx;
sFsDir_ := gParam.FsDir;
InfoList_ := TStringList.Create;
ChangeWindowMessageFilter(WM_COPYDATA, MSGFLT_ADD);
if sOwnerMtx_ = '' then
TerminateProcess(GetCurrentProcess, 98);
tMtx.Enabled := true;
end;
Destructor TDlgbs1fsgMain.Destroy;
begin
FreeAndNil(InfoList_);
Inherited;
end;
procedure TDlgbs1fsgMain.Button1Click(Sender: TObject);
var
nType: Integer;
sHInfo, sFsDir, sEncPath, sDecPath, sCPID: String;
InfoList: TStringList;
begin
SetOverWriteFlag(1);
// sFsDir := 'C:\taskToCSG\Tocsg.Module\FasooDRM\Document\25_0123 CJ_EDLP_암복호화 API (수정)\FasooPackagerADK_DLL\Release\fsdinit';
sFsDir := 'C:\taskToCSG\eCrmHE\OUT_Debug - Win64\conf\fsdinitg';
sEncPath := 'C:\taskToCSG\Tocsg.Module\FasooDRM\Document\25_0123 CJ_EDLP_암복호화 API (수정)\FasooPackagerADK_DLL\Release\content\encfile\FED5.xls';
sDecPath := 'C:\taskToCSG\Tocsg.Module\FasooDRM\Document\25_0123 CJ_EDLP_암복호화 API (수정)\FasooPackagerADK_DLL\Release\content\decfile\FED5_dec.xls';
// sEncPath := 'C:\taskToCSG\Tocsg.Module\FasooDRM\Document\25_0123 CJ_EDLP_암복호화 API (수정)\FasooPackagerADK_DLL\Release\content\encfile\FED4.xls';
// sDecPath := 'C:\taskToCSG\Tocsg.Module\FasooDRM\Document\25_0123 CJ_EDLP_암복호화 API (수정)\FasooPackagerADK_DLL\Release\content\decfile\FED4_dec.xls';
// GetFileType_r()는 제대로 동작암함 25_0217 18:44:44 kku
nType := GetFileTypeW_r(sEncPath);
case nType of
26, 103, 105, 106 : ;
else begin
ShowMessage(Format('파수DRM 파일이 아닙니다. Type=%d', [nType]));
exit;
end;
end;
sHInfo := GetFileHeader_r(sEncPath);
if sHInfo = '' then
begin
ShowMessage('파일 헤더 정보를 가져올 수 없습니다.');
exit;
end;
Guard(InfoList, TStringList.Create);
SplitString(sHInfo, ';', InfoList, true);
if InfoList.Count < 18 then
begin
ShowMessage('CPID 값을 확인 할 수 없습니다.');
exit;
end;
sCPID := InfoList[17]; // 18번째에 있음
if DoExtract_r(sFsDir, sCPID, sEncPath, sDecPath) = FASOO_OK then
ShowMessage('복호화 성공')
else
ShowMessage('복호화 실패');
end;
procedure TDlgbs1fsgMain.tMtxTimer(Sender: TObject);
begin
if not MutexExists(sOwnerMtx_) then
TerminateProcess(GetCurrentProcess, 99);
end;
procedure TDlgbs1fsgMain.process_WM_COPYDATA(var msg: TMessage);
var
dwData: DWORD;
pCpData: PCopyDataStruct;
O: ISuperObject;
sTemp, sEncPath, sDecPath: String;
nType: Integer;
begin
msg.Result := 0;
dwData := 0;
pCpData := PCopyDataStruct(msg.LParam);
try
dwData := pCpData.dwData;
case dwData of
FSCMD_DECRYPT_FILE :
begin
sTemp := Copy(PChar(pCpData.lpData), 1, pCpData.cbData);
O := SO(sTemp);
sEncPath := O.S['EncPath'];
sDecPath := O.S['DecPath'];
if not FileExists(sEncPath) then
begin
TTgTrace.T('파수DRM 복호화 대상 파일이 없습니다. EncPath=%s', [sEncPath]);
exit;
end;
// GetFileType_r()는 제대로 동작암함 25_0217 18:44:44 kku
// 특정 환경? 타이밍? 에서 DRM 파일인데도 20만 반환함
nType := GetFileTypeW_r(sEncPath);
TTgTrace.T('파수DRM 복호화 시작. Type=%d, EncPath=%s, DecPath=%s', [nType, sEncPath, sDecPath]);
case nType of
109, // 이거 뭔지 모르지만 GetFileTypeW_r()로 FED5 암호화파일에서 검출됨.. 25_0217 18:54:27 kku
26, 103, 105, 106 : ;
else begin
TTgTrace.T('파수DRM 파일이 아닙니다. Path=%s, Type=%d', [sEncPath, nType]);
exit;
end;
end;
sTemp := GetFileHeader_r(sEncPath);
if sTemp = '' then
begin
TTgTrace.T('파일 헤더 정보를 가져올 수 없습니다. Path=%s', [sEncPath]);
exit;
end;
SplitString(sTemp, ';', InfoList_, true);
if InfoList_.Count < 18 then
begin
TTgTrace.T('CPID 값을 확인 할 수 없습니다.');
exit;
end;
sTemp := InfoList_[17]; // 18번째에 있음
if not DirectoryExists(sFsDir_) then
begin
TTgTrace.T('FSD 폴더가 없습니다.');
exit;
end;
nType := DoExtract_r(sFsDir_, sTemp, sEncPath, sDecPath);
if nType = FASOO_OK then
msg.Result := 10
else
TTgTrace.T('파수DRM 복호화 실패, Path=%s, Error=%d', [sEncPath, nType]);
end;
end;
except
on E: Exception do
ETgException.TraceException(Self, E, 'Fail .. process_WM_COPYDATA()');
end;
end;
end.