WebKit is not completely open-source. Apple encapsulates a piece of code in a static library (libwebkitsysteminterfacexxxx. A) and does not provide source code. In addition, different OS versions (including IOS) have specific versions.
This is what I learned from my analysis today. I think the process is interesting and I want to record it.
1. There is such source code in WebKit (Laguage. mm):
static String httpStyleLanguageCode(NSString *languageCode){ ASSERT(isMainThread()); // Look up the language code using CFBundle. RetainPtr<CFStringRef> preferredLanguageCode(AdoptCF, wkCopyCFLocalizationPreferredName((CFStringRef)languageCode));
Wkcopycflocalizationpreferredname has only the following definitions and the Implementation Code cannot be found:
extern CFStringRef (*wkCopyCFLocalizationPreferredName)(CFStringRef);
2. query the address information of wkcopycflocalizationpreferredname at runtime.:
(lldb) p wkCopyCFLocalizationPreferredName(CFStringRef (*)(CFStringRef)) $0 = 0x0000000100478a49 (WebKit2`WKCopyCFLocalizationPreferredName)(lldb) image lookup -s WKCopyCFLocalizationPreferredName1 symbols match 'WKCopyCFLocalizationPreferredName' in /Volumes/Data/Project/Webkit/webkitSvn/Build/Products/Debug/WebKit2.framework/Versions/A/WebKit2: Address: WebKit2[0x0000000000464a49] (WebKit2.__TEXT.__text + 4600745) Summary: WebKit2`WKCopyCFLocalizationPreferredName1 symbols match 'WKCopyCFLocalizationPreferredName' in /Volumes/Data/Project/Webkit/webkitSvn/Build/Products/Debug/WebKit.framework/Versions/A/WebKit: Address: WebKit[0x00000000001b8275] (WebKit.__TEXT.__text + 1795141) Summary: WebKit`WKCopyCFLocalizationPreferredName
We can see that the code is located in webkit2.framework, but there is no source code information, so it is necessary to link a static library.
3. Check the compilation settings of the project and find the library to be linked.:
You can also find different system versions in the definition of webkit_system_interface_library.
You can find a library in use:
4. Open it with IDA (trial version) and check for wkcopycflocalizationpreferredname.:
You can also use nm to check the source file. Obviously, webkitsysteminterface. O cannot find the source code:
nm -a libWebKitSystemInterfaceLion.a/XXXXXX/Build/Products/Debug/libWebKitSystemInterfaceLion.a(WebKitSystemInterface.o):0000000000002591 t -[NSWindowGraphicsContext(WebKitSystemInterface) _WebKitSystemInterface_setGraphicsPort:]0000000000008d98 s -[NSWindowGraphicsContext(WebKitSystemInterface) _WebKitSystemInterface_setGraphicsPort:].eh00000000000090a8 S _WKCopyBundleURLForExecutableURL.eh00000000000006c7 T _WKCopyCFLocalizationPreferredName0000000000008200 S _WKCopyCFLocalizationPreferredName.eh
The following code is displayed in the disassembly:
function _WKCopyCFLocalizationPreferredName { CFBundleGetLocalizationInfoForLocalization(arg_0, &var_32, &var_28, &var_24, &var_20); rax = CFBundleCopyLocalizationForLocalizationInfo(var_32, var_28, var_24, var_20); return rax;}
It is very simple, that is, two function calls are involved. The problem is that these two functions are not in the development documentation.
5. Continue to find the origins of libwebkitsysteminterfacexxx... WebKit projects are all generated through gyp. The following description is mentioned in the open-up:
WebCore. Gyp
['OS = "Mac "',{
'Targets ':[
{
# On the Mac, libwebkitsysteminterface *. A is used to help WebCore
# Interface with the system. This library is supplied as a static
# LibraryIn binary format. At present, it contains into global
# Symbols not marked private_extern. It shoshould be considered
# Implementation detail of WebCore, and does not need these symbols
# To be exposed so widely.
#
# This target contains an action that cracks open the existing
# Static library and rebuilds it with these global symbols
# Transformed to private_extern.
'Target _ name': 'webkit _ system_interface ',
It is provided in binary format only. No problem. If there is a disassembly result, writing the same function is not a problem.
6. Find the origins of the two private APIs.
UseImage lookup-SIt is easy to determine that the two functions are in corefundation. framework. You can also find the declaration in the Apple open source (Class-dump is not good for the C interface ):
Cfbundlepriv. h on opensource.apple.com
Cfbundlegetlocalizationinfoforlocalization
Cfbundlecopylocalizationforlocalizationinfo
The following declaration can be used:
extern "C" {CF_EXPORT Boolean CFBundleGetLocalizationInfoForLocalization(CFStringRef localizationName, SInt32 *languageCode, SInt32 *regionCode, SInt32 *scriptCode, CFStringEncoding *stringEncoding);CF_EXPORT CFStringRef CFBundleCopyLocalizationForLocalizationInfo(SInt32 languageCode, SInt32 regionCode, SInt32 scriptCode, CFStringEncoding stringEncoding);}