承载Flash将不会加载SWF ressources(XML,图像等) [英] Hosting Flash won't load swf ressources (xml, image, etc.)

查看:445
本文介绍了承载Flash将不会加载SWF ressources(XML,图像等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现最初的SWF读者GTK2在我的UNIX机器。的工作,我可以使简单的SWF文件。现在,我想要一个配置添加到我的使用XML配置闪存文件,添加图像等不合格,将不会获得通过geturlnotify()。 这是我的code:

 的#include< stdio.h中>
#包括< stdlib.h中>
#包括< dlfcn.h中>
#包括< string.h中>
#包括< unistd.h中>
#包括<文件ctype.h>

#包括< GTK / gtk.h>
#包括< GDK / gdkx.h>
#包括npupp.h

#定义FLASH_PLUGIN_SO./libflashplayer.so

无效* flash_plugin_handle;

NPNetscapeFuncs browserFuncs;
NPPluginFuncs pluginFuncs;

的GtkWidget * main_window;

字符*文件名= NULL;
NPStream *流;
为const char * uagent =AXT / 1.0;

//默认窗口大小
INT WINDOW_XSIZE = 800;
INT WINDOW_YSIZE = 600;

//默认的子窗口的位置(Flash播放器)
INT xPosition位置= 0;
INT yPosition = 0;

NPError(* iNP_Initialize)(NPNetscapeFuncs * bFuncs,NPPluginFuncs * pFuncs);
NPError(* iNP_Shutdown)();
字符*(* iNP_GetMIMEDescription)();

无效* loadFlashPluginSo(){
  void *的处理;

  处理=的dlopen(FLASH_PLUGIN_SO,RTLD_LAZY | RTLD_LOCAL);
  如果(!手柄){
    fprintf中(错误,[ - ]错误li​​bflashplayer.so装载:%S \ N,dlerror获得());
    出口(1);
  }
  fprintf中(错误,[+]加载libflashplayer.so \ N);
  返回的句柄;
}

void *的loadSymbol(void *的手柄,为const char *名称){
  字符*错误;
  无效* RET;

  RET =的dlsym(手柄,姓名);

  如果((误差= dlerror获得())!= NULL){
    fprintf中(错误,[ - ]错误加载符号%s:%s的\ N的名字,错误);
    出口(1);
  } 其他 {
    fprintf中(错误,[+]加载符号%s,地址:%P \ N的名字,RET);
  }
  返回RET;
}

无效loadNPEntryPoints(void *的句柄){
  iNP_Initialize = loadSymbol(手柄,NP_Initialize);
  iNP_Shutdown = loadSymbol(手柄,NP_Shutdown);
  iNP_GetMIMEDescription = loadSymbol(手柄,NP_GetMIMEDescription);
}

无效printPluginEntrypoints(NPPl​​uginFuncs * pFuncs){
  fprintf中(错误,[*] NPP结构:\ N);
  fprintf中(错误,\ T-NPP_size:%8D \ N,pFuncs->大小);
  fprintf中(错误,\ T-NPP_version:%8D \ N,pFuncs->版);
  fprintf中(错误,\ T-NPP_NewProcPtr:%P \ N,pFuncs-> NEWP);
  fprintf中(错误,\ T-NPP_DestroyProcPtr:%P \ N,pFuncs->摧毁);
  fprintf中(错误,\ T-NPP_SetWindowProcPtr:%P \ N,pFuncs-> setwindow);
  fprintf中(错误,\ T-NPP_NewStreamProcPtr:%P \ N,pFuncs->方通);
  fprintf中(错误,\ T-NPP_DestroyStreamProcPtr:%P \ N,pFuncs-> destroystream);
  fprintf中(错误,\ T-NPP_StreamAsFileProcPtr:%P \ N,pFuncs-> asfile);
  fprintf中(错误,\ T-NPP_WriteReadyProcPtr:%P \ N,pFuncs-> writeready);
  fprintf中(错误,\ T-NPP_WriteProcPtr:%P \ N,pFuncs-→写);
  fprintf中(错误,\ T-NPP_PrintProcPtr:%P \ N,pFuncs->打印);
  fprintf中(错误,\ T-NPP_HandleEventProcPtr:%P \ N,pFuncs->事件);
  fprintf中(错误,\ T-NPP_URLNotifyProcPtr:%P \ N,pFuncs-> urlnotify);
  fprintf中(错误,\ T-JavaClass中:%P \ N,pFuncs->一个JavaClass);
  fprintf中(错误,\ T-NPP_GetValueProcPtr:%P \ N,pFuncs->的GetValue);
  fprintf中(错误,\ T-NPP_SetValueProcPtr:%P \ N,pFuncs->的setValue);
}

NPError NPN_GetValueProc(NPP例如,NPNVariable变量,无效* ret_value){
    fprintf中(错误,研究[D] NPN_GetValueProc例如:%P,变量:%D,abi_mask数:%d \ N,例如,变量,0);

    开关(可变){
    案例NPNVSupportsXEmbedBool:
      *((INT *)ret_value)= PR_TRUE;
      打破;
    //的Unix和Solaris修复
    案例NPNVToolkit:
      *((INT *)ret_value)= NPNVGtk2;
      打破;
    案例NPNVnetscapeWindow:
      *((INT *)ret_value)= PR_TRUE;
      打破;
    默认:
      *((INT *)ret_value)= PR_FALSE;
      打破;
    }
    返回NPERR_NO_ERROR;
}

为const char * NPN_UserAgentProc(NPP实例){
    fprintf中(错误,研究[D] NPN_UserAgentProc例如:%P \ N,实例);
    返回uagent;
}

NPError NPN_GetURLProc(NPP例如,为const char *的URL,为const char *窗口){
    fprintf中(错误,研究[D] NPN_GetURLProcPtr:%P,网址:%S,窗口:%S \ N,例如,URL,窗口);
    返回NPERR_NO_ERROR;
}

NPIdentifier NPN_GetStringIdentifierProc(常量NPUTF8 *名称){
    返回(NPIdentifier)0x41424344; //独特
}

静止
gboolean plug_removed_cb(的GtkWidget *窗口小部件,gpointer数据){
    fprintf中(错误,plug_removed_cb \ N [!]);
    返回TRUE;
}

静态无效
socket_unrealize_cb(的GtkWidget *窗口小部件,gpointer数据){
    fprintf中(错误,socket_unrealize_cb \ N [!]);
}


静态NPWindow *
npwindow_construct(的GtkWidget *部件){
  NPWindow * npwindow;
  NPSetWindowCallbackStruct * ws_info = NULL;

  GdkWindow * parent_win =小窗口>窗口;

  的GtkWidget * socketWidget = gtk_socket_new();

  gtk_widget_set_parent_window(socketWidget,parent_win);
  gtk_widget_set_uposition(socketWidget xPosition位置,yPosition);

  g_signal_connect(socketWidgetplug_removed,G_CALLBACK(plug_removed_cb),NULL);
  g_signal_connect(socketWidgetunrealize,G_CALLBACK(socket_unrealize_cb),NULL);
  g_signal_connect(socketWidget,消灭,G_CALLBACK(gtk_widget_destroyed),放大器; socketWidget);


  gpointer的user_data = NULL;
  gdk_window_get_user_data(parent_win,和放大器; USER_DATA);

  GtkContainer *容器= GTK_CONTAINER(USER_DATA);
  gtk_container_add(集装箱,socketWidget);
  gtk_widget_realize(socketWidget);

  GtkAllocation new_allocation;
  new_allocation.x = 0;
  new_allocation.y = 0;
  new_allocation.width = WINDOW_XSIZE;
  new_allocation.height = WINDOW_YSIZE;
  gtk_widget_size_allocate(socketWidget,和放大器; new_allocation);

  gtk_widget_show(socketWidget);
  gdk_flush();

  GdkNativeWindow WW = gtk_socket_get_id(GTK_SOCKET(socketWidget));
  GdkWindow * W = gdk_window_lookup(湿重);

  npwindow =的malloc(的sizeof(NPWindow));
  npwindow->窗口=(无效*)(无符号长)WW;
  npwindow-&X的催化剂= 0;
  npwindow-> Y = 0;
  npwindow-> WIDTH = WINDOW_XSIZE;
  npwindow->高度= WINDOW_YSIZE;

  ws_info =的malloc(的sizeof(NPSetWindowCallbackStruct));
  ws_info->类型= NP_SETWINDOW;
  ws_info->显示器= GDK_WINDOW_XDISPLAY(W);
  ws_info->颜色表= GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(W));
  GdkVisual * gdkVisual = gdk_drawable_get_visual(瓦特);
  ws_info->视觉= GDK_VISUAL_XVISUAL(gdkVisual);
  ws_info->深度= gdkVisual->深度;

  npwindow-> ws_info = ws_info;
  npwindow->类型= NPWindowTypeWindow;

  返回npwindow;
}

