在flash (flv)客户端中添加C Sharp的密码参数
本文关键字:Sharp 密码 参数 添加 flash flv 客户端 | 更新日期: 2023-09-27 18:17:44
假设我已经知道密码。无论如何,我可以在C夏普添加一个密码参数与要求密码的actionscript客户端进行通信。我想在C Sharp编码密码,这样当我登录到客户端时,它会自动输入密码。
由于Flash的构建方式,当您使用Flash Player或Flash Lite时,这(AFAIK)是不可能的。但是,您可以使用Adobe AIR(用于桌面和移动应用程序,使用Flash平台)完成类似的任务。为了使用下面的方法,你需要发布"扩展桌面"的AIR应用程序。
为了使其工作,您的C Sharp程序需要是命令行。在输入一些命令行提示符(如"READY")后,它需要在单行上输出密码。
您需要使用NativeProcess(文档)从Adobe AIR应用程序启动您的C Sharp程序。
下面的代码是我自己的工人类的修改版本。我不能保证没有错误,因为我去掉了几个专有元素。前两个需要作为自定义类存在于同一个包中。保存它们的文件夹必须与所讨论的. fla处于同一级别,并且具有与包名称相同的名称。
自定义事件类:
package myCustomPackage
{
import flash.events.Event;
public class NativeProcessEvent extends Event
{
public static const ON_RECEIVE:String = "onReceive";
public var customMessage:String = "";
public function NativeProcessEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false):void
{
super(type, bubbles, cancelable);
}
}
}
NATIVEPROCESS CLASS(进行通信):
package myCustomPackage
{
import flash.desktop.NativeProcess;
import flash.desktop.NativeProcessStartupInfo;
import flash.events.ProgressEvent;
import flash.utils.ByteArray;
import flash.filesystem.File;
import flash.events.EventDispatcher;
import myCustomPackage.NativeProcessEvent
public class nativeProcessChannel extends EventDispatcher
{
var startup:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var file:File = new File();
var process:NativeProcess = new NativeProcess();
private var mEvt:NativeProcessEvent;
var buffer:Array = [];
//Constructor
public function nativeProcessChannel()
{
file = File.applicationDirectory.resolvePath("mypasswordprogram.exe");
if(file.exists && NativeProcess.isSupported)
{
startup.executable = file;
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, addToBuffer);
process.start(startup);
}
else if(!file.exists)
{
trace("ERROR: Cannot find program.");
}
else
{
trace("ERROR: NativeProcess not supported.");
}
}
//Sends a line of input to the command line.
public function send(msg:String):void
{
process.standardInput.writeUTFBytes(msg + "'n");
}
function addToBuffer(event:ProgressEvent):void
{
var bytes:ByteArray = new ByteArray();
process.standardOutput.readBytes(bytes, 0, process.standardOutput.bytesAvailable);
buffer.push(bytes.toString());
mEvt = new NativeProcessEvent("onReceive");
mEvt.customMessage = "NativeProcess message received.";
dispatchEvent(mEvt);
}
//Receives a line of output from the command line
public function receive():String
{
var r:String = "";
if(buffer.length > 0)
{
r = buffer[0]
buffer.splice(0,1);
}
return r;
}
//This closes the connection, freeing memory.
public function close():void
{
process.exit();
}
}
}
实现:import myCustomPackage.NativeProcessClass;
import myCustomPackage.NativeProcessEvent;
var myProcess:NativeProcessClass = new NativeProcessClass();
myProcess.addEventListener(NativeProcessEvent.ON_RECEIVE, continueGetPassword);
//This function is necessary so you can reuse the NativeProcess channel.
public function reconnect()
{
myProcess = new NativeProcessClass();
myProcess.addEventListener(NativeProcessEvent.ON_RECEIVE, continueGetPassword);
}
public function getPassword()
{
myProcess.send("READY");
}
public function continueGetPassword()
{
var password:String = myProcess.receive();
//You now have the password from your c-sharp program. Do with it what you like!
myProcess.close()
reconnect();
}
据我所知,由于其安全限制,没有其他方法可以用Flash连接到另一个程序。Adobe AIR中的扩展桌面是唯一一个不会被沙盒化的基于flash的平台。
希望这对您有所帮助(并为任何代码错误道歉)