Jump to content

UnKn0wnBooof

Active Members
  • Posts

    146
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by UnKn0wnBooof

  1. Ah, my oroginal code was meant to be doing what the second piece of code does - send a file to the 3DS. The code I posted wasn't meant to be recieving anything. Since I had copied the first bunch of code from stackexchange, I had thought that it would be doing what the second piece of code does.

    Both pieces of code are meant to be sending a file, yes :) .

    Like I said - new to C, I pretty much know nothing. I'm definitely gonna note down your responses though, as they may come in handy when I try to learn more about it.

    The second piece of code I posted, was made by the developer of FBI. FBI (3DS Homebrew) receives the file while the code I posted was designed to send it.

    Really appreciate your response :D Do you do console hacking by any chance? You seem quite knowledgeable about this stuff! Why not make a homebrew? With your skills, you'd be an awesome addition to the GBATemp community!

  2. Well for all intents and purposes your code is fine. The only bit of cleanliness that's rubbing me the wrong way is that in C you have low-level IO using int file descriptors and high(er) level io using FILE* pointers. Typically you'd pick one and do everything with it. You're using both (low for the socket, high for the output file).

    Anyways, let's go over your code since it seems fairly decent.

    Line 10 - I have no idea what requires that include but it's not one I've seen much.

    Line 16 - Instead of having a big 'if' whose body is 90% of the program, test for argc not being 3 and if so, spit out an error and return. No need for an 'else' which means you drop 1 level of indentation which is always nice.

    Lines 18+19 - While it helps to give variables meaningful names, you're not really gaining anything here as you need the variables in question exactly once. Just use the argv[x] value and drop a comment near where you use it for clarity if you must.

    Line 20 - You're opening a file in (binary) append mode, meaning that if the file already existed you're going to append rather than replace which is almost certainly not what you want. The 'b'(inary) character is allowed for compatibility reasons, but NON-POSIX-compliant. All you need is a simple "w". For low-level IO you'd use int fd = open( argv[1], O_WRONLY|O_EXCL);

    Line 27 - 'First' relative to what? You created your destination file first...

    Line 38 - I'd use struct hostent *hostinfo = gethostbyname(argv[2]); instead which also does a DNS lookup if you needed it, the result you can then use to populate sin_addr with, like so:

      hostinfo = gethostbyname (argv[2]);
      if (hostinfo == NULL)
        {
          printf("Unknown host %s.\n", argv[2]);
          return 3; // Or whatever.
        }
      serv_addr.sin_addr = *(struct in_addr *) hostinfo->h_addr;

    Line 49 - You use memset to populate the buffer with all '0' characters (0x30 in ASCII). I think you want '\0' instead, which is the NUL character (0x00 in ASCII). Also, don't use sizeof(buff) but instead use sizeof(char)*BUF_SIZE

    Line 53 - Check your return codes - writes can fail too you know. For low-level IO you use int bytesWritten = write( fd, &buff, bytesReceived); and you should verify that bytesWritten == bytesReceived.

    Line 57 - As I mentioned before, the situation here is that the remote side closed the socket so you should report it as such.

    Line 59 - And also as mentioned before, now's the time to close the socket, flush the FILE* pointer if you're using that (file descriptors don't use buffers, so no need to flush them) and (f)close the destination file pointer/descriptor. After that, finally, you can return 0.

    Note: All code suggestions are untested and I might have a pointer reference mixed up, so don't take it all on face value.

    Wow! Thanks for the tips! As I said - most (if not all) of the code I provided was copied 'n pasted from stackexchange. I made minor modifications. I was pretty much guessing stuff :blink: .

    I really appreciate the help!

    I contacted the dev of FBI and he also provided some code and we spent about half an hour fixing stuff so it would compile under Linux. Here is the new code:

    #include <errno.h>
    #include <string.h>
    #ifdef __WIN32__
    #include <winsock2.h>
    
    char* sockGetErrorString() {
        char *s = NULL;
        FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD) WSAGetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR) &s, 0, NULL);
        return s;
    }
    #else
    #include <arpa/inet.h>
    char* sockGetErrorString() {
        return strerror(errno);
    }
    #endif
    
    #include <stdio.h>
    #include <fcntl.h>
    #include <unistd.h>
    #include <string>
    #include <stdlib.h>
    
    
    int main(int argc, const char* argv[]) {
        if(argc != 3) {
            printf("Usage: %s ip file\n", argv[0]);
            return -1;
        }
    
    #ifdef __WIN32__
        WORD versionWanted = MAKEWORD(1, 1);
        WSADATA wsaData;
        WSAStartup(versionWanted, &wsaData);
    #endif
    
        FILE* fd = fopen(argv[2], "r");
        if(!fd) {
            printf("Failed to open file: %s\n", sockGetErrorString());
    #ifdef __WIN32__
            WSACleanup();
    #endif
            return -1;
        }
    
        fseek(fd, 0, SEEK_END);
        uint64_t size = (uint64_t) ftell(fd);
        fseek(fd, 0, SEEK_SET);
    
        int sock = socket(AF_INET, SOCK_STREAM, 0);
        if(sock < 0) {
            printf("Failed to open socket: %s\n", sockGetErrorString());
    #ifdef __WIN32__
            WSACleanup();
    #endif
            return -1;
        }
    
        struct sockaddr_in address;
        memset(&address, 0, sizeof(address));
        address.sin_family = AF_INET;
        address.sin_port = htons(5000);
        address.sin_addr.s_addr = inet_addr(argv[1]);
        if(connect(sock, (struct sockaddr *) &address, sizeof(address)) < 0) {
            printf("Failed to connect: %s\n", sockGetErrorString());
    #ifdef __WIN32__
            WSACleanup();
    #endif
            return -1;
        }
    
        printf("Sending info...\n");
        fflush(stdout);
    
        uint64_t fileSize = size;
        static const int num = 42;
        if(*((char*) &num) == num) {
            fileSize = (((uint64_t) htonl((uint32_t) fileSize)) << 32) + htonl((uint32_t) (fileSize >> 32));
        }
    
        if(send(sock, (char*) &fileSize, sizeof(fileSize), 0) < 0) {
            printf("Failed to send info: %s\n", sockGetErrorString());
    #ifdef __WIN32__
            WSACleanup();
    #endif
            return -1;
        }
    
        printf("Sending file...\n");
        fflush(stdout);
    
        uint64_t bufSize = 1024 * 16; // 16KB
        void* buf = malloc(bufSize);
        for(uint64_t pos = 0; pos < size; pos += bufSize) {
            size_t read = fread(buf, 1, bufSize, fd);
            if(send(sock, (char*) buf, read, 0) < 0) {
                printf("Failed to send file (pos %d): %s\n", pos, sockGetErrorString());
    #ifdef __WIN32__
                WSACleanup();
    #endif
                return -1;
            }
        }
    
        printf("Waiting for server to finish receiving...\n");
    
        char temp;
        while(recv(sock, &temp, sizeof(temp), 0) != 0) {
            sleep(1);
        }
    
        printf("Closing...\n");
    
        close(sock);
        fclose(fd);
    
        printf("File successfully sent.\n");
    
    #ifdef __WIN32__
        WSACleanup();
    #endif
    
        return 0;
    }
    

    You think any improvements could be made to this?

  3. I looked at your sources and at both the FBI program and the java Sockfile thing's source code. None of these contain the string "Reading info".

    Care to try again? When you do, please specify the output you see on the screen on both sides of the communication channel.

    Regarding your own code, after having received all the data you should fflush() your fp and close both your socket and your fp. Second parameter to fwrite should be sizeof(char). And since bytesReceived being negative is your valid exit situation maybe you shouldn't print "Read error" on encountering it.

    On the 3DS screen, (in FBI) - it freezes on this:

    IMG_20150504_222139.jpg

    Do you think it would be possible to show a piece of example code? I'm new to C so...

    Edit: Also, I got "my" code from an example on stack exchange. I have no idea what some of the functions in my script even do. It could be completely wrong for all I know :wacko:

  4. So, I've been using a program called "FBI" for a while, which lets a user install .CIA files on to the 3DS. There's an option within the application which enables you to recieve a .CIA through WiFi via a sock connection.

    The dev of the homebrew is using a Java program to send the files. I want a C version so I can port it easily to other devices. I mainly want it so I can run it on Android (compile C as Linux binary, place it in /system/xbin).

    I looked at some code on other websites but non of which seems to work. Here is the code I'm currently working on:

    // For both
    #include <sys/socket.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <errno.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #define PORT 5000
    #define BUF_SIZE 16384
     
    int main(int argc, char** argv)
    {
        if (argc == 3)
        {
            const char* filename = argv[1];
            const char* consoleip = argv[2];
            FILE *fp = fopen(filename, "ab");
            if(NULL == fp)
            {
                printf("Error opening file");
                return 1;
            }
     
            /* Create a socket first */
            int sockfd = 0;
            if((sockfd = socket(AF_INET, SOCK_STREAM, 0))< 0)
            {
                printf("\n Error : Could not create socket \n");
                return 1;
            }
            /* Initialize sockaddr_in data structure */
            struct sockaddr_in serv_addr;
            serv_addr.sin_family = AF_INET;
            serv_addr.sin_port = htons(PORT); // port
            serv_addr.sin_addr.s_addr = inet_addr(consoleip);
     
            /* Attempt a connection */
            if(connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))<0)
            {
                printf("\nError : Connect Failed\n");
                return 1;
            }
            /* Receive data in chunks of BUF_SIZE bytes */
            int bytesReceived = 0;
            char buff[BUF_SIZE];
            memset(buff, '0', sizeof(buff));
            while((bytesReceived = read(sockfd, buff, BUF_SIZE)) > 0)
            {
                printf("Bytes received %d\n",bytesReceived);
                fwrite(buff, 1,bytesReceived,fp);
            }
            if(bytesReceived < 0)
            {
                printf("\nRead Error\n");
            }
            return 0;
        }
        else
        {
            printf("Usage:\n\n%s [FILENAME] [3DS IP]\n",argv[0]);
        }
        return 1; // Something went wrong
    }
    

    I'm new to C so I have no idea what to do. FBI freezes on "Reading info".

    This is the homebrew: http://gbatemp.net/threads/release-fbi-open-source-cia-installer.386433/

    Any help is deeply appreciated. Thanks!

  5. Wanna Pledge?

    So, how should I start this? Well... Some time last year, I took the time to modify parts of the MK5's web UI (here) but I wasn't able to fully test or modify it due to the lack of owning a physical unit - I had hosted it on a Raspberry Pi so most of the features were broken :sad: .

    As such, I couldn't really do much with it... Had if I owned a unit, I would've kept developing on it and provided all the code via GitHub so users could freely install it at will. Due to me being a rather low-class citizen with very little money, I am unable to purchase a WiFi Pineapple so my work could start off again, neither am I able to raise the funds myself as my current income pretty much goes towards essentials - leaving me with pretty much no money I can "play with".

    Anyway, I haven't started a pledge campaign yet because it would be pointless if no one wanted to help me out with it, so instead I'd rather ask you guys about it first - give me your opinion on the subject, would you be willing to help, if not - why?

    What can I offer in return?

    Well, I'll just put it in bullets for you - saves us all some time, don't you think?

    • Provide a custom UI
    • More customization over more elements (i.e. Change background, font styles/colors etc)
    • Fun!
    • Something a bit more "up-to-date" looking.
    • I'll add feature requests as soon as I can - making your Pineapple even more awesome!
    • Anything else?

    Why trust me?

    Well, I've contributed to this forum on various occasions.

    • I took the time to have a bit of fun with the MK5 firmware and share it with you guys.
    • Contributed to the USB Rubber Ducky community (such as here, here and here)
    • I'm generally quick at replying to messages and requests
    • I can be really dedicated
    • I love web design! It's amazing how cross-platform HTML is and that it can run on so many devices!
    • I've worked with people on other projects, such as Pi-RC with Brandon Skari (here)

    I've written in HTML (duur), Javascript (duurr), CSS (duur), Python, PHP (of course), Batch, Bash, Visual Basic and a tiny bit of C (really tiny). I studied Networking Principals and Maintenance at college, too! I've even made my own robot before (not bragging or anything xD).

    This is my recent work for my Raspberry Pi project:

    AlienThemedUI.png

    Of course, I'm just asking for your opinions first - I would be utterly thankful if you decide to help me out here! I really want to develop for this awesome "toy" and contribute to you guys!

    Thank you for your time and patience, I appreciate every second spent. :smile:

  6. Hi!

    As the title says, would it be possible for someone to make an emulated Wi-Fi Pineapple web UI and upload it to a web server? The reason why I ask is because I still do not own a MKV (hoping to get one soon, heck - I've tried my luck with Hak5's Trivia questions, hoping that I could win a WiFi Pineapple, though I doubt that'll happen) and I think it would be awesome to see how the new UI performs.

    Personally, I would like to try the Pineapples' UI on my Nintendo 3DS (hacking from a 3DS - CUMON! THAT'LL BE AWESOME!), to see if it would work.

    Thanks! Hope I get a reply soon!

  7. DFU-PROGRAMMER for Windows!

    So,

    I've recently purchased a new laptop with is a 64 bit system, unlike my old 32 bit netbook which sadly died (it was a great netbook!). Anyway, that doesn't matter - what matters is that batchisp.exe always gave me errors (and I DID read the instructions and install all appropriate programs) such as:

    • Could not find AtJniIsp.dll
    • The program can't start because MSVCR71.dll is missing

    I finally gave up on Atmel's software and replaced it with DFU Programmer - which is far more reliable and easier to setup. I've modified the program.bat script to work with dfu-programmer, the results are fantastic.

    How to setup:

    Setting up is a breeze, just follow these steps:

    1. Download the package, which contains the needed files and drivers from here
    2. Extract the archive (I use 7-zip).
    3. Drag a .hex file over the program_dfu.bat program to flash the ducky while in DFU mode. Alternatively, run this command from cmd:

    program_dfu.bat firmware.hex

    Easy as 123! So, what do you think? Do you prefer to use Atmel's, time consuming, setup frustrating method or just use a simple, standalone program?

    Note: If you don't have the drivers installed for the ducky, refer to the official documentation - it's easy to install though!

  8. OK. Firstly for you to be able to run the encoder on an Android device, you would need to modify the code to comply with the Android Architecture. By default android is actually Java-based, so you can develop the encoder in a similar way, only you would need to modify the application to work with Android.

    As for multiple platforms, well, I think Java is closest to C in the respect that it is supported by so many operating systems. I know what you mean, though. Java is tragically slow in comparison, as it is partially interpreted as well as compiled. If it was compiled, it would be much quicker (while the notice to us mere mortals would be very small) and I believe a C compiled version would be much better as well. I don't do C code specifically, but I know it would be much better.

    Good Luck.

    Actually, think about it a little more deeply. Yes - Android is mostly Java, but don't forget that it's also Linux. If your device is rooted, you can place a binary in /system/xbin then just chmod it. This will allow you to run it from the Terminal Emulator. Look at Busybox for Android, I highly doupt it's written in Java. I think that to compile a binary for Android, you will need the NDK (or was it the ADK?) since it provides the ability to compile binaries for a device.

    On the other hand, as long as a compiler knows what architecture to compile for (such as Arm 7 Neon, for example), it should work.

    I don't want a program written in Java. If a duck encoder was written as a Java app for Android, you'd have a activity, a GUI etc. A CLI is most preferred. The dsploit team have managed to get the metasploit framework (msf) running on Android, which is mostly written in Ruby.

    I agree with you about the "Java vs C", Java's speed is noticeable in some cases, such as the fact that Java isn't quick enough to relay high volume's of traffic so it tends to drop packets. If you haven't checked out dsploits github repository, I highly recommend that you do. The issue in the repository named "Dsploit Core?" goes into detail about this stuff.

    Back on topic however, still would be great if someone ports the encoder to C. I think Androids fastboot utility is written in C and someone on xda developer's managed to compile it for Android so we were able to use fastboot in conjunction with USB OTG to flash other devices through the terminal emulator program.

    I do think it is possible to compile C as a binary for Android.

    Thank you for the response :)

  9. Another question! I pretty much hate the idea of using Java to use the encoder, sure it's multi platform but it doesn't support many platforms. I think it would be better if the encoder was written in C so that it can be compiled for pretty much any OS and architecture. I want to be able to compile it to run on android via the Terminal Emulator application.

    The only way to accomplish this (at least in my opinion) is to have the encoder as a single standalone binary that doesn't need 3rd party requirements.

    So, is this possible? Does anyone have the knowledge to pull this off? Or does anyone have any better ideas to make this dream become a reality?

    Thanks.

  10. U3 is pretty much dead so essentially pointless.

    The add-on board for the MKV could easily be a Rubber Ducky 2.0 (if designed right). I have a prototype "Ducky 2.0/Add-on board" using off the shelf components, it wouldn't be too hard to properly design this fit a USB drive form factor.

    First things first: the terrible "Ducky Script" language needs revisiting!

    Doesn't U3 still work though? If it does, it would save us from opening cmd and manually entering commands. How much do you think you've spent on making this "Ducky 2.0"? Do you plan on making it open-source?

    Would be great if I could make my own Ducky-like hardware. As for the ducky script, yes - I agree. I think ducky script would be better if it was written something like this:

    if ( Key.Pressed[CAPS_LOCK] == true ) {

    Key.Pressed[CAPS_LOCK] == false // Disable caps lock.

    String.Write(Hello, this is a string!)

    Key.Press[GUI + R]

    sleep 2

    String.Write(cmd.exe)

    Key.Press[ENTER]

    Key.Hold[CTRL+ALT+C] // Can't remember what key combo stopped UAC from appearing.

    }

  11. Was hoping for a simple explanation for how the WiFi Pineapple is made, but never mind. All I wanted to know is if Hak5 are simply getting a much of people to make these or if its a "one man show" sort of thing; or even mass produced by machines - didn't need anything technical.

    Oh well - curiosity doesn't always get you an answer I guess.

  12. I'm a curious person and so I am now wondering, how is the Pineapple made?

    Are they assembled by machines, a bunch of people, just one dude, what? How long does it take to manufacture one unit?

    Would be great if there was a "insides video" of the manufacturing process.

    Anyone got a answer?

    Thanks.

  13. Lavanoid, it's great to see your theme. It seems you've spent considerable time on this project and I commend you for your contribution. I know there will be some technical details which will need to be ironed out seeing as the interface is currently being changed for v1.5. I believe Seb will detail them soon. Until then I just wanted to say thank you for input on the UI. Cheers!

    Do you think Seb can "steal" some parts from my work and merge them with the update? I think he will mostly find the "statusbar_handler" to be useful as it contains the script that creates the CPU % usage output as well as the tidy Logged On Users output.

×
×
  • Create New...