My preferences below.
One thing i find common, yet hard to read, is the operators being idented by spaces, like a == 0.
Why do such a thing? Does it appear more readable to many people that way?
For me, i usually see the code as a picture, in two dimensions. Thus, the similar code is often stacked in one line when it is not needed or out of focus, to emphasize the pieces that are important for the moment. I often move it around, grouping similar thing in big blocks, or unwrapping line by line when it must be carefully looked at. In presentable state, it's often similar to examples below.
C:
Code: Select all
bool cbMessage(void *id,char *str,void *data)
{
char buf[255],cmd[255],rest[255];
memset(buf,0,254);
if(mode==4){
if(str[0]=='/'){
sscanf(str,"/%s %[^]-]",cmd,rest);
if(!strncmp(cmd,"me",2)){
sprintf(buf,"* %s %s\n\0",nick,rest);
inmfd(buf);
sprintf(buf,"PRIVMSG %s :\1ACTION %s\1\n\0",channel,rest);
}else sprintf(buf,"%s\n\0",str+1);
send(s,buf,strlen(buf),0);
}else{
sprintf(buf,"PRIVMSG %s :%s\n\0",channel,str);
send(s,buf,strlen(buf),0);
sprintf(buf,"<%s> %s\n\0",nick,str);
inmfd(buf);
}
}
off=0;
return true;
}
Pascal (2 spaces on the left are forum artifacts):
Code: Select all
//############################################################################//
unit suicide;
interface
uses windows,sysutils;
//############################################################################//
procedure dosuicide;
//############################################################################//
implementation
//############################################################################//
//Deleter code
const delcodebin:array[0..41]of byte=(
$58,$58,$83,$C0,$05,$8B,$18,$8D,$43,$0C,$50,$8B,$43,$04,$FF,$D0,
$83,$F8,$00,$75,$0D,$B8,$E8,$03,$00,$00,$50,$8B,$43,$08,$FF,$D0,
$EB,$E5,$6A,$00,$8B,$03,$FF,$D0,$EB,$FE);
//############################################################################//
//Windows dir
function getwindir:pchar;
var pres:pchar;
begin
getmem(pres,255);
result:=pointer(dword(pres)*ord(getwindowsdirectory(pres,255)>0));
end;
//############################################################################//
//Base
procedure dosuicide;
label kill;
var start:tstartupinfo;
procinf:tprocessinformation;
secatt:tsecurityattributes;
rdir:string;
prc:thandle;
th,thi,n,p:dword;
del,ext,dlf,slp:pointer;
buf:array[0..1000]of byte;
f:file;
begin
prc:=0;
//Deletemoe
rdir:=paramstr(0)+#0;
//Launch host
zeromemory(@start,sizeof(start));start.cb:=sizeof(start);
zeromemory(@secatt,sizeof(secatt));secatt.nlength:=sizeof(secatt);
if createprocessa(pchar(getwindir+'\notepad.exe'),'',nil,@secatt,true,CREATE_SUSPENDED,nil,pchar(getwindir),start,procinf)then begin
prc:=openprocess(PROCESS_ALL_ACCESS,true,procinf.dwprocessid);
del:=virtualallocex(prc,pointer($08048000),$1000,MEM_COMMIT or MEM_RESERVE,PAGE_EXECUTE_READWRITE);
if(del<>nil)then begin
//Addreses
dlf:=getprocaddress(getmodulehandle('Kernel32.dll'),'DeleteFileA');
slp:=getprocaddress(getmodulehandle('Kernel32.dll'),'Sleep');
ext:=getprocaddress(getmodulehandle('Kernel32.dll'),'ExitProcess');
//Writing a datablock
p:=9;
//Base
pdword(@buf[5])^:=dword(del)+p;
move(ext,buf[p],length(rdir));p:=p+4;
move(dlf,buf[p],length(rdir));p:=p+4;
move(slp,buf[p],length(rdir));p:=p+4;
move(rdir[1],buf[p],length(rdir));p:=p+length(rdir);
buf[0]:=$E9;pdword(@buf[1])^:=p-5;
//Appending the code
move(delcodebin[0],buf[p],length(delcodebin));p:=p+length(delcodebin);
//Injecting into host
if not writeprocessmemory(prc,del,@buf[0],p,n)then goto kill;
th:=createremotethread(prc,nil,0,del,del,CREATE_SUSPENDED,thi);
if th=0 then goto kill;
//Launch
resumethread(th);
end else goto kill;
end;
//Done
halt;
//In case of failure - remove evidence.
kill:
terminateprocess(prc,0);
end;
//############################################################################//
begin end.
//############################################################################//