Exploit databaseDownload repository ZIP
GH-00acc2f4f084460752d9af64ad70a751
xcracker000/cve-2024-56426
Sources for CVE-2024-56426
2 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files2
xcracker000/cve-2024-56426Revision 7e2c12a3eafb
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
external/ghidra/ApplyLkPatches.java
Java · 5,215 bytes// Apply selected rows from an LK patch TSV to the current Ghidra program.
// @category Exynos9830
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressSet;
import ghidra.program.model.listing.Instruction;
import ghidra.program.model.listing.Listing;
import ghidra.program.disassemble.Disassembler;
import java.io.BufferedReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
public class ApplyLkPatches extends GhidraScript {
@Override
public void run() throws Exception {
String[] args = getScriptArgs();
if (args.length < 1) {
throw new IllegalArgumentException("usage: ApplyLkPatches.java <patch_tsv>");
}
Path patchPath = Paths.get(args[0]).toAbsolutePath().normalize();
Address base = currentProgram.getMinAddress();
Listing listing = currentProgram.getListing();
int applied = 0;
int skipped = 0;
int mismatches = 0;
int bytesPatched = 0;
AddressSet disassembleSet = new AddressSet();
int tx = currentProgram.startTransaction("Apply selected LK patches");
boolean commit = false;
try (BufferedReader reader = Files.newBufferedReader(patchPath)) {
String line;
int lineNo = 0;
while ((line = reader.readLine()) != null) {
lineNo++;
line = line.trim();
if (line.isEmpty() || line.startsWith("#")) {
continue;
}
String[] parts = line.split("\\|", 6);
if (parts.length < 4) {
printerr("Skipping malformed patch line " + lineNo + ": " + line);
skipped++;
continue;
}
if (!isEnabled(parts[0])) {
skipped++;
continue;
}
long offset = Long.decode(parts[1].trim());
byte[] oldBytes = fromHex(parts[2]);
byte[] newBytes = fromHex(parts[3]);
if (oldBytes.length != newBytes.length) {
throw new IllegalArgumentException("old/new length mismatch at line " + lineNo);
}
Address addr = base.add(offset);
Address endAddr = addr.add(newBytes.length - 1);
byte[] existing = new byte[oldBytes.length];
currentProgram.getMemory().getBytes(addr, existing);
if (!Arrays.equals(existing, oldBytes)) {
mismatches++;
println(String.format(
"warning: old bytes mismatch at 0x%X; applying selected patch anyway", offset));
}
clearOverlappingInstructions(listing, addr, endAddr, disassembleSet);
currentProgram.getMemory().setBytes(addr, newBytes);
applied++;
bytesPatched += newBytes.length;
println(String.format("applied 0x%X (%d bytes)", offset, newBytes.length));
monitor.checkCancelled();
}
if (!disassembleSet.isEmpty()) {
Disassembler disassembler = Disassembler.getDisassembler(currentProgram, monitor, null);
disassembler.disassemble(disassembleSet, disassembleSet, false);
}
commit = true;
}
finally {
currentProgram.endTransaction(tx, commit);
}
println(String.format(
"%s: applied=%d skipped=%d mismatches=%d bytes=%d",
currentProgram.getName(), applied, skipped, mismatches, bytesPatched));
}
private static boolean isEnabled(String value) {
String v = value.trim().toLowerCase();
return !(v.equals("0") || v.equals("false") || v.equals("no") || v.equals("disabled"));
}
private static byte[] fromHex(String value) {
String s = value.trim().replace(" ", "");
if ((s.length() & 1) != 0) {
throw new IllegalArgumentException("odd-length hex string");
}
byte[] out = new byte[s.length() / 2];
for (int i = 0; i < out.length; i++) {
out[i] = (byte) Integer.parseInt(s.substring(i * 2, i * 2 + 2), 16);
}
return out;
}
private void clearOverlappingInstructions(
Listing listing, Address startAddress, Address endAddress, AddressSet disassembleSet)
throws Exception {
Instruction instruction = listing.getInstructionContaining(startAddress);
if (instruction == null) {
instruction = listing.getInstructionAfter(startAddress);
}
while (instruction != null && instruction.getMinAddress().compareTo(endAddress) <= 0) {
Address clearStart = instruction.getMinAddress();
Address clearEnd = instruction.getMaxAddress();
listing.clearCodeUnits(clearStart, clearEnd, false, monitor);
disassembleSet.addRange(clearStart, clearEnd);
instruction = listing.getInstructionAfter(clearEnd);
}
}
}