Skip to content

Instantly share code, notes, and snippets.

View Scrappers-glitch's full-sized avatar
🤖
Software~Hardware Co-Desgin

pavl_g Scrappers-glitch

🤖
Software~Hardware Co-Desgin
View GitHub Profile
@Scrappers-glitch
Scrappers-glitch / test_pointer_op.c
Last active February 25, 2023 06:55
Tests using pointer operations on a data structure to evaluate its members.
/**
* @brief Tests using pointer operations on a data structure to evaluate its members.
*
* @author pavl_g
*/
#include <stdio.h>
struct Test {
int x;
int y;
@Scrappers-glitch
Scrappers-glitch / TestInitializers.java
Last active February 24, 2023 12:06
Tests different type of initializers in jvm
/**
* Tests different type of initializers in jvm:
* 1) <clinit>: stands for class or the static initializer, called only once on the first reference of the class name.
* 2) <init>: is the class object initializer or the instance initializer called whenever creating a new object and it resembles the class constructor.
*
* @author pavl_g
*/
public class TestInitializers {
static class TestClassInitializer {
public static int len = 00;
@Scrappers-glitch
Scrappers-glitch / test_memory_corruption.c
Created February 22, 2023 01:13
Tests memory corruption due to partition memory overflow.
#include<stdio.h>
#include<stdlib.h>
typedef struct {
void* start_address;
void* end_address;
size_t offset;
size_t size;
size_t pointer_location;
@Scrappers-glitch
Scrappers-glitch / partition_scheme.c
Last active February 21, 2023 23:02
A simple example to a buffer partitioning scheme
#include<stdio.h>
#include<stdlib.h>
typedef struct {
void* start_address;
void* end_address;
size_t offset;
size_t size;
size_t pointer_location;
@Scrappers-glitch
Scrappers-glitch / chunk_cpy.c
Created February 18, 2023 18:15
Tests chunk memory copy in C
/**
* Test chunk memcpy
*
* @author pavl_g
*/
#include <stdio.h>
#include <string.h>
static inline void printAddresses(char* arr, int length) {
for (int i = 0; i < length; i++) {
@Scrappers-glitch
Scrappers-glitch / jni_headers_example_2.c
Last active February 15, 2023 20:52
An example showing how to assign a function table to a C struct in one go
#include <stdio.h>
#include <stdlib.h>
/** jni.h **********************************************************************************/
struct JNINativeInterface_ {
void *reserved0;
void *reserved1;
void *reserved2;
void *reserved3;
@Scrappers-glitch
Scrappers-glitch / private_definition_techdemo.c
Created February 14, 2023 22:33
An example shows a function definition inside another function demonstrating local scopes effect on function definition
#include <stdio.h>
static inline void call_stack() {
void inside_block() {
printf("inside block");
}
inside_block();
}
int main() {
@Scrappers-glitch
Scrappers-glitch / number_utils_max.c
Created February 13, 2023 15:52
Finds the maximum number among some numbers
#include <stdio.h>
/**
* Finds the maximum number between 2 numbers.
*
* @param n0 the first operand
* @param n1 the second operand
* @return the maximum number, any of the 2 numbers if the numbers are equal
*/
static inline int max0(int n0, int n1) {
@Scrappers-glitch
Scrappers-glitch / techdemo.c
Created January 30, 2023 18:49
Constant pointer to non-constant data
#include <stdio.h>
int main(void) {
int x = 8; // define x
int y; // define y
// constant location (pointer) to non-constant data
int* const ptr = &x;
// an attempt to modifiy the data will succeed
*ptr = 55;
printf("%d\n", x);
// an attempt to modify the memory location will fail
@Scrappers-glitch
Scrappers-glitch / techdemo.c
Created January 30, 2023 18:45
Constant pointer to constant data example
#include <stdio.h>
int main(void) {
int x = 8; // define x
int y; // define y
// constant pointer to constant data
const int* const ptr = &x;
printf("%d\n", x);
}