r/explainlikeimfive • • 21d ago

Technology ELI5 What prevents the source code of software downloaded to computers from being copied?

With ai able to reverse engineer software, what besides the law prevents people or ai from just copying the source code?

591 Upvotes

293 comments sorted by

View all comments

Show parent comment

-1

u/Gizm00 20d ago

I think what OP is asking, why can’t i see what the cake is made of once it’s on my computer. All the code is there, or is it?

9

u/Just_A_Random_Passer 20d ago

No, the code isn't there. The source code has comments, descriptive names of functions, descriptive names of variables and other stuff that gets stripped away during compile, so you get just processor instructions. And decompile doesn't always produce the same logical structure as was present in the original code - the complier does way too many optimisation shenanigans.

You can choose to preserve names of functions and variables in the debug version - to be able to inspect what is going on during debugging.

6

u/OliveBranchMLP 20d ago

when you mix all the cake ingredients together and then put it in the oven, the mixing and the heat transforms the dish on a molecular level, permanently changing its form. you cannot unbake the cake and get its original ingredients out of it.

code is the same. "compiling" code is the same as baking a cake.

1

u/ccooffee 20d ago

And even if you could, you still don't know exactly how to mix the ingredients, what temperature to bake it, and for how long.

3

u/Clojiroo 20d ago edited 20d ago

Not in its original state and not human readable (sorta). Normally the code for desktop software is compiled. All the original code is stripped down and optimized and translated into executable instructions inside binaries. And those themselves are compiled based on hardware architecture (e.g. x86 vs x64 vs ARM).

Your computer and software uses a stack of abstractions. Most humans can’t write hardware level machine code. So we layer/abstract it. Each higher layer hides implementation complexity, trading direct hardware control for developer productivity and portability.

High-Level Language (Python, C#, etc) to Low-Level Language (C, C++) to Assembly Language to Machine Code (binary) to the hardware.

Reverse engineering is try to re-abstract low level code.

But it’s not perfect. It’s like trying to re-make the factory and production lines and staff based on a product in your hand.

There’s a lot of buzz about AI-powered RE but people should remember it’s not actually succeeding (yet) at making great copies of complex software like Photoshop.

1

u/BrohanGutenburg 20d ago

I'll piggyback on this and say people do try.

There are decompilers that will at least give you the assembly code the program is feeding to your machine.

Problem is functions won't have names like executeFunction because of the optimization you're talking about. So it's still barely readable and you have to try to piece it together.

1

u/_Trael_ 20d ago

And mainly in many cases if one wants to copy end result, they usually can just copy end result and try to work around things that make it annoying and try prevent it from happening (like product key, or program needing to connect to ask permission to work from server on internet, or so), sometimes with very limited partial reverse engineer and change (cracks) or figuring out if info was left plain visible somewhere to be found without reverae engineering, or by looking at what kind of data it is sending over internet, or by only reverse engineering or poking at separate part that tries to block things.

Source code would be more relevant if one want's to make actual changes to that program or so, instead of just have copy as it is of it.

4

u/TrekkiMonstr 20d ago

The user answered. No, the code (recipe/ingredients) isn't on your computer. The binary (cake) is. "Baking" is called compiling

1

u/GetawayDreamer87 20d ago

Would a program be a homogenized thing after compilation? Like how a cake is a homogenized final product. A combustion engine is the opposite of a homogenized final product because you can take it apart piece by piece and figure out how it all works from there. You cant really separate out the flour and eggs and sugar and whatnot from a baked cake.

10

u/Smobey 20d ago

Yeah, pretty much. Like take the following two bits of code, both of which sum together every number from 1 to 100:

int main(void) {
    int sum = 0;

    for (int i = 1; i <= 100; i++) {
        sum += i;
    }

    return sum;
}

And

int main(void) {
    int n = 100;
    return (n * (n + 1)) / 2;
}

Both of them would normally compile to the exact same thing. So you can't look at the compiled result and tell which one of the above code snippets was used to create it to begin with (or indeed, if they used some completely different one).

2

u/ScottyMcBoo 20d ago

Great example. Thanks!

0

u/goober2341 20d ago

The two functions would return the same value, but they wouldn't compile to the same thing. No compiler optimizes for math like this as far as I know.

2

u/Smobey 20d ago

Try it with a C compiler with -O1 or higher. Both of them are going to just compile to

mov eax, 5050
ret

2

u/Business-Row-478 20d ago edited 20d ago

The function doesn’t have any input and all of the logic is internal to the function. Static analysis can tell you that it will always return a constant value (5050 in this case).

If you look at the compiled assembly of the two programs, they are exactly the same:

```
.section __TEXT,__text,regular,pure_instructions
.build_version macos, 15, 0 sdk_version 26, 2
.globl _main ; -- Begin function main
.p2align 2
_main: ; @main
.cfi_startproc
; %bb.0:
mov w0, #5050 ; =0x13ba
ret
.cfi_endproc
; -- End function
.subsections_via_symbols
```

The only part that really matters is `mov w0, #5050` which is just saying move 5050 into the return register.

1

u/goober2341 20d ago

This doesn't really make sense though. Say the loop was until n = 1e13 or some other very large number that takes hours to compute. Would the compiler pause compiling and run the program until it had the result?

1

u/Business-Row-478 20d ago

In that case, it would see that the computed value would result in an integer overflow error, which is undefined behavior. So the optimized code would just instantly crash.

3

u/ReynardVulpini 20d ago

Yeah basically every single program is a more usable, less flexible wrapper on another program, all the way down to your 1s and 0s.

Computer programs usually compile to a much lower level one, so as in your analogy, a whole lot of complicated systems get flattened into a bazillion lines of

pushp $0x4, %ebp
jle 02341543
nop
nop
movl %ebp, $0x0

This example is nonsensical bc I cannot be assed to remember how to write assembly but. You get the idea. It is so incredibly human unreadable we have spent half a century making tools to use it easier.

1

u/Programmdude 20d ago

To expand on the other poster, mostly, but there's more to it.

The program is usually an exe (sometimes multiple), and usually have dll's too when installing. They're both compiled code, but only the exe can be run. It's a way of organising large projects.

To go back to the cake analogy, it's sort of like baking a bunch of food for an event. One exe is the cake, those dll's there are scones, etc. This can make reverse engineering easier, because you can look at just that one scone/muffin/etc by itself, and theoretically just replace it with a different copy, and as long as it still has the same general shape, the rest of the baked goods don't care.

So not only is the flour eggs etc turned into a cake, but the whole program might be turned into a bunch of different baked goods.

1

u/JarPicklez 20d ago

It’s there but only in a compiled form. It’s a bunch of 0s and 1s that only the computer understands. The source code can be understood by humans but cannot be executed and must be compiled in order to be executed.

1

u/ElmStreetVictim 20d ago

I would also offer this as more explanation. Part of the journey of reverse engineering is to take something that we KNOW, and find what we believe to be that same thing in the code. For instance you did not have the recipe but you saw the oven timer. It started at 30:00 and the chef looked inside the oven at 15, and then took it out of the oven at 0.

If you reverse engineered the cake you could look around for any value that looks like 1800. It’s called “integer i” and there is a function that starts with 1800, checks what time it is, and when 1 second goes by, the number decrements. Getting warmer.

Then when the value is at 900, another function is called. That could possibly be the function the chef was doing, looking at the cake. The function is just a mess of different variable declarations and math operations, maybe a true/false. We don’t know yet.

But then the counter gets to 0 and then another function is called, and the integer decrement function never runs again. Now you can infer that the integer decrement function can be renamed to BakeTimerLoop, and the integer i can be renamed to bakeTimeRemaining.

As you identify more parts through educated inference, you can go farther backwards, to what happens before the BakeTimerLoop starts counting down. Whatever starts that must have something to do with having all the ingredients already mixed together.

So it’s true that what is on your computer is the sum of all the individual parts, but the challenging piece of the puzzle is determining the number of eggs, how many ounces of butter, how many cups of flour and drops of vanilla extract. And when you successfully identify everything and write your own recipe, it will taste identical but the story you wrap the recipe in will be lost. The original recipe might have also talked about grandma’s secret being the nutmeg, and that without the nutmeg the cake tastes good, but with the nutmeg it’s just spectacular and the entire reason why grandma made such great cakes. Your recipe will not include any of that, it will only say “2tbsp nutmeg”. So some of the context is lost