<commit_before>/*
 * Change memory of another process 4 bytes at a time :)
 * 
 * Usage: ./poker <PID> <hex_address[:hexpair_value[:hexpair_value_original]]>
 * 
 * Example:
 * ./poker 247 0x00400658 - reads 4 bytes from address 0x00400658 of PID 247
 * 
 * Example:
 * ./poker 247 0x00400658:45464748 - changes 4 bytes to 'EFGH' at address 0x00400658 of PID 247
 * 
 * Example:
 * ./poker 247 0x00400658:45464748:41414141 - changes 'AAAA' to 'EFGH' at address 0x00400658 of PID 247 only if original bytes were 'AAAA'
 * 
 * ./poker 247 0x00400658:45464748:41414141 0x00400668:45464748 0x00800658:45464748 0x00400444:45464748:41414141- works as well
 * 
 * Compile with
 * arm-linux-gnueabihf-gcc --static -o poker poker.c --sysroot=../arm/ -Wl,-dynamic-linker,/lib/ld-2.13.s
 */

#include <strings.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/ptrace.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#define BUFF_SIZE 255

static bool debug = false;
static bool debug_errors = true;

int pid_attach(pid_t pid)
{
	unsigned char dev_mem_filename[BUFF_SIZE];
	debug && printf("ATTACH PID: %d\n",(int)pid);
	sprintf(dev_mem_filename, "/proc/%d/mem", pid);
	int fd = open(dev_mem_filename, O_RDWR);
	if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) == -1) {
		(debug || debug_errors) && printf("Open(%s): ERROR\n", dev_mem_filename);
		return false;
	}
	if (waitpid(pid, NULL, 0) == -1) {
		(debug || debug_errors) && printf("waitpid(%d): ERROR\n", (int)pid);
		ptrace(PTRACE_DETACH, pid, NULL, NULL);
		return false;
	}<commit_msg>Added #define _FILE_OFFSET_BITS 64<commit_after>/*
 * Change memory of another process 4 bytes at a time :)
 * 
 * Usage: ./poker <PID> <hex_address[:hexpair_value[:hexpair_value_original]]>
 * 
 * Example:
 * ./poker 247 0x00400658 - reads 4 bytes from address 0x00400658 of PID 247
 * 
 * Example:
 * ./poker 247 0x00400658:45464748 - changes 4 bytes to 'EFGH' at address 0x00400658 of PID 247
 * 
 * Example:
 * ./poker 247 0x00400658:45464748:41414141 - changes 'AAAA' to 'EFGH' at address 0x00400658 of PID 247 only if original bytes were 'AAAA'
 * 
 * ./poker 247 0x00400658:45464748:41414141 0x00400668:45464748 0x00800658:45464748 0x00400444:45464748:41414141- works as well
 * 
 * Compile with
 * arm-linux-gnueabihf-gcc --static -o poker poker.c --sysroot=../arm/ -Wl,-dynamic-linker,/lib/ld-2.13.s
 */

#include <strings.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/ptrace.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

#define BUFF_SIZE 255
#define _FILE_OFFSET_BITS 64

static bool debug = false;
static bool debug_errors = true;

int pid_attach(pid_t pid)
{
	unsigned char dev_mem_filename[BUFF_SIZE];
	debug && printf("ATTACH PID: %d\n",(int)pid);
	sprintf(dev_mem_filename, "/proc/%d/mem", pid);
	int fd = open(dev_mem_filename, O_RDWR);
	if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) == -1) {
		(debug || debug_errors) && printf("Open(%s): ERROR\n", dev_mem_filename);
		return false;
	}
	if (waitpid(pid, NULL, 0) == -1) {
		(debug || debug_errors) && printf("waitpid(%d): ERROR\n", (int)pid);
		ptrace(PTRACE_DETACH, pid, NULL, NULL);
		return false;
	}
{'fraction_non_alphanumeric': 0.15212264150943397, 'fraction_numerical': 0.11615566037735849, 'mean_word_length': 4.463768115942029, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2412507', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1322, 'n_words': 334}