隨筆 - 1  文章 - 37  trackbacks - 0
          <2008年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          留言簿(16)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          test

          搜索

          •  

          最新評論

           

          解密

          目前可用的加密版本有Delphi, VB, C++, C#,比較簡單,直接移植為JAVA語法就可以了

          C#移植過來的版本:
          public static byte[] Base64Decode(byte[] source) {

                  
          byte[] a1, a2;
                  a1 
          = source;
                  a2 
          = new byte[a1.length * 3 / 4];

                  
          for (int i = 0; i < a1.length; i++{
                      a1[i] 
          = (byte) (a1[i] - 0x3c);
                  }


                  
          for (int i = 0, k = a1.length / 4; i < k; i++{
                      a2[i 
          * 3= (byte) ((byte) (a1[i * 4<< 2+ (byte) (a1[i * 4 + 1>> 4));
                      a2[i 
          * 3 + 1= (byte) ((byte) (a1[i * 4 + 1<< 4+ (byte) (a1[i * 4 + 2>> 2));
                      a2[i 
          * 3 + 2= (byte) ((byte) (a1[i * 4 + 2<< 6+ a1[i * 4 + 3]);
                  }

                  
          if (a2.length % 3 == 2{
                      a2[a2.length 
          - 2= (byte) ((byte) (a1[a1.length - 3<< 2+ (byte) (a1[a1.length - 2>> 4));
                      a2[a2.length 
          - 1= (byte) ((byte) (a1[a1.length - 2<< 4+ (byte) (a1[a1.length - 1>> 2));
                  }
           else if (a2.length % 3 == 1)
                      a2[a2.length 
          - 1= (byte) ((byte) (a1[a1.length - 2<< 2+ (byte) (a1[a1.length - 1>> 4));

                  
          return a2;
              }

          C++移植過來的代碼:
          public static byte[] fnDecode6BitBuf(byte[] source) {
                  
          byte[] pszSrc = source;
                  
          byte[] pszDest = new byte[pszSrc.length * 3 / 4];
                  
          int nDestLen = pszDest.length;
                  
          int nLen = pszSrc.length;
                  
          int nDestPos = 0;
                  
          int nBitPos = 2;
                  
          int nMadeBit = 0;
                  
          byte ch;
                  
          byte chCode;
                  
          byte tmp = 0;

                  
          for (int i = 0; i < nLen; i++{
                      
          if ((pszSrc[i] - 0x3c>= 0)
                          ch 
          = (byte) (pszSrc[i] - 0x3c);
                      
          else {
                          nDestPos 
          = 0;
                          
          break;
                      }


                      
          if (nDestPos >= nDestLen)
                          
          break;

                      
          if ((nMadeBit + 6>= 8{
                          chCode 
          = (byte) (tmp | ((ch & 0x3f>> (6 - nBitPos)));
                          pszDest[nDestPos
          ++= (byte) chCode;

                          nMadeBit 
          = 0;

                          
          if (nBitPos < 6)
                              nBitPos 
          += 2;
                          
          else {
                              nBitPos 
          = 2;
                              
          continue;
                          }

                      }


                      tmp 
          = (byte) ((ch << nBitPos) & decode6BitMask[nBitPos - 2]);

                      nMadeBit 
          += (8 - nBitPos);
                  }

                  
          return pszDest;
              }


          解密

          解密的版本也是眾多,但是均不可直接移植,java的byte范圍最大只支持到128,超過128則取反(負),位移運算時需要考慮到補碼,C#或C++的版本中的位運算將不能正確解密
          以下是JAVA的解密方法
          public static byte[] Base64Encode(byte[] source) {
                  
          byte[] a1, a2;
                  a1 
          = source;
                  
          if (a1.length % 3 == 0)
                      a2 
          = new byte[a1.length * 4 / 3];
                  
          else
                      a2 
          = new byte[a1.length * 4 / 3 + 1];

                  
          for (int i = 0, k = a1.length / 3; i < k; i++{
                      a2[i 
          * 4= (byte) (((a1[i * 3>> 2& 0x3F+ 0x3c);
                      a2[i 
          * 4 + 1= (byte) (((((a1[i * 3<< 4& 0x3f)) | ((a1[i * 3 + 1>> 4& 0x0f)) + 0x3c);
                      a2[i 
          * 4 + 2= (byte) ((((a1[i * 3 + 1<< 2& 0x3f| ((a1[i * 3 + 2>> 6& 0x03)) + 0x3c);
                      a2[i 
          * 4 + 3= (byte) ((a1[i * 3 + 2& 0x3f+ 0x3c);
                  }


                  
          if (a1.length % 3 == 1){
                      a2[a2.length 
          - 2= (byte) (((a1[a1.length - 1>> 2& 0x3F+ 0x3c);
                      a2[a2.length 
          - 1= (byte) (((a1[a1.length - 1<< 4& 0x3F+ 0x3c);
                  }

                  
          else if (a1.length % 3 == 2)
                      a2[a2.length 
          - 1= (byte) ((byte) (a1[a1.length - 1<< 4>> 2);
                  
                  
          for (int i = 0; i < a2.length; i++{
                      System.out.println(
          "a2["+i+"] - "+a2[i]);
                  }

                  
          return a2;
              }



          數據結構

          typedef struct tag_TDEFAULTMESSAGE
          {
              
          int        nRecog;
              WORD    wIdent;
              WORD    wParam;
              WORD    wTag;
              WORD    wSeries;
          }
           _TDEFAULTMESSAGE, *_LPTDEFAULTMESSAGE;

          這是前12個字節的結構定義,字節數分別為 4,2,2,2,2,分別對應封包的前12個字節
          從后往前的順序重排字節組成對應數據,例如下面代碼獲得 nRecog

          nRecogBuffer.append(PacketEncode.byte2Hex(commandByte[3]));
                  nRecogBuffer.append(PacketEncode.byte2Hex(commandByte[
          2]));
                  nRecogBuffer.append(PacketEncode.byte2Hex(commandByte[
          1]));
                  nRecogBuffer.append(PacketEncode.byte2Hex(commandByte[
          0]));




           

          posted on 2008-05-19 20:44 Phrancol Yang 閱讀(469) 評論(0)  編輯  收藏 所屬分類: 反匯編

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 军事| 泗阳县| 布拖县| 阿拉善右旗| 乐安县| 漯河市| 磴口县| 本溪市| 尚义县| 铜山县| 玛纳斯县| 常熟市| 陆川县| 彰武县| 乐清市| 永丰县| 永定县| 盘锦市| 张北县| 青田县| 阿鲁科尔沁旗| 高安市| 廊坊市| 盐津县| 万盛区| 平江县| 扎鲁特旗| 迭部县| 南乐县| 松桃| 浠水县| 隆尧县| 阿克苏市| 通渭县| 丹寨县| 宣城市| 福海县| 南城县| 儋州市| 凌海市| 乌拉特中旗|