IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C++ Discussion :

Problème de debugger en c++


Sujet :

C++

  1. #1
    Membre à l'essai
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2020
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2020
    Messages : 51
    Points : 14
    Points
    14
    Par défaut Problème de debugger en c++
    Bonsoir, j'essaye de créer un debugger en C++ et avec mon code je n'ai pas d'affichage quand j'essaye de debugger une application et un crash de celui-ci. voici la source.

    Quelqu'un pourrez me dire ce qui va pas ????

    main.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
     
        #define       C_SIZE1             0x01
        #define       C_MODRM             0x02
        #define       C_DATA8             0x04
        #define       C_DATA16            0x08
        #define       C_DATA32            0x10
        #define       C_PREFIX            0x20
        #define       C_2BYTE             0x40
        #define       C_REL               0x80    //used to don't fuck up relative jmps with 67 prefix    
        #define       C_66                0x66    //operand size prefix
        #define       C_67                0x67    //address size prefix
     
        #define       C_UNKNOWN           0x00
     
        BYTE table_1[256]={
        /* 00 */  C_MODRM
        /* 01 */, C_MODRM
        /* 02 */, C_MODRM
        /* 03 */, C_MODRM
        /* 04 */, C_DATA8    // add al, ax, eax + 32imm  w not set imm size = 8
        /* 05 */, C_DATA32   // add al, ax, eax + 32imm  w set imm size = 32
        /* 06 */, C_SIZE1    //push es
        /* 07 */, C_SIZE1    //pop es
        /* 08 */, C_MODRM    //or w set
        /* 09 */, C_MODRM    //or w not set :)
        /* 0A */, C_MODRM
        /* 0B */, C_MODRM
        /* 0C */, C_DATA8    // or al/ax/eax shortcut
        /* 0D */, C_DATA32   // or al/ax/eax shortcut
        /* 0E */, C_SIZE1    // push cs
        /* 0F */, C_2BYTE
        /* 10 */, C_MODRM    //adc w/d set mod rm, next 4
        /* 11 */, C_MODRM
        /* 12 */, C_MODRM
        /* 13 */, C_MODRM
        /* 14 */, C_DATA8    //adc al, imm8
        /* 15 */, C_DATA32   //adc al, imm32
        /* 16 */, C_SIZE1    //push ss
        /* 17 */, C_SIZE1    //pop ss
        /* 18 */, C_MODRM    //sbb w set/not set
        /* 19 */, C_MODRM
        /* 1A */, C_MODRM    //sbb d/w combinations
        /* 1B */, C_MODRM    //sbb d/w combinations
        /* 1C */, C_DATA8    //sbb al, imm8
        /* 1D */, C_DATA32   //sbb eax, imm32
        /* 1E */, C_SIZE1    //push ds
        /* 1F */, C_SIZE1    //pop ds
        /* 20 */, C_MODRM    //and mod/rm d/w bit combinations = 4
        /* 21 */, C_MODRM
        /* 22 */, C_MODRM
        /* 23 */, C_MODRM    //end and mod/rm d/w bit combinations
        /* 24 */, C_DATA8    //and al, imm8
        /* 25 */, C_DATA32   //and al, imm32
        /* 26 */, C_PREFIX
        /* 27 */, C_SIZE1    //daa
        /* 28 */, C_MODRM    //sub w/d mixup
        /* 29 */, C_MODRM    
        /* 2A */, C_MODRM
        /* 2B */, C_MODRM    //sub w/d mixup end
        /* 2C */, C_DATA8    //sub al, ax ,eax imm8
        /* 2D */, C_DATA32   //sub al, ax, eax imm8
        /* 2E */, C_PREFIX
        /* 2F */, C_SIZE1    //das
        /* 30 */, C_MODRM    //xor next 4
        /* 31 */, C_MODRM
        /* 32 */, C_MODRM
        /* 33 */, C_MODRM
        /* 34 */, C_DATA8    //xor al, ax, eax imm 8 w not set (al)
        /* 35 */, C_DATA32   //xor al, ax, eax imm 32 w set (eax)
        /* 36 */, C_PREFIX
        /* 37 */, C_SIZE1           //AAA
        /* 38 */, C_MODRM           //cmp d/w set 4 combinations
        /* 39 */, C_MODRM           //cmp
        /* 3A */, C_MODRM           //cmp
        /* 3B */, C_MODRM           //cmp
        /* 3C */, C_DATA8           //cmp al, ax, eax imm 8
        /* 3D */, C_DATA32          //cmp al, ax, eax imm 32
        /* 3E */, C_PREFIX
        /* 3F */, C_SIZE1           //AAS
        /* 40 */, C_SIZE1           //inc reg (alternate encoding)
        /* 41 */, C_SIZE1
        /* 42 */, C_SIZE1
        /* 43 */, C_SIZE1
        /* 44 */, C_SIZE1
        /* 45 */, C_SIZE1
        /* 46 */, C_SIZE1
        /* 47 */, C_SIZE1
        /* 48 */, C_SIZE1           //dec reg (alternate encoding)
        /* 49 */, C_SIZE1
        /* 4A */, C_SIZE1
        /* 4B */, C_SIZE1
        /* 4C */, C_SIZE1
        /* 4D */, C_SIZE1
        /* 4E */, C_SIZE1
        /* 4F */, C_SIZE1
        /* 50 */, C_SIZE1
        /* 51 */, C_SIZE1
        /* 52 */, C_SIZE1
        /* 53 */, C_SIZE1
        /* 54 */, C_SIZE1
        /* 55 */, C_SIZE1
        /* 56 */, C_SIZE1
        /* 57 */, C_SIZE1
        /* 58 */, C_SIZE1    //pop reg
        /* 59 */, C_SIZE1
        /* 5A */, C_SIZE1
        /* 5B */, C_SIZE1
        /* 5C */, C_SIZE1
        /* 5D */, C_SIZE1
        /* 5E */, C_SIZE1
        /* 5F */, C_SIZE1    //pop reg ends
        /* 60 */, C_SIZE1    //pushad
        /* 61 */, C_SIZE1    //popad
        /* 62 */, C_MODRM    //bound
        /* 63 */, C_MODRM    //arpl
        /* 64 */, C_PREFIX
        /* 65 */, C_PREFIX
        /* 66 */, C_PREFIX
        /* 67 */, C_PREFIX
        /* 68 */, C_DATA32  //push immidiate 32
        /* 69 */, C_MODRM + C_DATA32       //imul reg/reg imm32
        /* 6A */, C_DATA8   //push imm 8
        /* 6B */, C_MODRM + C_DATA8        //imul reg/reg imm8
        /* 6C */, C_SIZE1   //ins w not set
        /* 6D */, C_SIZE1   //ins w set
        /* 6E */, C_SIZE1   //outs w not set
        /* 6F */, C_SIZE1   //outs w set
        /* 70 */, C_DATA8  + C_REL  //jcc 8 bit displacement start
        /* 71 */, C_DATA8  + C_REL
        /* 72 */, C_DATA8  + C_REL
        /* 73 */, C_DATA8  + C_REL
        /* 74 */, C_DATA8  + C_REL
        /* 75 */, C_DATA8  + C_REL
        /* 76 */, C_DATA8  + C_REL
        /* 77 */, C_DATA8  + C_REL
        /* 78 */, C_DATA8  + C_REL
        /* 79 */, C_DATA8  + C_REL
        /* 7A */, C_DATA8  + C_REL
        /* 7B */, C_DATA8  + C_REL
        /* 7C */, C_DATA8  + C_REL
        /* 7D */, C_DATA8  + C_REL
        /* 7E */, C_DATA8  + C_REL
        /* 7F */, C_DATA8  + C_REL  //jcc 8 bit displacement ends
        /* 80 */, C_MODRM + C_DATA8   //sub immidira/reg 32bit imm, also cmp modrm/imm32, also cmp
        /* 81 */, C_MODRM + C_DATA32   //sub imidiate/reg 32bit imm, also cmp modrm/imm32, also cmp
        /* 82 */, C_MODRM + C_DATA8    //sub or mod rm 8imm w not set, --||--      /imm8, also cmp
        /* 83 */, C_MODRM + C_DATA8    //sub or mod rm 8imm w set set, --||--      /imm8, also cmp
        /* 84 */, C_MODRM    //test w not set
        /* 85 */, C_MODRM    //test w set
        /* 86 */, C_MODRM    //xchg w not set
        /* 87 */, C_MODRM    //xchg w set
        /* 88 */, C_MODRM    //mov not set w
        /* 89 */, C_MODRM    //mov set w
        /* 8A */, C_MODRM    //mov d set/not
        /* 8B */, C_MODRM
        /* 8C */, C_MODRM    //mov reg/seg
        /* 8D */, C_MODRM    //lea
        /* 8E */, C_MODRM    //mov reg/seg I guess
        /* 8F */, C_MODRM    //pop reg/memory
        /* 90 */, C_SIZE1    //nop
        /* 91 */, C_SIZE1    //xchg al, ax, eax   reg
        /* 92 */, C_SIZE1
        /* 93 */, C_SIZE1
        /* 94 */, C_SIZE1
        /* 95 */, C_SIZE1
        /* 96 */, C_SIZE1
        /* 97 */, C_SIZE1    //xchg al, ax, eax,  ret ends
        /* 98 */, C_SIZE1    //cbw, cwde
        /* 99 */, C_SIZE1    //cdq, cwd
        /* 9A */, C_DATA32 + C_DATA16 //far call (call unsinged full offset,selector)
        /* 9B */, C_SIZE1    //wait//fwait
        /* 9C */, C_SIZE1           //pushfd
        /* 9D */, C_SIZE1           //popfd
        /* 9E */, C_SIZE1           //sahf
        /* 9F */, C_SIZE1           //LAHF
        /* A0 */, C_DATA32          //mov al, ax, eax,mem full_offset
        /* A1 */, C_DATA32          //mov al, ax, eax, mem full_offset
        /* A2 */, C_DATA32          //mov mem, al, ax, eax full_offset
        /* A3 */, C_DATA32          //mov mem, al, ax, eax full_offset
        /* A4 */, C_SIZE1           //movsb
        /* A5 */, C_SIZE1           //movsd
        /* A6 */, C_SIZE1    //cmpsb... 2 of them w bit set
        /* A7 */, C_SIZE1    
        /* A8 */, C_DATA8    //test al/ax/eax shortcut
        /* A9 */, C_DATA32   //test al/ax/eax shortcut
        /* AA */, C_SIZE1    //stosb
        /* AB */, C_SIZE1    //stosd, or stosw + PREFIX 66
        /* AC */, C_SIZE1    //lodsb
        /* AD */, C_SIZE1    //lodsw + PREFIX 66 or lodsd
        /* AE */, C_SIZE1    //scasb
        /* AF */, C_SIZE1    //scasd
        /* B0 */, C_DATA8    //mov reg, imm 8 alterante encoding
        /* B1 */, C_DATA8
        /* B2 */, C_DATA8
        /* B3 */, C_DATA8
        /* B4 */, C_DATA8
        /* B5 */, C_DATA8
        /* B6 */, C_DATA8
        /* B7 */, C_DATA8
        /* B8 */, C_DATA32   //mov immidiate to reg (alternate encoding)
        /* B9 */, C_DATA32
        /* BA */, C_DATA32
        /* BB */, C_DATA32
        /* BC */, C_DATA32
        /* BD */, C_DATA32
        /* BE */, C_DATA32
        /* BF */, C_DATA32
        /* C0 */, C_MODRM+C_DATA8 //rcl reg/mem by imm8 also rcr depends on opcode in modr/m field, also rol/ror
        /* C1 */, C_MODRM+C_DATA8 //-----------||-----------
        /* C2 */, C_DATA16
        /* C3 */, C_SIZE1    //ret no args
        /* C4 */, C_MODRM    //les
        /* C5 */, C_MODRM    //lds
        /* C6 */, C_MODRM+C_DATA8   // mov mem/imm
        /* C7 */, C_MODRM+C_DATA32  //litle change (mov mem/imm)
        /* C8 */, C_DATA8 + C_DATA16    //enter 16disp, 8bit level =4 size
        /* C9 */, C_SIZE1
        /* CA */, C_DATA16              //retf param
        /* CB */, C_SIZE1               //retf no param
        /* CC */, C_SIZE1
        /* CD */, C_DATA8    //int, 8bit interupt number
        /* CE */, C_SIZE1    //into 
        /* CF */, C_SIZE1    //iret
        /* D0 */, C_MODRM    //rcl reg/memory by 1 , also rcr, also ror/rol
        /* D1 */, C_MODRM    //same with w bit set , -||-
        /* D2 */, C_MODRM    //rcl register by cl  , -||-
        /* D3 */, C_MODRM    //same with w bit set , -||- , also rol,ror
        /* D4 */, C_DATA8    //aam 2 byte long but C_DATA8 is processed as 2 in my algo so this is ok
        /* D5 */, C_DATA8    //aad 2 bytes long C_DATA8 is processed as 2 byte long 
        /* D6 */, C_SIZE1    //salc
        /* D7 */, C_SIZE1    //xlat
        /* D8 */, C_MODRM    //all FPU are C_MODRM
        /* D9 */, C_MODRM    
        /* DA */, C_MODRM
        /* DB */, C_MODRM
        /* DC */, C_MODRM
        /* DD */, C_MODRM
        /* DE */, C_MODRM
        /* DF */, C_MODRM    //end FPU instructions
        /* E0 */, C_DATA8 + C_REL   //loonz 8bit
        /* E1 */, C_DATA8 + C_REL   //loopz 8bit
        /* E2 */, C_DATA8 + C_REL   //loop  8bit
        /* E3 */, C_DATA8 + C_REL    //jecxz 8bit Address-size prefix indicates jcxz or jecxz
        /* E4 */, C_DATA8    //in al, port
        /* E5 */, C_DATA8    //in eax, port
        /* E6 */, C_DATA8    //out port w not set (out 0, al)
        /* E7 */, C_DATA8    //out port w set (out 0, eax)
        /* E8 */, C_DATA32 + C_REL
        /* E9 */, C_DATA32 + C_REL   //jmp full displacement
        /* EA */, C_DATA32 + C_DATA16 //jmp far full offset, selector
        /* EB */, C_DATA8     //jmp 8 bit displacement
        /* EC */, C_SIZE1    //in
        /* ED */, C_SIZE1    //in
        /* EE */, C_SIZE1    //out
        /* EF */, C_SIZE1    //out
        /* F0 */, C_PREFIX
        /* F1 */, C_SIZE1    //int1
        /* F2 */, C_PREFIX
        /* F3 */, C_PREFIX
        /* F4 */, C_SIZE1    //hlt
        /* F5 */, C_SIZE1    //cmc
        /* F6 */, C_MODRM + C_DATA8 //not (w not set), neg depends on opcode field in modrm, it can be test imm
        /* F7 */, C_MODRM + C_DATA32 //not (w set)    , neg depends on opcode field in modrm, it can be test imm
        /* F8 */, C_SIZE1    //clc
        /* F9 */, C_SIZE1    //stc
        /* FA */, C_SIZE1    //cli
        /* FB */, C_SIZE1    //sti
        /* FC */, C_SIZE1    //cld
        /* FD */, C_SIZE1    //std    
        /* FE */, C_MODRM    //inc/dec w not set (modrm)
        /* FF */, C_MODRM    //inc/dec w set     (modrm) //call also depends on reg/opcode field
        };                   //also jmp (depends on reg/opcode) fild
     
        BYTE table_2[256]={
        /* 00 */  C_MODRM           //lldt
        /* 01 */, C_MODRM           //invlpg
        /* 02 */, C_MODRM           //lar
        /* 03 */, C_MODRM           //LSL
        /* 04 */, 0
        /* 05 */, 0
        /* 06 */, C_SIZE1           //clts
        /* 07 */, 0
        /* 08 */, C_SIZE1           //invd
        /* 09 */, C_SIZE1
        /* 0A */, 0
        /* 0B */, 0
        /* 0C */, 0
        /* 0D */, 0
        /* 0E */, 0
        /* 0F */, 0
        /* 10 */, 0
        /* 11 */, 0
        /* 12 */, 0
        /* 13 */, 0
        /* 14 */, 0
        /* 15 */, 0
        /* 16 */, 0
        /* 17 */, 0
        /* 18 */, 0
        /* 19 */, 0
        /* 1A */, 0
        /* 1B */, 0
        /* 1C */, 0
        /* 1D */, 0
        /* 1E */, 0
        /* 1F */, 0
        /* 20 */, C_MODRM           //mov reg/crX
        /* 21 */, C_MODRM           //mov drX/reg
        /* 22 */, C_MODRM           //mov crX/reg and it foes all the way down
        /* 23 */, C_MODRM           //mov reg/drX
        /* 24 */, 0
        /* 25 */, 0
        /* 26 */, 0
        /* 27 */, 0
        /* 28 */, 0
        /* 29 */, 0
        /* 2A */, 0
        /* 2B */, 0
        /* 2C */, 0
        /* 2D */, 0
        /* 2E */, 0
        /* 2F */, 0
        /* 30 */, C_SIZE1
        /* 31 */, C_SIZE1
        /* 32 */, C_SIZE1
        /* 33 */, C_SIZE1
        /* 34 */, C_SIZE1
        /* 35 */, 0
        /* 36 */, 0
        /* 37 */, 0
        /* 38 */, 0
        /* 39 */, 0
        /* 3A */, 0
        /* 3B */, 0
        /* 3C */, 0
        /* 3D */, 0
        /* 3E */, 0
        /* 3F */, 0
        /* 40 */, C_MODRM           //conditional move
        /* 41 */, C_MODRM
        /* 42 */, C_MODRM
        /* 43 */, C_MODRM
        /* 44 */, C_MODRM
        /* 45 */, C_MODRM
        /* 46 */, C_MODRM
        /* 47 */, C_MODRM
        /* 48 */, C_MODRM
        /* 49 */, C_MODRM
        /* 4A */, C_MODRM
        /* 4B */, C_MODRM
        /* 4C */, C_MODRM
        /* 4D */, C_MODRM
        /* 4E */, C_MODRM
        /* 4F */, C_MODRM           //end conditional move 
        /* 50 */, 0
        /* 51 */, 0
        /* 52 */, 0
        /* 53 */, 0
        /* 54 */, 0
        /* 55 */, 0
        /* 56 */, 0
        /* 57 */, 0
        /* 58 */, 0
        /* 59 */, 0
        /* 5A */, 0
        /* 5B */, 0
        /* 5C */, 0
        /* 5D */, 0
        /* 5E */, 0
        /* 5F */, 0
        /* 60 */, 0
        /* 61 */, 0
        /* 62 */, 0
        /* 63 */, 0
        /* 64 */, 0
        /* 65 */, 0
        /* 66 */, 0
        /* 67 */, 0
        /* 68 */, 0
        /* 69 */, 0
        /* 6A */, 0
        /* 6B */, 0
        /* 6C */, 0
        /* 6D */, 0
        /* 6E */, 0
        /* 6F */, 0
        /* 70 */, 0
        /* 71 */, 0
        /* 72 */, 0
        /* 73 */, 0
        /* 74 */, 0
        /* 75 */, 0
        /* 76 */, 0
        /* 77 */, 0
        /* 78 */, 0
        /* 79 */, 0
        /* 7A */, 0
        /* 7B */, 0
        /* 7C */, 0
        /* 7D */, 0
        /* 7E */, 0
        /* 7F */, 0
        /* 80 */, C_DATA32   //jccs 2 byte long imm32
        /* 81 */, C_DATA32
        /* 82 */, C_DATA32
        /* 83 */, C_DATA32
        /* 84 */, C_DATA32
        /* 85 */, C_DATA32
        /* 86 */, C_DATA32
        /* 87 */, C_DATA32
        /* 88 */, C_DATA32
        /* 89 */, C_DATA32
        /* 8A */, C_DATA32
        /* 8B */, C_DATA32
        /* 8C */, C_DATA32
        /* 8D */, C_DATA32
        /* 8E */, C_DATA32
        /* 8F */, C_DATA32   //jccs 2byte long ends imm32
        /* 90 */, C_MODRM
        /* 91 */, C_MODRM
        /* 92 */, C_MODRM
        /* 93 */, C_MODRM
        /* 94 */, C_MODRM
        /* 95 */, C_MODRM
        /* 96 */, C_MODRM
        /* 97 */, C_MODRM
        /* 98 */, C_MODRM
        /* 99 */, C_MODRM
        /* 9A */, C_MODRM
        /* 9B */, C_MODRM
        /* 9C */, C_MODRM
        /* 9D */, C_MODRM
        /* 9E */, C_MODRM
        /* 9F */, C_MODRM
        /* A0 */, C_SIZE1            //push fs
        /* A1 */, C_SIZE1           //pop fs
        /* A2 */, C_SIZE1           //cpuid
        /* A3 */, C_MODRM           //bt reg/mem
        /* A4 */, C_MODRM + C_DATA8
        /* A5 */, C_MODRM
        /* A6 */, 0
        /* A7 */, 0
        /* A8 */, C_SIZE1           //push gs
        /* A9 */, C_SIZE1           //pop gs
        /* AA */, C_SIZE1
        /* AB */, C_MODRM           //bts
        /* AC */, C_MODRM + C_DATA8
        /* AD */, C_MODRM
        /* AE */, 0
        /* AF */, C_MODRM           //imul reg/reg or reg/mem
        /* B0 */, C_MODRM           //cmpxchg
        /* B1 */, C_MODRM           //cmpxchg
        /* B2 */, C_MODRM           //lss
        /* B3 */, C_MODRM           //btr
        /* B4 */, C_MODRM           //lfs
        /* B5 */, C_MODRM           //lgs
        /* B6 */, C_MODRM           //movzx
        /* B7 */, C_MODRM           //movzx
        /* B8 */, 0
        /* B9 */, 0
        /* BA */, C_MODRM + C_DATA8 //bt imm8
        /* BB */, C_MODRM           //btc mod/rm
        /* BC */, C_MODRM           //BSF
        /* BD */, C_MODRM           //BSR
        /* BE */, C_MODRM           //movsx
        /* BF */, C_MODRM           //movsx
        /* C0 */, C_MODRM           //xadd
        /* C1 */, C_MODRM           //xadd
        /* C2 */, 0
        /* C3 */, 0
        /* C4 */, 0
        /* C5 */, 0
        /* C6 */, 0
        /* C7 */, 0
        /* C8 */, C_SIZE1           //bswap eax
        /* C9 */, C_SIZE1
        /* CA */, C_SIZE1
        /* CB */, C_SIZE1
        /* CC */, C_SIZE1
        /* CD */, C_SIZE1
        /* CE */, C_SIZE1
        /* CF */, C_SIZE1           //bswap reg ends
        /* D0 */, 0
        /* D1 */, 0
        /* D2 */, 0
        /* D3 */, 0
        /* D4 */, 0
        /* D5 */, 0
        /* D6 */, 0
        /* D7 */, 0
        /* D8 */, 0
        /* D9 */, 0
        /* DA */, 0
        /* DB */, 0
        /* DC */, 0
        /* DD */, 0
        /* DE */, 0
        /* DF */, 0
        /* E0 */, 0
        /* E1 */, 0
        /* E2 */, 0
        /* E3 */, 0
        /* E4 */, 0
        /* E5 */, 0
        /* E6 */, 0
        /* E7 */, 0
        /* E8 */, 0
        /* E9 */, 0
        /* EA */, 0
        /* EB */, 0
        /* EC */, 0
        /* ED */, 0
        /* EE */, 0
        /* EF */, 0
        /* F0 */, 0
        /* F1 */, 0
        /* F2 */, 0
        /* F3 */, 0
        /* F4 */, 0
        /* F5 */, 0
        /* F6 */, 0
        /* F7 */, 0
        /* F8 */, 0
        /* F9 */, 0
        /* FA */, 0
        /* FB */, 0
        /* FC */, 0
        /* FD */, 0
        /* FE */, 0
        /* FF */, 0
        };
    main.cpp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
     
    ////////////////////////////////////////////////////////////////////////////////
    // main.cpp
    //
    // Disassembler x86
     
    #include <windows.h>
    #include <stdio.h>
    #include "main.h"
    #include <iostream>
     
    DWORD Dasm(BYTE* StartAdr)
    {
    	int size = 0;
    	int opsizeprefix=0;
    	int addressprefix = 0;
     
    	BYTE* p=StartAdr;
    	BYTE opcode=*p;
     
    AGAIN:
    	if(C_PREFIX==table_1[opcode])
    	{
    		if(C_66==opcode)
    			opsizeprefix=1;
     
    		if(C_67==opcode)
    			addressprefix=1;
     
    		++size;
    		++p;
    		opcode=*p;
    		goto AGAIN;
    	}
     
    	BYTE instruction = table_1[opcode];
     
    	if((0xF6==opcode) || (0xF7==opcode))
    	{
    		opcode=p[1];
    		if(0!=(opcode & 0x38))		// test or neg/not
    			instruction=C_MODRM;
    	}
     
    	if(opsizeprefix)
    		if(instruction & C_DATA32)		// Where was 8 still is 8 //where was 32 now is 16
    		{
    			instruction &= ~(C_DATA32);
    			instruction |= C_DATA16;
    		}
     
    		if(addressprefix && !(instruction & C_REL))	// if not relative change
    		{
    			instruction &= ~(C_DATA32);
    			instruction &= ~(C_DATA8);
    			instruction |= C_DATA16;
    		}
     
    		if(instruction & C_REL)		// Clear relative flag
    		instruction &= ~(C_REL);
     
    		// fill instruction with flags from table_2 and decode it in right way
     
    		if(instruction == C_2BYTE)
    		{
    			size += 1;
    			++p;
    			instruction = table_2[*p];
     
    			//if (instruction == C_DATA32)
    			//size += 5;
    			//goto check_modrm;   
    		}
     
    		size += 1;	// opcode len;     
     
    //check_modrm:
     
    		if(instruction & C_MODRM)
    		{
    			unsigned char modrm, sib;
    			size += 1;
    			++p;
    			modrm = *p;
    			if((modrm >> 6) == 0 && (modrm & 0x07) == 0x05)	// modrm is folowed by 32disp
    				size+=4;
     
    			if((modrm >> 6) != 3 && (modrm & 0x07) == 0x04)
    			{
    				++size;
    				++p;
    				sib = *p;
     
    				if( (modrm >> 6) == 1 && (modrm & 0x07) == 0x04) // 8bit disp after SIB(added to index)
    					++size;
     
    				if((modrm >> 6) == 2 && (modrm & 0x07) == 0x04)	// 32bit displacement after sib(added to index)             
    					size += 4;
     
    				if((modrm >> 6) == 0 && (sib & 0x07) == 0x05)
    					size +=4;
    			}
     
     
    			if(modrm >= 0x40 && modrm <= 0x7f && (modrm & 0x07) != 0x04)
    				size +=1;
     
    			if(modrm >= 0x80 && modrm <= 0xbf && (modrm & 0x07) != 0x04)
    				size +=4;                            
     
    		}  
     
    	if(instruction & C_DATA32)	// Is this opcode opcode modrm immdata ?
    		size +=4;
     
    	if(instruction & C_DATA8)
    		size++;
     
    	if(instruction & C_DATA16)
    		size+=2;        
     
    	if(instruction == C_UNKNOWN)
    		size += 1;
     
    	return size;
    }
     
    #ifndef IMAGE_NT_OPTIONAL_HDR32_MAGIC
    #define IMAGE_NT_OPTIONAL_HDR32_MAGIC 0x10b
    #endif
    using namespace std;
    int main(void)
    {
    	LPVOID lpBaseAddress=NULL;
     
    	STARTUPINFO si;
    	PROCESS_INFORMATION pi;
     
    	ZeroMemory(&si,sizeof(si));
    	si.cb=sizeof(STARTUPINFO);
    	si.wShowWindow=SW_NORMAL;
     
         const char *application = "Notepad.exe";
     
    	if(CreateProcess(application,NULL,
    	NULL,NULL,FALSE,CREATE_SUSPENDED,NULL,NULL,&si,&pi))
    	{
    		HMODULE hModule=GetModuleHandle(application);
    		PIMAGE_DOS_HEADER idh=(PIMAGE_DOS_HEADER)hModule;
    		PIMAGE_NT_HEADERS inh=(PIMAGE_NT_HEADERS)((PBYTE)hModule+idh->e_lfanew);
     
    		if(IMAGE_NT_SIGNATURE==inh->Signature)
    		{
    			if(IMAGE_NT_OPTIONAL_HDR32_MAGIC==inh->OptionalHeader.Magic)
    			{
    				lpBaseAddress=VirtualAllocEx(pi.hProcess,(LPVOID)hModule,
    				inh->OptionalHeader.SizeOfImage,
    				MEM_COMMIT | MEM_RESERVE,PAGE_EXECUTE_READWRITE);
    			}
    		}
    	}
    	else
    	{
    		printf("Could not create process\n");
    		system("pause>nul");
    		exit(1);
    	}
     
    	if(!lpBaseAddress)
    	{
    		printf("Wow, empty the base address!\n");
    		system("pause>nul");
    		exit(1);
    	}
    	ResumeThread(pi.hThread);
    	CloseHandle(pi.hThread);
     
    	BYTE* Adr=(unsigned char*)lpBaseAddress;
     
    	for(DWORD i=0; i<50; ++i)
    	{
    		DWORD Size=Dasm(Adr);
    		BYTE* p=Adr;
     
    		for(DWORD j=0; j<Size; ++j)
    		printf("%.2X ", p[j]);
     
    		printf("\n");
    		Adr = Adr + Size;
    	}
     
    	printf("Press enter to exit\n");
    	system("pause>nul");
    } 
    ////////////////////////////////////////////////////////////////////////////////
    // <<eof>> main.cpp

  2. #2
    Expert éminent sénior
    Avatar de Médinoc
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Septembre 2005
    Messages
    27 369
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 27 369
    Points : 41 519
    Points
    41 519
    Par défaut
    Tu ne peux pas lire directement la mémoire d'un autre processus.
    Tu dois passer par ReadProcessMemory() pour copier la plage mémoire voulue vers un buffer à toi.
    SVP, pas de questions techniques par MP. Surtout si je ne vous ai jamais parlé avant.

    "Aw, come on, who would be so stupid as to insert a cast to make an error go away without actually fixing the error?"
    Apparently everyone.
    -- Raymond Chen.
    Traduction obligatoire: "Oh, voyons, qui serait assez stupide pour mettre un cast pour faire disparaitre un message d'erreur sans vraiment corriger l'erreur?" - Apparemment, tout le monde. -- Raymond Chen.

  3. #3
    Membre à l'essai
    Homme Profil pro
    Développeur Web
    Inscrit en
    Juin 2020
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Juin 2020
    Messages : 51
    Points : 14
    Points
    14
    Par défaut
    Comment faire ça ?

  4. #4
    Expert éminent sénior
    Avatar de koala01
    Homme Profil pro
    aucun
    Inscrit en
    Octobre 2004
    Messages
    11 614
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 52
    Localisation : Belgique

    Informations professionnelles :
    Activité : aucun

    Informations forums :
    Inscription : Octobre 2004
    Messages : 11 614
    Points : 30 626
    Points
    30 626
    Par défaut
    Salut,

    En lisant la doc de readProcessMemory, pour commencer
    La première chose que l'on y trouve est le prototype de la fonction qui est
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    BOOL ReadProcessMemory(
      [in]  HANDLE  hProcess,
      [in]  LPCVOID lpBaseAddress,
      [out] LPVOID  lpBuffer,
      [in]  SIZE_T  nSize,
      [out] SIZE_T  *lpNumberOfBytesRead
    );
    Nous nous rendons compte qu'elle s'attend à recevoir cinq paramètre, voyons un peu ce que ce prototype peut nous apprendre d'autre à leur sujet.
    Le premier paramètre est [in] HANDLE hProcess. le [in] nous indique que c'est une paramètre d'entrée, c'est à dire un paramètre qui n'est utilisé que pour fournir (une partie) des informations nécessaires à la fonction, mais qui ne seront en aucun cas modifiées par la fonction.
    HANDLE correspond au type de la donnée que l'on doit transmettre et représente -- essayons de faire simple -- à l'identifiant du processus auquel on souhaite accéder.

    Cela nous est d'ailleurs confirmé par le nom de ce paramètre (qui respecte ce que l'on appelle "la notation hongroise") hProcess qui signifie littérallement h(andel)Process

    Le deuxième paramètre et [in] LPCVOID lpBaseAddress Le [in] nous indique toujours la même chose, LPCVOID corresond à un "pointeur constant de type void"(un const void * en fait), c'est à dire à un pointeur susceptible de pointer vers "n'importe quel type de donnée" en mémoire dont le contenu n'est pas destiné à être modifié.

    Le nom du paramètre lpBaseAddress nous indique quant à lui que la fonction s'attend à ce que ce pointeur représente "l'adresse de base" qui nous intéresse. Autrement dit, l'adresse à laquelle se trouve le premier octet à récupérer

    Le troisième paramètre change un peu car il est déclaré comme étant un [out] LPVOID lpBuffer. [out] nous indique qu'il s'agit d'un paramètre de sortie. C'est à dire que la fonction s'apprête à modifier le contenu de la donnée fournie en paramètre afin que nous puissions le récupérer une fois que la fonction aura fini son travail.

    Le type (LPVOID) ne varie du type du paramètre précédent (LPCVOID) que par l'absence du C (qui représente le mot clé const), ce qui signifie que nous avons affaire ici à un pointeur (non constant) de type void (autrement dit un void *), c'est à dire à un pointeur susceptible de pointer vers "n'importe quel type de donnée" en mémoire dont le contenu est susceptible d'être modifié.

    Le nom lpBuffer nous indique que la donnée va servir de "tampon" dans lequel la fonction mettra le résultat. C'est à dire qu'il doit s'agir d'un espace mémoire contigu suffisant que pour pouvoir y "loger" toutes les données que l'on souhaite copier.

    Le quatrième paramètre [in] SIZE_T nSize nous indique toujours qu'il s'agit d'une donnée d'entrée, qui sera de type SIZE_T, c'est à dire de l'alias de type correspondant au type "le plus adéquat" susceptible d'être utilisé pour représenter une taille pour "l'ensemble du système".

    Comme la notion de taille n'implique aucune décimale, nous pouvons dire avec certitude qu'il s'agit d'un type entier, et comme il n'y a pas de sens à représenter une taille négative, nous pouvons également partir du principe qu'il s'agit une valeur non signée.
    Quant à savoir exactement à quel type correspond SIZE_T, c'est une autre histoire (et d'ailleurs, on s'en fout, en fait), car cela pourrait tout aussi bien être un unsigned int, un unsigned long ou un unsigned long long.

    Dans le doute, nous serions bien inspiré d'utiliser simplement SIZE_T

    Le nom nSize nous confirme qu'il s'agit bien d'un entier ((i)n(teger)Size) et nous indique en outre qu'il représente une taille. De quoi exactement ben, du buffer fourni comme paramètre précédent, pardi

    Enfin, le dernier paramètre [out] SIZE_T *lpNumberOfBytesRead nous indique qu'il s'agit d'un paramètre de sortie qui est de type SIZE_T *, c'est à dire d'un pointeur sur une donnée de type SIZE_T.

    Et le nom lpNumberOfByteReads nous indique qu'il nous permettra de récupérer (si on le souhaite)... le nombre de bytes( d'octets) qui ont été lus.

    A partir de là, ben "YAPUKA" agir en conséquence de toutes les informations que l'on a pu tirer de ce prototype:

    Il nous faut un handle sur le processus que l'on veut analyser, ainsi que "l'adresse de départ" à partir de laquelle on souhaite extraire les informations, un "tampon" suffisamment large que pour contenir les informations qui seront extraite, la taille précise de ce tampon et, enfin un pointeur sur une donnée entière (non signé) permettant de savoir combien d'octets ont été réellement lus.

    Une fois que tu disposeras de tout cela, tu n'aura plus qu'à appeler la fonction en lui transmettant ces informations, et tu récupérera le contenu du processus en question dans le buffer.

    Tu pourras alors en faire "ce que tu veux"
    A méditer: La solution la plus simple est toujours la moins compliquée
    Ce qui se conçoit bien s'énonce clairement, et les mots pour le dire vous viennent aisément. Nicolas Boileau
    Compiler Gcc sous windows avec MinGW
    Coder efficacement en C++ : dans les bacs le 17 février 2014
    mon tout nouveau blog

Discussions similaires

  1. Problème de debugger avec Ganymede
    Par felix79 dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 04/08/2009, 14h26
  2. [AS3] Problème de debugger
    Par WhiteD dans le forum ActionScript 3
    Réponses: 2
    Dernier message: 04/08/2008, 00h53
  3. Réponses: 11
    Dernier message: 05/09/2007, 18h23
  4. Problèmes de debugger - Visual Studio 2005
    Par estebann10 dans le forum MFC
    Réponses: 3
    Dernier message: 15/02/2006, 00h26
  5. [Dev cpp] Problème pour debugger
    Par gl0be dans le forum Dev-C++
    Réponses: 5
    Dernier message: 03/12/2005, 20h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo