#!/usr/bin/perl
use strict;
use warnings;
use Win32;
use Win32::API;
use Win32::API::Callback;
my $org_title = "Unbenannt - Editor";
my $new_title = "Hacked by esskar! :-)";
my $EnumWindows = Win32::API->new( "user32", "EnumWindows", "PN", "N" );
my $EnumChildWnds = Win32::API->new( "user32", "EnumChildWindows", "NKN", "N" );
my $FindWindowEx = Win32::API->new( "user32", "FindWindowEx", "NNPP", "N" );
my $GetClassName = Win32::API->new( "user32", "GetClassName", "NPN", "N" );
my $SetWindowText = Win32::API->new( "user32", "SetWindowText", "NP", "N" );
my $PostMessage = Win32::API->new( "user32", "PostMessage", "NNNN", "N" );
my $hwnd = $FindWindowEx->Call( 0, 0, "Notepad", 0 );
die "Window not found." unless $hwnd;
my $editHwnd = 0;
my $EnumWindowsProc = Win32::API::Callback->new(
sub {
my ( $hwnd, $param ) = @_;
my $className = " " x 256;
my $len =
$GetClassName->Call( $hwnd, $className, length($className) - 1 );
$className = substr( $className, 0, $len );
if ( lc $className eq 'edit' ) {
$editHwnd = $hwnd;
return 0;
}
return 1;
},
"NN",
"N"
);
$EnumChildWnds->Call( $hwnd, $EnumWindowsProc, 0 );
die "Edit Window not found." unless $editHwnd;
$SetWindowText->Call( $hwnd, $new_title );
&write_to_window( $editHwnd, "Just a test!\n" );
use constant WM_CHAR => 258;
sub write_to_window {
my ( $hwnd, $text ) = @_;
my @chars = split //, $text;
foreach my $c (@chars) {
$PostMessage->Call($hwnd, WM_CHAR, ord $c, 0);
}
}