SlideShare a Scribd company logo
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
•   #import <Foundation/Foundation.h>

    int main(int argc, char** argv) {
        NSAutoreleasePool* pool =
             [[NSAutoreleasePool alloc] init];

        // Objective-C code here
        NSLog(@”Hello World!”);

        [pool drain];
        return 0;
    }
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
•   #include   "EXTERN.h"
    #include   "perl.h"
    #include   "XSUB.h"
    #include   "ppport.h"

    XS(func) {
        dXSARGS;

        // code here

        XSRETURN(0);
    }

    XS(boot_Foo) {
        newXS("Foo::xs_function", func, __FILE__);
    }
• package Foo;
  use strict;
  use XSLoader;

  XSLoader::load __PACKAGE__, $VERSION;

  1;
• use   Foo;

  Foo::xs_function();
•   use inc::Module::Install;

    # some basic descriptions here

    use_ppport '3.19';

    WriteAll;
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
•   #include   "EXTERN.h"
    #include   "perl.h"
    #include   "XSUB.h"
    #include   "ppport.h"

    // undefine Move macro, this is conflict to Mac OS X QuickDraw API.
    #undef Move

    #import <Foundation/Foundation.h>

    XS(hello) {
        dXSARGS;

        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
        NSLog(@"Hello!");
        [pool drain];

        XSRETURN(0);
    }

    XS(boot_Hello) {
        newXS("Hello::hello", hello, __FILE__);
    }
• #include "EXTERN.h"
  #include "perl.h"
  #include "XSUB.h"
  #include "ppport.h"
• #undef   Move
• XS(function)   {
      dXSARGS;
      // code here
      XSRETURN(0);
  }
• XS(function)   {
      dXSARGS;
      // code here
      ST(0) = some_sv;
      XSRETURN(1);
  }
• XS(function)   {
      dXSARGS;
      // code here
      ST(0) = some_sv;
      ST(1) = some_sv2;
      XSRETURN(2);
  }
•   XS(function) {
        dXSARGS;

        SV* sv_args1 = ST(0);
        SV* sv_args2 = ST(1);

        // code here

        ST(0) = some_sv;
        ST(1) = some_sv2;
        XSRETURN(2);
    }
•   XS(function) {
        dXSARGS;

        if (items < 2) {
            Perl_croak(aTHX_ "Usage: function($args1, $args2)");
        }

        SV* sv_args1 = ST(0);
        SV* sv_args2 = ST(1);

        // code here

        ST(0) = some_sv;
        ST(1) = some_sv2;
        XSRETURN(2);
    }
STRLEN len;
char* c = SvPV(sv, len);
NSString* str = [NSString stringWithUTF8String:c];




SV* sv = sv_2mortal(newSV(0));
sv_setpv(sv, [str UTF8String]);
NSNumber* n;
if (SvNOKp(sv)) {
    n = [NSNumber numberWithDouble:(double)SvNVX(sv))];
}
else if (SvIOK_UV(sv)) {
    n = [NSNumber numberWithDouble:(double)SvUV(sv))];
}
else if (SvIOKp(sv)) {
    n = [NSNumber numberWithDouble:(double)SvIV(sv))];
}



SV* sv = sv_2mortal(newSVnv([n doubleValue]));
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
Hacking Mac OSX Cocoa API from Perl
• use   Cocoa::Growl ':all';

  my $installed = growl_installed();
  my $running   = growl_running();
• use   Cocoa::Growl ':all';

  # register application
  growl_register(
      app            => 'My growl script',
      icon           => '/path/to/icon.png',
                   # or 'http://urlto/icon'
      notifications =>
          [qw(Notification1 Notification2)],
  );
• use   Cocoa::Growl ':all';

  # show growl notification
  growl_notify(
      name        => 'Notification1',
      title       => 'Hello!',
      description => 'Growl world!',
  );
•   use Cocoa::EventLoop;
    use Cocoa::Growl ':all';

    growl_register(
        name          => 'test script',
        notifications => ['test notification'],
    );

    my $wait = 1;
    growl_notify(
        name         => 'test notification',
        title        => 'Hello',
        description => 'Growl World!',
        on_click => sub {
             warn 'click';
             $wait = 0;
        },
        on_timeout => sub {
             warn 'timeout';
             $want = 0;
        },
    );

    Cocoa::EventLoop->run_while(0.1) while unless $wait;
Hacking Mac OSX Cocoa API from Perl
use AnyEvent;
use Cocoa::EventLoop;

