BSOne.SFC/Tocsg.Module/TocsgDRM/EXE_DrmAssistor/DDrmAssistorMain.pas

255 lines
8.3 KiB
Plaintext
Raw Permalink Blame History

unit DDrmAssistorMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Tocsg.Process,
Vcl.ExtCtrls;
type
TDlgDrmAssistorMain = class(TForm)
Button1: TButton;
tAtiveV: TTimer;
procedure Button1Click(Sender: TObject);
procedure tAtiveVTimer(Sender: TObject);
private
{ Private declarations }
dwCurPid_,
dwOpenTick_,
dwChildExePid_: DWORD;
sOpenFName_: String;
ThdAppMon_: TThdProcessWatch;
procedure OnAppNotify(aSender: TThdProcessWatch; pEnt: PPwEnt; aKind: TProcessWatchKind);
public
{ Public declarations }
Constructor Create(aOwner: TComponent); override;
Destructor Destroy; override;
end;
var
DlgDrmAssistorMain: TDlgDrmAssistorMain;
implementation
uses
BoxedAppSDK_Static,
// BoxedAppSDK_DLL,
Tocsg.Safe, Tocsg.Shell, Winapi.ShellAPI, Tocsg.Trace, Tocsg.WndUtil,
Tocsg.Path;
{$R *.dfm}
Constructor TDlgDrmAssistorMain.Create(aOwner: TComponent);
begin
Inherited Create(aOwner);
sOpenFName_ := '';
dwOpenTick_ := 0;
dwCurPid_ := GetCurrentProcessId;
dwChildExePid_ := 0;
ThdAppMon_ := nil;
BoxedAppSDK_SetContext('21f2f010-06e4-465f-af8f-cde6a3752c39');
BoxedAppSDK_Init;
// BoxedAppSDK_EnableOption(DEF_BOXEDAPPSDK_OPTION__INHERIT_OPTIONS, TRUE);
// BoxedAppSDK_EnableOption(DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL, TRUE);
BoxedAppSDK_EnableOption(DEF_BOXEDAPPSDK_OPTION__EMBED_BOXEDAPP_IN_CHILD_PROCESSES, TRUE);
// BoxedAppSDK_EnableOption(DEF_BOXEDAPPSDK_OPTION__HIDE_VIRTUAL_FILES_FROM_FILE_DIALOG, TRUE);
// BoxedAppSDK_EnableOption(DEF_BOXEDAPPSDK_OPTION__EMULATE_OUT_OF_PROC_COM_SERVERS, TRUE);
end;
Destructor TDlgDrmAssistorMain.Destroy;
begin
// BoxedAppSDK_Exit;
if ThdAppMon_ <> nil then
FreeAndNil(ThdAppMon_);
Inherited;
end;
procedure TDlgDrmAssistorMain.OnAppNotify(aSender: TThdProcessWatch; pEnt: PPwEnt; aKind: TProcessWatchKind);
var
sHlpExe: String;
h: HWND;
begin
case aKind of
pwkUnknown : {$IFDEF DEBUG} ASSERT(false) {$ENDIF};
// pwkInit,
pwkExecute :
begin
if dwCurPid_ = pEnt.dwPPid then
begin
dwChildExePid_ := pEnt.dwPid;
tAtiveV.Enabled := true;
end;
end;
pwkTerminated :
begin
if pEnt.dwPid = dwChildExePid_ then
TerminateProcess(GetCurrentProcess, 100);
end;
end;
end;
procedure TDlgDrmAssistorMain.tAtiveVTimer(Sender: TObject);
var
h: HWND;
sPath,
sCaption: String;
begin
if dwChildExePid_ <> 0 then
begin
h := GetForegroundWindow;
if h <> 0 then
begin
sCaption := GetWindowCaption(h);
if sCaption = '' then
exit;
if GetProcessPIDFromWndHandle(h) = dwChildExePid_ then
begin
if (Pos(sOpenFName_, UpperCase(sCaption)) = 0) and
((GetTickCount - dwOpenTick_) < 3000) then exit;
tAtiveV.Enabled := false;
sPath := 'C:\taskToCSG\Tocsg.Module\TocsgDRM\OUT_Debug - Win32\ccc.txt';
if FileExists(sPath) then
DeleteFile(sPath); //
WriteLnFileEndUTF8(sPath, IntToStr(h));
// InjectModule(dwChildExePid_, GetRunExePathDir + 'DrmAssistor.dll');
BoxedAppSDK_RemoteProcess_LoadLibrary(dwChildExePid_, PChar(GetRunExePathDir + 'DrmAssistor.dll'));
if BoxedAppSDK_IsAttachedProcessId(dwChildExePid_) then
begin
BoxedAppSDK_RemoteProcess_EnableOption(dwChildExePid_, DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL, TRUE);
// ShowMessage('<27><><EFBFBD><EFBFBD>!');
end else
ShowMessage('<27><><EFBFBD><EFBFBD>...');
end;
end;
end;
end;
procedure TDlgDrmAssistorMain.Button1Click(Sender: TObject);
var
sPath, sVPath, sVEPath: String;
hFile: THandle;
ms: TMemoryStream;
dwTemp: DWORD;
StartupInfo: TStartupInfo;
ProcInfo: TProcessInformation;
sDir: String;
ShellExeInfo: TShellExecuteInfo;
dwPid: DWORD;
begin
// sPath := 'C:\Users\tocsg\Desktop\<5C><><EFBFBD>ñٹ<C3B1>PC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ַ<EFBFBD><D6B7><EFBFBD> <20><><EFBFBD><EFBFBD> RFI_v1.0.pdf';
sPath := 'C:\Users\tocsg\Desktop\<5C><><EFBFBD>İ<EFBFBD><C4B0><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> v1.0_220110.docx';
// sPath := 'C:\Users\tocsg\Desktop\<5C><><EFBFBD>İ<EFBFBD><C4B0><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ħ.hwp';
// sPath := 'C:\Users\tocsg\Desktop\cutproc.exe';
// ExecutePath('explorer.exe', sPath);
// exit;
if not FileExists(sPath) then
begin
ShowMessage('Fail .. 1');
exit;
end;
Guard(ms, TMemoryStream.Create);
ms.LoadFromFile(sPath);
// sDir := ExtractFilePath(sPath) + '$VVV\';
sDir := ExtractFilePath(sPath);
// if not BoxedAppSDK_CreateVirtualDirectory(PChar(sDir), nil) then
// exit;
// sVPath := '@TgDRM\' + sPath;
// sVPath := sDir + ExtractFileName(sPath);
sVPath := sDir + '$1_' + ExtractFileName(sPath);
if not FileExists(sVPath) then
begin
hFile := BoxedAppSDK_CreateVirtualFile(PChar(sVPath),
// GENERIC_WRITE, FILE_SHARE_READ, nil, CREATE_NEW, FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_READONLY, 0);
GENERIC_WRITE, FILE_SHARE_READ, nil, CREATE_NEW, FILE_ATTRIBUTE_HIDDEN, 0);
// GENERIC_WRITE, FILE_SHARE_READ, nil, CREATE_NEW, FILE_ATTRIBUTE_ARCHIVE, 0);
if (hFile = 0) or (hFile = INVALID_HANDLE_VALUE) then
begin
ShowMessage('Fail .. 2');
exit;
end;
dwTemp := 0;
WriteFile(hFile, ms.Memory^, ms.Size, dwTemp, nil);
CloseHandle(hFile);
end;
// WinExec(PAnsiChar(AnsiString(Format('notepad.exe "%s"', [sVPath]))), SW_SHOW);
// WinExec(PAnsiChar(AnsiString(sVPath)), SW_SHOWNORMAL);
// ExecutePath('explorer.exe', '"' + sVPath + '"');
// ExecutePath('"C:\Program Files\Adobe\Acrobat DC\Acrobat\Acrobat.exe"', '"' + sVPath + '"');
ThdAppMon_ := TThdProcessWatch.Create(true);
ThdAppMon_.OnProcessWatchNotify := OnAppNotify;
ThdAppMon_.StartThread;
// ExecutePath('"C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE"', '"' + sVPath + '"');
sOpenFName_ := UpperCase(ExtractFileName(sVPath));
dwOpenTick_ := GetTickCount;
ExecutePath(sVPath);
Button1.Enabled := false;
// dwPid := GetProcessPidByName('WINWORD.EXE');
// if dwPid <> 0 then
// begin
// BoxedAppSDK_RemoteProcess_EnableOption(dwPid, DEF_BOXEDAPPSDK_OPTION__INHERIT_OPTIONS, TRUE);
// BoxedAppSDK_RemoteProcess_EnableOption(dwPid, DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL, TRUE);
// BoxedAppSDK_RemoteProcess_EnableOption(dwPid, DEF_BOXEDAPPSDK_OPTION__HIDE_VIRTUAL_FILES_FROM_FILE_DIALOG, TRUE);
// end;
// ProcInfo := ExecuteApp('C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE', '"' + sVPath + '"', SW_SHOWNORMAL);
// if ProcInfo.dwProcessId <> 0 then
// begin
//// BoxedAppSDK_RemoteProcess_EnableOption(ProcInfo.dwProcessId, DEF_BOXEDAPPSDK_OPTION__INHERIT_OPTIONS, TRUE);
// BoxedAppSDK_RemoteProcess_EnableOption(ProcInfo.dwProcessId, DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL, TRUE);
//// BoxedAppSDK_RemoteProcess_EnableOption(ProcInfo.dwProcessId, DEF_BOXEDAPPSDK_OPTION__HIDE_VIRTUAL_FILES_FROM_FILE_DIALOG, TRUE);
// end;
// ZeroMemory(@ShellExeInfo, SizeOf(ShellExeInfo));
// ShellExeInfo.cbSize := SizeOf(ShellExeInfo);
// ShellExeInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
// ShellExeInfo.lpVerb := 'open';
// ShellExeInfo.nShow := SW_SHOWNORMAL;
// ShellExeInfo.lpFile := PChar(sVPath);
// ShellExecuteEx(@ShellExeInfo);
//
//
// if ShellExeInfo.hProcess <> 0 then
// begin
// dwPid := GetProcessId(ShellExeInfo.hProcess);
//// BoxedAppSDK_RemoteProcess_EnableOption(dwPid, DEF_BOXEDAPPSDK_OPTION__INHERIT_OPTIONS, TRUE);
// BoxedAppSDK_RemoteProcess_EnableOption(dwPid, DEF_BOXEDAPPSDK_OPTION__ALL_CHANGES_ARE_VIRTUAL, TRUE);
//// BoxedAppSDK_RemoteProcess_EnableOption(dwPid, DEF_BOXEDAPPSDK_OPTION__HIDE_VIRTUAL_FILES_FROM_FILE_DIALOG, TRUE);
//// ShowMessage(GetProcessNameByPid(dwPid));
// end;
// ms.Clear;
// ms.LoadFromFile('C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE');
// ZeroMemory(@ProcInfo, SizeOf(ProcInfo));
// ZeroMemory(@StartupInfo, SizeOf(StartupInfo));
// StartupInfo.cb := Sizeof(StartupInfo);
// StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
// StartupInfo.wShowWindow := SW_SHOWNORMAL;
// StartupInfo.dwX := 0;
// StartupInfo.dwY := 0;
//
// if not BoxedAppSDK_CreateProcessFromMemoryW(ms.Memory, ms.Size, nil, PChar('"' + sVPath + '"'),
// nil, nil, false, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS or CREATE_SUSPENDED, nil, nil, StartupInfo, ProcInfo) then
// ShowMessage('<27><><EFBFBD><EFBFBD>');
end;
end.