SlideShare a Scribd company logo
Hacking Titanium


     David Bankier
        Director
       YY Digital
     @davidbankier

   david@yydigital.com
Code is (mostly)
evaluated at runtime
TiHighlight


      tabGroup.setActiveTab(1);
  try {
    if(current && current.close !== undefined) {
       current.close();
    }
    current = eval(message.code);
    if(current && current.open !== undefined) {
                 tabGroup.activeTab.open(current);
    }
  } catch (e) {
    if(Ti.Platform.osname === 'android') {
       alert(e.toString());
    } else { //iOS Error
       alert("Line: " + e.line + "n" + e.message);
    }
  }
TiShadow




                     websockets
                     (socket.io)



  tishadow app                     tishadow
   TiSDK (partial)                  server
                                     node.js
                                     express
                                    socket.io
                                       Ace
TiShadow


 try {
   if(current && current.close !== undefined) {
     current.close();
   }
   current = eval(message.code);
   if(current && current.open !== undefined) {
     current.open();
   }
   log.info("Deployed");
 } catch (e) {
   log.error(utils.extractExceptionData(e));
 }




                               For More: Forging Titanium - Episode 23
Code in Transit
Cornwall


     $('#native').click(function() {
    Cornwall.execute(function() {
      Titanium.Contacts.showContacts({});
    });
  });



     var start = new Date();
  $('#variables').click(function() {
    var text = 'Hello World';
    Cornwall.execute(function(start, text) {
      alert("Started: " + start +
                          "nText: " + text);
    },start, text);
  });
Cornwall


var web_popup = function(a) {
  alert("Returned 'a' from Native: " + a.a);
};

$('#bounce').click(function() {
  Cornwall.execute(function() {
    alert("Hello From Native");
    Cornwall.callback(web_popup)({a: "A"});
  });
});
Cornwall


Cornwall.execute = function (fn, arg) {
  try {
    var args = [];
    for (var i = 1, length = arguments.length; i< length; i++) {
      args.push(arguments[i]);
    }
    Ti.App.fireEvent("cornwall:" + Cornwall.id, {
           fn: fn.toString(),
           args: args
       });
  } catch (e) {
    alert(e);
  }
}
Cornwall

function evalFn(o) {
   try{
     eval("(" + o.fn.replace(/Cornwall.callback(([^)]*))/g, "(function(o) {
__web.evalJS('$1(' + JSON.stringify(o) + ');');})") + ")("+
JSON.stringify(o.args).substring(1).replace("]","") +")");
   } catch (e) {
     alert(e);
   }
};
Cornwall


var web_popup = function(a) {
  alert("Returned 'a' from Native: " + a.a);
};

$('#bounce').click(function() {
  Cornwall.execute(function() {
    alert("Hello From Native");
    Cornwall.callback(web_popup)({a: "A"});
  });
});
Cornwall


  (function() {
    alert("Hello From Native");
    Cornwall.callback(web_popup)({a: "A"});
  })()
Cornwall

function evalFn(o) {
   try{
     eval("(" + o.fn.replace(/Cornwall.callback(([^)]*))/g, "(function(o) {
__web.evalJS('$1(' + JSON.stringify(o) + ');');})") + ")("+
JSON.stringify(o.args).substring(1).replace("]","") +")");
   } catch (e) {
     alert(e);
   }
};
Cornwall


  (function() {
    alert("Hello From Native");
    Cornwall.callback(web_popup)({a: "A"});
  })()
Cornwall


  (function() {
    alert("Hello From Native");
    (function(o) {
      __web.evalJS('web_popup('+
         JSON.stringify(o) + ');');
    })({a: "A"});
  })()
Apps in Transit
TiShadow



           • Bundles source and assets

           • Send bundle to device/s

           • Unpack

           • Execute
Tweaking TiSDK




                      • Allow require from the
                        applicationDataDirectory

                      • Do not cache CommonJS
                        modules loaded from
                        applicationDataDirectory



                 For More:
                 Commit: Allows CommonJS from
                 applicationDataDirectory
TiShadow




                      websockets
                      (socket.io)



  tishadow app
   TiSDK (partial)                  tishadow cli
  Built with Custom
                                     rewrites, bundles
    Titanium SDK
                                    and sends off your
                                           code.
