For starters, backpack and bags are handled differently. Your backpack items (24 slots) are stored alongside your gear, equipped bags, etc. These are stored in the form of a GUID and to gather any useful information you will have to obtain the address of the object associated with it. You can do so through the object manager.
You can read the item GUIDs contained in your backpack from your player's InvSlots array. This is a typical object field in BFA, and a descriptor in classic - see
here (Explanation of release info dumps).
Code:
public enum InventorySlot : byte {
// Equipment.
Head, Neck, Shoulders, Shirt,
Chest, Waist, Legs, Feet,
Wrists, Hands, Finger1, Finger2,
Trinket1, Trinket2, Back, MainHand,
OffHand, Ranged, Tabard,
// Bags, backpack, etc.
Bags = InventorySlotCount.Equipment,
Backpack = Bags + InventorySlotCount.Bags,
Bank = Backpack + InventorySlotCount.Backpack,
BankBags = Bank + InventorySlotCount.Bank,
BuyBack = BankBags + InventorySlotCount.BankBags,
#if WOW_RETAIL
ReagentBank = BuyBack + InventorySlotCount.BuyBack,
ChildEquipment = ReagentBank + InventorySlotCount.ReagentBank
#endif
}
For bags, you need to read the GUID of the bag from the player object (just as you would read items from your backpack, but using the 'Bags' index instead.) From there, get the object for that bag's GUID, and read the "Slots" array from it (again, typical object field in BFA, descriptor in classic.) These are also in the form of GUID, so you'll once again have to obtain the object address to gather anything useful.
Same goes for bank bags.
Let me know if you need any more info.