Skip to content

Adding track player #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions yalu102.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
03BE3C491E40B5E20094AD21 /* tracks in Resources */ = {isa = PBXBuildFile; fileRef = 03BE3C481E40B5E20094AD21 /* tracks */; };
EA1A3B9D1E391C4F009CA025 /* patchfinder64.o in Frameworks */ = {isa = PBXBuildFile; fileRef = EA1A3B9C1E391C4F009CA025 /* patchfinder64.o */; };
EA1A3BA81E398E33009CA025 /* 0.reload.plist in Resources */ = {isa = PBXBuildFile; fileRef = EA1A3BA61E398E33009CA025 /* 0.reload.plist */; };
EA1A3BAD1E399006009CA025 /* reload in Resources */ = {isa = PBXBuildFile; fileRef = EA1A3BAC1E399006009CA025 /* reload */; };
Expand All @@ -28,6 +29,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
03BE3C481E40B5E20094AD21 /* tracks */ = {isa = PBXFileReference; lastKnownFileType = folder; path = tracks; sourceTree = "<group>"; };
EA1A3B9B1E38BBDB009CA025 /* patchfinder64.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = patchfinder64.h; sourceTree = "<group>"; };
EA1A3B9C1E391C4F009CA025 /* patchfinder64.o */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.objfile"; path = patchfinder64.o; sourceTree = "<group>"; };
EA1A3BA61E398E33009CA025 /* 0.reload.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = 0.reload.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -70,6 +72,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
03BE3C471E40B5DA0094AD21 /* tracks */ = {
isa = PBXGroup;
children = (
03BE3C481E40B5E20094AD21 /* tracks */,
);
name = tracks;
sourceTree = "<group>";
};
EA9900DA1E1E9F060056FEBD = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -113,6 +123,7 @@
EA9901181E21A2180056FEBD /* IOKit.tbd */,
EA9901151E21A1D90056FEBD /* devicesupport.h */,
EA9901161E21A1D90056FEBD /* devicesupport.m */,
03BE3C471E40B5DA0094AD21 /* tracks */,
EA9900E61E1E9F060056FEBD /* Supporting Files */,
);
path = yalu102;
Expand Down Expand Up @@ -185,6 +196,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
03BE3C491E40B5E20094AD21 /* tracks in Resources */,
EA99010A1E21A04C0056FEBD /* tar in Resources */,
EA99010C1E21A0520056FEBD /* launchctl in Resources */,
EA9901061E219FF10056FEBD /* bootstrap.tar in Resources */,
Expand Down
37 changes: 29 additions & 8 deletions yalu102/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_0" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
Expand All @@ -19,47 +19,68 @@
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dw0-9I-nv5">
<rect key="frame" x="165" y="305" width="44" height="58"/>
<rect key="frame" x="138" y="255" width="44" height="58"/>
<fontDescription key="fontDescription" type="system" pointSize="38"/>
<state key="normal" title="go"/>
<connections>
<action selector="yolo:" destination="BYZ-38-t0r" eventType="touchUpInside" id="OEX-ZS-X4Q"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="yalu by qwertyoruiopz &amp; marcograssi" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gOx-xh-mld">
<rect key="frame" x="46" y="30" width="283" height="21"/>
<rect key="frame" x="19" y="30" width="283" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="for all iOS 10 up to 10.2 pre-i7" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="SBH-un-0mh">
<rect key="frame" x="74.5" y="616" width="226" height="21"/>
<rect key="frame" x="47" y="517" width="226" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Track Playing:" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="e3U-ly-l7J">
<rect key="frame" x="107" y="442" width="107" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Av8-aK-g1d">
<rect key="frame" x="0.0" y="471" width="320" height="21"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="6gj-Jy-R7l"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="1" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="Av8-aK-g1d" firstAttribute="centerX" secondItem="SBH-un-0mh" secondAttribute="centerX" id="1ez-rC-klB"/>
<constraint firstItem="SBH-un-0mh" firstAttribute="top" secondItem="Av8-aK-g1d" secondAttribute="bottom" constant="25" id="BRe-WL-nic"/>
<constraint firstItem="Av8-aK-g1d" firstAttribute="top" secondItem="e3U-ly-l7J" secondAttribute="bottom" constant="8" symbolic="YES" id="HWW-Bu-dqI"/>
<constraint firstItem="gOx-xh-mld" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="topMargin" constant="30" id="Lak-A4-fwI"/>
<constraint firstItem="dw0-9I-nv5" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="VK2-I1-MuP"/>
<constraint firstItem="dw0-9I-nv5" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="Vix-Ed-EfU"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="SBH-un-0mh" secondAttribute="bottom" constant="30" id="WX7-VB-beg"/>
<constraint firstItem="Av8-aK-g1d" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="bpt-5A-t6b"/>
<constraint firstItem="Av8-aK-g1d" firstAttribute="centerX" secondItem="e3U-ly-l7J" secondAttribute="centerX" id="dJg-2j-24b"/>
<constraint firstItem="gOx-xh-mld" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="go3-GK-gg8"/>
<constraint firstItem="SBH-un-0mh" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="llZ-Oo-VUY"/>
</constraints>
</view>
<connections>
<outlet property="dope" destination="dw0-9I-nv5" id="h3W-Lb-cpp"/>
<outlet property="trackLabel" destination="Av8-aK-g1d" id="QzV-0X-FfV"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="152.80000000000001" y="154.27286356821591"/>
<point key="canvasLocation" x="151.875" y="154.22535211267606"/>
</scene>
</scenes>
</document>
12 changes: 12 additions & 0 deletions yalu102/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@
//

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <CommonCrypto/CommonDigest.h>

