I can only really talk about Ohio machines & ballots, but how it works here is that the ballots are unique per precinct (local tax issues, local candidates, etc), and the machines will work on any ballot in the county (you can see this if you early vote at the Board of Elections).
You can look at your local ballots prior to an election. For example, if you go here:
you can see a Van Wert county approved sample ballot (note the BOE signatures)
The machines are general purpose, purchased by the state & "programmed" by the county for the local ballots. "Programming" is done using the machine vendor's software, not actually code writing. Ballot design is agreed upon by Republican & Democratic election reps. Because the machines are general purpose, they are looking in a location on the ballot to be darkened, that location is programmed to equal a vote, and the location is assigned to a candidate in the voting machines database, it doesn't really read the candidates name.
Kind of like the old scantron tests, the grader didn't know the answers, it only knew what space it had been told was the correct answer.
In theory, a machine could be manipulated, but the ballots are kept as a paper trail, because a person hand counting them knows how to identify a correct vote. Ballot scanners have no network radios in them and are never connected to a network.
County voting systems are tested by a federally accredited testing laboratory and certified by the U.S. Election Assistance Commission. The certification program tests a voting system against federal performance and security standards.
Prior to an election machines programmed for the county basically run an election with all sample ballots, that's what I mean that quality assurance failed.
There is a whole procedure to open a precinct for voting & the machines are never left unlocked while unattended, they ship to the locations in locked cages, return to the county in locked cages, votes on the machines are recorded on removable storage, the removable storage and paper ballots are delivered by hand to the county board. The removable storage is shipped to and from the precinct separated from the machines. Each machine is stored in a bag locked with tamper proof seals. The tamper proof seal number are recorded at opening and resealing.
Data stored on the removable storage is encrypted. Removable storage is assigned to a specific ballot scanner. If the machine detects a different memory device, the machine will not accept ballots.
Results released on election night are not official election results. The day after the election, all memory devices are re-uploaded. This process starts the official election results process.