# then all anyevent based api use
Cocoa::EventLoop!
•   use AnyEvent;
    use Cocoa::EventLoop;
    use Cocoa::Growl;

    my $cv = AE::cv;
    growl_notify(
        name         => 'test notification',
        title        => 'Hello',
        description => 'Growl World!',
        on_click => sub {
             warn ‘click’;
             $cv->send;
        },
        on_timeout => sub {
             warn ‘timeout’;
             $cv->send;
        },
    );
    $cv->recv;
Hacking Mac OSX Cocoa API from Perl

More Related Content

PDF
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
PDF
Ember background basics
ODP
Linux Command Line
PDF
Intro django
PDF
PuppetCamp SEA 1 - Version Control with Puppet
TXT
C99[2]
PDF
Javascript ES6 generators
Стажировка 2016-07-27 02 Денис Нелюбин. PostgreSQL и jsonb
Ember background basics
Linux Command Line
Intro django
PuppetCamp SEA 1 - Version Control with Puppet
C99[2]
Javascript ES6 generators

What's hot (20)

PDF
RabbitMQ
POTX
Accumulo Summit 2015: Zookeeper, Accumulo, and You [Internals]
PDF
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
PDF
KubeCon EU 2016: Custom Volume Plugins
PPTX
How Secure Are Docker Containers?
PDF
Build your own private openstack cloud
PDF
Docker 基本概念與指令操作
PDF
使用 CLI 管理 OpenStack 平台
PDF
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
PDF
Leaks & Zombies
PDF
Ansible tips & tricks
PDF
并发模型介绍
PDF
Debugging: Rules & Tools
PDF
ES6 generators
PDF
PDF
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
PDF
Beyond Golden Containers: Complementing Docker with Puppet
PPTX
Using the Power to Prove
KEY
Paris js extensions
PPTX
How to recognise that the user has just uninstalled your android app droidc...
RabbitMQ
Accumulo Summit 2015: Zookeeper, Accumulo, and You [Internals]
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
KubeCon EU 2016: Custom Volume Plugins
How Secure Are Docker Containers?
Build your own private openstack cloud
Docker 基本概念與指令操作
使用 CLI 管理 OpenStack 平台
Puppet Camp Chicago 2014: Smoothing Troubles With Custom Types and Providers ...
Leaks & Zombies
Ansible tips & tricks
并发模型介绍
Debugging: Rules & Tools
ES6 generators
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
Beyond Golden Containers: Complementing Docker with Puppet
Using the Power to Prove
Paris js extensions
How to recognise that the user has just uninstalled your android app droidc...

Similar to Hacking Mac OSX Cocoa API from Perl (20)

KEY
循環参照のはなし
PDF
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
PDF
5分で始める XS - tsukuba.xs#1
PDF
Introduction to Moose
KEY
Good Evils In Perl (Yapc Asia)
PDF
Os Wilhelm
PDF
CPAN 模組二三事
ODP
Embedding perl
ODP
Embed--Basic PERL XS
ODP
Getting started with Perl XS and Inline::C
PDF
Going to Mars with Groovy Domain-Specific Languages
ODP
30 Minutes To CPAN
PDF
PerlIntro
PDF
PerlIntro
PDF
What's New in Perl? v5.10 - v5.16
PDF
Writing Modular Command-line Apps with App::Cmd
PDF
Groovy Domain Specific Languages - SpringOne2GX 2012
PDF
Perl-C/C++ Integration with Swig
KEY
Api Design
PDF
Perl XS by example
循環参照のはなし
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
5分で始める XS - tsukuba.xs#1
Introduction to Moose
Good Evils In Perl (Yapc Asia)
Os Wilhelm
CPAN 模組二三事
Embedding perl
Embed--Basic PERL XS
Getting started with Perl XS and Inline::C
Going to Mars with Groovy Domain-Specific Languages
30 Minutes To CPAN
PerlIntro
PerlIntro
What's New in Perl? v5.10 - v5.16
Writing Modular Command-line Apps with App::Cmd
Groovy Domain Specific Languages - SpringOne2GX 2012
Perl-C/C++ Integration with Swig
Api Design
Perl XS by example

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPT
Teaching material agriculture food technology
PDF
Empathic Computing: Creating Shared Understanding
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Modernizing your data center with Dell and AMD
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
KodekX | Application Modernization Development
Spectral efficient network and resource selection model in 5G networks
Unlocking AI with Model Context Protocol (MCP)
The Rise and Fall of 3GPP – Time for a Sabbatical?
Teaching material agriculture food technology
Empathic Computing: Creating Shared Understanding
Diabetes mellitus diagnosis method based random forest with bat algorithm
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Modernizing your data center with Dell and AMD
Network Security Unit 5.pdf for BCA BBA.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Chapter 3 Spatial Domain Image Processing.pdf
Electronic commerce courselecture one. Pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
A Presentation on Artificial Intelligence
Mobile App Security Testing_ A Comprehensive Guide.pdf
KodekX | Application Modernization Development

