Skip to content

Instantly share code, notes, and snippets.

View Scrappers-glitch's full-sized avatar
🤖
Electrostat Lab.

pavl_g Scrappers-glitch

🤖
Electrostat Lab.
View GitHub Profile
@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 / 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 / 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_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 / sqmat_add.c
Last active March 4, 2023 11:14
Example showing matrix addition in c
#include <stdio.h>
#include <stdlib.h>
int* mat_add(int*, int*, int);
int* mat_add(int* a, int* b, int enteries) {
// enteries * 4 = 2 * 4 = 8 bytes
int* summation = (int*) calloc(enteries, sizeof(int));
for (int row = 0; row < enteries; row++) {
for (int column = 0; column < enteries; column++) {
@Scrappers-glitch
Scrappers-glitch / credentials_buffer.c
Created March 7, 2023 22:31
Tests Multi-dimensional arrays and accessing memory chunks using pointers
#include <stdio.h>
int main(void*) {
/* create an array of strings (arrays of characters) */
/* This buffer is allocated in contigous memory chunks */
const char credentials[][255] = {"Andrew",
"ZirqfRopWpedsS0012#24"};
/* get an element from the 1st dimension */
const char* user_cred = credentials[0]; /* or use *(credentials + 0) */
@Scrappers-glitch
Scrappers-glitch / credentials_references.c
Created March 7, 2023 22:34
Tests multi-dimensional references using a pointer to an array of strings.
#include <stdio.h>
int main(void*) {
const char* user = "Andrew";
const char* passwd = "ZirqfRopWpedsS0012#24";
/* create a pointer to strings (notice, we are just creating references here) */
const char* credentials[] = {user,
passwd};
/* get an element from the 1st dimension */
@Scrappers-glitch
Scrappers-glitch / star_matrix.c
Last active March 7, 2023 23:58
Tests a clean way of printing star matrices
#include <stdio.h>
/** Header file */
typedef struct {
int rows;
int columns;
} StarMatrixMetadata;
void print_star_matrix(StarMatrixMetadata metadata);
@Scrappers-glitch
Scrappers-glitch / jlong_implement.c
Last active March 27, 2023 23:23
Test void* to jlong implicit type-conversion.
#include <stdio.h>
#include <stdlib.h>
/* define a non-system-specific pointer type that can hold an address of up-to 8-bytes */
typedef long long jlong;
jlong Java_util_getAddress() {
int* x = malloc(sizeof(int));
*x = 2312;
void* address = x;
import java.util.ArrayList;
class TestSuperCapture {
static class TestSuper {}
static class TestSub extends TestSuper {}
static class TestSub2 extends TestSub {}
static class TestSub3 extends TestSub2 {}
public static void main(String[] args) {