隨筆 - 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)  編輯  收藏 所屬分類: 反匯編

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


          網站導航:
           
          主站蜘蛛池模板: 东阳市| 平罗县| 出国| 长春市| 克什克腾旗| 永昌县| 高安市| 亚东县| 砀山县| 洮南市| 东光县| 手机| 蕉岭县| 图们市| 昌江| 北海市| 郸城县| 凯里市| 凤台县| 武山县| 平顺县| 信丰县| 炉霍县| 鲜城| 开原市| 莒南县| 淅川县| 宣恩县| 大渡口区| 虹口区| 铁力市| 延吉市| 文成县| 寿阳县| 班戈县| 丰顺县| 旺苍县| 灌南县| 延边| 胶州市| 清涧县|