Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[JavaScript] dirty_functions_generation__aka_dead_code.js
var store = {}
, names = ["a1g3r_a", "a10ha", "ah0y", "am_wa1", "amd0ra", "amg01a", "amg3r", "amgu_1a", "amt_pat_0m", "arg3ma", "art_c13", "arula", "arw3m_a", "austra", "aw3", "az3rlam", "c0mfus_0m", "c0mt3wpt", "c0mta_m3r", "c0mtw3mt", "c0s", "c0wl_a", "c10th3s", "caw3r0m", "cawl0d_a", "ch_13", "ch_ma", "chad", "cr0a", "d0g", "d3spa_r", "d_sap0_mtw3mt", "dh31_a", "dj_l0ut_", "drug", "f0d", "f0pt_sw", "f0wam", "f1_3cht3mst3_m", "f1_d", "f1_l3r_a", "f1a0s", "f1ust", "f3csy", "f3cuad0r", "f3mvy", "f3r3a", "f3st0m_a", "f3th_a", "f3xc_t", "f10mg", "f10v3", "f13lam", "f13s0", "fr_ght", "fru_t", "furm_tur3", "fury", "g30rg_a", "g_lrar", "gal0m", "gr3ma", "gr3md", "gr3t_mgs", "gratud3", "gu3rms3y", "gu_1t", "gu_m3a-l_sau", "gu_m3a", "guad310up3", "guaw", "guya", "h0r", "h01a", "h3y", "h013", "h310", "hap_m3s", "hatr3d", "humg3r", "huw_ty", "j0l", "j0rdam", "j0y", "j3y", "jam", "k_lat_", "khstam", "kuwa_t", "kyzstam", "l0dy", "l0r3d0w", "l0tswa", "l01_a", "l1_s", "l3m", "l3rwuda", "l3w_1d3mt", "l31_z3", "l31arus", "l_rd", "la1", "la_m", "lad0s", "lamg1ad3sh", "lhutam", "lraz_1", "lrum3_", "lumd_", "lurwa", "m3pa1", "m_u3", "mau", "msfw", "p1amt", "p3mgu_m", "p3rs0m", "p3ru", "p13asur3", "p_ty", "pa_m", "pas_0m", "pau", "pay", "ph_m3s", "pr_d3", "qar", "r0umd", "r3um", "r3w0rs3", "rag3", "rus_a", "s0w", "s3ga1", "s3x", "s3ych3s", "s_0m", "s_c31amd", "s_m3s_a", "s_mgap0r3", "s_ms3ct", "s_mt", "sa1ut_0ms", "sadm3s", "sat_sfact_0m", "sh0ck", "shap3", "shaw3", "sup", "sur_maw3", "sur_s3", "surfac3", "svard", "swaz_1amd", "swugm3s", "t0k31au", "t0mga", "t0rw3mt", "t01", "t3r", "t_w0r-13", "taj_stam", "tam", "thamd", "tum_a", "turkw3m_stam", "tuva1u", "uay", "uga", "ukra_m3", "uzl3k_stam", "v3h_c13", "v31a", "v_3tmaw", "vatu", "w0mac0", "w0mts3rat", "w0va", "w0zawl_qu3", "w01_a", "w3ap0m", "w31amch01y", "wa1_", "wa1d_v3s", "wac3d0m_a", "wadm3s", "wart_qu3", "wau", "waur_ta", "waus", "way0t3", "ways_a", "whazup", "y3m", "z_w3", "zawl_a"]
, text = []
;
names.forEach(function(name,index){
text.push("function " + name + "(" + names[Math.floor(Math.random()*names.length)] + "){" + "\r\n"
+ " " + names[Math.floor(Math.random()*names.length)] + "(" + names[Math.floor(Math.random()*names.length)] + ", \"" + names[Math.floor(Math.random()*names.length)] + "\", \"" + (Math.random()*100).toString(16) + "\");" + "\r\n"
+ " " + "return " + ["true", "false", "0", "!0", "!1", "undefined", "null", "new Object(null)"][Math.floor(Math.random()*8)] + ";" + "\r\n"
+ "}"
);
});
text = text.join("\r\n\r\n");
@eladkarako

This comment has been minimized.

Copy link
Owner Author

commented Jul 7, 2019

improved version: reduce direct recursion

"use strict";