Hacking Mac OSX Cocoa API from Perl

  • 12. #import <Foundation/Foundation.h> int main(int argc, char** argv) { NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; // Objective-C code here NSLog(@”Hello World!”); [pool drain]; return 0; }
  • 17. #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" XS(func) { dXSARGS; // code here XSRETURN(0); } XS(boot_Foo) { newXS("Foo::xs_function", func, __FILE__); }
  • 18. • package Foo; use strict; use XSLoader; XSLoader::load __PACKAGE__, $VERSION; 1;
  • 19. • use Foo; Foo::xs_function();
  • 20. use inc::Module::Install; # some basic descriptions here use_ppport '3.19'; WriteAll;
  • 26. #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" // undefine Move macro, this is conflict to Mac OS X QuickDraw API. #undef Move #import <Foundation/Foundation.h> XS(hello) { dXSARGS; NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Hello!"); [pool drain]; XSRETURN(0); } XS(boot_Hello) { newXS("Hello::hello", hello, __FILE__); }
  • 27. • #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h"
  • 28. • #undef Move
  • 29. • XS(function) { dXSARGS; // code here XSRETURN(0); }
  • 30. • XS(function) { dXSARGS; // code here ST(0) = some_sv; XSRETURN(1); }
  • 31. • XS(function) { dXSARGS; // code here ST(0) = some_sv; ST(1) = some_sv2; XSRETURN(2); }
  • 32. XS(function) { dXSARGS; SV* sv_args1 = ST(0); SV* sv_args2 = ST(1); // code here ST(0) = some_sv; ST(1) = some_sv2; XSRETURN(2); }
  • 33. XS(function) { dXSARGS; if (items < 2) { Perl_croak(aTHX_ "Usage: function($args1, $args2)"); } SV* sv_args1 = ST(0); SV* sv_args2 = ST(1); // code here ST(0) = some_sv; ST(1) = some_sv2; XSRETURN(2); }
  • 34. STRLEN len; char* c = SvPV(sv, len); NSString* str = [NSString stringWithUTF8String:c]; SV* sv = sv_2mortal(newSV(0)); sv_setpv(sv, [str UTF8String]);
  • 35. NSNumber* n; if (SvNOKp(sv)) { n = [NSNumber numberWithDouble:(double)SvNVX(sv))]; } else if (SvIOK_UV(sv)) { n = [NSNumber numberWithDouble:(double)SvUV(sv))]; } else if (SvIOKp(sv)) { n = [NSNumber numberWithDouble:(double)SvIV(sv))]; } SV* sv = sv_2mortal(newSVnv([n doubleValue]));
  • 43. • use Cocoa::Growl ':all'; my $installed = growl_installed(); my $running = growl_running();
  • 44. • use Cocoa::Growl ':all'; # register application growl_register( app => 'My growl script', icon => '/path/to/icon.png', # or 'http://urlto/icon' notifications => [qw(Notification1 Notification2)], );
  • 45. • use Cocoa::Growl ':all'; # show growl notification growl_notify( name => 'Notification1', title => 'Hello!', description => 'Growl world!', );
  • 46. use Cocoa::EventLoop; use Cocoa::Growl ':all'; growl_register( name => 'test script', notifications => ['test notification'], ); my $wait = 1; growl_notify( name => 'test notification', title => 'Hello', description => 'Growl World!', on_click => sub { warn 'click'; $wait = 0; }, on_timeout => sub { warn 'timeout'; $want = 0; }, ); Cocoa::EventLoop->run_while(0.1) while unless $wait;
  • 48. use AnyEvent; use Cocoa::EventLoop; # then all anyevent based api use Cocoa::EventLoop!
  • 49. use AnyEvent; use Cocoa::EventLoop; use Cocoa::Growl; my $cv = AE::cv; growl_notify( name => 'test notification', title => 'Hello', description => 'Growl World!', on_click => sub { warn ‘click’; $cv->send; }, on_timeout => sub { warn ‘timeout’; $cv->send; }, ); $cv->recv;