/**************************************************************************** * NGCUnFreezeBlock ***************************************************************************/ int NGCUnFreezeBlock (char *name, uint8 * block, int size) { char buffer[20], *e; int len = 0; int rem = 0; GetMem (buffer, 11); if (strncmp (buffer, name, 3) != 0 || buffer[3] != ':' || buffer[10] != ':' || (len = strtol (&buffer[4], &e, 10)) == 0 || e != buffer + 10) { bufoffset -= 11; // go back to where we started return WRONG_FORMAT; } if (len > size) { rem = len - size; len = size; } ZeroMemory (block, size); GetMem ((char *) block, len); if (rem) { bufoffset += rem; } return SUCCESS; }
static void *amgmalloc (size_t n) { #ifndef DYNAMIC_MEMORY_ALLOCMODEL return(GetMem(MGHEAP(amgMG),n,FROM_BOTTOM)); #else return(GetMem(MGHEAP(amgMG),n,FROM_TOP)); #endif }
int main() { printf("Enter number of nodes: "); scanf("%d", &N); if (N < 3) return 0; GetMem(N); // printf("Enter left edge: "); // scanf("%e", &a); // printf("Enter right edge: "); // scanf("%e", &b); a = -1.0; b = 1.0; if (a >= b) return 0; Interpolate(N); printf("Retcode: %d", DrawWindow(DrawWindowContent, KeyPressFunction)); delete x; delete fv; delete d; delete w; return 0; }
int cN2Prov0501::ProcessBx(unsigned char *data, int len, int pos) { if(data[pos-1]!=0xBC) { PRINTF(L_SYS_EMU,"%04X: bad nano %02X for ROM 120",id,data[pos-1]); return -1; } if(pos!=(0x93-0x80)) { // maybe exploitable PRINTF(L_SYS_EMU,"%04X: refuse to execute from %04x",id,0x80+pos); return -1; } if(Init(id,120)) { SetMem(0x80,data,len); SetPc(0x80+pos); SetSp(0x0FFF,0x0FE0); Set(0x0001,0xFF); Set(0x000E,0xFF); Set(0x0000,0x04); ClearBreakpoints(); AddBreakpoint(0x821f); AddBreakpoint(0x0000); AddRomCallbacks(); while(!Run(hasMaprom ? 20000:5000)) { if(GetPc()==0x821f) { GetMem(0x80,data,len); return a; } else if(GetPc()==0x0000) break; else if(!RomCallbacks()) break; } } return -1; }
bool MemoryBlockLE::Read128(const u64 addr, u128* value) { if(!IsMyAddress(addr)) return false; *value = *(u128*)GetMem(FixAddr(addr)); return true; }
bool MemoryBlockLE::Write128(const u64 addr, const u128 value) { if(!IsMyAddress(addr)) return false; *(u128*)GetMem(FixAddr(addr)) = value; return true; }
luabind::object LuaProxy::mem(int mem, LuaProxy::L_FIELDTYPE ftype, lua_State *L) { int iftype = (int)ftype; void* ptr = ((&(*(byte*)mem))); switch (ftype) { case LFT_BYTE: case LFT_WORD: case LFT_DWORD: case LFT_FLOAT: case LFT_DFLOAT: { double val = GetMem((int)ptr, (FIELDTYPE)ftype); return luabind::object(L, val); } case LFT_STRING: { return luabind::object(L, VBStr((wchar_t*)*((int32_t*)ptr))); } case LFT_BOOL: { return luabind::object(L, 0 != *((int16_t*)ptr)); } default: return luabind::object(); } }
/** * Create new list by level */ PLISTCDSBYLEVEL NewListCDSByLevel(PLISTCDSBYLEVEL plcdsbylevel) { plcdsbylevel = (PLISTCDSBYLEVEL) GetMem(1, sizeof(LISTCDSBYLEVEL), "NewListCDSByLevel"); plcdsbylevel->pFirstLCDS = NULL; plcdsbylevel->NElem = 0; plcdsbylevel->MaxNElem = 0; return plcdsbylevel; }
__forceinline void MemoryBlock::FastWrite<u128>(const u64 addr, const u128 value) { u128 res; res.lo = re(value.hi); res.hi = re(value.lo); *(u128*)GetMem(addr) = res; }
bool MemoryBlock::SetMemFromAddr(void* src, const u64 addr, const u32 size) { if(!IsMyAddress(addr) || FixAddr(addr) + size > GetSize()) return false; memcpy(GetMem(FixAddr(addr)), src, size); return true; }
unsigned int Cpu::GetData(unsigned char Addressing, unsigned int Argument) { switch(Addressing) { case 0: return GetReg(Argument); case 1: return GetMem(GetReg(Argument)); case 2: return Argument; case 3: return GetMem(Argument); default: CoreCrash("Unknow addressing: %d", Addressing); return 0; } }
bool MemoryBlock::GetMemFFromAddr(void* dst, const u64 addr) { if(!IsMyAddress(addr)) return false; dst = GetMem(FixAddr(addr)); return true; }
void Interpolate(int n) { FreeMem(); GetMem(n); GetMaxMin(); GetNodesAndValues(n); GetWeights(n); }
__forceinline const u128 MemoryBlock::FastRead<u128>(const u64 addr) const { volatile const u128 data = *(const u128 *)GetMem(addr); u128 ret; ret.lo = re(data.hi); ret.hi = re(data.lo); return ret; }
/** * New node by level */ PLCDSNODEBYLEVEL NewLCDSNodeByLevel(PLISTCDS plcds) { PLCDSNODEBYLEVEL plcsnbylevel; plcsnbylevel = (PLCDSNODEBYLEVEL) GetMem((SIZE) 1, (SIZE) sizeof(LCDSNODEBYLEVEL), "NewLCDSNodeByLevel"); plcsnbylevel->plcds = plcds; plcsnbylevel->level = -1; plcsnbylevel->pnext = NULL; return plcsnbylevel; }
int offsetStringToInt(unsigned int type, const char* offsetBuffer) { int offset = -1; if (sscanf(offsetBuffer,"%4X",&offset) == EOF) { return -1; } if (type & BT_P) { return offset & 0x3FFF; } else if (type & BT_S) { return offset & 0x00FF; } else // BT_C { if (GameInfo->type == GIT_NSF) { //NSF Breakpoint keywords if (strcmp(offsetBuffer,"LOAD") == 0) return (NSFHeader.LoadAddressLow | (NSFHeader.LoadAddressHigh<<8)); if (strcmp(offsetBuffer,"INIT") == 0) return (NSFHeader.InitAddressLow | (NSFHeader.InitAddressHigh<<8)); if (strcmp(offsetBuffer,"PLAY") == 0) return (NSFHeader.PlayAddressLow | (NSFHeader.PlayAddressHigh<<8)); } else if (GameInfo->type == GIT_FDS) { //FDS Breakpoint keywords if (strcmp(offsetBuffer,"NMI1") == 0) return (GetMem(0xDFF6) | (GetMem(0xDFF7)<<8)); if (strcmp(offsetBuffer,"NMI2") == 0) return (GetMem(0xDFF8) | (GetMem(0xDFF9)<<8)); if (strcmp(offsetBuffer,"NMI3") == 0) return (GetMem(0xDFFA) | (GetMem(0xDFFB)<<8)); if (strcmp(offsetBuffer,"RST") == 0) return (GetMem(0xDFFC) | (GetMem(0xDFFD)<<8)); if ((strcmp(offsetBuffer,"IRQ") == 0) || (strcmp(offsetBuffer,"BRK") == 0)) return (GetMem(0xDFFE) | (GetMem(0xDFFF)<<8)); } else { //NES Breakpoint keywords if ((strcmp(offsetBuffer,"NMI") == 0) || (strcmp(offsetBuffer,"VBL") == 0)) return (GetMem(0xFFFA) | (GetMem(0xFFFB)<<8)); if (strcmp(offsetBuffer,"RST") == 0) return (GetMem(0xFFFC) | (GetMem(0xFFFD)<<8)); if ((strcmp(offsetBuffer,"IRQ") == 0) || (strcmp(offsetBuffer,"BRK") == 0)) return (GetMem(0xFFFE) | (GetMem(0xFFFF)<<8)); } } return offset; }
t_stat punch_card (int32 ilnt, int32 mod) { int32 i, colcount; static char pbuf[CDP_WIDTH + 1]; /* + null */ UNIT *uptr; if (s2sel) uptr = &stack_unit[0]; /* stack 2? */ else uptr = &cdp_unit; /* normal output */ if ((uptr -> flags & UNIT_ATT) == 0) { /* Attached? */ notready = 1; return SCPE_OK; } pcherror = s1sel = notready = 0; /* clear flags */ colcount = 128 - LCR; for (i = 0; i < colcount; i++) { /* Fetch data */ if (cdp_ebcdic) pbuf[i] = GetMem(DAR) & 0xff; else pbuf[i] = ebcdic_to_ascii[GetMem(DAR)]; DAR++; } for (i = CDP_WIDTH - 1; (i >= 0) && (pbuf[i] == ' '); i--) pbuf[i] = 0; pbuf[CDP_WIDTH] = 0; /* trailing null */ if (!cdp_ebcdic) { fputs (pbuf, uptr -> fileref); /* output card */ fputc ('\n', uptr -> fileref); /* plus new line */ } else { for (i = 0; i < 80; i++) { fputc(pbuf[i], uptr -> fileref); } } if (ferror (uptr -> fileref)) { /* error? */ perror ("Card punch I/O error"); clearerr (uptr -> fileref); pcherror = 1; } uptr -> pos = ftell (uptr -> fileref); /* update position */ return SCPE_OK; }
void* Context::Allocate(std::size_t sz) { struct TaggedObj* obj; if (POOL && sz < 8192) { std::vector<void*>& poolForSize = pools[sz]; if (poolForSize.size() > 0) { obj = reinterpret_cast<struct TaggedObj*>(poolForSize.back()); poolForSize.pop_back(); } else obj = reinterpret_cast<struct TaggedObj*>(GetMem(sz + sizeof(Context*))); } else obj = reinterpret_cast<struct TaggedObj*>(GetMem(sz + sizeof(Context*))); obj->context = this; return &(obj->body); }
VOID AddProtectedProcess(HANDLE ParentProcessId, HANDLE ProcessId) { PPROTECTED_PROCESS CurrentProcess = ProtectedProcess; // Если список ещё пуст: if (ProtectedProcess == NULL) { CurrentProcess = GetMem(sizeof(PROTECTED_PROCESS)); FillProtectionStruct(CurrentProcess, ParentProcessId, ProcessId); ProtectedProcess = CurrentProcess; return; } // Ищем последний элемент в списке: while (CurrentProcess->NextEntry != NULL) { if (CurrentProcess->ProcessID == ProcessId) return; CurrentProcess = CurrentProcess->NextEntry; } if (CurrentProcess->ProcessID == ProcessId) return; CurrentProcess->NextEntry = GetMem(sizeof(PROTECTED_PROCESS)); FillProtectionStruct(CurrentProcess->NextEntry, ParentProcessId, ProcessId); }
void CMyList::PushHead(void *tagData) { Lock(); MYLIST_NODE *pNewNode = (MYLIST_NODE *) GetMem(sizeof(MYLIST_NODE)); pNewNode->pData = tagData; pNewNode->pNext = m_MyListHead; if (m_MyListHead == NULL) { m_MyListTail = pNewNode; } m_MyListHead = pNewNode; m_NodeCount++; UnLock(); }
NTSTATUS GetKeyValue(HANDLE hKey, LPWSTR ValueName, PVOID OutputBuffer, ULONG BufferSize, OUT OPTIONAL PULONG BytesReturned) { if (BytesReturned != NULL) *BytesReturned = 0; UNICODE_STRING UnicodeValueName; RtlInitUnicodeString(&UnicodeValueName, ValueName); ULONG PartialInformationSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + BufferSize - 1; PKEY_VALUE_PARTIAL_INFORMATION PartialInformation = GetMem(PartialInformationSize); ULONG ResultLength = 0; NTSTATUS Status = ZwQueryValueKey(hKey, &UnicodeValueName, KeyValuePartialInformation, PartialInformation, PartialInformationSize, &ResultLength); if NT_SUCCESS(Status) { RtlCopyMemory(OutputBuffer, PartialInformation->Data, PartialInformation->DataLength); if (BytesReturned != NULL) *BytesReturned = PartialInformation->DataLength; } else if ((BytesReturned != NULL) && ((Status == STATUS_BUFFER_OVERFLOW) || (Status == STATUS_BUFFER_TOO_SMALL))) {
void handleDump(char* start, char* end) { int s = strtol(start, NULL, 16); int e = strtol(end, NULL, 16); bool ok = true; if(s > e){ printf("Error, start address is larger than end address\n"); ok = false; } if(e > 32767){ printf("Error: end address out of range 0x0 - 0x7FFF\n"); ok = false; } if(s < 0){ printf("Error: start address is negative"); ok = false; } if (ok) { printf("dumping from 0x%X to 0x%X\n", s, e); int i = 0; int temp = 0; printf(" +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F\n"); while (i < s % 16) { if(i == 0) printf("0x%06X: ", s); printf("-- "); if(i == 7) printf("|| "); i++; } if(s % 16 == 0) printf("0x%06X: ", s); while (s <= e) { GetMem(s, &temp, 0); printf("%2X ", temp); temp = s%16; if(temp == 7) printf("|| "); if(temp == 15 && s < e) printf("\n0x%06X: ", s); s++; } i = 0; temp = e%16; while(i + temp < 15){ printf("-- "); if(i + temp == 6) printf("|| "); i++; } printf("\n"); } }// </editor-fold>
int cN2Prov0501::RunEmu(unsigned char *data, int len, unsigned short load, unsigned short run, unsigned short stop, unsigned short fetch, int fetch_len) { if(Init(id,120)) { SetSp(0x0FFF,0x0EF8); SetMem(load,data,len); SetPc(run); ClearBreakpoints(); AddBreakpoint(stop); if(stop!=0x0000) AddBreakpoint(0x0000); AddRomCallbacks(); while(!Run(100000)) { if(GetPc()==0x0000 || GetPc()==stop) { GetMem(fetch,data,fetch_len); return 1; } else if(!RomCallbacks()) break; } } return -1; }
PSHARED_DISP_DATA GetSharedData() { PSHARED_DISP_DATA* pData = (PSHARED_DISP_DATA*)GetMem(); if (!*pData) { KdPrint(("Shared data not allocated, creating\n")); *pData = (PSHARED_DISP_DATA) ExAllocatePool (NonPagedPool, sizeof(SHARED_DISP_DATA)); if (!*pData) { KdPrint (("ExAllocatePool failed\n")); return NULL; } memset (*pData, 0, sizeof(SHARED_DISP_DATA)); (*pData)->Signature = SHARED_SIGNATURE; } return *pData; }
void CMyList::PushIndex(int idx, void *tagData) { if (idx <= 0) { PushHead(tagData); return; } if (idx >= m_NodeCount) { PushBack(tagData); return; } MYLIST_NODE *pNewNode = (MYLIST_NODE *) GetMem(sizeof(MYLIST_NODE)); pNewNode->pData = tagData; pNewNode->pNext = NULL; Lock(); MYLIST_NODE *pPrev = NULL, *pCurr = m_MyListHead; for (int i=0; i<idx; i++) { pPrev = pCurr; pCurr = pCurr->pNext; } if (pPrev) { pPrev->pNext = pNewNode; pNewNode->pNext = pCurr; } else { m_MyListHead = pNewNode; } m_NodeCount++; UnLock(); }
//CMD_TRSACTION //请求: [B0: 协议字] [B1: 0x0-Rollback, 0x1-StartTrsaction, 0x2-Commit] //响应: [B0: 协议字] [B1: 执行结果0|1] int OnTrsaction(QUEUE_LIST *pDataNode) { #ifndef _SUPPORT_CLITR //不支持客户端事物 setCmdError(pDataNode); return 1; #endif //客户端事务连接链表 CTrastionList *pTrList = pDataNode->pCliTr; SAConnection *psaConn = pTrList->getCliTrConn(pDataNode->SrvrPort, pDataNode->PeerSockId); //请求报文(MSG) CliTrsaction_t Req = (CliTrsaction_t)pDataNode->Buffer[1]; switch (Req) { case TR_ROLLBACK: if (NULL == psaConn) setCmdError(pDataNode); else { psaConn->Rollback(); //删除客户端事物连接 pTrList->delCliTrConn(pDataNode->SrvrPort, pDataNode->PeerSockId); setCmdSucceed(pDataNode); } break; case TR_START: if (NULL == psaConn) { //新建客户端事物连接 TRSACTION_NODE *pNode = (TRSACTION_NODE *) GetMem(sizeof(TRSACTION_NODE)); pNode->SrvrPort = pDataNode->SrvrPort; pNode->PeerSockId = pDataNode->PeerSockId; pNode->psaConn = new SAConnection(); if (isDBConnect(pNode->psaConn, pDataNode->thd_info)) { pTrList->PushHead((void *)pNode); //加入节点到链表 } else { delete pNode->psaConn; FreeMem(pNode); setCmdError(pDataNode); return 1; } } setCmdSucceed(pDataNode); break; case TR_COMMIT: if (NULL == psaConn) setCmdError(pDataNode); else { psaConn->Commit(); //删除客户端事物连接 pTrList->delCliTrConn(pDataNode->SrvrPort, pDataNode->PeerSockId); setCmdSucceed(pDataNode); } break; default: return 0; } return 1; }
//CMD_EXECSQL //远程客户端请求执行SQL //请求: [B0: 协议字] [B1:是否需要返回结果集] [B2~B5: 请求的起始记录号] [B6~B9: 最大返回的记录数] [B10~Bn: SQL语句] //响应: [B0: 协议字] [B1: 执行结果0|1] [B2: 是否还有后续数据0|1] [B3..Bn: CDS结果集] int OnExecSQL(QUEUE_LIST *pDataNode) { #ifdef _SUPPORT_CLITR //支持客户端事务连接 if (NULL != pDataNode->psaConn) { SAConnection *p = pDataNode->pCliTr->getCliTrConn(pDataNode->SrvrPort, pDataNode->PeerSockId); if (p) pDataNode->psaConn = p; } #endif //报文(MSG) unsigned char *p = pDataNode->Buffer; p++; int iStartRecNo, iMaxCount, iSqlLen; bool bNeedReturnData = (*p == 1); p++; P2DW(iStartRecNo, p); p += 4; P2DW(iMaxCount, p); p += 4; P2W(iSqlLen, p); p += 2; if (iSqlLen > 8 * ONE_PACKSIZE) { setCmdError(pDataNode); return 1; } unsigned char *pSQL = (unsigned char *) GetMem(iSqlLen + 1); memcpy(pSQL, p, iSqlLen); pSQL[iSqlLen] = 0; thd_log(LOG_DEBUG,"Execute SQL: %s", pSQL); SACommand saCmd; try{ saCmd.setConnection(pDataNode->psaConn); saCmd.setCommandText(_TSA(pSQL)); saCmd.Execute(); } catch(SAException &x) { thd_log( LOG_ERROR,(char *)"SQLAPI Exception %s", _T(x.ErrText())); setCmdError(pDataNode); return 1; } p = &pDataNode->Buffer[1]; int iOutLen = 1; *p++ = CMD_OK; //执行SQL成功 iOutLen++; *p++ = 0x0; iOutLen++; //不需要返回数据 if (!bNeedReturnData) { //m_pDataNode->psaConn->Commit(); int rowUpd = saCmd.RowsAffected(); //更新的记录数 W2P(p, rowUpd); iOutLen += 2; pDataNode->Length = iOutLen; FreeMem(pSQL); return 1; } bool bHasNext = false; p += 2; //返回数据 int iRet = CopyDataSet(&bHasNext, p, ALL_PACKSIZE, &saCmd, iStartRecNo, iMaxCount); p -= 2; W2P(p, iRet); //记录集大小 if (bHasNext) pDataNode->Buffer[2] = 0x1; //存在未返回记录 iOutLen += 2 + iRet; pDataNode->Length = iOutLen; thd_log(LOG_DEBUG,"cdsfmt2 len = %d",pDataNode->Length); trace_mem( LOG_DEBUG,pDataNode->Buffer, pDataNode->Length); FreeMem(pSQL); return 1; }
__forceinline const u8 MemoryBlock::FastRead8(const u64 addr) const { return *GetMem(addr); }
u8* MemoryBlock::GetMemFromAddr(const u64 addr) { if(!IsMyAddress(addr) || IsNULL()) return nullptr; return GetMem(FixAddr(addr)); }
__forceinline void MemoryBlock::FastWrite8(const u64 addr, const u8 value) { *GetMem(addr) = value; }