Article View: pl.comp.lang.c
Article #309246Re: need a program that will print a percent of code in tehe exe/dll
From: (fir)
Date: Sat, 29 Apr 2017 22:49
Date: Sat, 29 Apr 2017 22:49
89 lines
4458 bytes
4458 bytes
W dniu niedziela, 30 kwietnia 2017 00:01:21 UTC+2 użytkownik Roman Tyczka napisał:
> On Sat, 29 Apr 2017 14:01:26 -0700 (PDT), (fir) wrote:
>
> >> I do it for you with no your cost. Give me message if you agree.
> >
> > mozesz zapostowac kod jesli chcesz... sam przy okazji jednak tez to skrobne, bo jak mowie to dobry pomysl.. trudniej by bylo zrobic plugin do total komandera ktory by to wyswietlal a przydalby sie moze
>
> https://totalcmd.net/plugring/fileinfo.html
> https://totalcmd.net/plugring/peviewer.html
>
te pluginy podaja rozmiary w heksie co jest nieczytelne,
mi sjest potrzebny rozmiar kodu w kodzie w moich wlasnych produkcjach ot tak dla ciekawosci (mozna dostrzec ciekawe rzeczy np rozmiar .bss u mnie w niektorych libkach jest czasem zasakujaco duzy, a tak z glowy nie pamietalem ze az tyle tego alokuje)
machnalem jakiegos tam drafta testowego
///////////////////////////////////////////
int GetFileSize1(FILE* file)
{
int seek_pos = ftell(file);
int error = fseek(file, 0, SEEK_END);
if(error) printf ("seek1 error"), exit (-1);
int file_length = ftell(file) ;
error = fseek(file, seek_pos, SEEK_SET);
if(error) printf ("seek2 error"), exit (-1);
return file_length;
}
int main(int argc, char **argv)
{
char* filename = NULL ;
if (argc>=2)
filename = argv[1];
else
printf ("\n this tiny program prints names and sizes of executable file sections (exe or dll) \n USE: firdump.exe filepath \n "), exit (-1);
FILE* file = fopen ( filename , "rb" );
if (!file) printf ("cant open file %s", filename), exit (-1);
static char pe_image[1024];
int result = fread (pe_image, 1, 1024, file);
int file_size = GetFileSize1(file);
fclose(file);
///////////
printf("\n --= fir's executable sections info =-- \n\n sections for %s ( %d bytes ) \n", filename, file_size);
int pe_header_offset = *((int*) &pe_image[0x3c]);
int size_of_image_file_header = 24;
short size_of_optional_header = *((short*) &pe_image[pe_header_offset+20]);
int sections_offset = pe_header_offset + size_of_image_file_header + size_of_optional_header;
short number_of_sections = *( (short*) &pe_image[pe_header_offset+6]);
for(int n = 0; n<number_of_sections; n++)
{
char* section_name = (char*) &pe_image[sections_offset + n*0x28];
int section_size = *((int*) &pe_image[sections_offset + n*0x28 + 8]);
unsigned section_flags = *((unsigned*) &pe_image[sections_offset + n*0x28 + 36]);
static char section_flags_binary_string [33];
itoa (section_flags, section_flags_binary_string, 2);
int percent_size = 100*section_size/file_size;
if(section_size>file_size)
printf("\n %10.8s %10d bytes %4s %33s", section_name, section_size, " ", section_flags_binary_string );
else
printf("\n %10.8s %10d bytes %4d%% %33s", section_name, section_size, percent_size, section_flags_binary_string );
}
printf("\n\n " );
////////////
}
Technical Details
Message-ID:
<60b03ac2-9954-4a28-9a82-779a83d98ef2@googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!news.glorb.com!c26no963979itd.0!news-out.google.com!v18ni427ita.0!nntp.google.com!c26no968075itd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mailReferences:
<624bfa7c-7f80-4bc9-a2cb-7598eab65097@googlegroups.com> <2759e3b5-664e-473a-b1fc-7a1f84914943@googlegroups.com> <728708c8-2fa8-43ce-947c-f18c58289783@googlegroups.com> <14tyhz1ifk1vj.dlg@tyczka.com>Show Full Headers
Complete Article Headers
X-Received: by 10.157.42.132 with SMTP id e4mr7632300otb.114.1493506184686; Sat, 29 Apr 2017 15:49:44 -0700 (PDT) X-Received: by 10.157.40.242 with SMTP id s105mr364452ota.5.1493506184601; Sat, 29 Apr 2017 15:49:44 -0700 (PDT) Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit0.net!news.glorb.com!c26no963979itd.0!news-out.google.com!v18ni427ita.0!nntp.google.com!c26no968075itd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: pl.comp.lang.c Date: Sat, 29 Apr 2017 15:49:44 -0700 (PDT) In-Reply-To: <14tyhz1ifk1vj.dlg@tyczka.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=5.172.255.219; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN NNTP-Posting-Host: 5.172.255.219 References: <624bfa7c-7f80-4bc9-a2cb-7598eab65097@googlegroups.com> <2759e3b5-664e-473a-b1fc-7a1f84914943@googlegroups.com> <728708c8-2fa8-43ce-947c-f18c58289783@googlegroups.com> <14tyhz1ifk1vj.dlg@tyczka.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <60b03ac2-9954-4a28-9a82-779a83d98ef2@googlegroups.com> Subject: Re: need a program that will print a percent of code in tehe exe/dll From: "(fir)" <profesor.fir@gmail.com> Injection-Date: Sat, 29 Apr 2017 22:49:44 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit