Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
My first Question:Which is better publish a web site from visual studio,or upload it by filezilla?
I didn't try any of them but someone told me when using filezilla:when I try to access my website, i get a file listing and when i try to view one of them, i just get a html text version of my pages.
but then again he said filezilla keeps the website even if it goes offline,is visual studio also the same?
And my SECOND Questin:
This is a jquery or javascript function?am I right?(which one?)
I saw it in a source code of a site,why does it look strange?I can't understand it,it has been encrypted?how can I turn it to sth which is more understandable?
(function (a, b) {
function c(a) { return K.isWindow(a) ? a : a.nodeType === 9 ? a.defaultView || a.parentWindow : !1 } function d(a) { if (!cl[a]) { var b = H.body, c = K("<" + a + ">").appendTo(b), d = c.css("display"); c.remove(); if (d === "none" || d === "") { cm || (cm = H.createElement("iframe"), cm.frameBorder = cm.width = cm.height = 0), b.appendChild(cm); if (!cn || !cm.createElement) cn = (cm.contentWindow || cm.contentDocument).document, cn.write((H.compatMode === "CSS1Compat" ? "<!doctype html>" : "") + "<html><body>"), cn.close(); c = cn.createElement(a), cn.body.appendChild(c), d = K.css(c, "display"), b.removeChild(cm) } cl[a] = d } return cl[a] } function e(a, b) { var c = {}; return K.each(cr.concat.apply([], cr.slice(0, b)), function () { c[this] = a }), c } function f() { cs = b } function g() { return setTimeout(f, 0), cs = K.now() } function h() { try { return new a.ActiveXObject("Microsoft.XMLHTTP") } catch (b) { } } function i() { try { return new a.XMLHttpRequest } catch (b) { } } function j(a, c) { a.dataFilter && (c = a.dataFilter(c, a.dataType)); var d = a.dataTypes, e = {}, f, g, h = d.length, i, j = d[0], k, l, m, n, o; for (f = 1; f < h; f++) { if (f === 1) for (g in a.converters) typeof g == "string" && (e[g.toLowerCase()] = a.converters[g]); k = j, j = d[f]; if (j === "*") j = k; else if (k !== "*" && k !== j) { l = k + " " + j, m = e[l] || e["* " + j]; if (!m) { o = b; for (n in e) { i = n.split(" "); if (i[0] === k || i[0] === "*") { o = e[i[1] + " " + j]; if (o) { n = e[n], n === !0 ? m = o : o === !0 && (m = n); break } } } } !m && !o && K.error("No conversion from " + l.replace(" ", " to ")), m !== !0 && (c = m ? m(c) : o(n(c))) } } return c } ...
it countinues
Your friend told you non-sense or you understood it that way. There's more than plain file transfer in VS deploy solution (like compilation of your source code into a dll for example), that can be fine tuned and so. Filezilla on its side is just plain ftp : you send the files you wish to a server.
You're not supposed to ask 2 questions at the same time, but still, to your second question :
this looks a lot like javascript, and it probably was minimized. This is a technique in which a parser replaces variable names by short names (letters), removes whitespaces and line feeds, etc in order to make the file smaller. Oh and JQuery is actually a javascript framework so there's no big difference between both.
Related
i'm getting random syntax errors in js files, sometimes in my bundle, sometimes other files, like fabric.min.js which i know works fine, and i can't figure it out.
For example lately i got :
bundle.js Uncaught SyntaxError: Unexpected token ) at 2:261833
which point to this function :
return function (t, n, a, o) {
if (!e(n)) {
var u, l = !1, h = [];
if (e(t)) l = !0, f(n, h); else {
var d = r(t.nodeType);
if (!d && sr(t, n)) O(t, n, h, null, null, o); else {
if (d) {
if (1 === t.nodeType && t.hasAttribute(I) && (t.removeAttribute(I), a = !0), i(a) && A(t, n, h)) return S(n, h, !0), t;
u = t, t = new pt(c.tagName(u).toLowerCase(), {}, [], void 0, u)
}
var p = t.elm, m = c.parentNode(p);
if (f(n, h, p._leaveCb ? null : m, c.nextSibling(p)), r(n.parent)) for (var g = n.parent, y = v(n); g;) {
for (var _ = 0; _ < s.destroy.length; ++_) s.destroy[_](g);
if (g.elm = n.elm, y) {
for (var x = 0; x < s.create.length; ++x) s.create[x](ar, g);
var k = g.data.hook.insert;
if (k.merged) for (var T = 1; T < k.fns.length; T++) k.fns[T]()
} else ir(g);
g = g.parent
}
r(m) ? w([t], 0, 0) : r(t.tag) && b(t)// error here at 0)
}
}
return S(n, h, l), n.elm
}
r(t) && b(t)
}
which is a function inside vue, i think it's the patch function.
When browser is restarted, it fixes the issue for some times, but in the end it comes back.
I was thinking about SRI but since we use file:// protocol (app is loaded locally in a webview inside android), i can't do that.
I'm tracking this issue for weeks without success,
how can a valid file become invalid and trigger syntax error ? can it be some cache issue ?
I know it's kind of a broad question, and i don't have much code to show, if you have any idea on how i could debug that or what could be the culprit here, like filesystem/hardware issue.
Thanks.
I was trying to understand the JavaScript on a website when I found a weird phenomenon. I enabled breakpoints for XHRs in devtools and was reading through the stack trace when it hit the breakpoint. The issue is this.
There would be a function definition that is something like:
function foo(someObject) {
//Some code
}
and when I went one more step up the stack trace to see the call to this function, I'd see something like:
bar(someobject);
The name of the call doesn't match the definition! Someone please explain how this works. Some references to articles would be appreciated too.
This may be a rookie question so thank you for the patience.
Edit 1 - Here are some screenshots:
This is at the last item in the stack. The code paused at line 1829. This is inside the function named _() starting at line 1805. If I jump one step back in the stack trace,
it jumps to line 268 of the same js file, where the function call is. But the call is to t.scheduleFn(), not to _(). I have checked and verified that the object passed in is identical to the object received at the definition. Please drop a comment if you need any more info.
If you need to see this live, please go to this website, turn on breakpoints for XHRs, enter any number into the input field, click on 'Get OTP' and look at the stack trace.
Edit 3 - Here's some of the code:
Please read the comments that I've added.
This is the function inside which the code paused:
function _(e) { //Note that this is the function name
const o = e.data,
c = o.target;
c[i] = !1,
c[h] = !1;
const l = c[r];
d || (d = c[s], g = c[a]),
l && g.call(c, 'readystatechange', l);
const u = c[r] = () =>{
if (c.readyState === c.DONE) if (!o.aborted && c[i] && 'scheduled' === e.state) {
const n = c[t.__symbol__('loadfalse')];
if (n && n.length > 0) {
const r = e.invoke;
e.invoke = function () {
const n = c[t.__symbol__('loadfalse')];
for (let t = 0; t < n.length; t++) n[t] === e && n.splice(t, 1);
o.aborted || 'scheduled' !== e.state || r.call(e)
},
n.push(e)
} else e.invoke()
} else o.aborted || !1 !== c[i] || (c[h] = !0)
};
return d.call(c, 'readystatechange', u),
c[n] || (c[n] = e),
T.apply(c, o.args), //The code paused here.
c[i] = !0,
e
}
If I went one step back to see the call to the function _() I see this:
scheduleTask(e, t) {
let n = t;
if (this._scheduleTaskZS) this._hasTaskZS && n._zoneDelegates.push(this._hasTaskDlgtOwner),
n = this._scheduleTaskZS.onScheduleTask(this._scheduleTaskDlgt, this._scheduleTaskCurrZone, e, t),
n || (n = t);
else if (t.scheduleFn) t.scheduleFn(t); //The debugger shows that this is where the call to _() happened.
else {
if (t.type != S) throw new Error('Task is missing scheduleFn.');
k(t)
}
return n
}
My question is simply, how can a call to t.scheduleFn() go to _(). Hope this is clear.
I know there are in-build function in javascript like toLocalString() to achieve number formatting. But this question is purely for learning and logic understanding.
I have a function in javascript that formats given number in Indian Number formatting standards (eg: 1,234 | 12,21,123 | etc)
Code
function formatter(input) {
var inputStr = input.toString(), l = inputStr.length;
var c = 1, f = 0;
console.log(l);
for (var x=l-1; x>=0; x--) {
if (x === 0) {
continue;
}
if (c === 3 && f === 0) {
inputStr = inputStr.substring(0, x) + ',' + inputStr.substring(x);
f = 1;
c = 0;
} else if (c % 2 === 0 && f === 1) {
inputStr = inputStr.substring(0, x) + ',' + inputStr.substring(x);
c = 0;
}
c++;
}
return inputStr;
}
Now this works for most part (as far as I have test, do point out bugs if you spot any). But my question is how do I handle large number in this, i.e. how do I handle values greater than 9007199254740991.
Hope this now fixes the issue:
function formatter(inputStr) {
inputStr+="";
let c = 1, f = 0;
for (let x=inputStr.length-1; x>=0; x--) {
if (x === 0) continue;
if (c === 3 && f === 0) {
inputStr = inputStr.substring(0, x) + ',' + inputStr.substring(x);
f = 1;
c = 0;
} else if (c % 2 === 0 && f === 1) {
inputStr = inputStr.substring(0, x) + ',' + inputStr.substring(x);
c = 0;
}
c++;
}
return inputStr;
}
//========= Tests =======
console.log(formatter(9007199254740991));
console.log(formatter("900719925474093454549341"));
console.log(formatter("123456678890987665443221112345667676766545434243"));
In my journey to learn JavaScript I encountered today this strange code in a script that I'm trying to read its code and understanding.
var j =["\\1A\\W\\1g","\\X\\S\\1p\\M","\\I\\G\\x\\H\\x\\H\\V\\I\\M","\\s\\W\\L\\1o\\z","\\W\\z\\W\\H","\\1v\\S\\1p\\1B\\T\\z\\1C\\G\\x\\I\\M\\G\\H\\V"];
I tried to console log the value of the j variable like this.
console.log(j[1] + '' + j[2] + '' + j[3] + '' + j[4] + '' + j[5] + '' + j[6]);
but unfortunately the console gave me an error which is "undefined". So is there any one can help me figure out how I can read this code.
As others have mentioned in the comments, this is JavaScript obfuscation. From the looks of it, it's attempting to read values from a page (via jQuery). Here's a quick breakdown:
In the fiddle you linked with the script, you'll find an eval is called on minified or packed code. There are two parts two it - the script that executes and the argument passed. When you prettify the script, it looks like this:
function(d, e, a, c, b, f) {
b = function(a) {
return (a < e ? "" : b(parseInt(a / e))) + (35 < (a %= e) ? String.fromCharCode(a + 29) : a.toString(36))
};
if (!"".replace(/^/, String)) {
for (; a--;) f[b(a)] = c[a] || b(a);
c = [function(a) {
return f[a]
}];
b = function() {
return "\\w+"
};
a = 1
}
for (; a--;) c[a] && (d = d.replace(new RegExp("\\b" + b(a) + "\\b", "g"), c[a]));
return d
}
The long string of code (assigned to the variable J) is returned and then eval'd. This returns another array of values (found here) a Crypto function, and other self-executing functions. This is what the crypto function looks like:
var CryptoJS = CryptoJS || function(e, f) {
var g = {},
_0xda47x5 = g[_0x52e0[0]] = {},
_0xda47x6 = function() {},
_0xda47x7 = _0xda47x5[_0x52e0[1]] = {
extend: function(a) {
_0xda47x6[_0x52e0[2]] = this;
var b = new _0xda47x6;
a && b[_0x52e0[3]](a);
b[_0x52e0[5]](_0x52e0[4]) || (b[_0x52e0[4]] = function() {
b[_0x52e0[7]][_0x52e0[4]][_0x52e0[6]](this, arguments)
});
b[_0x52e0[4]][_0x52e0[2]] = b;
b[_0x52e0[7]] = this;
return b
},
create: function() {
var a = this[_0x52e0[8]]();
a[_0x52e0[4]][_0x52e0[6]](a, arguments);
return a
},
init: function() {},
mixIn: function(a) {
for (var b in a) {
a[_0x52e0[5]](b) && (this[b] = a[b])
};
a[_0x52e0[5]](_0x52e0[9]) && (this[_0x52e0[9]] = a[_0x52e0[9]])
},
clone: function() {
return this[_0x52e0[4]][_0x52e0[2]][_0x52e0[8]](this)
}
},
_0xda47x8 = _0xda47x5[_0x52e0[10]] = _0xda47x7[_0x52e0[8]]({
init: function(a, b) {
a = this[_0x52e0[11]] = a || [];
this[_0x52e0[12]] = b != f ? b : 4 * a[_0x52e0[13]]
},
toString: function(a) {
return (a || _0xda47xa)[_0x52e0[14]](this)
},
concat: function(a) {
var b = this[_0x52e0[11]],
_0xda47x10 = a[_0x52e0[11]],
_0xda47x11 = this[_0x52e0[12]];
a = a[_0x52e0[12]];
this[_0x52e0[15]]();
if (_0xda47x11 % 4) {
for (var c = 0; c < a; c++) {
b[_0xda47x11 + c >>> 2] |= (_0xda47x10[c >>> 2] >>> 24 - 8 * (c % 4) & 255) << 24 - 8 * ((_0xda47x11 + c) % 4)
}
} else {
if (65535 < _0xda47x10[_0x52e0[13]]) {
for (c = 0; c < a; c += 4) {
b[_0xda47x11 + c >>> 2] = _0xda47x10[c >>> 2]
}
} else {
b[_0x52e0[16]][_0x52e0[6]](b, _0xda47x10)
}
};
this[_0x52e0[12]] += a;
return this
},
clamp: function() {
var a = this[_0x52e0[11]],
_0xda47xf = this[_0x52e0[12]];
a[_0xda47xf >>> 2] &= 4294967295 << 32 - 8 * (_0xda47xf % 4);
a[_0x52e0[13]] = e[_0x52e0[17]](_0xda47xf / 4)
},
clone: function() {
var a = _0xda47x7[_0x52e0[19]][_0x52e0[18]](this);
a[_0x52e0[11]] = this[_0x52e0[11]][_0x52e0[20]](0);
return a
},
random: function(a) {
for (var b = [], _0xda47x10 = 0; _0xda47x10 < a; _0xda47x10 += 4) {
b[_0x52e0[16]](4294967296 * e[_0x52e0[21]]() | 0)
};
return new _0xda47x8[_0x52e0[4]](b, a)
}
}),
_0xda47x9 = g[_0x52e0[22]] = {},
_0xda47xa = _0xda47x9[_0x52e0[23]] = {
stringify: function(a) {
var b = a[_0x52e0[11]];
a = a[_0x52e0[12]];
for (var c = [], _0xda47x11 = 0; _0xda47x11 < a; _0xda47x11++) {
var d = b[_0xda47x11 >>> 2] >>> 24 - 8 * (_0xda47x11 % 4) & 255;
c[_0x52e0[16]]((d >>> 4).toString(16));
c[_0x52e0[16]]((d & 15).toString(16))
};
return c[_0x52e0[25]](_0x52e0[24])
},
parse: function(a) {
for (var b = a[_0x52e0[13]], _0xda47x10 = [], _0xda47x11 = 0; _0xda47x11 < b; _0xda47x11 += 2) {
_0xda47x10[_0xda47x11 >>> 3] |= parseInt(a[_0x52e0[26]](_0xda47x11, 2), 16) << 24 - 4 * (_0xda47x11 % 8)
};
return new _0xda47x8[_0x52e0[4]](_0xda47x10, b / 2)
}
},
_0xda47xb = _0xda47x9[_0x52e0[27]] = {
stringify: function(a) {
var b = a[_0x52e0[11]];
a = a[_0x52e0[12]];
for (var c = [], _0xda47x11 = 0; _0xda47x11 < a; _0xda47x11++) {
c[_0x52e0[16]](String[_0x52e0[28]](b[_0xda47x11 >>> 2] >>> 24 - 8 * (_0xda47x11 % 4) & 255))
};
return c[_0x52e0[25]](_0x52e0[24])
},
parse: function(a) {
for (var b = a[_0x52e0[13]], _0xda47x10 = [], _0xda47x11 = 0; _0xda47x11 < b; _0xda47x11++) {
_0xda47x10[_0xda47x11 >>> 2] |= (a[_0x52e0[29]](_0xda47x11) & 255) << 24 - 8 * (_0xda47x11 % 4)
};
return new _0xda47x8[_0x52e0[4]](_0xda47x10, b)
}
},
_0xda47xc = _0xda47x9[_0x52e0[30]] = {
stringify: function(a) {
try {
return decodeURIComponent(escape(_0xda47xb[_0x52e0[14]](a)))
} catch (c) {
throw Error(_0x52e0[31]);
}
},
parse: function(a) {
return _0xda47xb[_0x52e0[32]](unescape(encodeURIComponent(a)))
}
},
_0xda47xd = _0xda47x5[_0x52e0[33]] = _0xda47x7[_0x52e0[8]]({
reset: function() {
this[_0x52e0[34]] = new _0xda47x8[_0x52e0[4]];
this[_0x52e0[35]] = 0
},
_append: function(a) {
_0x52e0[36] == typeof a && (a = _0xda47xc[_0x52e0[32]](a));
this[_0x52e0[34]][_0x52e0[37]](a);
this[_0x52e0[35]] += a[_0x52e0[12]]
},
_process: function(a) {
var b = this[_0x52e0[34]],
_0xda47x10 = b[_0x52e0[11]],
_0xda47x11 = b[_0x52e0[12]],
_0xda47x12 = this[_0x52e0[38]],
_0xda47xb = _0xda47x11 / (4 * _0xda47x12),
_0xda47xb = a ? e[_0x52e0[17]](_0xda47xb) : e[_0x52e0[40]]((_0xda47xb | 0) - this[_0x52e0[39]], 0);
a = _0xda47xb * _0xda47x12;
_0xda47x11 = e[_0x52e0[41]](4 * a, _0xda47x11);
if (a) {
for (var c = 0; c < a; c += _0xda47x12) {
this._doProcessBlock(_0xda47x10, c)
};
c = _0xda47x10[_0x52e0[42]](0, a);
b[_0x52e0[12]] -= _0xda47x11
};
return new _0xda47x8[_0x52e0[4]](c, _0xda47x11)
},
clone: function() {
var a = _0xda47x7[_0x52e0[19]][_0x52e0[18]](this);
a[_0x52e0[34]] = this[_0x52e0[34]][_0x52e0[19]]();
return a
},
_minBufferSize: 0
});
_0xda47x5[_0x52e0[43]] = _0xda47xd[_0x52e0[8]]({
cfg: _0xda47x7[_0x52e0[8]](),
init: function(a) {
this[_0x52e0[44]] = this[_0x52e0[44]][_0x52e0[8]](a);
this[_0x52e0[45]]()
},
reset: function() {
_0xda47xd[_0x52e0[45]][_0x52e0[18]](this);
this._doReset()
},
update: function(a) {
this._append(a);
this._process();
return this
},
finalize: function(a) {
a && this._append(a);
return this._doFinalize()
},
blockSize: 16,
_createHelper: function(c) {
return function(a, b) {
return (new c[_0x52e0[4]](b))[_0x52e0[46]](a)
}
},
_createHmacHelper: function(c) {
return function(a, b) {
return (new h[_0x52e0[47]][_0x52e0[4]](c, b))[_0x52e0[46]](a)
}
}
});
var h = g[_0x52e0[48]] = {};
return g
}(Math);
I won't paste the other self-executing functions, but if you're interested - they can be found here: https://gist.github.com/anonymous/73b41a89f073653ee405
Some of the more interesting variable names are:
var code_text1 = $(_0x52e0[111])[_0x52e0[110]]();
var decrypted = CryptoJS[_0x52e0[106]][_0x52e0[71]](code_text1, _0x52e0[112]);
var plaintext2 = decrypted.toString(CryptoJS[_0x52e0[22]].Utf8);
var code_text2 = plaintext2[_0x52e0[113]](/[^[\]]+(?=])/g);
var secretBlog = code_text2[0];
var urlBlog = code_text2[1];
The eval itself breaks because code_text is attempting to set the value when it executes $(_0x52e0[111])[_0x52e0[110]]();, which - deobfucscated, is $('.buyer')['text']()
My guess - and purely my guess because it depends on WHERE this code would be executed, is that this is injected into an e-commerce site, which reads a value (based on a buyer text), and sends (or redirects) to a (secret) blog or another URL.
Anyway, hope this helps and have fun learning JS!
Well, you should first beautify the code. It really is hard to see where to go if the code is a mess. The first step is to make it prettier (I use jsbeautifier).
From there you'll see code similar to this:
eval(function(d, e, a, c, b, f) { ... }(...))
Because there is no complex obfuscation involved, we can simply replace eval with a variable statement.
var x = (function(d, e, a, c, b, f) { ... }(...))
Here we are basically telling the variable "x" to equal the returned code from the function. Next, console.log() the value of x like so.
console.log(x);
You'll notice that the code is a bit more readable now, progress! If you look through the output code, you'll notice that it follows a similar pattern of encoded characters. We can deobfuscate this code by entering it into jsbeautifier's simple textarea with "Unescape Printable Chars" checked.
From here, you'll notice yet another eval statement at the bottom of the rendered code. I won't go down another level, but hopefully this post gives you the basics of deobfuscation. To continue deobfuscation, you'd simply remove the if statement and change eval to another variable declaration and console.log() that return.
As you go further into deobfuscation, you will be able to understand the source more.
The JavaScript obfuscator CryptoJS is open-source if you want to check out its source code.
Good luck!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want a function that takes an integer and returns that number in the form of a church encoded function.
I have achieved this in newlisp:
(define (reduce stencil sq) (apply stencil sq 2))
(define (num n) (cond
((= n 0) 'x)
((< n 2) '(f x))
(true (reduce (fn (l i) (list 'f l)) (cons '(f x) (sequence 2 n)) ))))
(define (church-encode n)
(letex ((body (num n)))
(fn (f x) body)))
If I call (church-encode 0) I get back a lambda of the church-encoded zero:
(lambda (f x) x)
And (church-encode 3) will yield:
(lambda (f x) (f (f (f x))))
But I want to do the same in Javascript. Preferably without resorting to string jank like I have done here:
(function (_) {
var asnum = function(x) { return x((function(x) {return x+1;}), 0); };
function church_encode(n) {
function genBody() {
return _.reduce(_.range(n), function(e,x) {
return e.replace("x", "f(x)");
}, "x");
}
eval("var crap = function (f, x) { return "+genBody()+"; }");
return crap;
}
var encoded_nums = _.map(_.range(11), church_encode);
var numerics = _.map(encoded_nums, asnum);
console.log(numerics);
})(require('lodash'));
(function () {
function range(n){
var l = [];
for(var i = 0; i < n; i++){
l.push(i);
}
return l;
}
function church_encode(n) {
if(n < 1)
return function(f, x) { return x; };
if(n === 1)
return function(f, x) { return f(x); };
function succ (n) {
return function(f,x) {
return n(f,f(x));
}
}
return range(n).reduce(function(a){
return succ(a);
}, function (f,x) { return x; });
}
function to_int(f){
var i = 0;
f(function(){ i++ });
return i;
};
console.log(to_int(church_encode(5)));
})();