mirror of
https://github.com/LongSoft/UEFITool.git
synced 2025-05-21 10:45:24 -04:00

2) Fixed QHexView misalignment in Windows and macOS. 3) Added some more analysis to raw files and sections: raw files can (or can not) contain sections, raw sections can contain NVAR storage or PE/TE. 4) Improved CPU base address detection and propagation. 5) Improved FIT recognition. 7) ME region not displayed if it is in unknown format, fixed this because we still want to operate with it. 8) Small changes to Flash Descriptor parsing to get more cases for valid "Intel image". To get rid of cases when "Intel image" is already in tree but with parse error because of which "UEFI image" appears. 9) Added parsing of individual UEFI-files (these can be trimmed from UEFI-volume), displaying it as "UEFI volume part". 10) Added possibility to view/save contents of elements "Free volume space", "Free space" and such, because these can be non-empty. 11) Added info about blocks number and block size (with preliminary and stupid validity check) to volume info. 12) Added storage in settings of the following paths: open image file, save image file, open GUIDs file. 13) Added last opened files list. 14) Added permanent opened file name string to the end of the status bar. 15) Added opened file changes tracking: if the file was modified in other program while it is opened in UEFITool, there are 3 ways to act: a) ignore changes (but mark file path displayed in the status bar with italic font); b) ask user to reopen or ignore (if ignore, mark as in a); c) auto reopen changed file in UEFITool. If changes were in some way ignored, file path displayed in the right of the status bar will be marked with italic font and then become clickable: on click request to reopen appears again. 16) Switched to offset/size instead of byte array storing in each tree item. 17) For clarity - added icons to key tree items (compressed and with contents, contents now must be in root item only). 18) For usability - added expanding tree on open image (to depth level 1) and by menu command (expand all).
146 lines
3.6 KiB
C++
146 lines
3.6 KiB
C++
/* ustring.cpp
|
|
|
|
Copyright (c) 2016, Nikolaj Schlej. All rights reserved.
|
|
This program and the accompanying materials
|
|
are licensed and made available under the terms and conditions of the BSD License
|
|
which accompanies this distribution. The full text of the license may be found at
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
*/
|
|
|
|
#include "ustring.h"
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <stdarg.h>
|
|
#include "printf/printf.c"
|
|
|
|
static bool cStyleHexEnabled = false;
|
|
|
|
void putchar_(char c) {}
|
|
|
|
void setCStyleHexView(const bool enable)
|
|
{
|
|
cStyleHexEnabled = enable;
|
|
}
|
|
|
|
#if defined(QT_CORE_LIB)
|
|
|
|
typedef struct {
|
|
char flag_cstyle_Xh;
|
|
UString* string;
|
|
} qstring_opt_t;
|
|
|
|
void qstring_out(char c, void* extra_arg)
|
|
{
|
|
((qstring_opt_t*)extra_arg)->string->append(c);
|
|
}
|
|
|
|
UString usprintf(const char* fmt, ...)
|
|
{
|
|
UString msg;
|
|
qstring_opt_t opt = { cStyleHexEnabled ? '\1' : '\0', &msg };
|
|
|
|
va_list vl;
|
|
va_start(vl, fmt);
|
|
|
|
int n = vofctprintf(qstring_out, &opt, fmt, vl);
|
|
|
|
va_end(vl);
|
|
return msg;
|
|
}
|
|
|
|
UString urepeated(char c, int len)
|
|
{
|
|
return UString(len, c);
|
|
}
|
|
#else
|
|
/* Give WATCOM C/C++, MSVC some latitude for their non-support of vsnprintf */
|
|
#if defined(__WATCOMC__) || defined(_MSC_VER)
|
|
#define exvsnprintf(r,b,n,f,a) {r = _vsnprintf (b,n,f,a);}
|
|
#else
|
|
#ifdef BSTRLIB_NOVSNP
|
|
/* This is just a hack. If you are using a system without a vsnprintf, it is
|
|
not recommended that bformat be used at all. */
|
|
#define exvsnprintf(r,b,n,f,a) {vsprintf (b,f,a); r = -1;}
|
|
#define START_VSNBUFF (256)
|
|
#else
|
|
|
|
#if defined (__GNUC__) && !defined (__PPC__) && !defined(__WIN32__)
|
|
/* Something is making gcc complain about this prototype not being here, so
|
|
I've just gone ahead and put it in. */
|
|
extern "C" {
|
|
extern int vsnprintf(char *buf, size_t count, const char *format, va_list arg);
|
|
}
|
|
#endif
|
|
|
|
#define exvsnprintf(r,b,n,f,a) {r = vsnprintf (b,n,f,a);}
|
|
#endif
|
|
#endif
|
|
|
|
#ifndef START_VSNBUFF
|
|
#define START_VSNBUFF (16)
|
|
#endif
|
|
|
|
UString usprintf(const char* fmt, ...)
|
|
{
|
|
UString msg;
|
|
bstring b;
|
|
va_list arglist;
|
|
int r, n;
|
|
|
|
if (fmt == NULL) {
|
|
msg = "<NULL>";
|
|
}
|
|
else {
|
|
|
|
if ((b = bfromcstr("")) == NULL) {
|
|
msg = "<NULL>";
|
|
}
|
|
else {
|
|
if ((n = (int)(2 * (strlen)(fmt))) < START_VSNBUFF) n = START_VSNBUFF;
|
|
for (;;) {
|
|
if (BSTR_OK != balloc(b, n + 2)) {
|
|
b = bformat("<NULL>");
|
|
break;
|
|
}
|
|
|
|
va_start(arglist, fmt);
|
|
*(char*)b->data = cStyleHexEnabled ? '\1' : '\0';
|
|
r = vosnprintf_((char*)b->data, n + 1, fmt, arglist);
|
|
va_end(arglist);
|
|
|
|
b->data[n] = '\0';
|
|
b->slen = (int)(strlen)((char *)b->data);
|
|
|
|
if (b->slen < n) break;
|
|
if (r > n) n = r; else n += n;
|
|
}
|
|
msg = *b;
|
|
bdestroy(b);
|
|
}
|
|
}
|
|
|
|
return msg;
|
|
}
|
|
|
|
UString urepeated(char c, int len)
|
|
{
|
|
return UString(c, len);
|
|
}
|
|
#endif
|
|
|
|
UString uFromUcs2(const char* str, size_t max_len)
|
|
{
|
|
// Naive implementation assuming that only ASCII LE part of UCS2 is used, str may not be aligned.
|
|
UString msg;
|
|
const char *str8 = str;
|
|
size_t rest = (max_len == 0) ? SIZE_MAX : max_len;
|
|
while (str8[0] && rest) {
|
|
msg += str8[0];
|
|
str8 += 2;
|
|
rest--;
|
|
}
|
|
return msg;
|
|
}
|