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 {
|
||||
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."`
|
||||
Serial string `optional help:"The USB Serial."`
|
||||
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.eepromSize = config.EEPromSize
|
||||
|
||||
if h.eepromSize == 0 && config.PatchProbeEEPROM {
|
||||
h.eepromSize, err = h.patchEepromDetectSize()
|
||||
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 {
|
||||
// ...orig...
|
||||
// LCALL origAddr
|
||||
// MOV R0, #R0Value
|
||||
// LJMP hookAddr
|
||||
// PUSH R7
|
||||
// MOV R0, #R0Value
|
||||
// LCALL hookAddr
|
||||
// POP R7
|
||||
// ...orig... -> If this returns there will be no jump to origAddr, which is what we want.
|
||||
// LJMP origAddr
|
||||
|
||||
trampolineOrig := []byte{
|
||||
0x12, byte(origAddr >> 8), byte(origAddr),
|
||||
}
|
||||
|
||||
trampolineHook := []byte{
|
||||
result := []byte{
|
||||
0xC0, 0x7,
|
||||
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 {
|
||||
result = append(result, trampolineOrig...)
|
||||
result = append(result, []byte{0x02, byte(origAddr >> 8), byte(origAddr)}...)
|
||||
}
|
||||
result = append(result, trampolineHook...)
|
||||
|
||||
return result
|
||||
}
|
||||
|
|
@ -299,6 +299,7 @@ func (h *HAL) patchInitAlloc(userConfig MemoryRegion) (bool, error) {
|
|||
_, userOffset := RecursiveGetParentAddress(userConfig, userConfig.GetLength())
|
||||
|
||||
h.patchAllocAddr = userOffset + userCodeLen
|
||||
|
||||
return userCodePresent, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue