From 6d1c5812e691c835fd248d8f21a7b78628b4bbe3 Mon Sep 17 00:00:00 2001 From: vit9696 Date: Wed, 18 Jul 2018 01:37:47 +0300 Subject: [PATCH] Fix 0x handling --- README.md | 4 + efidevp.c | 10 +- gfxutil.xcodeproj/project.pbxproj | 47 ++++++---- main.c | 149 +++++++++++++++++++++++++----- main.h | 2 +- utils.c | 6 +- 6 files changed, 172 insertions(+), 46 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8c3e4d5 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +gfxutil +======= + +A tool to work with Device Properties commonly found in Apple Mac firmwares by [mcmatrix](http://forum.netkas.org/index.php?action=profile;u=4). Usage examples and changelogs may be found at [forum.netkas.org](http://forum.netkas.org/index.php?topic=64.0). You are free to use it and whatever you do please keep the result free for community. diff --git a/efidevp.c b/efidevp.c index f01b7ec..ec67cfc 100644 --- a/efidevp.c +++ b/efidevp.c @@ -227,13 +227,14 @@ EFI_DEVICE_PATH *UnpackDevicePath (EFI_DEVICE_PATH *DevPath) } // Allocate space for the unpacked path - NewPath = (EFI_DEVICE_PATH *)calloc(Size, sizeof(UINT8)); - + NewPath = (EFI_DEVICE_PATH *)malloc(Size); + if (NewPath != NULL) { - assert(((UINT32) NewPath) % MIN_ALIGNMENT_SIZE == 0); + memset(NewPath, 0, Size); + // Copy each node Src = DevPath; Dest = NewPath; @@ -296,9 +297,10 @@ EFI_DEVICE_PATH *CreateDeviceNode (UINT8 NodeType, UINT8 NodeSubType, UINT16 Nod return NULL; } - Node = (EFI_DEVICE_PATH *) calloc ((UINT32) NodeLength, sizeof(UINT8)); + Node = (EFI_DEVICE_PATH *) malloc ((UINT32) NodeLength); if (Node != NULL) { + memset(Node, 0, NodeLength); Node->Type = NodeType; Node->SubType = NodeSubType; SetDevicePathNodeLength (Node, NodeLength); diff --git a/gfxutil.xcodeproj/project.pbxproj b/gfxutil.xcodeproj/project.pbxproj index edfeab1..74a9ce0 100644 --- a/gfxutil.xcodeproj/project.pbxproj +++ b/gfxutil.xcodeproj/project.pbxproj @@ -8,11 +8,11 @@ /* Begin PBXBuildFile section */ 8DD76F770486A8DE00D96B5E /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = 08FB7796FE84155DC02AAC07 /* main.c */; settings = {ATTRIBUTES = (); }; }; - 8DD76F790486A8DE00D96B5E /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 09AB6884FE841BABC02AAC07 /* CoreFoundation.framework */; }; 8DD76F7C0486A8DE00D96B5E /* gfxutil.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6859E970290921104C91782 /* gfxutil.1 */; }; 9813AB380D12A271001DF28C /* utils.c in Sources */ = {isa = PBXBuildFile; fileRef = 9813AB360D12A271001DF28C /* utils.c */; }; 98CAD1240D322BF900808BB2 /* efidevp.c in Sources */ = {isa = PBXBuildFile; fileRef = 98CAD1230D322BF900808BB2 /* efidevp.c */; }; - 98CAD5760D360EF400808BB2 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 98CAD5750D360EF400808BB2 /* IOKit.framework */; }; + CE363A8220FE90F000ED7DC0 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE363A8120FE90F000ED7DC0 /* IOKit.framework */; }; + CE363A8420FE90FC00ED7DC0 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE363A8320FE90FC00ED7DC0 /* CoreFoundation.framework */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -30,15 +30,16 @@ /* Begin PBXFileReference section */ 08FB7796FE84155DC02AAC07 /* main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = ""; }; - 09AB6884FE841BABC02AAC07 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = /System/Library/Frameworks/CoreFoundation.framework; sourceTree = ""; }; 8DD76F7E0486A8DE00D96B5E /* gfxutil */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = gfxutil; sourceTree = BUILT_PRODUCTS_DIR; }; 9813AB360D12A271001DF28C /* utils.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = utils.c; sourceTree = ""; }; 9813AB370D12A271001DF28C /* utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = utils.h; sourceTree = ""; }; 98C862550D28CB8000DAEFF5 /* efidevp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = efidevp.h; sourceTree = ""; }; 98CAD1230D322BF900808BB2 /* efidevp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = efidevp.c; sourceTree = ""; }; 98CAD3FE0D3381B500808BB2 /* main.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = main.h; sourceTree = ""; }; - 98CAD5750D360EF400808BB2 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = /System/Library/Frameworks/IOKit.framework; sourceTree = ""; }; C6859E970290921104C91782 /* gfxutil.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = gfxutil.1; sourceTree = ""; }; + CE363A8120FE90F000ED7DC0 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; }; + CE363A8320FE90FC00ED7DC0 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; }; + CEC0494720FEA1B300FBCAC9 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -46,8 +47,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8DD76F790486A8DE00D96B5E /* CoreFoundation.framework in Frameworks */, - 98CAD5760D360EF400808BB2 /* IOKit.framework in Frameworks */, + CE363A8420FE90FC00ED7DC0 /* CoreFoundation.framework in Frameworks */, + CE363A8220FE90F000ED7DC0 /* IOKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -57,11 +58,10 @@ 08FB7794FE84155DC02AAC07 /* gfxutil */ = { isa = PBXGroup; children = ( - 98CAD5750D360EF400808BB2 /* IOKit.framework */, 08FB7795FE84155DC02AAC07 /* Source */, C6859E96029091FE04C91782 /* Documentation */, - 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */, 19C28FBDFE9D53C911CA2CBB /* Products */, + CE363A8020FE90F000ED7DC0 /* Frameworks */, ); name = gfxutil; sourceTree = ""; @@ -79,14 +79,6 @@ name = Source; sourceTree = ""; }; - 08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */ = { - isa = PBXGroup; - children = ( - 09AB6884FE841BABC02AAC07 /* CoreFoundation.framework */, - ); - name = "External Frameworks and Libraries"; - sourceTree = ""; - }; 19C28FBDFE9D53C911CA2CBB /* Products */ = { isa = PBXGroup; children = ( @@ -99,10 +91,20 @@ isa = PBXGroup; children = ( C6859E970290921104C91782 /* gfxutil.1 */, + CEC0494720FEA1B300FBCAC9 /* README.md */, ); name = Documentation; sourceTree = ""; }; + CE363A8020FE90F000ED7DC0 /* Frameworks */ = { + isa = PBXGroup; + children = ( + CE363A8320FE90FC00ED7DC0 /* CoreFoundation.framework */, + CE363A8120FE90F000ED7DC0 /* IOKit.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -172,6 +174,7 @@ GCC_MODEL_TUNING = G5; GCC_OPTIMIZATION_LEVEL = 0; INSTALL_PATH = /usr/local/bin; + ONLY_ACTIVE_ARCH = NO; PRODUCT_NAME = gfxutil; ZERO_LINK = YES; }; @@ -191,6 +194,8 @@ 1DEB924C08733DCA0010E9CD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; @@ -217,15 +222,19 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.6; ONLY_ACTIVE_ARCH = YES; PREBINDING = NO; - SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; + SDKROOT = macosx; + VALID_ARCHS = "i386 x86_64"; }; name = Debug; }; 1DEB924D08733DCA0010E9CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; @@ -251,8 +260,10 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.6; PREBINDING = NO; - SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk"; + SDKROOT = macosx; + VALID_ARCHS = "i386 x86_64"; }; name = Release; }; diff --git a/main.c b/main.c index 77fac86..efdb10e 100644 --- a/main.c +++ b/main.c @@ -29,7 +29,7 @@ static int unilen(const char *str, int len) { unsigned long ch; int posn = 0; - int nbytes = 0; + int nbytes = 2; while(posn < len) { ch = UTF8ReadChar(str, len, &posn); @@ -337,6 +337,32 @@ unsigned char *gfx2bin(GFX_HEADER *gfx) return NULL; } +static void free_gfx_blockheader_list(GFX_BLOCKHEADER *head, GFX_BLOCKHEADER *end) +{ + GFX_BLOCKHEADER *tmp; + + do { + if (head) { + tmp = head; + head = head->next; + free(tmp); + } + } while (head != end); +} + +static void free_gfx_entry_list(GFX_ENTRY *head, GFX_ENTRY *end) +{ + GFX_ENTRY *tmp; + + do { + if (head) { + tmp = head; + head = head->next; + free(tmp); + } + } while (head != end); +} + // this reads gfx binary info and parses it GFX_HEADER *parse_binary(unsigned char * bp, SETTINGS settings) { @@ -349,7 +375,7 @@ GFX_HEADER *parse_binary(unsigned char * bp, SETTINGS settings) GFX_ENTRY *gfx_entry_head = (GFX_ENTRY *) NULL; GFX_ENTRY *gfx_entry_end = (GFX_ENTRY *) NULL; unsigned char *data = NULL, *bin = NULL, *tmp = NULL, *dpathtmp = NULL; - char * str; + char * str = NULL; unsigned int str_len, data_len, size, length; int i,j; @@ -380,6 +406,7 @@ GFX_HEADER *parse_binary(unsigned char * bp, SETTINGS settings) if(!gfx_blockheader) { fprintf(stderr, "parse_binary: out of memory\n"); + free_gfx_blockheader_list(gfx_blockheader_head, gfx_blockheader_end); free(gfx_header); return NULL; } @@ -402,6 +429,8 @@ GFX_HEADER *parse_binary(unsigned char * bp, SETTINGS settings) { // BugBug: Code to catch bogus device path fprintf(stderr, "parse_binary: Cannot find device path end! Probably a bogus device path.\n"); + free_gfx_blockheader_list(gfx_blockheader_head, gfx_blockheader_end); + free(gfx_blockheader); free(gfx_header); return NULL; } @@ -415,7 +444,7 @@ GFX_HEADER *parse_binary(unsigned char * bp, SETTINGS settings) // read device path data gfx_blockheader->devpath_len = (unsigned int)abs((int)(tmp-bp)); - readbin(&bp, &size, &dpathtmp,gfx_blockheader->devpath_len); + assert(readbin(&bp, &size, &dpathtmp,gfx_blockheader->devpath_len)); gfx_blockheader->devpath = (EFI_DEVICE_PATH *)dpathtmp; gfx_entry_head = NULL; @@ -429,16 +458,20 @@ GFX_HEADER *parse_binary(unsigned char * bp, SETTINGS settings) if(!uni2str(bin, length, &str, &str_len)) { free(bin); - free(gfx_header); + free_gfx_blockheader_list(gfx_blockheader_head, gfx_blockheader_end); + free_gfx_entry_list(gfx_entry_head, gfx_entry_end); free(gfx_blockheader); + free(gfx_header); return NULL; } } else { free(bin); - free(gfx_header); + free_gfx_blockheader_list(gfx_blockheader_head, gfx_blockheader_end); + free_gfx_entry_list(gfx_entry_head, gfx_entry_end); free(gfx_blockheader); + free(gfx_header); return NULL; } @@ -446,10 +479,13 @@ GFX_HEADER *parse_binary(unsigned char * bp, SETTINGS settings) data_len -= 4; bp += 4; size -=4; if(!readbin(&bp, &size, &data, data_len)) { + free(str); free(data); free(bin); - free(gfx_header); + free_gfx_blockheader_list(gfx_blockheader_head, gfx_blockheader_end); + free_gfx_entry_list(gfx_entry_head, gfx_entry_end); free(gfx_blockheader); + free(gfx_header); return NULL; } @@ -457,10 +493,13 @@ GFX_HEADER *parse_binary(unsigned char * bp, SETTINGS settings) if(!gfx_entry) { fprintf(stderr, "parse_binary: out of memory\n"); + free(str); free(data); free(bin); - free(gfx_header); + free_gfx_blockheader_list(gfx_blockheader_head, gfx_blockheader_end); + free_gfx_entry_list(gfx_entry_head, gfx_entry_end); free(gfx_blockheader); + free(gfx_header); return NULL; } //read entries @@ -672,6 +711,8 @@ GFX_HEADER *CreateGFXFromPlist(CFPropertyListRef plist) if(!num_rec) { printf("CreateGFXFromPlist: empty dictionary block found in property list\n"); + free_gfx_blockheader_list(gfx_blockheader_head, gfx_blockheader_end); + free(gfx_header); return NULL; } @@ -691,12 +732,19 @@ GFX_HEADER *CreateGFXFromPlist(CFPropertyListRef plist) if (!bytes) { fprintf(stderr, "CreateGFXFromPlist: out of memory\n"); + free(gfx_blockheader); + free_gfx_blockheader_list(gfx_blockheader_head, gfx_blockheader_end); + free(gfx_header); return NULL; } - ret = CFStringGetBytes(dict_keys[i], CFRangeMake(0, count), kCFStringEncodingASCII, 0, false, bytes, count, &needed); - if(ret != count) // not ascii string + ret = CFStringGetBytes(dict_keys[i], CFRangeMake(0, count-1), kCFStringEncodingASCII, 0, false, bytes, count, &needed); + if(ret != count-1) // not ascii string { fprintf(stderr, "CreateGFXFromPlist: string conversion error occured, not ascii string!\n"); + free(gfx_blockheader); + free_gfx_blockheader_list(gfx_blockheader_head, gfx_blockheader_end); + free(gfx_header); + free(bytes); return NULL; } // add at end string terminator @@ -716,6 +764,10 @@ GFX_HEADER *CreateGFXFromPlist(CFPropertyListRef plist) if(gfx_blockheader->devpath == NULL) { fprintf(stderr, "CreateGFXFromPlist: device path conversion error occured, not correct sytax!\n"); + free(bytes); + free_gfx_blockheader_list(gfx_blockheader_head, gfx_blockheader_end); + free(gfx_header); + free(gfx_blockheader); return NULL; } gfx_blockheader->devpath_len = DevicePathSize (gfx_blockheader->devpath); @@ -723,6 +775,7 @@ GFX_HEADER *CreateGFXFromPlist(CFPropertyListRef plist) } free(key); + free(bytes); CFDictionaryGetKeysAndValues(this_block, (const void **)block_keys, (const void **)block_vals); gfx_entry_head = NULL; @@ -736,15 +789,24 @@ GFX_HEADER *CreateGFXFromPlist(CFPropertyListRef plist) if (!bytes) { fprintf(stderr, "CreateGFXFromPlist: out of memory\n"); + free_gfx_blockheader_list(gfx_blockheader_head, gfx_blockheader_end); + free_gfx_entry_list(gfx_entry_head, gfx_entry_end); + free(gfx_entry); return NULL; } - ret = CFStringGetBytes(block_keys[num_rec], CFRangeMake(0, count), kCFStringEncodingASCII, 0, false, bytes, count, &needed); - if(ret != count) // not ascii string + ret = CFStringGetBytes(block_keys[num_rec], CFRangeMake(0, count-1), kCFStringEncodingASCII, 0, false, bytes, count, &needed); + if(ret != count-1) // not ascii string { fprintf(stderr, "CreateGFXFromPlist: string conversion error occured, not ascii string!\n"); - return NULL; - } + free(bytes); + free_gfx_blockheader_list(gfx_blockheader_head, gfx_blockheader_end); + free_gfx_entry_list(gfx_entry_head, gfx_entry_end); + free(gfx_entry); + return NULL; + } + // add at end string terminator + bytes[needed] = '\0'; gfx_entry->key = (char *)bytes; gfx_entry->key_len = (unsigned int)needed; @@ -763,14 +825,23 @@ GFX_HEADER *CreateGFXFromPlist(CFPropertyListRef plist) if (!bytes) { fprintf(stderr, "CreateGFXFromPlist: out of memory\n"); + free_gfx_entry_list(gfx_entry_head, gfx_entry_end); + free(gfx_entry); + free(gfx_header); + free(gfx_blockheader); return NULL; } - ret = CFStringGetBytes(block_vals[num_rec], CFRangeMake(0, count), kCFStringEncodingASCII, 0, false, bytes, count, &needed); - if(ret != count) // not ascii string + ret = CFStringGetBytes(block_vals[num_rec], CFRangeMake(0, count-1), kCFStringEncodingASCII, 0, false, bytes, count, &needed); + if(ret != count-1) // not ascii string { fprintf(stderr, "CreateGFXFromPlist: string conversion error occured, not ascii string!\n"); - return NULL; + free(bytes); + free_gfx_entry_list(gfx_entry_head, gfx_entry_end); + free(gfx_entry); + free(gfx_header); + free(gfx_blockheader); + return NULL; } // add at end string terminator bytes[needed] = '\0'; @@ -844,6 +915,10 @@ GFX_HEADER *CreateGFXFromPlist(CFPropertyListRef plist) if (!bytes) { fprintf(stderr, "CreateGFXFromPlist: out of memory\n"); + free_gfx_entry_list(gfx_entry_head, gfx_entry_end); + free(gfx_entry); + free(gfx_header); + free(gfx_blockheader); return NULL; } @@ -860,6 +935,10 @@ GFX_HEADER *CreateGFXFromPlist(CFPropertyListRef plist) if (!bytes) { fprintf(stderr, "CreateGFXFromPlist: out of memory\n"); + free_gfx_entry_list(gfx_entry_head, gfx_entry_end); + free(gfx_entry); + free(gfx_header); + free(gfx_blockheader); return NULL; } bigint = CFBooleanGetValue(block_vals[num_rec]); @@ -875,6 +954,10 @@ GFX_HEADER *CreateGFXFromPlist(CFPropertyListRef plist) if (!bytes) { fprintf(stderr, "CreateGFXFromPlist: out of memory\n"); + free_gfx_entry_list(gfx_entry_head, gfx_entry_end); + free(gfx_entry); + free(gfx_header); + free(gfx_blockheader); return NULL; } CFDataGetBytes(block_vals[num_rec], CFRangeMake(0,needed), bytes); @@ -953,6 +1036,10 @@ CFPropertyListRef ReadPropertyList(CFURLRef fileURL) CFReadStreamClose(stream); CFRelease(stream); } + else + { + if (stream) CFRelease(stream); + } if(error) { @@ -963,16 +1050,31 @@ CFPropertyListRef ReadPropertyList(CFURLRef fileURL) if(plist == NULL) return NULL; - if(CFDictionaryGetTypeID() != CFGetTypeID(plist)) return NULL; - if(!CFPropertyListIsValid(plist, kCFPropertyListXMLFormat_v1_0)) return NULL; + if(CFDictionaryGetTypeID() != CFGetTypeID(plist)) + { + CFRelease(plist); + return NULL; + } + if(!CFPropertyListIsValid(plist, kCFPropertyListXMLFormat_v1_0)) + { + CFRelease(plist); + return NULL; + } return plist; } CFURLRef URLCreate(const char *path) { - CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, path, kCFStringEncodingASCII, kCFAllocatorNull), kCFURLPOSIXPathStyle, false); - return url; + CFStringRef cfpath = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, path, kCFStringEncodingASCII, kCFAllocatorNull); + if (cfpath) + { + CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfpath, kCFURLPOSIXPathStyle, false); + CFRelease(cfpath); + return url; + } + + return NULL; } static void usage() @@ -1172,7 +1274,7 @@ long getFileSize(const char *file) { if( !(filestat.st_mode & S_IFREG) ) filesize = 0; /* not a regular file */ else if( !(filestat.st_mode & S_IREAD) ) filesize = 0; /* not readable */ - else filesize = filestat.st_size; + else filesize = (long)filestat.st_size; } return(filesize); @@ -1428,9 +1530,12 @@ int main (int argc, char * argv[]) if(!gfx) { fprintf(stderr, "%s: cannot create gfx data from property list xml inputfile '%s'!\n",argv[0],settings.ifile); + if (fileURL) CFRelease(fileURL); exit(1); } + if(fileURL) CFRelease(fileURL); + CFRelease(plist); break; default: @@ -1505,8 +1610,10 @@ int main (int argc, char * argv[]) if(!WritePropertyList(plist,fileURL)) { fprintf(stderr, "%s: file '%s' cannot be open for writing property list data\n",argv[0], settings.ofile); + if (fileURL) CFRelease(fileURL); exit(1); } + if (fileURL) CFRelease(fileURL); CFRelease(plist); break; } diff --git a/main.h b/main.h index 7f7f2c1..96ee652 100644 --- a/main.h +++ b/main.h @@ -9,7 +9,7 @@ // Constants #define MAX_FILENAME 255 -#define VERSION "0.75b" +#define VERSION "0.76b" const unsigned char _HexTabLC[16]= "0123456789abcdef"; const unsigned char _HexTabUC[16]= "0123456789ABCDEF"; diff --git a/utils.c b/utils.c index c301951..9abe888 100644 --- a/utils.c +++ b/utils.c @@ -327,6 +327,7 @@ int UTF8WriteChar(char *str, unsigned long ch) // Skip the leading white space and '0x' or '0X' of a integer string char * TrimHexStr (char *Str, int *IsHex) { + int ZeroPrefix = 0; *IsHex = 0; // skip preceeding white space @@ -338,13 +339,14 @@ char * TrimHexStr (char *Str, int *IsHex) // skip preceeding zeros while (*Str && *Str == '0') { - Str += 1; + Str++; + ZeroPrefix++; } // skip preceeding character 'x' if (*Str && (*Str == 'x' || *Str == 'X')) { Str += 1; - *IsHex = 1; + *IsHex = ZeroPrefix == 1; } return Str;