#include <stdlib.h>
#include <string.h>

@interface ViewController : UIViewController
{
IBOutlet UIButton* dope;
IBOutlet UILabel *trackLabel;

AVPlayer *audioPlayer;

NSMutableArray *tracks;
NSInteger trackIndex;
NSInteger maxTracks;
}
- (IBAction)yolo:(id)sender;

Expand Down
180 changes: 178 additions & 2 deletions yalu102/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#import <mach-o/loader.h>
#import <sys/mman.h>
#import <pthread.h>

#include <sys/stat.h>
#include <sys/mman.h>

#undef __IPHONE_OS_VERSION_MIN_REQUIRED
#import <mach/mach.h>
#include <sys/utsname.h>
Expand All @@ -24,24 +28,192 @@
char pad[4096];
} sprz;

typedef struct file_map {
void *map_data;
mach_vm_size_t map_size;
uint32_t unique_id;
} file_map_t;

file_map_t *map_file_with_path(const char *path, int mode)
{
if (!path) return NULL;
if (access(path, R_OK) == -1) return NULL;

int32_t fd = open(path, mode);
if (fd < 0) {
return NULL;
}

struct stat st;
if(fstat(fd, &st) != 0)
goto fail;

file_map_t *map = (file_map_t *)malloc(sizeof(file_map_t));
if((map->map_data = mmap(NULL, (uint32_t)st.st_size, PROT_READ|PROT_WRITE, (mode == O_RDONLY) ? MAP_PRIVATE : MAP_SHARED, fd, 0)) == MAP_FAILED)
goto fail;
map->map_size = (mach_vm_size_t)st.st_size;
map->unique_id = (uint32_t)(((uint64_t)map << 32) >> 32);

return map;

fail:
close(fd);

return NULL;
}

@interface ViewController ()

@end

@implementation ViewController

- (void)advanceTrack {
audioPlayer = [[AVPlayer alloc] initWithURL:[NSURL fileURLWithPath:tracks[trackIndex]]];

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

audioPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[audioPlayer currentItem]];

char *track_name_ext = strrchr([tracks[trackIndex] UTF8String], '/') + 1;
char *extension = strstr(track_name_ext, ".mp3");

char track_name[256] = {0};
strncpy((char *)&track_name, track_name_ext, (size_t)(extension - track_name_ext));

[trackLabel setText:[NSString stringWithUTF8String:track_name]];

[audioPlayer play];
}

- (void)playerItemDidReachEnd:(NSNotification *)notification
{
if (trackIndex >= maxTracks)
trackIndex = 0;
else
trackIndex++;

[audioPlayer release];

[self advanceTrack];
}

- (void)labelTap {
[self playerItemDidReachEnd:nil];
}

