I am currently being confused by the Vector class.
I wrote a beautiful XML to TypedClass parser. Works beautifully and without fault. UNTIL a co-worker noticed we got a Conversion Error for Vector.<Number> to Vector.<*>.
Every Vector I've ever tested all extend Vector.<*>.
Vector.<Sprite>, Vector.<String>, Vector.<Point>, Vector.<Boolean>, Vector.<TextField>, Vector.<CustomObject>, etc etc etc. ALL of them.
<type name="__AS3__.vec::Vector.<String>" base="__AS3__.vec::Vector.<*>" isDynamic="true" isFinal="false" isStatic="false">
<extendsClass type="__AS3__.vec::Vector.<*>"/>
<extendsClass type="Object"/>
<accessor name="length" access="readwrite" type="uint" declaredBy="__AS3__.vec::Vector.<*>"/>
<accessor name="fixed" access="readwrite" type="Boolean" declaredBy="__AS3__.vec::Vector.<*>"/>
</type>
But then when I use describeType on Vector.<Number>, Vector.<uint> and Vector.<int>.
<type name="__AS3__.vec::Vector.<Number>" base="Object" isDynamic="true" isFinal="true" isStatic="false">
<extendsClass type="Object"/>
<constructor>
<parameter index="1" type="uint" optional="true"/>
<parameter index="2" type="Boolean" optional="true"/>
</constructor>
<accessor name="length" access="readwrite" type="uint" declaredBy="__AS3__.vec::Vector.<Number>"/>
<accessor name="fixed" access="readwrite" type="Boolean" declaredBy="__AS3__.vec::Vector.<Number>"/>
</type>
Now I have accounted for these 3 vectors individually as even uint and int does not extend Vector.<Number> as I would have expected.
And my parsing function works for all types correctly again. But my confusion comes as to WHY this is the case, and why I couldn't find any documentation on the subject.
I asked the same question on the Kirupa forums a few months back, but I cannot for the life of me find the thread.
If I remember this correctly, the Vector.<Number>, Vector.<int>, and Vector.<uint> (but not Boolean or String, oddly enough) classes are made to be as fast as possible, so they are written and treated as separate classes by the Flash Player.
As you have noticed, all other Vector classes extend Vector.<*> and type checking is done a bit differently (which is why Vectors are faster with int, uint, and Number, but Arrays are slightly faster for all other classes)
Anyway, that was the WHY. As for how to get around this issue, I'm afraid you are going to have to pass your vector as untyped to the function you want to use it in:
public function addItem(vector:*, item:*)
{ vector.push(item); }
Related
I have made a small REST based webservice in Flask by reading http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask and now I wanted to fuzz the JSON using Peach framework. I know it's uses a pit file(XML) for fuzzing but my small brain is not able to make the pit file that can serve my purpose. I googled a lot for peach pit file but all goes in vain.
I need a pit file or anyone can tell how to create a pit file for fuzzing payload.
There is a nice tutorial about peach available there.
Several elements need to be defined:
a data model describing the format of the data you want to send.
a state model describing the behavior of the fuzzer.
an agent runnning and monitoring the applications under fuzzing.
a test bringing all definitions together.
Here is an example of a Peach Pit file from the tutorial.
<Peach xmlns="http://peachfuzzer.com/2012/Peach" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://peachfuzzer.com/2012/Peach ../peach.xsd">
<DataModel name="DataHTER">
<String value="HTER " mutable="false" token="true"/>
<String value=""/>
<String value="\r\n" mutable="false" token="true"/>
</DataModel>
<StateModel name="StateHTER" initialState="Initial">
<State name="Initial">
<Action type="input" ><DataModel ref="DataResponse"/></Action>
<Action type="output"><DataModel ref="DataHTER"/></Action>
<Action type="input" ><DataModel ref="DataResponse"/></Action>
</State>
</StateModel>
<DataModel name="DataResponse">
<String value=""/>
</DataModel>
<Agent name="RemoteAgent" location="tcp://127.0.0.1:9001">
<!-- Run and attach windbg to a vulnerable server. -->
<Monitor class="WindowsDebugger">
<Param name="CommandLine" value="C:\Documents and Settings\Administrator\Desktop\vulnserver\vulnserver.exe"/>
<Param name="WinDbgPath" value="C:\Program Files\Debugging Tools for Windows (x86)" />
</Monitor>
</Agent>
<Test name="TestHTER">
<Agent ref="RemoteAgent"/>
<StateModel ref="StateHTER"/>
<Publisher class="TcpClient">
<Param name="Host" value="127.0.0.1"/>
<Param name="Port" value="9999"/>
</Publisher>
<Logger class="File">
<Param name="Path" value="Logs"/>
</Logger>
</Test>
If you want to use a JSON data model, you can follow the recommendation of one of the peach architect.
1)Define a data model corresponding to the JSON.
JSON Object
{
"name":"John Smith",
"address":{
"address1":"555 Main St.",
"city":"Seattle"
}
}
Data model
<DataModel>
<String name="name" value="John Smith" />
<Block name="address">
<String name="address1" value="555 Main St." />
<String name="city" value="Seattle" />
</Block>
</DataModel>
You then have to write your own custom publisher in C#. Here is a tutorial for this.
In another class elsewhere in the code, I want to access the parameters (and their types) of Foo.bar.
The result would contain [ "a", Number ] and [ "b", String ] in one form or another.
public class Foo
{
...
public function bar(a:Number, b:String):void
{
...
}
}
AS3 has a method called describeType
If you call describeType(Foo) on the above example, you'll get:
<type name="Foo" base="Class" isDynamic="true" isFinal="true" isStatic="true">
<extendsClass type="Class"/>
<extendsClass type="Object"/>
<accessor name="prototype" access="readonly" type="*" declaredBy="Class"/>
<factory type="Foo">
<extendsClass type="Object"/>
<method name="bar" declaredBy="Foo" returnType="void">
<parameter index="1" type="Number" optional="false"/>
<parameter index="2" type="String" optional="false"/>
<metadata name="__go_to_definition_help">
<arg key="pos" value="51"/>
</metadata>
</method>
<metadata name="__go_to_definition_help">
<arg key="pos" value="23"/>
</metadata>
</factory>
</type>
Now, you can use AS3's XML class and e4x to find the definition of the method with the name bar and grab the parameter elements.
I want to use the following load() method that accepts five parameters so that I can load a small "excerpt" from a larger video:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/video/VideoPlayer.html#load()
In particular, the startTime and duration parameters seem to be what I need, but I am getting errors that seem to indicate that I don't have the right object/version of something, even though the Adobe docs say that it should work. Here are my steps:
Start a new, blank FLA document (AS3).
Drag an FLVPlayback component to the stage and name it vPlayer.
Create a new layer and add Actionscript in frame 1:
import fl.video.*;
var innerPlayer = vPlayer.getVideoPlayer(vPlayer.activeVideoPlayerIndex);
trace(innerPlayer); // "[object VideoPlayer]" appears in Output window
innerPlayer.load(
"RTMP://..."
, 0 // totalTime
, false // isLive
, 60 // startTime
, 10 // duration
);
This should give me a ten-second clip starting from the one-minute mark, but I keep getting errors like ArgumentError: Error #1063: Argument count mismatch on fl.video::VideoPlayer/load(). Expected 1, got 5.
I've also tried casting innerPlayer to fl.video.VideoPlayer, but that doesn't work.
What am I doing wrong?
EDITS: Even though I'm on CS4/AS3 and the documentation claims to apply to CS4/AS3, the class files in my "Component Source" folder don't seem to match the documentation. I also tried this in CS6, and I got "1137: Incorrect number of arguments. Expected no more than 3."
#SunilD. - For CS4: FLVPlayback.VERSION=2.1.0.19, and I am targeting Flash Player 10 (the most recent available)+AS3. For CS6, FLVPlayback.VERSION=2.5.0.26, and I am targeting Flash Player 11.4.
In CS4 and CS6, the errors say that VideoPlayer load() only requires one argument (with two optional), and play() has three optional arguments. The output of describeType(innerPlayer) confirms:
<type name="fl.video::VideoPlayer" base="flash.media::Video" isDynamic="false" isFinal="false" isStatic="false">
...
<method name="play" declaredBy="fl.video::VideoPlayer" returnType="void">
<parameter index="1" type="String" optional="true"/>
<parameter index="2" type="Number" optional="true"/>
<parameter index="3" type="Boolean" optional="true"/>
</method>
...
<method name="load" declaredBy="fl.video::VideoPlayer" returnType="void">
<parameter index="1" type="String" optional="false"/>
<parameter index="2" type="Number" optional="true"/>
<parameter index="3" type="Boolean" optional="true"/>
</method>
...
</type>
Other notes: Flash CS6 is up to date. Manually installing the FLVPlayback 2.5 component didn't work.
Anon, I think this is an issue of poor documentation / too many different products (Flash, Flex, player, flvplayback component) with different versions.
I was able to get the .load() call to work with all 5 arguments (and verified that it did start playing at the specified start time), but only by compiling a new FLVPlayback_116.swc from the latest Flex SDK source code (Flex 4.6 with playerglobal.swc version 11.6).
See my screenshot.
Might as well see if it works for you. Here's what you'll need to do:
Remove the FLVPlayback component from your library - this defines conflicting classes with the updated version.
Download my FLVPlayback_116.swc library
Or FLVPlayback_116_air.swc if you're targeting Adobe AIR, not Flash Player / web
In Flash, open the File -> ActionScript Settings dialog, under the library path tab, click 'Browse to SWC file' and locate the FLVPlayback_116.swc file you just downloaded. My screenshot above shows this dialog and how the FLVPlayback_116.swc file is listed after being added.
In the code (see below):
You need to set: fl.video.VideoPlayer.iNCManagerClass = fl.video.NCManager;
Rather than using innerPlayer = vPlayer.getVideoPlayer you'll need to use innerPlayer = new VideoPlayer(width,height) and then addChild(innerPlayer) and innerPlayer.play()
I had to add the innerVideo.play() call to start the video playing (which I assume the GUI would handle)
Here's my code (also visible in the screenshot):
import fl.video.*;
fl.video.VideoPlayer.iNCManagerClass = fl.video.NCManager;
var innerPlayer = new VideoPlayer(640,480);
addChild(innerPlayer);
innerPlayer.load(
"http://10.0.1.3/test.flv"
, 0 // totalTime
, false // isLive
, 5 // startTime
, 5 // duration
);
innerPlayer.play();
Also, you can see that my describeType of VideoPlayer shows the proper number of arguments:
<method name="load" declaredBy="fl.video::VideoPlayer" returnType="void">
<parameter index="1" type="String" optional="false"/>
<parameter index="2" type="Number" optional="true"/>
<parameter index="3" type="Boolean" optional="true"/>
<parameter index="4" type="Number" optional="true"/>
<parameter index="5" type="Number" optional="true"/>
<metadata name="__go_to_definition_help">
<arg key="pos" value="41308"/>
</metadata>
</method>
<method name="play" declaredBy="fl.video::VideoPlayer" returnType="void">
<parameter index="1" type="String" optional="true"/>
<parameter index="2" type="Number" optional="true"/>
<parameter index="3" type="Boolean" optional="true"/>
<parameter index="4" type="Number" optional="true"/>
<parameter index="5" type="Number" optional="true"/>
<metadata name="__go_to_definition_help">
<arg key="pos" value="34410"/>
</metadata>
</method>
UPDATE: I've updated the library so that you can instantiate an FLVPlayback(w,h) and hence apply skins or whatnot -- treat it just like you would the vPlayer in your code above (except I added the width/height constructor args, since the size used to come from the component on-stage). Instantiate it like so:
var vPlayer:FLVPlayback = new FLVPlayback(640,480);
vPlayer.skin = "http://10.0.1.3/skin.swf"; // optional skin
addChild(vPlayer);
var innerPlayer = vPlayer.getVideoPlayer(vPlayer.activeVideoPlayerIndex);
innerPlayer.load(
"http://10.0.1.3/test.flv"
, 0 // totalTime
, false // isLive
, 5 // startTime
, 5 // duration
);
Note - to use a skin, I compiled one of the FLA examples from Flash CS6... I tried using a skin I found on the Internet and it didn't work - it was likely compiled for an older version. See this skinned screenshot and download my skin.swf.
Good luck, and let me know if you need further info!
i often get argument mismatch error ,that usually take me a lot of time to debug program.damn, i really hope i know the function's entrance requirement and where they are come from.
since i only know a function variable is a function,no any other information.
i wrote massive codes like this
public static function call(func:Function,params:Array = null,addToTailIfNotNull:*=null):void{
if (func!=null){
var args:Array =[];
if(params!=null){
args = ArrayTools.clone(params);
}
if (addToTailIfNotNull!=null){
args.push(addToTailIfNotNull);
}
func.apply(null,args);
}
}
i should do things more smartly .
I can suggest you using flash.utils.describeType() method. It returns an XML with a description of an object you passed as a parameter.
Lets say you have a Class:
public class Example {
public function someMethod(number:Number, string:String):void {
}
}
And you call somewhere:
flash.utils.describeType(Example);
You should get an XML with something like this in there:
<method name="someMethod" declaredBy="com.example::Example" returnType="void">
<parameter index="1" type="Number" optional="false"/>
<parameter index="2" type="String" optional="false"/>
<metadata name="__go_to_definition_help">
<arg key="pos" value="501"/>
</metadata>
</method>
I am not sure that this is what you looking for, as in your example if you pass you Function argument there you will get a description of Function class:
<type name="builtin.as$0::MethodClosure" base="Function" isDynamic="false" isFinal="true" isStatic="false">
<extendsClass type="Function"/>
<extendsClass type="Object"/>
<accessor name="length" access="readonly" type="int" declaredBy="Function"/>
<accessor name="prototype" access="readwrite" type="*" declaredBy="builtin.as$0::MethodClosure"/>
</type>
But maybe you can refactor you "call" method so it could get the right description (for example pass additional info into it - like an object class and a method name - so you could analyse the method signature in it. Not the most beautiful solution, but still...)
In ColdFusion, is there any way to pass in a struct of parameters to a function with multiple optional parameters?
For example, I want to do something like this:
<cfset myResults = myFunction(myStruct) />
<cffunction name="myFunction" ... >
<cfargument name="myArg1" type="numeric" required="no" default="" />
<cfargument name="myArg2" type="string" required="no" default="" />
<cfargument name="myArg3" type="numeric" required="no" default="" />
.....
</cffunction>
Where "myStruct" has a random combination of key-value pairs - for example, "myArg3":222 and "myArg2":"hello".
Is this possible, or do I have to specifically list each argument (with a check of "isDefined" for each one)?
Ok, I haven't tested this yet, but I just realized I might be able to do this using a <cfinvoke argumentCollection="#myStruct#">. Will try that now...
Edit:
This did work! And Sergii's suggestion for my original syntax without a cfinvoke works as well.