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();  ...
TiShadow                     websockets                     (socket.io)  tishadow app                     tishadow   TiSDK...
TiShadow try {   if(current && current.close !== undefined) {     current.close();   }   current = eval(message.code);   i...
Code in Transit
Cornwall     $(#native).click(function() {    Cornwall.execute(function() {      Titanium.Contacts.showContacts({});    })...
Cornwallvar web_popup = function(a) {  alert("Returned a from Native: " + a.a);};$(#bounce).click(function() {  Cornwall.e...
CornwallCornwall.execute = function (fn, arg) {  try {    var args = [];    for (var i = 1, length = arguments.length; i< ...
Cornwallfunction evalFn(o) {   try{     eval("(" + o.fn.replace(/Cornwall.callback(([^)]*))/g, "(function(o) {__web.evalJS...
Cornwallvar web_popup = function(a) {  alert("Returned a from Native: " + a.a);};$(#bounce).click(function() {  Cornwall.e...
Cornwall  (function() {    alert("Hello From Native");    Cornwall.callback(web_popup)({a: "A"});  })()
Cornwallfunction evalFn(o) {   try{     eval("(" + o.fn.replace(/Cornwall.callback(([^)]*))/g, "(function(o) {__web.evalJS...
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.string...
Apps in Transit
TiShadow           • Bundles source and assets           • Send bundle to device/s           • Unpack           • Execute
Tweaking TiSDK                      • Allow require from the                        applicationDataDirectory              ...
TiShadow                      websockets                      (socket.io)  tishadow app   TiSDK (partial)                 ...
TiShadow 16      + fs.readFileSync(src).toString() 17.replace(/Ti(tanium)?.Filesystem.(resourcesDirectory|getResourcesDire...
TiShadow18   .replace(/require(/g, "__p.require(")                               Redirect Require                         ...
TiShadow20   .replace(/([ :=(])(["])/(.*?)(["])/g, "$1__p.file($2$3$4)")                                 Redirect Assets
TiShadow21   .replace(/Ti(tanium)?.API/g, "__log");                              Redirect Logs
TiShadow15 var src_text = "try { var __p = require(/api/PlatformRequire), __log =require(/api/Log), assert = require(/api/...
TiShadow19   .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...
#TiLondon                      websockets                      (socket.io)  tishadow app   TiSDK (partial)                ...
@TiLondon
@Codestrong              Coding on ANY              device
David Bankier  @davidbankierdavid@yydigital.com
Section Title SlidePrelude to nextsection
Lorem Ipsum•   Item 1    Lorem ipsum dolor sit•   Item 2    amet, consectetur adipiscing elit.              Morbi pretium ...
Lorem Ipsum              • Item 1              • Item 2              • Item 3              • Item 4              • Item 5
Lorem Ipsum              • Item 1              • Item 2              • Item 3              • Item 4              • Highlig...
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 ...
Codestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session   hacking titanium
Codestrong 2012 breakout session   hacking titanium
Upcoming SlideShare
Loading in …5
×

Codestrong 2012 breakout session hacking titanium

854 views

Published on

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
854
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
13
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Codestrong 2012 breakout session hacking titanium

  1. 1. Hacking Titanium David Bankier Director YY Digital @davidbankier david@yydigital.com
  2. 2. Code is (mostly)evaluated at runtime
  3. 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. 4. TiShadow websockets (socket.io) tishadow app tishadow TiSDK (partial) server node.js express socket.io Ace
  5. 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
  6. 6. Code in Transit
  7. 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. 8. Cornwallvar 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. 9. CornwallCornwall.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. 10. Cornwallfunction 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. 11. Cornwallvar 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. 12. Cornwall (function() { alert("Hello From Native"); Cornwall.callback(web_popup)({a: "A"}); })()
  13. 13. Cornwallfunction 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. 14. Cornwall (function() { alert("Hello From Native"); Cornwall.callback(web_popup)({a: "A"}); })()
  15. 15. Cornwall (function() { alert("Hello From Native"); (function(o) { __web.evalJS(web_popup(+ JSON.stringify(o) + );); })({a: "A"}); })()
  16. 16. Apps in Transit
  17. 17. TiShadow • Bundles source and assets • Send bundle to device/s • Unpack • Execute
  18. 18. Tweaking TiSDK • Allow require from the applicationDataDirectory • Do not cache CommonJS modules loaded from applicationDataDirectory For More: Commit: Allows CommonJS from applicationDataDirectory
  19. 19. TiShadow websockets (socket.io) tishadow app TiSDK (partial) tishadow cli Built with Custom rewrites, bundles Titanium SDK and sends off your code.
  20. 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. 21. TiShadow18 .replace(/require(/g, "__p.require(") Redirect Require Function
  22. 22. TiShadow20 .replace(/([ :=(])(["])/(.*?)(["])/g, "$1__p.file($2$3$4)") Redirect Assets
  23. 23. TiShadow21 .replace(/Ti(tanium)?.API/g, "__log"); Redirect Logs
  24. 24. TiShadow15 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. 25. TiShadow19 .replace(/Ti.Locale.getString/g, "L”) Dynamic Localisation
  26. 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,describe,xdescribe];methods.forEach(function(method) {this[method] =jasmine[method];});" 24 +src_text; 25 } Fast(er) Testing Iterations
  27. 27. #TiLondon websockets (socket.io) tishadow app TiSDK (partial) tishadow cli Built with Custom rewrites, bundles Titanium SDK and sends off your code.
  28. 28. @TiLondon
  29. 29. @Codestrong Coding on ANY device
  30. 30. David Bankier @davidbankierdavid@yydigital.com
  31. 31. Section Title SlidePrelude to nextsection
  32. 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. 33. Lorem Ipsum • Item 1 • Item 2 • Item 3 • Item 4 • Item 5
  34. 34. Lorem Ipsum • Item 1 • Item 2 • Item 3 • Item 4 • Highlight Item
  35. 35. Lorem Ipsum • Item 1 • Item 2 • Item 3 • Item 4 • Item 5
  36. 36. Lorem Ipsum • Item 1 • Item 2 • Item 3 • Item 4 • Item 5
  37. 37. 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.”

×