Skip to content

Instantly share code, notes, and snippets.

View 0xced's full-sized avatar

Cédric Luthi 0xced

View GitHub Profile
@0xced
0xced / FromHeader.cs
Last active November 1, 2023 06:20
[FromHeader] parameter binding and attribute for ASP.NET Web API + Swashbuckle integration
using System;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Metadata;
@0xced
0xced / pin256.sh
Created August 30, 2017 14:50
Extract certificate + public key + pin from a TLS server
#!/usr/bin/env bash -e
HOST=${1:-cloudflare.com}
FILENAME=${2:-${HOST%%.*}}
# For file naming, see https://support.ssl.com/Knowledgebase/Article/View/19/0/der-vs-crt-vs-cer-vs-pem-certificates-and-how-to-convert-them
# For HTTP Public Key Pinning (HPKP), see https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning
CERTIFICATE_PEM="${FILENAME}_certificate.ascii.crt"
CERTIFICATE_DER="${FILENAME}_certificate.crt"
PUBKEY_PEM="${FILENAME}_pubkey.ascii.key"
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
@0xced
0xced / NSProgressHandlers.m
Last active October 5, 2016 18:52
Demonstrates how NSProgress handlers being invoked on any queue (as documented) might be problematic
#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
{
@autoreleasepool
{
NSProgress *progress = [[NSProgress alloc] initWithParent:nil userInfo:nil];
progress.cancellationHandler = ^{
NSLog(@"cancel");
};
@0xced
0xced / Emoji-iOS-10.0-14A5322e.json
Created August 8, 2016 22:38
Emoji from iOS beta 4 (14A5322e)
{
"People" : [
{
"Symbol" : "😀",
"Name" : "GRINNING FACE"
},
{
"Symbol" : "😬",
"Name" : "GRIMACING FACE"
},
@0xced
0xced / NSURLSessionTaskTransactionMetrics.txt
Created June 20, 2016 23:34
NSURLSessionTaskTransactionMetrics start and end dates visualization reproduced from WWDC 2016 session 711
secureConnectionStart
│ secureConnectionEnd
domainLookupStart │ │ responseStart
│ │ │ │
│ connectStart │ ││ connectEnd │
fetchStart │ │ │ ││ │ responseEnd
│ │ ├──────────┼────────────────┴┤ │ │
│ │ │ TCP │ TLS │ │ │
├─────────┼─────────┼──────────┴─────────────────┼─────┬───────────┼──────┤
@0xced
0xced / ClientCertificate.m
Last active September 13, 2018 02:22
Test for NSURLAuthenticationMethodClientCertificate
#import <Foundation/Foundation.h>
@interface Delegate : NSObject <NSURLConnectionDelegate, NSURLSessionDataDelegate>
@end
@implementation Delegate
#pragma mark - NSURLConnectionDelegate
- (void) connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
@0xced
0xced / NSJSONSerializationError.m
Created January 22, 2016 16:23
Convoluted way to get [NSJSONSerialization dataWithJSONObject:options:error:] to return an error
// http://twitter.com/nicklockwood/status/690540488433274881
// @0xced hmm, you're right. So under what circumstances *does* it populate the error param? Why even have it at all?
// http://twitter.com/0xced/status/690543445404991488
// @nicklockwood Just disassembled again, seems it can errors if a string fails to convert to UTF8. @nst021 Idea how to produce such a string?
// http://twitter.com/mikeash/status/690564095322542081
// mikeash: @0xced @nicklockwood @nst021 Maybe try an NSString containing half of a surrogate pair.
#import <Foundation/Foundation.h>
@0xced
0xced / MPMoviePlayerViewController.m
Created July 22, 2015 10:33
Reverse engineered implementation of -[MPMoviePlayerViewController _moviePlayerViewController_playbackDidFinishNotification:]
@implementation MPMoviePlayerViewController
- (void) _moviePlayerViewController_playbackDidFinishNotification:(NSNotification *)notification
{
if (self.presentingViewController.presentedViewController == self)
{
UIViewController *presentingViewController = self.presentingViewController;
if (self->_internal->_wasDisplayedAnimated)
[presentingViewController dismissMoviePlayerViewControllerAnimated];
else
@0xced
0xced / UIClassSwapper.m
Last active November 1, 2023 01:41
Reverse engineered implementation of -[UIClassSwapper initWithCoder:]
@implementation UIClassSwapper
- (instancetype) initWithCoder:(UINibDecoder *)decoder
{
NSString *className = [decoder decodeObjectForKey:@"UIClassName"];
NSString *originalClassName = [decoder decodeObjectForKey:@"UIOriginalClassName"];
Class class = NSClassFromString(className);
Class originalClass = NSClassFromString(originalClassName);