Page 1 of 1

How to disable console window when using ppapi flash

Posted: Tue Aug 22, 2017 7:38 am
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.

Re: How to disable console window when using ppapi flash

Posted: Tue Aug 22, 2017 8:12 am
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

Re: How to disable console window when using ppapi flash

Posted: Tue Aug 22, 2017 9:55 am
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 .

Re: How to disable console window when using ppapi flash

Posted: Thu Nov 09, 2017 1:26 pm
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);
    

Re: How to disable console window when using ppapi flash

Posted: Fri Nov 10, 2017 8:11 am
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...

Re: How to disable console window when using ppapi flash

Posted: Fri Nov 10, 2017 11:37 am
by salvadordf
What Windows version is installed in that computer?
Can you give more details about that computer?

Re: How to disable console window when using ppapi flash

Posted: Fri Nov 10, 2017 1:45 pm
by salvadordf
Thanks! :D

I'll try to replicate the error.