吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4246|回复: 3
收起左侧

[Java 转载] 在做闪讯拨号器时,翻译代码时遇到困难,C翻JAVA,大神进来看看。代码里面有注释

  [复制链接]
Maxwu 发表于 2015-3-14 23:32
C源代码:[mw_shl_code=c,true]#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <pppd/pppd.h>
#include <pppd/md5.h>

typedef unsigned char byte;

char pppd_version[] = VERSION;

static char saveuser[MAXNAMELEN] = {0};
static char savepwd[MAXSECRETLEN] = {0};

static void getPIN(byte *userName, byte *PIN)
{
    int i,j;//循环变量
    long timedivbyfive;//时间除以五
    time_t timenow;//当前时间,从time()获得
    byte RADIUS[16];//凑位字符
    byte timeByte[4];//时间 div 5
    byte beforeMD5[32];//时间 div 5+用户名+凑位
    MD5_CTX md5;//MD5结构体
    byte afterMD5[16];//MD5输出
    byte MD501H[2]; //MD5前两位
    byte MD501[3];
    byte timeHash[4]; //时间div5经过第一次转后后的值
    byte temp[32]; //第一次转换时所用的临时数组
    byte PIN27[6]; //PIN的2到7位,由系统时间转换

    //code
    info("sxplugin : using zjxinlisx01");
    strcpy(RADIUS, "zjxinlisx01");
    timenow = time(NULL);
    timedivbyfive = timenow / 5;

    for(i = 0; i < 4; i++) {
        timeByte[i] = (byte)(timedivbyfive >> (8 * (3 - i)) & 0xFF);
    }
    for(i = 0; i < 4; i++) {
        beforeMD5[i]= timeByte[i];
    }
    for(i = 4; i < 16 && userName[i-4]!='@' ; i++) {
        beforeMD5[i] = userName[i-4];
    }
    j=0;
    while(RADIUS[j]!='\0')
        beforeMD5[i++] = RADIUS[j++];

    MD5_Init(&md5);
    MD5_Update (&md5, beforeMD5, i);
    printf("%d %s\n",i,beforeMD5);
    MD5_Final (afterMD5, &md5);
//就是这一块,翻译成JAVA时总是失败
    MD501H[0] = afterMD5[0] >> 4 & 0xF;
    MD501H[1] = afterMD5[0] & 0xF;

    sprintf(MD501,"%x%x",MD501H[0],MD501H[1]);//到这里

//我翻译的java代码
/* MD501H[0] = (char) (afterMD5[0] >> 4 & 0xF);
        MD501H[1] = (char) (afterMD5[0] & 0xF);
        byte MD1=(byte)(MD501H[0]);byte MD2=(byte)(MD501H[1]);

       String MD=String.format("%x%x",MD1,MD2);
       MD501=MD.toCharArray();*/


    for(i = 0; i < 32; i++) {
        temp[i] = timeByte[(31 - i) / 8] & 1;
        timeByte[(31 - i) / 8] = timeByte[(31 - i) / 8] >> 1;
    }

    for (i = 0; i < 4; i++) {
        timeHash[i] = temp[i] * 128 + temp[4 + i] * 64 + temp[8 + i]
            * 32 + temp[12 + i] * 16 + temp[16 + i] * 8 + temp[20 + i]
            * 4 + temp[24 + i] * 2 + temp[28 + i];
    }

    temp[1] = (timeHash[0] & 3) << 4;
    temp[0] = (timeHash[0] >> 2) & 0x3F;
    temp[2] = (timeHash[1] & 0xF) << 2;
    temp[1] = (timeHash[1] >> 4 & 0xF) + temp[1];
    temp[3] = timeHash[2] & 0x3F;
    temp[2] = ((timeHash[2] >> 6) & 0x3) + temp[2];
    temp[5] = (timeHash[3] & 3) << 4;
    temp[4] = (timeHash[3] >> 2) & 0x3F;

    for (i = 0; i < 6; i++) {
        PIN27[i] = temp[i] + 0x020;
        if(PIN27[i]>=0x40) {
            PIN27[i]++;
        }
    }

    PIN[0] = '\r';
    PIN[1] = '\n';

    memcpy(PIN+2, PIN27, 6);

    PIN[8] = MD501[0];
    PIN[9] = MD501[1];

    strcpy(PIN+10, userName);
}


