NishanthMenon changed the topic of #openocd to: this is the place to discuss all things OpenOCD | Logs: https://libera.irclog.whitequark.org/openocd/
shoragan has quit [Ping timeout: 272 seconds]
shoragan has joined #openocd
tsal has quit [Ping timeout: 272 seconds]
tsal has joined #openocd
thinkfat has joined #openocd
thinkfat_ has quit [Ping timeout: 272 seconds]
crabbedhaloablut has quit [Quit: No Ping reply in 180 seconds.]
crabbedhaloablut has joined #openocd
nerozero has joined #openocd
crabbedhaloablut has quit [Remote host closed the connection]
crabbedhaloablut has joined #openocd
renrelkha has quit [Quit: bye]
renrelkha has joined #openocd
Hawk777 has quit [Quit: Leaving.]
Haohmaru has joined #openocd
Bugies has joined #openocd
akaWolf has quit [Ping timeout: 252 seconds]
akaWolf has joined #openocd
braunr has quit [Ping timeout: 276 seconds]
braunr has joined #openocd
bencoh has quit [Ping timeout: 255 seconds]
bencoh has joined #openocd
BlackMage has joined #openocd
bencoh has joined #openocd
bencoh has quit [Changing host]
BlackMage has quit [Quit: Client closed]
crabbedhaloablut has quit [Ping timeout: 268 seconds]
crabbedhaloablut has joined #openocd
wingsorc has quit [Quit: Leaving]
crabbedhaloablut has quit [Remote host closed the connection]
crabbedhaloablut has joined #openocd
nikomo has quit [Ping timeout: 264 seconds]
nikomo has joined #openocd
wingsorc has joined #openocd
crabbedhaloablut has quit [Remote host closed the connection]
crabbedhaloablut has joined #openocd
wolfshappen has quit [Quit: later]
wolfshappen has joined #openocd
Haohmaru has quit [Remote host closed the connection]
crabbedhaloablut has quit [Ping timeout: 268 seconds]
crabbedhaloablut has joined #openocd
wolfshappen has quit [Ping timeout: 252 seconds]
wolfshappen has joined #openocd
wolfshappen has quit [Ping timeout: 268 seconds]
wolfshappen has joined #openocd
wolfshappen has quit [Quit: later]
wolfshappen has joined #openocd
Guest0 has joined #openocd
<Guest0> hello!
<Guest0> I entered this command on telnet but there is no flashdump.bin file in my computer... so where does this file stored?
<Guest0> > halt; dump_image flashdump.bin 0x00000000 0x200000
<Guest0> dumped 2097152 bytes in 19.743622s (103.730 KiB/s)
<Guest0> oh, ok i found it. it was under: /usr/share/openocd/scripts
<Guest0> ok one more question :)  does this article help us to dump the flash memory or firmware (software source codes) ?
<Guest0> i can see the values in variables i defined, in flashdump.bin file; however I can not see the function names and passed parameters. how can i see the passed parameter value to my function?
<braunr> it's only the binary result
<braunr> unless it's an interpreted script, you cannot "dump source code"
<Guest0> binary of what? of the flash memory?
<braunr> of the compilation
Guest0 has quit [Quit: Client closed]
Guest0 has joined #openocd
<braunr> mhm
<braunr> Guest0: ah, welcome back
<Guest0> umm, so it is a similar output of compiled source code? so is it an ASM dump?
<Guest0> sorry for connection lost :)
<braunr> yes but in raw binary form
<Xogium> you cannot see source code of programs, since that doesn't get flashed... You can only see the binary
<braunr> Xogium: oh hey :)
<braunr> modern programs are built in a complex format with different areas
<Guest0> aha, thank you! if it is the ASM dump, so how can I dump the flash memory or RAM memory?
<Xogium> its not asm
<braunr> one for the code, one for the data, one for debugging symbols, etc..
<braunr> like ELF
<braunr> but a raw binary program is the most simple form of machine code (not ASM actually) there can be
<braunr> it's just the sequential data that a processor can process
<Xogium> yep, 0's and 1's all over the place
<Guest0> ahh okay, it is not ASM or source code; it is just a basic form of things to execute o.O
<braunr> and not indication of what it actually is, you have to infer it all by yourself
<braunr> machine code in raw sequential form, yes
<Guest0> <3
<Guest0> so, how can I read the flash memory or RAM memory? because I want to see the value I passed as a parameter to a function...
<Xogium> ELFs can't get flashed directly though, right ? That's why there's the ELF file and the bin file
<braunr> your question doesn't make sense
<braunr> the dump in your article correctly describes how to read flash or ram
<braunr> but that doesn't allow you to know the parameters passed to a function
<braunr> not directly, and doing it from that is hard
<braunr> if you want to debug a program in binary form, it's best if you have the complex form (on linux, ELF), and of course the source code
<braunr> you could then set a break point on that function, and let the debugger show you the parameters
<braunr> assuming optimizations still allow it
<Xogium> I actually don't see how you could do this. Gdb, maybe ? Hmm. I only ever used openocd to try to debug a hung kernel on cortex-a and it turns out it wasn't even something gdb could have told me. Missing low power clock source support. Woops
<braunr> gdb through openocd, yes
<braunr> actually, when debugging, you want to disable stuff like wait-for-interrupts
<Guest0> so, should i research "how to use gdb with openocd" to see the passed parameters?
<braunr> Guest0: that's a start
<Xogium> aw man that one was nasty. I spent like 10 hours bisecting a working .config with a non working .config
<braunr> but the skill set to comfortably do it is larger
<braunr> take your time
<Guest0> umm, okay. i will research on it more, thank you so much!
<Xogium> turns out that migrating to kernel 5.15 from 5.10, kconfig went a bit soft in the head and disabled this critical setting
<braunr> learn by doing
<Guest0> last question: is it an ELF file? the "flashdump.bin" file ?
<braunr> no it's not
<Xogium> nup
<braunr> Xogium: what setting ?
<Xogium> its made *from* the ELF though
<Guest0> is there a specific name for this file? :D  what did i get after dump_image command?
<Xogium> braunr: support for low power source clock on stm32mp1
<braunr> Guest0: there isn't, that's what i called raw binary form earlier
<braunr> Xogium: i see
<braunr> i only debugged the cm4 on stm32mp1
<Xogium> kernel was going no further than, enabled earlycon0, I was like, what the actual freaking hell
<Xogium> :D
<braunr> Guest0: you literally got what's on the flash
<Xogium> hmm, still haven't played with that one. I wonder what I could have it performing
<braunr> the process to produce that stuff is usually : source code -> formatted executable (like ELF) -> raw binary form
<Guest0> oh ok, so it is the full dump of the flash?
<braunr> the first transformation is through a compiler, the second through a tool like objcopy
<braunr> not necessary full
<braunr> usually you request a range
<braunr> the range can be the full range or a subset
<Xogium> I want to make a clapper device. Y'know, use a sound sensor, clap your hands, start music. Clap again and it stops music. But that runs on the cortex-a, as a linux app. The music player, that is. Still, would be fun to do this, just for fun. Challenging myself
<braunr> Xogium: the cm4 is only really there for real-time stuff
<Guest0> my flash is 2mb and i entered 0x00000000 - 0x200000 as range
<braunr> that's the full range then
<Xogium> yeah I'm probably not needing that to use the sound sensor
<braunr> probably not :)
<Guest0> one more question:D  sorry im really ignorant on this
<Xogium> no worries, we all started somewhere
<Guest0> i am using STM32CudeIDE to write my apps into flash. so, why can not I see all the source codes clearly?
<braunr> Guest0: well if you write your apps, you have the source code somewhere, don't you ?
<Guest0> i have in my computer, but i am trying to reverse it like a 3rd person
<braunr> Guest0: then that's normal
<braunr> 20:11 < braunr> the process to produce that stuff is usually : source code -> formatted executable (like ELF) -> raw binary form
<braunr> the source code isn't included in the formatted executable, and there is even more information loss at the last stage
<braunr> it's not called reverse engineering for nothing
<Guest0> hmm, as i understand: the flash never contains the full source codes and the processor runs the raw binary form in the flash?  right?
<braunr> yes
<Guest0> yess! thank you sir
nerozero has quit [Ping timeout: 245 seconds]
<braunr> have fun
<Guest0> so, today i learned how to dump flash memory, so what about the RAM?
<braunr> same stuff
<Guest0> is this dump already includes the RAM content?
<braunr> no, it's only the flash range
<braunr> you need to learn about device memory mapping
<braunr> the flash, the ram, the registers of the various devices are mapped in one memory space
<Guest0> its okay, but i used this command to extract the flash:           "halt; dump_image flashdump.bin 0x00000000 0x200000"
<Guest0> is there another command for dumping the RAM content?
<braunr> the same, at another memory range
<Xogium> which is often SoC specific if I'm not dumb ^^
<braunr> well, sometimes, depending on the device, the jtag and the cpu may not have the whole memory space
<braunr> yes
<braunr> well the cpu normally has full access, but the jtag may not
<Guest0> hmm, if I change 0x00000000 and 0x200000 - will i get the RAM content?
<braunr> don't guess
<braunr> find out
<braunr> get the manual for the microcontroller/SoC and find out
<Xogium> gotta read SoC datasheet and reference
<braunr> yes it's normally the datasheet
<braunr> but for quite a few stm32 uc, it's directly in the manual
<Guest0> a few days ago, i inspected a variable and it was storing at 0x20000334 address
<Guest0> 1) so, does it mean it stored in the RAM?
<braunr> that sounds like ram
<braunr> again you're guessing
<braunr> go find the manual, it's publically and freely available
<Guest0> 2) how can i edit the command (range) to access the value in this address?
<braunr> well you edit the command .. :)
<braunr> the first address is the start of the range, and the second the end
<braunr> or maybe the size
<Guest0> "halt; dump_image flashdump.bin 0x00000000 0x20000334"
<Guest0> like that?
<braunr> check that in the openocd manual
<braunr> you could but it's not very efficient
<braunr> rather dump_image ram.bin 0x20000000 0x20001000
<braunr> or 0x1000 if it's the size
<braunr> or lower
<braunr> like 0x338
<braunr> i don't know if the end is included or not, check the doc
<Guest0> i will try
<Guest0> let me upload the content, wait pls
<braunr> no
<braunr> we can help you, we won't do it for you :p
<braunr> (at least i won't)
<Guest0> :)  no sir, i will just ask a question
<Guest0> there are meanless values until line 880
<Guest0> and then readable things is started (its my bin file and output of "strings" command)
<Guest0> so, can we say that "the first 880 lines is content of RAM and the remaining lines are contents of flash?"
<braunr> no
<braunr> it's all flash
<braunr> hm wait
<braunr> what did you upload, the 0x20000000 0x20001000 range ?
<braunr> or 0x20000000 0x338 ?
<Guest0> no its 0x00000000 - 0x200000 range
<Guest0> which one do i try?
<braunr> then it's flash
<braunr> i don't know, check the doc
<PaulFertser> Guest0: get datasheet for the part you're using, check "Memory Map" there.
<braunr> from memory, i know that 0x0 is the flash and 0x20000000 is the ram, (at least, it's very likely) but i don't know much more
<braunr> the first 880 lines or so is a text representation of your code, most likely
<PaulFertser> stm32 usually maps flash to 0x08000000 , and whatever it boots from is mapped to 0x0 (so it can be ROM bootloader).
<braunr> and then it's data, and much of the data is made of read-only strings
<braunr> ah yes
<braunr> it's aliased
<Guest0> 0x2002 0000 - 0x2002 FFFF &&&& 0x2001 C000 - 0x2001 FFFF &&&& 0x2000 0000 - 0x2001 BFFF
<PaulFertser> Guest0: have you found memory map yet?
<Guest0> they are SRAM ranges as I understand, page 86: https://www.st.com/resource/en/datasheet/dm00071990.pdf
<Guest0> yes sir i found it
<PaulFertser> Normally code runs from directly from flash. Initial variable values are copied from flash to RAM on startup. const variables are stored in flash directly.
<Guest0> but in my STM32CubeIDE software, it just shows range like: https://i.ibb.co/QmS3z5r/image.png
<braunr> Guest0: those ranges follow each other
<braunr> they can be thought of as one
<braunr> 0x2001bfff + 1 = 0x2001c000
<Guest0> hmm, so lets look at the image it tells the range: 0x20000000 - 0x20030000
<Guest0> if i enter this command, will OpenOCD show me content of the RAM? : "halt; dump_image flashdump.bin 0x20000000 0x20030000"
<PaulFertser> Guest0: it won't be "flash" dump though, it'll be SRAM dump.
<PaulFertser> Guest0: and the last argument is size, not offset. So it's wrong.
<Guest0> i tried that command but did not output anything
<PaulFertser> OK :)
<Guest0> so how should i correct the command?:D
<PaulFertser> Size of the area should be the last argument.
<PaulFertser> And you need to wait some seconds for the whole SRAM dump.
<Guest0> it is 192 kb, should i enter this command: halt; "dump_image flashdump.bin 0x20000000 0x2EE00"
damex_ has quit []
<Guest0> or this one: "halt; dump_image flashdump.bin 0x20000000 0x00030000"
damex has joined #openocd
<braunr> try it
<braunr> but you should name the output file ramdump.bin
bacam has quit [*.net *.split]
bacam has joined #openocd
<Guest0> i tried and its the output: https://pst.klgrth.io/paste/cd7s8
<Guest0> its output of "strings ramdump.bin"
<Guest0> so all the data is meaningless
<Guest0> does it mean the RAM is protected? or this is the original value?
<braunr> it's only meaningless as strings
<braunr> you have to understand how data is encoded
<Guest0> how can i understand? :D
<Guest0> so can you confirm that its the content of the SRAM ?
<braunr> i can't
<braunr> but it's likely
<PaulFertser> Guest0: what data do you expect to find in RAM?
<braunr> Guest0: look you seem to be very new at this
<braunr> Guest0: but you seem interested in low level programming
<braunr> i made a small educational OS in the past (20:53 -!- Netsplit *.net <-> *.split quits: bacam
<braunr> 20:53 -!- Netsplit over, joins: bacam
<PaulFertser> "IDLE Tmr Svc defaultTask GUI_Task " looks like names of RTOS threads, so quite meaningful.
<braunr> 20:53 < Guest0> i tried and its the output: https://pst.klgrth.io/paste/cd7s8
<braunr> my bad
<braunr> 20:53 < Guest0> its output of "strings ramdump.bin"
<braunr> woops
<braunr> i made a small educational OS in the past (https://www.sceen.net/x1/)
<Guest0> yes sir im new
<braunr> Guest0: you probably don't need all of it, but there certainly are some useful links
<Guest0> and im trying to see the key (3) in the RAM (which I passed into caesarCipher function): https://i.ibb.co/qJ33rSn/image.png
<PaulFertser> Guest0: it's too short of a string, and probably it's a constant so not going into RAM ever.
<Guest0> yes, because i can see the value of a char variable in the RAM
<PaulFertser> Guest0: when linking your project you can ask the linker to generate a "map" file, you can see the exact offset of each variable in there.
<PaulFertser> 3 isn't even a string literal in your code, it's just a constant, and likely is encoded as immediate argument to some assembly instruction.
<braunr> PaulFertser: he wants to reverse from the binary content, as someone who doesn't have access to the code
<Guest0> yes, exactly
<PaulFertser> braunr: then Guest0 obviously needs to start with disassembling the binary dumped from flash :)
<Guest0> how could an hacker reveal that key (3) ?
<braunr> Guest0: learn about assembly and calling conventions
<braunr> PaulFertser: obviously :)
<braunr> Guest0: he wouldn't learn all he needs to do it in an hour :p
<braunr> it takes much more time
<PaulFertser> Guest0: by disassembling, and e.g. in radare2 you have "aaa" command that can find and annotate functions for you. But it's not a magic decompiler to see the source code.
<PaulFertser> Guest0: I suggest you start with some "crackme" tutorials. They're for x86 usually, but the idea is the same.
<braunr> i don't know someone who doesn't have a strong grasp of machine code / assembly, calling conventions, C, etc.. can effectively use something like radare2
<Guest0> ok, i will start with learning Assembly ^^
<braunr> err, i don't think*
<Guest0> my last question: if I would pass a long string like "hahacrackme" as a key, then could i see it in the memory dump?
<PaulFertser> braunr: absolutely impossible, especially with radare2 :)
<PaulFertser> Guest0: not likely in memory dump but likely in flash dump.
<Guest0> hmm
<braunr> the compiler would generate a call to the function, passing the address of the string as an argument
<PaulFertser> BTW, radare2 was forked recently, and probably the new tool is a bit more friendly.
<PaulFertser> Rizin is the name of the fork.
<Guest0> ok, i am so thankful for your helps, really appreciated ^^
<PaulFertser> The team also offers Cutter as the GUI to it.
<Guest0> have a good day <3
<PaulFertser> Guest0: you too, have fun.
<PaulFertser> Guest0: "crackme" is the keyword
<Guest0> i will exactly take a look at it, buummmm!! :)
Guest0 has quit [Quit: Client closed]
_whitelogger has joined #openocd
kraiskil_ has joined #openocd
kraiskil_ has quit [Ping timeout: 252 seconds]
wingsorc__ has joined #openocd
sbach has quit [Read error: Connection reset by peer]
sbach has joined #openocd
crabbedhaloablut has quit [Remote host closed the connection]
crabbedhaloablut has joined #openocd
akaWolf has quit [Ping timeout: 268 seconds]
akaWolf has joined #openocd
Steffanx has quit [Read error: Connection reset by peer]
Steffanx has joined #openocd
Bugies has quit [Ping timeout: 252 seconds]
Xogium has quit [Quit: Leaving.]
Xogium has joined #openocd
crabbedhaloablut has quit [Remote host closed the connection]
crabbedhaloablut has joined #openocd
crabbedhaloablut has quit [Remote host closed the connection]
crabbedhaloablut has joined #openocd