Thread: Help understanding this code

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    107

    Help understanding this code

    This was the/a solution to the 2011 GCHQ challenge. Binary world for binary people : GCHQ Challenge Part 1 - http://www.canyoucrackit.co.uk/

    I can understand most of it I think. Don't know what the u8, u16 and u32 type are. I dont understand this line.

    Code:
    *((u16 *)((u8 *)g + 0x93)) = 0xcccc;
    Code:
    #include <windows.h>
    #include <cstdint>
    typedef uint8_t u8;
    typedef uint16_t u16;
    typedef uint32_t u32;
    
    typedef void (*func)();
    
    int main(int argc, char** argv)
    {
        func g = (func)VirtualAlloc(NULL, 1024, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
        FILE *f = fopen("./part1.bin", "rb");
        fread(g, 1, 160, f);
        fclose(f);
        f = fopen("./DecodedBase64.bin", "rb");
        fread((u8 *)g + 160, 1, 58, f);
        fclose(f);
    
        *((u16 *)((u8 *)g + 0x93)) = 0xcccc;
    
        g();
    
        return 0;
    }
    Any explanations would be helpful.

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by jim_0 View Post
    I can understand most of it I think. Don't know what the u8, u16 and u32 type are. I dont understand this line.

    Code:
    typedef uint8_t u8;
    typedef uint16_t u16;
    typedef uint32_t u32;
    I think you can see it now, right? They are typedef'ed. If you google unit8_t, unit16_t and uint32_t you will find plenty of information.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding this code
    By sameertelkar in forum C Programming
    Replies: 11
    Last Post: 01-04-2013, 07:36 AM
  2. Need Help Understanding This Code.
    By thisbeme in forum C Programming
    Replies: 11
    Last Post: 03-04-2011, 12:01 PM
  3. Need help to understanding the code
    By zbonzbon in forum C Programming
    Replies: 10
    Last Post: 02-13-2011, 10:23 PM
  4. Help understanding a code
    By lolguy in forum Networking/Device Communication
    Replies: 2
    Last Post: 03-15-2009, 04:13 PM
  5. help understanding code
    By volk in forum C Programming
    Replies: 5
    Last Post: 02-08-2003, 10:50 AM