rule win_pirpi_auto {

    meta:
        author = "Felix Bilstein - yara-signator at cocacoding dot com"
        date = "2026-09-17"
        version = "1"
        description = "Detects win.pirpi."
        info = "autogenerated rule brought to you by yara-signator"
        tool = "yara-signator v0.6.0"
        signator_config = "callsandjumps;datarefs;binvalue"
        malpedia_reference = "https://malpedia.caad.fkie.fraunhofer.de/details/win.pirpi"
        malpedia_rule_date = "20260916"
        malpedia_hash = "53a643781c18e08f4a50949af60172d837a0b6f6"
        malpedia_version = "20260917"
        malpedia_license = "CC BY-SA 4.0"
        malpedia_sharing = "TLP:WHITE"

    /* DISCLAIMER
     * The strings used in this rule have been automatically selected from the
     * disassembly of memory dumps and unpacked files, using YARA-Signator.
     * The code and documentation is published here:
     * https://github.com/fxb-cocacoding/yara-signator
     * As Malpedia is used as data source, please note that for a given
     * number of families, only single samples are documented.
     * This likely impacts the degree of generalization these rules will offer.
     * Take the described generation method also into consideration when you
     * apply the rules in your use cases and assign them confidence levels.
     */


    strings:
        $sequence_0 = { 51 57 8bcd e8???????? 3933 750c }
            // n = 6, score = 200
            //   51                   | push                ecx
            //   57                   | push                edi
            //   8bcd                 | mov                 ecx, ebp
            //   e8????????           |                     
            //   3933                 | cmp                 dword ptr [ebx], esi
            //   750c                 | jne                 0xe

        $sequence_1 = { 50 56 55 53 ff15???????? 53 ff15???????? }
            // n = 7, score = 200
            //   50                   | push                eax
            //   56                   | push                esi
            //   55                   | push                ebp
            //   53                   | push                ebx
            //   ff15????????         |                     
            //   53                   | push                ebx
            //   ff15????????         |                     

        $sequence_2 = { c20c00 33d2 f7f1 8d04d2 8d93c8480000 8d04c0 8d8cc370340000 }
            // n = 7, score = 200
            //   c20c00               | ret                 0xc
            //   33d2                 | xor                 edx, edx
            //   f7f1                 | div                 ecx
            //   8d04d2               | lea                 eax, [edx + edx*8]
            //   8d93c8480000         | lea                 edx, [ebx + 0x48c8]
            //   8d04c0               | lea                 eax, [eax + eax*8]
            //   8d8cc370340000       | lea                 ecx, [ebx + eax*8 + 0x3470]

        $sequence_3 = { 49 51 68???????? 8d4c2460 ff15???????? 8a542413 }
            // n = 6, score = 200
            //   49                   | dec                 ecx
            //   51                   | push                ecx
            //   68????????           |                     
            //   8d4c2460             | lea                 ecx, [esp + 0x60]
            //   ff15????????         |                     
            //   8a542413             | mov                 dl, byte ptr [esp + 0x13]

        $sequence_4 = { 8b45fa 83c604 25ffff0000 56 50 8bcb e8???????? }
            // n = 7, score = 200
            //   8b45fa               | mov                 eax, dword ptr [ebp - 6]
            //   83c604               | add                 esi, 4
            //   25ffff0000           | and                 eax, 0xffff
            //   56                   | push                esi
            //   50                   | push                eax
            //   8bcb                 | mov                 ecx, ebx
            //   e8????????           |                     

        $sequence_5 = { 5d b801000000 5b 81c49c020000 c20c00 8b442410 }
            // n = 6, score = 200
            //   5d                   | pop                 ebp
            //   b801000000           | mov                 eax, 1
            //   5b                   | pop                 ebx
            //   81c49c020000         | add                 esp, 0x29c
            //   c20c00               | ret                 0xc
            //   8b442410             | mov                 eax, dword ptr [esp + 0x10]

        $sequence_6 = { 8b7c2418 85ff 0f8422010000 83f802 0f8587000000 8b8b20200000 8b8324200000 }
            // n = 7, score = 200
            //   8b7c2418             | mov                 edi, dword ptr [esp + 0x18]
            //   85ff                 | test                edi, edi
            //   0f8422010000         | je                  0x128
            //   83f802               | cmp                 eax, 2
            //   0f8587000000         | jne                 0x8d
            //   8b8b20200000         | mov                 ecx, dword ptr [ebx + 0x2020]
            //   8b8324200000         | mov                 eax, dword ptr [ebx + 0x2024]

        $sequence_7 = { ff15???????? 57 ff15???????? 3975fc 7415 53 }
            // n = 6, score = 200
            //   ff15????????         |                     
            //   57                   | push                edi
            //   ff15????????         |                     
            //   3975fc               | cmp                 dword ptr [ebp - 4], esi
            //   7415                 | je                  0x17
            //   53                   | push                ebx

        $sequence_8 = { 3bf5 72eb 5f 88442a02 5e 5d 8bc2 }
            // n = 7, score = 200
            //   3bf5                 | cmp                 esi, ebp
            //   72eb                 | jb                  0xffffffed
            //   5f                   | pop                 edi
            //   88442a02             | mov                 byte ptr [edx + ebp + 2], al
            //   5e                   | pop                 esi
            //   5d                   | pop                 ebp
            //   8bc2                 | mov                 eax, edx

        $sequence_9 = { c3 8b942440010000 83c9ff 8bfa 33c0 }
            // n = 5, score = 200
            //   c3                   | ret                 
            //   8b942440010000       | mov                 edx, dword ptr [esp + 0x140]
            //   83c9ff               | or                  ecx, 0xffffffff
            //   8bfa                 | mov                 edi, edx
            //   33c0                 | xor                 eax, eax

    condition:
        7 of them and filesize < 327680
}