Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Perl: Общие вопросы > спрятать программу


Автор: kirufka 10.11.2008, 14:40
 smile Народ такой вот вопрос: пишу не вирус! просто хотелось бы кое что спрятать от глаз юзверя (во имя секретности)... Поэтому: как спрятать консольное приложение под win и визуально и из task manager'а. Предположительно скомпилю в .exe  smile 

Автор: shamber 10.11.2008, 16:33
kirufka, а perl тут причем? 

Автор: kirufka 10.11.2008, 20:09
ммм... ну как причем тут perl, на perl'е же хочу сделать сею программу...

Автор: shamber 10.11.2008, 20:26
Код

Код

Use Win32::API. The following code does exactly what Win32::GUI does. 
use Win32::API 0.20;

# just for completeness...
use constant SW_HIDE => 0;
use constant SW_SHOWNORMAL => 1;

# the API we need
my $GetConsoleTitle = new Win32::API('kernel32', 'GetConsoleTitle', 'P
+N', 'N');
my $SetConsoleTitle = new Win32::API('kernel32', 'SetConsoleTitle', 'P
+', 'N');
my $FindWindow = new Win32::API('user32', 'FindWindow', 'PP', 'N');
my $ShowWindow = new Win32::API('user32', 'ShowWindow', 'NN', 'N');

# save the current console title
my $old_title = " " x 1024;
$GetConsoleTitle->Call( $old_title, 1024 );

# build up a new (fake) title
my $title = "PERL-$$-".Win32::GetTickCount();

# sets our string as the console title
$SetConsoleTitle->Call( $title );

# sleep 40 milliseconds to let Windows rename the window
Win32::Sleep(40);

# find the window by title
$hw = $FindWindow->Call( 0, $title );

# restore the old title
$SetConsoleTitle->Call( $old_title );

# hide the console!
$ShowWindow->Call( $hw, SW_HIDE );

# sleep one second, then show the console again

sleep(1);
$ShowWindow->Call( $hw, SW_SHOWNORMAL );

Answer: How to hide/inhibit the console window when launching a Perl script on Windows?
contributed by jdporter 

If you're using ActivePerl, use wperl.exe to run your script. This is a copy of perl.exe that just doesn't create a console window at all. Since you won't have STDIN/STDOUT/STDERR, you won't be able to catch errors. Therefore be sure your script is totally bulletproof before calling it with wperl.exe. 

Using Win32::Process::Create, You could have a "starter" script which launches your script as a detached process: 
Код

Win32::Process::Create( $Obj,
  "$perl_path/perl.exe",
  "perl test.pl",
  0, DETACHED_PROCESS,
  "$hs_path/scripts"
) or die ErrorReport();

Answer: How to hide/inhibit the console window when launching a Perl script on Windows?
contributed by jdporter 

The works when the window you want to hide isn't the one you're interacting with. This is useful, because it lets you see program print output (including error messages) if you run it from a command prompt, but it hides the window if you launch the script from Explorer, Start>Run, etc. 
Код

use Win32::API;


sub hide_console
{
    Win32::API->new( 'kernel32', 'FreeConsole', [], 'I' )->Call();
}

Answer: How to hide/inhibit the console window when launching a Perl script on Windows?
contributed by jdporter 

You can create a standalone .exe file using PerlApp (from ActiveState's PDK) and use the -gui option which will suppress the DOS window on program startup. 
Answer: How to hide/inhibit the console window when launching a Perl script on Windows?
contributed by jdporter 


If you want to stop console windows from popping up when you call commands with backticks, try adding the following block to your script: 
BEGIN
{
    Win32::SetChildShowWindow(0) 
        if defined &Win32::SetChildShowWindow;
}

Автор: shamber 10.11.2008, 20:42
А вот для того чтобы спрятать из Task Manager нужно очень постараться
можете почитать http://www.wasm.ru/article.php?article=1021007 или http://www.wasm.ru/article.php?article=apihook_1
Да в этих статьях нет ничего про перл, но и готовой инфы вы врядли найдете.

Автор: tolkien 11.11.2008, 12:58
Вам надо просто в MFC посмотреть как это делается на С++. Т.е узнать какие win api функции вызываются. И найти к ним интерфейс в perl

Автор: kirufka 11.11.2008, 13:28
Ммм.. всем спасибо smile Точно WinApi smile 

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)