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.
Related
I have several html A tag generated programmatically in ASP.NET with a JavaScript function taking long parameter in href. One of those has over 20K characters when it get assigned in backend, but I am seeing the actual link has only 5239 characters on the browser side and the JavaScript function does not have closing. So the link never works. I am thinking about workarounds for this implementation since it's not a good idea to put this much amount of data in links, but now I'm just curious about cause of the issue.
Examples of the code assigning values to the link:
HtmlAnchor.HRef = "javascript:doSomething('Import','" + strHeader_LineIds + "');"
In this case the variable strHeader_LineIds carries a string over 20k characters.
Example of what I'm actually seeing in client side:
<a id=anchor1 class=class1 href="javascript:doSomething('Import', 'blahblahblahblah....">Link Text</a>
Please note the javascript function has no closing here. But when I'm debugging in backend I do see the closing of the function.
I guess this issue may have something to do with the browser's URL limit? I am using IE and I learned IE has a maximum URL length limit as 2,083 characters from Here. But how can the link show up with 5,239 characters?
I've had a similar issue with javascript like dynamic functions created in code and then called. I found that I had to play with swapping out single quotes in the javascript function with double quotes or escaping the quotes.
Then again just reading your post could be a limit issue.
Have you tried assigning the long to an element in the background and then referencing that as part of the javacript. I know IE gets funny with spaces in passed in parameters.
I think found an answer to the issue though. According to This Article:
JavaScript URIs
The JavaScript protocol is used for bookmarklets (aka favlets), a lightweight form of extensibility that permits a user to click a button and run some stored JavaScript on the currently loaded page. In IE9, the team did some work to relax the length limit (from ~260 characters, if I recall correctly) to something significantly larger (~5kb, if I recall correctly).
So I just hit the ~5kb limit.
Hy,
I have a binary array that comes from deflating a string using this library.
I want to see the contents of the array in hex in firebug's console.
It's possible to do this? If it's possible, how can I do?
Of course, I tried console.log(array) in raw_deflating.js but it shows some garbage(of course, because it's binary)
I searched a lot on net, and surprisingly no one has asked this before.
Thank you,
I'll answer to my own question, if someone will have the same question:
Unfortunately, Firebug hasn't this feature. You can't see in debugger the hex value of a variable.
But, in my particular case, I was able to see the dec value of the variables directly from JavaScript, because the char array comes from String.fromCharCode(buff[j]);.
So, if you have a byte array, you can inspect the content using JS function String.charCodeAt()
I have an application with most of the code written in javascript. I am encountering a strange problem. I have a query string and my app reads it to perform various actions. Yesterday I changed the ordering of the query string parameters and the application stopped working. If I put the original order back then it starts working. What could be the reason? I thought that the effect of ordering of parameters should not matter. But, apparently it does matter for some reason. I am still trying to dig out what can be the issue but wanted to know if any one here has encountered a similar problem?
Thanks.
A properly written application will find a given query parameter in any order and will not be order sensitive. It is possible though to have poorly written parsing code that would only find a given parameter at the beginning, at the end, or only if after some other parameter. Without seeing the code that parses the query parameters, we can't really say what problem it has, but it is possible to have poorly written code that is position-sensitive.
If you post the code that parses the query parameters and the query string that works and the one that doesn't, we could advise more specifically. You should also check to make sure that your query parameters don't have any characters in them that are supposed to be encoded that could be throwing things off.
I have seen that kind of problem when the developer used the query string, as is, as a key to a cached object. When the query string changed, the key was not the same and the cache mechanism was failing (due to another bug).
It should not be a problem. Something else causes the error. Or you have some dependencies on the location variable that contains the URL.
Is it possible to write a program to grab the online search result?
Specifically, I want the data from http://portal.uspto.gov/external/portal/pair
sample data are application numbers, for example 9078871,10595401
Yes, they have CAPTCHAs, and I'm willing to type those in by hand. The problem is I have more than 500 application numbers, what shall I do? Are there any easier way for me to do this?
Thanks in advance! Also, the search engine seems to be written in javascript, but I am not exactly sure.
Sure it is possible and why should it not.
I do not know your gap in knowledge that would enable you to archieve this task as you didn't pointed that out.
Step by Step...
Analyze the Website' s code to see how links and content are generated.
Download the source code programaticly
Generate the hyperlinks to your search results
Parse the related data (I have always done this with some ugly regular expressions)
I have digged a little bit in the site you mentioned and what really can be said is that it won't be a 1-hour action as it's writte in Java (JSP; Java Server Pages).
What I so far found out is that you first have to write an equivalent of the function getDossier or use a Webbrowser control that enables you to call javascript manually to get the search results. Then you can simply bake some regular expressions together to parse the data out of the table.
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.