静态NPStream *
npstream_construct(){
    NPStream *流=的malloc(的sizeof(NPStream));
     - 于流GT; URL =文件名;
     - 于流GT; notifyData = 00000000;

    fprintf中(错误,研究[D] NPN_StreamConstructed:%P \ N,流);

    返回流;
}

布尔NPN_GetPropertyProc(NPP NPP,NPObject * OBJ,NPIdentifier propertyName的,NPVariant *结果){
    fprintf中(错误,研究[D] NPN_GetPropertyProc:%P \ N,结果);
    result->类型= NPVariantType_Object;
    result-> value.objectValue =(NPObject *)1;
    返回TRUE;
}


布尔NPN_InvokeProc(NPP NPP,NPObject * OBJ,NPIdentifier方法名,常量NPVariant *的args,uint32_t的argCount,NPVariant *结果){
    fprintf中(错误,研究[D] NPN_InvokeProc:%P \ N,结果);
    result-> TYPE = NPVariantType_String;
    result-> value.stringValue.utf8characters =文件名;
    result-> value.stringValue.utf8length = strlen的(文件名);
    返回TRUE;
}

无效NPN_ReleaseVariantValueProc(NPVariant *变量){
}

无效NPN_ReleaseObjectProc(NPObject * OBJ){
}

NPObject * NPN_CreateObjectProc(NPP NPP,NPClass * ACLASS){
    返回(NPObject *)1;
}

NPObject * NPN_RetainObjectProc(NPObject * OBJ){
    返回(NPObject *)1;
}

NPError NPN_GetURLNotifyProc(NPP例如,为const char *的URL,为const char *窗口,无效* notifyData){
    fprintf中(错误,研究[D] NPN_GetURLNotifyProc:%P,网址:%S,窗口:%S \ N,例如,URL,窗口);
    返回0;
}

