From b56eca4a10d0858db5103e8d4e7cc236e211aa84 Mon Sep 17 00:00:00 2001 From: Elias Kotlyar Date: Thu, 4 May 2023 17:51:29 +0200 Subject: [PATCH] Final Version --- PatchBoostGauge.py | 70 +++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/PatchBoostGauge.py b/PatchBoostGauge.py index 943c29c..1f31805 100644 --- a/PatchBoostGauge.py +++ b/PatchBoostGauge.py @@ -19,46 +19,74 @@ def compileList(cmdList,address): asm.assemble(toAddr(currentAddress),cmd) currentAddress = currentAddress +4 +def relativeAddress(address): + return hex(address - 0x7ffff0)+"(r13)" + asm = ghidra.app.plugin.assembler.Assemblers.getAssembler(currentProgram); # Enable Boost Gauge: - ADDRESS_CWLDANZ = 0x1C6338 ADDRESS_CWLDANZ = ADDRESS_CWLDANZ + 0x400000 setByte(toAddr(ADDRESS_CWLDANZ),0x01) createLabel(toAddr(ADDRESS_CWLDANZ), "CWLDANZ", True) - +# Can Byte: +canByte5Addr = 0x8043c0 +createLabel(toAddr(canByte5Addr), "mot7byte5", True) +# Absolute Pressure: +absolutePressure = 0x7fc99a +createLabel(toAddr(absolutePressure), "absolutePressure", True) # Section where new Code will be saved: sectionAddress1 = 0x47D000 -sectionAddress2 = 0x47D100 # Original Call Code: -canByte5Addr = 0x8043c0 -relativeAddress = canByte5Addr - 0x7ffff0 + + # Section 1: section1CmdList = [ - # Load 0x1 into R12 Register - "li r12,0x1", - # Store R12 in CANByte5 Adress: - "stb r12,"+hex(relativeAddress)+"(r13)", - # Original Function Call: - "li r3,0x8", - "bl 0x004e8ff4", -] -compileList(createFunction(section1CmdList),sectionAddress1) + # Loading Absolute Pressure in R4 + "lhz r12,"+relativeAddress(absolutePressure), + # Load 0x8000 in R11: + "lis r11, 0x0", + "ori r11,r11, 0x8000", + # Compare R11 with R4: + "cmpw r11,r12", + # If bigger, jump to location: + "bgt 0x47D030", + + # IF smaller than 0x8000 + # Byteshift 8 times + "srawi r12,r12,8", + # Multiply with 100 + "li r11, 200", + "mullw r12,r12,r11", + "b 0x47D03C", -# Section 2: -section2CmdList = [ - # Load 0x2 into R12 Register - "li r12,0x2", + + # If bigger: + # Byteshift 7 times + "srawi r12,r12,7", + # Multiply with 100 + "li r11, 100", + "mullw r12,r12,r11", + + + # Divide Result by 10 + "li r11, 10", + "divw r12,r12,r11", + # Divide by 20 + "li r11, 20", + "divw r12,r12,r11", + + + # Store R12 in CANByte5 Adress: - "stb r12,"+hex(relativeAddress)+"(r13)", + "stb r12,"+relativeAddress(canByte5Addr), # Original Function Call: "li r3,0x8", "bl 0x004e8ff4", ] -compileList(createFunction(section2CmdList),sectionAddress2) +compileList(createFunction(section1CmdList),sectionAddress1) @@ -67,5 +95,3 @@ def compileList(cmdList,address): rewriteAddr = 0x503a98 asm.assemble(toAddr(rewriteAddr),"bl "+hex(sectionAddress1)) -rewriteAddr = 0x573590 -asm.assemble(toAddr(rewriteAddr),"bl "+hex(sectionAddress2))