As an embedded linux programmer, I’ve had the opportunity to work on a number of different platforms, MIPS being one of my favorites.
There are a few general limitations that you’ll find. You have limited CPU power available, you have very little RAM available, and for more advanced operations and optimizations, your CPU will generally have a limited function set.
The usual good programming practices apply, but are of much greater importance. Specifically, don’t allocate memory that you don’t need, and dont put the CPU under undue stress with unnecessary or badly optimized loops. Taking C syntax and some pseudo code;
(more…)
Tags: assembler, embedded, loop, mips, optimize, x86
Compiling a program doesn’t protect it or necessarily hide the source. Take the following example C program. It serves no real life purpose and should never print anything to the console:
#include <stdio.h>
int main(void)
{
const char *password = "secretpassword";
const char *otherpassword = "othersecretpassword";
if(!strcmp(password, otherpassword))
{
printf("This will never get evaluated");
}
return 0;
}
To assemble the code using gcc -S test.c leaves test.s. The important point being that all strings remain intact:
(more…)
Tags: C, gcc, Linux, ls, reverse engineering, strings
Here’s a very brief example of how to use setuid() and setgid() functions in your C program.
int main(void)
{
int current_uid = getuid();
printf(“My UID is: %d. My GID is: %d\n”, current_uid, getgid());
system(“/usr/bin/id”);
if (setuid(0))
{
perror(“setuid”);
return 1;
}
//I am now root!
printf(“My UID is: %d. My GID is: %d\n”, getuid(), getgid());
system(“/usr/bin/id”);
//Time to drop back to regular user priviledges
setuid(current_uid);
printf(“My UID is: %d. My GID is: %d\n”, getuid(), getgid());
system(“/usr/bin/id”);
return 0;
}
The program above should be pretty self explainatory, now:
Tags: C, gcc, Linux, setgid, setuid, System
Further to post http://www.adamsinfo.com/multithreaded-tcp-proxy-tunnel-code/
I have received a report from a user experiencing the following error:
# gcc -Wall -g -O2 -o tcp_tun tcp_tun.c -lpthread
tcp_tun.c:44:37: error: getaddrinfo/getaddrinfo.h: No such file or directory
tcp_tun.c:45:37: error: getaddrinfo/getaddrinfo.c: No such file or directory
I think that this is a common error involving distros without getaddrinfo available. I have packaged up everything up with getaddrinfo and a configure/Makefile also. Please let me know your feedback.
Tags: C, gcc, Linux, tcp, tcp proxy, tcp tunnel
Further to my earlier article, I went ahead and developed this application. Here’s a beta!
File: tcp_tun.c
Version: 0.3-beta
Title: TCP reassembling client-server application
Date: 17 Aug 09
Author: Adam Palmer <adam [AT] adamsinfo [DOT] com>
URL: http://www.adamsinfo.com/
(more…)
Tags: C, code, debian, gcc, Linux, multithread, tcp, tcp proxy, tcp tunnel