🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.c
Article #309249

Re: need a program that will print a percent of code in tehe exe/dll

#309249
From: Przemek Biernat
Date: Sun, 30 Apr 2017 17:57
83 lines
4945 bytes
On Sunday, April 30, 2017 at 12:49:15 PM UTC+2, (fir) wrote:
> W dniu niedziela, 30 kwietnia 2017 10:44:50 UTC+2 użytkownik (fir) napisał:
> > W dniu niedziela, 30 kwietnia 2017 01:18:19 UTC+2 użytkownik Matt D. napisał:
> > > On 4/29/2017 14:46, (fir) wrote:
> > > > if you got exe or dll the most important sections are .code .data .const and .bss
> > > >
> > > >  need a simple console program that show the size of the code
> > > > (in bytes and also in percent) in given .exe .dll [also sieze of consts and initialised data, yet size of static arrays]
> > > 
> > > Tools:
> > > GNU Size: https://sourceware.org/binutils/docs/binutils/size.html
> > > PE Insider: http://cerbero.io/peinsider/
> > > 
> > > GNU Size Examples:
> > > http://www.geeksforgeeks.org/memory-layout-of-c-program/
> > > ttp://cs-fundamentals.com/c-programming/memory-layout-of-c-program-code-data-segments.php#size-of-code-data-bss-segments
> > > 
> > > See also Ange Albertini's work:
> > > http://i.imgur.com/tnUca.jpg
> > > https://speakerdeck.com/ange/workshop-exploring-the-portable-executable-format
> > > https://github.com/corkami/docs/blob/master/PE/PE.md
> > > https://speakerdeck.com/ange/x86-and-pe
> > > https://speakerdeck.com/ange/byte-ing-the-pe-that-fails-you
> > > https://speakerdeck.com/ange/booklet-elf101-a-linux-executable-walkthrough
> > > 
> > > Best,
> > > 
> > > Matt
> > 
> > ok, tnx moze sie przyda.. niby program napisany na razie a grzebanie w tym pe jest nudne ale jak ktos jest nieskopoziomowym programista windows to nieststy trzeba chyba znac
> 
> ps przy okazji skrobnalem disklaimer dlaczego czasem moj kod jest "enough good"
> 
> (ps my code posted is badly shaped i know, but it is becouse i do not code edge cases firstly also do not 
> shape code stylistically firstly (just to spare as 
> much energy i can) - anyway one must establish some level on which one think "this code is ENOUGH good" 
> and it is not excluded that setting this level lower 
> is better than setting it higher (i know using structs and do some edge case checking, reformating names and 
> shape etc is in fact better.. but form other point of view go worse is better - so i write this disclimer 
> to say that for sure i know thic coede i post could 
> look better but i also deny to tace comments on this as i code how i code for some practical purpose and dont like to meet morons with their stupid comments like your code is ugly ;c hope im understood) 
> 
> pisze to bo nie chce mi sie gadac z rozmaitymi debilami ktorzy pewnie zawsze pala sie by wypominac "bledy w kodzie " czy "zly wyglad" o czym nie mam zamiaru ostatnio  dyskutowac

My solution:

#include <stdio.h>
#include <iostream>

int main()
{

    FILE* file = fopen("file.txt", "r+w");

    fseek(file, 0, SEEK_END);

    unsigned long long space_count = 0;
    unsigned long long chars_count = 0;
    unsigned long long lines_count = 0;
    unsigned long long all_count = 0;

    char* ch = new char[1];

    while(!feof(file))
    {
        fread(ch, 1, 1, file)

        ++all_count;

        if(ch == 32) //space
            ++space_count;
        else if(ch == 13) //endline
            ++lines_count;
        else
            ++chars_count;
    }

    std::count << "spaces: " << space_count << std::endl;
    std::count << "chars: " << chars_count << std::endl;
    std::count << "lines: " << lines_count << std::endl;
    std::count << "all_count: " << all_count << std::endl;

}
Technical Details
Message-ID: <02d494e0-4a40-414d-9e06-d5aeeee0dc65@googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!news.glorb.com!c26no1168684itd.0!news-out.google.com!x200ni1054itb.0!nntp.google.com!c26no1164442itd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
References: <624bfa7c-7f80-4bc9-a2cb-7598eab65097@googlegroups.com> <oe36vt$i0q$1@portraits.wsisiz.edu.pl> <720aff2d-5d5c-4104-ba18-6167de325226@googlegroups.com> <c1f9ec13-4698-45c0-8249-dbc050d67066@googlegroups.com>

Show Full Headers
Complete Article Headers
X-Received: by 10.36.88.131 with SMTP id f125mr3311302itb.18.1493575020952;        Sun, 30 Apr 2017 10:57:00 -0700 (PDT)
X-Received: by 10.157.84.44 with SMTP id j44mr419857oth.16.1493575020898; Sun, 30 Apr 2017 10:57:00 -0700 (PDT)
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!news.glorb.com!c26no1168684itd.0!news-out.google.com!x200ni1054itb.0!nntp.google.com!c26no1164442itd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups: pl.comp.lang.c
Date: Sun, 30 Apr 2017 10:57:00 -0700 (PDT)
In-Reply-To: <c1f9ec13-4698-45c0-8249-dbc050d67066@googlegroups.com>
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=77.255.83.146; posting-account=JqeG5AoAAAAiFyQBrqF1gF5A1eLVPTrJ
NNTP-Posting-Host: 77.255.83.146
References: <624bfa7c-7f80-4bc9-a2cb-7598eab65097@googlegroups.com> <oe36vt$i0q$1@portraits.wsisiz.edu.pl> <720aff2d-5d5c-4104-ba18-6167de325226@googlegroups.com> <c1f9ec13-4698-45c0-8249-dbc050d67066@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <02d494e0-4a40-414d-9e06-d5aeeee0dc65@googlegroups.com>
Subject: Re: need a program that will print a percent of code in tehe exe/dll
From: Przemek Biernat <biernat.przemyslaw@gmail.com>
Injection-Date: Sun, 30 Apr 2017 17:57:00 +0000
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit