Generates a fish.so that irssi is able to load.

Has a /rf function that does FiSH encryption, now with a fixed key.
This commit is contained in:
Pedro de Oliveira 2023-08-12 19:00:39 +01:00
parent e843c65e17
commit 4712cd27ae
Signed by: falso
GPG Key ID: 1E4F05ACDBB2C85C
8 changed files with 113 additions and 54 deletions

5
.gitignore vendored
View File

@ -1,5 +1,2 @@
/target
/.idea/ /.idea/
rfish.iml rfish.so
rfish.h
main

View File

@ -1,17 +1,17 @@
# Makefile # Makefile
RUST_LIB_DIR = target/debug/ RUST_LIB_NAME = rfish
RUST_LIB_NAME = rfish RUST_LIB_DIR = lib$(RUST_LIB_NAME)/target/release
.PHONY: all clean .PHONY: all clean
all: cargo_build main all: cargo_build main
cargo_build: cargo_build:
cargo build cd lib$(RUST_LIB_NAME) && cargo build --release
main: rfish.c main: rfish.c
gcc -o main rfish.c -L$(RUST_LIB_DIR) -Wl,-rpath=$(RUST_LIB_DIR) -l$(RUST_LIB_NAME) -ldl gcc -shared -fPIC -o rfish.so rfish.c $(RUST_LIB_DIR)/lib$(RUST_LIB_NAME).a -Ilib$(RUST_LIB_NAME) -I/usr/include/irssi -I/usr/include/irssi/src -I/usr/include/irssi/src/fe-common/core -I/usr/include/irssi/src/core -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -lglib-2.0
clean: clean:
rm -f main rm -f main

4
librfish/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
/target
/.idea/
rfish.iml
rfish.h

View File

View File

@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib] [lib]
crate-type = ["cdylib"] crate-type = ["staticlib"]
[dependencies] [dependencies]
openssl = "0.10.56" openssl = "0.10.56"

View File

@ -1,14 +1,14 @@
extern crate cbindgen; extern crate cbindgen;
use std::env; use std::env;
fn main() { fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
cbindgen::Builder::new() cbindgen::Builder::new()
.with_crate(crate_dir) .with_crate(crate_dir)
.with_language(cbindgen::Language::C) .with_language(cbindgen::Language::C)
.generate() .generate()
.expect("Unable to generate bindings") .expect("Unable to generate bindings")
.write_to_file("rfish.h"); .write_to_file("rfish.h");
} }

98
rfish.c
View File

@ -1,20 +1,78 @@
#include <stdio.h> #define MODULE_NAME "rfish"
#include "rfish.h"
#include <irssi-config.h>
int main() { #include <common.h>
const uint8_t key[] = "chaveULTRAgulosa"; #include <core/settings.h>
uintptr_t key_len = sizeof(key) - 1; #include <core/levels.h>
#include <core/signals.h>
const uint8_t input[] = "teste123"; #include <core/recode.h>
uintptr_t input_len = sizeof(input) - 1; #include <core/commands.h>
#include <irc/core/irc.h>
char *encrypted = encrypt_cbc(key, key_len, input, input_len); #include <irc/core/irc-servers.h>
if (encrypted) { #include <irc/core/irc-queries.h>
printf("Encrypted: %s\n", encrypted); #include <fe-common/core/printtext.h>
free(encrypted); #include <fe-common/core/keyboard.h>
} else {
printf("Encryption failed.\n"); #include <stdio.h>
} #include "rfish.h"
return 0; void cmd_crypt_action(const char *data, SERVER_REC *server, WI_ITEM_REC *item) {
} const char *target;
int target_type = SEND_TARGET_NICK;
if (data == NULL || (strlen(data) < 2))
goto action_error;
if (item != NULL)
target = window_item_get_target(item);
else
goto action_error;
target_type = server_ischannel(server, target) ?
SEND_TARGET_CHANNEL : SEND_TARGET_NICK;
const uint8_t key[] = "chaveULTRAgulosa";
uintptr_t key_len = sizeof(key) - 1;
uintptr_t input_len = strlen(data);
const uint8_t *input_buffer = (const uint8_t *)malloc(input_len);
if (!input_buffer) {
printtext(server, target, MSGLEVEL_CRAP, "Memory allocation failed!");
return;
}
memcpy((void *)input_buffer, (const void *)data, input_len);
char *encrypted = encrypt_cbc(key, key_len, input_buffer, input_len);
if (encrypted) {
signal_emit("server sendmsg", 4, server, target, encrypted);
signal_emit(target_type == SEND_TARGET_CHANNEL ?
"message own_public" :
"message own_private", 4, server, encrypted,
target, target);
free(encrypted);
} else {
printtext(server, target, MSGLEVEL_CRAP, "Encryption failed!");
}
free((void *)input_buffer);
return;
action_error:
printtext(server, item != NULL ? window_item_get_target(item) : NULL,
MSGLEVEL_CRAP, "\002rFiSH:\002 Usage: /rf <message>");
}
void rfish_init(void) {
command_bind("rf", NULL, (SIGNAL_FUNC) cmd_crypt_action);
module_register("rfish", "core");
}
void rfish_deinit(void) {
command_unbind("rf", (SIGNAL_FUNC) cmd_crypt_action);
}
#ifdef IRSSI_ABI_VERSION
void rfish_abicheck(int *version)
{
*version = IRSSI_ABI_VERSION;
}
#endif