Skip to content

Commit

Permalink
fix can’t find strlen function address question
Browse files Browse the repository at this point in the history
  • Loading branch information
iainchen committed Mar 7, 2023
1 parent 2143f9f commit 5d25496
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 69 deletions.
3 changes: 3 additions & 0 deletions symdl/symdl/symdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,8 @@ void *symdl(const char *symbol){
return pointer;
}
}
if (strcmp(symbol, "strlen") == 0) {
return symdl("_platform_strlen");
}
return NULL;
}
36 changes: 18 additions & 18 deletions symdl_example/symdl_example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
8941CAED28B3386500B77455 /* SomeCppFile.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8941CAEB28B3386500B77455 /* SomeCppFile.cpp */; };
89E7B07A25651F06004B02D5 /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 89E7B07925651F06004B02D5 /* AppDelegate.mm */; };
89E7B07A25651F06004B02D5 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 89E7B07925651F06004B02D5 /* AppDelegate.m */; };
89E7B07D25651F06004B02D5 /* SceneDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 89E7B07C25651F06004B02D5 /* SceneDelegate.m */; };
89E7B08025651F06004B02D5 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 89E7B07F25651F06004B02D5 /* ViewController.m */; };
89E7B08325651F06004B02D5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 89E7B08125651F06004B02D5 /* Main.storyboard */; };
Expand All @@ -20,11 +19,9 @@

/* Begin PBXFileReference section */
0648422A8C85329A1854638B /* Pods-symdl_example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-symdl_example.release.xcconfig"; path = "Target Support Files/Pods-symdl_example/Pods-symdl_example.release.xcconfig"; sourceTree = "<group>"; };
8941CAEB28B3386500B77455 /* SomeCppFile.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SomeCppFile.cpp; sourceTree = "<group>"; };
8941CAEC28B3386500B77455 /* SomeCppFile.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = SomeCppFile.hpp; sourceTree = "<group>"; };
89E7B07525651F05004B02D5 /* symdl_example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = symdl_example.app; sourceTree = BUILT_PRODUCTS_DIR; };
89E7B07825651F06004B02D5 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
89E7B07925651F06004B02D5 /* AppDelegate.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AppDelegate.mm; sourceTree = "<group>"; };
89E7B07925651F06004B02D5 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
89E7B07B25651F06004B02D5 /* SceneDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SceneDelegate.h; sourceTree = "<group>"; };
89E7B07C25651F06004B02D5 /* SceneDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SceneDelegate.m; sourceTree = "<group>"; };
89E7B07E25651F06004B02D5 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -89,13 +86,11 @@
isa = PBXGroup;
children = (
89E7B07825651F06004B02D5 /* AppDelegate.h */,
89E7B07925651F06004B02D5 /* AppDelegate.mm */,
89E7B07925651F06004B02D5 /* AppDelegate.m */,
89E7B07B25651F06004B02D5 /* SceneDelegate.h */,
89E7B07C25651F06004B02D5 /* SceneDelegate.m */,
89E7B07E25651F06004B02D5 /* ViewController.h */,
89E7B07F25651F06004B02D5 /* ViewController.m */,
8941CAEC28B3386500B77455 /* SomeCppFile.hpp */,
8941CAEB28B3386500B77455 /* SomeCppFile.cpp */,
89E7B08125651F06004B02D5 /* Main.storyboard */,
89E7B08425651F07004B02D5 /* Assets.xcassets */,
89E7B08625651F07004B02D5 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -201,9 +196,8 @@
buildActionMask = 2147483647;
files = (
89E7B08025651F06004B02D5 /* ViewController.m in Sources */,
89E7B07A25651F06004B02D5 /* AppDelegate.mm in Sources */,
89E7B07A25651F06004B02D5 /* AppDelegate.m in Sources */,
89E7B08B25651F07004B02D5 /* main.m in Sources */,
8941CAED28B3386500B77455 /* SomeCppFile.cpp in Sources */,
89E7B07D25651F06004B02D5 /* SceneDelegate.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -281,7 +275,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -334,7 +328,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand All @@ -349,16 +343,19 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 59669493D8;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 59669493D8;
INFOPLIST_FILE = symdl_example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.yongpengliang.symdl;
PRODUCT_BUNDLE_IDENTIFIER = com.ypl.demo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = comypldemo;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -370,16 +367,19 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 59669493D8;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 59669493D8;
INFOPLIST_FILE = symdl_example/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.tencent.itop.example123;
PRODUCT_BUNDLE_IDENTIFIER = com.ypl.demo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
"PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = comypldemo;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1420"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "89E7B07425651F05004B02D5"
BuildableName = "symdl_example.app"
BlueprintName = "symdl_example"
ReferencedContainer = "container:symdl_example.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "89E7B07425651F05004B02D5"
BuildableName = "symdl_example.app"
BlueprintName = "symdl_example"
ReferencedContainer = "container:symdl_example.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "89E7B07425651F05004B02D5"
BuildableName = "symdl_example.app"
BlueprintName = "symdl_example"
ReferencedContainer = "container:symdl_example.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@
<integer>2</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>89E7B07425651F05004B02D5</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,22 @@
uuid = "ACA7B37E-4A24-40D2-803F-921A02E92972"
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "E5127474-E9D8-4443-82B1-71B195AF74E8"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "symdl_example/AppDelegate.mm"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "54"
endingLineNumber = "54"
landmarkName = "-application:didFinishLaunchingWithOptions:"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#import "AppDelegate.h"
#import <dlfcn.h>
#import <symdl/symdl.h>
#import "SomeCppFile.hpp"
#import <string.h>
#import <mach-o/stab.h>

extern size_t platform_strlen(const char *__s);

SomeCppClass sc2;

@interface AppDelegate ()

Expand All @@ -22,28 +24,37 @@ @implementation AppDelegate
NSString * MyNSStringGlobalVar = @"efasg";
const char * MyCStringGlobalVar = "afaf";

extern "C" void my_load(void *p){
NSLog(@"%p", p);
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


void *fopen_ptr = symdl("fopen");


printf("fopen addrss: %p\n", fopen);
printf("dymdl fopen addrss: %p\n", fopen_ptr);



int *MyIntGlobalVarPtr = (int *)symdl("MyIntGlobalVar");
char **MyCStringGlobalVarPtr = (char * *)symdl("MyCStringGlobalVar");
NSString * const*MyNSStringGlobalVarPtr = (NSString * const*)symdl("MyNSStringGlobalVar");

NSLog(@"MyIntGlobalVar: %d", *MyIntGlobalVarPtr);
NSLog(@"MyCStringGlobalVar: %s", *MyCStringGlobalVarPtr);
NSLog(@"MyNSStringGlobalVar: %@", *MyNSStringGlobalVarPtr);






size_t (*strPtr)(const char *) = symdl("strlen");;
size_t (*_platform_strlenPtr)(const char *) = symdl("_platform_strlen");



printf("%zu %zu", strPtr("agaef"), _platform_strlenPtr("aafea444"));
//

return YES;
}
Expand Down
15 changes: 0 additions & 15 deletions symdl_example/symdl_example/SomeCppFile.cpp

This file was deleted.

24 changes: 0 additions & 24 deletions symdl_example/symdl_example/SomeCppFile.hpp

This file was deleted.

0 comments on commit 5d25496

Please sign in to comment.