Skip to content

Commit

Permalink
Add a fake window.navigator object in the JavaScript context
Browse files Browse the repository at this point in the history
The JavaScript execution of the player script would fail with
`TypeError: undefined is not an object (evaluating 'window.navigator.j')`
before it could evaluate the parts required to descramble the signature.

Fixes 0xced#144
  • Loading branch information
0xced committed May 14, 2015
1 parent f4f6932 commit 065e8ea
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#### Version 2.1.3

* Adaptation to YouTube API change. (#144)

#### Version 2.1.2

* Fixed playback of some protected videos. (#122)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ These steps will ensure that `#import <XCDYouTubeKit/XCDYouTubeKit.h>` will work
**Warning**: If you use the iOS static library and you are targeting iOS 7, add the JavaScriptCore framework. If you are targeting iOS 5 or 6, you must add the following *Other Linker Flags* instead to your app:

```
-Wl,-U,_JSContextGetGlobalObject -Wl,-U,_JSEvaluateScript -Wl,-U,_JSGlobalContextCreate -Wl,-U,_JSGlobalContextRelease -Wl,-U,_JSObjectCallAsFunction -Wl,-U,_JSObjectGetPrototype -Wl,-U,_JSObjectIsFunction -Wl,-U,_JSObjectSetProperty -Wl,-U,_JSStringCopyCFString -Wl,-U,_JSStringCreateWithCFString -Wl,-U,_JSStringRelease -Wl,-U,_JSValueIsObject -Wl,-U,_JSValueIsString -Wl,-U,_JSValueMakeString -Wl,-U,_JSValueToStringCopy
-Wl,-U,_JSContextGetGlobalObject -Wl,-U,_JSEvaluateScript -Wl,-U,_JSGlobalContextCreate -Wl,-U,_JSGlobalContextRelease -Wl,-U,_JSObjectCallAsFunction -Wl,-U,_JSObjectIsFunction -Wl,-U,_JSObjectMake -Wl,-U,_JSObjectSetProperty -Wl,-U,_JSStringCopyCFString -Wl,-U,_JSStringCreateWithCFString -Wl,-U,_JSStringRelease -Wl,-U,_JSValueIsObject -Wl,-U,_JSValueIsString -Wl,-U,_JSValueMakeString -Wl,-U,_JSValueToStringCopy
```

See my [JavaScriptCore framework availability on iOS](http://stackoverflow.com/questions/23514579/javascriptcore-framework-availability-on-ios/23514580#23514580) answer on Stack Overflow for a complete explanation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,8 @@
"-Wl,-U,_JSGlobalContextCreate",
"-Wl,-U,_JSGlobalContextRelease",
"-Wl,-U,_JSObjectCallAsFunction",
"-Wl,-U,_JSObjectGetPrototype",
"-Wl,-U,_JSObjectIsFunction",
"-Wl,-U,_JSObjectMake",
"-Wl,-U,_JSObjectSetProperty",
"-Wl,-U,_JSStringCopyCFString",
"-Wl,-U,_JSStringCreateWithCFString",
Expand Down Expand Up @@ -538,8 +538,8 @@
"-Wl,-U,_JSGlobalContextCreate",
"-Wl,-U,_JSGlobalContextRelease",
"-Wl,-U,_JSObjectCallAsFunction",
"-Wl,-U,_JSObjectGetPrototype",
"-Wl,-U,_JSObjectIsFunction",
"-Wl,-U,_JSObjectMake",
"-Wl,-U,_JSObjectSetProperty",
"-Wl,-U,_JSStringCopyCFString",
"-Wl,-U,_JSStringCreateWithCFString",
Expand Down
2 changes: 1 addition & 1 deletion XCDYouTubeKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Pod::Spec.new do |s|
s.public_header_files = "XCDYouTubeKit/XCDYouTube{Client,Error,Kit,Operation,Video,VideoOperation,VideoPlayerViewController}.h"
s.osx.exclude_files = "XCDYouTubeKit/XCDYouTubeVideoPlayerViewController.{h,m}"
s.ios.frameworks = "MediaPlayer"
s.ios.xcconfig = { "OTHER_LDFLAGS" => "-Wl,-U,_JSContextGetGlobalObject -Wl,-U,_JSEvaluateScript -Wl,-U,_JSGlobalContextCreate -Wl,-U,_JSGlobalContextRelease -Wl,-U,_JSObjectCallAsFunction -Wl,-U,_JSObjectGetPrototype -Wl,-U,_JSObjectIsFunction -Wl,-U,_JSObjectSetProperty -Wl,-U,_JSStringCopyCFString -Wl,-U,_JSStringCreateWithCFString -Wl,-U,_JSStringRelease -Wl,-U,_JSValueIsObject -Wl,-U,_JSValueIsString -Wl,-U,_JSValueMakeString -Wl,-U,_JSValueToStringCopy" }
s.ios.xcconfig = { "OTHER_LDFLAGS" => "-Wl,-U,_JSContextGetGlobalObject -Wl,-U,_JSEvaluateScript -Wl,-U,_JSGlobalContextCreate -Wl,-U,_JSGlobalContextRelease -Wl,-U,_JSObjectCallAsFunction -Wl,-U,_JSObjectIsFunction -Wl,-U,_JSObjectMake -Wl,-U,_JSObjectSetProperty -Wl,-U,_JSStringCopyCFString -Wl,-U,_JSStringCreateWithCFString -Wl,-U,_JSStringRelease -Wl,-U,_JSValueIsObject -Wl,-U,_JSValueIsString -Wl,-U,_JSValueMakeString -Wl,-U,_JSValueToStringCopy" }
s.osx.frameworks = "JavaScriptCore"
s.requires_arc = true
end
17 changes: 11 additions & 6 deletions XCDYouTubeKit/XCDYouTubePlayerScript.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@ - (instancetype) initWithString:(NSString *)string

_context = JSGlobalContextCreate(NULL);

for (NSString *propertyName in @[ @"window", @"document", @"navigator" ])
for (NSString *propertyPath in @[ @"window.navigator", @"document", @"navigator" ])
{
JSObjectRef globalObject = JSContextGetGlobalObject(_context);
JSStringRef propertyNameRef = JSStringCreateWithCFString((__bridge CFStringRef)propertyName);
JSValueRef dummyValueRef = JSObjectGetPrototype(_context, globalObject);
JSObjectSetProperty(_context, globalObject, propertyNameRef, dummyValueRef, 0, NULL);
JSStringRelease(propertyNameRef);
JSObjectRef object = JSContextGetGlobalObject(_context);
for (NSString *propertyName in [propertyPath componentsSeparatedByString:@"."])
{
JSStringRef propertyNameRef = JSStringCreateWithCFString((__bridge CFStringRef)propertyName);
JSObjectRef defaultObject = JSObjectMake(_context, NULL, NULL);
JSObjectSetProperty(_context, object, propertyNameRef, defaultObject, 0, NULL);
JSStringRelease(propertyNameRef);

object = defaultObject;
}
}

JSStringRef scriptRef = JSStringCreateWithCFString((__bridge CFStringRef)script);
Expand Down

0 comments on commit 065e8ea

Please sign in to comment.