JNIEXPORT jstring JNICALL Java_com_dx_core_DxCore_getFingerPrint(JNIEnv *env, jobject, jint ptr, jbyteArray data, jint pos, jint len) { DxCore *dx = (DxCore *) ptr; u8 *in = (u8 *) (env->GetByteArrayElements(data, NULL)); u8 sha[UUID_LEN]; dx->sub_12FC(in, len, sha); env->ReleaseByteArrayElements(data, (jbyte *) in, 0); u8 result[UUID_LEN + 2]; dx->encode(sha, result, UUID_LEN); char str[sizeof(result) * 2 + 1]; HexToStr(result, sizeof(result), str); return env->NewStringUTF(str); }
int main(int argc, char* argv[]) { #ifdef _WIN32 if (argc != 4) { Usage(); return 0; } string sWildCharPathName = argv[1]; string sInputType = argv[2]; string sInput = argv[3]; // vPathName vector<string> vPathName; GetTableList(sWildCharPathName, vPathName); #else if (argc < 4) { Usage(); return 0; } string sInputType = argv[argc - 2]; string sInput = argv[argc - 1]; // vPathName vector<string> vPathName; GetTableList(argc, argv, vPathName); #endif if (vPathName.size() == 0) { printf("no rainbow table found\n"); return 0; } // fCrackerType, vHash, vUserName, vLMHash bool fCrackerType; // true: hash cracker, false: lm cracker vector<string> vHash; // hash cracker vector<string> vUserName; // lm cracker vector<string> vLMHash; // lm cracker vector<string> vNTLMHash; // lm cracker if (sInputType == "-h") { fCrackerType = true; string sHash = sInput; if (NormalizeHash(sHash)) vHash.push_back(sHash); else printf("invalid hash: %s\n", sHash.c_str()); } else if (sInputType == "-l") { fCrackerType = true; string sPathName = sInput; vector<string> vLine; if (ReadLinesFromFile(sPathName, vLine)) { int i; for (i = 0; i < vLine.size(); i++) { string sHash = vLine[i]; if (NormalizeHash(sHash)) vHash.push_back(sHash); else printf("invalid hash: %s\n", sHash.c_str()); } } else printf("can't open %s\n", sPathName.c_str()); } else if (sInputType == "-f") { fCrackerType = false; string sPathName = sInput; LoadLMHashFromPwdumpFile(sPathName, vUserName, vLMHash, vNTLMHash); } else { Usage(); return 0; } if (fCrackerType && vHash.size() == 0) return 0; if (!fCrackerType && vLMHash.size() == 0) return 0; // hs CHashSet hs; if (fCrackerType) { int i; for (i = 0; i < vHash.size(); i++) hs.AddHash(vHash[i]); } else { int i; for (i = 0; i < vLMHash.size(); i++) { hs.AddHash(vLMHash[i].substr(0, 16)); hs.AddHash(vLMHash[i].substr(16, 16)); } } // Run CCrackEngine ce; ce.Run(vPathName, hs); // Statistics //printf("statistics\n"); //printf("-------------------------------------------------------\n"); //printf("plaintext found: %d of %d (%.2f%%)\n", hs.GetStatHashFound(), // hs.GetStatHashTotal(), // 100.0f * hs.GetStatHashFound() / hs.GetStatHashTotal()); //printf("total disk access time: %.2f s\n", ce.GetStatTotalDiskAccessTime()); //printf("total cryptanalysis time: %.2f s\n", ce.GetStatTotalCryptanalysisTime()); //printf("total chain walk step: %d\n", ce.GetStatTotalChainWalkStep()); //printf("total false alarm: %d\n", ce.GetStatTotalFalseAlarm()); //printf("total chain walk step due to false alarm: %d\n", ce.GetStatTotalChainWalkStepDueToFalseAlarm()); //printf("\n"); // Result //printf("result\n"); //printf("-------------------------------------------------------\n"); if (fCrackerType) { int i; for (i = 0; i < vHash.size(); i++) { string sPlain, sBinary; if (!hs.GetPlain(vHash[i], sPlain, sBinary)) { sPlain = "<notfound>"; sBinary = "<notfound>"; } //printf("%s %s hex:%s\n", vHash[i].c_str(), sPlain.c_str(), sBinary.c_str()); } } else { int i; for (i = 0; i < vLMHash.size(); i++) { string sPlain1, sBinary1; bool fPart1Found = hs.GetPlain(vLMHash[i].substr(0, 16), sPlain1, sBinary1); if (!fPart1Found) { sPlain1 = "<notfound>"; sBinary1 = "<notfound>"; } string sPlain2, sBinary2; bool fPart2Found = hs.GetPlain(vLMHash[i].substr(16, 16), sPlain2, sBinary2); if (!fPart2Found) { sPlain2 = "<notfound>"; sBinary2 = "<notfound>"; } string sPlain = sPlain1 + sPlain2; string sBinary = sBinary1 + sBinary2; // Correct case if (fPart1Found && fPart2Found) { unsigned char NTLMHash[16]; int nHashLen; ParseHash(vNTLMHash[i], NTLMHash, nHashLen); if (nHashLen != 16) printf("debug: nHashLen mismatch\n"); string sNTLMPassword; if (LMPasswordCorrectCase(sPlain, NTLMHash, sNTLMPassword)) { sPlain = sNTLMPassword; sBinary = HexToStr((const unsigned char*)sNTLMPassword.c_str(), sNTLMPassword.size()); } else printf("case correction for password %s fail!\n", sPlain.c_str()); } // Display //printf("%-14s %s hex:%s\n", vUserName[i].c_str(), // sPlain.c_str(), // sBinary.c_str()); } } return 0; }
void CChainWalkSet::StoreToFile(uint64_t* pIndexE, unsigned char* pHash, int nHashLen) { if (debug) printf("\nDebug: Storing precalc\n"); std::string sCurrentPrecalcPathName = CheckOrRotatePreCalcFile(); std::string sCurrentPrecalcIndexPathName = sCurrentPrecalcPathName + ".index"; FILE* fp = fopen(sCurrentPrecalcPathName.c_str(), "ab"); if(fp!=NULL) { if(fwrite(pIndexE, sizeof(uint64_t), (unsigned long)m_nRainbowChainLen-1, fp) != (unsigned long)m_nRainbowChainLen-1) printf("File write error."); else { FILE* file = fopen(sCurrentPrecalcIndexPathName.c_str(), "a"); if (file!=NULL) { char precalculationLine[255]; sprintf(precalculationLine, "%s_%d_%d:%s\n", m_sHashRoutineName.c_str(), m_nRainbowTableIndex, m_nRainbowChainLen, HexToStr(pHash, nHashLen).c_str() ); fputs (precalculationLine, file); fclose (file); } } fclose(fp); } else printf("Cannot open precalculation file %s\n", sCurrentPrecalcPathName.c_str()); }
bool CChainWalkSet::FindInFile(uint64_t* pIndexE, unsigned char* pHash, int nHashLen) { //This is useless because we have a new BIN every file. //Potential for speedup across tables of the same BIN, but later. return false; int gotPrecalcOnLine = -1; char precalculationLine[255]; sprintf(precalculationLine, "%s_%d_%d:%s\n", m_sHashRoutineName.c_str(), m_nRainbowTableIndex, m_nRainbowChainLen, HexToStr(pHash, nHashLen).c_str() ); std::string precalcString(precalculationLine); std::string sCurrentPrecalcPathName = ""; std::string sCurrentPrecalcIndexPathName = ""; long unsigned int offset = 0; int i; for (i = 0; i < (int)vPrecalcFiles.size() && gotPrecalcOnLine == -1; i++) { sCurrentPrecalcPathName = vPrecalcFiles[i]; sCurrentPrecalcIndexPathName = sCurrentPrecalcPathName + ".index"; offset = 0; std::vector<std::string> precalcLines; if (ReadLinesFromFile(sCurrentPrecalcIndexPathName.c_str(), precalcLines)) { int j; for (j = 0; j < (int)precalcLines.size(); j++) { if (precalcString.compare(0, precalcString.size()-1, precalcLines[j]) == 0) { gotPrecalcOnLine = j; break; } // Parse std::vector<std::string> vPart; if (SeperateString(precalcLines[j], "__:", vPart)) { //0 is hashroutine //1 is index //2 is offset //3 is hash // add to offset offset += ((atoi(vPart[2].c_str())-1) * sizeof(uint64_t)); } else { // corrupt file printf("Corrupted precalculation file!\n"); std::cout<< "filename is " <<precalcLines[j] << std::endl; gotPrecalcOnLine = -1; break; } } } } if (gotPrecalcOnLine > -1) { // if (debug) // { // std::cout << "Debug: Reading pre calculations from file, line " // << gotPrecalcOnLine << " offset " << offset << std::endl; // } FILE* fp = fopen(sCurrentPrecalcPathName.c_str(), "rb"); if (fp!=NULL) { fseek(fp, offset, SEEK_SET); // We should do some verification here, for example by recalculating the middle chain, to catch corrupted files if(fread(pIndexE, sizeof(uint64_t), (unsigned long)m_nRainbowChainLen-1, fp) != (unsigned long)m_nRainbowChainLen-1) { std::cout << "Error reading " << sCurrentPrecalcPathName << std::endl; } fclose(fp); } else { std::cout << "Cannot open precalculation file " << sCurrentPrecalcPathName << "." << std::endl; } //printf("\npIndexE[0]: %s\n", uint64tostr(pIndexE[0]).c_str()); //printf("\npIndexE[nRainbowChainLen-2]: %s\n", uint64tostr(pIndexE[m_nRainbowChainLen-2]).c_str()); return true; } return false; }
std::string evalute::evalute_b2Fixture(Watch* watch) { std::string name = watch->MemberName; std::string result = ""; b2Fixture* m = boost::get<b2Fixture*>(watch->Object); std::string shapeTypePrefix = "", shapeVetexCountPrefix = "", shapeVerticesPrefix = "", shapeRadiusPrefix = "", shapeCenterPrefix = ""; bool shape = false; b2Shape* xshape = m->GetShape(); if(name == "Shape") { result += "{ "; shape = true; shapeTypePrefix = "Type = "; shapeVetexCountPrefix = ", VertexCount = "; shapeVerticesPrefix = ", Vertices = "; shapeRadiusPrefix = ", Radius = "; shapeCenterPrefix = ", Center = "; } if(name == "Shape.Type" || shape) { std::string type = ""; if(xshape->GetType() == b2Shape::e_unknown) type = "e_unknown"; else if(xshape->GetType() == b2Shape::e_circle) type = "e_circle"; else if(xshape->GetType() == b2Shape::e_polygon) type = "e_polygon"; else if(xshape->GetType() == b2Shape::e_typeCount) type = "e_typeCount"; result += shapeTypePrefix + type; } if(name == "Shape.Center" || shape) { if(xshape->GetType() == b2Shape::e_circle) { b2CircleShape* cshape= reinterpret_cast<b2CircleShape*>(xshape); result += shapeCenterPrefix + VectorToStr(cshape->m_p); } else if(xshape->GetType() == b2Shape::e_polygon) { b2PolygonShape* pshape= reinterpret_cast<b2PolygonShape*>(xshape); result += shapeCenterPrefix + VectorToStr(pshape->m_centroid); } } if(name == "Shape.Radius" || shape) result += shapeRadiusPrefix + FloatToStr(m->GetShape()->m_radius); if(name == "Shape.VertexCount" || shape) { if(xshape->GetType() == b2Shape::e_polygon) { b2PolygonShape* pshape= reinterpret_cast<b2PolygonShape*>(xshape); result += shapeVetexCountPrefix + IntToStr(pshape->m_vertexCount); } else { if(!shape) { result = "shape is circle"; } } } if(name == "Shape.Vertices" || shape) { if(xshape->GetType() == b2Shape::e_polygon) { b2PolygonShape* pshape= reinterpret_cast<b2PolygonShape*>(xshape); result += shapeVerticesPrefix; for(int i =0; i<pshape->m_vertexCount; ++i) { result += VectorToStr(pshape->m_vertices[i]); result += " "; } } else { if(!shape) { result = "shape is circle"; } } } if(shape) result += " }"; else if(name == "IsSensor") result = FloatToStr(m->IsSensor()); bool filter = false; std::string filterCategoryPrefix = "", filterMaskPrefix = "", filterGroupPrefix = ""; if(name == "Filter") { filter = true; result += "{ "; filterCategoryPrefix = "CategoryBits = "; filterMaskPrefix = ", MaskBits = "; filterGroupPrefix = ", GroupIndex = "; } if( name == "Filter.CategoryBits" || filter) result += filterCategoryPrefix + IntToStr(m->GetFilterData().categoryBits); if( name == "Filter.MaskBits" || filter) result += filterMaskPrefix + HexToStr(m->GetFilterData().maskBits); if( name == "Filter.GroupIndex") result += filterGroupPrefix + IntToStr(m->GetFilterData().groupIndex); if(filter) { result += " }"; } else if(name == "ParentBody") { Body* body = reinterpret_cast<Body*>(m->GetBody()->GetUserData()); if(body != NULL) result = body->getName(); else result = "Has no atached Body object"; } bool mass = false; std::string massValuePrefix = "", massCenterPrefix = "", massRotationInertiaPrefix = ""; b2MassData massData; m->GetMassData(&massData); if( name == "Mass") { mass = true; result += "{ "; massValuePrefix = "Value = "; massCenterPrefix = ", Center = "; massRotationInertiaPrefix = ", RotationInertia = "; } if( name == "Mass.Value" || mass) result += massValuePrefix + FloatToStr(massData.mass); if( name == "Mass.Center" || mass) result += massCenterPrefix + VectorToStr(massData.center); if( name == "Mass.RotationInertia" || mass) result += massRotationInertiaPrefix + FloatToStr(massData.I); if(mass) result += " }"; else if(name == "Density") result = FloatToStr(m->GetDensity()); else if(name == "Restitution") result = FloatToStr(m->GetRestitution()); else if(name == "Friction") result = FloatToStr(m->GetFriction()); bool aabb = false; std::string aabbTopPrefix = "", aabbBottomPrefix = "", aabbLeftPrefix = "", aabbRightPrefix = ""; if( name == "AABB" ) { aabb = true; result += "{ "; aabbTopPrefix = "Top = "; aabbBottomPrefix = "Bottom = "; aabbLeftPrefix = "Left = "; aabbRightPrefix = "Right = "; } if( name == "AABB.Top" || aabb) result += aabbTopPrefix + FloatToStr(m->GetAABB().upperBound.y); if( name == "AABB.Bottom" || aabb) result += aabbBottomPrefix + FloatToStr(m->GetAABB().lowerBound.y); if( name == "AABB.Left" || aabb) result += aabbLeftPrefix + FloatToStr(m->GetAABB().upperBound.x); if( name == "AABB.Right" || aabb) result += aabbRightPrefix + FloatToStr(m->GetAABB().upperBound.x); if(aabb) result += " }"; if( result == "") result = "Erorr, can't evalute"; return result; }
//---------------------------------------------------------------------- // 主函数 // 主要完成系统初始化,飞机激活、起飞、完成飞行任务,降落或返航 //---------------------------------------------------------------------- int main(void) { u8 t; delay_init(); //延时函数初始化 NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级 uart_init(230400); //串口初始化为230400,M100支持115200和230400,请结合N1调参软件修改 LED_Init(); //LED端口初始化 LCD_Init(); //液晶屏初始化 KEY_Init(); //按键初始化 本例程使用 PE4启动飞机 DJI_Pro_Test_Setup(); // 配置DJI SDK序列号 密钥 初始化通信链路 POINT_COLOR=RED;//设置字体为红色 LCD_ShowString(20,10,200,16,16,Dji_welcome); POINT_COLOR=BLUE;//设置字体为蓝色 YELLOW //下面循环用于等待用户触发PE4按键启动飞机 while(1) { t=KEY_Scan(0); if(t==1) break; } delay_s(8);//按键后延时,防止实飞时飞机伤到人。按键开始激活飞机、起飞,请立即远离飞机,以免造成伤害!!!!!!可以适当加长延时时间 //---------------------------------------------------------------------- // 此while循环完成飞机激活、获取控制权,如果没有激活成功或者获取到控制权,本次循环将终止跳到下次循环继续激活并获取控制权 // 直到成功获取后 执行起飞命定,break跳出循环继续执行飞行任务 //---------------------------------------------------------------------- while(1) { DJI_Onboard_API_Activation();//激活API delay_ms(500);//延时用来保障应答数据接收完毕 if(i>3)//i>3只是用来判断串口中断是否接收到数据 { HexToStr(PrintAck, RecBuff, i); display(40); if(RecBuff[0]==0xAA&RecBuff[12]==0x00&RecBuff[13]==0x00) { LCD_ShowString(20,55,200,16,12,"Activation Success "); } else LCD_ShowString(20,55,200,16,12,"Activation error "); i=0; } else continue; delay_s(1); DJI_Onboard_API_Control(1);//获取控制权 delay_ms(500); if(i>3) { HexToStr(PrintAck, RecBuff, i); display(80); if(RecBuff[0]==0xAA&RecBuff[12]==0x02&RecBuff[13]==0x00) { LCD_ShowString(20,95,200,16,12,"Obtain Success "); } else LCD_ShowString(20,95,200,16,12,"Obtain error "); i=0; } else continue; delay_s(1); DJI_Onboard_API_UAV_Control(4);//起飞 delay_ms(500); if(i>3) { HexToStr(PrintAck, RecBuff, i); display(120); if(RecBuff[0]==0xAA&RecBuff[12]==0x02&RecBuff[13]==0x00) { LCD_ShowString(20,135,200,16,12,"Begin to Take off"); } i=0; } else continue; break; } // 开始执行任务 delay_s(5); DJI_Onboard_API_Ctr(0x48,100,0,0,2,0); delay(400); LCD_ShowString(20,155,200,16,12,"Take off Success"); LCD_ShowString(20,175,200,16,12,"Begin to fly cube"); DJI_Onboard_API_Ctr_drawcube();//画正方体 delay_s(1); DJI_Onboard_API_Ctr(0x48,100,1,-0.414,0,0);//调整位置,规划圆心,准备画圆 delay_s(4); LCD_ShowString(20,195,200,16,12,"Begin to fly circle"); DJI_Onboard_API_Ctr_drawcircle();//在正方体上方绘制外接圆 delay_s(4); // LCD_ShowString(20,215,200,16,12,"Begin to landing"); // DJI_Onboard_API_UAV_Control(6);//降落 // DJI_Onboard_API_Ctr(0x48,200,6,0,0,0);//拉开距离,使飞机飞出起飞点20m外,方便测试返航功能,实飞时请不要执行该命令 LCD_ShowString(20,215,200,16,12,"Begin to go home"); DJI_Onboard_API_UAV_Control(1);//自动返航 delay_s(4); while(1) { LCD_ShowString(20,235,200,16,12,"All task finished "); } }
int Read_Contact_Card_Info(int cardtype,char *Dest) { switch(cardtype) { case 1://4442 { char cbuff[30]={0}; unsigned char data[100]={0}; int st=ICC_Reader_4442_PowerOn(ReaderHandle,data); //4442卡上电 if(st) { strcpy(Dest,"4442上电失败!"); return st; } st = ICC_Reader_4442_Read(ReaderHandle,100,14,(unsigned char*)Dest); if(st<0) { strcpy(Dest,"4442读取卡号失败!"); ICC_Reader_4442_PowerOff(ReaderHandle); return st; } for(int i=0;i<14;i++) { if(Dest[i]<0x30 || Dest[i]>0x39) { Dest[i]=0; break; } } ICC_Reader_4442_PowerOff(ReaderHandle); } break; case 2://4428 { unsigned char card_buff[100]={0}; unsigned char chack_buff[100]={0}; char cbuff[100]={0}; char a[3]={0}; int st = ICC_Reader_4428_Read(ReaderHandle,50,20,card_buff); if(st<0) { strcpy(Dest,"4428读取卡号失败-1!"); ICC_Reader_4428_PowerOff(ReaderHandle); return st; } for (int i =0; i < 20;i++) { sprintf(a,"%02X",card_buff[i]); strcat(cbuff,a); } bool fflag=true;; for(i=0;i<8;i++)//如果前8为有效数字,则为卡号 { if(cbuff[i]<0x30 || cbuff[i]>0x39) { fflag=false;//不是卡号 break; } } if(!fflag)//不是卡号 { memset(card_buff,0,100); st = ICC_Reader_4428_Read(ReaderHandle,100,14,card_buff); if(st<0) { strcpy(Dest,"4428读取卡号失败!-2"); ICC_Reader_4428_PowerOff(ReaderHandle); return st; } bool ffflag=true; for(i=0;i<4;i++)//如果前4为有效数字,则为卡号 { if(card_buff[i]<0x30 || card_buff[i]>0x39) { ffflag=false;//不是卡号 break; } } if(!ffflag)//不是卡号 { memset(card_buff,0,100); st = ICC_Reader_4428_Read(ReaderHandle,27,14,card_buff); if(st<0) { strcpy(Dest,"4428读取卡号失败!-3"); ICC_Reader_4428_PowerOff(ReaderHandle); return st; } bool feflag=true;; for(i=0;i<8;i++)//如果前4为有效数字,则为卡号 { if(card_buff[i]<0x30 || card_buff[i]>0x39) { feflag=false;//不是卡号 break; } } if(!feflag)//需要解密 { memset(card_buff,0,100); st = ICC_Reader_4428_Read(ReaderHandle,37,20,card_buff); if(st<0) { strcpy(Dest,"4428读取卡号失败!-4"); ICC_Reader_4428_PowerOff(ReaderHandle); return st; } memset(cbuff,0,100); procPassWord(card_buff, (unsigned char*)cbuff, 20); /*strdata += "431382";*/ for(i=0;i<20;i++) { if(cbuff[i]==' ') { cbuff[i]=0; break; } } } else { memset(cbuff,0,100); memcpy(cbuff,card_buff,14); for(i=0;i<14;i++)// { if(cbuff[i]<0x30 || cbuff[i]>0x39) { cbuff[i]=0;// break; } } } } else //是卡号 { memset(cbuff,0,100); memcpy(cbuff,card_buff,14); for(i=0;i<14;i++)// { if(cbuff[i]<0x30 || cbuff[i]>0x39) { cbuff[i]=0;// break; } } } } else { //memset(cbuff,0,100); //memcpy(cbuff,card_buff,20); for(i=0;i<40;i++)// { if(cbuff[i]<0x30 || cbuff[i]>0x39) { cbuff[i]=0;// break; } } cbuff[20]=0; } strcpy(Dest,cbuff); ICC_Reader_4428_PowerOff(ReaderHandle); } break; case 3://社保 { unsigned char cmd[100]={0}; unsigned char Response[100]={0}; unsigned char fakariqi[100] = {0};//发卡日期 unsigned char kayouxiaoqi[100] = {0};//卡有效期 unsigned char Shebaokahao[100] = {0};//社保卡号 unsigned char Shehuibaozhang[100] = {0};//社会保障号码 unsigned char Name[100] = {0};//姓名 unsigned char Sex[100] = {0};//性别 unsigned char Nation[100] = {0};//民族 unsigned char Address[100] = {0};//出生地 unsigned char Birth[100] = {0};//出生日期 //选SSSE memcpy(cmd, "\x00\xA4\x04\x00\x0F\x73\x78\x31\x2E\x73\x68\x2E\xC9\xE7\xBB\xE1\xB1\xA3\xD5\xCF", 20); int rt= ICC_Reader_Application(ReaderHandle,0x01, 20, cmd, Response); if(Response[rt-2]!=0x61 && Response[rt-2]!=0x90) { strcpy(Dest,"社保卡选SSSE失败!"); ICC_Reader_PowerOff(ReaderHandle,0x01); return rt; } //选SSSE/EF05 memset(cmd, 0, 100); memset(Response, 0, 100); memcpy(cmd, "\x00\xA4\x02\x00\x02\xEF\x05", 7); rt = ICC_Reader_Application(ReaderHandle, 0x01, 7, cmd, Response); if(rt<0 || Response[rt-2]!=0x90) { strcpy(Dest,"社保卡选SSSE-EF05失败!"); ICC_Reader_PowerOff(ReaderHandle,0x01); return rt; } //发卡日期 memset(cmd, 0, 100); memset(Response, 0, 100); memcpy(cmd, "\x00\xB2\x05\x00\x04", 5); rt = ICC_Reader_Application(ReaderHandle, 0x01, 5, cmd, Response); if(rt<0 && Response[rt-2]!=0x90) { strcpy(Dest,"发卡日期读取失败"); ICC_Reader_PowerOff(ReaderHandle,0x01); return rt; } HexToStr(Response+2,rt-4,fakariqi);//将16进制命令流转为字符流 // //卡有效期 memset(cmd, 0, 100); memset(Response, 0, 100); memcpy(cmd, "\x00\xB2\x05\x00\x04", 5); rt = ICC_Reader_Application(ReaderHandle, 0x01, 5, cmd, Response); if(rt<0 && Response[rt-2]!=0x90) { strcpy(Dest,"卡有效期读取失败"); ICC_Reader_PowerOff(ReaderHandle,0x01); return rt; } HexToStr(Response+2,rt-4,kayouxiaoqi);//将16进制命令流转为字符流 //卡号 memset(cmd, 0, 100); memset(Response, 0, 100); memcpy(cmd, "\x00\xB2\x07\x00\x09", 5); rt = ICC_Reader_Application(ReaderHandle, 0x01, 5, cmd, Response); if(rt<0 && Response[rt-2]!=0x90) { strcpy(Dest,"社保卡号失败"); ICC_Reader_PowerOff(ReaderHandle,0x01); return rt; } memcpy(Shebaokahao, Response+2,rt-4); //====================================================================== //选SSSE memcpy(cmd, "\x00\xA4\x04\x00\x0F\x73\x78\x31\x2E\x73\x68\x2E\xC9\xE7\xBB\xE1\xB1\xA3\xD5\xCF", 20); rt= ICC_Reader_Application(ReaderHandle,0x01, 20, cmd, Response); if(Response[rt-2]!=0x61 && Response[rt-2]!=0x90) { strcpy(Dest,"社保卡选SSSE失败!"); ICC_Reader_PowerOff(ReaderHandle,0x01); return rt; } //选SSSE/EF06 memset(cmd, 0, 100); memset(Response, 0, 100); memcpy(cmd, "\x00\xA4\x02\x00\x02\xEF\x06", 7); rt = ICC_Reader_Application(ReaderHandle, 0x01, 7, cmd, Response); if(rt<0 || Response[rt-2]!=0x90) { strcpy(Dest,"社保卡选SSSE-EF06失败!"); ICC_Reader_PowerOff(ReaderHandle,0x01); return rt; } //社会保障号码 memset(cmd, 0, 100); memset(Response, 0, 100); memcpy(cmd, "\x00\xB2\x08\x00\x12", 5); rt = ICC_Reader_Application(ReaderHandle, 0x01, 5, cmd, Response); if(rt<0 && Response[rt-2]!=0x90) { strcpy(Dest,"社会保障号码读取失败"); ICC_Reader_PowerOff(ReaderHandle,0x01); return rt; } memcpy(Shehuibaozhang, Response+2,rt-4); //姓名 memset(cmd, 0, 100); memset(Response, 0, 100); memcpy(cmd, "\x00\xB2\x09\x00\x1E", 5); rt = ICC_Reader_Application(ReaderHandle, 0x01, 5, cmd, Response); if(rt<0 && Response[rt-2]!=0x90) { strcpy(Dest,"姓名读取失败"); ICC_Reader_PowerOff(ReaderHandle,0x01); return rt; } memcpy(Name, Response+2,rt-4); //性别 memset(cmd, 0, 100); memset(Response, 0, 100); memcpy(cmd, "\x00\xB2\x0A\x00\x01", 5); rt = ICC_Reader_Application(ReaderHandle, 0x01, 5, cmd, Response); if(rt<0 && Response[rt-2]!=0x90) { strcpy(Dest,"性别读取失败"); ICC_Reader_PowerOff(ReaderHandle,0x01); return rt; } memcpy(Sex, Response+2,rt-4); //民族 memset(cmd, 0, 100); memset(Response, 0, 100); memcpy(cmd, "\x00\xB2\x0B\x00\x01", 5); rt = ICC_Reader_Application(ReaderHandle, 0x01, 5, cmd, Response); if(rt<0 && Response[rt-2]!=0x90) { strcpy(Dest,"民族读取失败"); ICC_Reader_PowerOff(ReaderHandle,0x01); return rt; } HexToStr(Response+2,rt-4,Nation); //出生地 memset(cmd, 0, 100); memset(Response, 0, 100); memcpy(cmd, "\x00\xB2\x0C\x00\x03", 5); rt = ICC_Reader_Application(ReaderHandle, 0x01, 5, cmd, Response); if(rt<0 && Response[rt-2]!=0x90) { strcpy(Dest,"出生地读取失败"); ICC_Reader_PowerOff(ReaderHandle,0x01); return rt; } HexToStr(Response+2,rt-4,Address); //出生日期 memset(cmd, 0, 100); memset(Response, 0, 100); memcpy(cmd, "\x00\xB2\x0D\x00\x04", 5); rt = ICC_Reader_Application(ReaderHandle, 0x01, 5, cmd, Response); if(rt<0 && Response[rt-2]!=0x90) { strcpy(Dest,"出生日期读取失败"); ICC_Reader_PowerOff(ReaderHandle,0x01); return rt; } HexToStr(Response+2,rt-4,Birth); sprintf(Dest,"%s|%s|%s|%s|%s|%s|%s|%s|%s",fakariqi,kayouxiaoqi,Shebaokahao,Shehuibaozhang,Name,Sex,Nation,Address,Birth); } break; } return 0; }
KeySpace *KeySpace::load(const char *fileName, uint32_t charaterEncoding) { std::vector<std::string> lines; std::ifstream fin(fileName, std::ifstream::in); std::string line, name, charSet; std::map<std::string,std::string> charSets; std::map<std::string,std::string>::iterator charSetMapIt; std::list<std::string> subKeySpace; std::list<std::list<std::string> > subKeySpaces; std::list<std::string>::iterator charSetIt; std::list<std::list<std::string> >::iterator subKeySpaceIt; size_t pos, pos2; uint32_t len, lineNumber = 0; bool multiCharNames = false; char ch[2] = {0, 0}; #ifdef BOINC if (!boinc_ReadLinesFromFile(fileName, lines)) #else if (!ReadLinesFromFile(fileName, lines)) #endif { fprintf(stderr, "ERROR: Can't open key space file '%s'\n", fileName); return NULL; } // Read character sets while (1) { // Read line if (lineNumber >= lines.size()) { // eof fprintf(stderr, "ERROR: '%s' is not a valid key space file\n", fileName); return NULL; } line = lines[lineNumber]; lineNumber++; if (line.length() == 0 || line[0] == '#') { continue; } if (line[line.length() - 1] != ']') { break; } // Get character set name pos = line.find_first_of(" \t", 0, 2); if (pos == std::string::npos) { break; } name = line.substr(0, pos); // Get character set pos = line.find_first_not_of(" \t", pos, 2); if (pos == std::string::npos) { break; // this is not even possible... meh } if (line[pos] == '[') { charSet = line.substr(pos + 1, line.length() - pos - 2); } else if (line[pos] == 'h' && line[pos + 1] == '[') { charSet = HexToStr((unsigned char*)line.substr(pos + 2, line.length() - pos - 3).c_str(), line.length() - pos - 3); if (charSet.length() == 0 && line.length() - pos - 3 != 0) { fprintf(stderr, "ERROR: '%s' has an invalid character set on line #%u\n", fileName, lineNumber); return NULL; } } else { break; } if (charSet.length() == 0) { fprintf(stderr, "ERROR: '%s' has an empty character set on line #%u\n", fileName, lineNumber); return NULL; } // Insert into map if (charSets.find(name) == charSets.end()) { if (name.length() != 1) { multiCharNames = true; } charSets[name] = charSet; } else { fprintf(stderr, "ERROR: '%s' has a duplicate character set name on line #%u\n", fileName, lineNumber); return NULL; } } if (line[line.length() - 1] == ']') { fprintf(stderr, "ERROR line #%u: '%s' is not a valid key space file\n", lineNumber, fileName); return NULL; } // Read sub key spaces do { if (multiCharNames) { pos = 0; while (pos != std::string::npos) { // Get character set name pos2 = line.find_first_of(" \t", pos, 2); if (pos2 == std::string::npos) { pos2 = line.length(); } name = line.substr(pos, pos2 - pos); // Get character set charSetMapIt = charSets.find(name); if (charSetMapIt == charSets.end()) { fprintf(stderr, "ERROR: Character set name '%s' not found on line #%u from key space file '%s'\n", name.c_str(), lineNumber, fileName); return NULL; } subKeySpace.push_back(charSetMapIt->second); if (pos2 == line.length()) { break; } pos = line.find_first_not_of(" \t", pos2, 2); } } else { len = line.length(); for (pos = 0; pos < len; pos++) { *ch = line[pos]; if (*ch != ' ' && *ch != '\t') { charSetMapIt = charSets.find(ch); if (charSetMapIt == charSets.end()) { fprintf(stderr, "ERROR: Character set name '%c' not found on line #%u from key space file '%s'\n", *ch, lineNumber, fileName); return NULL; } subKeySpace.push_back(charSetMapIt->second); } } } subKeySpaces.push_back(subKeySpace); subKeySpace.clear(); // Read line do { if (lineNumber >= lines.size()) { line = ""; break; // eof } line = lines[lineNumber]; lineNumber++; } while ((line.length() == 0 || line[0] == '#')); } while (line.length() != 0); KeySpace *ks = KeySpace::init(subKeySpaces, charaterEncoding); if (ks != NULL) { ks->m_name = fileName; } return ks; }
int __stdcall IC_GetData(ICC_ENV *iccenv,int datatype,char *data) { char ch='|'; hReader=ICC_Reader_Open("USB1"); if(hReader<=0)//设备打开失败返回 { char *p="Open device failure"; memcpy(data,p,strlen(p)); return 1; } unsigned char Response[50]={0}; long rt=0; //复位 rt=ICC_Reader_PowerOn(hReader,0x01,Response); if(rt<=0) { char *p="PowerOn failure"; memcpy(data,p,strlen(p)); return 2; } //发送选SSSE指令 unsigned char cmd[100]= {0x00,0xA4,0x04,0x00,0x0F, 0x73,0x78,0x31,0x2E,0x73, 0x68,0x2E,0xC9,0xE7,0xBB, 0xE1,0xB1,0xA3,0xD5,0xCF}; unsigned char ResponseAPDU[200]={0}; int len=ICC_Reader_Application(hReader,0x01,20,cmd,ResponseAPDU); if(len<=0) { char *p="其他卡型-00A4";; memcpy(data,p,strlen(p)); return 3; } if( (ResponseAPDU[len-2]!=0x61) && (ResponseAPDU[len-2]!=0x90) ) { char *p="其他卡型-00A4"; memcpy(data,p,strlen(p)); return 4; } //选SSSE/EF05 memset(cmd,0,100); memset(ResponseAPDU,0,200); memcpy(cmd, "\x00\xA4\x00\x00\x02\xEF\x05",7); len=ICC_Reader_Application(hReader,0x01,7,cmd,ResponseAPDU);//X选择EF05文件 if(len<=0 || ResponseAPDU[len-2]!=0x90) { char *p="00A4-EF05"; memcpy(data,p,strlen(p)); return 4; } //读卡类型标识 memset(cmd,0,100); memset(ResponseAPDU,0,200); memcpy(cmd, "\x00\xB2\x02\x04\x03",5); len = ICC_Reader_Application(hReader,0x01,5,cmd,ResponseAPDU); if(len<=0 || ResponseAPDU[len-2]!=0x90) { char *p="00B202"; memcpy(data,p,strlen(p)); return 4; } char CardType[2]={0}; memcpy(CardType,ResponseAPDU+2,1);//获卡类型标识 //读 卡号 社会保障卡:社会保障卡识别码 memset(cmd,0,100); memset(ResponseAPDU,0,200); memcpy(cmd, "\x00\xB2\x01\x04\x12",5); len = ICC_Reader_Application(hReader,0x01,5,cmd,ResponseAPDU); if(len<=0 || ResponseAPDU[len-2]!=0x90) { char *p="00B201"; memcpy(data,p,strlen(p)); return 4; } char CardNo[0x10*2+1]={0}; HexToStr(ResponseAPDU+2,0x10,(unsigned char *)CardNo); //memcpy(CardNo,ResponseAPDU+2,0x10);//获卡号 //读 个人编号 社会保障卡:卡面号 memset(cmd,0,100); memset(ResponseAPDU,0,200); memcpy(cmd, "\x00\xB2\x07\x04\x0b",5); len = ICC_Reader_Application(hReader,0x01,5,cmd,ResponseAPDU); if(len<=0 || ResponseAPDU[len-2]!=0x90) { char *p="00B207"; memcpy(data,p,strlen(p)); return 4; } char UserNo[0x0a]={0}; memcpy(UserNo,ResponseAPDU+2,0x09);//获个人编号 //选DDF03 memset(cmd,0,100); memset(ResponseAPDU,0,200); memcpy(cmd, "\x00\xA4\x01\x00\x02\xDF\x03",7); len = ICC_Reader_Application(hReader,0x01,7,cmd,ResponseAPDU); if(len<=0 || (ResponseAPDU[len-2]!=0x61 && ResponseAPDU[len-2]!=0x90)) { char *p="00A4-DF03"; memcpy(data,p,strlen(p)); return 4; } //认证PIN memset(cmd,0,100); memset(ResponseAPDU,0,200); memcpy(cmd, "\x00\x20\x00\x00\x03\x12\x34\x56",8); len = ICC_Reader_Application(hReader,0x01,8,cmd,ResponseAPDU); if(len<=0 || ResponseAPDU[len-2]!=0x90) { char *p="VeryfyPin-00200003"; memcpy(data,p,strlen(p)); return 4; } //选EF18 memset(cmd,0,100); memset(ResponseAPDU,0,200); memcpy(cmd, "\x00\xa4\x00\x00\x02\xEF\x19",7); len = ICC_Reader_Application(hReader,0x01,7,cmd,ResponseAPDU); if(len<=0 || ResponseAPDU[len-2]!=0x90) { char *p="00a4-EF18"; memcpy(data,p,strlen(p)); return 4; } //读 参保地行政区划代码 memset(cmd,0,100); memset(ResponseAPDU,0,200); memcpy(cmd, "\x00\xb2\x79\x00\x29",5); len = ICC_Reader_Application(hReader,0x01,5,cmd,ResponseAPDU); if(len<=0 || ResponseAPDU[len-2]!=0x90) { char *p="00b2 75 0005"; memcpy(data,p,strlen(p)); return 4; } char JAdress[0x03*2+1]={0}; //memcpy(JAdress,ResponseAPDU+9,0x03);//获参保地行政区划代码 HexToStr(ResponseAPDU+9,0x03,(unsigned char *)JAdress); char DevMN[6]="HD100"; //读卡器的型号 //获取读卡器序列号 char DevN[100]={0}; //读卡器的序列号 int nDevN=ICC_Reader_GetDeviceCSN(hReader,DevN); if(nDevN<=0) { char *p="Get device number failure"; memcpy(data,p,strlen(p)); return 5; } char DLLVersion[4]={"1.0"}; //DLL版本 char LIBVersion[4]={"1.0"}; //LIB版本 //操作SAM卡 memset(Response,0,50); rt=ICC_Reader_PowerOn(hReader,0x11,Response); //sam卡复位 if(rt<=0) { char *p="SAM PowerOn failure"; memcpy(data,p,strlen(p)); return 6; } //选SAM卡的MF memset(cmd,0,100); memset(ResponseAPDU,0,200); memcpy(cmd, "\x00\xA4\x00\x00\x00",5); len = ICC_Reader_Application(hReader,0x11,5,cmd,ResponseAPDU); if( (ResponseAPDU[len-2]!=0x61) && (ResponseAPDU[len-2]!=0x90) ) { char *p="SAM-其他卡型-00A4000000"; memcpy(data,p,strlen(p)); return 4; } //选SAM卡的MF/0015 memset(cmd,0,100); memset(ResponseAPDU,0,200); memcpy(cmd, "\x00\xA4\x00\x00\x02\x00\x15",7); len = ICC_Reader_Application(hReader,0x11,7,cmd,ResponseAPDU); if( (ResponseAPDU[len-2]!=0x61) && (ResponseAPDU[len-2]!=0x90) ) { char *p="SAM-00A4-0015"; memcpy(data,p,strlen(p)); return 4; } //读0015的内容 memset(cmd,0,100); memset(ResponseAPDU,0,200); memcpy(cmd, "\x00\xb0\x00\x00\x0f",5); len = ICC_Reader_Application(hReader,0x11,5,cmd,ResponseAPDU); if(len<=0 || ResponseAPDU[len-2]!=0x90) { char *p="00b000000f"; memcpy(data,p,strlen(p)); return 4; } char SamN[10*2+1]={0}; //memcpy(SamN,ResponseAPDU+1,10); //获取SAM卡的序列号 HexToStr(ResponseAPDU+1,10,(unsigned char *)SamN); //选SAM卡的MF/0016 memset(cmd,0,100); memset(ResponseAPDU,0,200); memcpy(cmd, "\x00\xA4\x00\x00\x02\x00\x16",7); len = ICC_Reader_Application(hReader,0x11,7,cmd,ResponseAPDU); if( (ResponseAPDU[len-2]!=0x61) && (ResponseAPDU[len-2]!=0x90) ) { char *p="SAM-00A4-0016"; memcpy(data,p,strlen(p)); return 4; } //读0016的内容 memset(cmd,0,100); memset(ResponseAPDU,0,200); memcpy(cmd, "\x00\xb0\x00\x00\x06",5); len = ICC_Reader_Application(hReader,0x11,5,cmd,ResponseAPDU); if(len<=0 || ResponseAPDU[len-2]!=0x90) { char *p="00b0000006"; memcpy(data,p,strlen(p)); return 4; } char MachineN[6*2+1]={0}; //memcpy(MachineN,ResponseAPDU,6); //获取终端机编号 HexToStr(ResponseAPDU,6,(unsigned char *)MachineN); //char CardType[2]={0}; 获卡类型标识 //char CardNo[0x11]={0}; 获卡号 //char UserNo[0x0a]={0}; 个人编号 //char JAdress[0x04]={0}; 获参保地行政区划代码 //char DevMN[6]="HD100"; 读卡器的型号 //char DevN[100]={0}; 读卡器的序列号(注意长度) nDevN //char DLLVersion[4]="1.0"; DLL版本 //char LIBVersion[4]="1.0"; LIB版本 //char SamN[11]={0}; SAM卡的序列号 //char MachineN[7]={0}; 端机编号 memcpy(data,CardType,1); data[1]=ch; int ich=0; while(data[ich]!=ch) ich++; memcpy(data+ich+1,CardNo,0x10*2); data[ich+1+0x10*2]=ch; ich=ich+1+0x10*2; memcpy(data+ich+1,UserNo,0x09); data[ich+1+0x09]=ch; ich=ich+1+0x09; memcpy(data+ich+1,JAdress,0x03*2); data[ich+1+0x03*2]=ch; ich=ich+1+0x03*2; memcpy(data+ich+1,DevMN,5); data[ich+1+5]=ch; ich=ich+1+5; memcpy(data+ich+1,DevN,nDevN); data[ich+1+nDevN]=ch; ich=ich+1+nDevN; memcpy(data+ich+1,DLLVersion,3); data[ich+1+3]=ch; ich=ich+1+3; memcpy(data+ich+1,LIBVersion,3); data[ich+1+3]=ch; ich=ich+1+3; memcpy(data+ich+1,MachineN,6*2); data[ich+1+6*2]=','; ich=ich+1+6*2; memcpy(data+ich+1,SamN,10*2); ich=ich+1+10*2; return 0; }
int main(int argc, char** argv) { int i, retval; const char *usage = "\nUsage: %s -app <app-name> [OPTIONS]\n" "Start validator for application <app-name>\n\n" "Optional arguments:\n" " --one_pass_N_WU N Validate at most N WUs, then exit\n" " --one_pass Make one pass through WU table, then exit\n" " --mod n i Process only WUs with (id mod n) == i\n" " --max_claimed_credit X If a result claims more credit than this, mark it as invalid\n" " --max_granted_credit X Grant no more than this amount of credit to a result\n" " --grant_claimed_credit Grant the claimed credit, regardless of what other results for this workunit claimed\n" " --update_credited_job Add record to credited_job table after granting credit\n" " --credit_from_wu Credit is specified in WU XML\n" " --sleep_interval n Set sleep-interval to n\n" " -d n, --debug_level n Set log verbosity level, 1-4\n" " -h | --help Show this\n" " -v | --version Show version information\n"; if ((argc > 1) && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))) { printf (usage, argv[0] ); exit(0); } check_stop_daemons(); for (i=1; i<argc; i++) { if (is_arg(argv[i], "one_pass_N_WU")) { one_pass_N_WU = atoi(argv[++i]); one_pass = true; } else if (is_arg(argv[i], "sleep_interval")) { sleep_interval = atoi(argv[++i]); } else if (is_arg(argv[i], "one_pass")) { one_pass = true; } else if (is_arg(argv[i], "app")) { strcpy(app_name, argv[++i]); } else if (is_arg(argv[i], "d") || is_arg(argv[i], "debug_level")) { debug_level = atoi(argv[++i]); log_messages.set_debug_level(debug_level); if (debug_level == 4) g_print_queries = true; } else if (is_arg(argv[i], "mod")) { wu_id_modulus = atoi(argv[++i]); wu_id_remainder = atoi(argv[++i]); } else if (is_arg(argv[i], "max_granted_credit")) { max_granted_credit = atof(argv[++i]); } else if (is_arg(argv[i], "max_claimed_credit")) { max_claimed_credit = atof(argv[++i]); } else if (is_arg(argv[i], "grant_claimed_credit")) { grant_claimed_credit = true; } else if (is_arg(argv[i], "update_credited_job")) { update_credited_job = true; } else if (is_arg(argv[i], "credit_from_wu")) { credit_from_wu = true; } else if (is_arg(argv[i], "v") || is_arg(argv[i], "version")) { printf("%s\n", SVN_VERSION); exit(0); } else if(!strcmp(argv[i], "-testmd5")) { unsigned char hash[16]; char text[5] = "test"; MD5((unsigned char*)&text, 4, (unsigned char *)&hash); string hex = HexToStr((const unsigned char *)&hash, 16); printf("test = %s", hex.c_str()); } else { fprintf(stderr, "Invalid option '%s'\nTry `%s --help` for more information\n", argv[i], argv[0] ); log_messages.printf(MSG_CRITICAL, "unrecognized arg: %s\n", argv[i]); exit(1); } } if (app_name[0] == 0) { log_messages.printf(MSG_CRITICAL, "must use '--app' to specify an application\n" ); printf (usage, argv[0] ); exit(1); } retval = config.parse_file(); if (retval) { log_messages.printf(MSG_CRITICAL, "Can't parse config.xml: %s\n", boincerror(retval) ); exit(1); } log_messages.printf(MSG_NORMAL, "Starting validator, debug level %d\n", log_messages.debug_level ); if (wu_id_modulus) { log_messages.printf(MSG_NORMAL, "Modulus %d, remainder %d\n", wu_id_modulus, wu_id_remainder ); } install_stop_signal_handler(); main_loop(); }
std::string CChainWalkContext::GetHash() { return HexToStr(m_Hash, m_nHashLen); }
std::string CChainWalkContext::GetBinary() { return HexToStr(m_Plain, m_nPlainLen); }
/**************************************************************************** **函数名: int disp_set_terparam(u8* param) **描述: 设置终端参数 **输入参数: param :传入参数 **输出参数: **返回值: >= 0:正常状态; < 0:不正常状态。 **备注: ** **版权:郑州友池电子技术有限公司深圳分公司 ** **作者 & 日期: 申伟宏(2015-01-31) **----------------------------------------------------------------------------- **修改记录: ****************************************************************************/ int disp_set_terparam(u8* param) { int re = ESUCCESS; u8 inputdata[50]; memset(inputdata, 0x00, sizeof(inputdata)); memcpy((char*)inputdata, (char*)gSysParam.m_TerminalNo, sizeof(gSysParam.m_TerminalNo)); re = disp_input_data((u8*)"终端参数", (u8*)"请输入终端号:", INPUT_TYPE_UNKNOW, (u8*)inputdata, 8, 8); if(re < 0){ goto EXIT_disp_set_terparam; } memcpy((char*)gSysParam.m_TerminalNo, (char*)inputdata, sizeof(gSysParam.m_TerminalNo)); memset((char*)inputdata, 0x00, sizeof(inputdata)); memcpy((char*)inputdata, (char*)gSysParam.m_MerchantNo, sizeof(gSysParam.m_MerchantNo)); re = disp_input_data((u8*)"终端参数", (u8*)"请输入商户号:", INPUT_TYPE_UNKNOW, (u8*)inputdata, 15, 15); if(re < 0){ goto EXIT_disp_set_terparam; } memcpy((char*)gSysParam.m_MerchantNo, (char*)inputdata, sizeof(gSysParam.m_MerchantNo)); memset(inputdata, 0x00, sizeof(inputdata)); HexToStr(gSysParam.m_VoucherNo,inputdata, sizeof(gSysParam.m_VoucherNo) * 2); re = disp_input_data((u8*)"终端参数", (u8*)"请设置流水号:", INPUT_TYPE_UNKNOW, inputdata, sizeof(gSysParam.m_VoucherNo) * 2, sizeof(gSysParam.m_VoucherNo) * 2); if(re < 0){ goto EXIT_disp_set_terparam; } inputdata[sizeof(gSysParam.m_VoucherNo) * 2] = 0x00; StrToHex(gSysParam.m_VoucherNo,inputdata); memset(inputdata, 0x00, sizeof(inputdata)); HexToStr(gSysParam.m_BatchNo,inputdata, sizeof(gSysParam.m_BatchNo) * 2); re = disp_input_data((u8*)"终端参数", (u8*)"请设置批次号:", INPUT_TYPE_UNKNOW, (u8*)inputdata, sizeof(gSysParam.m_BatchNo) * 2, sizeof(gSysParam.m_BatchNo) * 2); if(re < 0){ goto EXIT_disp_set_terparam; } inputdata[sizeof(gSysParam.m_BatchNo) * 2] = 0x00; StrToHex(gSysParam.m_BatchNo,inputdata); memset(inputdata, 0x00, sizeof(inputdata)); HexToStr(gSysParam.m_MaxTradeAmount,inputdata, sizeof(gSysParam.m_MaxTradeAmount) * 2); re = disp_input_data((u8*)"终端参数", (u8*)"最大交易金额:", INPUT_TYPE_AMT, (u8*)inputdata, 0, sizeof(gSysParam.m_MaxTradeAmount) * 2); if(re < 0){ goto EXIT_disp_set_terparam; } inputdata[sizeof(gSysParam.m_MaxTradeAmount) * 2] = 0x00; StrToHex(gSysParam.m_MaxTradeAmount,inputdata); memset(inputdata, 0x00, sizeof(inputdata)); sprintf((char*)inputdata, "%d", (int)gSysParam.m_MaxTradeNum); re = disp_input_data((u8*)"终端参数", (u8*)"最大交易笔数:", INPUT_TYPE_UNKNOW, (u8*)inputdata, 1, 10); if(re < 0){ goto EXIT_disp_set_terparam; } gSysParam.m_MaxTradeNum = atoi((char*)inputdata); memset(inputdata, 0x00, sizeof(inputdata)); sprintf((char*)inputdata, "%d", gSysParam.m_RepeatSend); re = disp_input_data((u8*)"终端参数", (u8*)"请设置重发次数:", INPUT_TYPE_UNKNOW, (u8*)inputdata, 1, 2); if(re < 0){ goto EXIT_disp_set_terparam; } gSysParam.m_RepeatSend= atoi((char*)inputdata); memset(inputdata, 0x00, sizeof(inputdata)); strcpy((char*)inputdata, (char*)gSysParam.m_MerChanName); re = disp_input_data((u8*)"终端参数", (u8*)"请设置商户名称:", INPUT_TYPE_UNKNOW, (u8*)inputdata, 0, 40); if(re < 0){ goto EXIT_disp_set_terparam; } strcpy((char*)gSysParam.m_MerChanName, (char*)inputdata); memset(inputdata, 0x00, sizeof(inputdata)); sprintf((char*)inputdata, "%d", (int)gSysParam.m_LowpowerTimeout); re = disp_input_data((u8*)"终端参数", (u8*)"低功耗时间(秒):", INPUT_TYPE_UNKNOW, (u8*)inputdata, 1, 10); if(re < 0){ goto EXIT_disp_set_terparam; } gSysParam.m_LowpowerTimeout = atoi((char*)inputdata); memset((char*)inputdata, 0x00, sizeof(inputdata)); sprintf((char*)inputdata, "%d", gSysParam.m_ShutDownTimeout); re = disp_input_data((u8*)"终端参数", (u8*)"低功耗自动关机(秒):", INPUT_TYPE_UNKNOW, (u8*)inputdata, 1, 10); if(re < 0){ goto EXIT_disp_set_terparam; } gSysParam.m_ShutDownTimeout = atoi((char*)inputdata); EXIT_disp_set_terparam: save_sysparam(); sharebuf_remove_globalfun(); return re; }
/* Cracks a single hash and returns a Python dictionary */ boost::python::dict crack(boost::python::list& hashes, std::string pathToTables, std::string outputFile, std::string sSessionPathName, std::string sProgressPathName, std::string sPrecalcPathName, std::string output, bool mysqlsha1format, bool debug, bool keepPrecalcFiles, int enableGPU, unsigned int maxThreads, uint64 maxMem) { #ifndef _WIN32 signal(SIGSEGV, handler); // Register segfault handler #endif CHashSet hashSet; bool resumeSession = false; // Sessions not currently supported std::vector<std::string> verifiedHashes; std::vector<std::string> vPathName; if ( !output.empty() ) { freopen(output.c_str(), "a", stdout); } if ( debug ) { std::cout << "[Debug]: List contains " << boost::python::len(hashes) << " hash(es)" << std::endl; } for (unsigned int index = 0; index < boost::python::len(hashes); ++index) { std::string sHash = boost::python::extract<std::string>(hashes[index]); if (NormalizeHash(sHash)) { verifiedHashes.push_back(sHash); } else { std::ostringstream stringBuilder; stringBuilder << "Invalid hash: <" << sHash.c_str() << ">"; std::string message = stringBuilder.str(); PyErr_SetString(PyExc_ValueError, message.c_str()); throw boost::python::error_already_set(); } } std::vector<std::string> sha1AsMysqlSha1; for (unsigned int index = 0; index < verifiedHashes.size(); ++index) { if (mysqlsha1format) { HASHROUTINE hashRoutine; CHashRoutine hr; std::string hashName = "sha1"; int hashLen = 20; hr.GetHashRoutine( hashName, hashRoutine, hashLen ); unsigned char* plain = new unsigned char[hashLen*2]; memcpy( plain, HexToBinary(verifiedHashes[index].c_str(), hashLen*2 ).c_str(), hashLen ); unsigned char hash_output[MAX_HASH_LEN]; hashRoutine( plain, hashLen, hash_output); sha1AsMysqlSha1.push_back(HexToStr(hash_output, hashLen)); hashSet.AddHash( sha1AsMysqlSha1[index] ); } else { hashSet.AddHash(verifiedHashes[index]); } } /* Load rainbow tables */ GetTableList(pathToTables, vPathName); if (debug) { std::cout << "[Debug]: Found " << vPathName.size() << " rainbow table file(s)" << std::endl; } /* Start cracking! */ CCrackEngine crackEngine; crackEngine.setSession(sSessionPathName, sProgressPathName, sPrecalcPathName, keepPrecalcFiles); crackEngine.Run(vPathName, hashSet, maxThreads, maxMem, resumeSession, debug, enableGPU); boost::python::dict results; results = fCrackerResults(verifiedHashes, sha1AsMysqlSha1, hashSet); return results; }
boost::python::dict otherResults(std::vector<std::string>& vLMHash, std::vector<std::string>& vNTLMHash, std::vector<std::string>& vUserName, CHashSet& hashSet, std::string& outputFile, bool debug) { boost::python::dict results; bool writeOutput = (outputFile == "" ? true:false); for (uint32 index = 0; index < vLMHash.size(); index++) { std::string sPlain1, sBinary1; bool fPart1Found = hashSet.GetPlain(vLMHash[index].substr(0, 16), sPlain1, sBinary1); if (!fPart1Found) { sPlain1 = "<Not Found>"; sBinary1 = "<Not Found>"; } std::string sPlain2, sBinary2; bool fPart2Found = hashSet.GetPlain(vLMHash[index].substr(16, 16), sPlain2, sBinary2); if (!fPart2Found) { sPlain2 = "<Not Found>"; sBinary2 = "<Not Found>"; } std::string sPlain = sPlain1 + sPlain2; std::string sBinary = sBinary1 + sBinary2; // Correct case if (fPart1Found && fPart2Found) { unsigned char NTLMHash[16]; int nHashLen; ParseHash(vNTLMHash[index], NTLMHash, nHashLen); if (nHashLen != 16) std::cout << "[Debug]: nHashLen mismatch" << std::endl; std::string sNTLMPassword; if (LMPasswordCorrectCase(sPlain, NTLMHash, sNTLMPassword)) { sPlain = sNTLMPassword; sBinary = HexToStr( (const unsigned char*) sNTLMPassword.c_str(), sNTLMPassword.size()); if (writeOutput) { if (!writeResultLineToFile(outputFile, vNTLMHash[index].c_str(), sPlain.c_str(), sBinary.c_str())) { std::string message = "Couldn't write final result to file!"; PyErr_SetString(PyExc_IOError, message.c_str()); throw boost::python::error_already_set(); } } } else { if ( debug ) { std::cout << "[Debug]: " << vUserName[index].c_str() << "\t" << sPlain.c_str() << "\thex:" << sBinary.c_str() << std::endl << "[Debug]: Failed case correction, trying unicode correction for: " << sPlain.c_str() << std::endl; } LM2NTLMcorrector corrector; if (corrector.LMPasswordCorrectUnicode(sBinary, NTLMHash, sNTLMPassword)) { sPlain = sNTLMPassword; sBinary = corrector.getBinary(); if (writeOutput) { if (!writeResultLineToFile(outputFile, vNTLMHash[index].c_str(), sPlain.c_str(), sBinary.c_str())) { std::string message = "Couldn't write final result to file!"; PyErr_SetString(PyExc_IOError, message.c_str()); throw boost::python::error_already_set(); } } } else if ( debug ) { std::cout << "[Debug]: unicode correction for password " << sPlain.c_str() << " failed!" << std::endl; } } } results[vUserName[index].c_str()] = sPlain.c_str(); } return results; }