Skip to content

Instantly share code, notes, and snippets.

View Silva97's full-sized avatar
🤔
Thinking, of course.

Luiz Felipe Silva Silva97

🤔
Thinking, of course.
View GitHub Profile
@Silva97
Silva97 / pipe.py
Created March 28, 2023 13:59
Class to create a wrapper to pipe function calls.
import inspect
class Pipe:
"""
Create a wrapper to pipe function calls with the given value.
The functions could be: value's method, builtin or any
function in the current module.
Examples:
@Silva97
Silva97 / sigreturn-frame.py
Created March 15, 2023 21:36
Class to make sigreturn frame to exploit SROP
# By Luiz Felipe Silva (https://github.com/Silva97)
## References ##
# sys_rt_sigreturn: https://elixir.bootlin.com/linux/latest/source/arch/x86/um/signal.c#L560
# sigframe: https://elixir.bootlin.com/linux/latest/source/arch/x86/include/asm/sigframe.h
# ucontext: https://elixir.bootlin.com/linux/latest/source/include/uapi/asm-generic/ucontext.h
# sigcontext: https://elixir.bootlin.com/linux/latest/source/arch/x86/include/uapi/asm/sigcontext.h#L324
import struct
@Silva97
Silva97 / target-example.c
Created November 2, 2021 11:28
Conditional function by target O.S. or architecture
#include <stdio.h>
#include "target.h"
OS_LINUX(char *os, void)
{
return "Linux";
}
OS_WINDOWS(char *os, void)
{
@Silva97
Silva97 / error_handling.c
Created October 21, 2021 20:40
PoC macros to do error handling in C
#include <stdio.h>
#include <string.h>
#define CATCH(name) \
if (0) \
_catch_##name:
#define FAIL(name) goto _catch_##name
#define FAIL_IF(expr, name) \
@Silva97
Silva97 / lexer-example.c
Last active June 23, 2022 12:56
Example of lexical analysis in C language.
/**
* Example by Luiz Felipe (Silva97)
*
* It's just an example. Don't consider it a final code and DON'T write
* all your code on a unique module, please.
*
* Tip: Use a struct to manipulate translate units instead of use only a
* FILE pointer ;)
*/
@Silva97
Silva97 / demo.c
Created August 19, 2021 16:35
C macro for print struct's fields
#include <stdio.h>
#include "printstruct.h"
typedef struct
{
int a;
char *b;
char c;
long int d;
long long int e;
@Silva97
Silva97 / get-function-size.c
Created July 11, 2021 15:45
Just an example of how to get the size of a function in bytes using the GCC compiler
// See how it's works using: gcc -S get-function-size.c -o get-function-size.s
// To manually check function size: objdump -d get-function-size
#include <stdio.h>
#define DECLARE_FUNCSIZE(funcname) \
extern unsigned int funcname##_funcsize; \
asm(#funcname "_funcsize: .long . - " #funcname "\n\t")
#define FUNCSIZE(funcname) \
funcname##_funcsize
#define _GNU_SOURCE
#include <dlfcn.h>
typedef int (*puts_t)(const char *);
int puts(const char *string)
{
puts_t original_puts = dlsym(RTLD_NEXT, "puts");
original_puts("-- Hookado --");
@Silva97
Silva97 / box.c
Created March 6, 2021 00:30
Just an exercise example.
// Just an exercise example.
#include <stdio.h>
#include <stdlib.h>
void crep(int character, unsigned int number);
int main(int argc, char **argv)
{
if (argc < 2)
{
#include <stdio.h>
int main(void)
{
int x = 5;
float y = 5.0f;
int *x_ptr = &x;
int *y_ptr = (int *)&y;