TiShadow


 16      + fs.readFileSync(src).toString()
 17
.replace(/Ti(tanium)?.Filesystem.(resourcesDirectory|getResourcesDirectory(
))/g, "Ti.Filesystem.applicationDataDirectory + '"+app_name.replace(/
/g,"_")+"/'")




                               Redirect Resources
TiShadow


18   .replace(/require(/g, "__p.require(")




                               Redirect Require
                               Function
TiShadow


20   .replace(/([ :=(])(['"])/(.*?)(['"])/g, "$1__p.file($2$3$4)")




                                 Redirect Assets
TiShadow


21   .replace(/Ti(tanium)?.API/g, "__log");




                              Redirect Logs
TiShadow

15 var src_text = "try { var __p = require('/api/PlatformRequire'), __log =
require('/api/Log'), assert = require('/api/Assert'), L =
require('/api/Localisation').fetchString;n"

//...

26 src_text += '} catch(e) { e.file="' + src + '";
__log.error(require("/api/Utils").extractExceptionData(e)); }';




                                  Better Error Handling
TiShadow


19   .replace(/Ti.Locale.getString/g, "L”)




                               Dynamic Localisation
TiShadow


 22 if (src.match("_spec.js$")) {
 23     src_text = "var jasmine = require('/lib/jasmine-1.2.0');var methods =
['spyOn','it','xit','expect','runs','waits','waitsFor','beforeEach','afterEach','describ
e','xdescribe'];methods.forEach(function(method) {this[method] =
jasmine[method];});"
 24      +src_text;
 25 }




                                    Fast(er) Testing
                                    Iterations
#TiLondon




                      websockets
                      (socket.io)



  tishadow app
   TiSDK (partial)                  tishadow cli
  Built with Custom
                                     rewrites, bundles
    Titanium SDK
                                    and sends off your
                                           code.
@TiLondon
@Codestrong




              Coding on ANY
              device
David Bankier
  @davidbankier

david@yydigital.com
Section Title Slide
Prelude to next
section
Lorem Ipsum


•   Item 1    Lorem ipsum dolor sit
•   Item 2    amet, consectetur adipiscing elit.
              Morbi pretium scelerisque nisl, sit
•   Item 3
              amet viverra mauris mollis nec.
•   Item 4
              Aliquam sem sem, rutrum non
•   Item 5    pellentesque id, tempus sit amet
              nibh. Morbi nisi ante, elementum vel
              facilisis a, gravida eu libero. In eget
              porttitor.
Lorem Ipsum


              • Item 1

              • Item 2

              • Item 3

              • Item 4

              • Item 5
Lorem Ipsum


              • Item 1

              • Item 2

              • Item 3

              • Item 4

              • Highlight Item
Codestrong 2012 breakout session   hacking titanium
Lorem Ipsum


              • Item 1

              • Item 2

              • Item 3

              • Item 4

              • Item 5
Lorem Ipsum


              • Item 1

              • Item 2

              • Item 3

              • Item 4

              • Item 5
Lorem Ipsum


       Jeff Haynie   “Appcelerator Titanium is the first
  CEO & Co-founder
      Appcelerator   mobile platform to combine the
                     flexibility of open source
                     development technologies with the
                     power of cloud services.”
Codestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session   hacking titanium

More Related Content

PDF
Virtual machine and javascript engine
PDF
JVM Mechanics
PDF
JavaScript ∩ WebAssembly
PDF
Scala to assembly
PDF
JVM Mechanics: Understanding the JIT's Tricks
PDF
Writing native bindings to node.js in C++
PDF
Java Performance Puzzlers
Virtual machine and javascript engine
JVM Mechanics
JavaScript ∩ WebAssembly
Scala to assembly
JVM Mechanics: Understanding the JIT's Tricks
Writing native bindings to node.js in C++
Java Performance Puzzlers

What's hot (20)

PDF
Letswift19-clean-architecture
PDF
The Ring programming language version 1.2 book - Part 79 of 84
PDF
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
PDF
Aaron Bedra - Effective Software Security Teams
PDF
科特林λ學
PDF
Wprowadzenie do technologi Big Data i Apache Hadoop
PDF
Advanced Object-Oriented JavaScript
PDF
The Ring programming language version 1.10 book - Part 102 of 212
PDF
Concurrency Concepts in Java
PDF
Node.js extensions in C++
PDF
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
PDF
JJUG CCC 2011 Spring
PDF
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
PDF
Compose Async with RxJS
ODP
2011-03-29 London - drools
PDF
The Ring programming language version 1.5.2 book - Part 13 of 181
PDF
The Ring programming language version 1.5.1 book - Part 9 of 180
PDF
Innovative Specifications for Better Performance Logging and Monitoring
PDF
Annotation processing and code gen
PDF
Testing a 2D Platformer with Spock
Letswift19-clean-architecture
The Ring programming language version 1.2 book - Part 79 of 84
Letswift18 워크숍#1 스위프트 클린코드와 코드리뷰
Aaron Bedra - Effective Software Security Teams
科特林λ學
Wprowadzenie do technologi Big Data i Apache Hadoop
Advanced Object-Oriented JavaScript
The Ring programming language version 1.10 book - Part 102 of 212
Concurrency Concepts in Java
Node.js extensions in C++
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
JJUG CCC 2011 Spring
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Compose Async with RxJS
2011-03-29 London - drools
The Ring programming language version 1.5.2 book - Part 13 of 181
The Ring programming language version 1.5.1 book - Part 9 of 180
Innovative Specifications for Better Performance Logging and Monitoring
Annotation processing and code gen
Testing a 2D Platformer with Spock

Similar to Codestrong 2012 breakout session hacking titanium (20)

PDF
20110525[Taipei GTUG] titanium mobile簡介
PDF
Cross Domain Web
Mashups with JQuery and Google App Engine
PPTX
Event-driven IO server-side JavaScript environment based on V8 Engine
PDF
KEY
CouchDB on Android
PDF
mobl
PPTX
Dartprogramming
PDF
JavaScript Web Workers
KEY
Kinect de-theremin
PPTX
Spicy javascript: Create your first Chrome extension for web analytics QA
KEY
Writing robust Node.js applications
KEY
iPhone Development Intro
PPTX
Phone Gap
PDF
Eric Lafortune - The Jack and Jill build system
ZIP
Javascript Everywhere
PPSX
Automated malware analysis
PDF
Node.js - async for the rest of us.
PDF
Painless Persistence in a Disconnected World
PDF
Online Meetup: Why should container system / platform builders care about con...
PDF
Eric Lafortune - The Jack and Jill build system
20110525[Taipei GTUG] titanium mobile簡介
Cross Domain Web
Mashups with JQuery and Google App Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
CouchDB on Android
mobl
Dartprogramming
JavaScript Web Workers
Kinect de-theremin
Spicy javascript: Create your first Chrome extension for web analytics QA
Writing robust Node.js applications
iPhone Development Intro
Phone Gap
Eric Lafortune - The Jack and Jill build system
Javascript Everywhere
Automated malware analysis
Node.js - async for the rest of us.
Painless Persistence in a Disconnected World
Online Meetup: Why should container system / platform builders care about con...
Eric Lafortune - The Jack and Jill build system

More from Axway Appcelerator (20)

PDF
Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
PPTX
2014 Dublin Web Summit by Jeff Haynie
PPTX
Making the Mobile Mind Shift
PPTX
Stop Debating, Start Measuring
PPTX
Mobile & The New Experience Economy (And What it Means for IT)
PPTX
Apps, APIs & Analytics: What "Mobile First" Really Means
PPTX
Appcelerator Presentation Template
PPTX
Codestrong 2012 keynote jonathan rende, appcelerator's vp of products
PPTX
Codestrong 2012 keynote jeff haynie, appcelerator's ceo
PPTX
Codestrong 2012 keynote how to build a top ten app
PPTX
Codestrong 2012 breakout session at&t api platform and trends
PPTX
Codestrong 2012 breakout session what's new in titanium studio
PPTX
Codestrong 2012 breakout session using appcelerator cloud services in your ...
PPTX
Codestrong 2012 breakout session the role of cloud services in your next ge...
PPTX
Codestrong 2012 breakout session new device platform support for titanium
PPTX
Codestrong 2012 breakout session mobile platform and infrastructure
PPTX
Codestrong 2012 breakout session making money on appcelerator's marketplace
PDF
Codestrong 2012 breakout session live multi-platform testing
PPTX
Codestrong 2012 breakout session leveraging titanium as part of your mobile...
PPTX
Codestrong 2012 breakout session i os internals and best practices
Axway Appcelerator - Titanium SDK 6.1.0 - Status, Releases & Roadmap
2014 Dublin Web Summit by Jeff Haynie
Making the Mobile Mind Shift
Stop Debating, Start Measuring
Mobile & The New Experience Economy (And What it Means for IT)
Apps, APIs & Analytics: What "Mobile First" Really Means
Appcelerator Presentation Template
Codestrong 2012 keynote jonathan rende, appcelerator's vp of products
Codestrong 2012 keynote jeff haynie, appcelerator's ceo
Codestrong 2012 keynote how to build a top ten app
Codestrong 2012 breakout session at&t api platform and trends
Codestrong 2012 breakout session what's new in titanium studio
Codestrong 2012 breakout session using appcelerator cloud services in your ...
Codestrong 2012 breakout session the role of cloud services in your next ge...
Codestrong 2012 breakout session new device platform support for titanium
Codestrong 2012 breakout session mobile platform and infrastructure
Codestrong 2012 breakout session making money on appcelerator's marketplace
Codestrong 2012 breakout session live multi-platform testing
Codestrong 2012 breakout session leveraging titanium as part of your mobile...
Codestrong 2012 breakout session i os internals and best practices

Codestrong 2012 breakout session hacking titanium

  • 1. Hacking Titanium David Bankier Director YY Digital @davidbankier david@yydigital.com
  • 3. TiHighlight tabGroup.setActiveTab(1); try { if(current && current.close !== undefined) { current.close(); } current = eval(message.code); if(current && current.open !== undefined) { tabGroup.activeTab.open(current); } } catch (e) { if(Ti.Platform.osname === 'android') { alert(e.toString()); } else { //iOS Error alert("Line: " + e.line + "n" + e.message); } }
  • 4. TiShadow websockets (socket.io) tishadow app tishadow TiSDK (partial) server node.js express socket.io Ace
  • 5. TiShadow try { if(current && current.close !== undefined) { current.close(); } current = eval(message.code); if(current && current.open !== undefined) { current.open(); } log.info("Deployed"); } catch (e) { log.error(utils.extractExceptionData(e)); } For More: Forging Titanium - Episode 23
  • 7. Cornwall $('#native').click(function() { Cornwall.execute(function() { Titanium.Contacts.showContacts({}); }); }); var start = new Date(); $('#variables').click(function() { var text = 'Hello World'; Cornwall.execute(function(start, text) { alert("Started: " + start + "nText: " + text); },start, text); });
  • 8. Cornwall var web_popup = function(a) { alert("Returned 'a' from Native: " + a.a); }; $('#bounce').click(function() { Cornwall.execute(function() { alert("Hello From Native"); Cornwall.callback(web_popup)({a: "A"}); }); });
  • 9. Cornwall Cornwall.execute = function (fn, arg) { try { var args = []; for (var i = 1, length = arguments.length; i< length; i++) { args.push(arguments[i]); } Ti.App.fireEvent("cornwall:" + Cornwall.id, { fn: fn.toString(), args: args }); } catch (e) { alert(e); } }
  • 10. Cornwall function evalFn(o) { try{ eval("(" + o.fn.replace(/Cornwall.callback(([^)]*))/g, "(function(o) { __web.evalJS('$1(' + JSON.stringify(o) + ');');})") + ")("+ JSON.stringify(o.args).substring(1).replace("]","") +")"); } catch (e) { alert(e); } };
  • 11. Cornwall var web_popup = function(a) { alert("Returned 'a' from Native: " + a.a); }; $('#bounce').click(function() { Cornwall.execute(function() { alert("Hello From Native"); Cornwall.callback(web_popup)({a: "A"}); }); });
  • 12. Cornwall (function() { alert("Hello From Native"); Cornwall.callback(web_popup)({a: "A"}); })()
  • 13. Cornwall function evalFn(o) { try{ eval("(" + o.fn.replace(/Cornwall.callback(([^)]*))/g, "(function(o) { __web.evalJS('$1(' + JSON.stringify(o) + ');');})") + ")("+ JSON.stringify(o.args).substring(1).replace("]","") +")"); } catch (e) { alert(e); } };
  • 14. Cornwall (function() { alert("Hello From Native"); Cornwall.callback(web_popup)({a: "A"}); })()
  • 15. Cornwall (function() { alert("Hello From Native"); (function(o) { __web.evalJS('web_popup('+ JSON.stringify(o) + ');'); })({a: "A"}); })()
  • 17. TiShadow • Bundles source and assets • Send bundle to device/s • Unpack • Execute
  • 18. Tweaking TiSDK • Allow require from the applicationDataDirectory • Do not cache CommonJS modules loaded from applicationDataDirectory For More: Commit: Allows CommonJS from applicationDataDirectory
  • 19. TiShadow websockets (socket.io) tishadow app TiSDK (partial) tishadow cli Built with Custom rewrites, bundles Titanium SDK and sends off your code.
  • 20. TiShadow 16 + fs.readFileSync(src).toString() 17 .replace(/Ti(tanium)?.Filesystem.(resourcesDirectory|getResourcesDirectory( ))/g, "Ti.Filesystem.applicationDataDirectory + '"+app_name.replace(/ /g,"_")+"/'") Redirect Resources
  • 21. TiShadow 18 .replace(/require(/g, "__p.require(") Redirect Require Function
  • 22. TiShadow 20 .replace(/([ :=(])(['"])/(.*?)(['"])/g, "$1__p.file($2$3$4)") Redirect Assets
  • 23. TiShadow 21 .replace(/Ti(tanium)?.API/g, "__log"); Redirect Logs
  • 24. TiShadow 15 var src_text = "try { var __p = require('/api/PlatformRequire'), __log = require('/api/Log'), assert = require('/api/Assert'), L = require('/api/Localisation').fetchString;n" //... 26 src_text += '} catch(e) { e.file="' + src + '"; __log.error(require("/api/Utils").extractExceptionData(e)); }'; Better Error Handling
  • 25. TiShadow 19 .replace(/Ti.Locale.getString/g, "L”) Dynamic Localisation
  • 26. TiShadow 22 if (src.match("_spec.js$")) { 23 src_text = "var jasmine = require('/lib/jasmine-1.2.0');var methods = ['spyOn','it','xit','expect','runs','waits','waitsFor','beforeEach','afterEach','describ e','xdescribe'];methods.forEach(function(method) {this[method] = jasmine[method];});" 24 +src_text; 25 } Fast(er) Testing Iterations
  • 27. #TiLondon websockets (socket.io) tishadow app TiSDK (partial) tishadow cli Built with Custom rewrites, bundles Titanium SDK and sends off your code.
  • 29. @Codestrong Coding on ANY device
  • 30. David Bankier @davidbankier david@yydigital.com
  • 31. Section Title Slide Prelude to next section
  • 32. Lorem Ipsum • Item 1 Lorem ipsum dolor sit • Item 2 amet, consectetur adipiscing elit. Morbi pretium scelerisque nisl, sit • Item 3 amet viverra mauris mollis nec. • Item 4 Aliquam sem sem, rutrum non • Item 5 pellentesque id, tempus sit amet nibh. Morbi nisi ante, elementum vel facilisis a, gravida eu libero. In eget porttitor.
  • 33. Lorem Ipsum • Item 1 • Item 2 • Item 3 • Item 4 • Item 5
  • 34. Lorem Ipsum • Item 1 • Item 2 • Item 3 • Item 4 • Highlight Item
  • 36. Lorem Ipsum • Item 1 • Item 2 • Item 3 • Item 4 • Item 5
  • 37. Lorem Ipsum • Item 1 • Item 2 • Item 3 • Item 4 • Item 5
  • 38. Lorem Ipsum Jeff Haynie “Appcelerator Titanium is the first CEO & Co-founder Appcelerator mobile platform to combine the flexibility of open source development technologies with the power of cloud services.”