Fracture

Theodore "Ted" Crawford (Anthony Hopkins), a wealthy and talented Irish aeronautical engineer in Los Angeles, discovers that his wife Jennifer (Embeth Davidtz) is having an affair with police detective Robert Nunally (Billy Burke). After confronting his wife, Crawford shoots her, seriously wounding her, and immediately confesses the crime to Nunally at the scene.
He then engages in a battle of wits with rising star deputy district attorney William "Willy" Beachum (Ryan Gosling), who considers this an open-and-shut matter and agrees to go to trial immediately. Beachum is busy, making preparations for his transition from criminal law to corporate attorney for Wooton &amp; Simms, a well-known law firm, and begins a romantic relationship with his future boss, Nikki Gardner (Rosamund Pike).
At the trial, Crawford acts as his own attorney, thereby matching up a star prosecutor against a supposedly untrained litigant. Crawford reveals that the arresting officer (Nunally) was having an affair with his wife, assaulted him during his arrest, and was present during his interrogation. Crawford's confession is ruled to be inadmissible as evidence, as it was fruit of the poisonous tree. Beachum discovers that Crawford's handgun was not used to shoot his wife because it had never been fired and did not match the shell casings at the crime scene. As the house was under surveillance the entire time from the shooting to Crawford's arrest, the police are baffled.
Beachum is tempted by Nunally's scheme to plant false evidence to implicate Crawford but decides against it at the last minute. With no new evidence to present to the jury, Beachum is forced to concede the trial, and Crawford is acquitted. The disgraced Nunally commits suicide outside the courtroom.
After the trial, Beachum's future with the prestigious firm is in tatters. However, he also begins to see his job as a D.A. as a means of fighting injustice for those like Crawford's wife. Crawford himself observes this change, joking scathingly that Beachum has "found God". This motivates Beachum to continue searching for evidence almost obsessively. Realizing that Crawford's plan is to dispose of the only eyewitness to the crime, Beachum goes to great lengths to get a court order to keep Jennifer on life support. Beachum obtains a court order and arrives at the hospital but is unable to prevent staff turning off Jennifer's life support.
A mix-up of cell phones causes Beachum to realize that both Nunally and Crawford used the same type of gun, a .45 caliber Glock 21. He figures out that before the crime Crawford switched his gun with Nunally's in a hotel room where Jennifer and Nunally secretly met. Crawford shot his wife with Nunally's gun, and then reloaded it. The detective arrived on the scene carrying Crawford's gun, and both Crawford and Nunally laid their weapons down as a preliminary move in hostage negotiations. When Nunally becomes aware of who the shooting victim is, and tries to revive Jennifer, Crawford switches the guns, retrieving his own unused gun. When Crawford appears in the room brandishing his gun, Nunally tackles and assaults him before Crawford's arrest. Nunally unwittingly holsters the murder weapon, letting the unused gun be taken as evidence.
Beachum confronts Crawford with his new evidence. Since she has now died, the bullet lodged in Jennifer's head can now be retrieved and matched with Nunally's gun. Crawford confesses, assuming himself to be protected under the Double Jeopardy Clause. However, Beachum reveals that by allowing his wife to die, Crawford can now be prosecuted for murder, having previously been tried merely for attempted murder. Since he had taken Jennifer off life support, new charges can be filed against Crawford and a new trial can be set. Crawford is arrested by the waiting police.
The film ends with a new trial about to begin, with Beachum prosecuting and Crawford surrounded by a group of high-priced defense attorneys.

Question: Who switched the guns?
Answer: Crawford