Advertisement
hackerboxes

as debug class

Aug 31st, 2012
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.42 KB | None | 0 0
  1. /**
  2. * Debug
  3. * Designed for version 0.96.7 to 1.0 of the Arthropod Debugger.
  4. *
  5. * USE AT YOUR OWN RISK!
  6. * Any trace that is made with arthropod may be viewed by others.
  7. * The main purpose of arthropod and this debug class is to debug
  8. * unpublished AIR applications or sites in their real
  9. * environment (such as a web-browser). Future versions of
  10. * Arthropod may change the trace-engine pattern and may cause
  11. * traces for older versions not work properly.
  12. *
  13. * A big thanks goes out to:
  14. * Stockholm Postproduction - www.stopp.se
  15. * Lee Brimelow - www.theflashblog.com
  16. *
  17. * @author Carl Calderon 2008
  18. * @version 0.74
  19. * @link http.//www.carlcalderon.com/
  20. * @since 0.72
  21. */
  22.  
  23. package com.carlcalderon.arthropod {
  24.  
  25. import flash.display.Bitmap;
  26. import flash.display.BitmapData;
  27. import flash.display.DisplayObject;
  28. import flash.display.IBitmapDrawable;
  29. import flash.display.Stage;
  30. import flash.events.StatusEvent;
  31. import flash.geom.Matrix;
  32. import flash.geom.Rectangle;
  33. import flash.net.LocalConnection;
  34. import flash.system.System;
  35. import flash.utils.ByteArray;
  36.  
  37. public class Debug {
  38.  
  39. /**
  40. * Version control
  41. */
  42. public static const NAME :String = 'Debug';
  43. public static const VERSION :String = '0.74';
  44.  
  45. /**
  46. * Privacy
  47. * By setting this password, you need to enter the
  48. * same in "Arthropod -> Settings -> Connection Password"
  49. * to be able to see the traces.
  50. *
  51. * default: 'CDC309AF';
  52. */
  53. public static var password :String = 'CDC309AF';
  54.  
  55. /**
  56. * Predefined colors
  57. */
  58. public static var RED :uint = 0xCC0000;
  59. public static var GREEN :uint = 0x00CC00;
  60. public static var BLUE :uint = 0x6666CC;
  61. public static var PINK :uint = 0xCC00CC;
  62. public static var YELLOW :uint = 0xCCCC00;
  63. public static var LIGHT_BLUE :uint = 0x00CCCC;
  64.  
  65. /**
  66. * Status event
  67. * If false, arthropod will trace error messages.
  68. */
  69. public static var ignoreStatus :Boolean = true;
  70.  
  71. /**
  72. * Security (not tested)
  73. * If secure is true, only the <code>secureDomain</code> will be accepted.
  74. */
  75. public static var secure :Boolean = false;
  76.  
  77. /**
  78. * A single domain to be used as the secure domain. (not tested)
  79. */
  80. public static var secureDomain :String = '*';
  81.  
  82. /**
  83. * Switches tracing on/off.
  84. * TIP: Set this switch to false before release of AIR applications.
  85. */
  86. public static var allowLog :Boolean = true;
  87.  
  88. /**
  89. * DO NOT CHANGE THESE VALUES! IF CHANGED, ARTHROPOD MIGHT NOT WORK PROPERLY!
  90. */
  91. private static const DOMAIN :String = 'com.carlcalderon.Arthropod';
  92. private static const CHECK :String = '.161E714B6C1A76DE7B9865F88B32FCCE8FABA7B5.1';
  93. private static const TYPE :String = 'app';
  94. private static const CONNECTION :String = 'arthropod';
  95.  
  96. private static const LOG_OPERATION :String = 'debug';
  97. private static const ERROR_OPERATION :String = 'debugError';
  98. private static const WARNING_OPERATION :String = 'debugWarning';
  99. private static const ARRAY_OPERATION :String = 'debugArray';
  100. private static const BITMAP_OPERATION :String = 'debugBitmapData';
  101. private static const OBJECT_OPERATION :String = 'debugObject';
  102. private static const MEMORY_OPERATION :String = 'debugMemory';
  103. private static const CLEAR_OPERATION :String = 'debugClear';
  104.  
  105. private static var lc :LocalConnection = new LocalConnection();
  106. private static var hasEventListeners :Boolean = false;
  107.  
  108. /**
  109. * Traces a message to Arthropod
  110. *
  111. * @param message Message to be traced
  112. * @param color opt. Color of the message
  113. * @return True if successful
  114. */
  115. public static function log ( message:*, color:uint = 0xFEFEFE ) :Boolean {
  116. return send ( LOG_OPERATION, String ( message ) , color ) ;
  117. }
  118.  
  119. /**
  120. * Traces a warning to Arthropod.
  121. * The message will be displayed in yellow.
  122. *
  123. * @param message Message to be traced
  124. * @return True if successful
  125. */
  126. public static function error ( message:* ) :Boolean {
  127. return send ( ERROR_OPERATION, String ( message ) , 0xCC0000 ) ;
  128. }
  129.  
  130. /**
  131. * Traces an error to Arthropod.
  132. * The message will be displayed in red.
  133. *
  134. * @param message Message to be traced
  135. * @return True if successful
  136. */
  137. public static function warning ( message:* ) :Boolean {
  138. return send ( WARNING_OPERATION, String ( message ) , 0xCCCC00 ) ;
  139. }
  140.  
  141. /**
  142. * Clears all the traces, including arrays and bitmaps
  143. * from the Arthropod application window.
  144. *
  145. * @return True if successful
  146. */
  147. public static function clear ( ) :Boolean {
  148. return send ( CLEAR_OPERATION, 0, 0x000000 ) ;
  149. }
  150.  
  151. /**
  152. * Traces an array to Arthropod.
  153. *
  154. * If no earlier arrays have been traced,
  155. * Arthropod will open up the array-window
  156. * automatically. For each array that is traced,
  157. * the array-window will clear and display the
  158. * new one. This is useful for buffer-arrays, etc.
  159. *
  160. * @param arr Array to be traced
  161. * @return True if successful
  162. */
  163. public static function array ( arr:Array ) :Boolean {
  164. return send ( ARRAY_OPERATION, arr,null ) ;
  165. }
  166.  
  167. /**
  168. * Traces a thumbnail of the specified BitmapData
  169. * to Arthropod.
  170. *
  171. * The internal connection between Arthropod and
  172. * the Debug class only accept calls less than
  173. * 40Kb. The bitmap method converts the specified
  174. * BitmapData to an acceptable size for the call.
  175. *
  176. * @param bmd Any IBitmapDrawable
  177. * @param label Label
  178. * @return True if successful
  179. */
  180. public static function bitmap ( bmd:*, label:String = null ) :Boolean {
  181. var bm:BitmapData = new BitmapData ( 100, 100, true, 0x00FFFFFF ) ;
  182. var mtx:Matrix = new Matrix ( ) ;
  183. var s:Number = 100 / (( bmd.width >= bmd.height ) ? bmd.width : bmd.height ) ;
  184. mtx.scale ( s, s ) ;
  185. bm.draw ( bmd, mtx,null,null,null,true ) ;
  186. var bounds:Rectangle = new Rectangle ( 0, 0, Math.floor ( bmd.width * s ) , Math.floor ( bmd.height * s ) ) ;
  187. return send ( BITMAP_OPERATION, bm.getPixels ( bounds ), { bounds:bounds, lbl:label } ) ;
  188. }
  189.  
  190. /**
  191. * Traces a snapshot of the current stage state.
  192. *
  193. * @param stage Stage
  194. * @param label Label
  195. * @return True if successful
  196. */
  197. public static function snapshot ( stage:Stage, label:String=null ) :Boolean {
  198. if ( stage )
  199. return bitmap ( stage, label ) ;
  200. return false;
  201. }
  202.  
  203. /**
  204. * Traces an <code>object</code> to Arthropod.
  205. * The first level of arguments are traced as follows:
  206. *
  207. * trace:
  208. * Debug.object( { name: Carl, surname: Calderon } );
  209. *
  210. * output:
  211. * object
  212. * name: Carl
  213. * surname: Calderon
  214. *
  215. * @param obj Object to be traced
  216. * @return True if successful
  217. */
  218. public static function object ( obj:* ) :Boolean {
  219. return send ( OBJECT_OPERATION, obj, null ) ;
  220. }
  221.  
  222. /**
  223. * Traces the current memory size used by Adobe Flash Player.
  224. * Observe that this also includes AIR applications (such as
  225. * Arthropod). Use with care.
  226. *
  227. * @return True if successful
  228. */
  229. public static function memory ( ) :Boolean {
  230. return send ( MEMORY_OPERATION, System.totalMemory, null ) ;
  231. }
  232.  
  233. /**
  234. * [internal-use]
  235. * Sends the message
  236. *
  237. * @param operation Operation name
  238. * @param value Value to send
  239. * @param color opt. Color of the message
  240. */
  241. private static function send( operation:String, value:*, prop:* ):Boolean {
  242. if (!secure) lc.allowInsecureDomain('*');
  243. else lc.allowDomain(secureDomain);
  244. if (!hasEventListeners) {
  245. if ( ignoreStatus ) lc.addEventListener(StatusEvent.STATUS, ignore);
  246. else lc.addEventListener(StatusEvent.STATUS, status);
  247. hasEventListeners = true;
  248. }
  249. if(allowLog){
  250. try {
  251. lc.send ( TYPE + '#' + DOMAIN + CHECK + ':' + CONNECTION , operation, password, value, prop ) ;
  252. return true;
  253. } catch (e:*) {
  254. return false;
  255. }
  256. }
  257. return false;
  258. }
  259.  
  260. /**
  261. * [internal-use]
  262. * Traces the status of the Debugger.
  263. *
  264. * @see ignoreStatus
  265. * @param e StatusEvent
  266. */
  267. private static function status(e:StatusEvent):void {
  268. trace( 'Arthropod status:\n' + e.toString() );
  269. }
  270.  
  271. /**
  272. * [internal-use]
  273. * Method used to ignore StatusEvent's if an error occurs.
  274. *
  275. * @see ignoreStatus
  276. * @param e StatusEvent
  277. */
  278. private static function ignore(e:StatusEvent):void { }
  279.  
  280. }
  281.  
  282. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement