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:
parent
e843c65e17
commit
4712cd27ae
|
@ -1,5 +1,2 @@
|
|||
/target
|
||||
/.idea/
|
||||
rfish.iml
|
||||
rfish.h
|
||||
main
|
||||
rfish.so
|
||||
|
|
6
Makefile
6
Makefile
|
@ -1,17 +1,17 @@
|
|||
# Makefile
|
||||
|
||||
RUST_LIB_DIR = target/debug/
|
||||
RUST_LIB_NAME = rfish
|
||||
RUST_LIB_DIR = lib$(RUST_LIB_NAME)/target/release
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: cargo_build main
|
||||
|
||||
cargo_build:
|
||||
cargo build
|
||||
cd lib$(RUST_LIB_NAME) && cargo build --release
|
||||
|
||||
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:
|
||||
rm -f main
|
|
@ -0,0 +1,4 @@
|
|||
/target
|
||||
/.idea/
|
||||
rfish.iml
|
||||
rfish.h
|
|
@ -6,7 +6,7 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
openssl = "0.10.56"
|
72
rfish.c
72
rfish.c
|
@ -1,20 +1,78 @@
|
|||
#define MODULE_NAME "rfish"
|
||||
|
||||
#include <irssi-config.h>
|
||||
#include <common.h>
|
||||
#include <core/settings.h>
|
||||
#include <core/levels.h>
|
||||
#include <core/signals.h>
|
||||
#include <core/recode.h>
|
||||
#include <core/commands.h>
|
||||
#include <irc/core/irc.h>
|
||||
#include <irc/core/irc-servers.h>
|
||||
#include <irc/core/irc-queries.h>
|
||||
#include <fe-common/core/printtext.h>
|
||||
#include <fe-common/core/keyboard.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include "rfish.h"
|
||||
|
||||
int main() {
|
||||
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;
|
||||
|
||||
const uint8_t input[] = "teste123";
|
||||
uintptr_t input_len = sizeof(input) - 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, input_len);
|
||||
char *encrypted = encrypt_cbc(key, key_len, input_buffer, input_len);
|
||||
if (encrypted) {
|
||||
printf("Encrypted: %s\n", 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 {
|
||||
printf("Encryption failed.\n");
|
||||
printtext(server, target, MSGLEVEL_CRAP, "Encryption failed!");
|
||||
}
|
||||
free((void *)input_buffer);
|
||||
return;
|
||||
|
||||
return 0;
|
||||
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
|
Loading…
Reference in New Issue