From 557bf9c01fd78848167c1db8327aed259c5b3690 Mon Sep 17 00:00:00 2001 From: stderr64 Date: Tue, 28 Oct 2025 18:11:09 +0200 Subject: Added some stuff --- all_unicode_chars/unichars | Bin 0 -> 16576 bytes cpp_unicode_test/stdstring_unicode.cpp | 33 +++++++++++++++ cpp_unicode_test/unicodechars.txt | 1 + cpp_unicode_test/writemisc.pl | 25 +++++++++++ kvrocks_filler/filler.pl | 75 +++++++++++++++++++++++++++++++++ php_kvrocks/kvrocks.php | 31 ++++++++++++++ php_kvrocks/kvrocks2.php | 10 +++++ python_cdll_multithread/Makefile | 8 ++++ python_cdll_multithread/cdll.py | 49 +++++++++++++++++++++ python_cdll_multithread/libpcdlltest.c | 54 ++++++++++++++++++++++++ 10 files changed, 286 insertions(+) create mode 100755 all_unicode_chars/unichars create mode 100644 cpp_unicode_test/stdstring_unicode.cpp create mode 100644 cpp_unicode_test/unicodechars.txt create mode 100755 cpp_unicode_test/writemisc.pl create mode 100755 kvrocks_filler/filler.pl create mode 100644 php_kvrocks/kvrocks.php create mode 100644 php_kvrocks/kvrocks2.php create mode 100644 python_cdll_multithread/Makefile create mode 100755 python_cdll_multithread/cdll.py create mode 100644 python_cdll_multithread/libpcdlltest.c diff --git a/all_unicode_chars/unichars b/all_unicode_chars/unichars new file mode 100755 index 0000000..4fc91c2 Binary files /dev/null and b/all_unicode_chars/unichars differ diff --git a/cpp_unicode_test/stdstring_unicode.cpp b/cpp_unicode_test/stdstring_unicode.cpp new file mode 100644 index 0000000..d60679c --- /dev/null +++ b/cpp_unicode_test/stdstring_unicode.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include + +int main( int argc, char *args[] ){ + unsigned char *fcontents = NULL; + std::fstream *charfile = new std::fstream( reinterpret_cast("./unicodechars.txt"), std::ios::in ); + if ( charfile->fail() ){ + std::cerr << "Failed to open file\n"; + exit( EXIT_FAILURE ); + } + charfile->seekg( 0, std::ios::end ); + ssize_t fsize = static_cast(charfile->tellg()); + charfile->seekg( 0, std::ios::beg ); + fcontents = static_cast(calloc(fsize, sizeof(unsigned char))); + if ( fcontents == NULL ){ + std::cerr << "calloc failed\n"; + exit( EXIT_FAILURE ); + } + charfile->read( reinterpret_cast(fcontents), fsize ); + charfile->close(); + delete charfile; + fsize = 0; + std::string *uchars = new std::string( "" ); + uchars->assign( reinterpret_cast(fcontents) ); + free( fcontents ); + std::cout << uchars->c_str() << "\n"; + delete uchars; + exit( EXIT_SUCCESS ); +} diff --git a/cpp_unicode_test/unicodechars.txt b/cpp_unicode_test/unicodechars.txt new file mode 100644 index 0000000..1012c1d --- /dev/null +++ b/cpp_unicode_test/unicodechars.txt @@ -0,0 +1 @@ +☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓☔☕☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☰☱☲☳☴☵☶☷☸☹☺☻☼☽☾☿♀♁♂♃♄♅♆♇♈♉♊♋♌♍♎♏♐♑♒♓♔♕♖♗♘♙♚♛♜♝♞♟♠♡♢♣♤♥♦♧♨♩♪♫♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚇⚈⚉⚊⚋⚌⚍⚎⚏⚐⚑⚒⚓⚔⚕⚖⚗⚘⚙⚚⚛⚜⚝⚞⚟⚠⚡⚢⚣⚤⚥⚦⚧⚨⚩⚪⚫⚬⚭⚮⚯⚰⚱⚲⚳⚴⚵⚶⚷⚸⚹⚺⚻⚼⚽⚾⚿⛀⛁⛂⛃⛄⛅⛆⛇⛈⛉⛊⛋⛌⛍⛎⛏⛐⛑⛒⛓⛔⛕⛖⛗⛘⛙⛚⛛⛜⛝⛞⛟⛠⛡⛢⛣⛤⛥⛦⛧⛨⛩⛪⛫⛬⛭⛮⛯⛰⛱⛲⛳⛴⛵⛶⛷⛸⛹⛺⛻⛼⛽⛾ diff --git a/cpp_unicode_test/writemisc.pl b/cpp_unicode_test/writemisc.pl new file mode 100755 index 0000000..43ba4ec --- /dev/null +++ b/cpp_unicode_test/writemisc.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl +use IO::File; + +my $charcode = 0x2600; + +my $out_string = ""; + +for ( ; $charcode < 0x26FF; $charcode++ ){ + $out_string .= chr( $charcode ); +} + +$out_string .= "\n"; + +undef $charcode; + +open( my $ofile, ">:encoding(UTF-8)", "unicodechars.txt" ) or die "Failed to open file for writing";; + +print( $ofile $out_string ); + +undef $ofile; +undef $out_string; + +print( "Finished writing to file\n" ); + +exit( 0 ); diff --git a/kvrocks_filler/filler.pl b/kvrocks_filler/filler.pl new file mode 100755 index 0000000..2efdc23 --- /dev/null +++ b/kvrocks_filler/filler.pl @@ -0,0 +1,75 @@ +#!/usr/bin/perl +use IO::Socket; + +print( "Connecting..\n" ); + +my $sck = IO::Socket->new( + "PeerHost" => "127.0.0.1", + "PeerPort" => 6000, + "Blocking" => 1, + "Proto" => "tcp", + "Domain" => IO::Socket::AF_INET, + "Type" => IO::Socket::SOCK_STREAM +) or die "Failed to create socket"; + +print( "Connected\n" ); + +my @chars = split( / /, "q w e r t y i o p a s d f g h j k l z x c v b n m" ); +my $jlen = scalar( @chars ); + +srand(); + +my $junk = ""; + +sub gen_junk{ + $junk = ""; + for ( my $jc = 0; $jc < 100; $jc++ ){ + $junk .= $chars[rand($jlen)]; + } + return $junk; +} + +my $kname = ""; + +sub gen_key_name{ + $kname = ""; + for ( my $kchars = 0; $kchars < 20; $kchars++ ){ + $kname .= $chars[rand($jlen)]; + } + return $kname; +} + +sub kv_add{ + print( "Command:\n*3\r\n\$3\r\nset\r\n\$".length($_[0])."\r\n".$_[0]."\r\n\$".length($_[1])."\r\n".$_[1]."\r\n" ); + $sck->send( "*3\r\n\$3\r\nset\r\n\$".length($_[0])."\r\n".$_[0]."\r\n\$".length($_[1])."\r\n".$_[1]."\r\n" ) or die "Failed to add key"; +} + +sub start_multi{ + $sck->send( "MULTI\r\n" ) or die "Failed to start multi"; + return; +} + +sub end_multi{ + $sck->send( "EXEC\r\n" ); + return; +} + +print( "Adding keys\n" ); + +start_multi(); + +for ( my $gc = 0; $gc < 2000000; $gc++ ){ + print( "Adding key number ".$gc."\n" ); + kv_add( gen_key_name(), gen_junk() ); +} + +end_multi(); + +print( "Finished adding keys\n" ); + +$sck->shutdown( SHUT_RDWR ); + +undef $chars; +undef $jlen; +undef $sck; +exit( 0 ); diff --git a/php_kvrocks/kvrocks.php b/php_kvrocks/kvrocks.php new file mode 100644 index 0000000..d40a773 --- /dev/null +++ b/php_kvrocks/kvrocks.php @@ -0,0 +1,31 @@ +'; +if ( socket_recv($sck, $recv_data, $avb, MSG_WAITALL) === false ){ + socket_close( $sck ); + die( 'Failed to recv data' ); +} +socket_shutdown( $sck ); +socket_close( $sck ); +$ddata = json_decode( explode("\r\n", $recv_data)[1], true ); +var_dump( $ddata ); +echo '
Cookies: '.strval($ddata['cookies']).'
group: '.$ddata['group'].'
'; +unset( $ddata ); +unset( $recv_dec ); +unset( $recv_data ); +exit( 0 ); +?> diff --git a/php_kvrocks/kvrocks2.php b/php_kvrocks/kvrocks2.php new file mode 100644 index 0000000..0d821cd --- /dev/null +++ b/php_kvrocks/kvrocks2.php @@ -0,0 +1,10 @@ + diff --git a/python_cdll_multithread/Makefile b/python_cdll_multithread/Makefile new file mode 100644 index 0000000..45040bf --- /dev/null +++ b/python_cdll_multithread/Makefile @@ -0,0 +1,8 @@ +CC=gcc +CFLAGS=-O2 -march=x86-64-v3 -fPIC -shared + +rel: + $(CC) ${CFLAGS} ./libpcdlltest.c -o libpcdlltest.so -lpthread + +clean: + rm ./libpcdlltest.so diff --git a/python_cdll_multithread/cdll.py b/python_cdll_multithread/cdll.py new file mode 100755 index 0000000..eb76d35 --- /dev/null +++ b/python_cdll_multithread/cdll.py @@ -0,0 +1,49 @@ +#!/usr/bin/python3 -u +import sys; +import time; +from ctypes import *; + +testlib = CDLL( "./libpcdlltest.so" ); + +print( testlib ); + +testlib.testfunc.restype = c_void_p; +testlib.testfunc2.restype = c_void_p; +testlib.testfunc3.restype = c_char_p; +testlib.cleanup_buffer.restype = c_void_p; + +print( "Executing first test function (simple message from C code)" ); + +testlib.testfunc(); + +print( "Executing test function 2 (pass python value to it)" ); + +pvar = create_string_buffer( bytes("test message", "utf8") ); +testlib.testfunc2( pvar ); +del pvar; + +print( "Executing test function 3 (return value from C code)" ); + +test_value = testlib.testfunc3().decode("utf8"); +print( f"Returned value: {test_value}" ); +del test_value; + +print( "Executing buffer cleanup functiion" ); + +testlib.cleanup_buffer(); + +print( "Starting C thread" ); + +testlib.threadstarter(); + +print( "Printing garbage from python code" ); + +for pcount in range(0, 40): + print( f"Count is now in python {pcount}" ); + time.sleep( 1 ); + +print( "All tests done" ); + +del testlib; + +sys.exit( 0 ); diff --git a/python_cdll_multithread/libpcdlltest.c b/python_cdll_multithread/libpcdlltest.c new file mode 100644 index 0000000..6bc10ea --- /dev/null +++ b/python_cdll_multithread/libpcdlltest.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +char *t3_buffer = NULL; + +__attribute__((visibility("default"))) extern void *testfunc(){ + fputs( "Yes, it worked, testfunc executed\n", stdout ); + return NULL; +} + +__attribute__((visibility("default"))) extern void *testfunc2( char *testvalue ){ + fprintf( stdout, "Value passed from python: %s\n", (const char*)testvalue ); + return NULL; +} + +__attribute__((visibility("default"))) extern char *testfunc3(){ + t3_buffer = (char*)calloc( strlen("test") + 1, sizeof(char) ); + assert( t3_buffer != NULL ); + snprintf( t3_buffer, (strlen("test") * sizeof(char)) + 1, "test" ); + return t3_buffer; +} + +__attribute__((visibility("default"))) extern void *cleanup_buffer(){ + if ( t3_buffer == NULL ) + return NULL; + free( t3_buffer ); + t3_buffer = NULL; + fputs( "Buffer freed\n", stdout ); + return NULL; +} + +__attribute__((visibility("hidden"))) extern void *thread_func( void *uptr ){ + uint32_t loop_counter = 0; + for ( ; loop_counter < 30; loop_counter++ ){ + fprintf( stdout, "Loop counter is now %i\n", loop_counter ); + sleep( 1 ); + } + return NULL; +} + +__attribute__((visibility("default"))) extern void *threadstarter(){ + pthread_t tid = 0; + if ( pthread_create(&tid, NULL, &thread_func, NULL) == -1 ) + return NULL; + return NULL; +} -- cgit v1.2.3-94-g38b9