r/programmingquestions • u/edg73018 • Jul 22 '20
Basic Question from a Dummy
Hi! I have a couple really basic questions which obviously come from someone with no programming knowledge.
1) Is there a conceivable way that the code from two different programs could become jumbled together?
2) If so, how might this happen?
3) Would it be possible for a programmer to go back in and identify which pieces of code came from which original program?
2
Upvotes
View all comments
Show parent comment
1
u/denzien Jul 28 '20
Storage drives all use some kind of file table to tell the computer exactly where on the drive a file lives (this is a numeric address, not a folder structure ... this is all math), and how big it is. Sometimes that file is fragmented and requires multiple entries, each of their own size, that must be read in the proper order to get the entire file.
You might consider causing this table to become corrupted, which would cause the computer to load files from disk incorrectly - missing parts of the original file, including parts of other files, rearranging fragments of the original file ... pretty much whatever. All scrambled up.
I haven't studied binaries in a long time, but IIRC, application code uses 'pointers' to tell the computer where the next instruction is. This is relative to the beginning of the file, so if the file was read from disk in the wrong order, these pointers will point to the wrong part of the file. It would be a stroke of luck if this sort of thing actually successfully fired off some random subroutine, but I doubt that level of realism really matters.
So, assuming the actual data was not corrupted (like if the file table existed on a separate device from the actual data, I suppose. You know - for security because if anyone stole the contents of the drive it would be worthless without the table?), your characters actually have a chance to restore the system to proper working order if that's what you want them to do.
To fix it, I would probably start by looking for a backup of the file tables (if it even makes sense to have that, if you pursue the security idea) - but that might only get me 70% there because data gets moved around, or new versions of a file are installed and it has a different length, or any number of reasons.
Performing some digital forensics might be the next step, analyzing the actual bytes on disk, looking for file boundaries and "magic bytes" to identify the type of the file.
Visualizations of the data disk would probably include scoring every block on disk with an entropy score (randomness) and a text score (mostly just characters within a narrow range, with lots of repetition). This would help the characters attempt to determine what sort of data is on disk, and what pieces are likely to go together. This is a *little* far fetched, but usually if you see a block (chunk of contiguous data on a disk) with a high text score next to a block with a high entropy score, that kind of looks like a file boundary.
They could then either rebuild the file table or construct a new one. Manipulating this file table would also allow one to hide files that still exist, by "deleting" them, if maybe there's some kind of coverup going on.
And then you could research slack space and shadow file systems! But that's probably going too far. Sorry for rambling.