var names         = ["a1g3r_a", "a10ha", "ah0y", "am_wa1", "amd0ra", "amg01a", "amg3r", "amgu_1a", "amt_pat_0m", "arg3ma", "art_c13", "arula", "arw3m_a", "austra", "aw3", "az3rlam", "c0mfus_0m", "c0mt3wpt", "c0mta_m3r", "c0mtw3mt", "c0s", "c0wl_a", "c10th3s", "caw3r0m", "cawl0d_a", "ch_13", "ch_ma", "chad", "cr0a", "d0g", "d3spa_r", "d_sap0_mtw3mt", "dh31_a", "dj_l0ut_", "drug", "f0d", "f0pt_sw", "f0wam", "f1_3cht3mst3_m", "f1_d", "f1_l3r_a", "f1a0s", "f1ust", "f3csy", "f3cuad0r", "f3mvy", "f3r3a", "f3st0m_a", "f3th_a", "f3xc_t", "f10mg", "f10v3", "f13lam", "f13s0", "fr_ght", "fru_t", "furm_tur3", "fury", "g30rg_a", "g_lrar", "gal0m", "gr3ma", "gr3md", "gr3t_mgs", "gratud3", "gu3rms3y", "gu_1t", "gu_m3a-l_sau", "gu_m3a", "guad310up3", "guaw", "guya", "h0r", "h01a", "h3y", "h013", "h310", "hap_m3s", "hatr3d", "humg3r", "huw_ty", "j0l", "j0rdam", "j0y", "j3y", "jam", "k_lat_", "khstam", "kuwa_t", "kyzstam", "l0dy", "l0r3d0w", "l0tswa", "l01_a", "l1_s", "l3m", "l3rwuda", "l3w_1d3mt", "l31_z3", "l31arus", "l_rd", "la1", "la_m", "lad0s", "lamg1ad3sh", "lhutam", "lraz_1", "lrum3_", "lumd_", "lurwa", "m3pa1", "m_u3", "mau", "msfw", "p1amt", "p3mgu_m", "p3rs0m", "p3ru", "p13asur3", "p_ty", "pa_m", "pas_0m", "pau", "pay", "ph_m3s", "pr_d3", "qar", "r0umd", "r3um", "r3w0rs3", "rag3", "rus_a", "s0w", "s3ga1", "s3x", "s3ych3s", "s_0m", "s_c31amd", "s_m3s_a", "s_mgap0r3", "s_ms3ct", "s_mt", "sa1ut_0ms", "sadm3s", "sat_sfact_0m", "sh0ck", "shap3", "shaw3", "sup", "sur_maw3", "sur_s3", "surfac3", "svard", "swaz_1amd", "swugm3s", "t0k31au", "t0mga", "t0rw3mt", "t01", "t3r", "t_w0r-13", "taj_stam", "tam", "thamd", "tum_a", "turkw3m_stam", "tuva1u", "uay", "uga", "ukra_m3", "uzl3k_stam", "v3h_c13", "v31a", "v_3tmaw", "vatu", "w0mac0", "w0mts3rat", "w0va", "w0zawl_qu3", "w01_a", "w3ap0m", "w31amch01y", "wa1_", "wa1d_v3s", "wac3d0m_a", "wadm3s", "wart_qu3", "wau", "waur_ta", "waus", "way0t3", "ways_a", "whazup", "y3m", "z_w3", "zawl_a"]
   ,shuffle_sort  = function(){return [-1,1][Math.floor(Math.random()*2)];}
   ,get_name      = function(but_not_that_name){    //reduce amount of 'recursion calls' in the text by providing a list of names that does not include a specific string (currently used, for example as a function name).
                      var valid_names = names;

                      but_not_that_name = but_not_that_name || "";    //normalize weird-input to string.

                      valid_names = valid_names.filter(function(name){
                                      return but_not_that_name !== name;
                                    });

                      return valid_names[Math.floor(Math.random()*valid_names.length)];
                    }
   ,store         = {}
   ;


names = names.sort(shuffle_sort);   //shuffle the array (in-case the future actions will also include trimming-of-it (optional) - shuffling will give different result each time which is a better quality of a 'dead-code-generator').


function generate_dead_code_text(limit){
  var text = [];
  //-------------------------------------------------------------------------optional)good-quality trimming of 'names'.
  limit = "number" !== typeof limit ? names.length  : limit;  //valid number
  limit = limit < 10                ? 10             : limit; //min
  limit = limit > names.length      ? names.length  : limit;  //max
  //--------------------------------------------------------------------------------------------------------------------

  names = names.slice(0,limit); //trim the amount of combinations/variations of names to use in the dead code generation. best to leave.
  
  names.forEach(function(name,index){
    text.push("function " + name + "(" + get_name(name) + "){"                                                                                                                                             + "\r\n"
              + "  " + get_name(name) + "(" + get_name(name) + ", \"" + get_name(name) + "\", \"" + (Math.random()*100).toString(16) + "\");"      + "\r\n"
              + "  " + "return " + ["true", "false", "0", "!0", "!1", "undefined", "null", "new Object(null)"][Math.floor(Math.random()*8)] + ";"                                                                                         + "\r\n"
              + "}"
              );
  });
  
  return text.join("\r\n\r\n");
}


generate_dead_code_text();    //no limit, use all list of names.

generate_dead_code_text(11);  //limit to 11 function calls total.

This will make sure that the 'name' won't be used in the same function currently ""running"" (in the text...)
there are in-direct recursion naturally...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.