20 #define LIBSMBIOS_SOURCE
30 using namespace smbiosLowlevel;
35 ISmbiosItem::~ISmbiosItem()
38 ISmbiosItem::ISmbiosItem()
45 :
ISmbiosItem(), header (source.header), header_size(source.header_size)
58 InternalErrorImpl internalError;
59 internalError.setMessageString(
_(
"Not a valid header. header is zero."));
69 :
ISmbiosItem(), header(init_header), header_size(0)
83 InternalErrorImpl internalError;
84 internalError.setMessageString(
_(
"Not a valid header. header is zero."));
93 while (*nextStruct || nextStruct[1])
114 delete []
const_cast<u8 *
>(
reinterpret_cast<const u8 *
>(
header));
144 const char *string_pointer =
reinterpret_cast<const char *
>(
header);
152 throw StringUnavailableImpl(
_(
"String does not exist."));
159 for (; which > 1; which--)
161 string_pointer += strlen (string_pointer);
167 const u8 *cur_loc =
reinterpret_cast<const u8 *
>(string_pointer);
168 const u8 *base_loc =
reinterpret_cast<const u8 *
>(
header);
171 ParseExceptionImpl parseException;
172 parseException.setMessageString(
_(
"Overflow while getting byte data at location: cur_loc >= base_loc + header_size\n cur_loc : %(cur_loc)i\n base_loc : %(base_loc)i\n header_size : %(header_size)i "));
173 parseException.setParameter(
"cur_loc",
force_u64_to_u32(reinterpret_cast<u64>(cur_loc)));
174 parseException.setParameter(
"base_loc",
force_u64_to_u32(reinterpret_cast<u64>(base_loc)));
175 parseException.setParameter(
"header_size",static_cast<u32>(
header_size));
176 throw parseException;
182 if( ! *string_pointer )
184 throw StringUnavailableImpl(
_(
"The string does not exist. Bad index caused this error"));
188 return string_pointer;
193 return auto_ptr<ISmbiosItem>(
new SmbiosItem (*
this));
198 return auto_ptr<const ISmbiosItem>(
new SmbiosItem (*
this));
218 DataOutOfBoundsImpl dataOutOfBounds;
219 dataOutOfBounds.setParameter(
"offset",static_cast<int>(offset));
220 dataOutOfBounds.setParameter(
"header_length",static_cast<int>(total_size));
223 if( offset > length )
225 dataOutOfBounds.setMessageString(
_(
"Attempt to access data outside the length of header. offset : %(offset)i, header_length : %(header_length)i"));
226 throw dataOutOfBounds;
229 if( offset + size < offset )
231 dataOutOfBounds.setMessageString(
_(
"Attempt to access data outside the length of header. offset : %(offset)i, header_length : %(header_length)i"));
232 throw dataOutOfBounds;
235 if( offset + size > length )
237 dataOutOfBounds.setMessageString(
_(
"Attempt to access data outside the length of header. offset : %(offset)i, header_length : %(header_length)i"));
238 throw dataOutOfBounds;
241 if( offset >= total_size )
247 dataOutOfBounds.setMessageString(
_(
"Attempt to access data outside header buffer. Impossible situation! offset : %(offset)i, header_length : %(header_length)i"));
248 throw dataOutOfBounds;
256 memcpy(out, reinterpret_cast<const u8 *>(
header)+offset, size);
263 const u8 *newBuffer =
new u8[ size ];
264 memcpy (const_cast<u8 *>(newBuffer),
header, size);
275 u8 *buffer =
const_cast<u8 *
>(
reinterpret_cast<const u8 *
>(
header));
282 cout <<
"operator << on an uninitialized SmbiosItem!";
285 std::ios::fmtflags old_opts = cout.flags ();
286 cout <<
"Handle 0x" << hex << setfill (
'0') <<
288 cout <<
"\tDMI type 0x" <<
static_cast<int>(
getType()) << dec <<
289 ", " << static_cast<int>(
getLength()) <<
" bytes." <<
291 cout.flags (old_opts);
319 item.
getData(offset, reinterpret_cast<u8 *>(&retval),
sizeof(retval));
326 item.
getData(offset, reinterpret_cast<u8 *>(&retval),
sizeof(retval));
333 item.
getData(offset, reinterpret_cast<u8 *>(&retval),
sizeof(retval));
340 item.
getData(offset, reinterpret_cast<u8 *>(&retval),
sizeof(retval));
347 getData(item, offset, stringNum);
361 DataOutOfBoundsImpl dataOutOfBounds;
362 dataOutOfBounds.setParameter(
"lsb",lsb);
363 dataOutOfBounds.setParameter(
"msb",msb);
364 dataOutOfBounds.setMessageString(
_(
"The total length of bit field is out of bounds. The largest accessible bit is 63. lsb: %(lsb)i , msb: %(msb)i"));
365 throw dataOutOfBounds;
369 unsigned int fieldLen = ((msb+1)/8) + (((msb+1)%8)?1:0);
372 item.
getData(offset, reinterpret_cast<u8 *>(&bitfield), fieldLen);
375 unsigned int bitlen = (msb-lsb) + 1;
376 bitfield = (bitfield >> lsb) & ((1<<bitlen)-1);
379 memcpy(out, &bitfield, ((bitlen)/8) + (((bitlen)%8)?1:0));
388 unsigned int byte = bitToTest / 8;
390 if (fieldValue & (1 << (bitToTest%8)))