Skip to content

Commit 21ec879

Browse files
committed
better identification of arch type
1 parent 8adc6df commit 21ec879

File tree

1 file changed

+46
-33
lines changed

1 file changed

+46
-33
lines changed

lldbinit.py

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,19 @@ def get_arch():
196196
def get_frame():
197197
return lldb.debugger.GetSelectedTarget().process.selected_thread.GetSelectedFrame();
198198

199+
#handle all iXXX (i386/i686) cases
200+
def is_i386():
201+
arch = get_arch();
202+
if arch[0:1] == "i":
203+
return True;
204+
return False;
205+
206+
def is_x64():
207+
arch = get_arch();
208+
if arch == "x86_64":
209+
return True;
210+
return False;
211+
199212
def color_reset():
200213
output("\033[0m");
201214
def color_bold():
@@ -725,9 +738,9 @@ def reg32():
725738

726739
def print_registers():
727740
arch = get_arch();
728-
if arch == "i386":
741+
if is_i386():
729742
reg32();
730-
elif arch == "x86_64":
743+
elif is_x64():
731744
reg64();
732745

733746
def get_GPRs():
@@ -749,16 +762,16 @@ def HandleHookStopOnTarget(debugger, command, result, dict):
749762
GlobalListOutput = [];
750763

751764
arch = get_arch();
752-
if arch != "i386" and arch != "x86_64":
765+
if not is_i386() and not is_x64():
753766
#this is for ARM probably in the future... when I will need it...
754767
print("Unknown architecture : " + arch);
755768
return;
756769

757770
output("\n");
758771
color(COLOR_SEPARATOR);
759-
if arch == "i386":
772+
if is_i386():
760773
output("---------------------------------------------------------------------------------");
761-
elif arch == "x86_64":
774+
elif is_x64():
762775
output("-----------------------------------------------------------------------------------------------------------------------");
763776

764777
color_bold();
@@ -767,27 +780,27 @@ def HandleHookStopOnTarget(debugger, command, result, dict):
767780
print_registers();
768781

769782
color(COLOR_SEPARATOR);
770-
if arch == "i386":
783+
if is_i386():
771784
output("---------------------------------------------------------------------------------");
772-
elif arch == "x86_64":
785+
elif is_x64():
773786
output("-----------------------------------------------------------------------------------------------------------------------");
774787
color_bold();
775788
output("[code]\n");
776789
color_reset();
777790

778-
if arch == "i386":
791+
if is_i386():
779792
pc = get_register("eip");
780-
elif arch == "x86_64":
793+
elif is_x64():
781794
pc = get_register("rip");
782795

783796
#debugger.HandleCommand("disassemble --start-address=" + pc + " --count=8");
784797
res = lldb.SBCommandReturnObject();
785798
lldb.debugger.GetCommandInterpreter().HandleCommand("disassemble --start-address=" + pc + " --count=8", res)
786799
output(res.GetOutput());
787800
color(COLOR_SEPARATOR);
788-
if arch == "i386":
801+
if is_i386():
789802
output("---------------------------------------------------------------------------------------");
790-
elif arch == "x86_64":
803+
elif is_x64():
791804
output("-----------------------------------------------------------------------------------------------------------------------------");
792805
color_reset();
793806
output("\n");
@@ -891,9 +904,9 @@ def stepo(debugger, command, result, dict):
891904

892905
err = lldb.SBError();
893906
target = lldb.debugger.GetSelectedTarget();
894-
if arch == "i386":
907+
if is_i386():
895908
pc = lldb.SBAddress(int(get_register("eip"), 16), target);
896-
elif arch == "x86_64":
909+
elif is_x64():
897910
pc = lldb.SBAddress(int(get_register("rip"), 16), target);
898911

899912
inst = lldb.SBTarget.ReadInstructions(target, pc, 2 , "intel");
@@ -902,9 +915,9 @@ def stepo(debugger, command, result, dict):
902915
pc_inst = str(pc_inst).split()[1];
903916

904917
pc_inst = inst[0].GetMnemonic(target);
905-
if arch == "i386":
918+
if is_i386():
906919
pc = int(get_register("eip"), 16) + inst[0].GetByteSize();
907-
elif arch == "x86_64":
920+
elif is_x64():
908921
pc = int(get_register("rip"), 16) + inst[0].GetByteSize();
909922

910923
if "call" in pc_inst or "movs" in pc_inst or "stos" in pc_inst or "loop" in pc_inst or "cmps" in pc_inst:
@@ -922,9 +935,9 @@ def hexdump(addr, chars, sep, width ):
922935
chars = chars[width:]
923936
line = line.ljust( width, '\000' )
924937
arch = get_arch();
925-
if arch == "i386":
938+
if is_i386():
926939
szaddr = "0x%.08X" % addr;
927-
elif arch == "x86_64":
940+
elif is_x64():
928941
szaddr = "0x%.016lX" % addr;
929942
l.append("\033[1m%s :\033[0m %s%s \033[1m%s\033[0m" % (szaddr, sep.join( "%02X" % ord(c) for c in line ), sep, quotechars( line )));
930943
addr += 0x10;
@@ -964,10 +977,10 @@ def dd(debugger, command, result, dict):
964977
return;
965978

