Skip to content

Commit

Permalink
Final Version
Browse files Browse the repository at this point in the history
  • Loading branch information
EliasKotlyar authored May 4, 2023
1 parent c67fbd4 commit b56eca4
Showing 1 changed file with 48 additions and 22 deletions.
70 changes: 48 additions & 22 deletions PatchBoostGauge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand All @@ -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))

0 comments on commit b56eca4

Please sign in to comment.