How to 'read' programs
How to 'read' programs
So I know a bit of C# , php and a bit of C.
what I really want to do is modify some linux programs to suit my needs.
basically how does one 'read' or understand a program ? Lets take jwm for example, lets say I want to add the ability to close applications by middle clicking on them in the taskbar: how do I go about understanding it ? Is there a method to it? I downloaded the source, opened a few C files . didn't understand I thing.
Should I first wet my feet with simpler C programs ? If so can someone suggest me some? I am interested in 'real' C linux programs.
Thanks
what I really want to do is modify some linux programs to suit my needs.
basically how does one 'read' or understand a program ? Lets take jwm for example, lets say I want to add the ability to close applications by middle clicking on them in the taskbar: how do I go about understanding it ? Is there a method to it? I downloaded the source, opened a few C files . didn't understand I thing.
Should I first wet my feet with simpler C programs ? If so can someone suggest me some? I am interested in 'real' C linux programs.
Thanks
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
Re: How to 'read' programs
helloreasonit wrote:...
Should I first wet my feet with simpler C programs ? If so can someone suggest me some? I am interested in 'real' C linux programs.
...
Re: How to 'read' programs
This is real C. It is as trivial as it comes for a do something utility. It isreasonit wrote:Should I first wet my feet with simpler C programs ?
If so can someone suggest me some? I am interested in 'real' C linux
programs.
Thanks
used as a pipe. Takes character input and outputs in hex.
Take a bite on it. Then Muggins or I can explain.
Code: Select all
#include <stdio.h>
int main() {
register int ch;
while((ch=getchar()) != EOF) {
if ( ch == 10 ) {
printf ("0a ");
continue;
}
printf ("%0x ", ch);
}
return(0);
}
Last edited by Bruce B on Thu 26 May 2011, 04:36, edited 1 time in total.
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
Re: How to 'read' programs
May I join the playground ?Bruce B wrote:Take a bite on it.
half bit of C, some php, bash and BaCon....
I am coming here from testing wary51157 running as fido, devx installed.
Code: Select all
mkdir ~/programming/C
compiled (fido can !)
Code: Select all
# gcc char2hex.c
Code: Select all
# echo "123" | ./a.out
31 32 33 0a
Code: Select all
# pwd
/root/programming/C
# whoami
fido
54 68 61 6e 6b 20 79 6f 75 0a #
L18L,
This is the bash script to reassemble the hex. You should be able to
take the output of char2hex, even on a complex file like a binary file
and reassemble with perfect md5sum match. Moreover, if not
perfect something is wrong.
The script doesn't work like it looks like it works. It is strictly a pipe.
Use it the same as the char2hex.
It only works on the hex input format like char2hex outputs.
cat filename.txt | char2hex | hex2char
So, you know by the command that filename.txt was converted to
the hex output, piped to hex2char and prints the text again.
For a binary file
cat filename.bin | char2hex
But not this
cat filename.bin | char2hex | hex2char
The reason why is there are often characters in the .bin file which
shouldn't be printed to the screen and locks up your bash terminal
In simple words. Don't output things to screen which crash the
monitor.
Bruce
~
This is the bash script to reassemble the hex. You should be able to
take the output of char2hex, even on a complex file like a binary file
and reassemble with perfect md5sum match. Moreover, if not
perfect something is wrong.
The script doesn't work like it looks like it works. It is strictly a pipe.
Use it the same as the char2hex.
It only works on the hex input format like char2hex outputs.
Code: Select all
#!/bin/bash
for i in `cat $1` ; do
printf "\x$i"
done
cat filename.txt | char2hex | hex2char
So, you know by the command that filename.txt was converted to
the hex output, piped to hex2char and prints the text again.
For a binary file
cat filename.bin | char2hex
But not this
cat filename.bin | char2hex | hex2char
The reason why is there are often characters in the .bin file which
shouldn't be printed to the screen and locks up your bash terminal
In simple words. Don't output things to screen which crash the
monitor.
Bruce
~
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
C language
Thank you, BruceBruce B wrote:...
This is the bash script to reassemble the hex. You should be able to
take the output of char2hex, even on a complex file like a binary file
and reassemble with perfect md5sum match. Moreover, if not
perfect something is wrong.
...
For me it was working.
But first let me point to the story that might give an explanation to OP and others.
And then admit: If had completely read this before my example would have been better.
Not:
Code: Select all
# gcc char2hex.c
Code: Select all
gcc char2hex.c -o char2hex
Anyway I had to use it with a.out instead of char2hex
No: with .a.aut
OT ?
- the dots are important
- fido can
Thanks again
- abushcrafter
- Posts: 1418
- Joined: Fri 30 Oct 2009, 16:57
- Location: England
- Contact:
Great idea! Close window on middle click. I love it . I hope it gets added to JWM.
[url=http://www.adobe.com/flashplatform/]adobe flash is rubbish![/url]
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/
- abushcrafter
- Posts: 1418
- Joined: Fri 30 Oct 2009, 16:57
- Location: England
- Contact:
Sorry, I meant on the task bar buttons.jpeps wrote:Middle button typically pastes the clipboard, which might be a conflict.abushcrafter wrote:Great idea! Close window on middle click. I love it . I hope it gets added to JWM.
[url=http://www.adobe.com/flashplatform/]adobe flash is rubbish![/url]
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/