Strange result when reading data from browser cache - javascript

In an experimental extension I am working on I use a function to get the source of a webpage and assign it to a variable. It worked perfectly fine. However I want to change the way it works and get the content from a txt file.
I am hosting a txt file like: http//1.2.3.4/1.txt.
What I want is to assign the contents of this txt file to a variable.
Function is here: http://jsfiddle.net/qumsm/.
(Function is not mine. I got it from another extension xpi which I cant remember right now. Respects to the coder of it.)
The function produces "ÿþP" this result which I dont get.

That's a byte order mark, the file you are looking at seems to be using UTF-16 LE encoding. You need to use nsIConverterInputStream instead of nsIScriptableInputStream when reading in that data and specify the correct encoding to convert from. nsIScriptableInputStream is only useful when reading in ANSI data, not Unicode. See code example on MDN.

Related

Extracting a C# Embedded Resource in JavaScript

I'm trying to extract an embedded resource from a .exe file. I can easily get the embedded resource out from C# code like so:
string changeLog;
/* Get the changelog embedded resource */
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SIPBandVoIPClient.CHANGELOG.md"))
using (var reader = new StreamReader(stream))
{
changeLog = reader.ReadToEnd();
}
However, now I'm trying to get the embedded resource out from JavaScript/nodeJS.
I tried just 'grepping' for some of the text that I knew was in the file, but I couldn't find it. Perhaps it's base64 encoded?
Edit: I tried embedding the resource in a different way - by using the properties section in Visual Studio, instead of adding the file to the project, and marking it as a resource.
Now, I can access it like so:
string changeLog = Encoding.UTF8.GetString(Resources.CHANGELOG);
Furthermore, I can find the text verbatim in the .exe. Before the text, there is some (binary?) data like this:
(Apologies for the screenshot, the text itself would not render nicely due to non printable characters, I assume)
I'm wondering if there's a way to convert this from whatever binary rubbish it is to a tag I can use to search the .exe. I could of course search for the "All notable changes to this project..." and back up a bit, but it seems a bit error prone. Would also be handy to know where to stop accurately.
I did consider using the node-ffi module, and hooking up to the Windows Api functions, however, this would be Windows only, and I think I need Linux support.

js files are loading in unreadable format

I was working on a Web App. I used a "✗" UTF-8 character as a delete button. Eclipse asked me to save file in UTF-8 format i told yes. Everything worked fine. But next day when i ran the app again it is throwing exception "Uncaught SyntaxError: Unexpected token ILLEGAL". When i checked it, all javascript file is loading in unreadable format. See image below.
I tried to replace that character with its UNICODE "✗" and saved all js files in default encoding, but didn't help.
Do anyone know why is this happening?
It sounds like you saved in a different text format than you loaded it and/or loaded it in a different text format that you saved it. Without recommending a tool, I would see if you can use something to change the code-page/text-format and then try stuff.
However, seeing as what you are showing on teh screen is 3rd part stuff, you could just more easily re-download it where you got it the first time, or perhaps unpack it if you saved the installer/zip-file.

Unable to debug an encodded javascript?

I’m having some problems debugging an encoded javacscript. This script I’m referring to given in this link over here.
The encoding here is simple and it works by shifting the unicodes values to whatever Codekey was use during encoding. The code that does the decoding is given here in plain English below:-
<script language="javascript">
function dF(s){
var s1=unescape(s.substr(0,s.length-1)); var t='';
for(i=0;i<s1.length;i++)t+=String.fromCharCode(s1.charCodeAt(i)-s.substr(s.length- 1,1));
document.write(unescape(t));
}
</script>
I’m interested in knowing or understanding the values (e.g s1,t). Like for example when the value of i=0 what values would the following attributes / method would hold
s1.charCodeAt(i) and s.substr(s.length-1,1)
The reason I’m doing this is to understand as to how a CodeKey function really works. I don’t see anything in the code above which tells it to decode on the basis of codekey value. The only thing I can point in the encoding text is the last character which is set to 1 , 2 ,3 or 4 depending upon the codekey selected during encoding process. One can verify using the link I have given above.
However, to debug, I’m using firebug addon with the script running as localhost on my wamp server. I’m able to put a breakpoint on the js using firebug but I’m unable to retrieve any of the user defined parameters or functions I mentioned above.
I want to know under this context what would be best way to debug this encoded js.

How to access a document.doc and .txt modify the content using javascript

Is it possible to access the .doc files and update in that document using javascript .
Thanks
I don't believe you can do this, for one .doc isn't stored in a format JavaScript can easily interpret...and I'm unaware of anyone ever taking the effort to port the .doc format to JavaScript. If it was possible, the library would need to edit it in memory and upload it again in some other format, base64 encoded perhaps?
In any case this is no small project, it's a huge effort and I've never seen anything close. That being said, there are alternatives depending on your exact needs, for example these guys do a browser implementation: http://www.textcontrol.com/en_US/products/dotnet/overview/
I'm not sure if there are others, and I haven't personally used theirs, but maybe that'll put you on the right track to finding the client solution you're after.
You used to be able to do this with ActiveX objects in IE. Probably still can. Code looked something like this:
var word = new ActiveXObject("Word.Application");
word.Visible = true;
// ...
See the reference for word's object model.

how do I download a file and then turn it into a base64 bit array?

This may seem like a silly question but here we go.
So all over the stacks I see stuff about bit arrays, but suppose I have the given link: https://files.parsetfss.com/aa780683-47b2-4d25-96f6-aff80a7daba2/tfss-6c5ff0d3-9336-4ab3-be4a-22d8371d5093-picture.jpg
The link listed above is an encrypted image file. I need to get the file from that location and then convert it into a base64 bitarray so I can then pass it to my decryptor.
Is there a good library for doing this? If so what is it, also. How do I download the file and then pass it? This may be kind of trivial, but until recently I have only done very basic javascript to display a message, not do download and manipulate its contents.

Categories

Resources