views:

131

answers:

2

I'm download web page and parse javascript code, which have in code hash and java decode function... please I want to call javascript decode method from C# program...

In web page I've :

window.decoded_hashes = {};
window.decodehash = function(hash) {
  window.dec_hash(hash);
  return window.decoded_hashes[hash];
window.dec_hash = function(hash) {
  (function(__){window.decoded_hashes[hash] = _(__,8,_____(__)-12)+_(__,0,5);})((function(__){____='';for(___=0;___<_____(__);++___)____+=______(__,_____(__)-___-1);return window[_______(88,11,-13)]?__:____;})((function(__){____=window[_______(103,-2)]?'':'____';for(___=0;___<_____(__);++___)____+=(function(__){return __>111?(121-__):_______(__);})(__.charCodeAt(___));return ____;})((function(__){_______=function(){var _='',__=0,___=arguments;for(var ____=0;____<___.length;++____)_+=String.fromCharCode(__+=___[____]);return _;};______=function(__,___){return __.charAt(___);};_____=function(__){return __.length;};____=(_=function(_,__,___){____='';(___=___?___:(_____(_)-__));for(;___;--___)____+=(function(_,__){return ______(_,__)})(_,__++);return ____;})(__,3,3);____+=_(__,0,2)+_(__,8);return ____;})(hash))));
}


window.wall_post_hash = decodehash('tsucuqtyqvedvvpruuqasavdpwdcxafcystrdfvsyd');

And I must sent decode hash on server... hash in () - dinamic

How to make easier? I've found Rhino and IKVM, but have not understood yet...

Give me advice Pls...

Sorry for my English;)

A: 

You could include Microsoft.JScript in your project references.

Check out an example from Rick Strahl's on how you can use Eval to get your results.

Here's an implementation I managed to work out after some debugging and changes. It returns the same result as your example. One issue is that .Net don't seem to work with the function "arguments" variable. So I added 5 variables to that function to get it to work. Seems the most which is passed is 3.

package Pack
{
    class JSEval
    {        
        public function MyEval(inputhash : String) : String
        {
            var ___ = 0;
            var _= '';
            var ____ = '';
            var _______;
            var ______;
            var _____;


            var ____ = (_ = function(_, __, ___) {
                ____ = '';
                (___ = ___ ? ___ : (_____(_) - __));
                for (; ___; --___) ____ += (function(_, __) {
                    return ______(_, __)
                })(_, __++);
                return ____;
            })                

            var mywin = new Object();
            mywin.decoded_hashes = {};
            mywin.dec_hash = function(hash) {
            (function(__) {
                mywin.decoded_hashes[hash] = _(__, 8, _____(__) - 12) + _(__, 0, 5);
            })((function(__) {
                var ____ = '';
                for (___ = 0; ___ < _____(__); ++___) ____ += ______(__, _____(__) - ___ - 1);
                return mywin[_______(88, 11, -13)] ? __ : ____;
            })((function(input) {
                var res = mywin[_______(103, -2)] ? '' : '____';

                for (var i = 0; i < _____(input); ++i) res += (function(input) {
                    return input > 111 ? (121 - input) : _______(input);
                })(input.charCodeAt(i));                
                return res;
            })((function(__) {
                _______ = function(a,b,c,d,e) {                    
                    var arguments = new Array();
                    if( a != undefined )
                        arguments.push(a);
                    if( b != undefined )
                        arguments.push(b);
                    if( c != undefined )
                        arguments.push(c);
                    if( d != undefined )
                        arguments.push(d);
                    if( e != undefined )
                        arguments.push(e);
                    var _ = '';
                    var __ = 0;
                    for (var i = 0; i < arguments.length; ++i) _ += String.fromCharCode(__ += arguments[i]);
                    return _;
                };
                ______ = function(__, ___) {
                    return __.charAt(___);
                };
                _____ = function(__) {
                    return __.length;
                };
                ____ = (_ = function(_, __, ___) {
                    ____ = '';
                    (___ = ___ ? ___ : (_____(_) - __));
                    for (; ___; --___) ____ += (function(_, __) {
                        return ______(_, __)
                    })(_, __++);
                    return ____;
                })(__, 3, 3);

                ____ += _(__, 0, 2) + _(__, 8);
                return ____;
            })(hash))));
        }
        mywin.decodehash = function(hash) {
            mywin.dec_hash(hash);
            return mywin.decoded_hashes[hash];
        }


        return mywin.decodehash(inputhash);                
        }
    }
}
Mikael Svenson
A: 

thx, but when I use this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JSEval;


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void but1_Click(object sender, EventArgs e)
        {
        JSEval.JSEval eval = new JSEval.JSEval();
        string expression, result;
        expression = textBox2.Text;
        try
        {
            result = eval.Eval(expression).ToString();
        }
        catch
        {
            result = "Error";
        }

        textBox3.Text = result;

        }
    }
}

and dll with:

package JSEval
{
    class JSEval
    {
        public function Eval(hash : String) : String
        {
         var hash = 'vbqaosvnwqncbrbusvtwavowtwutnqsvddaceeuppq';
      var ___;
      var _;
      var ____;
      var _____;
      var ______;
      var __;
            var z=function(hash) {return (function(__){return _(__,8,_____(__)-12)+_(__,0,5);})((function(__){____='';for(___=0;___<_____(__);++___)____+=______(__,_____(__)-___-1);return ____;})((function(__){____='';for(___=0;___<_____(__);++___)____+=(function(__){return __>109?(119-__):String.fromCharCode(__);})(__.charCodeAt(___));return ____;})((function(__){______=function(__,___){return __.charAt(___);};_____=function(__){return __.length;};____=(_=function(_,__,___){____='';(___=___?___:(_____(_)-__));for(;___;--___)____+=(function(_,__){return ______(_,__)})(_,__++);return ____;})(__,3,3);____+=_(__,0,2)+_(__,8);return ____;})(hash))));}
      return z;
     }
    }
}

why program return me in (textBox3.Text):

function(hash) {return (function(__){return _(__,8,_____(__)-12)+_(__,0,5);})((function(__){____='';for(___=0;___<_____(__);++___)____+=______(__,_____(__)-___-1);return ____;})((function(__){____='';for(___=0;___<_____(__);++___)____+=(function(__){return __>109?(119-__):String.fromCharCode(__);})(__.charCodeAt(___));return ____;})((function(__){______=function(__,___){return __.charAt(___);};_____=function(__){return __.length;};____=(_=function(_,__,___){____='';(___=___?___:(_____(_)-__));for(;___;--___)____+=(function(_,__){return ______(_,__)})(_,__++);return ____;})(__,3,3);____+=_(__,0,2)+_(__,8);return ____;})(hash))));}

Or I do this not correctly?

Dangeroot
Change return z; to return z(hash);But your variables _, __ etc are not declared so you will get an error when you run this. Also, you shouldn't declare "hash" inside your jscript code, but use the one passed into the function.
Mikael Svenson
I'm Change return z(hash); and delete var hash... And rebuild dll... In textbox2 write my hash.... -> TextBox3 Error :(
Dangeroot
On web page this variables _, etc in JS not declared too...
Dangeroot
I'm tested this:var ___=0;var _;var ____='';var _____='';var ______;var __=0;2,5 variables it's functions Command promt haven't errors
Dangeroot
Do you have a link with the original script?
Mikael Svenson
No, it's private site:(
Dangeroot
This hash is necessary for sending post q... Probably to work with page as in a browser? That JavaScript it would be processed by it...
Dangeroot
Did my code work for you, if so accept my answer.
Mikael Svenson