966979
color(BLUE);
967-
if arch == "i386":
980+
if is_i386():
968981
output("[0x0000:0x%.08X]" % value);
969982
output("------------------------------------------------------");
970-
elif arch == "x86_64":
983+
elif is_x64():
971984
output("[0x0000:0x%.016lX]" % value);
972985
output("------------------------------------------------------");
973986
color_bold();
@@ -978,9 +991,9 @@ def dd(debugger, command, result, dict):
978991
index = 0;
979992
while index < 0x100:
980993
data = struct.unpack("B"*16, membuff[index:index+0x10]);
981-
if arch == "i386":
994+
if is_i386:
982995
szaddr = "0x%.08X" % value;
983-
elif arch == "x86_64":
996+
elif is_x64:
984997
szaddr = "0x%.016lX" % value;
985998
fmtnice = "%.02X %.02X %.02X %.02X %.02X %.02X %.02X %.02X"
986999
fmtnice = fmtnice + " - " + fmtnice;
@@ -1039,10 +1052,10 @@ def dq(debugger, command, result, dict):
10391052
return;
10401053

10411054
color(BLUE);
1042-
if arch == "i386":
1055+
if is_i386():
10431056
output("[0x0000:0x%.08X]" % value);
10441057
output("-------------------------------------------------------");
1045-
elif arch == "x86_64":
1058+
elif is_x64():
10461059
output("[0x0000:0x%.016lX]" % value);
10471060
output("-------------------------------------------------------");
10481061
color_bold();
@@ -1052,9 +1065,9 @@ def dq(debugger, command, result, dict):
10521065
index = 0;
10531066
while index < 0x100:
10541067
(mem0, mem1, mem2, mem3) = struct.unpack("QQQQ", membuff[index:index+0x20]);
1055-
if arch == "i386":
1068+
if is_i386():
10561069
szaddr = "0x%.08X" % value;
1057-
elif arch == "x86_64":
1070+
elif is_x64():
10581071
szaddr = "0x%.016lX" % value;
10591072
output("\033[1m%s :\033[0m %.016lX %.016lX %.016lX %.016lX" % (szaddr, mem0, mem1, mem2, mem3));
10601073
if index + 0x20 != 0x100:
@@ -1091,10 +1104,10 @@ def ddword(debugger, command, result, dict):
10911104
return;
10921105

10931106
color(BLUE);
1094-
if arch == "i386":
1107+
if is_i386():
10951108
output("[0x0000:0x%.08X]" % value);
10961109
output("----------------------------------------");
1097-
elif arch == "x86_64":
1110+
elif is_x64():
10981111
output("[0x0000:0x%.016lX]" % value);
10991112
output("----------------------------------------");
11001113
color_bold();
@@ -1104,9 +1117,9 @@ def ddword(debugger, command, result, dict):
11041117
index = 0;
11051118
while index < 0x100:
11061119
(mem0, mem1, mem2, mem3) = struct.unpack("IIII", membuff[index:index+0x10]);
1107-
if arch == "i386":
1120+
if is_i386():
11081121
szaddr = "0x%.08X" % value;
1109-
elif arch == "x86_64":
1122+
elif is_x64():
11101123
szaddr = "0x%.016lX" % value;
11111124
output("\033[1m%s :\033[0m %.08X %.08X %.08X %.08X \033[1m%s\033[0m" % (szaddr,
11121125
mem0,
@@ -1148,10 +1161,10 @@ def dw(debugger, command, result, dict):
11481161
return;
11491162

11501163
color(BLUE);
1151-
if arch == "i386":
1164+
if is_i386():
11521165
output("[0x0000:0x%.08X]" % value);
11531166
output("--------------------------------------------");
1154-
elif arch == "x86_64":
1167+
elif is_x64():
11551168
output("[0x0000:0x%.016lX]" % value);
11561169
output("--------------------------------------------");
11571170
color_bold();
@@ -1161,9 +1174,9 @@ def dw(debugger, command, result, dict):
11611174
index = 0;
11621175
while index < 0x100:
11631176
data = struct.unpack("HHHHHHHH", membuff[index:index+0x10]);
1164-
if arch == "i386":
1177+
if is_i386():
11651178
szaddr = "0x%.08X" % value;
1166-
elif arch == "x86_64":
1179+
elif is_x64():
11671180
szaddr = "0x%.016lX" % value;
11681181
output("\033[1m%s :\033[0m %.04X %.04X %.04X %.04X %.04X %.04X %.04X %.04X \033[1m%s\033[0m" % (szaddr,
11691182
data[0],

0 commit comments

Comments
 (0)