mirror of
https://github.com/BertoldVdb/ms-tools.git
synced 2025-12-10 07:44:46 +01:00
Improve trampoline + put default vid + honour user specified eeprom size
This commit is contained in:
parent
f36ab9c26c
commit
b3722f7b20
3 changed files with 17 additions and 14 deletions
|
|
@ -15,7 +15,7 @@ type Context struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var CLI struct {
|
var CLI struct {
|
||||||
VID int `optional type:"hex" help:"The USB Vendor ID."`
|
VID int `optional type:"hex" help:"The USB Vendor ID." default:534d`
|
||||||
PID int `optional type:"hex" help:"The USB Product ID."`
|
PID int `optional type:"hex" help:"The USB Product ID."`
|
||||||
Serial string `optional help:"The USB Serial."`
|
Serial string `optional help:"The USB Serial."`
|
||||||
RawPath string `optional help:"The USB Device Path."`
|
RawPath string `optional help:"The USB Device Path."`
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,8 @@ func New(dev *hid.Device, config HALConfig) (*HAL, error) {
|
||||||
h.patchInstalled = true
|
h.patchInstalled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h.eepromSize = config.EEPromSize
|
||||||
|
|
||||||
if h.eepromSize == 0 && config.PatchProbeEEPROM {
|
if h.eepromSize == 0 && config.PatchProbeEEPROM {
|
||||||
h.eepromSize, err = h.patchEepromDetectSize()
|
h.eepromSize, err = h.patchEepromDetectSize()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -42,25 +42,25 @@ func (h *HAL) patchWriteWithRET(region MemoryRegion, addr int, data []byte) erro
|
||||||
}
|
}
|
||||||
|
|
||||||
func patchTrampolineEncode(orig []byte, origAddr int, R0Value byte, hookAddr int) []byte {
|
func patchTrampolineEncode(orig []byte, origAddr int, R0Value byte, hookAddr int) []byte {
|
||||||
// ...orig...
|
// PUSH R7
|
||||||
// LCALL origAddr
|
// MOV R0, #R0Value
|
||||||
// MOV R0, #R0Value
|
// LCALL hookAddr
|
||||||
// LJMP hookAddr
|
// POP R7
|
||||||
|
// ...orig... -> If this returns there will be no jump to origAddr, which is what we want.
|
||||||
|
// LJMP origAddr
|
||||||
|
|
||||||
trampolineOrig := []byte{
|
result := []byte{
|
||||||
0x12, byte(origAddr >> 8), byte(origAddr),
|
0xC0, 0x7,
|
||||||
}
|
|
||||||
|
|
||||||
trampolineHook := []byte{
|
|
||||||
0x78, R0Value,
|
0x78, R0Value,
|
||||||
0x02, byte(hookAddr >> 8), byte(hookAddr),
|
0x12, byte(hookAddr >> 8), byte(hookAddr),
|
||||||
|
0xD0, 0x7,
|
||||||
}
|
}
|
||||||
|
|
||||||
result := orig
|
result = append(result, orig...)
|
||||||
|
|
||||||
if origAddr != 0 {
|
if origAddr != 0 {
|
||||||
result = append(result, trampolineOrig...)
|
result = append(result, []byte{0x02, byte(origAddr >> 8), byte(origAddr)}...)
|
||||||
}
|
}
|
||||||
result = append(result, trampolineHook...)
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
@ -299,6 +299,7 @@ func (h *HAL) patchInitAlloc(userConfig MemoryRegion) (bool, error) {
|
||||||
_, userOffset := RecursiveGetParentAddress(userConfig, userConfig.GetLength())
|
_, userOffset := RecursiveGetParentAddress(userConfig, userConfig.GetLength())
|
||||||
|
|
||||||
h.patchAllocAddr = userOffset + userCodeLen
|
h.patchAllocAddr = userOffset + userCodeLen
|
||||||
|
|
||||||
return userCodePresent, nil
|
return userCodePresent, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue