逆向-beginners之结构体-CPU信息

#include <stdio.h>

#ifdef GNUC

static inline void cpuid(int code, int *a, int *b, int *c, int *d)

{

__asm volatile("cpuid":"=a"(*a), "=b"(*b), "=c"(*c), "=d"(*d):"a"(code));

}

#endif

#ifdef _MSC_VER

#include <intrin.h>

#endif

struct cpuid_1_eax

{

unsigned int stepping:4;

unsigned int model:4;

unsigned int family_id:4;

unsigned int processor_type:2;

unsigned int reserved1:2;

unsigned int extended_model_id:4;

unsigned int extended_family_id:8;

unsigned int reserved2:4;

};

int main()

{

struct cpuid_1_eax * tmp;

int b[4];

#ifdef _MSC_VER

__cpuid(b, 1);

#endif

#ifdef GNUC

cpuid(1, &b[0], &b[1], &b[2], &b[3]);

#endif

tmp = (struct cpuid_1_eax *) &b[0];

printf("stepping=%d\n", tmp->stepping);

printf("model=%d\n", tmp->model);

printf("family_id=%d\n", tmp->family_id);

printf("processor_type=%d\n", tmp->processor_type);

printf("extended_model_id=%d\n", tmp->extended_model_id);

printf("extended_family_id=%d\n", tmp->extended_family_id);

return 0;

}

#if 0

/*

* intel

*/

0000000000001169 <cpuid>:

1169: 55 push %rbp // rsp=0x7fffffffe180 rbp=0x7fffffffe1c0

116a: 48 89 e5 mov %rsp,%rbp // rsp=0x7fffffffe180 rbp=0x7fffffffe180

116d: 53 push %rbx // rsp=0x7fffffffe178 rbp=0x7fffffffe180

116e: 89 7d f4 mov %edi,-0xc(%rbp) // edi=1 (rbp-0xc)=0x7fffffffe174:0x555552e000000001

1171: 48 89 75 e8 mov %rsi,-0x18(%rbp) // rsi=0x7fffffffe1a0 (rbp-0x18)=0x7fffffffe168:0x00007fffffffe1a0

1175: 48 89 55 e0 mov %rdx,-0x20(%rbp) // rdx=0x7fffffffe1a4 (rbp-0x20)=0x7fffffffe160:0x00007fffffffe1a4

1179: 48 89 4d d8 mov %rcx,-0x28(%rbp) // rcx=0x7fffffffe1a8 (rbp-0x28)=0x7fffffffe158:0x00007fffffffe1a8

117d: 4c 89 45 d0 mov %r8,-0x30(%rbp) // r8=0x7fffffffe1ac (rbp-0x30)=0x7fffffffe150:0x00007fffffffe1ac

1181: 8b 45 f4 mov -0xc(%rbp),%eax // eax=1

1184: 0f a2 cpuid

1186: 89 de mov %ebx,%esi // esi=0x18400800

1188: 89 c7 mov %eax,%edi // edi=0x50657

118a: 48 8b 45 e8 mov -0x18(%rbp),%rax // rax=0x7fffffffe1a0

118e: 89 38 mov %edi,(%rax) // (rax)=0x7fffffffe1a0:0x0000000000050657

1190: 48 8b 45 e0 mov -0x20(%rbp),%rax // rax=0x7fffffffe1a4

1194: 89 30 mov %esi,(%rax) // (rax)=0x7fffffffe1a4:0x5555508018400800

1196: 48 8b 45 d8 mov -0x28(%rbp),%rax // rax=0x7fffffffe1a8

119a: 89 08 mov %ecx,(%rax) // (rax)=0x7fffffffe1a8:0x000055557ffefbff ecx=0x7ffefbff

119c: 48 8b 45 d0 mov -0x30(%rbp),%rax // rax=0x7fffffffe1ac

11a0: 89 10 mov %edx,(%rax) // (rax)=0x7fffffffe1ac:0xffffe2b0bfebfbff edx=0xbfebfbff

11a2: 90 nop // rsp=0x7fffffffe178 rbp=0x7fffffffe180

11a3: 5b pop %rbx // rsp=0x7fffffffe180 rbp=0x7fffffffe180

11a4: 5d pop %rbp // rsp=0x7fffffffe188 rbp=0x7fffffffe1c0

11a5: c3 retq // rsp=0x7fffffffe190 rbp=0x7fffffffe1c0 retq 相当于 : pop %rip

00000000000011a6 <main>:

11a6: f3 0f 1e fa endbr64 // rsp=0x7fffffffe1c8 rbp=0x0

11aa: 55 push %rbp // rsp=0x7fffffffe1c0

11ab: 48 89 e5 mov %rsp,%rbp // rsp=0x7fffffffe1c0 rbp=0x7fffffffe1c0

11ae: 48 83 ec 30 sub $0x30,%rsp // rsp=0x7fffffffe190 rbp=0x7fffffffe1c0

11b2: 64 48 8b 04 25 28 00 mov %fs:0x28,%rax // rax=0xc6a79e60e6de8500

11b9: 00 00

11bb: 48 89 45 f8 mov %rax,-0x8(%rbp) // (rbp-0x8)=0x7fffffffe1b8: 0xc6a79e60e6de8500

11bf: 31 c0 xor %eax,%eax // eax=0

11c1: 48 8d 45 e0 lea -0x20(%rbp),%rax // rax=rbp-0x20=0x7fffffffe1a0

11c5: 48 8d 70 0c lea 0xc(%rax),%rsi // rsi=rbp-0x20+0xc=0x7fffffffe1a0+0xc=0x7fffffffe1ac

11c9: 48 8d 45 e0 lea -0x20(%rbp),%rax // rax=rbp-0x20=0x7fffffffe1a0

11cd: 48 8d 48 08 lea 0x8(%rax),%rcx // rcx=rbp-0x20+0x8=0x7fffffffe1a8

11d1: 48 8d 45 e0 lea -0x20(%rbp),%rax // rax=rbp-0x20=0x7fffffffe1a0

11d5: 48 8d 50 04 lea 0x4(%rax),%rdx // rdx=rbp-0x20+0x4=0x7fffffffe1a4

11d9: 48 8d 45 e0 lea -0x20(%rbp),%rax // rax=rbp-0x20=0x7fffffffe1a0

11dd: 49 89 f0 mov %rsi,%r8 // r8=rbp-0x20+0xc=0x7fffffffe1ac

11e0: 48 89 c6 mov %rax,%rsi // rsi=rbp-0x20=0x7fffffffe1a0

11e3: bf 01 00 00 00 mov $0x1,%edi // edi=1

11e8: e8 7c ff ff ff callq 1169 <cpuid> // cpuid(edi, rsi, rdx, rcx, r8) (1, 0x7fffffffe1a0, 0x7fffffffe1a4, 0x7fffffffe1a8, 0x7fffffffe1ac)

// rsp=0x7fffffffe188 rbp=0x7fffffffe1c0

11ed: 48 8d 45 e0 lea -0x20(%rbp),%rax // rsp=0x7fffffffe190 rbp=0x7fffffffe1c0 rax=0x7fffffffe1a0 rbp-0x20=0x7fffffffe1a0:0x1840080000050657

11f1: 48 89 45 d8 mov %rax,-0x28(%rbp) // (rbp-0x28)=0x7fffffffe1a0 rax=0x7fffffffe1a0 rbp-0x28=0x7fffffffe198:0x00007fffffffe1a0

11f5: 48 8b 45 d8 mov -0x28(%rbp),%rax // rax=(rbp-0x28)=0x7fffffffe1a0 rbp-0x28=0x7fffffffe198:0x00007fffffffe1a0

11f9: 0f b6 00 movzbl (%rax),%eax // eax=0x57 (rax)=(rbp-0x28)=(0x7fffffffe1a0)=0x7fffffffe1a0:0x1840080000050657

11fc: 83 e0 0f and $0xf,%eax // eax=eax&0xf=0x7 /* 取字节低四位 */

11ff: 0f b6 c0 movzbl %al,%eax // eax=al=0x7

1202: 89 c6 mov %eax,%esi // esi=eax=0x7

1204: 48 8d 3d f9 0d 00 00 lea 0xdf9(%rip),%rdi # 2004 <_IO_stdin_used+0x4>

120b: b8 00 00 00 00 mov $0x0,%eax

1210: e8 5b fe ff ff callq 1070 <printf@plt> // rsp=0x7fffffffe190 rbp=0x7fffffffe1c0

1215: 48 8b 45 d8 mov -0x28(%rbp),%rax // rax=(rbp-0x28)=rbp-0x20=0x7fffffffe1a0

1219: 0f b6 00 movzbl (%rax),%eax // eax=(rax)=(rbp-0x20)=0x57

121c: c0 e8 04 shr $0x4,%al // al=al>>4=0x5 /* 取字节高四位 */

121f: 0f b6 c0 movzbl %al,%eax // eax=al=0x5

1222: 89 c6 mov %eax,%esi // esi=eax=0x5

1224: 48 8d 3d e6 0d 00 00 lea 0xde6(%rip),%rdi # 2011 <_IO_stdin_used+0x11>

122b: b8 00 00 00 00 mov $0x0,%eax

1230: e8 3b fe ff ff callq 1070 <printf@plt>

1235: 48 8b 45 d8 mov -0x28(%rbp),%rax // rax=0x7fffffffe1a0 x/xg 0x7fffffffe1a0:0x1840080000050657 x/8xb 0x7fffffffe1a0:0x57 0x06 0x05 0x00 0x00 0x08 0x40 0x18

