Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-06-2012, 06:43 PM   PM User | #1
wolfblood
New to the CF scene

 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
wolfblood is an unknown quantity at this point
Javascript reflective reference

If i am right than every object is under window.
i wrote this code

for(i in window)
{
document.write(i+"<br/>");
}
it returns me every defined object

but there is some object which is created by constructor and they are not returned

if("WebSocket" in window)

how can i get these
what else could be missing
wolfblood is offline   Reply With Quote
Old 09-06-2012, 08:59 PM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,553
Thanks: 9
Thanked 480 Times in 463 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
some folks say you can't.

here is a wise-guy workaround, but it's more of a joke than a real tool.
still, it might find a couple of surprises for you. window.dump? hehe
or it may hang your browser.
grab a sandwich check back later.


yes, it's a brute-force object detector. i'd never seen one before. this is just a proof of concept. i want a scalable distributed version.
Code:
var mystery=window; //"hello world"  false [1,2,3]  
var d1=+new Date;
r=[""];for(var i2=97; i2< 123;i2++){r.push(String.fromCharCode(i2));}
r[-1]="";
var s=r.join("");
var s0=0, s1=0, s2=0, s3=0, s4=0, s5=0, s6=0, s7=0, s8=0, n=27;
window.p={};

 window.k6="";
 window.k4="";
 var k1, k2, k3, k5;
 c=[0,0,0,0,0,0,0,0,0,0];

function runOne(){
 var i=0, x;
for(s0=c[0];s0<n;++s0){
for(s1=c[1];s1<n;s1++){ 
for(s2=c[2];s2<n;s2++){
for(s3=c[3];s3<n;s3++){ 
 if(i++>19){ c=[s0,s1?s1-1:0, s2?s2-1:0,s3?s3-1:0,0,0,0];  report(); return setTimeout(runOne, 750);  }
for(s4=c[4];s4<n;s4++){ k4=r[s0]+r[s1]+r[s2]+r[s3]+r[s4];
for(s5=c[5];s5<n;s5++){ k5=k4+r[s5];
for(s6=c[6];s6<n;s6++){ k6=k5+r[s6];
  if( (x=mystery[k6])!==undefined ) { p[k6]=String(x); }
}}}}}}}

 
 var d2= +new Date;
 console.log(document.title="done. found "+Object.keys(p).length +" properties in "+ (d2-d1)+"ms" );

}//end runOne()

function report(){
    document.body.innerHTML="<pre>"+JSON.stringify(p, null, "\t");
}

runOne()
it misses anything with a number or uppercase letter. that slows it down even more...

after about 30 seconds, it had found this when run on this page using firebug:
Code:
  {
	"c": "0,0,0,0,0,0,0,0,0,0",
	"i": "16",
	"n": "27",
	"p": "[object Object]",
	"r": ",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z",
	"s": "abcdefghijklmnopqrstuvwxyz",
	"ltr": "left",
	"top": "[object Window]",
	"who": "function who(A) {\n    return openWindow(\"misc.php?\" + SESSIONURL + \"do=whoposted&t=\" + A, 230, 300);\n}",
	"atob": "function atob() {\n    [native code]\n}",
	"back": "function back() {\n    [native code]\n}",
	"blur": "function blur() {\n    [native code]\n}",
	"btoa": "function btoa() {\n    [native code]\n}",
	"dump": "function dump() {\n    [native code]\n}",
	"eval": "function eval() {\n    [native code]\n}",
	"find": "function find() {\n    [native code]\n}",
	"gapi": "[object Object]",
	"home": "function home() {\n    [native code]\n}",
	"java": "[Java Package \"java\"]",
	"name": "",
	"open": "function open() {\n    [native code]\n}",
	"self": "[object Window]",
	"stop": "function stop() {\n    [native code]\n}"
}

i wrote this just this weekend. this one is 7 chars, and the code got away from me, so it's a little sloppy. the 4 chars was fast and stable, but limited.

real answer: i think firebug is easier.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:15.2% IE7:0.5% IE8:8.4% IE9:8.5% IE10:8.5%

Last edited by rnd me; 09-06-2012 at 09:08 PM..
rnd me is online now   Reply With Quote
Old 09-06-2012, 10:22 PM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,530
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
The for..in statement will never process anything flagged as not enumerable. This includes many of the predevined properties and methods in the built in objects (such as window).

The latest version of JavaScript provides more direct access to the se types of settings so that you can now create your own properties and methods that will have that flag set and so be skipped over by for..in
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/

Last edited by felgall; 09-06-2012 at 10:28 PM..
felgall is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript, reflection

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:25 AM.


Advertisement
Log in to turn off these ads.