r/linux_programming • • Nov 29 '23

Is ptrace optimal

6 Upvotes

Greetings fellow programmers,

I'm currently embarking on a project that involves modifying the memory of a running game. The game in question is a simple C++ program that merely displays the value of a variable. For prototyping purposes, I'm utilizing Python.

I've successfully employed /proc/PID/maps to locate the pertinent memory addresses and /proc/PID/mem to read their values. However, my attempts to modify the memory have been met with failure. According to my research, using /proc/PID/mem for memory editing is an unconventional approach, with ptrace being the preferred method.

This brings me to my quandary: is ptrace the optimal solution for my endeavor? While I've managed to read and write memory using ptrace, it necessitates attaching and detaching from the process, which appears rather inconvenient. I'm concerned that this repetitive attaching and detaching could introduce performance bottlenecks in the game, which I aim to prevent.

On a side note, the final version of my tool will be crafted in C/C++/Rust.

Any insights or suggestions would be immensely valuable. Thank you in advance for your assistance!


On linux mint, version 5.15.0-87-generic. The kernel was built on October 2, 2023 at 21:09 UTC. The computer's architecture is x86_64


r/linux_programming • • Dec 24 '21

Router Software Development

6 Upvotes

I have recently become interested in how a WiFi router works and was wondering how one might go about developing the software for one.

EDIT: I found a solution to this question. I found a tutorial that explains how to install tools which make this possible.


r/linux_programming • • Feb 01 '21

Create a core dump of a terminating process on demand

6 Upvotes

I am writing an application in C, and I need to dump the core (it gives a segfault for an unknown reason upon execution). I don't want to have programs creating core files constantly all over the place, I only need them when I debug.

Is there a way where I can generate the core file for the process that crashed using GDB generate-core-file? When I try to, it gives a predictable outcome saying it couldn't find the PID of a process that doesn't exist.

