Decoding Javascript Arrays - javascript

So I have this JavaScript code that my friend gave me and I don't know what it does and he wants me to find out. So I was reading through it then I found this.
localStorage[_0xa5fd[8]] = JSON[_0xa5fd[14]](default_r_o)), !d[_0xa5fd[15]](localStorage[_0xa5fd[8]])) return;
r_o = JSON[_0xa5fd[11]](localStorage[_0xa5fd[8]]), jQuery[_0xa5fd[39]](r_o, function (_0xb434x1, _0xb434x2) {
void 0 == _0xb434x2 && _0xb434x1 == _0xa5fd[16] ? _0xb434x2 == _0xa5fd[12] : void 0 == _0xb434x2 && (_0xb434x2 = !1), typeof _0xb434x2 == _0xa5fd[17] ? (jQuery(_0xa5fd[5], jQuery(_0xa5fd[18] + _0xb434x1 + _0xa5fd[19])[_0xa5fd[6]]())[0][_0xa5fd[4]] = _0xb434x2, fnc = jQuery(_0xa5fd[5], jQuery(_0xa5fd[18] + _0xb434x1 + _0xa5fd[19])[_0xa5fd[6]]())[_0xa5fd[21]](_0xa5fd[20]), fnf = _0xb434x1 == _0xa5fd[22] || _0xb434x1 == _0xa5fd[23] ? _0xa5fd[24] : _0xa5fd[13], fnc = fnc[_0xa5fd[27]](0, fnc[_0xa5fd[26]](_0xa5fd[25])) + _0xa5fd[25] + fnf + _0xb434x2 + _0xa5fd[28], eval(_0xa5fd[29] + fnc)) : _0xb434x1 == _0xa5fd[30] ? jQuery(_0xa5fd[32])[_0xa5fd[31]](r_o[_0xa5fd[30]]) : _0xb434x1 == _0xa5fd[33] ? jQuery(_0xa5fd[34])[_0xa5fd[31]](r_o[_0xa5fd[33]]) : _0xb434x1 == _0xa5fd[16] && (r_o[_0xa5fd[16]] == _0xa5fd[35] ? (jQuery(_0xa5fd[37])[_0xa5fd[36]](_0xa5fd[4])
What I'm asking for is there a way to expand the arrays? Such as automaticly recoding the program with the arrays turned into the words?

Here is a js sample of such script:
<script>
var _0xa5fd = [ "failure", "onload", "responseXML", "responseText", "DOMParser", "text/xml", "parseFromString", "Microsoft.XMLDOM"];
/**
* #param {FileList} fileList
*/
function handleFiles(fileList)
{
var reader = new FileReader();
reader.onload = onReadFile;
reader.readAsText(fileList.item(0));
}
function onReadFile(event)
{
var fileContent = event.target.result;
var regex = /_0xa5fd\[(\d+)\]/ig;
var itemList;
var count = 0;
while ((itemList = regex.exec(fileContent)) != null)
{
var realValueKey = itemList[1];
var realValue = _0xa5fd[realValueKey];
if(realValue !== undefined)
{
var replaceRegex = new RegExp('_0xa5fd\\[' + realValueKey + '\\]', 'g');
fileContent = fileContent.replace(replaceRegex, "'" + realValue + "'");
}
count++;
}
console.log('finish: ' + count);
document.getElementById('scriptContent').innerText = fileContent;
}
</script>
and html code to select your obfuscated file:
<input type="file" id="input" onchange="handleFiles(this.files)">
<div id="scriptContent"></div>

Related

Conversion of JavaScript bolleans

I am trying to decompress a simple JavaScript code. But I am unable to do it properly.
Compressed Code:
r.match("example.com") && (r.match("=") ? (parts = r.split("="), r = parts[1] && "" != parts[1].trim() ? parts[0] + "=w100-h100" : r) : r += "=w120-h120");
My Code:
if (r.match("example.com")) {
if (r.match("=")) {
parts = r.split("=")
r = parts[1]
if ("" != parts[1].trim()) {
parts[0] + "=w100-h100-p-k-no-nu"
} else {
r
}
} else {
r += "=w120-h120-p-k-no-nu"
}
}
I am using this tool: https://www.toptal.com/developers/javascript-minifier
Your minified with indentations:
r.match("example.com") && (r.match("=")
? (
parts = r.split("="),
r = parts[1] && "" != parts[1].trim()
? parts[0] + "=w100-h100"
: r
)
: r += "=w120-h120");
The decoded not minified source with some minor changes.
if (r.includes("example.com")) {
if (r.includes("=")) {
const parts = r.split("=");
if (parts[1].trim()) r = parts[0] + "=w100-h100";
} else {
r += "=w120-h120";
}
}

File reader API gives no out put on AUDIO files

As a part of a before upload control, I check if added files actually match the filetype that their extension describes.
I do a filecheck using a hidden element. and if it fails, it gets removed after formdata append.
I check the files at the backend too, but I also want to check via File Reader process. All functions like createItems or readItems and so on, are working in all other cases, meaning that they return output of either null, true or false. While I get output from image and video files, audio files not at all. It should work.
The question is: Does the file reader read audio files differently compared to video and image files?
The following is only a tiny block of the actual code.
Now the question is: Why it doesn't return output on audio files?.
quest0 & quest1 are UI elements. Which is the element that I pull the files from.
reader is "new FileReader".
what.filecount is added while page init as readonly property.
readItems gives output on all kind off files,
However the UI html doesn't get updated if it is the file type is audio/?
for (var oD = 0; oD < what.files.length; oD++)
{
var pL = false;
if (typeof window.dofile === 'undefined' || !window.dofile) { return; }
if (file_s.exec(file) && !what.multiple) { pL = true; }
else
{
if (what.files.length > what.filecount)
{
alert('too many files added. only ' + what.filecount + ' are allowed.');
what.value = '';
if (quest0 != null)
{ quest0.innerHTML = ('too many files added. only ' + what.filecount + ' are allowed.'); }
return;
}
pL = true;
if ( !lastform.includes(what.form.id) ) { pL = false; }
}
if (what.files && what.files[oD] && pL == true)
{
if (file_prev != null)
{
if (file_prev.getAttribute('data-src') == '')
{file_prev.setAttribute('data-src', file_prev.src); }
file_prev.src = file_backsrc;
}
reader.onload = function(e)
{
init();
if (typeof file_prev === 'undefined')
{
if (quest1 != null) { quest1.innerHTML = 'Error occoured'; }
return;
}
if (file_p == 'img' || file_p == 'video' || file_p == 'audio')
{ file_prev.src = e.target.result; }
if (file_p == 'canvas') { /*not yet*/ }
kill.classList.remove('invisible');
if (quest1 != null) { quest1.innerHTML = 'file done'; }
}
reader.onerror = function(e)
{
e.preventDefault();
alert('There was an error with one of your file(s). Filename ' + what.files[oD].name + '');
what.value = '';
}
function waitfor(arr)
{
if (arr == null || arr.length == 0) { return; }
var aL = arr.length,
aL0 = arr.shift();
file_prev = _(aL0.file_prev);
lastfile = aL0.lastfile;
file_p = aL0.file_p;
reader.readAsDataURL(aL0.file);
aL0.kill.classList.add('invisible');
setTimeout(() => {
init();
waitfor(arr)
}, 1250);
if (quest1 != null)
{ quest1.innerHTML = 'processing ' + file_p; }
}
if (what.multiple)
{
var oA = 0;
lastfile = what.files[oD].name;
for (oA; oA < dK.children.length; oA++)
{
var oB = what.files[oD], oB0, oB1;
if (oB.type.includes('im')) { file_p = 'img'; }
if (oB.type.includes('au')) { file_p = 'audio'; }
if (oB.type.includes('vi')) { file_p = 'video'; }
if (lastfile != what.files[oD].name || lastfilearr.length <= what.filecount)
{
oB0 = dK.children[oA];
if (oB0.nodeName.toLowerCase() == file_p && what.form.querySelectorAll(file_p)[oD] != null)
{
if ( /*oB0.getAttribute('data-src')==''&&*/ !lastfilearr.includes(what.files[oD].name))
{
oB0 = what.form.querySelectorAll(file_p)[oD];
file_prev = oB0;
lastfilearr.push(what.files[oD].name);
oB0.setAttribute('data-src', lastfile);
oB1 = new Object({
'file_prev': file_prev.id,
'file_p': file_p,
'file': what.files[oD],
'kill': kill
});
stoargearr.push(oB1);
createtoast(['Filechecker', 'the ' + what.files[oD].name + ' is getting checked.', 3e3, true, true, ['bg-info', 'text-dark', 'rounded', 'px-2', 'mx-1']]);
createItems('upload', 's', what.files[oD].name, 'name:' + what.files[oD].name + ';nr:' + oD + ';filesize:' + what.files[oD].size + ';filesizehuman:' + Math.abs(what.files[oD].size / 1024 / 1024).toFixed(2) + ';lastmodified:' + new Date(what.files[oD].lastModified).toUTCString() + ';type:' + what.files[oD].type + ';');
}
}
}
}
if (stoargearr.length == what.files.length) { waitfor(stoargearr); }
else { reader.readAsDataURL(what.files[oD]); }
}
}
}
Does the "File reader API" react different on audio files as it does on video or image files?
Thanks for any help.
here it goes.
for (var oD = 0; oD < what.files.length; oD++) {
var pL = false;
if (typeof window.dofile === 'undefined' || !window.dofile) {
return;
};
if (file_s.exec(file) && !what.multiple) {
pL = true;
} else {
if (what.files.length > what.filecount) {
alert('too many files added. only ' + what.filecount + ' are allowed.');
what.value = '';
if (quest0 != null) {
quest0.innerHTML = 'too many files added. only ' + what.filecount + ' are allowed.';
};
return;
};
pL = true;
if (!lastform.includes(what.form.id)) {
pL = false;
};
};
if (what.files && what.files[oD] && pL == true) {
if (file_prev != null) {
if (file_prev.getAttribute('data-src') == '') {
file_prev.setAttribute('data-src', file_prev.src);
};
file_prev.src = file_backsrc;
};
reader.onload = function(e) {
init();
if (typeof file_prev === 'undefined') {
if (quest1 != null) {
quest1.innerHTML = 'Error occoured';
};
return;
};
if (file_p == 'img' || file_p == 'video' || file_p == 'audio') {
file_prev.src = e.target.result;
};
if (file_p == 'canvas') { /*not yet*/ };
kill.classList.remove('invisible');
if (quest1 != null) {
quest1.innerHTML = 'file done';
};
};
reader.onerror = function(e) {
e.preventDefault();
alert('There was an error with one of your file(s). Filename ' + what.files[oD].name + '');
what.value = '';
};
function waitfor(arr) {
if (arr == null || arr.length == 0) {
return;
};
var aL = arr.length,
aL0 = arr.shift();
file_prev = _(aL0.file_prev);
lastfile = aL0.lastfile;
file_p = aL0.file_p;
reader.readAsDataURL(aL0.file);
aL0.kill.classList.add('invisible');
setTimeout(() => {
init();
waitfor(arr)
}, 1250);
if (quest1 != null) {
quest1.innerHTML = 'processing ' + file_p;
};
};
if (what.multiple) {
var oA = 0;
lastfile = what.files[oD].name;
for (oA; oA < dK.children.length; oA++) {
var oB = what.files[oD],
oB0, oB1;
if (oB.type.includes('im')) {
file_p = 'img';
};
if (oB.type.includes('au')) {
file_p = 'audio';
};
if (oB.type.includes('vi')) {
file_p = 'video';
};
if (lastfile != what.files[oD].name || lastfilearr.length <= what.filecount) {
oB0 = dK.children[oA];
if (oB0.nodeName.toLowerCase() == file_p && what.form.querySelectorAll(file_p)[oD] != null) {
if ( /*oB0.getAttribute('data-src')==''&&*/ !lastfilearr.includes(what.files[oD].name)) {
oB0 = what.form.querySelectorAll(file_p)[oD];
file_prev = oB0;
lastfilearr.push(what.files[oD].name);
oB0.setAttribute('data-src', lastfile);
oB1 = new Object({
'file_prev': file_prev.id,
'file_p': file_p,
'file': what.files[oD],
'kill': kill
});
stoargearr.push(oB1);
createtoast(['Filechecker', 'the ' + what.files[oD].name + ' is getting checked.', 3e3, true, true, ['bg-info', 'text-dark', 'rounded', 'px-2', 'mx-1']]);
createItems('upload', 's', what.files[oD].name, 'name:' + what.files[oD].name + ';nr:' + oD + ';filesize:' + what.files[oD].size + ';filesizehuman:' + Math.abs(what.files[oD].size / 1024 / 1024).toFixed(2) + ';lastmodified:' + new Date(what.files[oD].lastModified).toUTCString() + ';type:' + what.files[oD].type + ';');
};
};
};
};
if (stoargearr.length == what.files.length) {
waitfor(stoargearr);
};
} else {
reader.readAsDataURL(what.files[oD]);
};
};
};```
if (quest1 != null) {
quest1.innerHTML = 'processing ' + file_p;
};
This block gives no output on audio files.

null coalescing a JsonConvert in javascript

I have a script that looks like this
Item i = db.Items.Find(Model.ItemID);
Component comp = db.Components.Find(Model.ComponentID);
<script type="text/javascript">
function clicked(e) {
var comp = #Html.Raw(JsonConvert.SerializeObject(comp.ComponentID)) || null;
var item = #Html.Raw(JsonConvert.SerializeObject(i.ItemID)) || null;
var compFSTK = #Html.Raw(JsonConvert.SerializeObject(comp.FSTK)) || null;
var itemFSTK = #Html.Raw(JsonConvert.SerializeObject(i.FSTK)) || null;
if (item == null) {
alert('item is null');
}
if (comp == null) {
alert('comp is null');
}
if(comp != null && item == null) {
var compQty = $('#compQTY').val();
var compDiff = #Model.comp_qty - compQty;
var compFuture = compFSTK - compDiff;
if (!confirm('Are you sure? Doing this will reduce component ' + comp.ComponentID + ' future stock to ' + compFuture))e.preventDefault();
}
else if(item!== null && comp == null ) {
var itemQty = $('#itemQTY').val();
var itemDiff = #Model.item_qty - itemQty;
var itemFuture = itemFSTK - itemDiff;
if (!confirm('Are you sure? Doing this will reduce item ' + item.ItemID + ' future stock to ' + itemFuture))e.preventDefault();
}
<script>
But whenever comp or i is null and is deserialized I receive the error of 'i/comp is null'
how can I make it so that it just sets the variable to null if it is null?

Why is win undefined?

I wrote this in javascript to chat. Now I can call openChat with clicking a button and that works. But if I call it from onmessage-event, I get the
error: Uncaught TypeError: Cannot read property 'document' of
undefined
I'm new to javascript and I don't know, why I get this error?. Can somebody maybe help me?
Thanks:)
Thats the code:
var app = new Vue({
el: '#app',
data: {
busy: false,
roomId: 'POWebinar',
joinedRoom: false,
chatWirCB: false,
chatKundenCB: false,
microphoneWirCB: false,
microphoneKundenCB: false,
user: 'Benutzer',
},
methods: {
openChat: function () {
console.log("in fkt openChat");
win = window.open('', 'myconsole',
'scrollbars=1, width=450,height=500'
+ ',menubar=1'
+ ',toolbar=1'
+', location=1'
+ ',resizable=1')
win.document.writeln("<head><meta name='viewport' content='width=device-width, initial-scale=1, user-scalable=no'></head><body style='background-color:#ecf0f1'></body>");
chat = document.getElementById("chatHtml").innerHTML;
win.document.write(chat);
win.document.title = "PatOrg - Live Chat";
win.document.getElementById('input-text-chat').onkeyup = function (e) {
if (e.keyCode != 13) return;
// removing trailing/leading whitespace
this.value = this.value.replace(/^\s+|\s+$/g, '');
var a = new Date();
var b = a.getHours(); var c = a.getMinutes(); var d = a.getSeconds();
if (b < 10) { b = '0' + b; }
if (c < 10) { c = '0' + c; }
if (d < 10) { d = '0' + d; }
var time = b + ':' + c + ':' + d;
if (!this.value.length) return
console.log(this.value);
connection.send('<div id="chatSend" class="chat-OutputGET bubbleGET"> <font color="white">' + username + '(' + time + '): ' + this.value + '</font></div>');
console.log(username);
console.log('User (' + time + '): ' + this.value);
appendDIV('<div id="chatGet" class="chat-OutputSEND bubble"> <font color="white"> Ich (' + time + '): ' + this.value + '</font></div>');
this.value = '';
};
var chatContainer = win.document.getElementById('chat-output');
function appendDIV(event) {
if (event == "turnMicroOff" || event.data == "turnMicroOff" || event == "turnMicroOn" || event.data == "turnMicroOn" || event == "turnChatOn" || event.data == "turnChatOn" || event == "turnChatOff" || event.data == "turnChatOff") {
if (event == "turnMicroOff" || event.data == "turnMicroOff") {
console.log("audioID: " + audioID);
console.log("audioID: " + audioID);
for (i = 0; i < audioID.length; i++) {
connection.streamEvents[audioID[i]].stream.mute('audio');
}
}
else if (event == "turnMicroOn" || event.data == "turnMicroOn") {
console.log("audioID: " + audioID);
console.log("audioID: " + audioID);
for (i = 0; i < audioID.length; i++) {
connection.streamEvents[audioID[i]].stream.unmute('audio');
}
}
else if (event == "turnChatOn" || event.data == "turnChatOn") {
document.getElementById("btnChatOpen").style.visibility = "visible";
}
else if (event == "turnChatOff" || event.data == "turnChatOff") {
document.getElementById("btnChatOpen").style.visibility = "hidden";
}
}
else {
var div = document.createElement('div');
div.innerHTML = event.data || event;
chatContainer.appendChild(div);
div.tabIndex = 0;
div.focus();
win.document.getElementById('input-text-chat').focus();
emojify.run(win.document.getElementById('chat-output'));
}
}
connection.onmessage = appendDIV;
}
}
})
connection.onmessage = function (event) {
console.log(event.data);
if (event == "turnMicroOff" || event.data == "turnMicroOff") {
for (i = 0; i < audioID.length; i++) {
console.log("audioID: " + audioID[i]);
connection.streamEvents[audioID[i]].stream.mute('audio');
}
}
else if (event == "turnMicroOn" || event.data == "turnMicroOn") {
app.openChat();
for (i = 0; i < audioID.length; i++) {
console.log("audioID: " + audioID[i]);
connection.streamEvents[audioID[i]].stream.unmute('audio');
}
}
else if (event == "turnChatOn" || event.data == "turnChatOn") {
document.getElementById("btnChatOpen").style.visibility = "visible";
}
else if (event == "turnChatOff" || event.data == "turnChatOff") {
document.getElementById("btnChatOpen").style.visibility = "hidden";
}
}

add textarea name to document.form

Below is the function which dont work... when try to add "newTextArea" to "document.postform.nTextArea"
Can anyone help me?
function AddText(text, newTextArea) {
nTextArea = newTextArea;
var tarea = document.postform.nTextArea;
alert(nTextArea);
if (typeof tarea.selectionStart != 'undefined'){ // if it supports DOM2
start = tarea.selectionStart;
end = tarea.selectionEnd;
tarea.value = tarea.value.substr(0,tarea.selectionStart)
+ text + tarea.value.substr(tarea.selectionEnd);
tarea.focus();
tarea.selectionStart = ((start - end) == 0) ? start + text.length : start;
tarea.selectionEnd = start + text.length;
} else {
if (tarea.createTextRange && tarea.caretPos) {
var caretPos = tarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
}
else {
tarea.value += text;
}
tarea.focus(caretPos);
}
}
Assuming newTextArea is name of textarea element, the correct way to access it is with such code:
var tarea = document.postform.elements[newTextArea];
if (typeof tarea.selectionStart != 'undefined'){ // if it supports DOM2
//...
}

Categories

Resources