NPN_GetURL,NPN_GetURLNotify和NPP_URLNotify

无效initNPNetscapeFuncs(NPNetscapeFuncs * bFuncs){
  INT I = 0;

  对于(i = 1; I<的sizeof(* bFuncs)/的sizeof(ssize_t供);我++)
    *(((ssize_t供*)bFuncs)+ I)= I + 1000;

  bFuncs->的getURL = NPN_GetURLProc;
  bFuncs->的GetValue = NPN_GetValueProc;
  bFuncs-> uagent = NPN_UserAgentProc;
  bFuncs->的getProperty = NPN_GetPropertyProc;
  bFuncs-> getstringidentifier = NPN_GetStringIdentifierProc;
  bFuncs->调用= NPN_InvokeProc;
  bFuncs-> releasevariantvalue = NPN_ReleaseVariantValueProc;
  bFuncs-> releaseobject = NPN_ReleaseObjectProc;
  bFuncs-> CREATEOBJECT = NPN_CreateObjectProc;
  bFuncs-> retainobject = NPN_RetainObjectProc;
  bFuncs-> geturlnotify = NPN_GetURLNotifyProc;
  bFuncs->大小= sizeof的(bFuncs);
  bFuncs->版本=(NP_VERSION_MAJOR&其中;&所述; 8)| NP_VERSION_MINOR ;;
}

静态无效的破坏(的GtkWidget *窗口小部件,gpointer数据){
    gtk_main_quit();
}

静态无效checkError(为const char *海峡,NPError ERR){
  如果(ERR == NPERR_NO_ERROR)
    fprintf中(错误,[+]%S:成功\ N,STR);
  其他
    fprintf中(错误,[ - ]%S:失败(%D)\ N,STR,ERR);
    fflush(NULL);
}

