Results 1 to 15 of 15

Thread: pcode internals

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2015
    Posts
    446

    pcode internals

    If you are curious about programming language design looking at the vb6 runtime & pcode implementation
    is a very interesting research subject.

    Its a huge and intricate topic that is not well documented. The best way to really understand it, is
    to watch it run live in a pcode debugger.

    Name:  dbg.jpg
Views: 406
Size:  12.0 KB

    This video details how pcode for loops were implemented. You will also get a glimpse of loading
    constants, equality operations, and if statements.

    https://www.youtube.com/watch?v=SmVmgdcCrDA

    You can find some more videos from this series here:
    https://www.youtube.com/watch?v=p08y...7WpYn3gPQKSfYO

    More posts on the subject and the text version of the contents of this video here:
    http://sandsprite.com/blogs/index.ph...=483&year=2020
    Last edited by dz32; Apr 1st, 2020 at 08:48 PM.

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    6,027

    Re: pcode internals

    This is a very interesting subject, one I've always been fascinated with. In fact, just the other day I was sitting down thinking about creating my own VM with its own stack machine and opcodes. Not for any practical use but just because it's extremely interesting to me and I know I'd enjoy learning and implementing something like this.

    If you are curious about programming language design looking at the vb6 runtime & pcode implementation
    is a very interesting research subject.
    As a matter of historical interest, pcode is a good subject but I think if one wants to really learn about compilers, stack machines etc., there is quite a lot more information in the .Net and Java world. The .Net Framework's internals, including the CIL which can also be implemented using a stack machine, has a lot more information on it. I've had a passive interest in this stuff for many many years and I remember looking for information on VB's PCode implementation and there was almost no information. When MSIL, now known as CIL became a standard, there was so much information becoming available on it. In fact, it's what gave me the confidence to believe I could actually make my own as a matter of academic interest. There's just so much information in the Java and .Net eco-systems on this subject. One shouldn't just limit their study to VB6's PCode if they really want to learn this stuff. Also, the brilliant minds behind these things have learned a lot and I mean a lot since the days where VB6's PCode interpreter was a giant in it's domain. Highly optimized JIT compilers are just one area where massive advancements have been made.

    Nonetheless, this is a very interesting topic you raised.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena


    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. -jmcilhinney

  3. #3
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,021

    Re: pcode internals

    > Highly optimized JIT compilers are just one area where massive advancements have been made.

    Tracing JIT compiler for VB6 p-code is next :-))

    Edit: Some info on JS state of JIT -- https://mathiasbynens.be/notes/shapes-ics

    cheers,
    </wqw>

  4. #4

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    36,143

    Re: pcode internals

    CIL is probably an easier place to start than VB6 pcode for another reason, as well: It's reasonably close to ASM, so if you have any background in ASM you will find that you can work your way through CIL pretty well, whereas this distance between pcode and ASM is greater, making it harder to read.

    However, one should be willing to dance if one wants to take up writing a JIT compiler. After all, any mistakes you make could be considered JITer bugs.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2015
    Posts
    446

    Re: pcode internals

    and a description of the For Loop runtime asm handler: http://sandsprite.com/blogs/index.ph...=484&year=2020
    Last edited by dz32; Apr 7th, 2020 at 05:53 AM.

  7. #7
    Addicted Member
    Join Date
    Jun 2016
    Location
    Espaņa
    Posts
    244

    Re: pcode internals

    very good work.
    I follow you and I always like all your videos.
    Although for me it is complicated, but I think it is a great job.
    Greetings

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2015
    Posts
    446

    Re: pcode internals

    I have some more blog posts coming out on this topic that people may be interested in. This weeks installment is the inner workings of PCode Disassembly & runtime . Next week will be how to write a pcode debugger. Enjoy

    https://decoded.avast.io/davidzimmer...e-disassembly/

    In this article we are going to discuss the inner depths of VB6 P-Code disassembly and the VB6 runtime.

    As a malware analyst, VB6 in general, and P-Code in particular, has always been a problem area. It is not well documented and the publicly available tooling did not give me the clarity I really desired.
    Last edited by dz32; May 5th, 2021 at 05:24 PM.

  9. #9
    Hyperactive Member
    Join Date
    Aug 2020
    Posts
    314

    Re: pcode internals

    Very useful learning materials, thank you very much, dz32.

    Thanks also to Niya, wqweto, The trick and Shaggy Hiker for their information.
    Last edited by SearchingDataOnly; May 5th, 2021 at 09:18 PM.

  10. #10
    Addicted Member
    Join Date
    Jun 2016
    Location
    Espaņa
    Posts
    244

    Re: pcode internals

    interesting very good work

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2015
    Posts
    446

    Re: pcode internals

    next article: Writing a PCode Debugger

    https://decoded.avast.io/davidzimmer...code-debugger/

    One more to go after this on how to extract and call pcode byte blobs from C
    (study in pcode function structure, const pool layout, and how execution is transferred from native code to pcode)

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2015
    Posts
    446

    Re: pcode internals

    btw the vbdec pcode disassembler/debugger has now been released as a free download

  13. #13
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    706

    Re: pcode internals

    [slightly off-topic]

    Is VB pcode the same pcode as used by Pascal compilers from the 1980's (and now?) ? Or are these pcodes quite different?
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++20 Compiler: Microsoft VS2019 (16.10.0)

  14. #14
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Posts
    3,021

    Re: pcode internals

    This is like assuming that VB's IR (Intermediate Representation) can be the same as some Pascal (or any other) compiler's IR. This might happen if both compilers are from the same vendor or both use (outsource) IR to something like LLVM.

    The point is that p-code is not something specific to VB's interpreter. Most interpreted languages VM's use some form of p-code (Lua, python, not sure about VBScript) using whatever bytecode and opcodes are most suitable for them.

    cheers,
    </wqw>

  15. #15
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: pcode internals

    What virtual machine interpreter are you working on?I can't understand these, so I can only optimize or choose some ordinary algorithms.If I don't understand, I will send some questions and let's Technology Communication and Learning them together.

    How to decompile the VB6 code parser and debugger, this thing is really useful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width