[PATCH 2/2] [WineDump]: simplify guid dumping
Eric Pouech
eric.pouech at wanadoo.fr
Sat Feb 10 02:10:13 CST 2007
A+
---
tools/winedump/debug.c | 4 +---
tools/winedump/dump.c | 32 ++++++++++++++++++--------------
tools/winedump/lnk.c | 15 +++++++--------
tools/winedump/pdb.c | 3 +--
tools/winedump/winedump.h | 2 +-
5 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/tools/winedump/debug.c b/tools/winedump/debug.c
index 278b547..4f26c2b 100644
--- a/tools/winedump/debug.c
+++ b/tools/winedump/debug.c
@@ -425,11 +425,9 @@ static void dump_codeview_headers(unsign
if (memcmp(signature, "RSDS", 4) == 0)
{
const OMFSignatureRSDS* rsds_data;
- char guid_str[40];
rsds_data = (const void *)cv_base;
- printf(" Guid: %s\n",
- guid_to_string(&rsds_data->guid, guid_str, sizeof(guid_str)));
+ printf(" Guid: %s\n", get_guid_str(&rsds_data->guid));
printf(" Dunno: %08X\n", rsds_data->unknown);
printf(" Filename: %s\n", rsds_data->name);
return;
diff --git a/tools/winedump/dump.c b/tools/winedump/dump.c
index 1d15995..8310bfb 100644
--- a/tools/winedump/dump.c
+++ b/tools/winedump/dump.c
@@ -1,7 +1,7 @@
/*
* File dumping utility
*
- * Copyright 2001,2005 Eric Pouech
+ * Copyright 2001,2007 Eric Pouech
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -96,13 +96,9 @@ const char *get_time_str(unsigned long _
const time_t t = (const time_t)_t;
const char *str = ctime(&t);
size_t len;
- static char buf[128];
+ char* buf;
- if (!str) /* not valid time */
- {
- strcpy(buf, "not valid time");
- return buf;
- }
+ if (!str) return "not valid time";
len = strlen(str);
/* FIXME: I don't get the same values from MS' pedump running under Wine...
@@ -110,8 +106,12 @@ const char *get_time_str(unsigned long _
*/
if (len && str[len-1] == '\n') len--;
if (len >= sizeof(buf)) len = sizeof(buf) - 1;
- memcpy( buf, str, len );
- buf[len] = 0;
+ buf = dump_want_n(len + 1);
+ if (buf)
+ {
+ memcpy( buf, str, len );
+ buf[len] = 0;
+ }
return buf;
}
@@ -200,12 +200,16 @@ const char* get_symbol_str(const char* s
return ret;
}
-char* guid_to_string(const GUID* guid, char* str, size_t sz)
+const char* get_guid_str(const GUID* guid)
{
- snprintf(str, sz, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
- guid->Data1, guid->Data2, guid->Data3,
- guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
- guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
+ char* str;
+
+ str = dump_want_n(39);
+ if (str)
+ sprintf(str, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
+ guid->Data1, guid->Data2, guid->Data3,
+ guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
+ guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
return str;
}
diff --git a/tools/winedump/lnk.c b/tools/winedump/lnk.c
index 91f109c..661e48d 100644
--- a/tools/winedump/lnk.c
+++ b/tools/winedump/lnk.c
@@ -279,14 +279,14 @@ static int dump_advertise_info(const cha
printf("%s = %s\n", type, avt->bufA);
if (avt->magic == 0xa0000006)
{
- char prod_str[40], comp_str[40], feat_str[40];
- const char *feat, *comp;
+ char comp_str[40];
+ const char *feat, *comp, *prod_str, *feat_str;
GUID guid;
if (base85_to_guid(avt->bufA, &guid))
- guid_to_string( &guid, prod_str, sizeof(prod_str) );
+ prod_str = get_guid_str( &guid );
else
- strcpy( prod_str, "?" );
+ prod_str = "?";
comp = &avt->bufA[20];
feat = strchr(comp,'>');
@@ -303,9 +303,9 @@ static int dump_advertise_info(const cha
}
if (feat && feat[0] == '>' && base85_to_guid( &feat[1], &guid ))
- guid_to_string( &guid, feat_str, sizeof(feat_str) );
+ feat_str = get_guid_str( &guid );
else
- feat_str[0] = 0;
+ feat_str = "";
printf(" product: %s\n", prod_str);
printf(" component: %s\n", comp_str );
@@ -332,7 +332,6 @@ enum FileSig get_kind_lnk(void)
void lnk_dump(void)
{
const LINK_HEADER* hdr;
- char guid[40];
offset = 0;
hdr = fetch_block();
@@ -340,7 +339,7 @@ void lnk_dump(void)
printf("Header\n");
printf("------\n\n");
printf("Size: %04x\n", hdr->dwSize);
- printf("GUID: %s\n", guid_to_string(&hdr->MagicGuid, guid, sizeof(guid)));
+ printf("GUID: %s\n", get_guid_str(&hdr->MagicGuid));
printf("FileAttr: %08x\n", hdr->dwFileAttr);
printf("FileLength: %08x\n", hdr->dwFileLength);
diff --git a/tools/winedump/pdb.c b/tools/winedump/pdb.c
index bd71ede..c03967c 100644
--- a/tools/winedump/pdb.c
+++ b/tools/winedump/pdb.c
@@ -625,7 +625,6 @@ static void pdb_ds_dump(void)
if (root)
{
const char* ptr;
- char guid_str[40];
printf("Root:\n"
"\tVersion: %u\n"
@@ -636,7 +635,7 @@ static void pdb_ds_dump(void)
root->Version,
root->TimeDateStamp,
root->Age,
- guid_to_string(&root->guid, guid_str, sizeof(guid_str)),
+ get_guid_str(&root->guid),
root->cbNames);
for (ptr = &root->names[0]; ptr < &root->names[0] + root->cbNames; ptr += strlen(ptr) + 1)
printf("\tString: %s\n", ptr);
diff --git a/tools/winedump/winedump.h b/tools/winedump/winedump.h
index 55406ab..506ab99 100644
--- a/tools/winedump/winedump.h
+++ b/tools/winedump/winedump.h
@@ -236,11 +236,11 @@ void dump_data( const unsigne
const char* get_time_str( unsigned long );
unsigned int strlenW( const unsigned short *str );
void dump_unicode_str( const unsigned short *str, int len );
+const char* get_guid_str(const GUID* guid);
const char* get_symbol_str(const char* symname);
void dump_file_header(const IMAGE_FILE_HEADER *);
void dump_optional_header(const IMAGE_OPTIONAL_HEADER32 *, UINT);
void dump_section(const IMAGE_SECTION_HEADER *);
-char* guid_to_string(const GUID* guid, char *str, size_t sz);
enum FileSig get_kind_exec(void);
void dos_dump( void );
More information about the wine-patches
mailing list