Permalink
Browse files

recognized Pascal strings in the __cstring section in x86 code, and t…

…rying to replace libiberty with c++filt

git-svn-id: http://otx.osxninja.com/builds/trunk@293 5968870d-8a1b-0410-8ef2-9208d525af3e
  • Loading branch information...
1 parent 231bac0 commit 98f2dfbf78940701ffefd4df5fde3cdebc5454c7 otxdev committed Jul 2, 2007
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -27,7 +27,7 @@ int main(
#ifdef OTX_CLI
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- CLIController* controller =
+ CLIController* controller =
[[CLIController alloc] initWithArgs: argv count: argc];
if (!controller)
@@ -7,12 +7,14 @@
objects = {
/* Begin PBXBuildFile section */
+ 25A62EFD0C38A7C500B08D38 /* Prefs Output Icon.tif in Resources */ = {isa = PBXBuildFile; fileRef = 25A62EFA0C38A7C500B08D38 /* Prefs Output Icon.tif */; };
+ 25A62EFE0C38A7C500B08D38 /* Prefs General Icon.tif in Resources */ = {isa = PBXBuildFile; fileRef = 25A62EFB0C38A7C500B08D38 /* Prefs General Icon.tif */; };
+ 25A62EFF0C38A7C500B08D38 /* Main Window Background.tif in Resources */ = {isa = PBXBuildFile; fileRef = 25A62EFC0C38A7C500B08D38 /* Main Window Background.tif */; };
+ 25A62F060C38A86C00B08D38 /* App Icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 25A62F050C38A86C00B08D38 /* App Icon.icns */; };
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; };
8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
- E125C39D0A86B2D000098114 /* App Icon.icns in Resources */ = {isa = PBXBuildFile; fileRef = E125C39C0A86B2D000098114 /* App Icon.icns */; };
E13539830A6817C700CBDDE5 /* ObjcSwap.c in Sources */ = {isa = PBXBuildFile; fileRef = E13539820A6817C700CBDDE5 /* ObjcSwap.c */; };
E145F6D30B437F5900615A16 /* SmoothViewAnimation.m in Sources */ = {isa = PBXBuildFile; fileRef = E145F6D20B437F5900615A16 /* SmoothViewAnimation.m */; };
- E147FA8C0BD72B0400F0B657 /* Main Window Background.tif in Resources */ = {isa = PBXBuildFile; fileRef = E147FA8B0BD72B0400F0B657 /* Main Window Background.tif */; };
E172D5190A74874100C85E7A /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 8D1107310486CEB800E47090 /* Info.plist */; };
E182007209AE4CD800584B07 /* AppController.m in Sources */ = {isa = PBXBuildFile; fileRef = E182007009AE4CD800584B07 /* AppController.m */; };
E1978C9E0AC603A40096EE62 /* Help in Resources */ = {isa = PBXBuildFile; fileRef = E1978C6A0AC603A40096EE62 /* Help */; };
@@ -40,8 +42,6 @@
E1B135E50B185123002EB674 /* ObjcAccessors.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B135E30B185122002EB674 /* ObjcAccessors.m */; };
E1B1361F0B192AAC002EB674 /* ArchSpecifics.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B1361E0B192AAC002EB674 /* ArchSpecifics.m */; };
E1B136200B192AAC002EB674 /* ArchSpecifics.m in Sources */ = {isa = PBXBuildFile; fileRef = E1B1361E0B192AAC002EB674 /* ArchSpecifics.m */; };
- E1CB34440BAF828F00DAD44D /* Prefs General Icon.tif in Resources */ = {isa = PBXBuildFile; fileRef = E1CB34430BAF828E00DAD44D /* Prefs General Icon.tif */; };
- E1CB347F0BAFB54600DAD44D /* Prefs Output Icon.tif in Resources */ = {isa = PBXBuildFile; fileRef = E1CB347E0BAFB54500DAD44D /* Prefs Output Icon.tif */; };
E1F81AC50AE1EE02003D8E2C /* SmartCrashReportsInstall.o in Frameworks */ = {isa = PBXBuildFile; fileRef = E1F81AC40AE1EE02003D8E2C /* SmartCrashReportsInstall.o */; };
E1F81ADD0AE1EEEC003D8E2C /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E1F81AC80AE1EEEB003D8E2C /* Carbon.framework */; };
E1F81B090AE1EF07003D8E2C /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E1F81ADE0AE1EF07003D8E2C /* CoreFoundation.framework */; };
@@ -67,20 +67,22 @@
/* Begin PBXFileReference section */
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
+ 25A62EFA0C38A7C500B08D38 /* Prefs Output Icon.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = "Prefs Output Icon.tif"; path = "images/Prefs Output Icon.tif"; sourceTree = "<group>"; };
+ 25A62EFB0C38A7C500B08D38 /* Prefs General Icon.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = "Prefs General Icon.tif"; path = "images/Prefs General Icon.tif"; sourceTree = "<group>"; };
+ 25A62EFC0C38A7C500B08D38 /* Main Window Background.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; name = "Main Window Background.tif"; path = "images/Main Window Background.tif"; sourceTree = "<group>"; };
+ 25A62F050C38A86C00B08D38 /* App Icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = "App Icon.icns"; path = "images/App Icon.icns"; sourceTree = "<group>"; };
29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = "<group>"; };
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
32CA4F630368D1EE00C91783 /* otx_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = otx_Prefix.pch; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8D1107320486CEB800E47090 /* otx.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = otx.app; sourceTree = BUILT_PRODUCTS_DIR; };
E1167F1C09C8086900E7398D /* StolenDefs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StolenDefs.h; path = source/StolenDefs.h; sourceTree = "<group>"; };
- E125C39C0A86B2D000098114 /* App Icon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = "App Icon.icns"; sourceTree = "<group>"; };
E13539810A68178D00CBDDE5 /* SyscallStrings.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SyscallStrings.h; path = source/SyscallStrings.h; sourceTree = "<group>"; };
E13539820A6817C700CBDDE5 /* ObjcSwap.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ObjcSwap.c; path = source/ObjcSwap.c; sourceTree = "<group>"; };
E13539900A68185500CBDDE5 /* AppController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = AppController.h; path = source/AppController.h; sourceTree = "<group>"; };
E145F6D10B437F5900615A16 /* SmoothViewAnimation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SmoothViewAnimation.h; path = source/SmoothViewAnimation.h; sourceTree = "<group>"; };
E145F6D20B437F5900615A16 /* SmoothViewAnimation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SmoothViewAnimation.m; path = source/SmoothViewAnimation.m; sourceTree = "<group>"; };
- E147FA8B0BD72B0400F0B657 /* Main Window Background.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = "Main Window Background.tif"; sourceTree = "<group>"; };
E16222240A4F80F4007ECB26 /* Optimizations.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Optimizations.h; path = source/Optimizations.h; sourceTree = "<group>"; };
E182007009AE4CD800584B07 /* AppController.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = AppController.m; path = source/AppController.m; sourceTree = "<group>"; wrapsLines = 0; };
E1978C6B0AC603A40096EE62 /* English */ = {isa = PBXFileReference; lastKnownFileType = folder; name = English; path = English.lproj/Help; sourceTree = "<group>"; };
@@ -118,8 +120,6 @@
E1B1361E0B192AAC002EB674 /* ArchSpecifics.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = ArchSpecifics.m; path = source/Categories/ArchSpecifics.m; sourceTree = "<group>"; };
E1B136210B192ABE002EB674 /* ArchSpecifics.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ArchSpecifics.h; path = source/Categories/ArchSpecifics.h; sourceTree = "<group>"; };
E1BB58C80A50CB120076CDCA /* UserDefaultKeys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UserDefaultKeys.h; path = source/UserDefaultKeys.h; sourceTree = "<group>"; };
- E1CB34430BAF828E00DAD44D /* Prefs General Icon.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = "Prefs General Icon.tif"; sourceTree = "<group>"; };
- E1CB347E0BAFB54500DAD44D /* Prefs Output Icon.tif */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = "Prefs Output Icon.tif"; sourceTree = "<group>"; };
E1F483530B38DB4200CECE18 /* SharedDefs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SharedDefs.h; path = source/SharedDefs.h; sourceTree = "<group>"; };
E1F81AC20AE1EDC0003D8E2C /* SmartCrashReportsInstall.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SmartCrashReportsInstall.h; path = "source/Smart Crash Reports/SmartCrashReportsInstall.h"; sourceTree = "<group>"; };
E1F81AC40AE1EE02003D8E2C /* SmartCrashReportsInstall.o */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.objfile"; name = SmartCrashReportsInstall.o; path = "source/Smart Crash Reports/SmartCrashReportsInstall.o"; sourceTree = "<group>"; };
@@ -241,10 +241,10 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
- E125C39C0A86B2D000098114 /* App Icon.icns */,
- E147FA8B0BD72B0400F0B657 /* Main Window Background.tif */,
- E1CB34430BAF828E00DAD44D /* Prefs General Icon.tif */,
- E1CB347E0BAFB54500DAD44D /* Prefs Output Icon.tif */,
+ 25A62F050C38A86C00B08D38 /* App Icon.icns */,
+ 25A62EFA0C38A7C500B08D38 /* Prefs Output Icon.tif */,
+ 25A62EFB0C38A7C500B08D38 /* Prefs General Icon.tif */,
+ 25A62EFC0C38A7C500B08D38 /* Main Window Background.tif */,
8D1107310486CEB800E47090 /* Info.plist */,
29B97318FDCFA39411CA2CEA /* MainMenu.nib */,
E1978C6A0AC603A40096EE62 /* Help */,
@@ -387,9 +387,11 @@
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "otx" */;
+ compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 29B97314FDCFA39411CA2CEA /* otx */;
projectDirPath = "";
+ projectRoot = "";
targets = (
8D1107260486CEB800E47090 /* otx gui */,
E1FA33D00B1005450060060A /* otx cli */,
@@ -404,11 +406,11 @@
files = (
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */,
E172D5190A74874100C85E7A /* Info.plist in Resources */,
- E125C39D0A86B2D000098114 /* App Icon.icns in Resources */,
+ 25A62F060C38A86C00B08D38 /* App Icon.icns in Resources */,
+ 25A62EFF0C38A7C500B08D38 /* Main Window Background.tif in Resources */,
+ 25A62EFE0C38A7C500B08D38 /* Prefs General Icon.tif in Resources */,
+ 25A62EFD0C38A7C500B08D38 /* Prefs Output Icon.tif in Resources */,
E1978C9E0AC603A40096EE62 /* Help in Resources */,
- E1CB34440BAF828F00DAD44D /* Prefs General Icon.tif in Resources */,
- E1CB347F0BAFB54600DAD44D /* Prefs Output Icon.tif in Resources */,
- E147FA8C0BD72B0400F0B657 /* Main Window Background.tif in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -299,6 +299,7 @@ enum {
GPRegisterInfo mStack[MAX_STACK_SIZE];
TextFieldWidths mFieldWidths;
ProcOptions mOpts;
+ FILE* mCPFiltPipe;
// base pointers for indirect addressing
SInt8 mCurrentThunk; // x86 register identifier
@@ -16,6 +16,8 @@
#import "ObjectLoader.h"
#import "UserDefaultKeys.h"
+#define OTX_CPPFILT 1
+
// ============================================================================
@implementation ExeProcessor
@@ -28,7 +30,7 @@ @implementation ExeProcessor
// destruction. Do not reuse a single instance of those subclasses for
// multiple processings.
-// initWithURL:controller:andOptions:
+// initWithURL:controller:options:
// ----------------------------------------------------------------------------
- (id)initWithURL: (NSURL*)inURL
@@ -38,7 +40,7 @@ - (id)initWithURL: (NSURL*)inURL
if (!inURL || !inController || !inOptions)
return nil;
- if ((self = [super init]))
+ if (self = [super init])
{
mOFile = inURL;
mController = inController;
@@ -83,6 +85,15 @@ - (id)initWithURL: (NSURL*)inURL
mArchMagic = *(UInt32*)mRAMFile;
mExeIsFat = (mArchMagic == FAT_MAGIC || mArchMagic == FAT_CIGAM);
+ // Setup the C++ name demangler.
+ if (mOpts.demangleCppNames)
+ {
+ mCPFiltPipe = popen("c++filt -_", "r+");
+
+ if (!mCPFiltPipe)
+ fprintf(stderr, "otx: unable to open c++filt pipe.\n");
+ }
+
[self speedyDelivery];
}
@@ -142,6 +153,12 @@ - (void)dealloc
mLocalVars = nil;
}
+ if (mCPFiltPipe)
+ {
+ if (pclose(mCPFiltPipe) == -1)
+ perror("otx: unable to close c++filt pipe");
+ }
+
[self deleteFuncInfos];
[self deleteLinesFromList: mPlainLineListHead];
[self deleteLinesFromList: mVerboseLineListHead];
@@ -607,6 +624,28 @@ - (void)processLine: (Line*)ioLine;
// If we got here, we have a symbol name.
if (mOpts.demangleCppNames)
{
+#if OTX_CPPFILT
+ if (strstr(ioLine->chars, "__Z") == ioLine->chars)
+ {
+ char demangledName[MAX_COMMENT_LENGTH];
+
+ // Replace trailing colon with \0.
+ char* colonPos = strchr(ioLine->chars, ':');
+
+ if (colonPos)
+ *colonPos = 0;
+
+ fputs(ioLine->chars, mCPFiltPipe);
+ fputs("\n", mCPFiltPipe);
+ fgets(demangledName, MAX_COMMENT_LENGTH, mCPFiltPipe);
+
+ free(ioLine->chars);
+ ioLine->length = strlen(demangledName);
+ ioLine->chars = malloc(ioLine->length + 1);
+
+ strncpy(ioLine->chars, demangledName, ioLine->length + 1);
+ }
+#else
char* demString =
PrepareNameForDemangling(ioLine->chars);
@@ -637,6 +676,7 @@ - (void)processLine: (Line*)ioLine;
free(cpName);
}
}
+#endif
}
}
@@ -970,6 +1010,27 @@ - (void)processCodeLine: (Line**)ioLine;
// Demangle operands if necessary.
if (mLineOperandsCString[0] && mOpts.demangleCppNames)
{
+#if OTX_CPPFILT
+ if (strstr(mLineOperandsCString, "__Z") == mLineOperandsCString)
+ {
+ char demangledName[MAX_COMMENT_LENGTH];
+
+ fputs(mLineOperandsCString, mCPFiltPipe);
+ fputs("\n", mCPFiltPipe);
+ fgets(demangledName, MAX_COMMENT_LENGTH, mCPFiltPipe);
+
+ // Replace trailing newline with \0.
+ char* colonPos = strchr(demangledName, '\n');
+
+ if (colonPos)
+ *colonPos = 0;
+
+ UInt32 demangledLength = strlen(demangledName);
+
+ if (demangledLength < MAX_OPERANDS_LENGTH - 1)
+ strncpy(mLineOperandsCString, demangledName, demangledLength + 1);
+ }
+#else
char* demString =
PrepareNameForDemangling(mLineOperandsCString);
@@ -989,11 +1050,33 @@ - (void)processCodeLine: (Line**)ioLine;
free(cpName);
}
}
+#endif
}
// Demangle comment if necessary.
if (theCommentCString[0] && mOpts.demangleCppNames)
{
+#if OTX_CPPFILT
+ if (strstr(theCommentCString, "__Z") == theCommentCString)
+ {
+ char demangledName[MAX_COMMENT_LENGTH];
+
+ fputs(theCommentCString, mCPFiltPipe);
+ fputs("\n", mCPFiltPipe);
+ fgets(demangledName, MAX_COMMENT_LENGTH, mCPFiltPipe);
+
+ // Replace trailing newline with \0.
+ char* colonPos = strchr(demangledName, '\n');
+
+ if (colonPos)
+ *colonPos = 0;
+
+ UInt32 demangledLength = strlen(demangledName);
+
+ if (demangledLength < MAX_OPERANDS_LENGTH - 1)
+ strncpy(theCommentCString, demangledName, demangledLength + 1);
+ }
+#else
char* demString =
PrepareNameForDemangling(theCommentCString);
@@ -1013,6 +1096,7 @@ - (void)processCodeLine: (Line**)ioLine;
free(cpName);
}
}
+#endif
}
// Optionally add local offset.
@@ -1860,14 +1944,17 @@ - (char*)getPointer: (UInt32)inAddr
// not somewhere in the middle.
if (*(thePtr - 1) != 0 && inAddr != mCStringSect.s.addr)
thePtr = nil;
+ // Check if this may be a Pascal string. Thanks, Metrowerks.
+ else if (outType && strlen(thePtr) == thePtr[0] + 1)
+ *outType = PStringType;
}
else // (__TEXT,__const) (Str255* sometimes)
if (inAddr >= mConstTextSect.s.addr &&
inAddr < mConstTextSect.s.addr + mConstTextSect.size)
{
thePtr = (mConstTextSect.contents + (inAddr - mConstTextSect.s.addr));
- if (strlen(thePtr) == thePtr[0] + 1 && outType)
+ if (outType && strlen(thePtr) == thePtr[0] + 1)
*outType = PStringType;
else
thePtr = nil;
@@ -242,6 +242,15 @@ - (void)commentForLine: (Line*)inLine;
sscanf(inLine->info.code, "%02hhx", &opcode);
mLineCommentCString[0] = 0;
+/**/
+
+if (inLine->info.address == 0x0000ee05)
+{
+ UInt8 theBreak = 9;
+}
+
+/**/
+
switch (opcode)
{
case 0x0f: // 2-byte and SSE opcodes **add sysenter support here
@@ -1107,6 +1116,7 @@ - (void)commentForLine: (Line*)inLine;
break;
+ case PStringType:
case PointerType:
theSymPtr = theDummyPtr;

0 comments on commit 98f2dfb

Please sign in to comment.