INT主(INT ARGC,字符** argv的)
{
  INT℃;
  为extern字符* OPTARG;

  而((C = getopt的(ARGC,ARGV,F:W:H:X:Y:!))= EOF){
    开关(三){
      案例'F':
        文件名= OPTARG;
        fprintf中(错误,[+]文件名:%S \ N,OPTARG);
        打破;
      案W:
        WINDOW_XSIZE =的atoi(OPTARG);
        fprintf中(错误,[+] WINDOW_XSIZE:%S \ N,OPTARG);
        打破;
      案H:
        WINDOW_YSIZE =的atoi(OPTARG);
        fprintf中(错误,[+] WINDOW_YSIZE:%S \ N,OPTARG);
        打破;
      情况下'X':
        xPosition位置=的atoi(OPTARG);
        fprintf中(错误,[+]您的位置在X:%S \ N,OPTARG);
        打破;
      案例'Y':
        yPosition =的atoi(OPTARG);
        fprintf中(错误,[+]您的位置在Y:%S \ N,OPTARG);
        打破;
      外壳 '?':
        如果(optopt =='F'| optopt =='W'| optopt =='H')
          fprintf中(错误,[ - ]选项 - %C需要一个参数\ n,optopt);
        否则,如果(isprint判断(optopt))
          fprintf中(错误,[ - ]未知的选项' - %C'\ñ,optopt);
        其他
          fprintf中(错误,[ - ]未知的选项字符'\\ X%X'\ñ,optopt);
          出口(-1);
      默认:
        fprintf中(错误,[ - ]用法:%s的-f< swffile> -x< xsize> -Y< ysize> \ N的argv [0]);
        出口(-1);
    }
  }

  gtk_init(安培; ARGC,和放大器; argv的);
  main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_usize(main_window,WINDOW_XSIZE,WINDOW_YSIZE);
  gtk_widget_set_uposition(main_window xPosition位置,yPosition);
  g_signal_connect(G_OBJECT(main_window),消灭,G_CALLBACK(破坏),NULL);
  gtk_widget_realize(main_window);
  gtk_widget_show_all(main_window);
  fprintf中(错误,[+]在GTK控件的\ n);

  flash_plugin_handle = loadFlashPluginSo();

  loadNPEntryPoints(flash_plugin_handle);
  fprintf中(错误,[+]初始化flash插件入口点的\ n);

  initNPNetscapeFuncs(安培; browserFuncs);
  fprintf中(错误,[+]初始化浏览器功能的\ n);

  checkError(NP_Initialize,iNP_Initialize(安培; browserFuncs,&安培; pluginFuncs));

  printPluginEntrypoints(安培; pluginFuncs);

  NPWindow * npwin = npwindow_construct(main_window);
  fprintf中(错误,[+]创建NPWindow部件的\ n);

  NPP_t * instancep =的malloc(的sizeof(NPP_t));
  memset的(instancep,0,sizeof的(的sizeof(NPP_t)));
  NPP例如= instancep;

  NPSavedData *保存=的malloc(的sizeof(NPSavedData));
  memset的(保存,0,sizeof的(的sizeof(NPSavedData)));

  流= npstream_construct();
  uint16_t STYPE;

  字符* xargv [] = {质量,BGCOLOR,宽度,高度,allowScriptAccess的,循环};
  字符* xargm [] = {高,#000000,1360,768,永远,假};


  checkError(NPN_New,pluginFuncs.newp(应用程序/ x-冲击波闪光,例如,NP_EMBED,0,xargv,xargm,保存));
  checkError(NPN_SetWindow,pluginFuncs.setwindow(例如,npwin));
  checkError(NPN_NewStream,pluginFuncs.newstream(例如,应用程序/ x-冲击波闪光,流,0,&安培; STYPE));


  FILE *页;

  字符缓冲区[8192];
  PP = FOPEN(文件名,RB);

  INT LEN;

  而((LEN =的fread(缓冲液,1,sizeof的(缓冲器),第))!= 0){
    pluginFuncs.writeready(例如,流);
    pluginFuncs.write(例如,流,0,len个,缓冲区);
  }

  fclose函数(PP);

  checkError(NPN_DestroyStream,pluginFuncs.destroystream(例如,流,N preS_DONE));

  免费(流);

  进入主循环();

  checkError(NPN_Destroy,pluginFuncs.destroy(例如,和放大器;保存));


  checkError(NP_Shutdown,iNP_Shutdown());

  dlclose(flash_plugin_handle);
  返回0;
}
 

如果我加载没有XML的SWF。有用。 当我有一个配置到我的XML。它会停止。

下面是我得到的输出中:

 〜/测试闪光$ ./test-flash -f xml_sample.swf -w 400 -h 600 -x 15 -y 15
[+]文件名:xml_sample.swf
[+] WINDOW_XSIZE:400
[+] WINDOW_YSIZE:600
[+]您的位置在X:15
[+]您的位置在Y:15
[+]在GTK控件
[+]加载libflashplayer.so
[+]加载符号NP_Initialize,地址:0x7ff03fb634d0
[+]加载符号NP_Shutdown,地址:0x7ff03fb634c0
[+]加载符号NP_GetMIMEDescription,地址:0x7ff03fb63870
[+]初始化flash插件入口点
[+]初始化浏览器的功能
[+] NP_Initialize:成功
[*] NPP结构:
         -  NPP_size:0
         -  NPP_version:0
         -  NPP_NewProcPtr:0x7ff03fb63990
         -  NPP_DestroyProcPtr:0x7ff03fb63980
         -  NPP_SetWindowProcPtr:0x7ff03fb63970
         -  NPP_NewStreamProcPtr:0x7ff03fb63960
         -  NPP_DestroyStreamProcPtr:0x7ff03fb63910
         -  NPP_StreamAsFileProcPtr:0x7ff03fb63920
         -  NPP_WriteReadyProcPtr:0x7ff03fb63950
         -  NPP_WriteProcPtr:0x7ff03fb63940
         -  NPP_PrintProcPtr:0x7ff03fb63900
         -  NPP_HandleEventProcPtr:0x7ff03fb638f0
         -  NPP_URLNotifyProcPtr:0x7ff03fb63930
         - 一个JavaClass:(无)
         -  NPP_GetValueProcPtr:0x7ff03fb63860
         -  NPP_SetValueProcPtr:(无)
[+]创建NPWindow部件
[D]。NPN_StreamConstructed:0x25ce5e0
[D]。NPN_GetValueProc例如:0x25cc720,变量:14,abi_mask:0
[D]。NPN_GetValueProc例如:0x25cc720,变量:268435469,abi_mask:0
[D]。NPN_UserAgentProc例如:(无)
[D]。NPN_GetValueProc例如:0x25cc720,变量:15,abi_mask:0
[D]。NPN_GetValueProc例如:0x25cc720,变量:15,abi_mask:0
[D]。NPN_GetValueProc例如:0x25cc720,变量:18,abi_mask:0
[+] NPN_New:成功
[D]。NPN_GetValueProc例如:0x25cc720,变量:14,abi_mask:0
[+] NPN_SetWindow:成功
[D]。NPN_GetURLNotifyProc:0x25cc720,网址:JavaScript的:top.location +__ flashplugin_unique__窗口:(空)
[D]。NPN_GetValueProc例如:0x25cc720,变量:15,abi_mask:0
[+] NPN_NewStream:成功
长度:455
[D]。NPN_UserAgentProc实例:0x25cc720
[+] NPN_DestroyStream:成功
[D]。NPN_GetURLNotifyProc:0x25cc720,网址:sample.xml中,窗口:(空)
 

感谢您!

编辑:

我想是这样的(code在NPN_GetURLNotifyProc功能)。但后来,我的应用程序冻结我geturlnotifyproc内...

  NPStream秒;
UINT16 STYPE;
memset的(安培; S,0,sizeof的(NPStream));
s.url =的strdup(URL);
fprintf中(错误,URL:%S \ N,s.url);
checkError(NPN_NewStream,pluginFuncs.newstream(例如,text / html的,和放大器; S,0,&安培; STYPE));
    writeStream(例如,和放大器; pluginFuncs,和放大器; S);
pluginFuncs.urlnotify(例如,URL,N preS_DONE,notifyData);
checkError(NPN_DestroyStream,pluginFuncs.destroystream(例如,与放,S,N preS_DONE));
            免费((无效*)s.url);
 

解决方案

我忘了补充的通知到我流...

  NPError NPN_GetURLNotifyProc(NPP例如,为const char *的URL,为const char *的目标,无效* notifyData){
    fprintf中(错误,研究[D] NPN_GetURLNotifyProc:%P,网址:%S,窗口:%s的数据:%P \ N,例如,URL,目标,notifyData);
    NPStream S;
    UINT16 STYPE;

    memset的(安培; S,0,sizeof的(NPStream));
    s.url =的strdup(URL);
    s.notifyData = notifyData;

    fprintf中(错误,NPP:%P网址:%S \ N,例如,URL);

    checkError(NPN_NewStream,pluginFuncs.newstream(例如,text / html的,和放大器; S,0,&安培; STYPE));
    writeStream(例如,和放大器; pluginFuncs,和放大器; S);

    checkError(NPN_DestroyStream,pluginFuncs.destroystream(例如,与放,S,N preS_DONE));
    免费((无效*)s.url);
    pluginFuncs.urlnotify(例如,URL,N preS_DONE,notifyData);
    返回0;
}
 

我现在谁可以编译运行闪存(SWF)独立的GTK应用程序。 希望它可以帮助别人的未来。我建议做一个插件来读取另一个插件(也称为嗅探器),以实际知道哪个函数被调用(和事情如何工作),以有工作体面的日志文件。

I tried to achieve at first a swf reader with gtk2 on my unix machine. Worked, I could render simple swf files. Now, I'm trying to add a configuration to my flash file with xml configuration, add image, etc. Failed, won't get pass geturlnotify(). Here's my code:

#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h>

#include <gtk/gtk.h> 
#include <gdk/gdkx.h>
#include "npupp.h"

#define FLASH_PLUGIN_SO "./libflashplayer.so"

void *flash_plugin_handle;

NPNetscapeFuncs browserFuncs;
NPPluginFuncs   pluginFuncs;

GtkWidget *main_window;

char* fileName = NULL;
NPStream *       stream;
const char * uagent = "Axt/1.0";

//Default window size
int WINDOW_XSIZE = 800;
int WINDOW_YSIZE = 600;

//Default child window position (flash player)
int xPosition = 0;
int yPosition = 0;

NPError (*iNP_Initialize)(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs);
NPError (*iNP_Shutdown)();
char*   (*iNP_GetMIMEDescription)();

void* loadFlashPluginSo() {
  void *handle;

  handle = dlopen(FLASH_PLUGIN_SO, RTLD_LAZY | RTLD_LOCAL);
  if(!handle) {
    fprintf(stderr, "[-] error loading libflashplayer.so: %s\n", dlerror());
    exit(1);
  } 
  fprintf(stderr,"[+] loaded libflashplayer.so\n");
  return handle;
}

void* loadSymbol(void *handle, const char *name) {
  char *error;
  void *ret;

  ret = dlsym(handle, name);

  if((error = dlerror()) != NULL) {
    fprintf(stderr, "[-] error loading symbol %s: %s\n", name, error);
    exit(1);
  } else {
    fprintf(stderr,"[+] loaded symbol %s, address: %p\n", name, ret);
  }
  return ret;
}

void loadNPEntryPoints(void *handle) {
  iNP_Initialize=loadSymbol(handle, "NP_Initialize");
  iNP_Shutdown=loadSymbol(handle, "NP_Shutdown");
  iNP_GetMIMEDescription = loadSymbol(handle,"NP_GetMIMEDescription");
}

void printPluginEntrypoints(NPPluginFuncs* pFuncs) {
  fprintf(stderr,"[*] NPP struct:\n");
  fprintf(stderr,"\t- NPP_size:                 %8d\n",pFuncs->size);
  fprintf(stderr,"\t- NPP_version:              %8d\n",pFuncs->version);
  fprintf(stderr,"\t- NPP_NewProcPtr:           %p\n", pFuncs->newp);
  fprintf(stderr,"\t- NPP_DestroyProcPtr:       %p\n", pFuncs->destroy);
  fprintf(stderr,"\t- NPP_SetWindowProcPtr:     %p\n", pFuncs->setwindow);
  fprintf(stderr,"\t- NPP_NewStreamProcPtr:     %p\n", pFuncs->newstream);
  fprintf(stderr,"\t- NPP_DestroyStreamProcPtr: %p\n", pFuncs->destroystream);
  fprintf(stderr,"\t- NPP_StreamAsFileProcPtr:  %p\n", pFuncs->asfile);
  fprintf(stderr,"\t- NPP_WriteReadyProcPtr:    %p\n", pFuncs->writeready);
  fprintf(stderr,"\t- NPP_WriteProcPtr:         %p\n", pFuncs->write);
  fprintf(stderr,"\t- NPP_PrintProcPtr:         %p\n", pFuncs->print);
  fprintf(stderr,"\t- NPP_HandleEventProcPtr:   %p\n", pFuncs->event);
  fprintf(stderr,"\t- NPP_URLNotifyProcPtr:     %p\n", pFuncs->urlnotify);
  fprintf(stderr,"\t- javaClass:                %p\n", pFuncs->javaClass);
  fprintf(stderr,"\t- NPP_GetValueProcPtr:      %p\n", pFuncs->getvalue);
  fprintf(stderr,"\t- NPP_SetValueProcPtr:      %p\n", pFuncs->setvalue);
}

NPError NPN_GetValueProc(NPP instance, NPNVariable variable, void *ret_value) {
    fprintf(stderr,"[D] NPN_GetValueProc instance:%p, variable:%d, abi_mask:%d\n", instance, variable, 0);

    switch (variable) {
    case NPNVSupportsXEmbedBool:
      *((int*)ret_value)= PR_TRUE;
      break;
    //Unix and solaris fix
    case NPNVToolkit:
      *((int*)ret_value)= NPNVGtk2;
      break;
    case NPNVnetscapeWindow:
      *((int*)ret_value)= PR_TRUE;
      break;
    default:
      *((int*)ret_value)=PR_FALSE;
      break;
    }
    return NPERR_NO_ERROR;
}

const char* NPN_UserAgentProc(NPP instance) {
    fprintf(stderr,"[D] NPN_UserAgentProc instance:%p\n", instance);
    return uagent;
}

NPError NPN_GetURLProc(NPP instance, const char* url, const char* window) {
    fprintf(stderr,"[D] NPN_GetURLProcPtr:%p, url: %s, window: %s\n", instance, url, window);
    return NPERR_NO_ERROR;
}

NPIdentifier NPN_GetStringIdentifierProc(const NPUTF8* name) {
    return (NPIdentifier)0x41424344; //Unique
}

static 
gboolean plug_removed_cb (GtkWidget *widget, gpointer data) {
    fprintf(stderr,"[!] plug_removed_cb\n");
    return TRUE;
}

static void
socket_unrealize_cb(GtkWidget *widget, gpointer data) {
    fprintf(stderr, "[!] socket_unrealize_cb\n");
}


static NPWindow *
npwindow_construct (GtkWidget *widget) {
  NPWindow *npwindow;
  NPSetWindowCallbackStruct *ws_info = NULL;

  GdkWindow *parent_win = widget->window;

  GtkWidget *socketWidget = gtk_socket_new();

  gtk_widget_set_parent_window(socketWidget, parent_win);
  gtk_widget_set_uposition(socketWidget, xPosition, yPosition);

  g_signal_connect(socketWidget, "plug_removed", G_CALLBACK(plug_removed_cb), NULL);
  g_signal_connect(socketWidget, "unrealize", G_CALLBACK(socket_unrealize_cb), NULL);
  g_signal_connect(socketWidget, "destroy", G_CALLBACK(gtk_widget_destroyed), &socketWidget);


  gpointer user_data = NULL;
  gdk_window_get_user_data(parent_win, &user_data);

  GtkContainer *container = GTK_CONTAINER(user_data);
  gtk_container_add(container, socketWidget);
  gtk_widget_realize(socketWidget);

  GtkAllocation new_allocation;
  new_allocation.x = 0;
  new_allocation.y = 0;
  new_allocation.width = WINDOW_XSIZE;
  new_allocation.height = WINDOW_YSIZE;
  gtk_widget_size_allocate(socketWidget, &new_allocation);

  gtk_widget_show(socketWidget);
  gdk_flush();

  GdkNativeWindow ww = gtk_socket_get_id(GTK_SOCKET(socketWidget));
  GdkWindow *w = gdk_window_lookup(ww); 

  npwindow = malloc (sizeof (NPWindow));
  npwindow->window = (void*)(unsigned long)ww;
  npwindow->x = 0;
  npwindow->y = 0;
  npwindow->width  = WINDOW_XSIZE;
  npwindow->height = WINDOW_YSIZE;

  ws_info = malloc(sizeof (NPSetWindowCallbackStruct));
  ws_info->type = NP_SETWINDOW;
  ws_info->display = GDK_WINDOW_XDISPLAY(w);
  ws_info->colormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(w));
  GdkVisual* gdkVisual = gdk_drawable_get_visual(w);
  ws_info->visual = GDK_VISUAL_XVISUAL(gdkVisual);
  ws_info->depth = gdkVisual->depth;

  npwindow->ws_info = ws_info;
  npwindow->type = NPWindowTypeWindow;

  return npwindow;
}