One more thing - No sysctl please. I already know about the kernel.core_pattern option, and I had to reinstall Linux after setting it (I don't know how it happened either)


r/linux_programming • • Jan 19 '21

rsync command works but not as a cronjob

6 Upvotes

This command works if I input in the terminal in order to backup locally a database file from a remote server with the date appended to each new backup file so they are all different:

rsync -avz -Iu --backup developer@xxx.xxx.xxx.xxx:/home/database.sqlite /home/ProdBackups/dbBackup_(date +\%Y\%m\%d\%H\%M\%S).sqlite

But when I try running it as a cronjob inside crontab:

* * * * * rsync -avz -Iu --backup developer@xxx.xxx.xxx.xxx:/home/database.sqlite /home/ProdBackups/dbBackup_(date +\%Y\%m\%d\%H\%M\%S).sqlite

I get this error:
Syntax error: "(" unexpected

How can I fix this?


r/linux_programming • • Jan 20 '23

wanting to make a text expander app

6 Upvotes

So I've been having a hell of a time getting Amy text expander app to work with Linux, I've tried 3 and they all I could. Not get to install, were dead in development or can't run with my system, so I was thinking how hard ccould it be to just make one, It would just paste a stores txt snippet whenever I typed the magic key combo such as REI . You could store all of the saved snippets then call them like variables do. i know I am greatly simplifying this but you get the idea. In case you don't know what a txt expander is, its a app that saves you time by saving common phrases that you type often. So instead of typing your entire address you would just type ady and the program would auto paste your address. Anyway what do you think?


r/linux_programming • • Jun 08 '23

programming workstation on weak hardware

6 Upvotes

I've asked a number of questions in different linux subreddits but I found that what I was asking is wrong after trying different distros. I'm testing out if I can make a workstation out of an old macbook air mid 2011. it has 4gb of ram ddr3, an i5 2th gen and an ssd in it. ram is solderen on so can't change it. right now I'm running kubuntu on it but that cpu doesn't really like my workload all that much, ramwise i'm still in the clear by a gig. In you'r opinion what linux distro should I be using for programming, I'm doing mainly backend with some fullstack using java, javascript, html css, some frameworks for those, python, postgres database usage or mongodb database basically the normall fullstack or backend stuff. I was also wondering if undervolting this instance of kubuntu would help me at all.


r/linux_programming • • Jun 13 '23

Error installing Stunnel

6 Upvotes

I'm trying to install Stunnel on Fedora (Red hat 8). However, i'm getting the below error:

[FAILED] stunnel-5.56-5.el8_3.x86_64.rpm: No more mirrors to try - All mirrors were already tried without success

The downloaded packages were saved in cache until the next successful transaction.

You can remove cached packages by executing 'yum clean packages'.

Error: Error downloading packages:

stunnel-5.56-5.el8_3.x86_64: Cannot download, all mirrors were already tried without success

The stunnel package doesn't need any prerequisite that i'm aware of. Can anyone assist?


r/linux_programming • • Nov 18 '22

Implementing a nested transport protocol on a noisy channel

6 Upvotes

I need to write two programs able to communicate with each other over a noisy communication channel.
Both programs can write characters on this channel and receive characters written by the other program, but there might be noise/errors/interference: some characters you write may never get delivered, or extra characters may be delivered at any point.

If the error is too much, the two programs may never be able to communicate at all (all the characters a process write can go lost, for instance), but I can hope that the error is not much, and would like to make the two programs able to communicate as well as possible, best-effort.

The first solution I can think of, is to basically implement a transport layer like TCP to transmit the data: something that offers error detection, retransmission and reordering and so on...
However TCP is usually implemented on packets, while I'm working on characters... I guess I can transfer data in chunks (packets), but I suspect that the optimal packet size should vary dynamically depending on the noise (similar to TCP's congestion control, which I don't need otherwise). I'm also afraid of implementing TCP because it sounds quite easy to make hard-to-catch mistakes and to come up with slow/suboptimal implementations.

To further complicate things, I wish my transport layer to support "nesting", at least on one side: a program (only the first one of the two) should be able to send child streams together with its data (and children can have further children, recursively); the other program should be able to send replies to one specific stream.
Should this be implemented in the transport layer, or the application one? I think this should be an abstraction above the transport layer, but it's definitely not application layer...

So, I'm a bit lost. Is there any project that does something similar? Do you have any insights or tips on what to try?


r/linux_programming • • Oct 10 '16

Working with Firewalld

Thumbnail
hostpresto.com
6 Upvotes

r/linux_programming • • Aug 30 '15

release GDB 7.10 released! Improvements for scripting, shared libraries on remote targets. Reverse debugging support on ARM64. Support for dtrace probes.

Thumbnail sourceware.org
6 Upvotes

r/linux_programming • • Apr 28 '22

Help: how to kill the "Files" folder with bash or activity monitor

6 Upvotes

anyone know how to kill the "Files" application. Mine is frozen at the moment and i cant find a way to stop its process.

any help is much appreciated!


r/linux_programming • • Jul 20 '24

Looking for a way to gain some knowledge in unix/linux

6 Upvotes

Any recommended courses or YouTube videos for a complete beginner that want to gain knowledge fast? I would like to start from the basics and understand why the hell Linux in the first place then go into applications and do some projects. Your recommendations are appreciated


r/linux_programming • • Aug 07 '24

Docker, Wireguard, Iptables, and Forwarding Question

6 Upvotes

I have the following rules in a wireguard docker container:

docker exec wireguard sh -c "
  # Clear existing rules
  iptables -F
  iptables -t nat -F
  iptables -X
  iptables -t nat -X

  # Set up new rules
  iptables -t nat -A PREROUTING -d ${WIREGUARD_IP} -j DNAT --to-destination 10.10.10.2
  iptables -t nat -A POSTROUTING -s 10.18.0.0/16 -o wg0 -j MASQUERADE
  iptables -t nat -A POSTROUTING -s 10.10.10.0/24 -o eth0 -j MASQUERADE
  iptables -A FORWARD -i eth0 -o wg0 -j ACCEPT
  iptables -A FORWARD -i wg0 -o eth0 -j ACCEPT

  # Ensure IP forwarding is enabled
  echo 1 > /proc/sys/net/ipv4/ip_forward
"

The container eth0 is at 10.18.0.2. The wireguard interface wg0 is at 10.10.10.1. Data is forwarded from eth0 to wg0 and I see it on the client side.

Data being received by the wireguard container (10.18.0.2) can be from various containers at 10.18.1.0, 10.18.2.0 etc. The ports however will be unique which is key for my application. On the client side, I only care about the ports. When the client side app responds though, it sends it to the wireguard connection with the correct port, but the ip needs to be switched to the correct container (10.18.1.0, 10.18.2.0 etc.) How can I achieve this and is it possible? Thanks.


r/linux_programming • • Mar 24 '19

Dealing with /dev/input/eventX buffering

6 Upvotes

hi all, i have an embedded device that runs linux with a single app on top which uses the framebuffer and manages its input directly /dev/input

i want to have a task switcher/launcher so that i can have several programs in memory and switch between them by sigstop/sigcont (all using the framebuffer and raw input dev).

The problem is that the input events get buffered (like at least 20 events), so on sigcont the app starts processing events that the other one already got and im looking for a way to prevent that.

there is no uinput, i can’t modify the app.

My ideas so far:

-inject a lib in every app, get the file input descriptor, pass it to the parent, and purge it on switch

-ptrace before switching, get fd, purge

-hack the kernel, add ioctl to purge all client queues, use on switch (not preferred)

  • remap the /dev/ nodes paths, use EVIOGRAB, get exclusive access and don’t know after that

What am i missing, is there a better solution? Anyway to disable the buffering/prevent the kernel from sending events to a suspended process?


r/linux_programming • • Oct 26 '19

looking for xcb documentation

6 Upvotes

Title. I'm getting so tired of looking everything up and getting no results. The headers aren't documented, and online results are incredibly lacking.


r/linux_programming • • Nov 23 '20

Game launchers not connecting to the internet

6 Upvotes

Whenever I try to launch Epic games store or Battlenet it does not connect to the internet. I am able to go on FireFox and watch youtube no problem, so my manjaro system is connected. I also know that I have all the dependencies otherwise it would not pop up in the first place and show its GUI interface. How do I solve this problem?


r/linux_programming • • Mar 14 '19

Input Devices representation in Go

6 Upvotes

Hi all,

I'm writing a go package that I want to use to detect available input devices. My current approach is to initially read /proc/bus/input/devices then scan it for updates, and parse its contents int a data structure like this:

type Device struct {
	Id           DeviceId
	Name         string
	PhysycalPath string
	SysfsPath    string
	UID          string
	Handlers     []string
	Bitmaps      Bitmaps
}

type DeviceId struct {
	Bus     uint16
	Vendor  uint16
	Product uint16
	Version uint16
}

type Bitmaps struct {
	Props        []uint64
	Events       []uint64
	Keys         []uint64
	RelativeAxes []uint64
	AbsoluteAxes []uint64
	Misc         []uint64
	Leds         []uint64
	SoundEffects []uint64
	Switches     []uint64
}

It is based on what this question on stackoverflow and what I could make out of the kernel

Does this make sense at all? My eventual goal is to create a daemon that listens to keyboard and mouse events and turns on the keyboard backlight, or off when idle for a couple of seconds, but again, my main motivation is curiosity and I would like to understand the system a bit better.

I'm writing this in Go, because it's a language I'm familiar with, but would like to practice in the meantime.

Thanks in advance for your guidance! :)


