mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
Candidate release of source code.
This commit is contained in:
parent
db81e6b3b0
commit
79d8f164f8
12449 changed files with 2800756 additions and 16 deletions
63
GhidraDocs/GhidraClass/Advanced/Examples/Makefile
Normal file
63
GhidraDocs/GhidraClass/Advanced/Examples/Makefile
Normal file
|
@ -0,0 +1,63 @@
|
|||
CC=gcc
|
||||
CXX=g++
|
||||
AS=gcc
|
||||
|
||||
OUTDIR := out
|
||||
|
||||
EXAMPLES := dataMutability override custom switch sharedReturn jumpWithinInstruction opaque globalRegVars.so setRegister compilerVsDecompiler noReturn createStructure animals ldiv inline
|
||||
|
||||
$(EXAMPLES): | $(OUTDIR)
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir -p $(OUTDIR)
|
||||
|
||||
all: $(EXAMPLES)
|
||||
|
||||
dataMutability: dataMutability.c
|
||||
$(CC) dataMutability.c -o $(OUTDIR)/dataMutability -O2
|
||||
|
||||
override: override.c
|
||||
$(CC) override.c -o $(OUTDIR)/override.so -shared -fPIC -O2
|
||||
|
||||
custom: custom.c
|
||||
$(CC) custom.c -o $(OUTDIR)/custom -fomit-frame-pointer
|
||||
|
||||
switch: switch.s
|
||||
$(AS) switch.s -o $(OUTDIR)/switch
|
||||
|
||||
jumpWithinInstruction: jumpWithinInstruction.c
|
||||
$(CC) jumpWithinInstruction.c -o $(OUTDIR)/jumpWithinInstruction -O2 -fno-inline
|
||||
|
||||
sharedReturn: sharedReturn.c
|
||||
$(CC) sharedReturn.c -o $(OUTDIR)/sharedReturn -O2 -fno-inline
|
||||
strip -s $(OUTDIR)/sharedReturn
|
||||
|
||||
opaque: opaque.c
|
||||
$(CC) opaque.c -o $(OUTDIR)/opaque -O2
|
||||
|
||||
globalRegVars.so: globalRegVars.c
|
||||
$(CC) globalRegVars.c -o $(OUTDIR)/globalRegVars.so -fPIC -shared -O2
|
||||
|
||||
setRegister: setRegister.c
|
||||
$(CC) setRegister.c -o $(OUTDIR)/setRegister -O2 -fno-inline
|
||||
|
||||
compilerVsDecompiler: compilerVsDecompiler.s
|
||||
$(AS) compilerVsDecompiler.s -o $(OUTDIR)/compilerVsDecompiler
|
||||
|
||||
noReturn: noReturn.c
|
||||
$(CC) noReturn.c -o $(OUTDIR)/noReturn -shared -fPIC
|
||||
|
||||
createStructure: createStructure.c
|
||||
$(CC) createStructure.c -o $(OUTDIR)/createStructure -shared -fPIC -O2
|
||||
|
||||
animals: animals.cpp
|
||||
$(CXX) animals.cpp -o $(OUTDIR)/animals -O2 -std=c++11
|
||||
|
||||
ldiv: ldiv.c
|
||||
$(CC) ldiv.c -o $(OUTDIR)/ldiv -O2
|
||||
|
||||
inline: inline.s
|
||||
$(AS) inline.s -o $(OUTDIR)/inline
|
||||
|
||||
clean:
|
||||
rm -rf $(OUTDIR)
|
85
GhidraDocs/GhidraClass/Advanced/Examples/animals.cpp
Executable file
85
GhidraDocs/GhidraClass/Advanced/Examples/animals.cpp
Executable file
|
@ -0,0 +1,85 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include<string>
|
||||
#include<iostream>
|
||||
|
||||
class Animal{
|
||||
protected:
|
||||
unsigned long weight;
|
||||
unsigned long age;
|
||||
std::string name;
|
||||
public:
|
||||
Animal(long w, long a, std::string n){
|
||||
weight = w;
|
||||
age = a;
|
||||
name = n;
|
||||
}
|
||||
void printInfo(){
|
||||
std::cout << "Name: " << name << ", age: " << age << ", weight: " << weight << '\n';
|
||||
}
|
||||
std::string getName(void){ return name;}
|
||||
virtual void printSound(void) = 0;
|
||||
virtual void printSpecificFact(void) = 0;
|
||||
virtual int getAnimalAge(void) = 0;
|
||||
};
|
||||
|
||||
class Cat : public Animal {
|
||||
protected:
|
||||
unsigned long numLives;
|
||||
public:
|
||||
Cat(unsigned long w, unsigned long a, std::string n, long num) : Animal(w,a,n){
|
||||
numLives = num;
|
||||
}
|
||||
void printSound(void) { std::cout << name << " says MEOW!\n";}
|
||||
void printSpecificFact(void){ std::cout << name + " has " + std::to_string(numLives) + " lives";}
|
||||
int getAnimalAge(void){ return age * 4 + 20;}
|
||||
};
|
||||
|
||||
class Dog : public Animal {
|
||||
protected:
|
||||
bool wantsWalk;
|
||||
public:
|
||||
Dog(unsigned long w, unsigned long a, std::string n): Animal(w,a,n){
|
||||
wantsWalk = true;
|
||||
}
|
||||
void printSound(void) {std::cout << name << " says BARK!\n";}
|
||||
void printSpecificFact(void) {std::cout << name + " wants a walk";}
|
||||
int getAnimalAge(void) {return age * 7;}
|
||||
};
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
Animal *a;
|
||||
if (argc % 2 == 0){
|
||||
a = new Cat(8,3,"Lord Meowington II",9);
|
||||
}
|
||||
else {
|
||||
a = new Dog(60, 5, "Pigblob 9000");
|
||||
}
|
||||
std::cout << '\n';
|
||||
a->printInfo();
|
||||
a->printSound();
|
||||
a->printSpecificFact();
|
||||
int animalAge = a->getAnimalAge();
|
||||
delete(a);
|
||||
return animalAge;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
109
GhidraDocs/GhidraClass/Advanced/Examples/compilerVsDecompiler.s
Normal file
109
GhidraDocs/GhidraClass/Advanced/Examples/compilerVsDecompiler.s
Normal file
|
@ -0,0 +1,109 @@
|
|||
.file "compilerVsDecompiler.c"
|
||||
.intel_syntax noprefix
|
||||
.text
|
||||
.p2align 4,,15
|
||||
.globl calls_memcmp
|
||||
.type calls_memcmp, @function
|
||||
calls_memcmp:
|
||||
.LFB3:
|
||||
.cfi_startproc
|
||||
mov rax, rdi
|
||||
mov rcx, rdx
|
||||
mov rdi, rsi
|
||||
cmp rdx, rdx
|
||||
mov rsi, rax
|
||||
repz cmpsb
|
||||
seta al
|
||||
setb dl
|
||||
sub al, dl
|
||||
movsx eax, al
|
||||
ret
|
||||
.cfi_endproc
|
||||
.LFE3:
|
||||
.size calls_memcmp, .-calls_memcmp
|
||||
.p2align 4,,15
|
||||
.globl calls_memcmp_fixed_len
|
||||
.type calls_memcmp_fixed_len, @function
|
||||
calls_memcmp_fixed_len:
|
||||
.LFB4:
|
||||
.cfi_startproc
|
||||
mov rax, rdi
|
||||
mov ecx, 8
|
||||
mov rdi, rsi
|
||||
mov rsi, rax
|
||||
repz cmpsb
|
||||
seta al
|
||||
setb dl
|
||||
sub al, dl
|
||||
movsx eax, al
|
||||
ret
|
||||
.cfi_endproc
|
||||
.LFE4:
|
||||
.size calls_memcmp_fixed_len, .-calls_memcmp_fixed_len
|
||||
.section .rodata.str1.8,"aMS",@progbits,1
|
||||
.align 8
|
||||
.LC0:
|
||||
.string "\nUsage: %s string1 string2 len\n\n"
|
||||
.section .rodata.str1.1,"aMS",@progbits,1
|
||||
.LC1:
|
||||
.string "\nres1: %d res2: %d\n\n"
|
||||
.section .text.startup,"ax",@progbits
|
||||
.p2align 4,,15
|
||||
.globl main
|
||||
.type main, @function
|
||||
main:
|
||||
.LFB2:
|
||||
.cfi_startproc
|
||||
push r12
|
||||
.cfi_def_cfa_offset 16
|
||||
.cfi_offset 12, -16
|
||||
cmp edi, 4
|
||||
push rbp
|
||||
.cfi_def_cfa_offset 24
|
||||
.cfi_offset 6, -24
|
||||
push rbx
|
||||
.cfi_def_cfa_offset 32
|
||||
.cfi_offset 3, -32
|
||||
mov rbx, rsi
|
||||
je .L4
|
||||
mov rsi, QWORD PTR [rsi]
|
||||
mov edi, OFFSET FLAT:.LC0
|
||||
xor eax, eax
|
||||
call printf
|
||||
.L5:
|
||||
pop rbx
|
||||
.cfi_remember_state
|
||||
.cfi_def_cfa_offset 24
|
||||
pop rbp
|
||||
.cfi_def_cfa_offset 16
|
||||
xor eax, eax
|
||||
pop r12
|
||||
.cfi_def_cfa_offset 8
|
||||
ret
|
||||
.L4:
|
||||
.cfi_restore_state
|
||||
mov rdi, QWORD PTR [rsi+24]
|
||||
mov edx, 10
|
||||
xor esi, esi
|
||||
call strtoul
|
||||
mov rbp, QWORD PTR [rbx+16]
|
||||
mov rbx, QWORD PTR [rbx+8]
|
||||
mov rdx, rax
|
||||
mov rsi, rbp
|
||||
mov rdi, rbx
|
||||
call calls_memcmp
|
||||
mov rsi, rbp
|
||||
mov r12d, eax
|
||||
mov rdi, rbx
|
||||
call calls_memcmp_fixed_len
|
||||
mov esi, r12d
|
||||
mov edx, eax
|
||||
mov edi, OFFSET FLAT:.LC1
|
||||
xor eax, eax
|
||||
call printf
|
||||
jmp .L5
|
||||
.cfi_endproc
|
||||
.LFE2:
|
||||
.size main, .-main
|
||||
.ident "GCC: (GNU) 4.8.5 20150623 (Red Hat 4.8.5-28)"
|
||||
.section .note.GNU-stack,"",@progbits
|
36
GhidraDocs/GhidraClass/Advanced/Examples/createStructure.c
Normal file
36
GhidraDocs/GhidraClass/Advanced/Examples/createStructure.c
Normal file
|
@ -0,0 +1,36 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include<stdlib.h>
|
||||
|
||||
typedef struct {
|
||||
long a;
|
||||
int b;
|
||||
char * c;
|
||||
short d;
|
||||
} exampleStruct;
|
||||
|
||||
typedef exampleStruct * exampleStructPtr;
|
||||
|
||||
|
||||
void setFirstAndThird(exampleStructPtr ptr, long x, char *str){
|
||||
ptr->a = x;
|
||||
ptr->c = str;
|
||||
}
|
||||
|
||||
void setSecondAndFourth(exampleStructPtr ptr, int y, short z){
|
||||
ptr->b = y;
|
||||
ptr->d = z;
|
||||
}
|
65
GhidraDocs/GhidraClass/Advanced/Examples/custom.c
Normal file
65
GhidraDocs/GhidraClass/Advanced/Examples/custom.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
//compile with fomit-frame-pointer
|
||||
//how to turn off inferred variable references
|
||||
|
||||
long sum(void);
|
||||
void diff(void);
|
||||
|
||||
int main(int argc, char **argv){
|
||||
asm(".intel_syntax noprefix");
|
||||
register long a asm ("r14");
|
||||
register long b asm ("r15");
|
||||
register long c asm ("rbx");
|
||||
asm(".att_syntax prefix");
|
||||
|
||||
a = strtol(argv[1], NULL, 10);
|
||||
b = strtol(argv[2], NULL, 10);
|
||||
long s = sum();
|
||||
printf("sum: %ld\n", s);
|
||||
asm(".intel_syntax noprefix");
|
||||
asm("push r15");
|
||||
asm("push r14");
|
||||
asm(".att_syntax prefix");
|
||||
diff();
|
||||
printf("diff: %ld\n",c);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
long sum(void){
|
||||
asm(".intel_syntax noprefix");
|
||||
asm("mov rax, r14");
|
||||
asm("add rax, r15");
|
||||
}
|
||||
|
||||
void diff(void){
|
||||
asm(".intel_syntax noprefix");
|
||||
asm("mov rbx, [rsp+8]");
|
||||
asm("sub rbx, [rsp+0x10]");
|
||||
asm("ret 16");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
37
GhidraDocs/GhidraClass/Advanced/Examples/dataMutability.c
Normal file
37
GhidraDocs/GhidraClass/Advanced/Examples/dataMutability.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
char * const readOnly = "This string can't be modified, so the decompiler will show it.";
|
||||
char *writeable = "This string might change, so the decompiler won't show it.";
|
||||
|
||||
volatile int status;
|
||||
|
||||
int counter;
|
||||
|
||||
int main(int argc, char **argv){
|
||||
printf("%s\n",readOnly);
|
||||
printf("%s\n",writeable);
|
||||
status = 0;
|
||||
while (status == 0){
|
||||
counter++;
|
||||
}
|
||||
printf("\nEncountered non-zero value for status. Counter = %d\n", counter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
31
GhidraDocs/GhidraClass/Advanced/Examples/globalRegVars.c
Normal file
31
GhidraDocs/GhidraClass/Advanced/Examples/globalRegVars.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include<stdlib.h>
|
||||
|
||||
long c;
|
||||
register long *b asm("r15");
|
||||
|
||||
void initRegisterPointerVar(){
|
||||
b = &c;
|
||||
}
|
||||
|
||||
void setRegisterPointerVar(long x){
|
||||
*b = x;
|
||||
}
|
||||
|
||||
long getRegisterPointerVar(){
|
||||
return *b;
|
||||
}
|
137
GhidraDocs/GhidraClass/Advanced/Examples/inline.s
Normal file
137
GhidraDocs/GhidraClass/Advanced/Examples/inline.s
Normal file
|
@ -0,0 +1,137 @@
|
|||
.file "inline.c"
|
||||
.intel_syntax noprefix
|
||||
.section .rodata
|
||||
.LC0:
|
||||
.string "\nUsage: %s arg1 arg2\n\n"
|
||||
.LC1:
|
||||
.string "\nSum of %lu and %lu: %lu\n\n"
|
||||
.text
|
||||
.globl main
|
||||
.type main, @function
|
||||
main:
|
||||
.LFB2:
|
||||
sub rsp, 40
|
||||
.LCFI0:
|
||||
mov DWORD PTR [rsp+12], edi
|
||||
mov QWORD PTR [rsp], rsi
|
||||
cmp DWORD PTR [rsp+12], 3
|
||||
je .L2
|
||||
mov rax, QWORD PTR [rsp]
|
||||
mov rax, QWORD PTR [rax]
|
||||
mov rsi, rax
|
||||
mov edi, OFFSET FLAT:.LC0
|
||||
mov eax, 0
|
||||
call printf
|
||||
mov eax, 0
|
||||
jmp .L3
|
||||
.L2:
|
||||
mov rax, QWORD PTR [rsp]
|
||||
add rax, 8
|
||||
mov rax, QWORD PTR [rax]
|
||||
mov edx, 10
|
||||
mov esi, 0
|
||||
mov rdi, rax
|
||||
call strtoul
|
||||
mov QWORD PTR [rsp+24], rax
|
||||
mov rax, QWORD PTR [rsp]
|
||||
add rax, 16
|
||||
mov rax, QWORD PTR [rax]
|
||||
mov edx, 10
|
||||
mov esi, 0
|
||||
mov rdi, rax
|
||||
call strtoul
|
||||
mov QWORD PTR [rsp+16], rax
|
||||
call adjustStack
|
||||
mov rax, QWORD PTR [rsp+32]
|
||||
mov rdx, QWORD PTR [rsp+40]
|
||||
lea rcx, [rdx+rax]
|
||||
mov rdx, QWORD PTR [rsp+32]
|
||||
mov rax, QWORD PTR [rsp+40]
|
||||
mov rsi, rax
|
||||
mov edi, OFFSET FLAT:.LC1
|
||||
mov eax, 0
|
||||
call printf
|
||||
call restoreStack
|
||||
mov eax, 0
|
||||
.L3:
|
||||
add rsp, 40
|
||||
.LCFI1:
|
||||
ret
|
||||
.LFE2:
|
||||
.size main, .-main
|
||||
.globl adjustStack
|
||||
.type adjustStack, @function
|
||||
adjustStack:
|
||||
.LFB3:
|
||||
pop rdi
|
||||
sub rsp, 0x10
|
||||
push rdi
|
||||
ret
|
||||
.LFE3:
|
||||
.size adjustStack, .-adjustStack
|
||||
.globl restoreStack
|
||||
.type restoreStack, @function
|
||||
restoreStack:
|
||||
.LFB4:
|
||||
pop rdi
|
||||
add rsp, 0x10
|
||||
push rdi
|
||||
ret
|
||||
.LFE4:
|
||||
.size restoreStack, .-restoreStack
|
||||
.section .eh_frame,"a",@progbits
|
||||
.Lframe1:
|
||||
.long .LECIE1-.LSCIE1
|
||||
.LSCIE1:
|
||||
.long 0
|
||||
.byte 0x3
|
||||
.string "zR"
|
||||
.uleb128 0x1
|
||||
.sleb128 -8
|
||||
.uleb128 0x10
|
||||
.uleb128 0x1
|
||||
.byte 0x3
|
||||
.byte 0xc
|
||||
.uleb128 0x7
|
||||
.uleb128 0x8
|
||||
.byte 0x90
|
||||
.uleb128 0x1
|
||||
.align 8
|
||||
.LECIE1:
|
||||
.LSFDE1:
|
||||
.long .LEFDE1-.LASFDE1
|
||||
.LASFDE1:
|
||||
.long .LASFDE1-.Lframe1
|
||||
.long .LFB2
|
||||
.long .LFE2-.LFB2
|
||||
.uleb128 0
|
||||
.byte 0x4
|
||||
.long .LCFI0-.LFB2
|
||||
.byte 0xe
|
||||
.uleb128 0x30
|
||||
.byte 0x4
|
||||
.long .LCFI1-.LCFI0
|
||||
.byte 0xe
|
||||
.uleb128 0x8
|
||||
.align 8
|
||||
.LEFDE1:
|
||||
.LSFDE3:
|
||||
.long .LEFDE3-.LASFDE3
|
||||
.LASFDE3:
|
||||
.long .LASFDE3-.Lframe1
|
||||
.long .LFB3
|
||||
.long .LFE3-.LFB3
|
||||
.uleb128 0
|
||||
.align 8
|
||||
.LEFDE3:
|
||||
.LSFDE5:
|
||||
.long .LEFDE5-.LASFDE5
|
||||
.LASFDE5:
|
||||
.long .LASFDE5-.Lframe1
|
||||
.long .LFB4
|
||||
.long .LFE4-.LFB4
|
||||
.uleb128 0
|
||||
.align 8
|
||||
.LEFDE5:
|
||||
.ident "GCC: (GNU) 4.8.5 20150623 (Red Hat 4.8.5-28)"
|
||||
.section .note.GNU-stack,"",@progbits
|
|
@ -0,0 +1,32 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
void printMessage(void);
|
||||
|
||||
int main(int argc, char **argv){
|
||||
asm(".intel_syntax noprefix");
|
||||
asm(".byte 0xeb, 0xff, 0xc0, 0x67, 0x48");
|
||||
asm(".att_syntax prefix");
|
||||
printMessage();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void printMessage(void){
|
||||
printf("\nIn printMessage function.\n\n");
|
||||
return;
|
||||
}
|
30
GhidraDocs/GhidraClass/Advanced/Examples/ldiv.c
Normal file
30
GhidraDocs/GhidraClass/Advanced/Examples/ldiv.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
|
||||
int main(int argc, char **argv){
|
||||
long numerator = strtoul(argv[1],NULL,10);
|
||||
long denominator = strtoul(argv[2],NULL,10);
|
||||
ldiv_t res = ldiv(numerator,denominator);
|
||||
printf("\nquotient: %ld, remainder: %ld\n", res.quot, res.rem);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
52
GhidraDocs/GhidraClass/Advanced/Examples/noReturn.c
Normal file
52
GhidraDocs/GhidraClass/Advanced/Examples/noReturn.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include<stdio.h>
|
||||
|
||||
//compile with -shared -fPIC, no optimizations
|
||||
|
||||
void __attribute__((noreturn)) loopForever(int);
|
||||
void printInput(unsigned long, unsigned long);
|
||||
void printInputThenLoop(unsigned long, unsigned long);
|
||||
|
||||
void __attribute__((noreturn)) loopForever(int x) {
|
||||
for(;;){
|
||||
printf("x: %d\n",x);
|
||||
}
|
||||
}
|
||||
|
||||
void printInputThenLoop1(unsigned long a, unsigned long b){
|
||||
printf("\na: %lu, b: %lu\n",a,b);
|
||||
loopForever(1);
|
||||
}
|
||||
|
||||
asm (".byte 0xff");
|
||||
asm (".byte 0xff");
|
||||
|
||||
void printInput(unsigned long a, unsigned long b){
|
||||
printf("\na: %lu, b%lu\n\n",a,b);
|
||||
return;
|
||||
}
|
||||
|
||||
void printInputThenLoop2(unsigned long a, unsigned long b){
|
||||
printf("\na: %lu, b: %lu\n", a,b);
|
||||
loopForever(2);
|
||||
}
|
||||
|
||||
asm (".byte 0xe8");
|
||||
|
||||
unsigned long add(unsigned long a, unsigned long b){
|
||||
return a+b;
|
||||
}
|
39
GhidraDocs/GhidraClass/Advanced/Examples/opaque.c
Normal file
39
GhidraDocs/GhidraClass/Advanced/Examples/opaque.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
int main(int argc, char **argv){
|
||||
if (argc != 3){
|
||||
printf("\nUsage: %s input1 input2\n\n",argv[0]);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
unsigned long input = strtoul(argv[1], NULL, 10);
|
||||
input *= input;
|
||||
input = input % 4;
|
||||
if (input >= 2){
|
||||
asm(".intel_syntax noprefix");
|
||||
asm(".byte 0xeb");
|
||||
asm(".byte 0x9");
|
||||
asm(".att_syntax prefix");
|
||||
}
|
||||
else {
|
||||
unsigned long second = strtoul(argv[2],NULL,10);
|
||||
input = second << 2 + input;
|
||||
printf("Returning %ld\n", input);
|
||||
}
|
||||
return input;
|
||||
}
|
31
GhidraDocs/GhidraClass/Advanced/Examples/override.c
Normal file
31
GhidraDocs/GhidraClass/Advanced/Examples/override.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include<stdio.h>
|
||||
|
||||
int a = 1;
|
||||
long b = 2;
|
||||
double c = 3.0;
|
||||
char d[] = "4";
|
||||
|
||||
|
||||
int overrideSignature(int e,int f, int g, int h){
|
||||
return printf("a: %d, b: %ld, c: %g, d: %s, e: %d, %d, %d, %d\n", a,b,c,d,e,f,g,h);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
75
GhidraDocs/GhidraClass/Advanced/Examples/setRegister.c
Normal file
75
GhidraDocs/GhidraClass/Advanced/Examples/setRegister.c
Normal file
|
@ -0,0 +1,75 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
long switchFunc(long);
|
||||
|
||||
int main(int argc, char **argv){
|
||||
long x = strtol(argv[1],NULL,10);
|
||||
return (int) switchFunc(x);
|
||||
}
|
||||
|
||||
long switchFunc(long x){
|
||||
long retVal = 0;
|
||||
switch(x){
|
||||
case 0:
|
||||
retVal = 0;
|
||||
printf("\nReturning %ld\n\n", retVal);
|
||||
break;
|
||||
case 1:
|
||||
retVal = 1;
|
||||
printf("\nReturning %ld\n\n", retVal);
|
||||
break;
|
||||
case 2:
|
||||
retVal = 22;
|
||||
printf("\nReturning %ld\n\n", retVal);
|
||||
break;
|
||||
case 3:
|
||||
retVal = 333;
|
||||
printf("\nReturning %ld\n\n", retVal);
|
||||
break;
|
||||
case 4:
|
||||
retVal = 4444;
|
||||
printf("\nReturning %ld\n\n", retVal);
|
||||
break;
|
||||
case 5:
|
||||
retVal = 55555;
|
||||
printf("\nReturning %ld\n\n", retVal);
|
||||
break;
|
||||
case 6:
|
||||
retVal = 666666;
|
||||
printf("\nReturning %ld\n\n", retVal);
|
||||
break;
|
||||
case 7:
|
||||
retVal = 7777777;
|
||||
printf("\nReturning %ld\n\n", retVal);
|
||||
break;
|
||||
case 8:
|
||||
retVal = 88888888;
|
||||
printf("\nReturning %ld\n\n", retVal);
|
||||
break;
|
||||
case 9:
|
||||
retVal = 999999999;
|
||||
printf("\nReturning %ld\n\n", retVal);
|
||||
break;
|
||||
default:
|
||||
retVal = -1;
|
||||
printf("\nReturning %ld\n\n", retVal);
|
||||
break;
|
||||
}
|
||||
return retVal;
|
||||
}
|
50
GhidraDocs/GhidraClass/Advanced/Examples/sharedReturn.c
Normal file
50
GhidraDocs/GhidraClass/Advanced/Examples/sharedReturn.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
long func1(long, long, long);
|
||||
long func2(long, long, long, long);
|
||||
long sumOfSquares(long,long);
|
||||
|
||||
int main(int argc, char **argv){
|
||||
if (argc != 5){
|
||||
printf("\nUsage: %s a b c d\n\n",argv[0]);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
long a = strtol(argv[1],NULL,10);
|
||||
long b = strtol(argv[2],NULL,10);
|
||||
long c = strtol(argv[3],NULL,10);
|
||||
long d = strtol(argv[4],NULL,10);
|
||||
return (int) (func1(a,b,c) + func2(a,b,c,d));
|
||||
}
|
||||
|
||||
long func1(long a, long b, long c){
|
||||
long x = c*(a+b);
|
||||
long y = c*(a-b);
|
||||
return sumOfSquares(x,y);
|
||||
}
|
||||
|
||||
|
||||
long func2(long a, long b, long c, long d){
|
||||
long x = a*c;
|
||||
long y = b*d;
|
||||
return sumOfSquares(x,y);
|
||||
}
|
||||
|
||||
long sumOfSquares(long a, long b){
|
||||
return a*a + b*b;
|
||||
}
|
122
GhidraDocs/GhidraClass/Advanced/Examples/switch.s
Normal file
122
GhidraDocs/GhidraClass/Advanced/Examples/switch.s
Normal file
|
@ -0,0 +1,122 @@
|
|||
.file "switch.c"
|
||||
.intel_syntax noprefix
|
||||
.section .rodata.str1.1,"aMS",@progbits,1
|
||||
.LC0:
|
||||
.string "\nUsage: %s switch_var input\n\n"
|
||||
.LC1:
|
||||
.string "Returning %ld\n"
|
||||
.section .text.startup,"ax",@progbits
|
||||
.p2align 4,,15
|
||||
.globl main
|
||||
.type main, @function
|
||||
main:
|
||||
.LFB20:
|
||||
.cfi_startproc
|
||||
push rbp
|
||||
.cfi_def_cfa_offset 16
|
||||
.cfi_offset 6, -16
|
||||
push rbx
|
||||
.cfi_def_cfa_offset 24
|
||||
.cfi_offset 3, -24
|
||||
mov rbx, rsi
|
||||
sub rsp, 8
|
||||
.cfi_def_cfa_offset 32
|
||||
cmp edi, 3
|
||||
je .L12
|
||||
mov rsi, QWORD PTR [rsi]
|
||||
mov edi, OFFSET FLAT:.LC0
|
||||
xor eax, eax
|
||||
call printf
|
||||
xor eax, eax
|
||||
.L13:
|
||||
add rsp, 8
|
||||
.cfi_remember_state
|
||||
.cfi_def_cfa_offset 24
|
||||
pop rbx
|
||||
.cfi_def_cfa_offset 16
|
||||
pop rbp
|
||||
.cfi_def_cfa_offset 8
|
||||
ret
|
||||
.L12:
|
||||
.cfi_restore_state
|
||||
mov rdi, QWORD PTR [rsi+8]
|
||||
mov edx, 10
|
||||
xor esi, esi
|
||||
call strtoul
|
||||
mov rdi, QWORD PTR [rbx+16]
|
||||
mov rbp, rax
|
||||
mov edx, 10
|
||||
xor esi, esi
|
||||
call strtol
|
||||
mov ecx, 10
|
||||
mov rbx, rax
|
||||
xor edx, edx
|
||||
mov rax, rbp
|
||||
div rcx
|
||||
jmp [QWORD PTR array[0+rdx*8]]
|
||||
.L2:
|
||||
lea rbx, [rbx+rbx*4]
|
||||
add rbx, 17
|
||||
.L14:
|
||||
mov rsi, rbx
|
||||
mov edi, OFFSET FLAT:.LC1
|
||||
xor eax, eax
|
||||
call printf
|
||||
mov eax, ebx
|
||||
jmp .L13
|
||||
.L11:
|
||||
imul rbx, rbx, 14
|
||||
add rbx, 53
|
||||
jmp .L14
|
||||
.L10:
|
||||
imul rbx, rbx, 13
|
||||
add rbx, 47
|
||||
jmp .L14
|
||||
.L9:
|
||||
imul rbx, rbx, 12
|
||||
add rbx, 43
|
||||
jmp .L14
|
||||
.L8:
|
||||
imul rbx, rbx, 11
|
||||
add rbx, 41
|
||||
jmp .L14
|
||||
.L7:
|
||||
imul rbx, rbx, 10
|
||||
add rbx, 37
|
||||
jmp .L14
|
||||
.L6:
|
||||
lea rbx, [rbx+rbx*8]
|
||||
add rbx, 31
|
||||
jmp .L14
|
||||
.L5:
|
||||
lea rbx, [29+rbx*8]
|
||||
jmp .L14
|
||||
.L4:
|
||||
imul rbx, rbx, 7
|
||||
add rbx, 23
|
||||
jmp .L14
|
||||
.L3:
|
||||
imul rbx, rbx, 6
|
||||
add rbx, 19
|
||||
jmp .L14
|
||||
.cfi_endproc
|
||||
.LFE20:
|
||||
.size main, .-main
|
||||
.globl array
|
||||
.data
|
||||
.align 32
|
||||
.type array, @object
|
||||
.size array, 80
|
||||
array:
|
||||
.quad OFFSET FLAT:.L2
|
||||
.quad OFFSET FLAT:.L3
|
||||
.quad OFFSET FLAT:.L4
|
||||
.quad OFFSET FLAT:.L5
|
||||
.quad OFFSET FLAT:.L6
|
||||
.quad OFFSET FLAT:.L7
|
||||
.quad OFFSET FLAT:.L8
|
||||
.quad OFFSET FLAT:.L9
|
||||
.quad OFFSET FLAT:.L10
|
||||
.quad OFFSET FLAT:.L11
|
||||
.ident "GCC: (GNU) 4.8.5 20150623 (Red Hat 4.8.5-28)"
|
||||
.section .note.GNU-stack,"",@progbits
|
Loading…
Add table
Add a link
Reference in a new issue