static NPStream *
npstream_construct() {
    NPStream *stream = malloc(sizeof(NPStream));
    stream->url=fileName;
    stream->notifyData = 0x00000000;

    fprintf(stderr,"[D] NPN_StreamConstructed: %p\n", stream);

    return stream;
}

bool NPN_GetPropertyProc(NPP npp, NPObject *obj, NPIdentifier propertyName, NPVariant *result) {
    fprintf(stderr,"[D] NPN_GetPropertyProc: %p\n", result);
    result->type = NPVariantType_Object;
    result->value.objectValue= (NPObject*)1;
    return TRUE;
}


bool NPN_InvokeProc(NPP npp, NPObject* obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result) {
    fprintf(stderr,"[D] NPN_InvokeProc: %p\n", result);
    result->type= NPVariantType_String;
    result->value.stringValue.utf8characters=fileName;
    result->value.stringValue.utf8length=strlen(fileName);
    return TRUE;
}

void NPN_ReleaseVariantValueProc(NPVariant *variant) {
}

void NPN_ReleaseObjectProc(NPObject *obj) {
}

NPObject*  NPN_CreateObjectProc(NPP npp, NPClass *aClass) {
    return (NPObject*)1;
}

NPObject*  NPN_RetainObjectProc(NPObject *obj) {
    return (NPObject*)1;
}

