double CPersist::GetDouble(LPCTSTR Section, LPCTSTR Entry, double Default) { double r; DWORD Size = sizeof(double); if (GetBinary(Section, Entry, &r, &Size)) return(r); return(Default); }
float CPersist::GetFloat(LPCTSTR Section, LPCTSTR Entry, float Default) { float r; DWORD Size = sizeof(float); if (GetBinary(Section, Entry, &r, &Size)) return(r); return(Default); }
GlueFileBinaryData GlueFile::GetBinary(uint32 seekPos, uint32 numbytes) { AMJU_CALL_STACK; GlueFileBinaryData data; data.Allocate(numbytes); GetBinary(seekPos, numbytes, const_cast<unsigned char*>(data.GetBuffer())); return data; }
BOOL CPersist::GetFont(LPCTSTR Section, LPCTSTR Entry, CFont *Font) { LOGFONT lf; DWORD Size = sizeof(LOGFONT); if (Font != NULL && GetBinary(Section, Entry, &lf, &Size) && Size == sizeof(LOGFONT)) return(Font->CreateFontIndirect(&lf)); return(FALSE); }
const char *GProfile::GetCiphered(const char *szSectionName, const char *szKey, const char *pzPassword, GString &strDest) { GString strData; GetBinary(szSectionName, szKey, strData); GString strErrorOut; GString strPass(pzPassword); DecryptMemoryToMemory(strPass, strData, (int)strData.Length(), strDest, strErrorOut); return strDest; }
uint32 GlueFile::GetBinary(uint32 seekPos, uint32 numbytes, unsigned char* pBuffer) { AMJU_CALL_STACK; #ifdef GLUE_FILE_DEBUG std::cout << "GLUE FILE: GetBinary: seek: " << seekPos << " num bytes: " << numbytes << "\n"; #endif // *** NB Not MT Safe *** uint32 pos = GetPos(); SetPos(seekPos); uint32 bytesRead = GetBinary(numbytes, pBuffer); SetPos(pos); return bytesRead; }
sU8 *sDiskItem::Load() { sU8 *mem; sInt size; mem = 0; size = GetBinarySize(sDIA_DATA); if(size>0) { mem = new sU8[size]; if(!GetBinary(sDIA_DATA,mem,size)) { delete[] mem; mem = 0; } } return mem; }
sChar *sDiskItem::LoadText() { sChar *mem; sInt size; mem = 0; size = GetBinarySize(sDIA_DATA); if(size>0) { mem = new sChar[size+1]; mem[size]=0; if(!GetBinary(sDIA_DATA,(sU8 *)mem,size)) { delete[] mem; mem = 0; } } return mem; }
PyObject* GetData(Cursor* cur, Py_ssize_t iCol) { // Returns an object representing the value in the row/field. If 0 is returned, an exception has already been set. // // The data is assumed to be the default C type for the column's SQL type. ColumnInfo* pinfo = &cur->colinfos[iCol]; // First see if there is a user-defined conversion. int conv_index = GetUserConvIndex(cur, pinfo->sql_type); if (conv_index != -1) return GetDataUser(cur, iCol, conv_index); switch (pinfo->sql_type) { case SQL_WCHAR: case SQL_WVARCHAR: case SQL_WLONGVARCHAR: return GetText(cur, iCol); case SQL_CHAR: case SQL_VARCHAR: case SQL_LONGVARCHAR: case SQL_SS_XML: case SQL_DB2_XML: return GetText(cur, iCol); case SQL_GUID: if (UseNativeUUID()) return GetUUID(cur, iCol); return GetText(cur, iCol); break; case SQL_BINARY: case SQL_VARBINARY: case SQL_LONGVARBINARY: return GetBinary(cur, iCol); case SQL_DECIMAL: case SQL_NUMERIC: return GetDataDecimal(cur, iCol); case SQL_BIT: return GetDataBit(cur, iCol); case SQL_TINYINT: case SQL_SMALLINT: case SQL_INTEGER: return GetDataLong(cur, iCol); case SQL_BIGINT: return GetDataLongLong(cur, iCol); case SQL_REAL: case SQL_FLOAT: case SQL_DOUBLE: return GetDataDouble(cur, iCol); case SQL_TYPE_DATE: case SQL_TYPE_TIME: case SQL_TYPE_TIMESTAMP: return GetDataTimestamp(cur, iCol); case SQL_SS_TIME2: return GetSqlServerTime(cur, iCol); } return RaiseErrorV("HY106", ProgrammingError, "ODBC SQL type %d is not yet supported. column-index=%zd type=%d", (int)pinfo->sql_type, iCol, (int)pinfo->sql_type); }
CTobCompiler::EToken CTobCompiler::CompilePass1() { EToken r; CString str, buf; CByteArray* bin = 0; for(;;) { if((r = GetToken(str)) <= 0) return r; if(r == SYM_KEY) { if((r = GetToken(str)) < 0) return r; if(r != SYM_TOKEN) { m_err = "not found keyword after '.'"; return ERR_NORMAL; } if(str == "def") { if((r = GetToken(str)) < 0) return r; if(r != SYM_TOKEN) { m_err = "not found token after '.def'"; return ERR_NORMAL; } if((r = GetToken(buf)) < 0) return r; if(r == SYM_BIN) { bin = new CByteArray; if((r = GetBinary(*bin)) < 0) { delete bin; return r; } } else if(r == SYM_STR) { if((r = GetString(buf, false)) < 0) return r; bin = new CByteArray; for(LPCTSTR p = buf; *p; ++p) bin->Add(*(U8*)p); if(r == SYM_STRING) bin->Add(0); } else if(r == SYM_STRING) { if((r = GetString(buf, true)) < 0) return r; bin = new CByteArray; for(LPCTSTR p = buf; *p; ++p) bin->Add(*(U8*)p); if(r == SYM_STRING) bin->Add(0); } else { m_err = "not found '[' or ''' or '\"' after '.def <token>''"; return ERR_NORMAL; } m_defbin.SetAt(str, bin); bin = 0; } else if(str == "change") { if((r = GetToken(str)) < 0) return r; if(r != SYM_STR) { m_err = "not found ''' after '.change'"; return ERR_NORMAL; } if((r = GetString(str, false)) < 0) return r; if( str.IsEmpty() || str.GetLength()>2 || str.GetLength() == 2 && (U8)str[0]<0x80) { m_err = "only one character is allowed after '.change'"; return ERR_NORMAL; } U16 c = (U8)str[0]; if(str.GetLength() == 2) c = (c<<8) + (U8)str[1]; if((r = GetToken(str)) < 0) return r; if(r == SYM_BIN) { CByteArray tmp; if((r = GetBinary(tmp)) < 0) return r; buf.Empty(); int i, n = tmp.GetSize(); for(i = 0; i < n; ++i) { U8 b = tmp.GetAt(i); if(!b) break; buf += (TCHAR)b; } } else if(r == SYM_STR) { if((r = GetString(buf, false)) < 0) return r; } else if(r == SYM_STRING) { if((r = GetString(buf, true)) < 0) return r; } else { m_err = "not found ''' or '\"' after '.change <char>'"; return ERR_NORMAL; } m_change.SetAt(c, buf); } else if(str == "bit") { if((r = GetToken(str)) < 0) return r; if(r != SYM_TOKEN) { m_err = "not found parameter after '.bit'"; return ERR_NORMAL; } int bit = atoi(str); if(bit!=8 && bit!=16 && bit!=24 && bit!=32) { m_err = "only '.bit 8/16/24/32' is available"; return ERR_NORMAL; } m_bit_i = bit; } else if(str == "maxc") { if((r = GetToken(str)) < 0) return r; if(r != SYM_TOKEN) { m_err = "not found parameter after '.maxc'"; return ERR_NORMAL; } m_maxc = atoi(str); } else if(str == "maxw") { if((r = GetToken(str)) < 0) return r; if(r != SYM_TOKEN) { m_err = "not found parameter after '.maxw'"; return ERR_NORMAL; } m_maxw = atoi(str); } else if(str == "maxs") { if((r = GetToken(str)) < 0) return r; if(r != SYM_TOKEN) { m_err = "not found parameter after '.maxs'"; return ERR_NORMAL; } m_maxs = atoi(str); } else { m_err.Format("unknwon keyword '%s' after '.'", (LPCTSTR)str); return ERR_NORMAL; } } else if(r == SYM_BIN) { if((r = GetBinary(m_bin)) < 0) return r; } else if(r == SYM_STR) { if((r = GetString(buf, false)) < 0) return r; for(LPCTSTR p=buf;* p; ++p) m_bin.Add(*(U8*)p); if(r == SYM_STRING) m_bin.Add(0); } else if(r == SYM_STRING) { if((r = GetString(buf, true)) < 0) return r; for(LPCTSTR p=buf;* p; ++p) m_bin.Add(*(U8*)p); if(r == SYM_STRING) m_bin.Add(0); } else if(r == SYM_TOKEN) { if(!m_defbin.Lookup(str, bin)) { m_err.Format("not defined token '%s'", (LPCTSTR)str); return ERR_NORMAL; } m_bin.Append(*bin); bin = 0; } else if(r == SYM_ADDR) { if((r = GetToken(str)) < 0) return r; SExpInfo* ti = new SExpInfo(m_bin.GetSize(), m_line); if(r == SYM_EXP_BEGIN) { for(;;) { if((r = GetToken(buf)) < 0) { delete ti; return r; } if(r == SYM_TOKEN || r == SYM_NUM) ti->m_item.Add(buf); else if(r == SYM_ADD) ti->m_item.Add("+"); else if(r == SYM_SUB) ti->m_item.Add("-"); else if(r == SYM_ADDR) ti->m_item.Add("@"); else if(r == SYM_EXP_END) break; else { delete ti; m_err.Format("found unknown token '%s' in expression", (LPCTSTR)buf); return ERR_NORMAL; } } } else if(r == SYM_TOKEN) ti->m_item.Add(str); else { delete ti; m_err = "not found token or expression after '@'"; return ERR_NORMAL; } m_exp.Add(ti); for(int i = m_bit_i/8; i--;) m_bin.Add(0); } else if(r == SYM_LABEL) { if((r = GetToken(str)) < 0) return r; if(r != SYM_TOKEN) { m_err = "not found label after '#'"; return ERR_NORMAL; } m_label.SetAt(str, m_bin.GetSize()); } else { m_err = "unknown or bad symbol"; return ERR_NORMAL; } } }
bool GlueFile::ReadTable() { AMJU_CALL_STACK; // Get the number of sub-files. This is the uint32 at file pos zero. uint32 numFiles = 0; //m_gluefile.seekg(0); GetBinary(0, sizeof(uint32), (unsigned char*)&numFiles); numFiles = Endian(numFiles); #ifdef GLUE_FILE_DEBUG std::cout << "GLUE FILE: no of files: " << numFiles << "\n"; #endif // Get the file pos of the table. This is the next uint32. //m_gluefile.read((char*)&m_tablePos, sizeof(uint32)); GetBinary(4, sizeof(uint32), (unsigned char*)&m_tablePos); m_tablePos = Endian(m_tablePos); #ifdef GLUE_FILE_DEBUG std::cout << "GLUE FILE: table start: " << m_tablePos << "\n"; #endif // Seek to the table start. uint32 tablePos = m_tablePos; //m_gluefile.seekg(m_tablePos); uint32 pos = BASE; // For each sub-file, get the name and file pos. for (uint32 i = 0; i < numFiles; i++) { // Get the length of the sub-file name. uint32 subfilenamelen = 0; //m_gluefile.read((char*)&subfilenamelen, sizeof(uint32)); GetBinary(tablePos, sizeof(uint32), (unsigned char*)&subfilenamelen); tablePos += sizeof(uint32); subfilenamelen = Endian(subfilenamelen); unsigned char buf[1000]; //m_gluefile.read(buf, subfilenamelen); GetBinary(tablePos, subfilenamelen, buf); buf[subfilenamelen] = '\0'; #ifdef GLUE_FILE_DEBUG std::cout << "GLUE FILE: file " << i << " size of name: " << subfilenamelen << " name: \"" << buf << "\"\n"; #endif tablePos += subfilenamelen; string lowname = ToLower((char*)buf); // Now get the size of this sub-file. uint32 size = 0; //m_gluefile.read((char*)&size, sizeof(uint32)); GetBinary(tablePos, sizeof(uint32), (unsigned char*)&size); tablePos += sizeof(uint32); size = Endian(size); #ifdef GLUE_FILE_DEBUG std::cout << "GLUE FILE: Found file: " << lowname.c_str() << " size: " << size << " pos: " << pos << "\n"; #endif // Store the sub-file's size and position.. m_table[lowname] = make_pair(size, pos); // .. also append to this list so we keep the order in which the // sub-files were added. m_filenames.push_back(lowname); pos += size; } // Copy the list of all subfiles. As subfiles are 'opened', they are removed // from the unused list. The ones left are printed out in the dtor. m_unusedFiles = m_filenames; return true; }
CTobCompiler::EToken CTobCompiler::CompilePass1() { EToken r, LastToken; CString str, buf, sizebuf; CByteArray* bin; SValueType* val; SExpression* exp; for(;;) { BOOL bSkipGetToken = FALSE; if ((r = GetToken(str)) <= 0) return r; _SkipGetToken: if (r == SYM_DEF) { /* if (m_bin.GetSize() > 0) { m_err = "const token can not defined after data"; return ERR_NORMAL; } */ if ((r = GetToken(str)) < 0) return r; if (r != SYM_TOKEN) { m_err = "not found token after '@'"; return ERR_NORMAL; } if (str == "_IGNORECASE") { m_Option.bIgnoreCase = TRUE; continue; } if ((r = GetToken(buf)) < 0) return r; if (r == SYM_BIN) { bin = new CByteArray; if ((r = GetBinary(*bin)) < 0) { delete bin; return r; } AddMap(m_binmap, str, bin); } else if (r == SYM_STR) { bin = new CByteArray; if ((r = GetString(*bin)) < 0) { delete bin; return r; } AddMap(m_binmap, str, bin); } else if (r == SYM_INT) { ULONG Length; BOOL bHex = (buf[0] == '0' && buf[1] == 'x'); r = GetToken(sizebuf); LastToken = r; if (r == SYM_TYPE) { r = GetToken(sizebuf); if (r != SYM_TOKEN) { m_err = "not found type after ':'"; return ERR_NORMAL; } Length = GetSizeFromType(sizebuf[0]); if (Length == -1) { m_err.Format("unknown type '%c' after ':'", sizebuf[0]); return ERR_NORMAL; } } else { Length = -1; } val = new SValueType((int)strtoul(buf, NULL, bHex ? 16 : 10), Length); AddMap(m_valmap, str, val); if (Length == -1) bSkipGetToken = TRUE; r = SYM_INT; } else if (r == SYM_FLOAT) { AddMap(m_valmap, str, new SValueType(atof(buf))); } else { m_err.Format("not found '[' or ''' or '\"' or number after '@%s'", (LPCTSTR)str); return ERR_NORMAL; } if (m_Option.bIgnoreCase) str.MakeUpper(); if (str == "_DEFI") { if (r != SYM_INT || val->ival < 1 || val->ival > 4) { m_err = "_DEFI must be 1/2/3/4"; return ERR_NORMAL; } m_Option.DefInt = val->ival; } else if (str == "_DEFF") { if (r != SYM_INT || val->ival != 4 && val->ival != 8) { m_err = "_DEFF must be 4/8"; return ERR_NORMAL; } m_Option.DefFloat = val->ival; } else if (str == "_MOD") { if (r != SYM_INT) { m_err = "_MOD must be number"; return ERR_NORMAL; } while (m_bin.GetSize() % val->ival) m_bin.Add(0); } else if (str == "_INCLUDE") { FILE *fsrc; WCHAR szPath[MAX_PATH]; CByteArray *bin; if (m_Option.bIgnoreCase) str.MakeLower(); if (!m_binmap.Lookup(str, bin)) continue; m_binmap.RemoveKey(str); MultiByteToWideChar( CP_GB2312, 0, (LPSTR)bin->GetData(), -1, szPath, countof(szPath)); delete bin; fsrc = m_fsrc; m_fsrc = _wfopen(szPath, L"rb"); if (m_fsrc == NULL) { m_fsrc = fsrc; m_err.Format("can't open include file '%S'", szPath); return ERR_SEVERE; } else { EToken r; for(;;) { r = CompilePass1(); if (r == ERR_EOF) break; if (r < 0) { if (!ErrorHandlerInternal(GetErrorString(m_err))) break; } if (r == ERR_SEVERE) break; } fclose(m_fsrc); m_fsrc = fsrc; if (r < 0) return r; } } if (bSkipGetToken) { str = sizebuf; r = LastToken; goto _SkipGetToken; } } else if (r == SYM_BIN) { if ((r = GetBinary(m_bin)) < 0) return r; } else if (r == SYM_STR) { if ((r = GetString(m_bin)) < 0) return r; } else if (r == SYM_TOKEN) { if (!m_binmap.Lookup(str, bin)) { m_err.Format("unknown token '%s'", (LPCTSTR)str); return ERR_NORMAL; } m_bin.Append(*bin); } else if (r == SYM_LABEL) { if ((r = GetToken(str)) < 0) return r; if (r != SYM_TOKEN) { m_err = "not found token after '#'"; return ERR_NORMAL; } if (m_valmap.Lookup(str, val)) { m_err.Format("already defined label token '%s'", (LPCTSTR)str); return ERR_NORMAL; } m_valmap.SetAt(str, new SValueType(m_bin.GetSize())); } else if (r == SYM_EXP_BEGIN) { int i = m_exparr.GetSize(); do { int len = m_Option.DefInt; BOOL hastype = FALSE; exp = new SExpression(m_bin.GetSize(), m_line); for(;;) { if ((r = GetToken(buf)) < 0) { delete exp; return r; } if (r == SYM_TOKEN) { val = NULL; if (!hastype && len > 0 && m_valmap.Lookup(buf, val) && val->isfloat) len = -m_Option.DefFloat; exp->m_item.Add(buf); if (val != NULL && val->m_size != -1) len = val->isfloat ? -val->m_size : val->m_size; } else if (r == SYM_ADD) { exp->m_item.Add("+"); } else if (r == SYM_SUB) { exp->m_item.Add("-"); } else if (r == SYM_DEF) { exp->m_item.Add("@"); } else if (r == SYM_INT) { exp->m_item.Add(buf); } else if (r == SYM_FLOAT) { if (!hastype && len > 0) len = -m_Option.DefFloat; exp->m_item.Add(buf); } else if (r == SYM_TYPE) { int newlen; if ((r = GetToken(buf)) < 0) { delete exp; return r; } if (r != SYM_TOKEN) { delete exp; m_err = "not found type after ':'"; return ERR_NORMAL; } newlen = GetSizeFromType(buf[0]); if (newlen == -1) { delete exp; m_err.Format("unknown type '%c' after ':'", buf[0]); return ERR_NORMAL; } if (hastype && newlen != len) { delete exp; m_err = "found different types in one expression"; return ERR_NORMAL; } hastype = TRUE; len = newlen; } else if (r == SYM_BIN) { if (exp->m_item.GetSize() > 0) { delete exp; m_err = "found different types in one expression"; return ERR_NORMAL; } if ((r = GetBinary(m_bin)) < 0) { delete exp; return r; } } else if (r == SYM_STR) { if (exp->m_item.GetSize() > 0) { delete exp; m_err = "found different types in one expression"; return ERR_NORMAL; } if ((r = GetString(m_bin)) < 0) { delete exp; return r; } } else if (r == SYM_NEXT || r == SYM_EXP_END) { break; } else { delete exp; m_err.Format("unknown or bad symbol1 '%s' in expression", (LPCTSTR)str); return ERR_NORMAL; } } if (exp->m_item.GetSize() <= 0) { delete exp; } else { exp->m_size = len; m_exparr.Add(exp); if (len < 0) len = -len; while(len--) m_bin.Add(0); } } while(r != SYM_EXP_END); for(int j = m_exparr.GetSize(); i < j; ++i) m_exparr[i]->m_self = m_bin.GetSize(); } else { m_err.Format("unknown or bad symbol2 '%s'", (LPCTSTR)str); return ERR_NORMAL; } } }
BOOL CPersist::GetWndPlacement(LPCTSTR Section, LPCTSTR Name, WINDOWPLACEMENT& wp) { DWORD Size = sizeof(WINDOWPLACEMENT); memset(&wp, 0, Size); return(GetBinary(Section, CString(Name) + WND_PLACE, &wp, &Size)); }