发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| Maxwu 发表于 2015-3-15 10:06
为什么没有人啊。。。。。。
 楼主| Maxwu 发表于 2015-3-15 10:05
[Java] 纯文本查看 复制代码
package cn.zjun.rucksack;
import java.util.Date;
public class GetPIN {
	 String username;
     String password;
     
	public String getPIN(char[] userName,char[] PIN)
     {

    	 
         //var
         int i,j = 0;//循环变量
         long timedivbyfive;//时间除以五 
         long timenow ; //当前时间,从time()获得 
         char[] RADIUS = new char[16];//凑位字符 
         char[] timeByte = new char[4];//时间 div 5 
         char[] beforeMD5 = new char[32];//时间 div 5+用户名+凑位 
         //MD5_CTX md5;//MD5结构体 
         char[] afterMD5 = new char[16];//MD5输出
         char[] MD501H = new char[2]; //MD5前两位
         char[] MD501 = new char[3];
         char[] timeHash = new char[4]; //时间div5经过第一次转后后的值
         char[] temp = new char[32]; //第一次转换时所用的临时数组
         char[] PIN27 = new char[6]; //PIN的2到7位,由系统时间转换

         //code
         String s = "zjxinlisx01";
         RADIUS = s.toCharArray();

         Date dt= new Date();
         timenow=  dt.getTime()/ 1000; //得到1970年的时间戳获取秒数
         timedivbyfive = timenow / 5;
         
         for (i = 0; i < 4; i++)
         {
             timeByte[i] = (char) (timedivbyfive >> (8 * (3 - i)) & 0xFF);
         }

         for (i = 0; i < 4; i++)
         {
             beforeMD5[i] = timeByte[i];
         }
         for (i = 4; i < 16; i++)
         {
             beforeMD5[i] = userName[i - 4];
         }
         while(j<RADIUS.length)
             beforeMD5[i++] = RADIUS[j++];


         Md5 m=new Md5();
        afterMD5=(m.MD5(beforeMD5.toString())).toCharArray();

       int MD5 =( afterMD5[0] >> 4 )& 0xF;
       int  MDH = afterMD5[0] & 0xF;
        //byte MD1=(byte)(MD501H[0]);byte MD2=(byte)(MD501H[1]);

       String MD=String.format("%x%x",MD5,MDH);
       MD501=MD.toCharArray();

         for (i = 0; i < 32; i++)
         {
             temp[i] = (char)(timeByte[(31 - i) / 8] & 1);
             timeByte[(31 - i) / 8] = (char)(timeByte[(31 - i) / 8] >> 1);
         }

         for (i = 0; i < 4; i++)
         {
             timeHash[i] = (char)(temp[i] * 128 + temp[4 + i] * 64 + temp[8 + i]
                 * 32 + temp[12 + i] * 16 + temp[16 + i] * 8 + temp[20 + i]
                 * 4 + temp[24 + i] * 2 + temp[28 + i]);
         }

         temp[1] = (char)((timeHash[0] & 3) << 4);
         temp[0] = (char)((timeHash[0] >> 2) & 0x3F);
         temp[2] = (char)((timeHash[1] & 0xF) << 2);
         temp[1] = (char)((timeHash[1] >> 4 & 0xF) + temp[1]);
         temp[3] = (char)(timeHash[2] & 0x3F);
         temp[2] = (char)(((timeHash[2] >> 6) & 0x3) + temp[2]);
         temp[5] = (char)((timeHash[3] & 3) << 4);
         temp[4] = (char)((timeHash[3] >> 2) & 0x3F);

         for (i = 0; i < 6; i++)
         {
             PIN27[i] = (char)(temp[i] + 0x020);
             if (PIN27[i] >= 0x40)
             {
                 PIN27[i]++;
             }
         }

		PIN[0] = '\r';
		PIN[1] = '\n';

		//System.arraycopy(PIN,2,PIN27,0,6);
       for(j=0;j<=5;j++){
    	   PIN[j+2]=PIN27[j];
       }

         PIN[8] = MD501[0];
         PIN[9] = MD501[1];
         
         for(j=0;j<userName.length;j++){
      	   PIN[j+10]=userName[j];
         }

         return new String(PIN);
     }
	
 }




附上我翻译的JAVA代码
975556036 发表于 2015-3-19 14:27
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-23 22:43

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表