1239: 0f b6 40 01 movzbl 0x1(%rax),%eax // eax=0x6 (rax+0x1)=0x7fffffffe1a0+1=0x7fffffffe1a1=0x6

123d: 83 e0 0f and $0xf,%eax // eax=eax&0xf=0x6

1240: 0f b6 c0 movzbl %al,%eax // eax=al=0x6

1243: 89 c6 mov %eax,%esi // esi=0x6

1245: 48 8d 3d cf 0d 00 00 lea 0xdcf(%rip),%rdi # 201b <_IO_stdin_used+0x1b>

124c: b8 00 00 00 00 mov $0x0,%eax

1251: e8 1a fe ff ff callq 1070 <printf@plt>

1256: 48 8b 45 d8 mov -0x28(%rbp),%rax // rax=0x7fffffffe1a0

125a: 0f b6 40 01 movzbl 0x1(%rax),%eax // eax=(rax+0x1)=0x6

125e: c0 e8 04 shr $0x4,%al // al=al>>4=0x0

1261: 83 e0 03 and $0x3,%eax // eax&=3=0x0

1264: 0f b6 c0 movzbl %al,%eax // eax=0x0

1267: 89 c6 mov %eax,%esi

1269: 48 8d 3d b9 0d 00 00 lea 0xdb9(%rip),%rdi # 2029 <_IO_stdin_used+0x29>

1270: b8 00 00 00 00 mov $0x0,%eax

1275: e8 f6 fd ff ff callq 1070 <printf@plt>

127a: 48 8b 45 d8 mov -0x28(%rbp),%rax // rax=0x7fffffffe1a0

127e: 0f b6 40 02 movzbl 0x2(%rax),%eax // eax=(rax+0x2)=0x5

1282: 83 e0 0f and $0xf,%eax // eax=0x5

1285: 0f b6 c0 movzbl %al,%eax // eax=0x5

1288: 89 c6 mov %eax,%esi

128a: 48 8d 3d ab 0d 00 00 lea 0xdab(%rip),%rdi # 203c <_IO_stdin_used+0x3c>

1291: b8 00 00 00 00 mov $0x0,%eax

1296: e8 d5 fd ff ff callq 1070 <printf@plt>

129b: 48 8b 45 d8 mov -0x28(%rbp),%rax // rax=0x7fffffffe1a0

129f: 0f b7 40 02 movzwl 0x2(%rax),%eax // eax=0x5

12a3: 66 c1 e8 04 shr $0x4,%ax // ax=0x0

12a7: 80 e4 ff and $0xff,%ah // ah=0x0

12aa: 0f b6 c0 movzbl %al,%eax // eax=0x0

12ad: 89 c6 mov %eax,%esi

12af: 48 8d 3d 9c 0d 00 00 lea 0xd9c(%rip),%rdi # 2052 <_IO_stdin_used+0x52>

12b6: b8 00 00 00 00 mov $0x0,%eax

12bb: e8 b0 fd ff ff callq 1070 <printf@plt>

12c0: b8 00 00 00 00 mov $0x0,%eax

12c5: 48 8b 55 f8 mov -0x8(%rbp),%rdx

12c9: 64 48 33 14 25 28 00 xor %fs:0x28,%rdx

12d0: 00 00

12d2: 74 05 je 12d9 <main+0x133>

12d4: e8 87 fd ff ff callq 1060 <__stack_chk_fail@plt>

12d9: c9 leaveq

12da: c3 retq

12db: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)

/*

* arm

*/

#endif

相关推荐
Crossoads2 天前
【汇编语言】端口 —— 「从端口到时间:一文了解CMOS RAM与汇编指令的交汇」
android·java·汇编·深度学习·网络协议·机器学习·汇编语言
雪碧透心凉_5 天前
8086汇编(16位汇编)学习笔记00.DEBUG命令使用解析及范例大全
汇编
C66668888 天前
C#多线程
开发语言·汇编·c#
傻童:CPU8 天前
汇编源程序的理解
汇编
木槿718 天前
软件包git没有可安装候选
汇编·git
ok0609 天前
各种开源汇编、反汇编引擎的非专业比较
汇编·开源
roboko_9 天前
MIPS指令集(一)基本操作
汇编
Crossoads9 天前
【汇编语言】内中断(三) —— 中断探险:从do0到特殊响应的奇妙旅程
android·开发语言·javascript·网络·汇编·单片机·机器学习
染指111010 天前
49.第二阶段x86游戏实战2-鼠标点击call深追二叉树
汇编·c++·windows·游戏安全·反游戏外挂·游戏逆向
程序leo源12 天前
深入理解指针
android·c语言·开发语言·汇编·c++·青少年编程·c#