Skip to content

Global variable chapter added#162

Open
Farhan-25 wants to merge 3 commits intorizinorg:masterfrom
Farhan-25:global_var
Open

Global variable chapter added#162
Farhan-25 wants to merge 3 commits intorizinorg:masterfrom
Farhan-25:global_var

Conversation

@Farhan-25
Copy link
Contributor

@Farhan-25 Farhan-25 commented Jan 27, 2026

Your checklist for this pull request

  • I've used AI tools to generate these changes, fully or partially.
  • I've manually tested all commands and examples in these changes.

@Farhan-25
Copy link
Contributor Author

@wargio please check i have divided it into 2 seperate PR. This one is for global_variable chapter

avgx[jq] <name> # print all xrefs to the global variable
```

**Listing Global Variables**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That part is not really necessary I think


`avga <var_name> <type>` This command lets you manually add global variables with their name and type.

You use then when a global variables is missed during the analysis. Here `<type>` means the datatype of the variable. Example int, char, long.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You use then when a global variables is missed during the analysis. Here `<type>` means the datatype of the variable. Example int, char, long.
You use then when a global variables is missed during the analysis. Here `<type>` means the datatype of the variable. Example: `int`, `char`, `long`.


You use then when a global variables is missed during the analysis. Here `<type>` means the datatype of the variable. Example int, char, long.

Rizin Example :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Rizin Example :


**Printing Global Variables**

`avgp <name>` This command prints the value of the variable.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Describe what value it prints. If Rizin is in debug mode, does it print the value of the global at a certain break point?
Does it only print meaningful things for read only globals? Etc.
Please try this out and describe it here.

Comment on lines +47 to +56
**Deleting Global Variables**

`avgd <addr>` This command deletes the global variable located at the given address.

`avgm <name>` This command also lets you delete the global variable using its name.

**Renaming Global Variables**

`avgn <old_var_name> <new_var_name>` This command lets you rename the global variables.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are not needed as well. They just repeat the command docs.

Comment on lines +67 to +76
**Cross-References to Global Variables**

`avgx[jq] <name>` This command shows all the xrefs to the given global variable.

```
avgx <name> # print all xrefs to the global variable
avgxj <name> # print all xrefs to the global variable (JSON mode)
avgxq <name> # print all xrefs to the global variable (quiet mode)
```
There are two modes of display quiet and JSON.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here, it just repeats the command docs. So I don't think it is needed.

```
There are two modes of display quiet and JSON.

A working example on how the commands work. Lets take a sample file with no global variables.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a heading before the example

name type size address decl_file decl_line decl_col
――――――――――――――――――――――――――――――――――――――――――――――――――――
```
### **What Was Done in This Example**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### **What Was Done in This Example**
### What Was Done in This Example

A working example on how the commands work. Lets take a sample file with no global variables.

```
[0x00001040]> avglt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example is good.

But I would suggest to move the description into here. It is easier to follow this way.

# Ran 'avglt' to check for existing global variables (none were present).
[0x00001040]> avglt

# Step ...
[0x00001040]> COMANND

@Farhan-25
Copy link
Contributor Author

Okay thanks a lot for the review. I will fix the issues.

Farhan-25 and others added 2 commits February 2, 2026 19:18
Co-authored-by: Rot127 <45763064+Rot127@users.noreply.github.com>

`avgp <name>` This command prints the value of the variable.
`avgp <name>` reads memory at the address of the specified global variable and displays its current value.
>In debug mode → shows the value at the current breakpoint.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried this btw?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I tested it using a small C program with a global variable. The behavior works as expected, but my wording was inaccurate I should have said that in debug mode the value is read from process memory, rather than writing that it corresponds to a specific breakpoint location.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you open a PR in Rizin which adds this test please?
Because we don't have one and this is a pretty essential thing to check.

the binary with source code should be added in rizin-testbins repo.

Would really appreciate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure i can do that,

// test.c
#include <stdio.h>

int test_global = 1337;

int main() {
    printf("Ready: %d\n", test_global); 
    return 0;
}
rizin -d test.exe
Spawned new process with pid 30760, tid = 21376
 -- Save your projects with 'Ps <project-filename>' and restore then with 'Po <project-filename>'
[0x7ffc8970c510]> aaa
[WARNING: invalid address from 0x7ff7465b1500entry0 (aa)
[x] Analyze all flags starting with sym. and entry0 (aa)
[x] Analyze function calls
[x] Analyze len bytes of instructions for references
[x] Analyze local variables and arguments
[WARNING: core: analysis propagation type can't be exectured when in debugger mode.
[x] Type matching analysis for all functions
[x] Applied 0 FLIRT signatures via sigdb
[x] Propagate noreturn information
[x] Check for classes
[x] Integrate dwarf function information.
[x] Resolve pointers to data sections
[x] Use -AA or aaaa to perform additional experimental analysis.
[0x7ffc8970c510]> s sym.main
[0x7ff7465b1450]> db
[0x7ff7465b1450]> dc
ERROR: Cannot create flag "teb.40716" at 0x7117ace000 because there is already "PRIVATE__..7117ace000" flag
[0x7ffc8979f4ee]> avgp test_global
 int : 0x140003000 = -1

As you can see while debugging the value of test_global was stored as -1 in the process memory. Hence avgp prints that value instead of test_global.
@Rot127 please check once is this correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not.

#include <stdio.h>

int test_global = 1337;

int main() {
    printf("Ready: %d\n", test_global); 
    test_global = 1;
    printf("Ready: %d\n", test_global); 
    return 0;
}

Before the first printf call it should print 1337 (and it does for me).
Then it sets it to 1.
Before the second printf call it should print 1. But for me it still prints 1337.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants