Improve trampoline + put default vid + honour user specified eeprom size

This commit is contained in:
Bertold Van den Bergh 2021-08-04 17:56:41 +02:00
parent f36ab9c26c
commit b3722f7b20
3 changed files with 17 additions and 14 deletions

View file

@ -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."`

View file

@ -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 {

View file

@ -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
// PUSH R7
// MOV R0, #R0Value
// LJMP hookAddr
// 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
}