Skip to content

Commit

Permalink
4.9
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-tamago committed Dec 30, 2022
1 parent 992e851 commit 4fc2d4c
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 60 deletions.
8 changes: 2 additions & 6 deletions NoCameraSound/NoCameraSound.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
3D16394B295C4ABF006D31D8 /* vm_unaligned_copy_switch_race.c in Sources */ = {isa = PBXBuildFile; fileRef = 3D16394A295C4ABF006D31D8 /* vm_unaligned_copy_switch_race.c */; };
3D163953295C7029006D31D8 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3D163955295C7029006D31D8 /* Localizable.strings */; };
3D163959295C7810006D31D8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3D163958295C7810006D31D8 /* Assets.xcassets */; };
3D2342AB295D31BD00A6E40D /* plist in Resources */ = {isa = PBXBuildFile; fileRef = 3D2342AA295D31BD00A6E40D /* plist */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -29,7 +28,6 @@
3D16394A295C4ABF006D31D8 /* vm_unaligned_copy_switch_race.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = vm_unaligned_copy_switch_race.c; sourceTree = "<group>"; };
3D163954295C7029006D31D8 /* ja */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Localizable.strings; sourceTree = "<group>"; };
3D163958295C7810006D31D8 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
3D2342AA295D31BD00A6E40D /* plist */ = {isa = PBXFileReference; lastKnownFileType = folder; path = plist; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -71,7 +69,6 @@
3D163917295B520E006D31D8 /* NoCameraSound.swift */,
3D163919295B5227006D31D8 /* NoCameraSound-Bridging-Header.h */,
3D163958295C7810006D31D8 /* Assets.xcassets */,
3D2342AA295D31BD00A6E40D /* plist */,
3D16390D295B51DB006D31D8 /* Preview Content */,
);
path = NoCameraSound;
Expand Down Expand Up @@ -146,7 +143,6 @@
buildActionMask = 2147483647;
files = (
3D163953295C7029006D31D8 /* Localizable.strings in Resources */,
3D2342AB295D31BD00A6E40D /* plist in Resources */,
3D163959295C7810006D31D8 /* Assets.xcassets in Resources */,
3D16390F295B51DB006D31D8 /* Preview Assets.xcassets in Resources */,
);
Expand Down Expand Up @@ -318,7 +314,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 4.8;
MARKETING_VERSION = 4.9;
PRODUCT_BUNDLE_IDENTIFIER = "com.straight-tamago.NoCameraSound";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -353,7 +349,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 4.8;
MARKETING_VERSION = 4.9;
PRODUCT_BUNDLE_IDENTIFIER = "com.straight-tamago.NoCameraSound";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
Binary file not shown.
61 changes: 40 additions & 21 deletions NoCameraSound/NoCameraSound/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ import SwiftUI
struct ContentView: View {
private let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
@State private var LogMessage = ""
@State private var LogText = ""
@State var LogText = ""
@State private var ViewLog = true
@State private var SettingsShowing = false
@State private var ios14Warning = false
@State private var Notcompatiblewithios14 = false
var body: some View {
VStack {
if ViewLog {
Text("")
.frame(width: 300, height: 200)
.padding()
.padding(.top, 10)
.disabled(true)
}
Text("NoCameraSound").font(.largeTitle).fontWeight(.bold)
HStack {
//---------------------------------------------------------------------------
Button("Disable Shutter Sound") {
if #available(iOS 15.0, *) {
LogText = ""
Expand All @@ -45,7 +47,7 @@ struct ContentView: View {
secondaryButton: .default(Text("Cancel"))
)
}

//---------------------------------------------------------------------------
Button {
SettingsShowing = true
} label: {
Expand All @@ -68,10 +70,15 @@ struct ContentView: View {
}
},
.default(Text("\(NSLocalizedString("Auto run when the app starts (Status: ", comment: ""))"+String(UserDefaults.standard.bool(forKey: "AutoRun"))+")")) {
if UserDefaults.standard.bool(forKey: "AutoRun") == true {
UserDefaults.standard.set(false, forKey: "AutoRun")
}else {
UserDefaults.standard.set(true, forKey: "AutoRun")
if #available(iOS 15.0, *) {
if UserDefaults.standard.bool(forKey: "AutoRun") == true {
UserDefaults.standard.set(false, forKey: "AutoRun")
}else {
UserDefaults.standard.set(true, forKey: "AutoRun")
}
}
else {
Notcompatiblewithios14 = true
}
},
.default(Text("\(NSLocalizedString("View Log (Status: ", comment: ""))"+String(UserDefaults.standard.bool(forKey: "ViewLog"))+")")) {
Expand All @@ -81,24 +88,37 @@ struct ContentView: View {
}else {
UserDefaults.standard.set(true, forKey: "ViewLog")
ViewLog = true

}
},
.default(Text("\(NSLocalizedString("Camera silent + English notation (JP Only) (Status: ", comment: ""))"+String(UserDefaults.standard.bool(forKey: "Visibility"))+")")) {
if Locale.preferredLanguages.first! == "ja-JP" {
if UserDefaults.standard.bool(forKey: "Visibility") == true {
UserDefaults.standard.set(false, forKey: "Visibility")
}else {
UserDefaults.standard.set(true, forKey: "Visibility")
if #available(iOS 15.0, *) {
if Locale.preferredLanguages.first! == "ja-JP" {
if UserDefaults.standard.bool(forKey: "Visibility") == true {
UserDefaults.standard.set(false, forKey: "Visibility")
}else {
UserDefaults.standard.set(true, forKey: "Visibility")
}
}
}
else {
Notcompatiblewithios14 = true
}
},
.cancel()
])
}
.alert(isPresented: $Notcompatiblewithios14) {
Alert(title: Text("Not compatible with ios14"),
primaryButton: .destructive(Text("OK")),
secondaryButton: .default(Text("Cancel"))
)
}
//---------------------------------------------------------------------------
}
if ViewLog {
ScrollViewReader { reader in
Text(LogMessage)
.padding(.top, 10)
ScrollView {
Text(LogText)
.frame(maxWidth: .infinity, alignment: .leading)
Expand All @@ -112,15 +132,15 @@ struct ContentView: View {
}
.frame(width: 300, height: 200)
.border(Color.black, width: 1)
.padding()
.padding(.top, 10)
}
Text(LogMessage)
.padding()

}else {
Text(LogMessage)
.padding()
}
}.onAppear {
LogMessage = "v\(version)"
LogText = "NoCameraSound v\(version) by straight-tamago"+"\n"
if UserDefaults.standard.bool(forKey: "AutoRun") == true {
LogText = ""
Expand All @@ -134,8 +154,7 @@ struct ContentView: View {
}



// ---------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------
func disable_shuttersound() {
LogText += "NoCameraSound v\(version) by straight-tamago"+"\n"
LogText += "\nDisabling Shutter Sound..."
Expand Down Expand Up @@ -181,7 +200,7 @@ struct ContentView: View {
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
static var previews: some View {
ContentView()
}
}
62 changes: 29 additions & 33 deletions NoCameraSound/NoCameraSound/NoCameraSound.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,45 @@
import UIKit

func overwriteAsync(TargetFilePath: String, completion: @escaping (String) -> Void) {
DispatchQueue.global(qos: .userInteractive).async {
let succeeded = overwrite(TargetFilePath: TargetFilePath)
DispatchQueue.main.async {
let base = "0123456789"
let randomStr = String((0..<2).map{ _ in base.randomElement()! })
completion(succeeded ? "Success - "+randomStr : "Error")
DispatchQueue.global(qos: .userInteractive).async {
let succeeded = overwrite(TargetFilePath: TargetFilePath)
DispatchQueue.main.async {
let base = "0123456789"
let randomStr = String((0..<2).map{ _ in base.randomElement()! })
completion(succeeded ? "Success - "+randomStr : "Error")
}
}
}
}

func overwrite(TargetFilePath: String) -> Bool {
// let OverwriteFileData = "xxx".data(using: .utf8)!
guard let OverwriteFileURL = Bundle.main.url(forResource: "Info.plist", withExtension: nil, subdirectory: "plist") else {
fatalError("ファイルが見つからない")
}
let OverwriteFileData = try! Data(contentsOf: OverwriteFileURL)
let OverwriteFileData = "xxx".data(using: .utf8)!
let fd = open(TargetFilePath, O_RDONLY | O_CLOEXEC)
defer { close(fd) }
let Map = mmap(nil, OverwriteFileData.count, PROT_READ, MAP_SHARED, fd, 0)
if Map == MAP_FAILED {
return false
}
guard mlock(Map, OverwriteFileData.count) == 0 else {
return false
}
for chunkOff in stride(from: 0, to: OverwriteFileData.count, by: 0x4000) {
let dataChunk = OverwriteFileData[chunkOff..<min(OverwriteFileData.count, chunkOff + 0x3fff)]
var overwroteOne = false
for _ in 0..<2 {
let overwriteSucceeded = dataChunk.withUnsafeBytes { dataChunkBytes in
return unaligned_copy_switch_race(
fd, Int64(chunkOff), dataChunkBytes.baseAddress, dataChunkBytes.count)
}
if overwriteSucceeded {
overwroteOne = true
break
}
sleep(1)
guard mlock(Map, OverwriteFileData.count) == 0 else {
return false
}
guard overwroteOne else {
return false
for chunkOff in stride(from: 0, to: OverwriteFileData.count, by: 0x4000) {
let dataChunk = OverwriteFileData[chunkOff..<min(OverwriteFileData.count, chunkOff + 0x3fff)]
var overwroteOne = false
for _ in 0..<2 {
let overwriteSucceeded = dataChunk.withUnsafeBytes { dataChunkBytes in
return unaligned_copy_switch_race(
fd, Int64(chunkOff), dataChunkBytes.baseAddress, dataChunkBytes.count)
}
if overwriteSucceeded {
overwroteOne = true
break
}
sleep(1)
}
guard overwroteOne else {
return false
}
}
}
print("Success")
return true
print("Success")
return true
}
1 change: 1 addition & 0 deletions NoCameraSound/NoCameraSound/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
"Auto run when the app starts (Status: " = "アプリ起動時に無音化自動実行 (状態: ";
"Camera silent + English notation (JP Only) (Status: " = "書き換えに成功したからカメラを英語表記にする (状態: ";
"View Log (Status: " = "ログを表示 (状態: ";
"Not compatible with ios14" = "この機能はiOS14非対応";
Binary file removed NoCameraSound/NoCameraSound/plist/Info.plist
Binary file not shown.

0 comments on commit 4fc2d4c

Please sign in to comment.