If you buy the stock on Ex-date then you will not be eligible for the buyback because the stock will not be in your Demat account on Record date(next day). The last day to buy stocks before any corporate action is the day before the Ex-date, as it takes T+2 days for stocks to reach Demat.
Assuming you have stocks in Demat as of Record date, then you have already received your eligibility ticket for the buyback. Now you can trade the shares if you please and you have to only ensure to buy it back and keep it in your Demat before you tender the shares before the buyback window closes.