Posts tagged with “debugging”

May 25, 10

Embedding Private Keys in SWF files

I've recently came across the new [online SWF, Zend, and Java decomplier at]( that allows you to almost "view the source" of the SWF file online. If you had some important data stored in your SWF (such as API keys or passwords) you may not wish them being exposed. The easiest (and therefore naïve) way to hide them* would be to store them in external text files and embed in the SWF. [Embed(source="api_key.txt", mimeType="application/octet-stream")] private const API_KEY:Class; // ... var myAPI_KEY:String = String(new API_KEY()); Then you can create an instance and cast it to String, like shown above. The asset class extends mx.core.ByteArrayAsset and its byte content is not revealed by most decompilers. ***Of course, this "solution" does not offer any serious protection, you can still decompress the SWF and view the keys in the hex editor. You could scramble/hash them a bit to make the hacker's job harder but it's still possible to extract them.**
12:46 PM | | 2 Comments | Tags: , ,
November 14, 09

Nostalgia in Parts

The nostalgia definitely came back. With the recent re-release of the [C64 emulator for iPhone](/manomio-c64-emulator-for-iphone-ipod-touch-review/) I felt that I am somehow thrown back into C64 world again – the only difference is that I am twice as old as I used to be when being active on C64 demoscene and it feels a bit tight. Some time ago I bumped into this amazing [ICU64 project]( - realtime debugging/hacking tool by Mathfigure. Do you remember Matrix the movie? ####The first part I sooooo wanted to have all that working in AS3, that I have resurrected [FC64]( – low level C64 emulator written by Claus Wahlers (Codeazur) with [Darron Shall]( The code was moved to GitHub recently, so I just had [forked it]( and thus give it its new life. Let's roll with a small demo.
FC64 player
__Click to activate and watch this (very buggy here but interesting) part from [Parts, great demo from 1995 by Oxyron]( Red and green indicate memory write/read, grayscale map represents memory values. Click on the map and use mouse wheel or +/- keys to zoom in and out.__ (Memory debugger idea shamefully borrowed from Mathfigure.) The demo itself doesn't play nicely with FC64 and it's quiet as there's still a lot of work to do on the emulator, but just pay attention the memory snapshot – discover how data is being populated in the memory. The image of girl's face is decompressed and overwrites BASIC area. I am kind of quietly hoping to get other (ex-)demosceners involved to cooperate and improve FC64 as there's loads to do. The most important thing is to re-enable the SID (maybe using [Ralph's TinySID alchemy port]( as there are traces of early SID implementation in the FC64 source. There's another idea for a secret project involving [KickAssembler](, but shhhh for now... ####...and yet another part of the same story Yes, there is more to it. I am supposed to work on the HTML/CSS templates for the new, cool (web2.0) version of [Intros C64]( - the biggest online C64 cracking intros repository. The design (also be me) has been approved a year ago, and I am somehow in stuck in the middle - need to work out the roadmap. Anyway, I wrote a tiny a little bookmarklet to enable live preview of the intros, here are two example links: Dynamic Duo 3D stars Dynamic Duo (pictured above) And the Bookmarklet itself - just drag the link to your toolbar and use on Intros C64 site (you have to select an intro first - get the view with the comments).
06:30 PM | | 0 Comments | Tags: , , , , , , ,
June 03, 09

A TextField called Dolly

I love Flash IDE. Especially the way you can stylise the TextField – decide what glyphs to embed and what fonts to include, set line height (leading), kerning (letterSpacing), colours, etc. I really hate creating new TextFields from scratch, entirely in code. __Using Library to store a TextField__ Unfortunately, we can't store a TextField directly as a Flash IDE library symbol, so we have to wrap it up in a MovieClip and reference to it as follows: var textFieldNormal:TextField = new TextMC().textTF; where TextMC is the library MovieClip symbol containing a TextField named textTF. __How to duplicate (clone) a TextField?__ You can't do it natively in AS3. But you can do some magic instead – clone all (excluding read-only) properties of another TextField. var description:XML = describeType(referenceTextField); for each (var item:XML in description.accessor) { // clone passed textfield properties that are not read only if (item.@access != "readonly") targetTextField[item.@name] = referenceTextField[item.@name]; } targetTextField.defaultTextFormat = referenceTextField.getTextFormat(); TextFormat of the referenceTextField won't be cloned with the loop above as it's not accessible via getter/setter/public methods. You have to clone it manually and this is what the last line does. __It's very handy when you want to change the default kerning (letterSpacing) in Flash IDE and you want it to be preserved in your cloned text field.__ I wrote a FixedTextField class that does that ([plus fixes a couple of other TextField problems](/fixing-jumpy-htmltext-links/)) – download zipped demo including the class.
01:00 PM | | 0 Comments | Tags: , , , , ,
May 12, 09

Finding the missing child

How many times you've encountered that annoying error ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller message? It often happens when you're trying to remove a non-existing child which you would swear you had put there. How to find what depth is resides at, quickly? A simple "trace display list" [package-level function closure]( "package-level function closure example") traceDL(displayListElement, depth | "filter string") to the rescue! package { import flash.display.DisplayObjectContainer; import flash.display.DisplayObject; public function traceDL(container:DisplayObjectContainer, options:* = undefined, indentString:String = "", depth:int = 0, childAt:int = 0):void { if (typeof options == "undefined") options = Number.POSITIVE_INFINITY; if (depth > options) return; const INDENT:String = " "; var i:int = container.numChildren; while (i--) { var child:DisplayObject = container.getChildAt(i); var output:String = indentString + (childAt++) + ": " + + " ➔ " + child; // debug alpha/visible properties output += "\t\talpha: " + child.alpha.toFixed(2) + "/" + child.visible; // debug x and y position output += ", @: (" + child.x + ", " + child.y + ")"; // debug transform properties output += ", w: " + child.width + "px (" + child.scaleX.toFixed(2) + ")"; output += ", h: " + child.height + "px (" + child.scaleY.toFixed(2) + ")"; output += ", r: " + child.rotation.toFixed(1) + "°"; if (typeof options == "number") trace(output); else if (typeof options == "string" && output.match(new RegExp(options, "gi")).length != 0) { trace(output, "in",, "➔", container); } if (child is DisplayObjectContainer) traceDL(DisplayObjectContainer(child), options, indentString + INDENT, depth + 1); } } } __So, where is my child?__ With traceDL(someDisplayObject) you can reveal the whole display list of any DisplayObject. It will traverse its display list and show you all the instance names and types of the children (with depths they reside on), so it's easy to find out which depth your object hides. Some additional parameters like __alpha__, __visibility__, __x__ and __y__ coordinates, __width__ and __height__ (with __scaling__), and __rotation__ will be displayed as well to help debugging (if it's too much, you can comment some of them out in the class file). It's also possible to cut the traversing depth by specifying a number of levels to show: traceDL(someDisplayObject, 0) – will only show the first children, traceDL(someDisplayObject, 1) – will show you first children of someDisplayObject and also first children of its children. __Too many children shows up, it's like needle in the haystack!__ No worries, just use traceDL(someDisplayObject, "filter string") where filter string is anything you think your child may contain, either it's an object's name, class (like MovieClip) or even some parameters (x: 100). Just anything that you think will match your child characteristics (that is what's outputted when you won't pass a search string). Remember that if you hadn't explicitly set a name for a DisplayObject (either in code or Flash IDE), Flash player by default will call it instance and will assign a sequential number to it. Giving your object a name will always make it easier to identify. __I want to add a display object at a certain depth to a Library Symbol, but don't know the depth...__ Nothing more perfect! With traceDL() it's childishly easy to trace any Library Symbol structure and determine what depth to use with addChildAt to dynamically add a DisplayObject to the Symbol. __Everything has slowed down!__ The traceDL()function is recursive (unless you limit the depth it will dig till the last display node is scanned), and will use up a lot of your processor time, so take extra care and always remember to disable it in production code. __Erm, any demo/example usage?__ Sure, there. var rectangle:MovieClip = new MovieClip(); = "table"; var circle:Shape = new Shape(); circle.x = 100; circle.y = 200; circle.rotation = 45; circle.scaleY = 0.5; var square:Sprite = new Sprite(); = "square"; square.rotation = 45; square.scaleX = 0.5; square.scaleY = 2; var someSprite:Sprite = new Sprite(); addChild(rectangle); rectangle.addChild(circle); rectangle.addChild(square); addChild(someSprite); traceDL(this); //0: instance4 ➔ [object Sprite] alpha: 1.00/true, @: (0, 0), w: 0px (1.00), h: 0px (1.00), r: 0.0° //1: table ➔ [object MovieClip] alpha: 1.00/true, @: (0, 0), w: 0px (1.00), h: 0px (1.00), r: 0.0° // 0: square ➔ [object Sprite] alpha: 1.00/true, @: (0, 0), w: 0px (0.50), h: 0px (2.00), r: 45.0° // 1: instance2 ➔ [object Shape] alpha: 1.00/true, @: (100, 200), w: 0px (1.00), h: 0px (0.50), r: 45.0° traceDL(this, "square"); // 0: square ➔ [object Sprite] alpha: 1.00/true, @: (0, 0), w: 0px (0.50), h: 0px (2.00), r: 45.0° in table ➔ [object MovieClip] traceDL(this, 0); //0: instance4 ➔ [object Sprite] alpha: 1.00/true, @: (0, 0), w: 0px (1.00), h: 0px (1.00), r: 0.0° //1: table ➔ [object MovieClip] alpha: 1.00/true, @: (0, 0), w: 0px (1.00), h: 0px (1.00), r: 0.0° traceDL(rectangle, 1); //0: square ➔ [object Sprite] alpha: 1.00/true, @: (0, 0), w: 0px (0.50), h: 0px (2.00), r: 45.0° //1: instance2 ➔ [object Shape] alpha: 1.00/true, @: (100, 200), w: 0px (1.00), h: 0px (0.50), r: 45.0° traceDL(this, "clip"); //1: table ➔ [object MovieClip] alpha: 1.00/true, @: (0, 0), w: 0px (1.00), h: 0px (1.00), r: 0.0° in root1 ➔ [object MainTimeline] traceDL(this, "shape"); // 1: instance2 ➔ [object Shape] alpha: 1.00/true, @: (100, 200), w: 0px (1.00), h: 0px (0.50), r: 45.0° in table ➔ [object MovieClip] If you were comfortable with AS2 "any depth" before and now feel a bit lost in AS3 depth management, traceDL() will definitely help you to switch. __You got me, I want it now!__ Download the class
12:11 AM | | 10 Comments | Tags: , , ,
March 11, 09

Geek Tool loves Flash trace logs

![Geektool trace();](/files/images/geektool.png "Geektool trace();") Have you ever used trace(...) to debug your Flash files? Somewhat it might be very limiting (comparing to some professional debugging tools around) and you'd get condemned by many Flash devs in your town. Well, they'd be right there – there's a few cons not to use trace(...) method at all, i.e., it only allows to view logs in Flash IDE (slowing down the performance of your SWF when loads of traces are dumped out), but hey! - it may become your racing horse as well. Here's how. If you develop on Mac (and I hope you do so), there's a neat free app called [GeekTool]( "GeekTool download") – all what it does is displaying contents of a file (files) directly onto your desktop wallpaper – check out [example screenshots]( "Geektool example screenshots"). As you already might know (especially if you were using Firefox FlashTracer plugin by Sepiroth before), all trace(...) messages are added to a global log file which (on Mac) is stored in the following location: /Users//Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt Check it out, if it's not there, you might need to create a **mm.cfg** file in your home directory (/Users//mm.cfg) containing the following: TraceOutPutFileName=/Users//Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt
Geektool itself is trivial to configure, just add a group (by clicking the **New Entry button**), rename it to **Flash** (or whatever name it feels appropriate for you) and paste the Flash log path into the **Path** field. Make sure the **Enable GeekTool** option is checked and there you go, contents of your Flash log should appear directly on your desktop wallpaper. Play around with fonts and colours, be careful with shadows though – that's somehow not perfectly working (at least with GeekTool 2.1.2). You may also want your log to be displayed always on top of everything (i.e., when you're using additional monitor). In order to view your logs generated by Flash Player in a browser, you need a [debug version of Flash Player]( "Flash Player 10 Debugger"). And finally – make sure you only use trace(...) in production/development mode and disable it for release builds (by unchecking **Omit trace actions** in Flash IDE: *Publish settings...* > *Flash tab*), unless you want to [entertain other Flash developers]( "Hidden YouTube's logs"). **UPDATE:** If you are having problems with getting your logs out, Mark Walters describes ways of [outputting Flash trace logs on various operating systems]( "outputting Flash trace in the browser"). Actually, I've found a comment there by [Marc-André Lavoie]( pointing to the geek tool as well.
01:30 PM | 0 Comments | Tags: , ,