Skip to content

Instantly share code, notes, and snippets.

@jstaursky
jstaursky / getline.c
Last active July 12, 2022 20:33
crossplatform getline c function.
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <stddef.h>
typedef ptrdiff_t ssize_t;
/*******************************************************************************
* getline -- Stores line of text from stream. *
* *
* Parameters *
@jstaursky
jstaursky / fgetline.c
Last active January 12, 2019 03:15
retrieve arbitrary length strings from a given FILE stream
#include <stdlib.h>
char*
fgetLine(FILE *stream)
{
const size_t chunk = 128;
size_t max = chunk;
/* Preliminary check */
if (!stream || feof(stream))
#include <stdio.h>
int main(int argc, char *argv[])
{
char* Array[2][2] = { { "0th Row, 0th Col", "0th Row, 1st Col"},
{ "1st Row, 0th Col", "1st Row, 1st Col"}};
puts (Array[0][0]);
puts (Array[0][1]);
#include <stdio.h>
#include <stdlib.h> // void exit( int exit_code)
#include <signal.h> // void (*signal( int sig, void (*handler) (int))) (int)
// handler must be of the form "void func (int sig)"
// signal_code is useful in-cases where handler is used for more than one signal
void handler (int signal_code)
{
printf ("\nHello World!\n");
printf ("signal value: %d\n", signal_code);
#include <stdio.h>
struct fn_struct {
int number;
void (*f) (void *);
};
void foo (unsigned int m)
{
unsigned int tmp = 0;
#include <stdio.h>
#include <stdint.h> // for fixed width types e.g. uint8_t, etc.
#include <inttypes.h> // for PRI{fmt}{type} and SCN{fmt}{type} macros
int main()
{
uint32_t num;
scanf("%"SCNu32, &num);
#!/usr/bin/env perl
use warnings;
while (read STDIN, my $octets, 3) {
# converts the 3 octal numbers to equivalent decimal number and then said
# decimal number into its hex equivalent.
$hex_fmt = sprintf "%02x", oct($octets);
# print out hex in raw hex byte values.
print pack("H*", $hex_fmt);
}
// PrintUnicode.c - input ascii utf8 hex value and prints the corresponding unicode
// character.
// example - try the following!
// echo -n '0xf09f9886' | xargs ./PrintUnicode
// Or
// ./PrintUnicode f09f9886
#include <stdio.h> // sscanf, printf
#include <stdint.h> // uint32_t, uint8_t
// gcc --static -m32 -fno-stack-protector bufExploits1.c -g -o ex1
// If using gcc on windows, gcc -static-libgcc -bufExploits1.c -m32 -fno-stack-protector -g -o ex1
/*
* NOTE: Windows 10 will trigger windows defender and quarantine the exe before you can run it.
* I kept getting the threat warning for "Trojan:win32/Conteban.B!ml" -- not sure why, guess windows doesn't like stack smashing.
* You will need to first restore the exe from windows defender to let windows know this behavior is okay for this program.
*/
#ifdef _WIN32
#include <windows.h>
#endif
@jstaursky
jstaursky / printBinary.c
Last active September 9, 2019 22:52
Have fun manipulating data on the binary level!
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <inttypes.h>
// gcc Print_data_in_binary.c -o printBinary
//
// ./printBinary 27