Spacc BBS Spacc BBS
    • Categorie
    • Recenti
    • Tag
    • Popolare
    • Mondo
    • Utenti
    • Gruppi
    • Registrati
    • Accedi
    La nuova BBS è in fase Alpha. I post precedenti al 22 luglio 2024 potrebbero non essere trasferibili, ma rimarranno disponibili per la lettura su /old/.

    @blinry tried to teach me some binary from scratch, which worked pretty well, but now I'm stuck.

    Pianificato Fissato Bloccato Spostato Uncategorized
    fedihelpaskfedi
    9 Post 1 Autori 0 Visualizzazioni
    Caricamento altri post
    • Da Vecchi a Nuovi
    • Da Nuovi a Vecchi
    • Più Voti
    Rispondi
    • Topic risposta
    Effettua l'accesso per rispondere
    Questa discussione è stata eliminata. Solo gli utenti con diritti di gestione possono vederla.
    • piko@chaos.socialP Questo utente è esterno a questo forum
      piko@chaos.social
      ultima modifica di

      @blinry tried to teach me some binary from scratch, which worked pretty well, but now I'm stuck. I have two versions of a program, one works, one doesn't, and I can't figure out why...
      I marked the differences of the two with yellow circles.
      #fedihelp #askfedi

      piko@chaos.socialP 1 Risposta Ultima Risposta Rispondi Cita 1 0
      • piko@chaos.socialP Questo utente è esterno a questo forum
        piko@chaos.social @piko@chaos.social
        ultima modifica di

        As I can't add binary files to posts, you get the hex dump of the working file here :>
        454c4602010103000000000000000002003e000100000082000100000000004000000000000000000000000000000000000000400038000100400000000000010000000500000078000000000000007800010000000000deadbeefc0ffee992c000000000000002c00000000000000000000000000000048454c4c20574f524c44b801000000bf01000000be78000100ba0a0000000f05b83c000000bf2a0000000f05

        piko@chaos.socialP 1 Risposta Ultima Risposta Rispondi Cita 0
        • piko@chaos.socialP Questo utente è esterno a questo forum
          piko@chaos.social @piko@chaos.social
          ultima modifica di

          The three differences pertain to the amount of data which gets loaded into memory.

          The first one (broken 0a... vs. working 82...) are the address in RAM, where the program starts. In the working version, this is 0x10082 (we're little endian, so 82-00-01 gets converted to 01-00-82), so if we would put the whole program on the address 1-00-00, then the first command of the program (directly after the faultless and accurate string we want to print) starts on position 1-00-82.

          piko@chaos.socialP 1 Risposta Ultima Risposta Rispondi Cita 1 0
          • piko@chaos.socialP Questo utente è esterno a questo forum
            piko@chaos.social @piko@chaos.social
            ultima modifica di

            The last post was a little misleading; we actually don't put the whole program at 1-00-00, we only put the part after the program header table (the computer knows that this table ends in the middle of line "70" (where the green "4845 4c4c ..." starts)) at the position we indicate in the second yellow circle. As every line is 16 bytes long, the middle of line "70" is position 78.

            piko@chaos.socialP 1 Risposta Ultima Risposta Rispondi Cita 0
            • piko@chaos.socialP Questo utente è esterno a questo forum
              piko@chaos.social @piko@chaos.social
              ultima modifica di

              The "78" in the second yellow circle is the place to which we copy the whole interesting part (the string data (the green "4845...") and after that the commands). It's convenient that this is the same number as the relative start of the interesting part in our little hex dump, because then every other position in the program also matches. This means we can rely on the loaded data also starting at 78, which we actually do in the third yellow circle:

              piko@chaos.socialP 1 Risposta Ultima Risposta Rispondi Cita 0
              • piko@chaos.socialP Questo utente è esterno a questo forum
                piko@chaos.social @piko@chaos.social
                ultima modifica di

                There we say "fetch the data from position 78" with the bytes "be".

                piko@chaos.socialP 1 Risposta Ultima Risposta Rispondi Cita 0
                • piko@chaos.socialP Questo utente è esterno a questo forum
                  piko@chaos.social @piko@chaos.social
                  ultima modifica di

                  (Actually I still simplyfied a bit, because I omitted the 00 01 after the three marked bytes. As I mentioned earier, "82-00-01-00" actually means "00-01-00-82", or 10082. So the numbers aren't 82 and 78, but 10082 and 10078, (and even actuallier 0x10082 and 0x10078, but please ignore this if you don't immediatly recognize it). So we put the stuff not in position 78, but in position 10078, but the math still works out, it's just 10000 positions later.)

                  piko@chaos.socialP 1 Risposta Ultima Risposta Rispondi Cita 0
                  • piko@chaos.socialP Questo utente è esterno a questo forum
                    piko@chaos.social @piko@chaos.social
                    ultima modifica di

                    Soooo, this is how the working one works. But how does the not working one *not* work?
                    Let's start with the second yellow circle: Here's a 00 where we had a 78. So we put the interesting part (string data + commands) at position 00 (or more precisely 1-00-00 instead of 1-00-78) in the RAM. This means the green "4845 ..." starts at 1-00-00. The first command (the red "b801 ..." after the data) is ten positions after that, which is "0a" in hexadecimal. Oh look, it's the first yellow circle!

                    piko@chaos.socialP 1 Risposta Ultima Risposta Rispondi Cita 1 0
                    • piko@chaos.socialP Questo utente è esterno a questo forum
                      piko@chaos.social @piko@chaos.social
                      ultima modifica di

                      And that's good, because the first yellow circle tells the computer where in RAM to look for the commands. So if we put our data at 00, we have the commands at 0a. Or, if we put it at 1-00-00, we have it at 1-00-0a, which is what actually happens.

                      So everything should work as before, just in RAM 78 positions earlier... But it doesn't :(
                      Please tell me what I missed!

                      1 Risposta Ultima Risposta Rispondi Cita 1 0
                      • gustavinobevilacqua@mastodon.cisti.orgG gustavinobevilacqua@mastodon.cisti.org shared this topic on
                      • Primo post
                        Ultimo post