NPError NPN_GetURLNotifyProc(NPP instance, const char* url, const char* window, void* notifyData) {
    fprintf(stderr,"[D] NPN_GetURLNotifyProc:%p, url: %s, window: %s\n", instance, url, window);
    return 0;
}

NPN_GetURL, NPN_GetURLNotify, and NPP_URLNotify

void initNPNetscapeFuncs(NPNetscapeFuncs *bFuncs) {
  int i=0;

  for(i=1; i<sizeof(*bFuncs)/sizeof(ssize_t); i++)
    *(((ssize_t*)bFuncs)+i)=i+1000;

  bFuncs->geturl=NPN_GetURLProc;
  bFuncs->getvalue=NPN_GetValueProc;
  bFuncs->uagent=NPN_UserAgentProc;
  bFuncs->getproperty=NPN_GetPropertyProc;
  bFuncs->getstringidentifier=NPN_GetStringIdentifierProc;
  bFuncs->invoke=NPN_InvokeProc;
  bFuncs->releasevariantvalue=NPN_ReleaseVariantValueProc;
  bFuncs->releaseobject=NPN_ReleaseObjectProc;
  bFuncs->createobject=NPN_CreateObjectProc;
  bFuncs->retainobject=NPN_RetainObjectProc;
  bFuncs->geturlnotify=NPN_GetURLNotifyProc;
  bFuncs->size= sizeof(bFuncs);
  bFuncs->version= (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;;
}

static void destroy(GtkWidget *widget, gpointer data) {
    gtk_main_quit ();
}

static void checkError(const char* str, NPError err) {
  if(err == NPERR_NO_ERROR)
    fprintf(stderr, "[+] %s: success\n", str);
  else
    fprintf(stderr, "[-] %s: failed (%d)\n", str, err);
    fflush(NULL);
}

int main(int argc, char **argv) 
{
  int c;
  extern char *optarg;

  while ((c = getopt(argc, argv, "f:w:h:x:y:")) != EOF){
    switch (c) {
      case 'f':
        fileName = optarg;
        fprintf (stderr, "[+] Filename: %s\n", optarg);
        break;
      case 'w':
        WINDOW_XSIZE = atoi(optarg);
        fprintf (stderr, "[+] WINDOW_XSIZE: %s\n", optarg);
        break;
      case 'h':
        WINDOW_YSIZE = atoi(optarg);
        fprintf (stderr, "[+] WINDOW_YSIZE: %s\n", optarg);
        break;
      case 'x':
        xPosition = atoi(optarg);
        fprintf (stderr, "[+] Position in x: %s\n", optarg);
        break;
      case 'y':
        yPosition = atoi(optarg);
        fprintf (stderr, "[+] Position in y: %s\n", optarg);
        break;
      case '?':
        if (optopt == 'f' | optopt == 'w' | optopt == 'h')
          fprintf (stderr, "[-] Option -%c requires an argument.\n", optopt);
        else if (isprint (optopt))
          fprintf (stderr, "[-] Unknown option `-%c'.\n", optopt);
        else
          fprintf (stderr,"[-] Unknown option character `\\x%x'.\n", optopt);
          exit(-1);
      default:
        fprintf(stderr,"[-] Usage: %s -f <swffile> -x <xsize> -y <ysize>\n", argv[0]);
        exit(-1);
    }
  }

  gtk_init (&argc, &argv);
  main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_set_usize (main_window, WINDOW_XSIZE, WINDOW_YSIZE);
  gtk_widget_set_uposition (main_window, xPosition, yPosition);
  g_signal_connect (G_OBJECT (main_window), "destroy", G_CALLBACK (destroy), NULL);
  gtk_widget_realize(main_window);
  gtk_widget_show_all(main_window);
  fprintf(stderr,"[+] created GTK widget\n");

  flash_plugin_handle = loadFlashPluginSo();

  loadNPEntryPoints(flash_plugin_handle);
  fprintf(stderr,"[+] initialized flash plugin entry points\n");

  initNPNetscapeFuncs(&browserFuncs);
  fprintf(stderr,"[+] initialized browser functions\n");

  checkError("NP_Initialize", iNP_Initialize(&browserFuncs, &pluginFuncs));

  printPluginEntrypoints(&pluginFuncs);

  NPWindow *npwin = npwindow_construct(main_window);
  fprintf(stderr,"[+] created NPWindow widget\n");

  NPP_t *instancep = malloc(sizeof(NPP_t));
  memset(instancep,0,sizeof(sizeof(NPP_t)));
  NPP instance     = instancep;

  NPSavedData* saved = malloc(sizeof(NPSavedData));
  memset(saved,0,sizeof(sizeof(NPSavedData)));

  stream = npstream_construct();
  uint16_t stype;

  char *xargv[]= {"quality", "bgcolor", "width", "height", "allowScriptAccess", "loop" };
  char *xargm[]= {"high", "#000000", "1360", "768", "always", "false" };


  checkError("NPN_New", pluginFuncs.newp("application/x-shockwave-flash", instance, NP_EMBED, 0, xargv, xargm, saved));
  checkError("NPN_SetWindow", pluginFuncs.setwindow(instance, npwin));
  checkError("NPN_NewStream", pluginFuncs.newstream(instance, "application/x-shockwave-flash", stream, 0,  &stype));


  FILE *pp;

  char buffer[8192];
  pp = fopen(fileName,"rb");

  int len;

  while((len=fread(buffer, 1, sizeof(buffer), pp)) != 0) {
    pluginFuncs.writeready(instance, stream);
    pluginFuncs.write(instance, stream, 0, len, buffer);
  }

  fclose(pp);

  checkError("NPN_DestroyStream",pluginFuncs.destroystream(instance, stream, NPRES_DONE));

  free(stream);

  gtk_main ();

  checkError("NPN_Destroy",pluginFuncs.destroy(instance, &saved));


  checkError("NP_Shutdown", iNP_Shutdown());

  dlclose(flash_plugin_handle);
  return 0;
}

If I load a swf with no xml. It works. When I had a config to my xml. It stops.

Here's the ouput I get:

~/test-flash$ ./test-flash -f xml_sample.swf -w 400 -h 600 -x 15 -y 15
[+] Filename: xml_sample.swf
[+] WINDOW_XSIZE: 400
[+] WINDOW_YSIZE: 600
[+] Position in x: 15
[+] Position in y: 15
[+] created GTK widget
[+] loaded libflashplayer.so
[+] loaded symbol NP_Initialize, address: 0x7ff03fb634d0
[+] loaded symbol NP_Shutdown, address: 0x7ff03fb634c0
[+] loaded symbol NP_GetMIMEDescription, address: 0x7ff03fb63870
[+] initialized flash plugin entry points
[+] initialized browser functions
[+] NP_Initialize: success
[*] NPP struct:
        - NPP_size:                        0
        - NPP_version:                     0
        - NPP_NewProcPtr:           0x7ff03fb63990
        - NPP_DestroyProcPtr:       0x7ff03fb63980
        - NPP_SetWindowProcPtr:     0x7ff03fb63970
        - NPP_NewStreamProcPtr:     0x7ff03fb63960
        - NPP_DestroyStreamProcPtr: 0x7ff03fb63910
        - NPP_StreamAsFileProcPtr:  0x7ff03fb63920
        - NPP_WriteReadyProcPtr:    0x7ff03fb63950
        - NPP_WriteProcPtr:         0x7ff03fb63940
        - NPP_PrintProcPtr:         0x7ff03fb63900
        - NPP_HandleEventProcPtr:   0x7ff03fb638f0
        - NPP_URLNotifyProcPtr:     0x7ff03fb63930
        - javaClass:                (nil)
        - NPP_GetValueProcPtr:      0x7ff03fb63860
        - NPP_SetValueProcPtr:      (nil)
[+] created NPWindow widget
[D] NPN_StreamConstructed: 0x25ce5e0
[D] NPN_GetValueProc instance:0x25cc720, variable:14, abi_mask:0
[D] NPN_GetValueProc instance:0x25cc720, variable:268435469, abi_mask:0
[D] NPN_UserAgentProc instance:(nil)
[D] NPN_GetValueProc instance:0x25cc720, variable:15, abi_mask:0
[D] NPN_GetValueProc instance:0x25cc720, variable:15, abi_mask:0
[D] NPN_GetValueProc instance:0x25cc720, variable:18, abi_mask:0
[+] NPN_New: success
[D] NPN_GetValueProc instance:0x25cc720, variable:14, abi_mask:0
[+] NPN_SetWindow: success
[D] NPN_GetURLNotifyProc:0x25cc720, url: javascript:top.location+"__flashplugin_unique__", window: (null)
[D] NPN_GetValueProc instance:0x25cc720, variable:15, abi_mask:0
[+] NPN_NewStream: success
Lenght: 455
[D] NPN_UserAgentProc instance:0x25cc720
[+] NPN_DestroyStream: success
[D] NPN_GetURLNotifyProc:0x25cc720, url: sample.xml, window: (null)

Thank you!

EDIT:

I tried something like this (code is in NPN_GetURLNotifyProc function) . but then, my app freeze inside my geturlnotifyproc...

NPStream s;
uint16 stype;
memset(&s,0,sizeof(NPStream));
s.url = strdup(url);
fprintf(stderr, "URL: %s\n", s.url);
checkError("NPN_NewStream", pluginFuncs.newstream(instance,"text/html",&s,0,&stype));    
    writeStream(instance, &pluginFuncs, &s);
pluginFuncs.urlnotify(instance,url,NPRES_DONE,notifyData);
checkError("NPN_DestroyStream", pluginFuncs.destroystream(instance,&s,NPRES_DONE));
            free((void*)s.url);

解决方案

I forgot to add the notify to my stream...

NPError NPN_GetURLNotifyProc(NPP instance, const char* url, const char* target, void* notifyData) {
    fprintf(stderr,"[D] NPN_GetURLNotifyProc:%p, url: %s, window: %s, data: %p\n", instance, url, target, notifyData);
    NPStream s;
    uint16 stype;

    memset(&s,0,sizeof(NPStream));
    s.url = strdup(url);
    s.notifyData = notifyData;

    fprintf(stderr, "NPP: %p URL: %s\n", instance, url);

    checkError("NPN_NewStream", pluginFuncs.newstream(instance,"text/html",&s,0,&stype));    
    writeStream(instance, &pluginFuncs, &s);

    checkError("NPN_DestroyStream", pluginFuncs.destroystream(instance,&s,NPRES_DONE));
    free((void*)s.url);
    pluginFuncs.urlnotify(instance, url, NPRES_DONE, notifyData);
    return 0;
}

I have now a standalone gtk application who can run compiled flash (swf). Hope it helps someone in the future. I recommend doing a plugin to read another plugin (aka Sniffer) to actually know which function is called ("and how things works") to have a decent log file to work with.

这篇关于承载Flash将不会加载SWF ressources(XML,图像等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