- (void)viewDidLoad {

[super viewDidLoad];

init_offsets();

struct utsname u = { 0 };
uname(&u);


if (strstr(u.version, "MarijuanARM")) {
[dope setEnabled:NO];
[dope setTitle:@"already jailbroken" forState:UIControlStateDisabled];
}


#if 1 /* track player */
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
NSString *tracksPath = [bundlePath stringByAppendingPathComponent:@"tracks"];

if (access([tracksPath UTF8String], R_OK) != -1) {
NSArray* dirs = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:tracksPath error:NULL];

tracks = [[NSMutableArray alloc] init];
[dirs enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSString *filename = (NSString *)obj;
NSString *extension = [[filename pathExtension] lowercaseString];
if ([extension isEqualToString:@"mp3"]) {
[tracks addObject:[tracksPath stringByAppendingPathComponent:filename]];
}
}];

if (![tracks count]) {
NSLog(@"[Warning]: The \'tracks\' directory is present, but no tracks inside.");
[trackLabel setText:@"~"];
} else {

/*
hash checksum for track files.

seems quick enough, but boring to add new tracks.
best way would be to ship tracks folder as a zip file,
checking sum for that, if it matches unzip it and go on.

since i don't want to add too much code to yalu, i went with
this instead.
*/

#define TRACK_COUNT 3
static const char *track_checksums[TRACK_COUNT] = {
"fbc04d4ca819535e3377ffca65c16ff2899bb17c", /* kjc 1 */
"2ed60a2638d5d6d224aecd7cded52d4e59fca86b", /* kjc 2 */
"9e13620ffbe5b33a23a64ffbb4846a4089604961" /* kjc 3 */
};

if ([tracks count] > TRACK_COUNT) {
NSLog(@"[Error]: Expected %d mp3 files, found %d. Aborting.", TRACK_COUNT, [tracks count]);
exit(1);
} else if ([tracks count] < TRACK_COUNT) {
NSLog(@"[Error]: Expected %d mp3 files, found %d. Aborting.", TRACK_COUNT, [tracks count]);
exit(1);
}


for (uint32_t i = 0; i < [tracks count]; i++) { /* we ignore non-mp3 files */
file_map_t *map = map_file_with_path([tracks[i] UTF8String], O_RDONLY);
if (map) {
uint8_t digest[CC_SHA1_DIGEST_LENGTH] = {0};
CC_SHA1(map->map_data, (size_t)map->map_size, digest);

NSMutableString *output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];
for (int k = 0; k < CC_SHA1_DIGEST_LENGTH; k++)
[output appendFormat:@"%02x", digest[k]];

for (uint32_t j = 0; j < TRACK_COUNT; j++)
if (strcmp([output UTF8String], track_checksums[j]) == 0)
goto ok;

NSLog(@"[Error]: Checksum %@ for file \'%s\' is invalid! Aborting.", output, (strrchr([tracks[i] UTF8String], '/') + 1));
exit(2);

ok:;
NSLog(@"Checksum %@ for file \'%s\' validated!", output, (strrchr([tracks[i] UTF8String], '/') + 1));

munmap(map->map_data, (vm_size_t)map->map_size);
free(map);
}
}

maxTracks = [tracks count] - 1;
trackIndex = arc4random_uniform(maxTracks + 1);

[self advanceTrack];

trackLabel.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap)];
[trackLabel addGestureRecognizer:tapGesture];
}
} else {
NSLog(@"[Warning]: No \'tracks\' folder present in bundle, so no tracks will play. If you want to play tracks, simply add a folder called \'tracks\' containing .mp3 files, inside your bundle.");

[trackLabel setText:@"~"];
}
#else
[trackLabel setText:@"~"];
#endif

// Do any additional setup after loading the view, typically from a nib.
}

Expand Down Expand Up @@ -384,4 +556,8 @@ - (void)didReceiveMemoryWarning {
}


- (void)dealloc {
[trackLabel release];
[super dealloc];
}
@end
Binary file not shown.
Binary file added yalu102/tracks/KJC - RIP JB Community Pt. 3.mp3
Binary file not shown.
Binary file added yalu102/tracks/KJC - RIP JB Community.mp3
Binary file not shown.