载入中,请稍候……

在JPG图片中追加、分离其它文件数据的脚本

Admin 于 2008-10-22 00:50:51 发表JavaScript

订阅: http://www.miniboke.com/Feed/Article_78.aspx
引用: http://www.miniboke.com/Trackback/rlOZdncPnwzTkamBaBto.aspx (UTF-8)
C++实现目录文件的非递归遍历并用伪函数来进行文件操作 < 在JPG图片中追加、分离其它文件数据的脚本 > MFC中对音量的控制:增大,减小,静音

用法:
1、追加文件:jpgexe.js jpg1.jpg + exe1.exe jpgout.jpg
程序exe1已经到图片jpgout.jpg 中了。
2.、分离:jpgexe.js jpgout.jpg  exe2.exe
程序exe2已经分离出来了。
脚本:

  1. function existsArg(args,argValue) 
  2.     for(var i = 0;i<args.length; ++i) 
  3.     { 
  4.         if(args.item(i) == argValue) 
  5.         { 
  6.             return true
  7.         } 
  8.     } 
  9.      
  10.     return false
  11.  
  12. Number.prototype.toBytes = function() 
  13.     var n = this
  14.     var s = new ActiveXObject("adodb.stream"); 
  15.     s.Charset = "ASCII"
  16.     s.Type = 2; 
  17.     s.Open(); 
  18.     s.Position = 0; 
  19.      
  20.     s.WriteText(String.fromCharCode(n & 0xff)); 
  21.     s.WriteText(String.fromCharCode((n >> 8) & 0xff)); 
  22.     s.WriteText(String.fromCharCode((n >> 16) & 0xff)); 
  23.     s.WriteText(String.fromCharCode((n >> 24) & 0xff)); 
  24.     s.Position = 0; 
  25.     s.Type = 1; 
  26.     var buf = s.Read(4); 
  27.      
  28.     s.Close(); 
  29.     return buf;     
  30.  
  31. Number.fromBytes = function(buf) 
  32.     var s = new ActiveXObject("adodb.stream"); 
  33.     s.Type = 1; 
  34.     s.Open(); 
  35.     s.Write(buf); 
  36.     if(s.Size != 4) 
  37.         throw 'Number.fromByte函数中,buf长度不对'
  38.     s.Position = 0; 
  39.     s.Type = 2; 
  40.     s.Charset = "ASCII"
  41.  
  42.     var str = s.ReadText(4); 
  43.     var n = str.charCodeAt(0);     
  44.     n |= (str.charCodeAt(1) << 8); 
  45.     n |= (str.charCodeAt(2) << 16); 
  46.     n |= (str.charCodeAt(3) << 24); 
  47.     s.Close(); 
  48.      
  49.     return n; 
  50.  
  51. function bindFile(picFile,exeFile,outFile) 
  52.     var streamPic = new ActiveXObject("adodb.stream"); 
  53.     streamPic.Type = 1; 
  54.     streamPic.Open(); 
  55.     streamPic.LoadFromFile(picFile); 
  56.     streamPic.Position = streamPic.Size; 
  57.      
  58.     var streamExe = new ActiveXObject("adodb.stream"); 
  59.     streamExe.Type = 1; 
  60.     streamExe.Open(); 
  61.     streamExe.LoadFromFile(exeFile); 
  62.     streamExe.Position = 0; 
  63.     streamExe.CopyTo(streamPic,streamExe.Size); 
  64.     streamPic.Write(streamExe.Size.toBytes()); 
  65.     streamExe.Close(); 
  66.     streamPic.SaveToFile(outFile); 
  67.     streamPic.Close(); 
  68.  
  69.  
  70. function exportExe(picFile,outFile) 
  71.     var bRet = false
  72.     var s = new ActiveXObject("adodb.stream"); 
  73.     s.Type = 1; 
  74.     s.Open(); 
  75.     s.LoadFromFile(picFile); 
  76.     s.Position = s.Size - 4; 
  77.     var buf = s.Read(4); 
  78.     var size = Number.fromBytes(buf); 
  79.     if(size > 0) 
  80.     { 
  81.         var pos =  s.Size - 4 - size; 
  82.         if(pos >= 0) 
  83.         { 
  84.             s.Position = pos; 
  85.             var exeData = s.Read(size); 
  86.             s.Close(); 
  87.             s.Open(); 
  88.             s.Write(exeData); 
  89.             s.SaveToFile(outFile); 
  90.             bRet = true
  91.         } 
  92.     } 
  93.      
  94.     s.Close(); 
  95.      
  96.     return bRet; 
  97.  
  98. function main(args) 
  99.     if(existsArg(args,"+")) 
  100.     { 
  101.         var picFile = args.item(0).toString(); 
  102.         var exeFile = args.item(2).toString(); 
  103.         var outFile = args.item(3).toString(); 
  104.         bindFile(picFile,exeFile,outFile); 
  105.     } 
  106.     else 
  107.     { 
  108.         var picFile = args.item(0).toString(); 
  109.         var outFile = args.item(1).toString(); 
  110.         exportExe(picFile, outFile); 
  111.          
  112.     } 
  113.  
  114. main(WScript.Arguments); 

 

被阅718次, 0投一票
  • 看完了要说点啥么?
  • 昵称 (不填说不了话)
  • 信箱地址 (不会被公开,但是不填也说不了话)
  • 网址 (这个不填也成)

Powered by MiniBoke v2.0.0.8 Build 0828

Copyright © 2008 迷你博客. All rights reserved.

粤ICP备07500939号