TA的每日心情 | 奋斗 2019-8-1 16:41 |
---|
签到天数: 1014 天 连续签到: 1 天 [LV.10]以坛为家III
|
发表于 2015-7-20 11:38:10
|
显示全部楼层
另外两个函数
这其实实现的就是双击jink.exe正常情况下看到的
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx@1
int v4; // eax@8
const char *v5; // ecx@20
int v7; // esi@32
char v8; // al@32
const char *v9; // [sp-8h] [bp-2F4h]@10
int v10; // [sp-4h] [bp-2F0h]@10
char *v11; // [sp+Ch] [bp-2E0h]@8
char v12; // [sp+13h] [bp-2D9h]@1
int v13; // [sp+14h] [bp-2D8h]@8
int v14; // [sp+18h] [bp-2D4h]@1
char v15; // [sp+1Ch] [bp-2D0h]@1
int v16; // [sp+1Dh] [bp-2CFh]@1
__int16 v17; // [sp+21h] [bp-2CBh]@1
char v18; // [sp+23h] [bp-2C9h]@1
char Dest[4]; // [sp+24h] [bp-2C8h]@3
char v20; // [sp+2Eh] [bp-2BEh]@3
__int16 v21; // [sp+EAh] [bp-202h]@3
char v22; // [sp+ECh] [bp-200h]@27
v16 = 0;
v17 = 0;
v3 = 0;
v15 = 0;
v18 = 0;
v14 = 0;
v12 = 0;
sub_40E890("SEGGER J-Link Commander V%d.%02d%s ('?' for help)\n", 4, 34, &v15);
sub_40E890("Compiled Aug 26 2011 18:24:47\n");
if ( argc > 1 )
{
if ( !sub_407530(argv[1], "ip") )
{
strcpy(Dest, "localhost");
memset(&v20, 0, 0xBCu);
v21 = 0;
if ( argc > 2 )
strncpy(Dest, argv[2], 0xC8u);
sub_40E890("Connecting via TCP/IP to %s\n", Dest);
JLINKARM_SelectIP(Dest, 0);
goto LABEL_12;
}
if ( !sub_407530(argv[1], "SelectEmuBySN") )
{
if ( argc <= 2 )
goto LABEL_12;
v11 = (char *)argv[2];
sub_401870(&v11, &v13);
v4 = JLINKARM_EMU_SelectByUSBSN(v13);
if ( v4 >= 0 )
{
sub_40E890("Emulator %d with USB serial number %d selected.\n", v4, v13);
goto LABEL_12;
}
v10 = v13;
v9 = "Could not find emulator with USB serial number %d.\n";
LABEL_11:
sub_40E890(v9, v10);
goto LABEL_12;
}
if ( sub_407530(argv[1], "usb") )
{
if ( argc > 2 || !sub_407530(argv[1], "/?") )
{
sub_40E890("USAGE:\n");
sub_40E890(" JLink [filename]\n\n");
sub_40E890(" NOTE: If a filename is specified, J-Link Commander\n");
sub_40E890(" will run in script mode.\n");
return 0;
}
}
else
{
if ( argc > 2 )
{
v5 = argv[2];
v13 = 0;
v11 = (char *)v5;
sub_401590((int)&v11);
if ( *v11 )
sub_401870(&v11, &v13);
sub_40E890("Connecting to J-Link via USB (Port: %d)\n", v13);
if ( (unsigned __int8)JLINKARM_SelectUSB(v13) )
{
v10 = v13;
v9 = "Can not connect via USB (Port: %d)\n";
goto LABEL_11;
}
}
}
}
LABEL_12:
timeBeginPeriod(1u);
if ( argc != 2 || !sub_407530(argv[1], "ip") || !sub_407530(argv[1], "usb") || !sub_407530(argv[1], "SelectEmuBySN") )
{
LABEL_31:
sub_402D90();
if ( !v12 )
{
LABEL_35:
sub_40D680();
goto LABEL_36;
}
LABEL_32:
sub_40E890("Processing script file...\n");
v8 = sub_40D300(v3);
v7 = v8;
v14 = v8;
sub_40E890("\nScript processing completed.\n\n");
if ( v3 )
sub_40EB10((LPVOID)v3);
if ( v7 )
goto LABEL_36;
goto LABEL_35;
}
v3 = sub_40D550(argv[1]);
if ( v3 )
{
v12 = 1;
v11 = (char *)v3;
if ( (unsigned __int8)sub_40D1C0(&v11, &v22, 512) )
{
v11 = &v22;
if ( !(unsigned __int8)sub_404270(&v11, "usb")
|| !(unsigned __int8)sub_404270(&v11, "ip")
|| !(unsigned __int8)sub_404270(&v11, "SelectEmuBySN") )
goto LABEL_32;
}
goto LABEL_31;
}
v14 = 1;
LABEL_36:
timeEndPeriod(1u);
return v14;
}
_________________________________________________________________
char __cdecl sub_402D90()
{
const char *v0; // eax@1
signed int v2; // ecx@3
int v3; // edi@3
char v4; // zf@5
signed int v5; // ecx@7
signed int v6; // ecx@7
unsigned int v7; // ebx@7
char *v8; // edi@7
const void *v9; // esi@7
char v10; // zf@9
signed int v11; // ecx@11
int v12; // edi@11
char v13; // zf@13
unsigned int v14; // edx@15
signed int v15; // ecx@15
signed int v16; // ecx@15
char *v17; // edi@15
const void *v18; // esi@15
char v19; // zf@17
void *v20; // eax@19
int v21; // ST2C_4@20
int v22; // eax@23
int v23; // edx@28
int v24; // ecx@28
int v25; // edi@29
const char *v26; // [sp-10h] [bp-72Ch]@31
unsigned int v27; // [sp+4h] [bp-718h]@29
unsigned int v28; // [sp+8h] [bp-714h]@37
int v29; // [sp+Ch] [bp-710h]@38
char FileName; // [sp+14h] [bp-708h]@3
int v31; // [sp+118h] [bp-604h]@20
int v32; // [sp+11Ch] [bp-600h]@20
int v33; // [sp+120h] [bp-5FCh]@20
__int16 v34; // [sp+124h] [bp-5F8h]@20
char Dest; // [sp+21Ch] [bp-500h]@11
char v36; // [sp+61Ch] [bp-100h]@11
JLINKARM_EnableLog(sub_401050);
JLINKARM_SetLogFile("C:\\JLink.log");
JLINKARM_SetWarnOutHandler(sub_403190);
v0 = (const char *)JLINKARM_OpenEx(sub_401050, sub_403170);
if ( v0 )
{
sub_40E890(v0);
sub_40E890((const char *)L"\n");
sub_403160(0x5DCu);
return 1;
}
sub_4039B0(&FileName);
v3 = (int)"Default.ini";
v2 = -1;
do
{
if ( !v2 )
break;
v4 = *(_BYTE *)v3++ == 0;
--v2;
}
while ( !v4 );
v6 = ~v2;
v9 = (const void *)(v3 - v6);
v7 = v6;
v8 = &FileName;
v5 = -1;
do
{
if ( !v5 )
break;
v10 = *v8++ == 0;
--v5;
}
while ( !v10 );
memcpy(v8 - 1, v9, v7);
sprintf(&Dest, "projectfile = %s", &FileName);
((void (__cdecl *)(char *, char *, signed int))JLINKARM_ExecCommand)(&Dest, &v36, 256);
sub_4039B0(&FileName);
v12 = (int)"Default.c";
v11 = -1;
do
{
if ( !v11 )
break;
v13 = *(_BYTE *)v12++ == 0;
--v11;
}
while ( !v13 );
v16 = ~v11;
v18 = (const void *)(v12 - v16);
v17 = &FileName;
v14 = v16;
v15 = -1;
do
{
if ( !v15 )
break;
v19 = *v17++ == 0;
--v15;
}
while ( !v19 );
memcpy(v17 - 1, v18, v14);
v20 = (void *)sub_40E2C0(&FileName, 5);
if ( v20 != (void *)-1 )
{
Dest = 0;
sub_40E350(v20);
v31 = dword_41A3B4;
v33 = dword_41A3BC;
v34 = word_41A3C0;
v32 = dword_41A3B8;
strcpy((char *)&v31 + strlen((const char *)&v31) - 1, &FileName);
JLINKARM_ExecCommand(&v31, &Dest, 1024, v21);
}
JLINKARM_SetErrorOutHandler(sub_403170);
JLINKARM_EnableLog(sub_4031B0);
JLINKARM_SetInitRegsOnReset(0);
sub_401130();
sub_401090();
if ( !JLINKARM_HasError() || JLINKARM_HasError() == -259 )
{
v22 = JLINKARM_GetSN();
sub_40E890("S/N: %d \n", v22);
JLINKARM_GetOEMString(&Dest);
if ( strlen(&Dest) != 1 )
sub_40E890("OEM: %s \n", &Dest);
JLINKARM_GetFeatureString(&Dest);
if ( strlen(&Dest) != 1 )
sub_40E890("Feature(s): %s \n", &Dest);
}
if ( !JLINKARM_HasError() )
{
if ( sub_403830() )
{
v25 = sub_4038F0(&v27);
if ( v25 != -1 )
{
sub_40E890("IP-Addr.: ");
if ( v25 == 1 )
{
v26 = "No configuration received via DHCP\n";
}
else
{
sub_40E890("%d.%d.%d.%d", v27 >> 24, BYTE2(v27), BYTE1(v27), (unsigned __int8)v27);
if ( v25 == 2 )
v26 = " (DHCP)\n";
else
v26 = " (user assigned)\n";
}
sub_40E890(v26);
}
}
if ( JLINKARM_GetEmuCaps(v24, v23) & 0x40 )
{
JLINKARM_TRACE_Control(20, &v28);
sub_40E890("ETM support, Trace buffer size: %dKB\n", v28 >> 10);
}
if ( !JLINKARM_GetHWStatus(&v29) )
sub_40E890(
"VTarget = %d.%.3dV\n",
((unsigned int)(274877907 * (unsigned __int64)(unsigned __int16)v29 >> 32) >> 31)
+ ((signed int)(274877907 * (unsigned __int64)(unsigned __int16)v29 >> 32) >> 6),
(unsigned __int16)v29 % 1000);
JLINKARM_SetSpeed(100);
if ( (_WORD)v29 > 0x1F4u )
{
if ( (unsigned __int8)sub_4031F0() )
{
JLINKARM_ClrError();
JLINKARM_SetSpeed(4);
sub_4031F0();
return 0;
}
sub_403760();
}
}
return 0;
}
|
|