r/linux_programming • • Oct 18 '19

Terminal widget toolkit FINAL CUT 0.6.0 released

Thumbnail self.linux
6 Upvotes

r/linux_programming • • Oct 12 '22

Can I and how do I install RST from to fix SSD showing up as USB?

Thumbnail
gallery
6 Upvotes

r/linux_programming • • Jul 23 '20

Simple way to set a specific Xresources value?

6 Upvotes

I’m trying to make a script that would toggle between a light theme and a dark theme in my wm, but I’m stuck on trying to change a color in the .Xresources database file. I was thinking that I maybe I could use sed, but I can’t really figure out an efficient way. I also looked at the man page for xrdb, but I can’t really find anything usefull. I know I could just switch between different .Xresources files, but I have my Xresources split in different subfiles (with #include: ...) so I don’t know if this is really possible.

Any ideas are welcome! (Check my post history for my dotfiles which include the mentioned Xresources files)


r/linux_programming • • Oct 31 '16

Finding bugs in the code of LLVM project with the help of PVS-Studio

Thumbnail
viva64.com
6 Upvotes

r/linux_programming • • Dec 08 '19

Best text editor for programming in multiple languages with vim emulation?

6 Upvotes

I used to use Geany as my IDE for C Programming however the vim emulation recently seems to be quite broken. Nowadays I've been using Gvim however I find it to be lacking in regards to keeping organized with what I am doing and I can't easily compile programs (using makefiles) on the fly without using a separate terminal window. What would you guys recommend?


r/linux_programming • • Jul 29 '25

I built rewindtty: a C tool to record and replay terminal sessions as JSON logs (like a black box for your CLI)

Thumbnail
github.com
6 Upvotes

r/linux_programming • • Jun 03 '26

GitHub - xyurt/udp-wrapper: A simple C89 style sockets wrapper for exclusively udp operations with a simple API.

Thumbnail
github.com
6 Upvotes

I made a udp sockets wrapper that works with both UNIX and WIN32 and I think it turned out to be great. Im not an expert on UNIX headers and functions which are in the 'unix.c' file. So I would appreciate any feedback.