bool Environment::Is64BitOperatingSystem() { #if UCFG_64 return true; #elif UCFG_USE_POSIX return GetMachineType().find("X86_64") != String::npos; #elif UCFG_WIN32_FULL typedef void (__stdcall *PFN)(SYSTEM_INFO *psi); CDynamicLibrary dll("kernel32.dll"); if (PFN pfn = (PFN)GetProcAddress(dll.m_hModule, String("GetNativeSystemInfo"))) { SYSTEM_INFO si; pfn(&si); return si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64; } #endif return false; }
static return_val initORL( void ) { orl_file_flags flags; orl_machine_type machine_type; orl_return o_error = ORL_OKAY; orl_file_format type; bool byte_swap; ORLSetFuncs( orl_cli_funcs, objRead, objSeek, MemAlloc, MemFree ); ORLHnd = ORLInit( &orl_cli_funcs ); if( ORLHnd != ORL_NULL_HANDLE ) { type = ORLFileIdentify( ORLHnd, NULL ); if( type == ORL_UNRECOGNIZED_FORMAT ) { PrintErrorMsg( RC_OKAY, WHERE_NOT_COFF_ELF ); return( RC_ERROR ); } ObjFileHnd = ORLFileInit( ORLHnd, NULL, type ); if( ObjFileHnd != ORL_NULL_HANDLE ) { // check byte order flags = ORLFileGetFlags( ObjFileHnd ); byte_swap = false; #ifdef __BIG_ENDIAN__ if( flags & ORL_FILE_FLAG_LITTLE_ENDIAN ) { byte_swap = true; } #else if( flags & ORL_FILE_FLAG_BIG_ENDIAN ) { byte_swap = true; } #endif // check intended machine type machine_type = GetMachineType(); switch( machine_type ) { // If there's no machine specific code, the CPU we choose shouldn't // matter; there are some object files like this. case ORL_MACHINE_TYPE_NONE: case ORL_MACHINE_TYPE_ALPHA: if( DisInit( DISCPU_axp, &DHnd, byte_swap ) != DR_OK ) { ORLFini( ORLHnd ); PrintErrorMsg( RC_OKAY, WHERE_UNSUPPORTED_PROC ); return( RC_ERROR ); } break; case ORL_MACHINE_TYPE_PPC601: if( DisInit( DISCPU_ppc, &DHnd, byte_swap ) != DR_OK ) { ORLFini( ORLHnd ); PrintErrorMsg( RC_OKAY, WHERE_UNSUPPORTED_PROC ); return( RC_ERROR ); } // PAS assembler expects "", not \" for quotes. if( (Options & METAWARE_COMPATIBLE) == 0 ) { QuoteChar = '\"'; } break; case ORL_MACHINE_TYPE_R3000: case ORL_MACHINE_TYPE_R4000: if( DisInit( DISCPU_mips, &DHnd, byte_swap ) != DR_OK ) { ORLFini( ORLHnd ); PrintErrorMsg( RC_OKAY, WHERE_UNSUPPORTED_PROC ); return( RC_ERROR ); } break; case ORL_MACHINE_TYPE_I386: case ORL_MACHINE_TYPE_I8086: if( DisInit( DISCPU_x86, &DHnd, byte_swap ) != DR_OK ) { ORLFini( ORLHnd ); PrintErrorMsg( RC_OKAY, WHERE_UNSUPPORTED_PROC ); return( RC_ERROR ); } break; case ORL_MACHINE_TYPE_AMD64: if( DisInit( DISCPU_x64, &DHnd, byte_swap ) != DR_OK ) { ORLFini( ORLHnd ); PrintErrorMsg( RC_OKAY, WHERE_UNSUPPORTED_PROC ); return( RC_ERROR ); } break; case ORL_MACHINE_TYPE_SPARC: case ORL_MACHINE_TYPE_SPARCPLUS: if( DisInit( DISCPU_sparc, &DHnd, byte_swap ) != DR_OK ) { ORLFini( ORLHnd ); PrintErrorMsg( RC_OKAY, WHERE_UNSUPPORTED_PROC ); return( RC_ERROR ); } break; default: ORLFini( ORLHnd ); PrintErrorMsg( RC_OKAY, WHERE_UNSUPPORTED_PROC ); return( RC_ERROR ); } return( RC_OKAY ); } else { o_error = ORLGetError( ORLHnd ); ORLFini( ORLHnd ); // An "out of memory" error is not necessarily what it seems. // The ORL returns this error when encountering a bad or // unrecognized object file record. if( o_error == ORL_OUT_OF_MEMORY ) { PrintErrorMsg( RC_OUT_OF_MEMORY, WHERE_OPENING_ORL ); return( RC_OUT_OF_MEMORY ); } else { PrintErrorMsg( RC_ERROR, WHERE_OPENING_ORL ); return( RC_ERROR ); } } } else { return( RC_OUT_OF_MEMORY ); } }
//修改注册号 bool COperator::ModifyRegisterEx(TSSmartDocEx *pDocEx, TSCmdBuffer *pBuffer, int nPort) { bool bRet = false; unsigned char Buffer[256]; switch(GetMachineType(pDocEx->pChildDoc[pDocEx->nPortNo]) ) { case MACHINE_TYPE_5301: { TSDeviceInfo Info; bool bFound = false; unsigned char sPortID[16]; memset(sPortID, 0, sizeof(sPortID)); for( int p=0; p<3; p++) { MakeBuf_SearchPort(&pDocEx->pChildDoc[0]->DeviceInfo, pBuffer, nPort); if( SendRequest(pDocEx->pChildDoc[0], pBuffer) == RET_OK ) { if( UnMakeDeviceBuffer(pBuffer) == RET_OK && !pBuffer->pBuffer[2] ) { bFound = true; break; } } } if( !bFound ) { printf("搜索端口%d失败! 不能修改端口注册号!\n", nPort); return false; } bFound = false ; for( p =0; p < 3; p++ ) { MakeBuf_GetPortPar(&pDocEx->pChildDoc[pDocEx->nPortNo]->DeviceInfo, pBuffer, nPort); if( SendRequest(pDocEx->pChildDoc[0], pBuffer) == RET_OK ) { if( UnMakeDeviceBuffer(pBuffer) == RET_OK && !pBuffer->pBuffer[2] ) { bFound = true; SVC_HEX_2_DSP(&pBuffer->pBuffer[4], sPortID, 4); break; } } } if( !bFound ) { printf("得到端口%d的设备失败! 不能修改端口注册号!\n", nPort); return false; } //匹配原来端口的硬件 int nIndex = GetPos(pDocEx, nPort); if( nIndex <= 0 ) { printf("端口%d有硬件变动! 设备档案表中没有此终端记录! 设备ID:%s\n", nPort, sPortID); /* MakeBuf_ClearPortData(&pDocEx->pChildDoc[pDocEx->nPortNo]->DeviceInfo, pBuffer, nPort); if( SendRequest(pDocEx->pChildDoc[0], pBuffer) == RET_OK ) { if( UnMakeDeviceBuffer(pBuffer) == RET_OK && !pBuffer->pBuffer[2] ) { return true; } }*/ return false; } //比较设备ID if( strcmp((char*)sPortID, pDocEx->pChildDoc[nIndex]->m_szDeviceID) ) { printf("端口%d的设备已更换, 查找端口%d上新的相关设备!\n", nPort, nPort); nIndex = GetPosEx(pDocEx, (char*)sPortID); if( nIndex <= 0 ) { printf("端口%d(设备ID:%s) 与终端设备%s的设备ID不同, 不能修改端口注册号!\n", nPort, sPortID, pDocEx->pChildDoc[nIndex]->m_szRegister); return false; } } /* if( pBuffer->pBuffer[8] != pDocEx->pChildDoc[nIndex]->DeviceInfo.nAddr ) { printf("端口%d(机号:%d) 与终端设备%s(机号:%d)的机号不同, 不能修改端口注册号!\n", nPort, pBuffer->pBuffer[8] , pDocEx->pChildDoc[nIndex]->m_szRegister, pDocEx->pChildDoc[nIndex]->DeviceInfo.nAddr); return false; } */ printf("端口:%d, 端口设备ID号:%s ,与终端设备ID相同, 准备修改端口注册号为:%s!\n", nPort, sPortID, pDocEx->pChildDoc[nIndex]->m_szRegister); memcpy(&Info, &pDocEx->pChildDoc[nIndex]->DeviceInfo, sizeof(Info)); //更改Lport服务器该端口注册号 for( int n=0; n<3; n++) { SVC_DSP_2_HEX((unsigned char *)pDocEx->pChildDoc[nIndex]->m_szRegister, Buffer, 4); MakeBuf_SetPortRegNoAndMacNo( pDocEx->pDeviceInfo, pBuffer, nPort, Buffer, pDocEx->pChildDoc[nIndex]->DeviceInfo.nAddr); if ( SendRequest(pDocEx->pChildDoc[0], pBuffer) == RET_OK ) { if( UnMakeDeviceBuffer(pBuffer) == RET_OK && !pBuffer->pBuffer[2] ) { CString strText; strText.Format("端口%d注册号与实际注册号不符! 修改端口%d注册号成功!", nPort, nPort); ReportLog(pDocEx, NULL, RET_OK, "实时收集", strText.GetBuffer(0)); printf("%s\n", strText.GetBuffer(0)); bRet = true; break; } } } } break; default: break; } return bRet; }
//修改注册号 bool COperator::ModifyRegister(TSSmartDoc *pDoc, TSCmdBuffer *pBuffer) { unsigned char newRegNo[4]; bool bRet = false; unsigned char sID[256]; memset(sID, 0, sizeof(sID)); SVC_DSP_2_HEX((BYTE*)pDoc->m_szDeviceID, sID, 4); sID[4] = pDoc->DeviceInfo.nAddr; MakeBuf_SetAddr(&pDoc->DeviceInfo, pBuffer, sID); for(int k=0; k<3; k++) { if( SendRequest(pDoc, pBuffer) == RET_OK ) { if( UnMakeDeviceBuffer(pBuffer) == RET_OK && !pBuffer->pBuffer[2] ) { bRet = true; break; } } } #if 0 MakeBuf_GetID(&pDoc->DeviceInfo, pBuffer); for(int k=0; k<3; k++) { if(SendRequest(pDoc, pBuffer) == RET_OK ) { if( UnMakeDeviceBuffer(pBuffer) == RET_OK && !pBuffer->pBuffer[2] ) { unsigned char szTemp[256]; unsigned char *pHardBuffer = pBuffer->pBuffer+4; memset(szTemp, 0, sizeof(szTemp)); SVC_HEX_2_DSP(pHardBuffer, szTemp, 4); if( strcmp(pDoc->m_szDeviceID, ( char*)szTemp) ) { printf("设备ID不同, 不能更改注册号!\n"); return false; } else { //strcpy(pDoc->m_szDeviceID, ( char*)szTemp); bRet = true; break; } } } } #endif if( !bRet ) { printf("设备ID不同, 不能更改注册号!\n"); return false; } bRet = false; MakeBuf_Debug_GetMainPar(&pDoc->DeviceInfo, pBuffer); for(k=0; k<3; k++) { if( SendRequest(pDoc, pBuffer) == RET_OK ) { if( UnMakeDeviceBuffer(pBuffer) == RET_OK && !pBuffer->pBuffer[2] ) { char szReg[32]; memset(szReg, 0, sizeof(szReg)); if( !strcmp(pDoc->m_szMacCode, "5301") || pDoc->m_nParentID > 0 ) SVC_HEX_2_DSP(pBuffer->pBuffer+8, (unsigned char*)szReg, 4); else SVC_HEX_2_DSP(pBuffer->pBuffer+4, (unsigned char*)szReg, 4); strcpy(pDoc->m_szRegister, ( char*)szReg); strcpy(pDoc->DeviceInfo.sRegNo, ( char*)szReg); printf("机器正在使用的注册号........%s...!\n", ( char*)szReg); bRet = true; break; } } } if( !bRet ) { return false; } bRet = false; switch( GetMachineType(pDoc) ) { case MACHINE_TYPE_5301: { for(int i=0;i<3;i++) { SVC_DSP_2_HEX((unsigned char *)pDoc->m_szRegister, newRegNo, 4); MakeBuf_SetLportNewRegNo(&pDoc->DeviceInfo, pBuffer, newRegNo); if(SendRequest(pDoc, pBuffer) == RET_OK ) { if( UnMakeDeviceBuffer(pBuffer) == RET_OK && !pBuffer->pBuffer[2] ) { bRet = true; break; } } } } break; case MACHINE_TYPE_0201://增值机 case MACHINE_TYPE_0226://收费机 case MACHINE_TYPE_0228://车载机 case MACHINE_TYPE_0230://管理机 case MACHINE_TYPE_0232://上机上网机 case MACHINE_TYPE_0234://淋浴管理机 case MACHINE_TYPE_0240://售票机 case MACHINE_TYPE_0130://身份识别机 case MACHINE_TYPE_0140://检票机 { //查询终端 CString strSQL; strSQL.Format("SELECT * FROM Smart_Machine WHERE SMT_Authno = %d", pDoc->m_nAuthID); unsigned char sBuffer[256]; char sValue[256]; // GetFieldStringValueEx(nRec, "Smt_RegNo", (char*)sValue); // SVC_DSP_2_HEX(sValue, sBuffer, 4); for(int i=0;i<3;i++) { MakeBuf_SetRegNo(&pDoc->DeviceInfo, pBuffer, sBuffer); if(SendRequest(pDoc, pBuffer) == RET_OK ) { if( UnMakeDeviceBuffer(pBuffer) == RET_OK && !pBuffer->pBuffer[2] ) { strcpy(pDoc->m_szRegister, ( char*)sValue); strcpy(pDoc->DeviceInfo.sRegNo, ( char*)sValue); //bRet = true; printf("更改注册号为........%s...!\n", ( char*)sValue); break; } } } } break; default: break; } return bRet; }
//处理扎帐纪录 long CCollectionData::Process_StateData(TSSmartDocEx *pDocEx,TSSmartTask *pTask,TSCmdBuffer *pBuffer,unsigned char *ucRawData,int nPortNo) { unsigned char ucFlowNo[2]; int nFlowNo; //CString strText; OutputRealData(pTask, pDocEx->pChildDoc[nPortNo], 0x03, ucRawData, 256); //printf("nPortNo = %d 扎帐流水=%d\n",nPortNo,ucRawData[6]*256+ucRawData[7]); ucFlowNo[0] = ucRawData[6]; ucFlowNo[1] = ucRawData[7]; for(int i=0; i<3; i++) { if( GetMachineType(m_pDocEx->pChildDoc[m_pDocEx->nPortNo]) == MACHINE_TYPE_5301) MakeBuf_ConfirmData(&pDocEx->pChildDoc[nPortNo]->DeviceInfo, pBuffer, ucFlowNo); else MakeBuf_ConfirmStateData(&pDocEx->pChildDoc[nPortNo]->DeviceInfo, pBuffer, ucFlowNo); /*printf("%.2X%.2X%.2X%.2X%.2X%.2X%.2X\n",pBuffer->pBuffer[0], pBuffer->pBuffer[1], pBuffer->pBuffer[2], pBuffer->pBuffer[3], pBuffer->pBuffer[4], pBuffer->pBuffer[5], pBuffer->pBuffer[6]);*/ if( SendRequest(pDocEx->pChildDoc[nPortNo], pBuffer) == RET_OK ) { //做标记成功,退出 if( UnMakeDeviceBuffer(pBuffer) == RET_OK && pBuffer->pBuffer[2]==0x00 ) { return true; } } else { //printf("做扎帐记录失败\n"); Sleep(100); } } return RET_OK; CSmartJZSRCTable SRCTable; //unsigned char ucFlowNo[2]; //int nFlowNo; CString strText; ucFlowNo[0] = ucRawData[6]; ucFlowNo[1] = ucRawData[7]; nFlowNo = ucFlowNo[0]*256+ucFlowNo[1]; if( nPortNo < 0 || nPortNo >= pDocEx->nChildDoc ) { printf("端口%d非法!\n", nPortNo); nPortNo = pDocEx->nPortNo; } if( nPortNo > 0 ) { pDocEx->pChildDoc[nPortNo]->m_dwTryCount = m_pDocEx->pChildDoc[0]->m_dwTryCount; } char szStatus[64]; long nTick = GetTickCount(); //modified by lina 20050403 //CRC检测 OutputRealData(pTask, pDocEx->pChildDoc[nPortNo], 0x03, ucRawData, 256); if(nFlowNo == 0xFFFF) pDocEx->pChildDoc[nPortNo]->m_wFlowNo = 0x0000; else pDocEx->pChildDoc[nPortNo]->m_wFlowNo += 1; ConfirmJZData(pDocEx, pTask, pBuffer, ucFlowNo, pDocEx->nPortNo, 3); /*if( OutputRealData(pTask, pDocEx->pChildDoc[nPortNo], 0x03, ucRawData, 256) == RET_OK ) { //数据确认流程,不成功重试3次 if(nFlowNo == 0xFFFF) pDocEx->pChildDoc[nPortNo]->m_wFlowNo = 0x0000; else pDocEx->pChildDoc[nPortNo]->m_wFlowNo += 1; ConfirmJZData(pDocEx, pTask, pBuffer, ucFlowNo, pDocEx->nPortNo, 3); //ConfirmData(pDocEx,pTask,pBuffer,ucFlowNo,pDocEx->nPortNo, 3); strcpy(szStatus, "保存成功!"); } else { printf("保存失败, 没有做标记, 重复收集此数!!!!\n"); strcpy(szStatus, "保存失败!没有做标记!重复收集此数!"); }*/ WriteLog("扎帐流水号%d, 开始收数时间点:%ld, 收数时间(毫秒):%d, 保存时间(毫秒):%s, 本笔总耗费时间(毫秒):%d. 状态:%s.", nFlowNo, pDocEx->pChildDoc[nPortNo]->m_dwTryCount, nTick - pDocEx->pChildDoc[nPortNo]->m_dwTryCount, GetTickCount() - nTick, GetTickCount() - pDocEx->pChildDoc[nPortNo]->m_dwTryCount, szStatus); return RET_OK; }
//*---------------------------------------------------------------------------- //*函数: long ProcessRequest() //*功能: 处理具体的业务请求 //*参数: 无 //*返回: 见系统返回值说明 //*说明: //*---------------------------------------------------------------------------- long CCollectionData::ProcessData(TSSmartDocEx *pDocEx, TSSmartTask *pTask, TSCmdBuffer *pBuffer) { int nIndex = m_pDocEx->nPortNo ; long nRet = RET_NG; //接收成功统计 InterlockedExchangeAdd((LONG*)&gSendRecv, (LONG)(GetTickCount()- pDocEx->pChildDoc[pDocEx->nPortNo]->m_dwLastTick)); InterlockedIncrement((LONG*)&gTrySendRecv); switch(GetMachineType(m_pDocEx->pChildDoc[nIndex])) { case MACHINE_TYPE_5301://服务器 nRet = LPort_Process(pDocEx,pTask,pBuffer); break; case MACHINE_TYPE_0201://增值机 case MACHINE_TYPE_0226://收费机 case MACHINE_TYPE_0228://车载机 case MACHINE_TYPE_0230://管理机 case MACHINE_TYPE_0232://上机上网机 case MACHINE_TYPE_0234://淋浴管理机 case MACHINE_TYPE_0240://售票机 case MACHINE_TYPE_0130://身份识别机 case MACHINE_TYPE_0140://检票机 case MACHINE_TYPE_0248://上海淋浴转帐机 { unsigned char ucRawData[256]; #ifdef __DEBUG_OUTPUT__ /*for(int i=0; i< 256; i++) { printf("%02X ", pBuffer->pBuffer[i]); } printf("\n");*/ #endif memset(ucRawData, 0, sizeof(ucRawData)); switch(pBuffer->pBuffer[2]) { case 0x17: if( ReadJZRecord(pDocEx, pTask, pBuffer) ) { memcpy(ucRawData, &pBuffer->pBuffer[4], pBuffer->pBuffer[3]); nRet = Process_StateData(pDocEx,pTask,pBuffer,&ucRawData[0], 0); } else nRet = RET_NG; break; case 0x0D: { CString strText; strText.Format("机器%d申请签到!", pDocEx->pChildDoc[pDocEx->nPortNo]->m_nAuthID); ReportLog(pDocEx->pChildDoc[0], pTask, RET_OK, "实时收数", strText.GetBuffer(0)); CSingInServer SingIn; SingIn.SignInProcess(pDocEx, pBuffer, 0, pTask); break; } case 0x00: memcpy(ucRawData, &pBuffer->pBuffer[4], pBuffer->pBuffer[3]); nRet = Process_DealTypeData(pDocEx,pTask,pBuffer,&ucRawData[0], 0); break; default: nRet = RET_NG; break; } } break; case MACHINE_TYPE_0121://计时宝 { unsigned char ucRawData[256]; #ifdef __DEBUG_OUTPUT__ for(int i=0; i< 256; i++) { printf("%02X ", pBuffer->pBuffer[i]); } printf("\n"); #endif memset(ucRawData, 0, sizeof(ucRawData)); switch(pBuffer->pBuffer[2]) { case 0x17: if( ReadJZRecord(pDocEx, pTask, pBuffer) ) { memcpy(ucRawData, &pBuffer->pBuffer[4], pBuffer->pBuffer[3]); nRet = Process_StateData(pDocEx,pTask,pBuffer,&ucRawData[0], 0); } else nRet = RET_NG; break; case 0x0D: { CString strText; strText.Format("机器%d申请签到!", pDocEx->pChildDoc[pDocEx->nPortNo]->m_nAuthID); ReportLog(pDocEx->pChildDoc[0], pTask, RET_OK, "实时收数", strText.GetBuffer(0)); CSingInServer SingIn; SingIn.SignInProcess(pDocEx, pBuffer, 0, pTask); break; } case 0x00: memcpy(ucRawData, pBuffer->pBuffer+4, pBuffer->pBuffer[3]); nRet = Process_IdentifyData(pDocEx,pTask,pBuffer,ucRawData, 0); break; default: nRet = RET_NG; break; } } break; case MACHINE_TYPE_0224://挂失机 { unsigned char ucRawData[256]; #ifdef __DEBUG_OUTPUT__ for(int i=0; i< 256; i++) { printf("%02X ", pBuffer->pBuffer[i]); } printf("\n"); #endif memset(ucRawData, 0, sizeof(ucRawData)); switch(pBuffer->pBuffer[2]) { case 0x17: if( ReadJZRecord(pDocEx, pTask, pBuffer) ) { memcpy(ucRawData, &pBuffer->pBuffer[4], pBuffer->pBuffer[3]); nRet = Process_StateData(pDocEx,pTask,pBuffer,&ucRawData[0], 0); } else nRet = RET_NG; break; case 0x0D: { CString strText; strText.Format("机器%d申请签到!", pDocEx->pChildDoc[pDocEx->nPortNo]->m_nAuthID); ReportLog(pDocEx->pChildDoc[0], pTask, RET_OK, "实时收数", strText.GetBuffer(0)); CSingInServer SingIn; SingIn.SignInProcess(pDocEx, pBuffer, 0, pTask); break; } case 0x00: memcpy(ucRawData, &pBuffer->pBuffer[4], pBuffer->pBuffer[3]); nRet = Process_GSJData(pDocEx,pTask,pBuffer,&ucRawData[0], 0); break; default: nRet = RET_NG; break; } } break; default: break; } return nRet; }
//*---------------------------------------------------------------------------- //*函数: long LPort_DataProcess(TSSmartDocEx *pDocEx,TSSmartTask *pTask,TSCmdBuffer *pBuffer) //*功能: 处理具体的业务请求 //*参数: 无 //*返回: 见系统返回值说明 //*说明: //*---------------------------------------------------------------------------- long CCollectionData::LPort_Process(TSSmartDocEx *pDocEx,TSSmartTask *pTask,TSCmdBuffer *pBuffer) { unsigned char ucRawData[256]; int nTotalPortNo, nPortNo; memset(ucRawData, 0, sizeof(ucRawData)); memcpy(ucRawData, &pBuffer->pBuffer[4], pBuffer->pBuffer[3]); #ifdef __DEBUG_OUTPUT__ for(int i=0; i< 256; i++) { printf("%02X ", pBuffer->pBuffer[i]); } printf("\n"); #endif int nTempLen = pBuffer->nCmdSize ; unsigned char sTempData[256]; memcpy(sTempData, pBuffer->pBuffer, 256); //不等于端口总数 if( ucRawData[2] != pDocEx->pChildDoc[pDocEx->nPortNo]->m_nPortCount ) { CString strString; strString.Format("收集LPort数据时, 返回的端口总数与数据库端口总数不相等. 返回的端口数为:%d, 档案表为:%d! 您的LPort参数设置不正确, 请重新校对LPort的参数", ucRawData[2], pDocEx->pChildDoc[0]->m_nPortCount); ReportLog(pDocEx, pTask, RET_SYSERROR, "实时收数", strString.GetBuffer(0) ); if( !ResetDevice(pDocEx->pChildDoc[pDocEx->nPortNo], pBuffer) ) { printf("1---实时收集LPORT数据时,返回的端口总数不等于参数内的端口总数\n"); ReportLog(pDocEx, pTask, RET_SYSERROR, "实时收数", "收集LPort数据时, 由于返回的端口总数不相等, 复位时出错!"); } return RET_SYSERROR; } /* LportState(pDocEx,pTask,pBuffer,ucRawData); if( !LportState(pDocEx,pTask,pBuffer,ucRawData) ) { InterlockedIncrement((LONG*)&gNotFound); //Sleep(50); return RET_NG; }*/ nTotalPortNo = ucRawData[2]; nPortNo = ucRawData[3+nTotalPortNo]; //端口数不对, 复位 if( nPortNo > nTotalPortNo ) { printf("1---实时收集LPORT数据时,返回的端口总数不等于参数内的端口总数\n"); ResetDevice(pDocEx->pChildDoc[pDocEx->nPortNo], pBuffer); return RET_SYSERROR; } nPortNo = GetPos(pDocEx, nPortNo); pBuffer->nCmdSize = nTempLen; memset(pBuffer->pBuffer, 0, pBuffer->nBufferSize); memcpy(pBuffer->pBuffer, sTempData, 256); long nRet = RET_NG ; switch(GetMacDataType(pBuffer)) { case MACDATA_TYPE_JY://为交易类型数据 { int nType = MACHINE_TYPE_5301 ; if( nPortNo < 0 ) { char szDataReg[32]; sprintf(szDataReg, "%.2X%.2X%.2X%.2X", ucRawData[5+nTotalPortNo],ucRawData[6+nTotalPortNo],ucRawData[7+nTotalPortNo],ucRawData[8+nTotalPortNo]); if( nPortNo < 0 ) { //是否在本服务器内 int iPos = GetPos(pDocEx, szDataReg); if( iPos > 0 ) { nPortNo = iPos; } else { TSSmartDoc doc; //档案表中有数据 if( FindMachine(szDataReg, &doc) ) nType = GetMachineType(&doc); } } } nType = GetMachineType(pDocEx->pChildDoc[nPortNo]); switch( nType) { case MACHINE_TYPE_5301://服务器 case MACHINE_TYPE_0201://增值机 case MACHINE_TYPE_0226://收费机 case MACHINE_TYPE_0228://车载机 case MACHINE_TYPE_0230://管理机 case MACHINE_TYPE_0232://上机上网机 case MACHINE_TYPE_0234://淋浴管理机 case MACHINE_TYPE_0240://售票机 case MACHINE_TYPE_0130://身份识别机 case MACHINE_TYPE_0140://检票机 case MACHINE_TYPE_0248://上海理工转帐机 nRet = Process_DealTypeData(pDocEx,pTask,pBuffer,&ucRawData[5+nTotalPortNo],nPortNo); break; case MACHINE_TYPE_0121://计时宝 nRet = Process_IdentifyData(pDocEx,pTask,pBuffer,&ucRawData[5+nTotalPortNo],nPortNo); break; case MACHINE_TYPE_0224://挂失机 nRet = Process_GSJData(pDocEx,pTask,pBuffer,&ucRawData[5+nTotalPortNo],nPortNo); break; default: break; } } break; case MACDATA_TYPE_ZZ://为扎帐数据 nRet = Process_StateData(pDocEx,pTask,pBuffer,&ucRawData[5+nTotalPortNo],pDocEx->nPortNo); break; case MACDATA_TYPE_BZ://为补助数据 nRet = Process_AssisData(pDocEx,pTask,pBuffer,&ucRawData[5+nTotalPortNo],nPortNo); break; default: break; } LportState(pDocEx,pTask,pBuffer,ucRawData); /*if( !LportState(pDocEx,pTask,pBuffer,ucRawData) ) { InterlockedIncrement((LONG*)&gNotFound); Sleep(50); //printf("处理LPORT%.8X状态返回\n",pDocEx->pChildDoc[0]->m_nAuthID); return RET_NG; }*/ Sleep(100); return nRet; }
return_val DoPass1( orl_sec_handle shnd, unsigned_8 *contents, orl_sec_size size, ref_list sec_ref_list, scantab_ptr stl ) // perform pass 1 on one section { orl_sec_offset loop; dis_dec_ins decoded; dis_value value; dis_return dr; unnamed_label_return_struct rs; return_val error; unsigned i; ref_entry r_entry; dis_inst_flags flags; orl_sec_offset op_pos; int is_intel; int adjusted; sa_disasm_struct sds; sds.data = contents; sds.last = size - 1; if( sec_ref_list != NULL ) { r_entry = sec_ref_list->first; } else { r_entry = NULL; } flags.u.all = DIF_NONE; if( GetMachineType() == ORL_MACHINE_TYPE_I386 ) { if( ( GetFormat() != ORL_OMF ) || ( ORLSecGetFlags( shnd ) & ORL_SEC_FLAG_USE_32 ) ) { flags.u.x86 = DIF_X86_USE32_FLAGS; } is_intel = 1; } else { is_intel = IsIntelx86(); } for( loop = 0; loop < size; loop += decoded.size ) { // skip data in code segment while( stl && ( loop > stl->end ) ) { stl = stl->next; } if( stl && ( loop >= stl->start ) ) { decoded.size = 0; if( is_intel ) { r_entry = DoPass1Relocs( contents, r_entry, loop, stl->end ); } loop = stl->end; stl = stl->next; continue; } // data may not be listed in scan table, but a fixup at this offset will // give it away while( r_entry && ( ( r_entry->offset < loop ) || SkipRef(r_entry) ) ) { r_entry = r_entry->next; } if( r_entry && ( r_entry->offset == loop ) ) { if( is_intel || IsDataReloc( r_entry ) ) { // we just skip the data op_pos = loop; decoded.size = 0; loop += RelocSize( r_entry ); r_entry = DoPass1Relocs( contents, r_entry, op_pos, loop ); continue; } } DisDecodeInit( &DHnd, &decoded ); decoded.flags.u.all |= flags.u.all; sds.offs = loop; dr = DisDecode( &DHnd, &sds, &decoded ); // if an invalid instruction was found, there is nothing we can do. if( dr != DR_OK ) return( RC_ERROR ); for( i = 0; i < decoded.num_ops; ++i ) { adjusted = 0; op_pos = loop + decoded.op[i].op_position; switch( decoded.op[i].type & DO_MASK ) { case DO_IMMED: if( !is_intel ) break; /* fall through */ case DO_RELATIVE: case DO_MEMORY_REL: if( ( decoded.op[i].type & DO_MASK ) != DO_IMMED ) { decoded.op[i].value += loop; adjusted = 1; } /* fall through */ case DO_ABSOLUTE: case DO_MEMORY_ABS: // Check for reloc at this location while( r_entry && r_entry->offset < op_pos ) { r_entry = r_entry->next; } if( r_entry && ( r_entry->offset == op_pos ) ) { if( is_intel && r_entry->label->shnd && ( r_entry->type != ORL_RELOC_TYPE_SEGMENT ) && ( r_entry->label->type == LTYP_SECTION ) ) { /* For section offsets under intel we MUST generate a * local label because the offset might change when the * code is re-assembled */ if( r_entry->addend ) { r_entry->no_val = 0; CreateUnnamedLabel( r_entry->label->shnd, HandleAddend( r_entry ), &rs ); } else { r_entry->no_val = 1; if( adjusted && isSelfReloc( r_entry ) && ( r_entry->label->type == LTYP_SECTION ) ) { /* This is a kludgy reloc done under OMF */ decoded.op[i].value -= loop; decoded.op[i].value -= decoded.size; switch( RelocSize( r_entry ) ) { case( 2 ): decoded.op[i].value = (uint_16)(decoded.op[i].value); case( 1 ): decoded.op[i].value = (uint_8)(decoded.op[i].value); } } value = decoded.op[i].value; if( value < 0 || value > ORLSecGetSize( r_entry->label->shnd ) ) { // can't fold it into the label position - BBB Oct 28, 1996 value = 0; r_entry->no_val = 0; } CreateUnnamedLabel( r_entry->label->shnd, value, &rs ); } if( rs.error != RC_OKAY ) return( rs.error ); r_entry->label = rs.entry; } else { // fixme: got to handle other types of relocs here } } else if( ( decoded.op[i].type & DO_MASK ) != DO_IMMED ) { if( decoded.op[i].base == DR_NONE && decoded.op[i].index == DR_NONE ) { switch( decoded.op[i].type & DO_MASK ) { case DO_MEMORY_REL: case DO_MEMORY_ABS: // use decoded instruction size for absolute memory on amd64. // the cpu will reference rip _after_ the instruction is // completely fetched and decoded. // relocations in pass2 are not applied because they break // relative memory references if no relocation is present! if( GetMachineType() == ORL_MACHINE_TYPE_AMD64 ) { decoded.op[i].value += decoded.size; // I don't know if this is neccessary, but it will generate // labels for memory references if no symbol is present // (ex: executable file) CreateUnnamedLabel( shnd, decoded.op[i].value, &rs ); if( rs.error != RC_OKAY ) return( rs.error ); error = CreateUnnamedLabelRef( shnd, rs.entry, op_pos ); } else { // create an LTYP_ABSOLUTE label CreateAbsoluteLabel( shnd, decoded.op[i].value, &rs ); if( rs.error != RC_OKAY ) return( rs.error ); error = CreateAbsoluteLabelRef( shnd, rs.entry, op_pos ); } break; default: // create an LTYP_UNNAMED label CreateUnnamedLabel( shnd, decoded.op[i].value, &rs ); if( rs.error != RC_OKAY ) return( rs.error ); error = CreateUnnamedLabelRef( shnd, rs.entry, op_pos ); break; } if( error != RC_OKAY ) { return( error ); } } } break; } } } return( RC_OKAY ); }
void GetIpAddr(struct olsrv2* olsr, union olsr_ip_addr* addr, char* str) { //#if defined (WIN32) || defined (_WIN32) || defined (__WIN64) if(olsr->olsr_cnf->ip_version == AF_INET) { int i[4], n, j; sscanf(str, "%d.%d.%d.%d",&i[0],&i[1],&i[2],&i[3]); //changed for MAC mismatch /* for(n = 0; n <= 3; n++) { addr->v4 += i[n] << (n*8); }*/ if (GetMachineType()== B_ENDIAN) { for(n = 3, j=0; n >= 0; n--, j++) { addr->v4 += i[n] << (j*8); } } else { for(n = 0; n <= 3; n++) { addr->v4 += i[n] << (n*8); } } //changed for MAC mismatch end } else { int i[8], n; sscanf(str, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",&i[0],&i[1],&i[2],&i[3],&i[4],&i[5],&i[6],&i[7]); for(n = 0; n <= 7; n++) { //addr->v6.s6_addr_8[n] = (olsr_u8_t)(addr->v6.s6_addr_8[n] + i[n]); addr->v6.s6_addr_16[n] = (olsr_u16_t)htons((u_short)i[n]); } } /*#else if(olsr->olsr_cnf->ip_version == AF_INET) { int i[4], n; sscanf(str, "%d.%d.%d.%d",&i[0],&i[1],&i[2],&i[3]); for(n = 0; n <= 3; n++) { addr->v4 += i[n] << (n*8); } } else { int i[8], n; sscanf(str, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",&i[0],&i[1],&i[2],&i[3],&i[4],&i[5],&i[6],&i[7]); for(n = 0; n <= 7; n++) { addr->v6.s6_addr_8[n] += i[n]; } } // inet_pton(olsr->olsr_cnf->ip_version, str, addr); #endif*/ }
num_errors DoPass2( section_ptr sec, unsigned_8 *contents, orl_sec_size size, label_list sec_label_list, ref_list sec_ref_list ) // perform pass 2 on one section { struct pass2 data; label_entry l_entry; dis_dec_ins decoded; char name[ MAX_INS_NAME ]; char ops[ MAX_OBJ_NAME + 24 ]; // at most 1 label/relocation per instruction, plus room for registers, brackets and other crap dis_inst_flags flags; scantab_ptr st; int is_intel; sa_disasm_struct sds; char *FPU_fixup; int pos_tabs; bool is32bit; routineBase = 0; st = sec->scan; data.size = size; sds.data = contents; sds.last = size - 1; l_entry = NULL; if( sec_label_list != NULL ) { l_entry = sec_label_list->first; } if( sec_ref_list != NULL ) { data.r_entry = sec_ref_list->first; } else { data.r_entry = NULL; } data.disassembly_errors = 0; if( source_mix ) { GetSourceFile( sec ); } PrintHeader( sec ); if( size && sec_label_list ) PrintAssumeHeader( sec ); flags.u.all = DIF_NONE; if( GetMachineType() == ORL_MACHINE_TYPE_I386 ) { if( ( GetFormat() != ORL_OMF ) || ( ORLSecGetFlags( sec->shnd ) & ORL_SEC_FLAG_USE_32 ) ) { flags.u.x86 = DIF_X86_USE32_FLAGS; } is_intel = 1; } else { is_intel = IsIntelx86(); } is32bit = ( size >= 0x10000 ); for( data.loop = 0; data.loop < size; data.loop += decoded.size ) { // process data in code segment while( st && ( data.loop > st->end ) ) { st = st->next; } if( st && ( data.loop >= st->start ) ) { decoded.size = 0; processDataInCode( sec, contents, &data, st->end - data.loop, &l_entry ); st = st->next; continue; } // data may not be listed in scan table, but a fixup at this offset will // give it away while( data.r_entry && ( data.r_entry->offset < data.loop ) ) { data.r_entry = data.r_entry->next; } FPU_fixup = processFpuEmulatorFixup( &data.r_entry, data.loop ); if( data.r_entry && ( data.r_entry->offset == data.loop ) ) { if( is_intel || IsDataReloc( data.r_entry ) ) { // we just skip the data decoded.size = 0; processDataInCode( sec, contents, &data, RelocSize( data.r_entry ), &l_entry ); continue; } } if( source_mix ) { MixSource( data.loop ); } DisDecodeInit( &DHnd, &decoded ); decoded.flags.u.all |= flags.u.all; sds.offs = data.loop; DisDecode( &DHnd, &sds, &decoded ); if( sec_label_list ) { l_entry = handleLabels( sec->name, data.loop, data.loop + decoded.size, l_entry, size ); if( ( l_entry != NULL ) && ( l_entry->offset > data.loop ) && ( l_entry->offset < data.loop + decoded.size ) ) { /* If we have a label planted in the middle of this instruction (see inline memchr for example), put out a couple of data bytes, and then restart decode and label process from offset of actual label. */ decoded.size = 0; processDataInCode( sec, contents, &data, l_entry->offset - data.loop, &l_entry ); continue; } } DisFormat( &DHnd, &data, &decoded, DFormat, name, sizeof( name ), ops, sizeof( ops ) ); if( FPU_fixup != NULL ) { if( !(DFormat & DFF_ASM) ) { BufferAlignToTab( PREFIX_SIZE_TABS ); } BufferStore( "\t%sFPU fixup %s\n", CommentString, FPU_fixup ); } if( !(DFormat & DFF_ASM) ) { unsigned_64 *tmp_64; unsigned_32 *tmp_32; unsigned_16 *tmp_16; tmp_64 = (unsigned_64 *)(contents + data.loop); tmp_32 = (unsigned_32 *)(contents + data.loop); tmp_16 = (unsigned_16 *)(contents + data.loop); if( DHnd.need_bswap ) { switch( DisInsSizeInc( &DHnd ) ) { //case 8: SWAP_64( *tmp_64 ); // break; case 4: SWAP_32( *tmp_32 ); break; case 2: SWAP_16( *tmp_16 ); break; default: break; } } PrintLinePrefixAddress( data.loop, is32bit ); PrintLinePrefixData( contents, data.loop, size, DisInsSizeInc( &DHnd ), decoded.size ); BufferAlignToTab( PREFIX_SIZE_TABS ); } BufferStore( "\t%s", name ); if( *ops != '\0' ) { pos_tabs = ( DisInsNameMax( &DHnd ) + TAB_WIDTH ) / TAB_WIDTH + 1; if( !(DFormat & DFF_ASM) ) { pos_tabs += PREFIX_SIZE_TABS; } BufferAlignToTab( pos_tabs ); BufferConcat( ops ); } BufferConcatNL(); BufferPrint(); } if( sec_label_list ) { l_entry = handleLabels( sec->name, size, (orl_sec_offset)-1, l_entry, size ); } if( !(DFormat & DFF_ASM) ) { routineSize = data.loop - routineBase; BufferConcatNL(); BufferMsg( ROUTINE_SIZE ); BufferStore(" %d ", routineSize ); BufferMsg( BYTES ); BufferConcat(", "); BufferMsg( ROUTINE_BASE ); BufferStore(" %s + %04X\n\n", sec->name, routineBase ); BufferPrint(); } if( source_mix ) { EndSourceMix(); } PrintTail( sec ); return( data.disassembly_errors ); }
size_t HandleAReference( dis_value value, int ins_size, ref_flags flags, orl_sec_offset offset, orl_sec_size sec_size, ref_entry * r_entry, char *buff ) // handle any references at this offset { return_val error; dis_value nvalue; char *p; buff[0] = '\0'; for( ; *r_entry && (*r_entry)->offset == offset; *r_entry = (*r_entry)->next ) { if( (*r_entry)->no_val == 0 ) { nvalue = value; } else if( (*r_entry)->addend ) { nvalue = HandleAddend( *r_entry ); } else { nvalue = 0; } switch( (*r_entry)->type ) { case ORL_RELOC_TYPE_MAX + 1: case ORL_RELOC_TYPE_JUMP: case ORL_RELOC_TYPE_REL_21_SH: case ORL_RELOC_TYPE_WORD_26: error = referenceString( *r_entry, sec_size, "j^", "", "", buff, flags ); if( error != RC_OKAY ) { // label is defined to be beyond the boundaries of the section! if( !(DFormat & DFF_ASM) ){ BufferStore("\t %04X", offset ); BufferAlignToTab( COMMENT_TAB_POS ); } else { BufferConcat("\t" ); } BufferConcat( CommentString ); BufferMsg( LABEL_BEYOND_SECTION ); BufferConcatNL(); BufferPrint(); *r_entry = (*r_entry)->next; return( 0 ); } continue; // Don't print addend break; case ORL_RELOC_TYPE_SEC_REL: referenceString( *r_entry, sec_size, "s^", "s^", "@s", buff, flags ); break; case ORL_RELOC_TYPE_HALF_HI: referenceString( *r_entry, sec_size, "h^", "h^", "@h", buff, flags ); break; case ORL_RELOC_TYPE_HALF_HA: referenceString( *r_entry, sec_size, "ha^", "ha^", "@ha", buff, flags ); break; case ORL_RELOC_TYPE_HALF_LO: referenceString( *r_entry, sec_size, "l^", "l^", "@l", buff, flags ); break; case ORL_RELOC_TYPE_REL_14: case ORL_RELOC_TYPE_REL_24: case ORL_RELOC_TYPE_WORD_14: case ORL_RELOC_TYPE_WORD_24: nvalue &= ~0x3; case ORL_RELOC_TYPE_WORD_16: case ORL_RELOC_TYPE_WORD_32: case ORL_RELOC_TYPE_WORD_64: if( ( (*r_entry)->label->type != LTYP_GROUP ) && ( flags & RFLAG_IS_IMMED ) && IsMasmOutput() ) { referenceString( *r_entry, sec_size, "offset ", "offset ", "", buff, flags ); } else { referenceString( *r_entry, sec_size, "", "", "", buff, flags ); } break; case ORL_RELOC_TYPE_REL_16: if( IsIntelx86() && !(*r_entry)->no_val ) { nvalue -= ins_size; } if( ( (*r_entry)->label->type != LTYP_GROUP ) && ( flags & RFLAG_IS_IMMED ) && IsMasmOutput() ) { referenceString( *r_entry, sec_size, "offset ", "offset ", "", buff, flags ); } else { referenceString( *r_entry, sec_size, "", "", "", buff, flags ); } break; case ORL_RELOC_TYPE_WORD_8: case ORL_RELOC_TYPE_WORD_16_SEG: case ORL_RELOC_TYPE_WORD_HI_8: case ORL_RELOC_TYPE_WORD_32_SEG: // Keep these seperate because they are OMF specific referenceString( *r_entry, sec_size, "", "", "", buff, flags ); break; case ORL_RELOC_TYPE_SEGMENT: if( ( (*r_entry)->label->type != LTYP_GROUP ) && ( (*r_entry)->label->type != LTYP_SECTION ) && ( flags & RFLAG_IS_IMMED ) && IsMasmOutput() ) { referenceString( *r_entry, sec_size, "seg ", "seg ", "", buff, flags ); } else { referenceString( *r_entry, sec_size, "", "", "", buff, flags ); } break; case ORL_RELOC_TYPE_REL_32_NOADJ: // this is a little kluge because Brian's ELF files seem to have // -4 in the implicit addend for calls and such BBB May 09, 1997 nvalue += 4; // fall through case ORL_RELOC_TYPE_REL_8: case ORL_RELOC_TYPE_REL_16_SEG: case ORL_RELOC_TYPE_REL_HI_8: case ORL_RELOC_TYPE_REL_32_SEG: case ORL_RELOC_TYPE_REL_32: case ORL_RELOC_TYPE_REL_32_ADJ5: case ORL_RELOC_TYPE_REL_32_ADJ4: case ORL_RELOC_TYPE_REL_32_ADJ3: case ORL_RELOC_TYPE_REL_32_ADJ2: case ORL_RELOC_TYPE_REL_32_ADJ1: // For some reason we add the instruction size to the value // of the displacement in a relative call and get a bad // offset, due to CORE implementation // // Main reason : // instruction size with displacement and with addend is correct for // relative addresses without relocate // // in amd64 code the instruction size will be added in pass1.c! if( (*r_entry)->no_val == 0 && !( GetMachineType() == ORL_MACHINE_TYPE_AMD64 ) ) { nvalue -= ins_size; } referenceString( *r_entry, sec_size, "", "", "", buff, flags ); break; case ORL_RELOC_TYPE_TOCREL_14: nvalue &= ~0x3; case ORL_RELOC_TYPE_TOCREL_16: referenceString( *r_entry, sec_size, "[toc]", "[toc]", "@toc", buff, flags ); break; case ORL_RELOC_TYPE_TOCVREL_14: nvalue &= ~0x3; case ORL_RELOC_TYPE_TOCVREL_16: referenceString( *r_entry, sec_size, "[tocv]", "[tocv]", "@tocv", buff, flags ); break; case ORL_RELOC_TYPE_GOT_16: referenceString( *r_entry, sec_size, "", "", "@got", buff, flags ); break; case ORL_RELOC_TYPE_GOT_16_HI: referenceString( *r_entry, sec_size, "", "", "@got@h", buff, flags ); break; case ORL_RELOC_TYPE_GOT_16_HA: referenceString( *r_entry, sec_size, "", "", "@got@ha", buff, flags ); break; case ORL_RELOC_TYPE_GOT_16_LO: referenceString( *r_entry, sec_size, "", "", "@got@l", buff, flags ); break; case ORL_RELOC_TYPE_PLTREL_24: case ORL_RELOC_TYPE_PLTREL_32: case ORL_RELOC_TYPE_PLT_32: referenceString( *r_entry, sec_size, "", "", "@plt", buff, flags ); break; case ORL_RELOC_TYPE_PLT_16_HI: referenceString( *r_entry, sec_size, "", "", "@plt@h", buff, flags ); break; case ORL_RELOC_TYPE_PLT_16_HA: referenceString( *r_entry, sec_size, "", "", "@plt@ha", buff, flags ); break; case ORL_RELOC_TYPE_PLT_16_LO: referenceString( *r_entry, sec_size, "", "", "@plt@l", buff, flags ); break; default: continue; } // LTYP_UNNAMED labels are always at the correct location // if( nvalue != 0 && (*r_entry)->label->type != LTYP_UNNAMED ) { // not so - BBB Oct 28, 1996 if(( (*r_entry)->no_val == 0 ) && ( nvalue != 0 )) { p = &buff[strlen(buff)]; if( nvalue < 0 ) { *p++ = '-'; nvalue = -nvalue; } else { *p++ = '+'; } FmtHexNum( p, 0, nvalue, FALSE ); } } return( strlen( buff ) ); }