`
icess
  • 浏览: 253409 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

decode javascript.encode using java

阅读更多

在前面一篇文章(http://www.hexiao.cn/blog/index.php?job=art&articleid=a_20060730_130422)中, 提到了 关于IE中的 js.edcode的加密问题. 由于要使用这些加密后的信息,就要解密,在网络上找了一个js版本的解密程序, 由于要在java中使用,就把他转化为java代码了, 解密js.encode的java代码如下:

 

//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
/**
 * Decode encode
 * @author icess
 * @blog http://blog.matrix.org.cn/page/icess
 */
public class EncodeDecode {
 final int STATE_COPY_INPUT = 100;

 final int STATE_READLEN = 101;

 final int STATE_DECODE = 102;

 final int STATE_UNESCAPE = 103;

 int[] digits = new int[128];

 int[][] transformed = new int[3][128];

 int[] pick_encoding = { 1, 2, 0, 1, 2, 0, 2, 0, 0, 2, 0, 2, 1, 0, 2, 0, 1,
   0, 2, 0, 1, 1, 2, 0, 0, 2, 1, 0, 2, 0, 0, 2, 1, 1, 0, 2, 0, 2, 0,
   1, 0, 1, 1, 2, 0, 1, 0, 2, 1, 0, 2, 0, 1, 1, 2, 0, 0, 1, 1, 2, 0,
   1, 0, 2 };

 int[] rawData = { 0x64, 0x37, 0x69, 0x50, 0x7E, 0x2C, 0x22, 0x5A, 0x65,
   0x4A, 0x45, 0x72, 0x61, 0x3A, 0x5B, 0x5E, 0x79, 0x66, 0x5D, 0x59,
   0x75, 0x5B, 0x27, 0x4C, 0x42, 0x76, 0x45, 0x60, 0x63, 0x76, 0x23,
   0x62, 0x2A, 0x65, 0x4D, 0x43, 0x5F, 0x51, 0x33, 0x7E, 0x53, 0x42,
   0x4F, 0x52, 0x20, 0x52, 0x20, 0x63, 0x7A, 0x26, 0x4A, 0x21, 0x54,
   0x5A, 0x46, 0x71, 0x38, 0x20, 0x2B, 0x79, 0x26, 0x66, 0x32, 0x63,
   0x2A, 0x57, 0x2A, 0x58, 0x6C, 0x76, 0x7F, 0x2B, 0x47, 0x7B, 0x46,
   0x25, 0x30, 0x52, 0x2C, 0x31, 0x4F, 0x29, 0x6C, 0x3D, 0x69, 0x49,
   0x70, 0x3F, 0x3F, 0x3F, 0x27, 0x78, 0x7B, 0x3F, 0x3F, 0x3F, 0x67,
   0x5F, 0x51, 0x3F, 0x3F, 0x3F, 0x62, 0x29, 0x7A, 0x41, 0x24, 0x7E,
   0x5A, 0x2F, 0x3B, 0x66, 0x39, 0x47, 0x32, 0x33, 0x41, 0x73, 0x6F,
   0x77, 0x4D, 0x21, 0x56, 0x43, 0x75, 0x5F, 0x71, 0x28, 0x26, 0x39,
   0x42, 0x78, 0x7C, 0x46, 0x6E, 0x53, 0x4A, 0x64, 0x48, 0x5C, 0x74,
   0x31, 0x48, 0x67, 0x72, 0x36, 0x7D, 0x6E, 0x4B, 0x68, 0x70, 0x7D,
   0x35, 0x49, 0x5D, 0x22, 0x3F, 0x6A, 0x55, 0x4B, 0x50, 0x3A, 0x6A,
   0x69, 0x60, 0x2E, 0x23, 0x6A, 0x7F, 0x09, 0x71, 0x28, 0x70, 0x6F,
   0x35, 0x65, 0x49, 0x7D, 0x74, 0x5C, 0x24, 0x2C, 0x5D, 0x2D, 0x77,
   0x27, 0x54, 0x44, 0x59, 0x37, 0x3F, 0x25, 0x7B, 0x6D, 0x7C, 0x3D,
   0x7C, 0x23, 0x6C, 0x43, 0x6D, 0x34, 0x38, 0x28, 0x6D, 0x5E, 0x31,
   0x4E, 0x5B, 0x39, 0x2B, 0x6E, 0x7F, 0x30, 0x57, 0x36, 0x6F, 0x4C,
   0x54, 0x74, 0x34, 0x34, 0x6B, 0x72, 0x62, 0x4C, 0x25, 0x4E, 0x33,
   0x56, 0x30, 0x56, 0x73, 0x5E, 0x3A, 0x68, 0x73, 0x78, 0x55, 0x09,
   0x57, 0x47, 0x4B, 0x77, 0x32, 0x61, 0x3B, 0x35, 0x24, 0x44, 0x2E,
   0x4D, 0x2F, 0x64, 0x6B, 0x59, 0x4F, 0x44, 0x45, 0x3B, 0x21, 0x5C,
   0x2D, 0x37, 0x68, 0x41, 0x53, 0x36, 0x61, 0x58, 0x58, 0x7A, 0x48,
   0x79, 0x22, 0x2E, 0x09, 0x60, 0x50, 0x75, 0x6B, 0x2D, 0x38, 0x4E,
   0x29, 0x55, 0x3D, 0x3F };

 public EncodeDecode() {
//  System.out.println(rawData[0]);
  init();
 }

 public String decode(String encodingString) {
//  System.out.println("encodingString  :  " + encodingString);
  String marker = "#@~^";
  String at;
  String encodingLable = null;
  String unEncodingString = "";
  int stringIndex = 0;
  int scriptIndex = -1;
  int unEncodingIndex = 0;
  int unEncodinglength = 0;
  int state = STATE_COPY_INPUT;
  // int statePos = 0;

  while (state != 0) {
   // System.out.println("in the Swith statePos is :" + statePos +
   // "State:" +state);
   switch (state) {
   case (STATE_COPY_INPUT):
    scriptIndex = encodingString.indexOf(marker, stringIndex);
    // System.out.println("scriptIndex1"+scriptIndex);
    if (scriptIndex != -1) {
     unEncodingString += encodingString.substring(stringIndex,
       stringIndex + scriptIndex);
     scriptIndex += marker.length();
     state = STATE_READLEN;
    } else {
     stringIndex = stringIndex == 0 ? 0 : stringIndex;
     unEncodingString += encodingString.substring(stringIndex,
       encodingString.length());
     state = 0;
    }
    break;

   case (STATE_READLEN):
    // System.out.println("scriptIndex"+scriptIndex);
    encodingLable = encodingString.substring(scriptIndex,
      scriptIndex + 6);
    unEncodinglength = decodeBase64(encodingLable);
    scriptIndex += (6 + "==".length());
    state = STATE_DECODE;
    break;

   case (STATE_DECODE):
    if (unEncodinglength == 0) {
     stringIndex = scriptIndex + "DQgAAA==^#~@".length();
     unEncodingIndex = 0;
     state = STATE_COPY_INPUT;
     break;
    }
    at = encodingString.substring(scriptIndex, scriptIndex + 1);
    if (at == "@")
     state = STATE_UNESCAPE;
    else {
     if (at.codePointAt(0) < 0xFF) {
      unEncodingString += String
        .valueOf((char) transformed[pick_encoding[unEncodingIndex % 64]][at
          .codePointAt(0)]);
      unEncodingIndex++;
     } else {
      unEncodingString += at;
     }
     scriptIndex++;
     unEncodinglength--;
     break;
    }

   case STATE_UNESCAPE:
    unEncodingString += unescape(encodingString.substring(
      ++scriptIndex, scriptIndex + 1));
    scriptIndex++;
    unEncodinglength -= 2;
    unEncodingIndex++;
    state = STATE_DECODE;
    break;
   }
  }

  // System.out.println("unEncodingString : " + unEncodingString);
  // Pattern pattern = Pattern.compile("JScript.Encode");
  // Matcher matcher = pattern.matcher(unEncodingString);
  // if(matcher.find()) {
  // System.out.println("unEncodingString 1: " + unEncodingString);
  // unEncodingString = unEncodingString.substring(0, matcher.start()) +
  // matcher.group() + unEncodingString.substring(matcher.end());
  // }

//  System.out.println("EncodeDecode.decode : unEncodingString  :  " + unEncodingString);
  return unEncodingString;
 }

 public int decodeBase64(String string) {
  int val = 0;
  val += (digits[string.codePointAt(0)] << 2);
  val += (digits[string.codePointAt(1)] >> 4);
  val += (digits[string.codePointAt(1)] & 0xf) << 12;
  val += ((digits[string.codePointAt(2)] >> 2) << 8);
  val += ((digits[string.codePointAt(2)] & 0x3) << 22);
  val += (digits[string.codePointAt(3)] << 16);
  return val;
 }

 public String unescape(String ch) { // no used, and no test
  // System.out.println("dddd");
  String escapes = "#&!*$";
  String escaped = "\r\n<>@";

  if (ch.codePointAt(0) > 126)
   return ch;
  int index = escapes.indexOf(ch);
  if (index != -1)
   return escaped.substring(index, index + 1);
  return "?";
 }

 public void init() {
  for (int i = 31; i <= 126; i++)
   for (int j = 0; j < 3; j++)
    transformed[j][rawData[(i - 31) * 3 + j]] = (i == 31) ? 9 : i;

  for (int i = 0; i < 26; i++) {
   digits['A' + i] = i;
   digits['a' + i] = i + 26;
  }
  for (int i = 0; i < 10; i++)
   digits['0' + i] = i + 52;
  digits[0x2b] = 62;
  digits[0x2f] = 63;
 }

 /**
  * @param args
  */
 public static void main(String[] args) {
  // new EncodeDecode().decode("<script
  // language='JScript.Encode'>#@~^SwAAAA==-mD~DK'B8vZfF~!0FyF/TFFFZXFR!F8)TvZc82qsq98,TfZ+!wF{T;F&q*Z2T!Z1ZAqZFl!bEiyRAAAA==^#~@</script>");
  String plantext = new EncodeDecode()
    .decode("#@~^SwAAAA==-mD~DK'B8vZfF~!0FyF/TFFFZXFR!F8)TvZc82qsq98,TfZ+!wF{T;F&q*Z2T!Z1ZAqZFl!bEiyRAAAA==^#~@");
  System.out
    .println(plantext
      .equals("var ero='16031B08121C07110518011A06041E1F1D190D020F170C13140E00090B10150A';"));
  System.out.println("0".codePointAt(0) + " " + (int) 'a' + " "
    + (int) 'A');
  
  System.out.println("ididgigggi".indexOf("i", 1));
 }

}

现在可以得到需要的信息了. 呵呵

分享到:
评论

相关推荐

    python3.6.5参考手册 chm

    The json module: JavaScript Object Notation The plistlib module: A Property-List Parser ctypes Enhancements Improved SSL Support Deprecations and Removals Build and C API Changes Port-Specific ...

    iOS json -》模型

    在iOS开发中,数据交换和存储经常涉及到JSON(JavaScript Object Notation)格式,因为它是轻量级、易于读写的数据交换格式。将JSON数据转换为iOS应用中的模型对象是常见的需求,这使得开发者能方便地处理从服务器...

    Swift与JSON:高效数据处理的秘诀

    let person = Person(name: "Jane Doe", age: 28, isEmployee: true, skills: ["Java", "Kotlin"]) do { let data = try JSONEncoder().encode(person) if let jsonString = String(data: data, encoding: .utf8) ...

    demjson-2.2.4

    **demjson-2.2.4** 是一个Python库,专为处理JSON(JavaScript Object Notation)数据格式而设计。JSON是一种轻量级的数据交换格式,因其简洁、易读、易于解析的特点,广泛应用于Web服务和应用程序之间的数据传输。...

    二维码读取和生成

    2. Web应用集成:在Web应用中,可以通过JavaScript与C#后台交互,生成二维码图片,用于下载链接、电子票务等场景。 3. 系统自动化:在企业级系统中,二维码可以作为物料、设备标识,通过C#程序自动识别和追踪。 ...

    ios-数据持久化.zip

    JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,易于人阅读和编写,同时也易于机器解析和生成。在iOS中,我们可以使用内置的`JSONSerialization`类进行JSON的编码和解码。如果数据结构符合JSON格式...

    SwiftJson.zip

    JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,广泛用于Web服务和移动应用之间的数据通信。在Swift中,我们可以使用`JSONSerialization`类的`jsonObject(with:options:)`方法将JSON数据转换为一个...

    MySQL and JSON A Practical Programming Guide 2018

    Practical instruction on using JavaScript Object Notation (JSON) with MySQL This hands-on guide teaches, step by step, how to use JavaScript Object Notation (JSON) with MySQL. Written by a MySQL ...

    Swift-model(Json文件)

    JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,易于人阅读和编写,同时也易于机器解析和生成。Swift提供了多种方法来解析和序列化JSON,让我们深入探讨一下。 首先,Swift内置了`JSON...

    php.ini-development

    recommending using the production ini in production and testing environments. ; php.ini-development is very similar to its production variant, except it's ; much more verbose when it comes to errors...

    JSON解析demo

    - `json_decode(jsonString, true)`:第二个参数设为`true`,会返回关联数组而非对象。 三、JSON的编码与解码 与解析相对应的是编码,即将数据结构转换为JSON字符串。这在发送数据到服务器或保存数据时非常有用。...

    JSON 转换工具

    JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,被广泛用于Web服务和移动应用中的数据传输。在iOS开发中,处理JSON数据是常见的任务,尤其在与服务器交互时。本文将详细介绍如何使用JSON转换工具,...

    multicodec:[JSJava]

    import { encode, decode } from 'multicodec'; /* Encodings to use: Compression (deflate) + stringify (base64) */ const format = 'deflate+base64'; /* Input data to encode */ const input = Buffer.from('...

    swift-HandyJSON是一个Swift编写的JSON-对象间序列化反序列化库用法简单

    首先,让我们理解一下JSON(JavaScript Object Notation)的概念。JSON是一种轻量级的数据交换格式,易于人阅读和编写,同时也易于机器解析和生成。在Swift中,我们通常需要将JSON数据转换为Swift对象以便操作,反之...

    JSONTesting

    JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,被广泛用于Web服务和应用程序之间的数据传输。在Swift中,由于其简洁明了的语法,JSON解析和序列化是开发过程中常见的任务。本主题将深入探讨如何在...

    json格式读写+base64加密 C++

    JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,它易于人阅读和编写,同时也易于机器解析和生成。在C++中,处理JSON通常需要第三方库,如nlohmann/json,这是一个非常流行的选择。这个库允许你方便...

    jackson_html_page_源码

    PHP有许多内置的函数,如json_encode和json_decode,用于与JSON数据交互,但如果项目使用了Jackson,那可能是因为它提供了更高级的功能,比如对象绑定、流处理或者更灵活的序列化选项。 一个单页应用程序通常利用...

    rfc-5987-encoding:根据RFC 5987进行编码

    rfc-5987编码 根据编码encode(arg) 返回具有字符集UTF-8的已编码str。 如果arg是一个对象,则str和lang属性分别用于内容和语言。 否则,将使用arg强制...decode(str) 返回具有属性str和lang的对象。 当前仅支持UTF-8。

    将新型冠状病毒转二进制的代码(首发)

    using namespace std; void outc(char c) { unsigned char k = 0x80; for(int i = 0; i ; i++, k &gt;&gt;= 1){ if(c & k){ printf("1"); }else{ printf("0"); } } printf(""); } int main(){ char str[] = ...

Global site tag (gtag.js) - Google Analytics