Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View NghiaTranUIT's full-sized avatar
💭
Workaholic 👨‍💻

Noah Tran NghiaTranUIT

💭
Workaholic 👨‍💻
View GitHub Profile
@NghiaTranUIT
NghiaTranUIT / iosCertTrustManager.py
Created December 12, 2019 04:37
iosCertTrustManager.py
#! /usr/bin/env python
# Script to manage additional trusted root certificate in the IOS simulator
#
# Allows to add/list/delete/export trusted root certificates to the IOS simulator
# TrustStore.sqlite3 file.
#
# Additionally, root certificates added to a device can be listed and exported from
# a device backup
#
@NghiaTranUIT
NghiaTranUIT / JavaScriptCore+fetch.swift
Created October 22, 2020 01:55 — forked from yycking/JavaScriptCore+fetch.swift
add fetch, console.log and Promise.then/catch to JavaScriptCore on iOS/Mac
import JavaScriptCore
extension JSContext {
subscript(key: String) -> Any {
get {
return self.objectForKeyedSubscript(key)
}
set{
self.setObject(newValue, forKeyedSubscript: key as NSCopying & NSObjectProtocol)
}
secret = "xxx"
data = "http://someurl?someparams"
hmac = OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), secret.encode("ASCII"), data.encode("ASCII"))
signature = Base64.encode64(hmac).chomp
@NghiaTranUIT
NghiaTranUIT / proxyman_iOS_playground.swift
Created January 31, 2020 02:28
A workaround to enable SSL Proxying on iOS Swift Playground for Charles and Proxyman app. (swift 5)
// This workaround is only for iOS Swift Playground
// Don't need it on macOS Playground
import Foundation
// Accept all challenges from Charles or Proxyman for self-signed certificates
class NetworkSSlProxying: NSObject, URLSessionDelegate {
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
completionHandler(.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
}
}

The correct way, install homebrew on apple m1.

# We'll be installing Homebrew in the /opt directory.
cd /opt

# Create a directory for Homebrew. This requires root permissions.
sudo mkdir homebrew

# Make us the owner of the directory so that we no longer require root permissions.
sudo chown -R $(whoami) /opt/homebrew
private func newPacketTunnelSettings(proxyHost: String, proxyPort: Int) -> NEPacketTunnelNetworkSettings {
let settings = NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "127.0.0.1")
/* proxy settings */
let proxySettings = NEProxySettings()
proxySettings.httpServer = NEProxyServer(
address: proxyHost,
port: proxyPort
)
proxySettings.httpsServer = NEProxyServer(
internal let DEFAULT_MIME_TYPE = "application/octet-stream"
internal let mimeTypes = [
"html": "text/html",
"htm": "text/html",
"shtml": "text/html",
"css": "text/css",
"xml": "text/xml",
"gif": "image/gif",
"jpeg": "image/jpeg",
@NghiaTranUIT
NghiaTranUIT / viewcontroller.swift
Created December 7, 2020 12:56
NSTextFiels check isFocus
import AppKit
// Credit: Vadim Shpakovski from AppKitAbusers
class ViewController: NSViewController {
let textField1: CustomTextField = .init(string: "Field 1")
let textField2: CustomTextField = .init(string: "Field 2")
var observation1: NSKeyValueObservation?
@NghiaTranUIT
NghiaTranUIT / script.js
Created October 23, 2020 06:03
Combine Map Local and Breakpoint with Scripting feature - Proxyman (https://proxyman.io)
// /Users/nghiatran/Library/Application Support/com.proxyman.NSProxy/users/D6B9C80C.default_message_683CE65F.json
const file = require("@users/D6B9C80C.default_message_683CE65F.json");
function onRequest(context, url, request) {
// Done
return request;
}
function onResponse(context, url, request, response) {
@NghiaTranUIT
NghiaTranUIT / sslconnect.c
Created May 13, 2020 16:35 — forked from endSly/sslconnect.c
Example code for building a SSL connection and retrieving the server certificate
/* ------------------------------------------------------------ *
* file: sslconnect.c *
* purpose: Example code for building a SSL connection and *
* retrieving the server certificate *
* author: 06/12/2012 Frank4DD *
* *
* gcc -lssl -lcrypto -o sslconnect sslconnect.c *
* ------------------------------------------------------------ */
#include <sys/socket.h>