Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

How to disable console window when using ppapi flash

Post Reply
crystalxp
Posts: 39
Joined: Tue Jul 04, 2017 8:23 am

How to disable console window when using ppapi flash

Post by crystalxp »

Hello!
When I use demo like minibrowser....the GlobalCEFApp.FlashEnabled:= True...
a black console window will flashed and then disappear after 1 or 2 seconds...
it ugly for me :oops: :oops: :oops:

I find that BriskBard browser not show this ugly window.... How can i do the same thing using cef4delphi


I have find the topic in http://magpcss.org/ceforum/viewtopic.php?f=6&t=13094
and try to set GlobalCEFApp.NoSandbox:= False ...but it still not sovled this problem.
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to disable console window when using ppapi flash

Post by salvadordf »

Hi,

Flash shows a DOS box with the message NOT SANDBOXED whenever you try to use their plugin in a non sandboxed browser. This is a bug in the Flash plugin.

Creating a sandboxed browser requires, among other things, to add cef_sandbox.lib into the executable but that's not easy for Delphi apps and I'm not sure it would be legal to do it in anything that is not distributed under the GPL license.

You could modify the flash plugin but antivirus software might not like that and it could cause legal problems.

The solution for now is to hook and intercept those calls with the Detours library or wait till 2020 when Adobe will discontinue the Flash plugin.

More information about hooking :
https://en.wikipedia.org/wiki/Hooking

The Detours library :
https://github.com/MahdiSafsafi/delphi-detours-library
crystalxp
Posts: 39
Joined: Tue Jul 04, 2017 8:23 am

Re: How to disable console window when using ppapi flash

Post by crystalxp »

Thanks,Finally,I choose the modify flash to solve this problem....because this app is just used for myself inner....
hook maybe conflict with other code...and cause other problem....so i give up it .
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to disable console window when using ppapi flash

Post by salvadordf »

This code has been tested in 32 bit ONLY!

Follow these steps :
  • Download the Detours library from https://github.com/MahdiSafsafi/delphi-detours-library
  • Decompress the ZIP file in your "Projects" folder.
  • Add the full path to "Detours\Source" to the library path in Delphi.
  • Add "CPUID", "InstDecode" and "DDetours" to the "uses" section in your DPR file.
  • Add this variables to your DPR file :

    Code: Select all

    var
      TrampCreateProcessA : function(lpApplicationName: LPCSTR; lpCommandLine: LPSTR;
                                     lpProcessAttributes, lpThreadAttributes: PSecurityAttributes;
                                     bInheritHandles: BOOL; dwCreationFlags: DWORD; lpEnvironment: Pointer;
                                     lpCurrentDirectory: LPCSTR; const lpStartupInfo: TStartupInfoA;
                                     var lpProcessInformation: TProcessInformation): BOOL; stdcall = nil;
    
      TrampCreateProcessW : function(lpApplicationName: LPCWSTR; lpCommandLine: LPWSTR;
                                     lpProcessAttributes, lpThreadAttributes: PSecurityAttributes;
                                     bInheritHandles: BOOL; dwCreationFlags: DWORD; lpEnvironment: Pointer;
                                     lpCurrentDirectory: LPCWSTR; const lpStartupInfo: TStartupInfoW;
                                     var lpProcessInformation: TProcessInformation): BOOL; stdcall = nil;
    
  • Add these functions to your DPR file :

    Code: Select all

    function AnsiStringToString(const aAnsiChar : PAnsiChar; aCodePage : cardinal; var aRsltString : string; aFlags : cardinal) : boolean;
    var
      TempLen : integer;
    begin
      Result := False;
      TempLen := MultiByteToWideChar(aCodePage, aFlags, aAnsiChar, -1, nil, 0);
    
      if (TempLen > 0) then
        begin
          SetLength(aRsltString, TempLen);
          Result := (MultiByteToWideChar(aCodePage, aFlags, aAnsiChar, -1, PWideChar(aRsltString), TempLen) > 0);
        end;
    end;
    
    function InterceptCreateProcessA(lpApplicationName: LPCSTR; lpCommandLine: LPSTR;
                                     lpProcessAttributes, lpThreadAttributes: PSecurityAttributes;
                                     bInheritHandles: BOOL; dwCreationFlags: DWORD; lpEnvironment: Pointer;
                                     lpCurrentDirectory: LPCSTR; const lpStartupInfo: TStartupInfoA;
                                     var lpProcessInformation: TProcessInformation): BOOL; stdcall;
    const
      CODEPAGE_ANSI = 1252;
    var
      TempString : string;
    begin
      AnsiStringToString(lpCommandLine, CODEPAGE_ANSI, TempString, 0);
    
      if (pos('echo NOT SANDBOXED', TempString) > 0) then
        Result := True
       else
        Result := TrampCreateProcessA(lpApplicationName, lpCommandLine, lpProcessAttributes,
                                      lpThreadAttributes, bInheritHandles, dwCreationFlags,
                                      lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation);
    end;
    
    function InterceptCreateProcessW(lpApplicationName: LPCWSTR; lpCommandLine: LPWSTR;
                                     lpProcessAttributes, lpThreadAttributes: PSecurityAttributes;
                                     bInheritHandles: BOOL; dwCreationFlags: DWORD; lpEnvironment: Pointer;
                                     lpCurrentDirectory: LPCWSTR; const lpStartupInfo: TStartupInfoW;
                                     var lpProcessInformation: TProcessInformation): BOOL; stdcall;
    var
      TempString : string;
    begin
      TempString := lpCommandLine;
    
      if (pos('echo NOT SANDBOXED', TempString) > 0) then
        Result := True
       else
        Result := TrampCreateProcessW(lpApplicationName, lpCommandLine, lpProcessAttributes,
                                      lpThreadAttributes, bInheritHandles, dwCreationFlags,
                                      lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation);
    end;
    
  • Add these code lines to your DPR file :

    Code: Select all

        @TrampCreateProcessA := InterceptCreate(@CreateProcessA, @InterceptCreateProcessA);
        @TrampCreateProcessW := InterceptCreate(@CreateProcessW, @InterceptCreateProcessW);
    
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to disable console window when using ppapi flash

Post by salvadordf »

That's estrange.

It's hard to tell what's causing this but it could be a Detours library bug, a virus infection, operating system corruption, outdated graphics drivers, hardware problems...
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to disable console window when using ppapi flash

Post by salvadordf »

What Windows version is installed in that computer?
Can you give more details about that computer?
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: How to disable console window when using ppapi flash

Post by salvadordf »

Thanks! :D

I'll try to replicate the error.
Post Reply