随笔 - 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 阅读(455) 评论(0)  编辑  收藏 所属分类: 反汇编

只有注册用户登录后才能发表评论。


网站导航: